Skip to content

Commit

Permalink
Run SharedArrayBuffer WPT tests in virtual/sharedarraybuffer testsuite
Browse files Browse the repository at this point in the history
This also fixes an issue in postMessage when
CanTransferArrayBuffersAndImageBitmaps is false (e.g. MessagePorts).
Previously, we would remove all transferables from the transferables list,
serialize that, then transfer the transferables separately. This prevents an
exception from being thrown when a SharedArrayBuffer is in the transferables
list.

BUG=chromium:716320

Review-Url: https://codereview.chromium.org/2860303002
Cr-Commit-Position: refs/heads/master@{#470154}
  • Loading branch information
binji authored and Commit bot committed May 9, 2017
1 parent 02d415e commit 43a78b9
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 5 deletions.
5 changes: 5 additions & 0 deletions third_party/WebKit/LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -3250,6 +3250,11 @@ crbug.com/718394 virtual/enable_asmjs/http/tests/asmjs/asm-warnings.html [ Needs
crbug.com/681468 fast/forms/suggestion-picker/date-suggestion-picker-appearance-zoom125.html [ Failure Pass ]
crbug.com/681468 fast/forms/suggestion-picker/date-suggestion-picker-appearance-zoom200.html [ Failure Pass ]

crbug.com/716320 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/broadcastchannel-success-and-failure.html [ Timeout ]
crbug.com/716320 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/broadcastchannel-success.html [ Timeout ]
crbug.com/716320 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/window-messagechannel-success.html [ Timeout ]
crbug.com/716320 virtual/sharedarraybuffer/external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/window-sharedworker-failure.html [ Timeout ]

crbug.com/683800 [ Win7 Debug ] external/wpt/selection/ [ Failure Pass ]

# CQ and Rebaseline-cl for crrev.com/2626973005 does not include this
Expand Down
6 changes: 6 additions & 0 deletions third_party/WebKit/LayoutTests/VirtualTestSuites
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@
"args": ["--mse-audio-buffer-size-limit=1048576",
"--mse-video-buffer-size-limit=1048576"]
},
{
"prefix": "sharedarraybuffer",
"base": "external/wpt/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers",
"args": ["--js-flags=--harmony-sharedarraybuffer",
"--enable-blink-features=SharedArrayBuffer"]
},
{
"prefix": "sharedarraybuffer",
"base": "fast/beacon",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"testSendFloat32Array",
"testSendFloat64Array",
"testSendSharedArrayBufferTwice",
"testTransferArrayBufferAndSharedArrayBuffer"
"testTransferArrayBufferAndSharedArrayBuffer",
"testSharedArrayBufferInTransferListViaMessagePort",
];
var testIndex = 0;

Expand Down Expand Up @@ -191,6 +192,47 @@
worker.postMessage(msg);
}

function testSharedArrayBufferInTransferListViaMessagePort() {
var ab1 = new ArrayBuffer(4);
var ab2 = new ArrayBuffer(4);
var sab1 = new SharedArrayBuffer(16);
var sab2 = new SharedArrayBuffer(16);
var msg = {
name : 'SharedArrayBufferInTransferListViaMessagePort',
ab1: ab1,
ab2: ab2,
sab1: sab1,
sab2: sab2,
};

var channel = new MessageChannel();

channel.port2.onmessage = function() {
log("FAIL: Message should not be sent.");
};

log("Running SharedArrayBufferInTransferListViaMessagePort test case");

try {
channel.port1.postMessage(msg, [ab1, sab1, ab2, sab2]);
log("FAIL: Passing SharedArrayBuffer in the transfer list did not throw.");
} catch (e) {
log("PASS: Passing SharedArrayBuffer in the transfer list threw.");
}

if (ab1.byteLength === 0)
log("FAIL: ArrayBuffer 'ab1' was neutered.");
else
log("PASS: ArrayBuffer 'ab1' was not neutered.");

if (ab2.byteLength === 0)
log("FAIL: ArrayBuffer 'ab2' was neutered.");
else
log("PASS: ArrayBuffer 'ab2' was not neutered.");

runNextTest();
}

if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This suite runs the tests in with --js-flags=--harmony-sharedarraybuffer
# This enables the SharedArrayBuffer language feature in V8.
# See https://github.com/tc39/ecmascript_sharedmem for more information.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This is a testharness.js-based test.
PASS postMessaging to this window does not give back the same SharedArrayBuffer (but does use the same backing block)
PASS postMessaging to a worker and back does not give back the same SharedArrayBuffer
PASS postMessaging to an iframe and back does not give back the same SharedArrayBuffer
Harness: the test ran to completion.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This is a testharness.js-based test.
PASS Trying to transfer a SharedArrayBuffer to this window throws
PASS Trying to transfer a SharedArrayBuffer to a worker throws
PASS Trying to transfer a SharedArrayBuffer through a MessagePort throws
Harness: the test ran to completion.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
This is a testharness.js-based test.
FAIL history.pushState(): simple case assert_throws: function "() => {
history[method](new SharedArrayBuffer(), "dummy title");
}" did not throw
FAIL history.pushState(): is interleaved correctly assert_throws: function "() => {
history[method]([
{ get x() { getter1Called = true; return 5; } },
new SharedArrayBuffer(),
{ get x() { getter2Called = true; return 5; } }
], "dummy title");
}" did not throw
FAIL history.replaceState(): simple case assert_throws: function "() => {
history[method](new SharedArrayBuffer(), "dummy title");
}" did not throw
FAIL history.replaceState(): is interleaved correctly assert_throws: function "() => {
history[method]([
{ get x() { getter1Called = true; return 5; } },
new SharedArrayBuffer(),
{ get x() { getter2Called = true; return 5; } }
], "dummy title");
}" did not throw
Harness: the test ran to completion.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is a testharness.js-based test.
PASS postMessaging to a same-origin-domain (but not same-origin) iframe allows them to see each others' modifications
Harness: the test ran to completion.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is a testharness.js-based test.
FAIL SharedArrayBuffer cannot cross agent clusters, service worker edition assert_unreached: Got an unexpected message from the service worker: worker onmessage was reached when in state "we are expecting a messageerror due to the window sending us a SAB" and data null Reached unreachable code
Harness: the test ran to completion.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is a testharness.js-based test.
PASS postMessaging to a not same-origin-domain, but similar origin, iframe allows them to see each others' modifications
Harness: the test ran to completion.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This is a testharness.js-based test.
PASS postMessaging to a dedicated worker allows them to see each others' modifications with DataView
PASS postMessaging to a dedicated worker allows them to see each others' modifications with Int8Array
PASS postMessaging to a dedicated worker allows them to see each others' modifications with Uint8Array
PASS postMessaging to a dedicated worker allows them to see each others' modifications with Uint8ClampedArray
PASS postMessaging to a dedicated worker allows them to see each others' modifications with Int16Array
PASS postMessaging to a dedicated worker allows them to see each others' modifications with Uint16Array
PASS postMessaging to a dedicated worker allows them to see each others' modifications with Int32Array
PASS postMessaging to a dedicated worker allows them to see each others' modifications with Uint32Array
PASS postMessaging to a dedicated worker allows them to see each others' modifications with Float32Array
PASS postMessaging to a dedicated worker allows them to see each others' modifications with Float64Array
PASS postMessaging to a same-origin iframe allows them to see each others' modifications
PASS postMessaging to a same-origin deeply-nested iframe allows them to see each others' modifications
PASS postMessaging to a same-origin opened window allows them to see each others' modifications
Harness: the test ran to completion.

Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,9 @@ Running TransferArrayBufferAndSharedArrayBuffer test case
PASS: ArrayBuffer was neutered during transfer.
PASS: Transferred data is OK.
PASS: Transferred data is OK.
Running SharedArrayBufferInTransferListViaMessagePort test case
PASS: Passing SharedArrayBuffer in the transfer list threw.
PASS: ArrayBuffer 'ab1' was not neutered.
PASS: ArrayBuffer 'ab2' was not neutered.
DONE

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "bindings/core/v8/serialization/SerializedScriptValue.h"

#include <algorithm>
#include <memory>
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/IDLTypes.h"
Expand Down Expand Up @@ -443,6 +444,25 @@ bool SerializedScriptValue::ExtractTransferables(
return true;
}

ArrayBufferArray SerializedScriptValue::ExtractNonSharedArrayBuffers(
Transferables& transferables) {
ArrayBufferArray& array_buffers = transferables.array_buffers;
ArrayBufferArray result;
// Partition array_buffers into [shared..., non_shared...], maintaining
// relative ordering of elements with the same predicate value.
auto non_shared_begin =
std::stable_partition(array_buffers.begin(), array_buffers.end(),
[](Member<DOMArrayBufferBase>& array_buffer) {
return array_buffer->IsShared();
});
// Copy the non-shared array buffers into result, and remove them from
// array_buffers.
result.AppendRange(non_shared_begin, array_buffers.end());
array_buffers.erase(non_shared_begin - array_buffers.begin(),
array_buffers.end() - non_shared_begin);
return result;
}

std::unique_ptr<SerializedScriptValue::ArrayBufferContentsArray>
SerializedScriptValue::TransferArrayBufferContents(
v8::Isolate* isolate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class CORE_EXPORT SerializedScriptValue
Transferables&,
ExceptionState&);

static ArrayBufferArray ExtractNonSharedArrayBuffers(Transferables&);

// Helper function which pulls ArrayBufferContents out of an ArrayBufferArray
// and neuters the ArrayBufferArray. Returns nullptr if there is an
// exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,7 @@ static void postMessageImpl(const char* interfaceName, {{cpp_class}}* instance,
// Clear references to array buffers and image bitmaps from transferables
// so that the serializer can consider the array buffers as
// non-transferable and serialize them into the message.
ArrayBufferArray transferableArrayBuffers = transferables.array_buffers;
transferables.array_buffers.clear();
ArrayBufferArray transferableArrayBuffers = SerializedScriptValue::ExtractNonSharedArrayBuffers(transferables);
ImageBitmapArray transferableImageBitmaps = transferables.image_bitmaps;
transferables.image_bitmaps.clear();
SerializedScriptValue::SerializeOptions options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8303,8 +8303,7 @@ static void postMessageImpl(const char* interfaceName, TestObject* instance, con
// Clear references to array buffers and image bitmaps from transferables
// so that the serializer can consider the array buffers as
// non-transferable and serialize them into the message.
ArrayBufferArray transferableArrayBuffers = transferables.array_buffers;
transferables.array_buffers.clear();
ArrayBufferArray transferableArrayBuffers = SerializedScriptValue::ExtractNonSharedArrayBuffers(transferables);
ImageBitmapArray transferableImageBitmaps = transferables.image_bitmaps;
transferables.image_bitmaps.clear();
SerializedScriptValue::SerializeOptions options;
Expand Down

0 comments on commit 43a78b9

Please sign in to comment.