mirror of https://github.com/tc39/test262.git
Atomics.waitAsync: ValidateSharedIntegerTypedArray, ValidateAtomicAccess & Return promiseCapability.[[Promise]]
This commit is contained in:
parent
4e48a5692c
commit
c0f0adffdd
|
@ -0,0 +1,32 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-atomics.waitasync
|
||||
description: >
|
||||
Test range checking of Atomics.waitAsync on arrays that allow atomic operations
|
||||
info: |
|
||||
Atomics.waitAsync( typedArray, index, value, timeout )
|
||||
|
||||
1. Return DoWait(async, typedArray, index, value, timeout).
|
||||
|
||||
DoWait ( mode, typedArray, index, value, timeout )
|
||||
|
||||
...
|
||||
2. Let i be ? ValidateAtomicAccess(typedArray, index).
|
||||
...
|
||||
|
||||
includes: [testAtomics.js]
|
||||
features: [Atomics.waitAsync, Atomics, SharedArrayBuffer]
|
||||
---*/
|
||||
const i32a = new Int32Array(
|
||||
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 8)
|
||||
);
|
||||
|
||||
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
|
||||
assert.throws(RangeError, function() {
|
||||
Atomics.waitAsync(i32a, IdxGen(i32a), 0, 0);
|
||||
}, '`Atomics.waitAsync(i32a, IdxGen(i32a), 0, 0)` throws RangeError');
|
||||
});
|
||||
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-atomics.waitasync
|
||||
description: >
|
||||
Throws a TypeError if typedArray arg is not an Int32Array
|
||||
info: |
|
||||
Atomics.waitAsync( typedArray, index, value, timeout )
|
||||
|
||||
1. Return DoWait(async, typedArray, index, value, timeout).
|
||||
|
||||
DoWait ( mode, typedArray, index, value, timeout )
|
||||
|
||||
1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
|
||||
|
||||
ValidateSharedIntegerTypedArray ( typedArray [ , waitable ] )
|
||||
|
||||
5. If waitable is true, then
|
||||
a. If typeName is not "Int32Array" or "BigInt64Array", throw a TypeError exception.
|
||||
|
||||
features: [Atomics.waitAsync, Float32Array, Float64Array, Int8Array, TypedArray, Uint16Array, Uint8Array, Uint8ClampedArray]
|
||||
---*/
|
||||
const poisoned = {
|
||||
valueOf() {
|
||||
throw new Test262Error('should not evaluate this code');
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
const view = new Float64Array(
|
||||
new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * 8)
|
||||
);
|
||||
Atomics.waitAsync(view, poisoned, poisoned, poisoned);
|
||||
}, '`const view = new Float64Array( new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * 8) ); Atomics.waitAsync(view, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
const view = new Float32Array(
|
||||
new SharedArrayBuffer(Float32Array.BYTES_PER_ELEMENT * 4)
|
||||
);
|
||||
Atomics.waitAsync(view, poisoned, poisoned, poisoned);
|
||||
}, '`const view = new Float32Array( new SharedArrayBuffer(Float32Array.BYTES_PER_ELEMENT * 4) ); Atomics.waitAsync(view, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
const view = new Int16Array(
|
||||
new SharedArrayBuffer(Int16Array.BYTES_PER_ELEMENT * 2)
|
||||
);
|
||||
Atomics.waitAsync(view, poisoned, poisoned, poisoned);
|
||||
}, '`const view = new Int16Array( new SharedArrayBuffer(Int16Array.BYTES_PER_ELEMENT * 2) ); Atomics.waitAsync(view, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
const view = new Int8Array(
|
||||
new SharedArrayBuffer(Int8Array.BYTES_PER_ELEMENT)
|
||||
);
|
||||
Atomics.waitAsync(view, poisoned, poisoned, poisoned);
|
||||
}, '`const view = new Int8Array( new SharedArrayBuffer(Int8Array.BYTES_PER_ELEMENT) ); Atomics.waitAsync(view, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
const view = new Uint32Array(
|
||||
new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT * 4)
|
||||
);
|
||||
Atomics.waitAsync(view, poisoned, poisoned, poisoned);
|
||||
}, '`const view = new Uint32Array( new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT * 4) ); Atomics.waitAsync(view, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
const view = new Uint16Array(
|
||||
new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * 2)
|
||||
);
|
||||
Atomics.waitAsync(view, poisoned, poisoned, poisoned);
|
||||
}, '`const view = new Uint16Array( new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * 2) ); Atomics.waitAsync(view, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
const view = new Uint8Array(
|
||||
new SharedArrayBuffer(Uint8Array.BYTES_PER_ELEMENT)
|
||||
);
|
||||
Atomics.waitAsync(view, poisoned, poisoned, poisoned);
|
||||
}, '`const view = new Uint8Array( new SharedArrayBuffer(Uint8Array.BYTES_PER_ELEMENT) ); Atomics.waitAsync(view, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
const view = new Uint8ClampedArray(
|
||||
new SharedArrayBuffer(Uint8ClampedArray.BYTES_PER_ELEMENT)
|
||||
);
|
||||
Atomics.waitAsync(view, poisoned, poisoned, poisoned);
|
||||
}, '`const view = new Uint8ClampedArray( new SharedArrayBuffer(Uint8ClampedArray.BYTES_PER_ELEMENT) ); Atomics.waitAsync(view, poisoned, poisoned, poisoned)` throws TypeError');
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-atomics.waitasync
|
||||
description: >
|
||||
Throws a TypeError if typedArray.buffer is not a SharedArrayBuffer
|
||||
info: |
|
||||
Atomics.waitAsync( typedArray, index, value, timeout )
|
||||
|
||||
1. Return DoWait(async, typedArray, index, value, timeout).
|
||||
|
||||
DoWait ( mode, typedArray, index, value, timeout )
|
||||
|
||||
1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
|
||||
|
||||
ValidateSharedIntegerTypedArray ( typedArray [ , waitable ] )
|
||||
|
||||
5. If waitable is true, then
|
||||
a. If typeName is not "Int32Array" or "BigInt64Array", throw a TypeError exception.
|
||||
|
||||
features: [Atomics.waitAsync, ArrayBuffer, Atomics, TypedArray]
|
||||
---*/
|
||||
const i32a = new Int32Array(
|
||||
new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
|
||||
);
|
||||
|
||||
const poisoned = {
|
||||
valueOf() {
|
||||
throw new Test262Error('should not evaluate this code');
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.wait(i32a, 0, 0, 0);
|
||||
}, '`Atomics.wait(i32a, 0, 0, 0)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.wait(i32a, poisoned, poisoned, poisoned);
|
||||
}, '`Atomics.wait(i32a, poisoned, poisoned, poisoned)` throws TypeError');
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-atomics.waitasync
|
||||
description: >
|
||||
Throws a TypeError if the typedArray arg is not a TypedArray object
|
||||
info: |
|
||||
Atomics.waitAsync( typedArray, index, value, timeout )
|
||||
|
||||
1. Return DoWait(async, typedArray, index, value, timeout).
|
||||
|
||||
DoWait ( mode, typedArray, index, value, timeout )
|
||||
|
||||
1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
|
||||
|
||||
ValidateSharedIntegerTypedArray ( typedArray [ , waitable ] )
|
||||
|
||||
2. Perform ? RequireInternalSlot(typedArray, [[TypedArrayName]]).
|
||||
|
||||
RequireInternalSlot ( O, internalSlot )
|
||||
|
||||
1. If Type(O) is not Object, throw a TypeError exception.
|
||||
2. If O does not have an internalSlot internal slot, throw a TypeError exception.
|
||||
|
||||
features: [Atomics.waitAsync]
|
||||
---*/
|
||||
const poisoned = {
|
||||
valueOf() {
|
||||
throw new Test262Error('should not evaluate this code');
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.waitAsync({}, 0, 0, 0);
|
||||
}, '`Atomics.waitAsync({}, 0, 0, 0)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.waitAsync({}, poisoned, poisoned, poisoned);
|
||||
}, '`Atomics.waitAsync({}, poisoned, poisoned, poisoned)` throws TypeError');
|
|
@ -0,0 +1,59 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-atomics.waitasync
|
||||
description: >
|
||||
Throws a TypeError if typedArray arg is not an Object
|
||||
info: |
|
||||
Atomics.waitAsync( typedArray, index, value, timeout )
|
||||
|
||||
1. Return DoWait(async, typedArray, index, value, timeout).
|
||||
|
||||
DoWait ( mode, typedArray, index, value, timeout )
|
||||
|
||||
1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
|
||||
|
||||
ValidateSharedIntegerTypedArray ( typedArray [ , waitable ] )
|
||||
|
||||
2. Perform ? RequireInternalSlot(typedArray, [[TypedArrayName]]).
|
||||
|
||||
RequireInternalSlot ( O, internalSlot )
|
||||
|
||||
1. If Type(O) is not Object, throw a TypeError exception.
|
||||
2. If O does not have an internalSlot internal slot, throw a TypeError exception.
|
||||
|
||||
features: [Atomics.waitAsync, Symbol]
|
||||
---*/
|
||||
const poisoned = {
|
||||
valueOf() {
|
||||
throw new Test262Error('should not evaluate this code');
|
||||
}
|
||||
};
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.waitAsync(null, poisoned, poisoned, poisoned);
|
||||
}, '`Atomics.waitAsync(null, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.waitAsync(undefined, poisoned, poisoned, poisoned);
|
||||
}, '`Atomics.waitAsync(undefined, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.waitAsync(true, poisoned, poisoned, poisoned);
|
||||
}, '`Atomics.waitAsync(true, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.waitAsync(false, poisoned, poisoned, poisoned);
|
||||
}, '`Atomics.waitAsync(false, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.waitAsync('***string***', poisoned, poisoned, poisoned);
|
||||
}, '`Atomics.waitAsync(\'***string***\', poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.waitAsync(Number.NEGATIVE_INFINITY, poisoned, poisoned, poisoned);
|
||||
}, '`Atomics.waitAsync(Number.NEGATIVE_INFINITY, poisoned, poisoned, poisoned)` throws TypeError');
|
||||
|
||||
assert.throws(TypeError, () => {
|
||||
Atomics.waitAsync(Symbol('***symbol***'), poisoned, poisoned, poisoned);
|
||||
}, '`Atomics.waitAsync(Symbol(\'***symbol***\'), poisoned, poisoned, poisoned)` throws TypeError');
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-atomics.waitasync
|
||||
description: >
|
||||
A null value for bufferData throws a TypeError
|
||||
info: |
|
||||
Atomics.waitAsync( typedArray, index, value, timeout )
|
||||
|
||||
1. Return DoWait(async, typedArray, index, value, timeout).
|
||||
|
||||
DoWait ( mode, typedArray, index, value, timeout )
|
||||
|
||||
1. Let buffer be ? ValidateSharedIntegerTypedArray(typedArray, true).
|
||||
|
||||
ValidateSharedIntegerTypedArray ( typedArray [ , waitable ] )
|
||||
|
||||
2. Perform ? RequireInternalSlot(typedArray, [[TypedArrayName]]).
|
||||
|
||||
RequireInternalSlot ( O, internalSlot )
|
||||
|
||||
1. If Type(O) is not Object, throw a TypeError exception.
|
||||
2. If O does not have an internalSlot internal slot, throw a TypeError exception.
|
||||
|
||||
includes: [detachArrayBuffer.js]
|
||||
features: [Atomics.waitAsync, ArrayBuffer, Atomics, TypedArray]
|
||||
---*/
|
||||
const i32a = new Int32Array(
|
||||
new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
|
||||
);
|
||||
|
||||
const poisoned = {
|
||||
valueOf() {
|
||||
throw new Test262Error('should not evaluate this code');
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
$DETACHBUFFER(i32a.buffer); // Detaching a non-shared ArrayBuffer sets the [[ArrayBufferData]] value to null
|
||||
} catch (error) {
|
||||
$ERROR(`An unexpected error occurred when detaching ArrayBuffer: ${error.message}`);
|
||||
}
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
Atomics.waitAsync(i32a, poisoned, poisoned, poisoned);
|
||||
}, '`Atomics.waitAsync(i32a, poisoned, poisoned, poisoned)` throws TypeError');
|
|
@ -0,0 +1,33 @@
|
|||
// Copyright (C) 2020 Rick Waldron. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-atomics.waitasync
|
||||
description: >
|
||||
Atomics.waitAsync returns a promise.
|
||||
info: |
|
||||
Atomics.waitAsync( typedArray, index, value, timeout )
|
||||
|
||||
1. Return DoWait(async, typedArray, index, value, timeout).
|
||||
|
||||
DoWait ( mode, typedArray, index, value, timeout )
|
||||
|
||||
...
|
||||
13. Let promiseCapability be undefined.
|
||||
14. If mode is async, then
|
||||
a. Set promiseCapability to ! NewPromiseCapability(%Promise%).
|
||||
|
||||
...
|
||||
24. Return promiseCapability.[[Promise]].
|
||||
|
||||
features: [Atomics.waitAsync]
|
||||
---*/
|
||||
|
||||
const i32a = new Int32Array(
|
||||
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 8)
|
||||
);
|
||||
|
||||
let p = Atomics.waitAsync(i32a, 0, 0, 0);
|
||||
|
||||
assert(p instanceof Promise);
|
||||
assert.sameValue(Object.getPrototypeOf(p), Promise.prototype);
|
Loading…
Reference in New Issue