in benchmarks/JetStream2/wasm/HashSet.js [482:672]
function integrateWasmJS() {
var wasmTextFile = "HashSet.wast";
var wasmBinaryFile = "HashSet.wasm";
var asmjsCodeFile = "HashSet.temp.asm.js";
if (!isDataURI(wasmTextFile)) {
wasmTextFile = locateFile(wasmTextFile);
}
if (!isDataURI(wasmBinaryFile)) {
wasmBinaryFile = locateFile(wasmBinaryFile);
}
if (!isDataURI(asmjsCodeFile)) {
asmjsCodeFile = locateFile(asmjsCodeFile);
}
var wasmPageSize = 64 * 1024;
var info = {
"global": null,
"env": null,
"asm2wasm": asm2wasmImports,
"parent": Module
};
var exports = null;
function mergeMemory(newBuffer) {
var oldBuffer = Module["buffer"];
if (newBuffer.byteLength < oldBuffer.byteLength) {
err("the new buffer in mergeMemory is smaller than the previous one. in native wasm, we should grow memory here");
}
var oldView = new Int8Array(oldBuffer);
var newView = new Int8Array(newBuffer);
newView.set(oldView);
updateGlobalBuffer(newBuffer);
updateGlobalBufferViews();
}
function fixImports(imports) {
return imports;
}
function getBinary() {
try {
if (Module["wasmBinary"]) {
return new Uint8Array(Module["wasmBinary"]);
}
if (Module["readBinary"]) {
return Module["readBinary"](wasmBinaryFile);
} else {
throw "both async and sync fetching of the wasm failed";
}
} catch (err) {
abort(err);
}
}
function getBinaryPromise() {
if (!Module["wasmBinary"] && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === "function") {
return fetch(wasmBinaryFile, {
credentials: "same-origin"
}).then((function(response) {
if (!response["ok"]) {
throw "failed to load wasm binary file at '" + wasmBinaryFile + "'";
}
return response["arrayBuffer"]();
})).catch((function() {
return getBinary();
}));
}
return new Promise((function(resolve, reject) {
resolve(getBinary());
}));
}
function doNativeWasm(global, env, providedBuffer) {
if (typeof WebAssembly !== "object") {
err("no native wasm support detected");
return false;
}
if (!(Module["wasmMemory"] instanceof WebAssembly.Memory)) {
err("no native wasm Memory in use");
return false;
}
env["memory"] = Module["wasmMemory"];
info["global"] = {
"NaN": NaN,
"Infinity": Infinity
};
info["global.Math"] = Math;
info["env"] = env;
function receiveInstance(instance, module) {
exports = instance.exports;
if (exports.memory) mergeMemory(exports.memory);
Module["asm"] = exports;
Module["usingWasm"] = true;
removeRunDependency("wasm-instantiate");
}
addRunDependency("wasm-instantiate");
if (Module["instantiateWasm"]) {
try {
return Module["instantiateWasm"](info, receiveInstance);
} catch (e) {
err("Module.instantiateWasm callback failed with error: " + e);
return false;
}
}
function receiveInstantiatedSource(output) {
receiveInstance(output["instance"], output["module"]);
}
function instantiateArrayBuffer(receiver) {
getBinaryPromise().then((function(binary) {
return WebAssembly.instantiate(binary, info);
}))
.then((...args) => {
reportCompileTime(benchmarkTime() - __startupStartTime);
return Promise.resolve(...args);
})
.then(receiver).catch((function(reason) {
err("failed to asynchronously prepare wasm: " + reason);
abort(reason);
}));
}
if (!Module["wasmBinary"] && typeof WebAssembly.instantiateStreaming === "function" && !isDataURI(wasmBinaryFile) && typeof fetch === "function") {
WebAssembly.instantiateStreaming(fetch(wasmBinaryFile, {
credentials: "same-origin"
}), info).then(receiveInstantiatedSource).catch((function(reason) {
err("wasm streaming compile failed: " + reason);
err("falling back to ArrayBuffer instantiation");
instantiateArrayBuffer(receiveInstantiatedSource);
}));
} else {
instantiateArrayBuffer(receiveInstantiatedSource);
}
return {};
}
Module["asmPreload"] = Module["asm"];
var asmjsReallocBuffer = Module["reallocBuffer"];
var wasmReallocBuffer = (function(size) {
var PAGE_MULTIPLE = Module["usingWasm"] ? WASM_PAGE_SIZE : ASMJS_PAGE_SIZE;
size = alignUp(size, PAGE_MULTIPLE);
var old = Module["buffer"];
var oldSize = old.byteLength;
if (Module["usingWasm"]) {
try {
var result = Module["wasmMemory"].grow((size - oldSize) / wasmPageSize);
if (result !== (-1 | 0)) {
return Module["buffer"] = Module["wasmMemory"].buffer;
} else {
return null;
}
} catch (e) {
return null;
}
}
});
Module["reallocBuffer"] = (function(size) {
if (finalMethod === "asmjs") {
return asmjsReallocBuffer(size);
} else {
return wasmReallocBuffer(size);
}
});
var finalMethod = "";
Module["asm"] = (function(global, env, providedBuffer) {
env = fixImports(env);
if (!env["table"]) {
var TABLE_SIZE = Module["wasmTableSize"];
if (TABLE_SIZE === undefined) TABLE_SIZE = 1024;
var MAX_TABLE_SIZE = Module["wasmMaxTableSize"];
if (typeof WebAssembly === "object" && typeof WebAssembly.Table === "function") {
if (MAX_TABLE_SIZE !== undefined) {
env["table"] = new WebAssembly.Table({
"initial": TABLE_SIZE,
"maximum": MAX_TABLE_SIZE,
"element": "anyfunc"
});
} else {
env["table"] = new WebAssembly.Table({
"initial": TABLE_SIZE,
element: "anyfunc"
});
}
} else {
env["table"] = new Array(TABLE_SIZE);
}
Module["wasmTable"] = env["table"];
}
if (!env["memoryBase"]) {
env["memoryBase"] = Module["STATIC_BASE"];
}
if (!env["tableBase"]) {
env["tableBase"] = 0;
}
var exports;
exports = doNativeWasm(global, env, providedBuffer);
assert(exports, "no binaryen method succeeded.");
return exports;
});
}