Skip to content

Commit 91814e1

Browse files
committed
fix:update imports
1 parent c590b96 commit 91814e1

11 files changed

+275
-714
lines changed

pkg/csp_nonce_html_transformer.d.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,72 @@ export class HTMLRewriter {
2525
write(chunk: Uint8Array): void;
2626
end(): void;
2727
}
28+
29+
export type InitInput =
30+
| RequestInfo
31+
| URL
32+
| Response
33+
| BufferSource
34+
| WebAssembly.Module;
35+
36+
export interface InitOutput {
37+
readonly memory: WebAssembly.Memory;
38+
readonly __wbg_element_free: (a: number, b: number) => void;
39+
readonly element_setAttribute: (
40+
a: number,
41+
b: number,
42+
c: number,
43+
d: number,
44+
e: number,
45+
) => Array;
46+
readonly __wbg_htmlrewriter_free: (a: number, b: number) => void;
47+
readonly htmlrewriter_new: (a: number) => number;
48+
readonly htmlrewriter_on: (
49+
a: number,
50+
b: number,
51+
c: number,
52+
d: number,
53+
) => Array;
54+
readonly htmlrewriter_write: (a: number, b: number, c: number) => Array;
55+
readonly htmlrewriter_end: (a: number) => Array;
56+
readonly __wbindgen_malloc: (a: number, b: number) => number;
57+
readonly __wbindgen_realloc: (
58+
a: number,
59+
b: number,
60+
c: number,
61+
d: number,
62+
) => number;
63+
readonly __wbindgen_export_2: WebAssembly.Table;
64+
readonly __externref_table_dealloc: (a: number) => void;
65+
readonly __externref_table_alloc: () => number;
66+
readonly __wbindgen_exn_store: (a: number) => void;
67+
readonly __wbindgen_start: () => void;
68+
}
69+
70+
export type SyncInitInput = BufferSource | WebAssembly.Module;
71+
/**
72+
* Instantiates the given `module`, which can either be bytes or
73+
* a precompiled `WebAssembly.Module`.
74+
*
75+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
76+
*
77+
* @returns {InitOutput}
78+
*/
79+
export function initSync(
80+
module: { module: SyncInitInput } | SyncInitInput,
81+
): InitOutput;
82+
83+
/**
84+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
85+
* for everything else, calls `WebAssembly.instantiate` directly.
86+
*
87+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
88+
*
89+
* @returns {Promise<InitOutput>}
90+
*/
91+
export default function __wbg_init(
92+
module_or_path?:
93+
| { module_or_path: InitInput | Promise<InitInput> }
94+
| InitInput
95+
| Promise<InitInput>,
96+
): Promise<InitOutput>;

pkg/csp_nonce_html_transformer.js

Lines changed: 188 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
let wasm;
2+
13
const cachedTextDecoder = typeof TextDecoder !== "undefined"
24
? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true })
35
: {
@@ -101,9 +103,18 @@ const cachedTextEncoder = typeof TextEncoder !== "undefined"
101103
},
102104
};
103105

104-
const encodeString = function (arg, view) {
105-
return cachedTextEncoder.encodeInto(arg, view);
106-
};
106+
const encodeString = typeof cachedTextEncoder.encodeInto === "function"
107+
? function (arg, view) {
108+
return cachedTextEncoder.encodeInto(arg, view);
109+
}
110+
: function (arg, view) {
111+
const buf = cachedTextEncoder.encode(arg);
112+
view.set(buf);
113+
return {
114+
read: arg.length,
115+
written: buf.length,
116+
};
117+
};
107118

