Atomics.waitAsync: misused symbol args.

This commit is contained in:
Rick Waldron 2020-04-15 15:06:58 -04:00
parent 127fa27720
commit 161ce480d1
10 changed files with 342 additions and 33 deletions

View File

@ -51,8 +51,6 @@ $262.agent.start(`
$262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
Atomics.add(i32a, 0, 1);
assert.sameValue(agentCount, 1);
const lapse = await $262.agent.getReportAsync();

View File

@ -27,13 +27,13 @@ const RUNNING = 1;
$262.agent.start(`
const poisonedValueOf = {
valueOf() {
throw new Error("should not evaluate this code");
throw new Error('should not evaluate this code');
}
};
const poisonedToPrimitive = {
[Symbol.toPrimitive]() {
throw new Error("passing a poisoned object using @@ToPrimitive");
throw new Error('passing a poisoned object using @@ToPrimitive');
}
};
@ -41,18 +41,18 @@ $262.agent.start(`
const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
let status1 = "";
let status2 = "";
let status1 = ';
let status2 = ';
try {
Atomics.wait(i32a, 0, 0, poisonedValueOf);
} catch (error) {
status1 = "poisonedValueOf";
status1 = 'poisonedValueOf';
}
try {
Atomics.wait(i32a, 0, 0, poisonedToPrimitive);
} catch (error) {
status2 = "poisonedToPrimitive";
status2 = 'poisonedToPrimitive';
}
$262.agent.report(status1);
@ -74,6 +74,7 @@ $262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
'poisonedValueOf',
'Atomics.wait(i32a, 0, 0, poisonedValueOf) throws'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'poisonedToPrimitive',

View File

@ -6,14 +6,16 @@ esid: sec-atomics.waitasync
description: >
Throws a TypeError if index arg can not be converted to an Integer
info: |
Atomics.wait( typedArray, index, value, timeout )
Atomics.waitAsync( typedArray, index, value, timeout )
4. Let q be ? ToNumber(timeout).
1. Return DoWait(async, typedArray, index, value, timeout).
Object -> Apply the following steps:
DoWait ( mode, typedArray, index, value, timeout )
Let primValue be ? ToPrimitive(argument, hint Number).
Return ? ToNumber(primValue).
6. Let q be ? ToNumber(timeout).
Let primValue be ? ToPrimitive(argument, hint Number).
Return ? ToNumber(primValue).
features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics]
---*/
@ -30,7 +32,7 @@ const poisonedValueOf = {
const poisonedToPrimitive = {
[Symbol.toPrimitive]() {
throw new Test262Error("passing a poisoned object using @@ToPrimitive");
throw new Test262Error('passing a poisoned object using @@ToPrimitive');
}
};

View File

@ -6,7 +6,6 @@ esid: sec-atomics.waitasync
description: >
Atomics.waitAsync returns a result object containing a string "not-equal" and async is false.
info: |
Atomics.waitAsync( typedArray, index, value, timeout )
1. Return DoWait(async, typedArray, index, value, timeout).

View File

@ -0,0 +1,97 @@
// 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 index arg can not be converted to an Integer
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).
ValidateAtomicAccess( typedArray, requestIndex )
2. Let accessIndex be ? ToIndex(requestIndex).
ToIndex ( value )
2. Else,
a. Let integerIndex be ? ToInteger(value).
ToInteger(value)
1. Let number be ? ToNumber(argument).
Symbol --> Throw a TypeError exception.
flags: [async]
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, Atomics]
---*/
const RUNNING = 1;
$262.agent.start(`
const poisonedValueOf = {
valueOf() {
throw new Test262Error('should not evaluate this code');
}
};
const poisonedToPrimitive = {
[Symbol.toPrimitive]() {
throw new Test262Error('should not evaluate this code');
}
};
$262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
let status1 = '';
let status2 = '';
try {
Atomics.waitAsync(i32a, Symbol('1'), poisonedValueOf, poisonedValueOf);
} catch (error) {
status1 = 'A ' + error.name;
}
try {
Atomics.waitAsync(i32a, Symbol('2'), poisonedToPrimitive, poisonedToPrimitive);
} catch (error) {
status2 = 'B ' + error.name;
}
$262.agent.report(status1);
$262.agent.report(status2);
$262.agent.leaving();
});
`);
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
$262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
assert.sameValue(agentCount, 1);
assert.sameValue(
await $262.agent.getReportAsync(),
'A TypeError',
'Atomics.waitAsync(i32a, Symbol("1"), ..., ...) throws TypeError'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'B TypeError',
'Atomics.waitAsync(i32a, Symbol("2"), ..., ...) throws TypeError'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
}).then($DONE, $DONE);

View File

@ -0,0 +1,67 @@
// 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 index arg can not be converted to an Integer
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).
ValidateAtomicAccess( typedArray, requestIndex )
2. Let accessIndex be ? ToIndex(requestIndex).
ToIndex ( value )
2. Else,
a. Let integerIndex be ? ToInteger(value).
ToInteger(value)
1. Let number be ? ToNumber(argument).
Symbol --> Throw a TypeError exception.
features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
const poisonedValueOf = {
valueOf() {
throw new Test262Error('should not evaluate this code');
}
};
const poisonedToPrimitive = {
[Symbol.toPrimitive]() {
throw new Test262Error('should not evaluate this code');
}
};
assert.throws(Test262Error, function() {
Atomics.waitAsync(i32a, poisonedValueOf, poisonedValueOf, poisonedValueOf);
}, '`Atomics.waitAsync(i32a, poisonedValueOf, poisonedValueOf, poisonedValueOf)` throws Test262Error');
assert.throws(Test262Error, function() {
Atomics.waitAsync(i32a, poisonedToPrimitive, poisonedToPrimitive, poisonedToPrimitive);
}, '`Atomics.waitAsync(i32a, poisonedToPrimitive, poisonedToPrimitive, poisonedToPrimitive)` throws Test262Error');
assert.throws(TypeError, function() {
Atomics.waitAsync(i32a, Symbol('1'), poisonedValueOf, poisonedValueOf);
}, '`Atomics.waitAsync(i32a, Symbol("1"), poisonedValueOf, poisonedValueOf)` throws TypeError');
assert.throws(TypeError, function() {
Atomics.waitAsync(i32a, Symbol('2'), poisonedToPrimitive, poisonedToPrimitive);
}, '`Atomics.waitAsync(i32a, Symbol("2"), poisonedToPrimitive, poisonedToPrimitive)` throws TypeError');

View File

@ -28,18 +28,18 @@ $262.agent.start(`
const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
let status1 = "";
let status2 = "";
let status1 = '';
let status2 = '';
try {
Atomics.wait(i32a, 0, 0, Symbol("1"));
Atomics.waitAsync(i32a, 0, 0, Symbol('1'));
} catch (error) {
status1 = 'Symbol("1")';
status1 = 'A ' + error.name;
}
try {
Atomics.wait(i32a, 0, 0, Symbol("2"));
Atomics.waitAsync(i32a, 0, 0, Symbol('2'));
} catch (error) {
status2 = 'Symbol("2")';
status2 = 'B ' + error.name;
}
$262.agent.report(status1);
@ -58,14 +58,14 @@ $262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
assert.sameValue(
await $262.agent.getReportAsync(),
'Symbol("1")',
'Atomics.wait(i32a, 0, 0, Symbol("1")) throws'
'A TypeError',
'Atomics.wait(i32a, 0, 0, Symbol("1")) throws TypeError'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'Symbol("2")',
'Atomics.wait(i32a, 0, 0, Symbol("2")) throws'
'B TypeError',
'Atomics.wait(i32a, 0, 0, Symbol("2")) throws TypeError'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');

View File

@ -35,17 +35,17 @@ const poisonedToPrimitive = {
};
assert.throws(Test262Error, function() {
Atomics.wait(i32a, 0, 0, poisonedValueOf);
}, '`Atomics.wait(i32a, 0, 0, poisonedValueOf)` throws Test262Error');
Atomics.waitAsync(i32a, 0, 0, poisonedValueOf);
}, '`Atomics.waitAsync(i32a, 0, 0, poisonedValueOf)` throws Test262Error');
assert.throws(Test262Error, function() {
Atomics.wait(i32a, 0, 0, poisonedToPrimitive);
}, '`Atomics.wait(i32a, 0, 0, poisonedToPrimitive)` throws Test262Error');
Atomics.waitAsync(i32a, 0, 0, poisonedToPrimitive);
}, '`Atomics.waitAsync(i32a, 0, 0, poisonedToPrimitive)` throws Test262Error');
assert.throws(TypeError, function() {
Atomics.wait(i32a, 0, 0, Symbol("foo"));
}, '`Atomics.wait(i32a, 0, 0, Symbol("foo"))` throws TypeError');
Atomics.waitAsync(i32a, 0, 0, Symbol("foo"));
}, '`Atomics.waitAsync(i32a, 0, 0, Symbol("foo"))` throws TypeError');
assert.throws(TypeError, function() {
Atomics.wait(i32a, 0, 0, Symbol("foo"));
}, '`Atomics.wait(i32a, 0, 0, Symbol("foo"))` throws TypeError');
Atomics.waitAsync(i32a, 0, 0, Symbol("foo"));
}, '`Atomics.waitAsync(i32a, 0, 0, Symbol("foo"))` throws TypeError');

