Fix Wasm limit and Safari instantiation (#1857)

test and fix wasm 4KB limit, as well as fixing Safari instantiation
This commit is contained in:
Guy Bedford 2018-10-06 22:09:11 +02:00 committed by GitHub
parent 989a04f1c0
commit cb25b39f57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -12,7 +12,14 @@ systemJSPrototype.instantiate = function (url, parent) {
.then(function (res) {
if (!res.ok)
throw new Error(res.status + ' ' + res.statusText + ' ' + res.url + (parent ? ' loading from ' + parent : ''));
return WebAssembly.compileStreaming(res);
if (WebAssembly.compileStreaming)
return WebAssembly.compileStreaming(res);
return res.arrayBuffer()
.then(function (buf) {
return WebAssembly.compile(buf);
});
})
.then(function (module) {
const deps = [];
@ -34,7 +41,10 @@ systemJSPrototype.instantiate = function (url, parent) {
return {
setters: setters,
execute: function () {
_export(new WebAssembly.Instance(module, importObj).exports);
return WebAssembly.instantiate(module, importObj)
.then(function (instance) {
_export(instance.exports);
});
}
};
}];

View File

@ -125,4 +125,12 @@ suite('SystemJS Standard Tests', function() {
assert.equal(m.exampleExport(1), 2);
});
});
if (typeof WebAssembly !== 'undefined' && typeof process === 'undefined')
test('Loading WASM over 4KB limit', function () {
return System.import('fixtures/wasm/addbloated.wasm')
.then(function (m) {
assert.equal(m.addTwo(1, 1), 2);
});
});
});

Binary file not shown.