OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 |
| 6 function TestStreamedCompile() { |
| 7 return fetch('incrementer.wasm') |
| 8 .then(WebAssembly.compile) |
| 9 .then(m => new WebAssembly.Instance(m)) |
| 10 .then(i => assert_equals(5, i.exports.increment(4))); |
| 11 } |
| 12 |
| 13 function TestShortFormStreamedCompile() { |
| 14 return WebAssembly.compile(fetch('incrementer.wasm')) |
| 15 .then(m => new WebAssembly.Instance(m)) |
| 16 .then(i => assert_equals(5, i.exports.increment(4))); |
| 17 } |
| 18 |
| 19 function NegativeTestStreamedCompilePromise() { |
| 20 return WebAssembly.compile(new Promise((resolve, reject)=>{resolve(5);})) |
| 21 .then(assert_unreached, |
| 22 e => assert_true(e instanceof TypeError)); |
| 23 } |
| 24 |
| 25 function BlankResponse() { |
| 26 return WebAssembly.compile(new Response()) |
| 27 .then(assert_unreached, |
| 28 e => assert_true(e instanceof TypeError)); |
| 29 } |
| 30 |
| 31 function FromArrayBuffer() { |
| 32 return fetch('incrementer.wasm') |
| 33 .then(r => r.arrayBuffer()) |
| 34 .then(arr => new Response(arr)) |
| 35 .then(WebAssembly.compile) |
| 36 .then(m => new WebAssembly.Instance(m)) |
| 37 .then(i => assert_equals(6, i.exports.increment(5))); |
| 38 } |
| 39 |
| 40 function FromInvalidArrayBuffer() { |
| 41 var arr = new ArrayBuffer(10); |
| 42 var view = new Uint8Array(arr); |
| 43 for (var i = 0; i < view.length; ++i) view[i] = i; |
| 44 |
| 45 return WebAssembly.compile(new Response(arr)) |
| 46 .then(assert_unreached, |
| 47 e => assert_true(e instanceof Error)); |
| 48 } |
OLD | NEW |