View File

@ -0,0 +1,90 @@
// 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 value arg is a Symbol
info: |
Atomics.waitAsync( typedArray, index, value, timeout )
1. Return DoWait(async, typedArray, index, value, timeout).
DoWait ( mode, typedArray, index, value, timeout )
5. Otherwise, let v be ? ToInt32(value).
ToInt32(value)
1.Let number be ? ToNumber(argument).
Symbol --> Throw a TypeError exception.
flags: [async]
includes: [atomicsHelper.js]
features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, Atomics]
---*/
const RUNNING = 1;
$262.agent.start(`
const poisonedValueOf = {
valueOf: function() {
throw new Test262Error('should not evaluate this code');
}
};
const poisonedToPrimitive = {
[Symbol.toPrimitive]: function() {
throw new Test262Error("passing a poisoned object using @@ToPrimitive");
}
};
$262.agent.receiveBroadcast(function(sab) {
const i32a = new Int32Array(sab);
Atomics.add(i32a, ${RUNNING}, 1);
let status1 = "";
let status2 = "";
try {
Atomics.waitAsync(i32a, 0, Symbol("1"), poisonedValueOf);
} catch (error) {
status1 = 'A ' + error.name;
}
try {
Atomics.waitAsync(i32a, 0, Symbol("2"), poisonedToPrimitive);
} catch (error) {
status2 = 'B ' + error.name;
}
$262.agent.report(status1);
$262.agent.report(status2);
$262.agent.leaving();
});
`);
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
$262.agent.safeBroadcastAsync(i32a, RUNNING, 1).then(async (agentCount) => {
assert.sameValue(agentCount, 1);
assert.sameValue(
await $262.agent.getReportAsync(),
'A TypeError',
'Atomics.waitAsync(i32a, 0, Symbol("1"), ...) throws TypeError'
);
assert.sameValue(
await $262.agent.getReportAsync(),
'B TypeError',
'Atomics.waitAsync(i32a, 0, Symbol("2"), ...) throws TypeError'
);
assert.sameValue(Atomics.notify(i32a, 0), 0, 'Atomics.notify(i32a, 0) returns 0');
}).then($DONE, $DONE);

