Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/wasm/wasm_serialization_tests.js

Issue 2405153003: [wasm] support for recompilation if deserialization fails (Closed)
Patch Set: uncompiled->wire Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 function instantiateInWorker() { 5 function TestInstantiateInWorker() {
6 // the file incrementer.wasm is copied from 6 return createWasmModule()
7 // //v8/test/mjsunit/wasm. This is because currently we cannot 7 .then((mod) => {
8 // reference files outside the LayoutTests folder. When wasm format
9 // changes require that file to be updated, there is a test on the
10 // v8 side (same folder), ensure-wasm-binaries-up-to-date.js, which
11 // fails and will require incrementer.wasm to be updated on that side.
12 return fetch('incrementer.wasm')
13 .then(response => {
14 if (!response.ok) throw new Error(response.statusText);
15 return response.arrayBuffer();
16 })
17 .then(data => {
18 var mod = new WebAssembly.Module(data);
19 var worker = new Worker("wasm_serialization_worker.js"); 8 var worker = new Worker("wasm_serialization_worker.js");
20 return new Promise((resolve, reject) => { 9 return new Promise((resolve, reject) => {
21 worker.postMessage(mod); 10 worker.postMessage(mod);
22 worker.onmessage = function(event) { 11 worker.onmessage = function(event) {
23 resolve(event.data); 12 resolve(event.data);
24 } 13 }
25 }); 14 });
26 }) 15 })
27 .then(data => assert_equals(data, 43)) 16 .then(data => assert_equals(data, 43))
28 .catch(error => assert_unreached(error)); 17 .catch(error => assert_unreached(error));
29 } 18 }
19
20 function ascii(a) { return a.charCodeAt(0); }
21
22 function findStartOfWasmHeader(byteView) {
23 for (var i = 0; i < byteView.length - 2; ++i) {
24 if (byteView[i] === ascii('a') &&
25 byteView[i+1] === ascii('s') &&
26 byteView[i+2] === ascii('m')) {
27 return i;
28 }
29 }
30 return -1;
31 }
32
33 function TestIncompatibleDowngrade() {
34 return createWasmModule()
35 .then((mod) => {
36 var buffer = window.internals.serializeObject(mod);
37 var byteView = new Uint8Array(buffer);
38 // The serialized payload starts with some serialization header, followed
39 // by the wasm wire bytes. Those should start with the characters
40 // 'a' 's' 'm'.
41 // Find the start of that sequence and invalidate the wire bytes by
42 // clearing the first byte.
43 var startOfWasmHeader = findStartOfWasmHeader(byteView);
44 assert_greater_than(startOfWasmHeader, 0,
45 "The wire format should contain a wasm header.");
46 byteView[startOfWasmHeader] = 0;
47 // Also invalidate the serialized blob. That follows the wire bytes.
48 // Start from the end and clear the first non-null byte.
49 var invalidalidated = false;
50 for (var i = byteView.length - 1; i >= startOfWasmHeader + 3; --i) {
51 if (byteView[i] != 0) {
52 byteView[i] = 0;
53 invalidated = true;
54 break;
55 }
56 }
57 assert_true(invalidated,
58 "the serialized blob should contain some non-null bytes.");
59
60 var deserialized = undefined;
61 try {
62 deserialized = window.internals.deserializeBuffer(byteView.buffer);
63 assert_unreached();
64 } catch (e) {
65 assert_equals(deserialized, undefined);
66 }
67 });
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698