| 1 |
// Copyright (C) 2017 Mozilla Corporation. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-atomics.islockfree |
| 6 |
description: > |
| 7 |
Test isLockFree on nonnegative integer arguments |
| 8 |
---*/ |
| 9 |
|
| 10 |
var sizes = [ 1, 2, 3, 4, 5, 6, 7, 8, |
| 11 |
9, 10, 11, 12]; |
| 12 |
var answers = [ {}, {}, false, true, false, false, false, false, |
| 13 |
false, false, false, false]; |
| 14 |
|
| 15 |
function testIsLockFree() { |
| 16 |
var saved = {}; |
| 17 |
|
| 18 |
// This should defeat most optimizations. |
| 19 |
|
| 20 |
for (var i = 0; i < sizes.length; i++) { |
| 21 |
var v = Atomics.isLockFree(sizes[i]); |
| 22 |
var a = answers[i]; |
| 23 |
assert.sameValue(typeof v, 'boolean'); |
| 24 |
if (typeof a == 'boolean') |
| 25 |
assert.sameValue(v, a); |
| 26 |
else |
| 27 |
saved[sizes[i]] = v; |
| 28 |
} |
| 29 |
|
| 30 |
// This ought to be optimizable. Make sure the answers are the same |
| 31 |
// as for the unoptimized case. |
| 32 |
|
| 33 |
assert.sameValue(Atomics.isLockFree(1), saved[1]); |
| 34 |
assert.sameValue(Atomics.isLockFree(2), saved[2]); |
| 35 |
assert.sameValue(Atomics.isLockFree(3), false); |
| 36 |
assert.sameValue(Atomics.isLockFree(4), true); |
| 37 |
assert.sameValue(Atomics.isLockFree(5), false); |
| 38 |
assert.sameValue(Atomics.isLockFree(6), false); |
| 39 |
assert.sameValue(Atomics.isLockFree(7), false); |
| 40 |
assert.sameValue(Atomics.isLockFree(8), false); |
| 41 |
assert.sameValue(Atomics.isLockFree(9), false); |
| 42 |
assert.sameValue(Atomics.isLockFree(10), false); |
| 43 |
assert.sameValue(Atomics.isLockFree(11), false); |
| 44 |
assert.sameValue(Atomics.isLockFree(12), false); |
| 45 |
} |
| 46 |
|
| 47 |
testIsLockFree(); |