Skip to content

Commit

Permalink
2 again
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeChampion committed Nov 21, 2024
1 parent 8029640 commit 20a0b24
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 91 deletions.
111 changes: 30 additions & 81 deletions pkg/csp_nonce_html_transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ const encodeString = function (arg, view) {
};

function passStringToWasm0(arg, malloc, realloc) {
if (typeof arg !== "string") {
throw new Error(`expected a string argument, found ${typeof arg}`);
}

if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
Expand Down Expand Up @@ -138,7 +134,7 @@ function passStringToWasm0(arg, malloc, realloc) {
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);
if (ret.read !== arg.length) throw new Error("failed to pass whole string");

offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
Expand All @@ -161,6 +157,12 @@ function getDataViewMemory0() {
return cachedDataViewMemory0;
}

function takeFromExternrefTable0(idx) {
const value = wasm.__wbindgen_export_2.get(idx);
wasm.__externref_table_dealloc(idx);
return value;
}

function isLikeNone(x) {
return x === undefined || x === null;
}
Expand All @@ -171,39 +173,6 @@ function addToExternrefTable0(obj) {
return idx;
}

function logError(f, args) {
try {
return f.apply(this, args);
} catch (e) {
let error = function () {
try {
return e instanceof Error
? `${e.message}\n\nStack:\n${e.stack}`
: e.toString();
} catch (_) {
return "<failed to stringify thrown value>";
}
}();
console.error(
"wasm-bindgen: imported JS function that was not marked as `catch` threw an error:",
error,
);
throw e;
}
}

function _assertNum(n) {
if (typeof n !== "number") {
throw new Error(`expected a number argument, found ${typeof n}`);
}
}

function takeFromExternrefTable0(idx) {
const value = wasm.__wbindgen_export_2.get(idx);
wasm.__externref_table_dealloc(idx);
return value;
}

function passArray8ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 1, 1) >>> 0;
getUint8ArrayMemory0().set(arg, ptr / 1);
Expand All @@ -225,10 +194,6 @@ const ElementFinalization = (typeof FinalizationRegistry === "undefined")
: new FinalizationRegistry((ptr) => wasm.__wbg_element_free(ptr >>> 0, 1));

