Commit 7f34af65 authored by binji's avatar binji Committed by Commit bot

In Atomics API, convert operands to numbers before calling runtime.

R=jarin@chromium.org

Review URL: https://codereview.chromium.org/1232243002

Cr-Commit-Position: refs/heads/master@{#29625}
parent 24bddcd3
......@@ -36,6 +36,8 @@ function AtomicsCompareExchangeJS(sta, index, oldValue, newValue) {
if (index < 0 || index >= sta.length) {
return UNDEFINED;
}
oldValue = $toNumber(oldValue);
newValue = $toNumber(newValue);
return %_AtomicsCompareExchange(sta, index, oldValue, newValue);
}
......@@ -54,6 +56,7 @@ function AtomicsStoreJS(sta, index, value) {
if (index < 0 || index >= sta.length) {
return UNDEFINED;
}
value = $toNumber(value);
return %_AtomicsStore(sta, index, value);
}
......@@ -63,6 +66,7 @@ function AtomicsAddJS(ia, index, value) {
if (index < 0 || index >= ia.length) {
return UNDEFINED;
}
value = $toNumber(value);
return %_AtomicsAdd(ia, index, value);
}
......@@ -72,6 +76,7 @@ function AtomicsSubJS(ia, index, value) {
if (index < 0 || index >= ia.length) {
return UNDEFINED;
}
value = $toNumber(value);
return %_AtomicsSub(ia, index, value);
}
......@@ -81,6 +86,7 @@ function AtomicsAndJS(ia, index, value) {
if (index < 0 || index >= ia.length) {
return UNDEFINED;
}
value = $toNumber(value);
return %_AtomicsAnd(ia, index, value);
}
......@@ -90,6 +96,7 @@ function AtomicsOrJS(ia, index, value) {
if (index < 0 || index >= ia.length) {
return UNDEFINED;
}
value = $toNumber(value);
return %_AtomicsOr(ia, index, value);
}
......@@ -99,6 +106,7 @@ function AtomicsXorJS(ia, index, value) {
if (index < 0 || index >= ia.length) {
return UNDEFINED;
}
value = $toNumber(value);
return %_AtomicsXor(ia, index, value);
}
......@@ -108,6 +116,7 @@ function AtomicsExchangeJS(ia, index, value) {
if (index < 0 || index >= ia.length) {
return UNDEFINED;
}
value = $toNumber(value);
return %_AtomicsExchange(ia, index, value);
}
......
......@@ -344,6 +344,58 @@ function testAtomicOp(op, ia, index, expectedIndex, name) {
}
})();
(function TestToNumber() {
IntegerTypedArrayConstructors.forEach(function(t) {
var sab = new SharedArrayBuffer(1 * t.constr.BYTES_PER_ELEMENT);
var sta = new t.constr(sab);
var valueOf = {valueOf: function(){ return 3;}};
var toString = {toString: function(){ return '3';}};
[false, true, undefined, valueOf, toString].forEach(function(v) {
var name = Object.prototype.toString.call(sta) + ' - ' + v;
// CompareExchange
sta[0] = 50;
assertEquals(50, Atomics.compareExchange(sta, 0, v, v), name);
// Store
assertEquals(+v, Atomics.store(sta, 0, v), name);
assertEquals(v|0, sta[0], name);
// Add
sta[0] = 120;
assertEquals(120, Atomics.add(sta, 0, v), name);
assertEquals(120 + (v|0), sta[0], name);
// Sub
sta[0] = 70;
assertEquals(70, Atomics.sub(sta, 0, v), name);
assertEquals(70 - (v|0), sta[0]);
// And
sta[0] = 0x20;
assertEquals(0x20, Atomics.and(sta, 0, v), name);
assertEquals(0x20 & (v|0), sta[0]);
// Or
sta[0] = 0x3d;
assertEquals(0x3d, Atomics.or(sta, 0, v), name);
assertEquals(0x3d | (v|0), sta[0]);
// Xor
sta[0] = 0x25;
assertEquals(0x25, Atomics.xor(sta, 0, v), name);
assertEquals(0x25 ^ (v|0), sta[0]);
// Exchange
sta[0] = 0x09;
assertEquals(0x09, Atomics.exchange(sta, 0, v), name);
assertEquals(v|0, sta[0]);
});
});
})();
(function TestWrapping() {
IntegerTypedArrayConstructors.forEach(function(t) {
var sab = new SharedArrayBuffer(10 * t.constr.BYTES_PER_ELEMENT);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment