Skip to content

Commit

Permalink
XHR/CSS/Compression: use Wasm to get at a SharedArrayBuffer instance
Browse files Browse the repository at this point in the history
For #22358.
  • Loading branch information
annevk authored Mar 24, 2020
1 parent a9b1735 commit c8d8f8e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
6 changes: 4 additions & 2 deletions compression/compression-bad-chunks.tentative.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ const badChunks = [
// Use a getter to postpone construction so that all tests don't fail where
// SharedArrayBuffer is not yet implemented.
get value() {
return new SharedArrayBuffer();
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
return new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;
}
},
{
name: 'shared Uint8Array',
get value() {
return new Uint8Array(new SharedArrayBuffer())
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
return new Uint8Array(new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer)
}
},
];
Expand Down
6 changes: 4 additions & 2 deletions compression/decompression-bad-chunks.tentative.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ const badChunks = [
// Use a getter to postpone construction so that all tests don't fail where
// SharedArrayBuffer is not yet implemented.
get value() {
return new SharedArrayBuffer();
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
return new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;
}
},
{
name: 'shared Uint8Array',
get value() {
return new Uint8Array(new SharedArrayBuffer())
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
return new Uint8Array(new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer)
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion css/css-layout-api/constraints-data-sab-failure.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@

try {
childFragment = await child.layoutNextFragment({
data: { sab: new SharedArrayBuffer(4) }
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
data: { sab: new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer }
});
} catch(e) {
// Success! The structured cloning algorithm should have thrown an error.
Expand Down
3 changes: 2 additions & 1 deletion css/css-layout-api/fragment-data-sab-failure.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
async layout(children, edges, constraints, styleMap) {
const childFragments = await Promise.all(children.map(child => child.layoutNextFragment()));

return {autoBlockSize: 0, childFragments, data: {sab: new SharedArrayBuffer(4) }};
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
return {autoBlockSize: 0, childFragments, data: {sab: new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer }};
}
});
</script>
Expand Down
10 changes: 6 additions & 4 deletions xhr/send-data-sharedarraybuffer.any.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// META: title=XMLHttpRequest.send(sharedarraybuffer)

test(() => {
var xhr = new XMLHttpRequest();
var buf = new SharedArrayBuffer();
const xhr = new XMLHttpRequest();
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const buf = new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer;

xhr.open("POST", "./resources/content.py", true);
assert_throws_js(TypeError, function() {
Expand All @@ -13,8 +14,9 @@ test(() => {
["Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array",
"Int32Array", "Uint32Array", "Float32Array", "Float64Array", "DataView"].forEach((type) => {
test(() => {
var xhr = new XMLHttpRequest();
var arr = new self[type](new SharedArrayBuffer());
const xhr = new XMLHttpRequest();
// See https://github.com/whatwg/html/issues/5380 for why not `new SharedArrayBuffer()`
const arr = new self[type](new WebAssembly.Memory({ shared:true, initial:1, maximum:1 }).buffer);

xhr.open("POST", "./resources/content.py", true);
assert_throws_js(TypeError, function() {
Expand Down

0 comments on commit c8d8f8e

Please sign in to comment.