source: trip-planner-front/node_modules/webpack/lib/wasm-async/AsyncWasmChunkLoadingRuntimeModule.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const RuntimeGlobals = require("../RuntimeGlobals");
9const RuntimeModule = require("../RuntimeModule");
10const Template = require("../Template");
11
12class AsyncWasmChunkLoadingRuntimeModule extends RuntimeModule {
13 constructor({ generateLoadBinaryCode, supportsStreaming }) {
14 super("wasm chunk loading", RuntimeModule.STAGE_ATTACH);
15 this.generateLoadBinaryCode = generateLoadBinaryCode;
16 this.supportsStreaming = supportsStreaming;
17 }
18
19 /**
20 * @returns {string} runtime code
21 */
22 generate() {
23 const { compilation, chunk } = this;
24 const { outputOptions, runtimeTemplate } = compilation;
25 const fn = RuntimeGlobals.instantiateWasm;
26 const wasmModuleSrcPath = compilation.getPath(
27 JSON.stringify(outputOptions.webassemblyModuleFilename),
28 {
29 hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
30 hashWithLength: length =>
31 `" + ${RuntimeGlobals.getFullHash}}().slice(0, ${length}) + "`,
32 module: {
33 id: '" + wasmModuleId + "',
34 hash: `" + wasmModuleHash + "`,
35 hashWithLength(length) {
36 return `" + wasmModuleHash.slice(0, ${length}) + "`;
37 }
38 },
39 runtime: chunk.runtime
40 }
41 );
42 return `${fn} = ${runtimeTemplate.basicFunction(
43 "exports, wasmModuleId, wasmModuleHash, importsObj",
44 [
45 `var req = ${this.generateLoadBinaryCode(wasmModuleSrcPath)};`,
46 this.supportsStreaming
47 ? Template.asString([
48 "if (typeof WebAssembly.instantiateStreaming === 'function') {",
49 Template.indent([
50 "return WebAssembly.instantiateStreaming(req, importsObj)",
51 Template.indent([
52 `.then(${runtimeTemplate.returningFunction(
53 "Object.assign(exports, res.instance.exports)",
54 "res"
55 )});`
56 ])
57 ]),
58 "}"
59 ])
60 : "// no support for streaming compilation",
61 "return req",
62 Template.indent([
63 `.then(${runtimeTemplate.returningFunction("x.arrayBuffer()", "x")})`,
64 `.then(${runtimeTemplate.returningFunction(
65 "WebAssembly.instantiate(bytes, importsObj)",
66 "bytes"
67 )})`,
68 `.then(${runtimeTemplate.returningFunction(
69 "Object.assign(exports, res.instance.exports)",
70 "res"
71 )});`
72 ])
73 ]
74 )};`;
75 }
76}
77
78module.exports = AsyncWasmChunkLoadingRuntimeModule;
Note: See TracBrowser for help on using the repository browser.