View File

@ -0,0 +1,55 @@
// 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 value arg is a Symbol
info: |
Atomics.waitAsync( typedArray, index, value, timeout )
1. Return DoWait(async, typedArray, index, value, timeout).
DoWait ( mode, typedArray, index, value, timeout )
5. Otherwise, let v be ? ToInt32(value).
ToInt32(value)
1.Let number be ? ToNumber(argument).
Symbol --> Throw a TypeError exception.
features: [Atomics.waitAsync, SharedArrayBuffer, Symbol, Symbol.toPrimitive, TypedArray, computed-property-names, Atomics]
---*/
const i32a = new Int32Array(
new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4)
);
const poisonedValueOf = {
valueOf() {
throw new Test262Error('should not evaluate this code');
}
};
const poisonedToPrimitive = {
[Symbol.toPrimitive]() {
throw new Test262Error("passing a poisoned object using @@ToPrimitive");
}
};
assert.throws(Test262Error, function() {
Atomics.waitAsync(i32a, 0, poisonedValueOf, poisonedValueOf);
}, '`Atomics.waitAsync(i32a, 0, poisonedValueOf, poisonedValueOf)` throws Test262Error');
assert.throws(Test262Error, function() {
Atomics.waitAsync(i32a, 0, poisonedToPrimitive, poisonedToPrimitive);
}, '`Atomics.waitAsync(i32a, 0, poisonedToPrimitive, poisonedToPrimitive)` throws Test262Error');
assert.throws(TypeError, function() {
Atomics.waitAsync(i32a, 0, Symbol("foo"), poisonedValueOf);
}, '`Atomics.waitAsync(i32a, 0, Symbol("foo"), poisonedValueOf)` throws TypeError');
assert.throws(TypeError, function() {
Atomics.waitAsync(i32a, 0, Symbol("foo"), poisonedToPrimitive);
}, '`Atomics.waitAsync(i32a, 0, Symbol("foo"), poisonedToPrimitive)` throws TypeError');