|
| 1 | +let wasm; |
| 2 | + |
1 | 3 | const cachedTextDecoder = typeof TextDecoder !== "undefined" |
2 | 4 | ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) |
3 | 5 | : { |
@@ -101,9 +103,18 @@ const cachedTextEncoder = typeof TextEncoder !== "undefined" |
101 | 103 | }, |
102 | 104 | }; |
103 | 105 |
|
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 | + }; |
107 | 118 |
|
108 | 119 | function passStringToWasm0(arg, malloc, realloc) { |
109 | 120 | if (realloc === undefined) { |
@@ -305,93 +316,182 @@ export class HTMLRewriter { |
305 | 316 | } |
306 | 317 | } |
307 | 318 |
|
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); |
346 | 367 | 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", |
354 | 443 | ); |
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); |
390 | 458 | } |
391 | 459 |
|
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 | +} |
396 | 495 |
|
397 | | -wasm.__wbindgen_start(); |
| 496 | +export { initSync }; |
| 497 | +export default __wbg_init; |
0 commit comments