Skip to content

Commit

Permalink
[MERGE #2674 @akroshg] Atomics check fails for virtual typedarray.
Browse files Browse the repository at this point in the history
Merge pull request #2674 from akroshg:atomics

Atomics operation failed on the virtual typedarray (when SharedArrayBuffer is more than 2^16). However In our case we don't need to check for virtual table check as the final operation happes on the typedarray itself. Fixed that by checking just the typeid.
  • Loading branch information
akroshg committed Mar 10, 2017
2 parents cb03b8b + 1ab1e9a commit e3d8f2b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/Runtime/Library/AtomicsObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ namespace Js
JavascriptError::ThrowTypeError(scriptContext, JSERR_NeedTypedArrayObject);
}

TypeId typeId = JavascriptOperators::GetTypeId(typedArray);
if (onlyInt32)
{
if (!Int32Array::Is(typedArray))
if (typeId != TypeIds_Int32Array)
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_InvalidOperationOnTypedArray);
}
}
else
{
if (!(Int8Array::Is(typedArray) || Uint8Array::Is(typedArray) || Int16Array::Is(typedArray) ||
Uint16Array::Is(typedArray) || Int32Array::Is(typedArray) || Uint32Array::Is(typedArray)))
if (!(typeId == TypeIds_Int8Array || typeId == TypeIds_Uint8Array || typeId == TypeIds_Int16Array ||
typeId == TypeIds_Uint16Array || typeId == TypeIds_Int32Array || typeId == TypeIds_Uint32Array))
{
JavascriptError::ThrowTypeError(scriptContext, JSERR_InvalidOperationOnTypedArray);
}
Expand Down
14 changes: 14 additions & 0 deletions test/es7/atomics_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,20 @@ var tests = [{
assert.areEqual(ret, "timed-out", "Negative infinity will be treated as 0 and so this will time-out");
}
},
{
name : "Atomics on virtual typedarray",
body : function () {
[2**15, 2**20, 2**25].forEach(function(size) {
IntViews.forEach(function(item) {
var view = new item.ctor(new SharedArrayBuffer(size));
Atomics.add(view, 0, 10);
Atomics.store(view, 2**10, 20);
assert.areEqual(Atomics.load(view, 0), 10);
assert.areEqual(Atomics.load(view, 2**10), 20);
});
});
}
},
];

testRunner.runTests(tests, {
Expand Down

0 comments on commit e3d8f2b

Please sign in to comment.