export class Element {
constructor() {
throw new Error("cannot invoke `new` directly");
}

static __wrap(ptr) {
ptr = ptr >>> 0;
const obj = Object.create(Element.prototype);
Expand All @@ -253,8 +218,6 @@ export class Element {
* @param {string} value
*/
setAttribute(name, value) {
if (this.__wbg_ptr == 0) throw new Error("Attempt to use a moved value");
_assertNum(this.__wbg_ptr);
const ptr0 = passStringToWasm0(
name,
wasm.__wbindgen_malloc,
Expand Down Expand Up @@ -312,8 +275,6 @@ export class HTMLRewriter {
* @param {any} handlers
*/
on(selector, handlers) {
if (this.__wbg_ptr == 0) throw new Error("Attempt to use a moved value");
_assertNum(this.__wbg_ptr);
const ptr0 = passStringToWasm0(
selector,
wasm.__wbindgen_malloc,
Expand All @@ -329,8 +290,6 @@ export class HTMLRewriter {
* @param {Uint8Array} chunk
*/
write(chunk) {
if (this.__wbg_ptr == 0) throw new Error("Attempt to use a moved value");
_assertNum(this.__wbg_ptr);
const ptr0 = passArray8ToWasm0(chunk, wasm.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.htmlrewriter_write(this.__wbg_ptr, ptr0, len0);
Expand All @@ -339,8 +298,6 @@ export class HTMLRewriter {
}
}
end() {
if (this.__wbg_ptr == 0) throw new Error("Attempt to use a moved value");
_assertNum(this.__wbg_ptr);
const ret = wasm.htmlrewriter_end(this.__wbg_ptr);
if (ret[1]) {
throw takeFromExternrefTable0(ret[0]);
Expand All @@ -350,51 +307,43 @@ export class HTMLRewriter {

const imports = {
__wbindgen_placeholder__: {
__wbg_element_9f7a29ae173a1783: function () {
return logError(function (arg0) {
const ret = arg0.element;
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
}, arguments);
},
__wbindgen_string_new: function (arg0, arg1) {
const ret = getStringFromWasm0(arg0, arg1);
return ret;
},
__wbg_element_new: function () {
return logError(function (arg0) {
const ret = Element.__wrap(arg0);
return ret;
}, arguments);
__wbg_element_9f7a29ae173a1783: function (arg0) {
const ret = arg0.element;
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
},
__wbg_element_new: function (arg0) {
const ret = Element.__wrap(arg0);
return ret;
},
__wbg_call_3bfa248576352471: function () {
return handleError(function (arg0, arg1, arg2) {
const ret = arg0.call(arg1, arg2);
return ret;
}, arguments);
},
__wbg_new_9a7e38dd635a4e93: function () {
return logError(function (arg0, arg1) {
const ret = new TypeError(getStringFromWasm0(arg0, arg1));
return ret;
}, arguments);
__wbg_new_9a7e38dd635a4e93: function (arg0, arg1) {
const ret = new TypeError(getStringFromWasm0(arg0, arg1));
return ret;
},
__wbg_new_fec2611eb9180f95: function () {
return logError(function (arg0) {
const ret = new Uint8Array(arg0);
return ret;
}, arguments);
__wbg_buffer_ccaed51a635d8a2d: function (arg0) {
const ret = arg0.buffer;
return ret;
},
__wbg_newwithbyteoffsetandlength_7e3eb787208af730: function () {
return logError(function (arg0, arg1, arg2) {
const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
return ret;
}, arguments);
__wbg_newwithbyteoffsetandlength_7e3eb787208af730: function (
arg0,
arg1,
arg2,
) {
const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
return ret;
},
__wbg_buffer_ccaed51a635d8a2d: function () {
return logError(function (arg0) {
const ret = arg0.buffer;
return ret;
}, arguments);
__wbg_new_fec2611eb9180f95: function (arg0) {
const ret = new Uint8Array(arg0);
return ret;
},
__wbindgen_debug_string: function (arg0, arg1) {
const ret = debugString(arg1);
Expand Down
Binary file modified pkg/csp_nonce_html_transformer_bg.wasm
Binary file not shown.
18 changes: 9 additions & 9 deletions pkg/csp_nonce_html_transformer_bg.wasm.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function __wbg_htmlrewriter_free(a: number, b: number): void;
export function htmlrewriter_new(a: number): number;
export function htmlrewriter_on(
export function __wbg_element_free(a: number, b: number): void;
export function element_setAttribute(
a: number,
b: number,
c: number,
d: number,
e: number,
): Array;
export function htmlrewriter_write(a: number, b: number, c: number): Array;
export function htmlrewriter_end(a: number): Array;
export function __wbg_element_free(a: number, b: number): void;
export function element_setAttribute(
export function __wbg_htmlrewriter_free(a: number, b: number): void;
export function htmlrewriter_new(a: number): number;
export function htmlrewriter_on(
a: number,
b: number,
c: number,
d: number,
e: number,
): Array;
export function htmlrewriter_write(a: number, b: number, c: number): Array;
export function htmlrewriter_end(a: number): Array;
export function __wbindgen_malloc(a: number, b: number): number;
export function __wbindgen_realloc(
a: number,
Expand All @@ -27,7 +27,7 @@ export function __wbindgen_realloc(
d: number,
): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function __externref_table_alloc(): number;
export function __externref_table_dealloc(a: number): void;
export function __externref_table_alloc(): number;
export function __wbindgen_exn_store(a: number): void;
export function __wbindgen_start(): void;
Binary file modified pkg/html_rewriter_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
async function main() {
await Deno.run({
cmd: ["wasm-pack", "build", "--target", "deno", "--dev"],
cmd: ["wasm-pack", "build", "--target", "deno", "--release"],
}).status();
await Deno.remove("./pkg/.gitignore");
}
Expand Down

0 comments on commit 20a0b24

Please sign in to comment.