108119
function passStringToWasm0(arg, malloc, realloc) {
109120
if (realloc === undefined) {
@@ -305,93 +316,182 @@ export class HTMLRewriter {
305316
}
306317
}
307318

308-
const imports = {
309-
__wbindgen_placeholder__: {
310-
__wbindgen_string_new: function (arg0, arg1) {
311-
const ret = getStringFromWasm0(arg0, arg1);
312-
return ret;
313-
},
314-
__wbg_element_9f7a29ae173a1783: function (arg0) {
315-
const ret = arg0.element;
316-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
317-
},
318-
__wbg_element_new: function (arg0) {
319-
const ret = Element.__wrap(arg0);
320-
return ret;
321-
},
322-
__wbg_call_3bfa248576352471: function () {
323-
return handleError(function (arg0, arg1, arg2) {
324-
const ret = arg0.call(arg1, arg2);
325-
return ret;
326-
}, arguments);
327-
},
328-
__wbg_new_9a7e38dd635a4e93: function (arg0, arg1) {
329-
const ret = new TypeError(getStringFromWasm0(arg0, arg1));
330-
return ret;
331-
},
332-
__wbg_buffer_ccaed51a635d8a2d: function (arg0) {
333-
const ret = arg0.buffer;
334-
return ret;
335-
},
336-
__wbg_newwithbyteoffsetandlength_7e3eb787208af730: function (
337-
arg0,
338-
arg1,
339-
arg2,
340-
) {
341-
const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
342-
return ret;
343-
},
344-
__wbg_new_fec2611eb9180f95: function (arg0) {
345-
const ret = new Uint8Array(arg0);
319+
async function __wbg_load(module, imports) {
320+
if (typeof Response === "function" && module instanceof Response) {
321+
if (typeof WebAssembly.instantiateStreaming === "function") {
322+
try {
323+
return await WebAssembly.instantiateStreaming(module, imports);
324+
} catch (e) {
325+
if (module.headers.get("Content-Type") != "application/wasm") {
326+
console.warn(
327+
"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",
328+
e,
329+
);
330+
} else {
331+
throw e;
332+
}
333+
}
334+
}
335+
336+
const bytes = await module.arrayBuffer();
337+
return await WebAssembly.instantiate(bytes, imports);
338+
} else {
339+
const instance = await WebAssembly.instantiate(module, imports);
340+
341+
if (instance instanceof WebAssembly.Instance) {
342+
return { instance, module };
343+
} else {
344+
return instance;
345+
}
346+
}
347+
}
348+
349+
function __wbg_get_imports() {
350+
const imports = {};
351+
imports.wbg = {};
352+
imports.wbg.__wbindgen_string_new = function (arg0, arg1) {
353+
const ret = getStringFromWasm0(arg0, arg1);
354+
return ret;
355+
};
356+
imports.wbg.__wbg_element_9f7a29ae173a1783 = function (arg0) {
357+
const ret = arg0.element;
358+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
359+
};
360+
imports.wbg.__wbg_element_new = function (arg0) {
361+
const ret = Element.__wrap(arg0);
362+
return ret;
363+
};
364+
imports.wbg.__wbg_call_3bfa248576352471 = function () {
365+
return handleError(function (arg0, arg1, arg2) {
366+
const ret = arg0.call(arg1, arg2);
346367
return ret;
347-
},
348-
__wbindgen_debug_string: function (arg0, arg1) {
349-
const ret = debugString(arg1);
350-
const ptr1 = passStringToWasm0(
351-
ret,
352-
wasm.__wbindgen_malloc,
353-
wasm.__wbindgen_realloc,
368+
}, arguments);
369+
};
370+
imports.wbg.__wbg_new_9a7e38dd635a4e93 = function (arg0, arg1) {
371+
const ret = new TypeError(getStringFromWasm0(arg0, arg1));
372+
return ret;
373+
};
374+
imports.wbg.__wbg_buffer_ccaed51a635d8a2d = function (arg0) {
375+
const ret = arg0.buffer;
376+
return ret;
377+
};
378+
imports.wbg.__wbg_newwithbyteoffsetandlength_7e3eb787208af730 = function (
379+
arg0,
380+
arg1,
381+
arg2,
382+
) {
383+
const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
384+
return ret;
385+
};
386+
imports.wbg.__wbg_new_fec2611eb9180f95 = function (arg0) {
387+
const ret = new Uint8Array(arg0);
388+
return ret;
389+
};
390+
imports.wbg.__wbindgen_debug_string = function (arg0, arg1) {
391+
const ret = debugString(arg1);
392+
const ptr1 = passStringToWasm0(
393+
ret,
394+
wasm.__wbindgen_malloc,
395+
wasm.__wbindgen_realloc,
396+
);
397+
const len1 = WASM_VECTOR_LEN;
398+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
399+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
400+
};
401+
imports.wbg.__wbindgen_throw = function (arg0, arg1) {
402+
throw new Error(getStringFromWasm0(arg0, arg1));
403+
};
404+
imports.wbg.__wbindgen_memory = function () {
405+
const ret = wasm.memory;
406+
return ret;
407+
};
408+
imports.wbg.__wbindgen_init_externref_table = function () {
409+
const table = wasm.__wbindgen_export_2;
410+
const offset = table.grow(4);
411+
table.set(0, undefined);
412+
table.set(offset + 0, undefined);
413+
table.set(offset + 1, null);
414+
table.set(offset + 2, true);
415+
table.set(offset + 3, false);
416+
};
417+
418+
return imports;
419+
}
420+
421+
function __wbg_init_memory(imports, memory) {
422+
}
423+
424+
function __wbg_finalize_init(instance, module) {
425+
wasm = instance.exports;
426+
__wbg_init.__wbindgen_wasm_module = module;
427+
cachedDataViewMemory0 = null;
428+
cachedUint8ArrayMemory0 = null;
429+
430+
wasm.__wbindgen_start();
431+
return wasm;
432+
}
433+
434+
function initSync(module) {
435+
if (wasm !== undefined) return wasm;
436+
437+
if (typeof module !== "undefined") {
438+
if (Object.getPrototypeOf(module) === Object.prototype) {
439+
({ module } = module);
440+
} else {
441+
console.warn(
442+
"using deprecated parameters for `initSync()`; pass a single object instead",
354443
);
355-
const len1 = WASM_VECTOR_LEN;
356-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
357-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
358-
},
359-
__wbindgen_throw: function (arg0, arg1) {
360-
throw new Error(getStringFromWasm0(arg0, arg1));
361-
},
362-
__wbindgen_memory: function () {
363-
const ret = wasm.memory;
364-
return ret;
365-
},
366-
__wbindgen_init_externref_table: function () {
367-
const table = wasm.__wbindgen_export_2;
368-
const offset = table.grow(4);
369-
table.set(0, undefined);
370-
table.set(offset + 0, undefined);
371-
table.set(offset + 1, null);
372-
table.set(offset + 2, true);
373-
table.set(offset + 3, false);
374-
},
375-
},
376-
};
377-
378-
const wasm_url = new URL("csp_nonce_html_transformer_bg.wasm", import.meta.url);
379-
let wasmCode = "";
380-
switch (wasm_url.protocol) {
381-
case "file:":
382-
wasmCode = await Deno.readFile(wasm_url);
383-
break;
384-
case "https:":
385-
case "http:":
386-
wasmCode = await (await fetch(wasm_url)).arrayBuffer();
387-
break;
388-
default:
389-
throw new Error(`Unsupported protocol: ${wasm_url.protocol}`);
444+
}
445+
}
446+
447+
const imports = __wbg_get_imports();
448+
449+
__wbg_init_memory(imports);
450+
451+
if (!(module instanceof WebAssembly.Module)) {
452+
module = new WebAssembly.Module(module);
453+
}
454+
455+
const instance = new WebAssembly.Instance(module, imports);
456+
457+
return __wbg_finalize_init(instance, module);
390458
}
391459

392-
const wasmInstance =
393-
(await WebAssembly.instantiate(wasmCode, imports)).instance;
394-
const wasm = wasmInstance.exports;
395-
export const __wasm = wasm;
460+
async function __wbg_init(module_or_path) {
461+
if (wasm !== undefined) return wasm;
462+
463+
if (typeof module_or_path !== "undefined") {
464+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
465+
({ module_or_path } = module_or_path);
466+
} else {
467+
console.warn(
468+
"using deprecated parameters for the initialization function; pass a single object instead",
469+
);
470+
}
471+
}
472+
473+
if (typeof module_or_path === "undefined") {
474+
module_or_path = new URL(
475+
"csp_nonce_html_transformer_bg.wasm",
476+
import.meta.url,
477+
);
478+
}
479+
const imports = __wbg_get_imports();
480+
481+
if (
482+
typeof module_or_path === "string" ||
483+
(typeof Request === "function" && module_or_path instanceof Request) ||
484+
(typeof URL === "function" && module_or_path instanceof URL)
485+
) {
486+
module_or_path = fetch(module_or_path);
487+
}
488+
489+
__wbg_init_memory(imports);
490+
491+
const { instance, module } = await __wbg_load(await module_or_path, imports);
492+
493+
return __wbg_finalize_init(instance, module);
494+
}
396495

397-
wasm.__wbindgen_start();
496+
export { initSync };
497+
export default __wbg_init;
-252 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)