Commit b2a81802 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[v8][wasm] Throw TypeError if Response status is not ok

The WebAssembly spec [1] requires that a TypeError is thrown if the
status of the Response input of streaming compilation is not ok.

I added layout tests for this, and cleaned up the surrounding tests a
bit.


[1] https://github.com/WebAssembly/design/blob/master/Web.md#webassemblycompilestreaming

R=mlippautz@chromium.org, mathias@chromium.org

also-by: mathias@chromium.org
Bug: chromium:832552
Change-Id: Icd50e537ab659662708274a96959eb94d7fbc554
Reviewed-on: https://chromium-review.googlesource.com/1012035Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551269}
parent 2c38c289
......@@ -4,15 +4,7 @@
if (isset($_GET['name'])) {
$fileName = $_GET['name'];
}
$fileSize = filesize($fileName);
header("Content-Type: " . "application/wasm");
$fn = fopen($fileName, "rb");
$buffer = fread($fn, $fileSize);
print($buffer);
flush();
fclose($fn);
exit;
header("Content-Type: application/wasm");
require($fileName);
?>
......@@ -6,6 +6,9 @@
<script src="../wasm/resources/wasm-module-builder.js"></script>
<script>
promise_test(TestStreamedCompile, "test compileStreaming");
promise_test(TestCompileOkStatusIsChecked, "test HTTP status is verified (compileStreaming)");
promise_test(TestInstantiateOkStatusIsChecked, "test HTTP status is verified (instantiateStreaming)");
promise_test(TestCompileMimeTypeIsChecked, "test MIME type is verified (compileStreaming)");
promise_test(TestInstantiateMimeTypeIsChecked, "test MIME type is verified (instantiateStreaming)");
promise_test(TestShortFormStreamedCompile, "test compileStreaming with promise parameter");
......
......@@ -3,7 +3,8 @@
// found in the LICENSE file.
const incrementer_url = '../wasm/resources/load-wasm.php';
const invalid_wasm_url = '../wasm/resources/load-wasm.php?name=invalid-wasm.wasm'
const not_available_url = '../wasm/resources/not-available.php';
const invalid_wasm_url = '../wasm/resources/load-wasm.php?name=invalid-wasm.wasm';
function AssertType(obj, type) {
assert_equals(obj.constructor, type);
......@@ -24,6 +25,20 @@ function TestStreamedCompile() {
.then(i => assert_equals(5, i.exports.increment(4)));
}
function TestCompileOkStatusIsChecked() {
return fetch(not_available_url)
.then(WebAssembly.compileStreaming)
.then(assert_unreached,
AssertTypeError);
}
function TestInstantiateOkStatusIsChecked() {
return fetch(not_available_url)
.then(WebAssembly.instantiateStreaming)
.then(assert_unreached,
AssertTypeError);
}
function TestCompileMimeTypeIsChecked() {
return fetch('../wasm/resources/incrementer.wasm')
.then(WebAssembly.compileStreaming)
......
......@@ -160,6 +160,11 @@ void CompileFromResponseCallback(
return;
}
if (!response->ok()) {
exception_state.ThrowTypeError("HTTP status code is not ok");
return;
}
if (response->MimeType() != "application/wasm") {
exception_state.ThrowTypeError(
"Incorrect response MIME type. Expected 'application/wasm'.");
......
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