Skip to content

Commit

Permalink
test3
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeChampion committed Nov 21, 2024
1 parent a4ecd37 commit 08aec11
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 132 deletions.
4 changes: 0 additions & 4 deletions pkg/csp_nonce_html_transformer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ export class HTMLRewriter {
* @param {any} handlers
*/
on(selector: string, handlers: any): void;
/**
* @param {any} handlers
*/
onDocument(handlers: any): void;
/**
* @param {Uint8Array} chunk
*/
Expand Down
63 changes: 0 additions & 63 deletions pkg/csp_nonce_html_transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,6 @@ export class Doctype {
throw new Error("cannot invoke `new` directly");
}

static __wrap(ptr) {
ptr = ptr >>> 0;
const obj = Object.create(Doctype.prototype);
obj.__wbg_ptr = ptr;
DoctypeFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}

__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
Expand Down Expand Up @@ -463,14 +455,6 @@ export class DocumentEnd {
throw new Error("cannot invoke `new` directly");
}

static __wrap(ptr) {
ptr = ptr >>> 0;
const obj = Object.create(DocumentEnd.prototype);
obj.__wbg_ptr = ptr;
DocumentEndFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}

__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
Expand Down Expand Up @@ -1019,17 +1003,6 @@ export class HTMLRewriter {
throw takeFromExternrefTable0(ret[0]);
}
}
/**
* @param {any} handlers
*/
onDocument(handlers) {
if (this.__wbg_ptr == 0) throw new Error("Attempt to use a moved value");
_assertNum(this.__wbg_ptr);
const ret = wasm.htmlrewriter_onDocument(this.__wbg_ptr, handlers);
if (ret[1]) {
throw takeFromExternrefTable0(ret[0]);
}
}
/**
* @param {Uint8Array} chunk
*/
Expand Down Expand Up @@ -1238,18 +1211,6 @@ const imports = {
return ret;
}, arguments);
},
__wbg_doctype_new: function () {
return logError(function (arg0) {
const ret = Doctype.__wrap(arg0);
return ret;
}, arguments);
},
__wbg_documentend_new: function () {
return logError(function (arg0) {
const ret = DocumentEnd.__wrap(arg0);
return ret;
}, arguments);
},
__wbg_element_new: function () {
return logError(function (arg0) {
const ret = Element.__wrap(arg0);
Expand Down Expand Up @@ -1280,30 +1241,6 @@ const imports = {
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
}, arguments);
},
__wbg_doctype_51e5196c1e758077: function () {
return logError(function (arg0) {
const ret = arg0.doctype;
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
}, arguments);
},
__wbg_comments_78fee064e6b4bdd7: function () {
return logError(function (arg0) {
const ret = arg0.comments;
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
}, arguments);
},
__wbg_text_b65dd2bb2bc16a12: function () {
return logError(function (arg0) {
const ret = arg0.text;
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
}, arguments);
},
__wbg_end_c6c7e99b41918cc0: function () {
return logError(function (arg0) {
const ret = arg0.end;
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
}, arguments);
},
__wbg_String_b9412f8799faab3e: function () {
return logError(function (arg0, arg1) {
const ret = String(arg1);
Expand Down
Binary file modified pkg/csp_nonce_html_transformer_bg.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion pkg/csp_nonce_html_transformer_bg.wasm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export function htmlrewriter_on(
c: number,
d: number,
): Array;
export function htmlrewriter_onDocument(a: number, b: number): Array;
export function htmlrewriter_write(a: number, b: number, c: number): Array;
export function htmlrewriter_end(a: number): Array;
export function __wbg_endtag_free(a: number, b: number): void;
Expand Down
53 changes: 1 addition & 52 deletions src/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
use super::comment::Comment;
use super::doctype::Doctype;
use super::document_end::DocumentEnd;
use super::element::Element;
use super::text_chunk::TextChunk;
use super::*;
use js_sys::Function as JsFunction;
use lol_html::{
DocumentContentHandlers as NativeDocumentContentHandlers,
ElementContentHandlers as NativeElementContentHandlers,
};
use lol_html::ElementContentHandlers as NativeElementContentHandlers;
use std::mem;
use std::rc::Rc;
use thiserror::Error;
Expand Down Expand Up @@ -84,49 +79,3 @@ impl IntoNativeHandlers<NativeElementContentHandlers<'static>> for ElementConten
native
}
}

#[wasm_bindgen]
extern "C" {
pub type DocumentContentHandlers;

#[wasm_bindgen(method, getter)]
fn doctype(this: &DocumentContentHandlers) -> Option<JsFunction>;

#[wasm_bindgen(method, getter)]
fn comments(this: &DocumentContentHandlers) -> Option<JsFunction>;

#[wasm_bindgen(method, getter)]
fn text(this: &DocumentContentHandlers) -> Option<JsFunction>;

#[wasm_bindgen(method, getter)]
fn end(this: &DocumentContentHandlers) -> Option<JsFunction>;
}

impl IntoNativeHandlers<NativeDocumentContentHandlers<'static>> for DocumentContentHandlers {
fn into_native(self) -> NativeDocumentContentHandlers<'static> {
let handlers: Rc<JsValue> = Rc::new((&self).into());
let mut native = NativeDocumentContentHandlers::default();

if let Some(handler) = self.doctype() {
let this = Rc::clone(&handlers);
native = native.doctype(make_handler!(handler, Doctype, this, stack_ptr));
}

if let Some(handler) = self.comments() {
let this = Rc::clone(&handlers);
native = native.comments(make_handler!(handler, Comment, this, stack_ptr));
}

if let Some(handler) = self.text() {
let this = Rc::clone(&handlers);
native = native.text(make_handler!(handler, TextChunk, this, stack_ptr));
}

if let Some(handler) = self.end() {
let this = Rc::clone(&handlers);
native = native.end(make_handler!(handler, DocumentEnd, this, stack_ptr));
}

native
}
}
13 changes: 1 addition & 12 deletions src/html_rewriter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use super::handlers::{
DocumentContentHandlers, ElementContentHandlers, HandlerJsErrorWrap, IntoNativeHandlers,
};
use super::handlers::{ ElementContentHandlers, HandlerJsErrorWrap, IntoNativeHandlers };
use super::*;
use js_sys::{Function as JsFunction, Uint8Array};
use lol_html::errors::RewritingError;
Expand Down Expand Up @@ -118,15 +116,6 @@ impl HTMLRewriter {
Ok(())
}

#[wasm_bindgen(method, js_name=onDocument)]
pub fn on_document(&mut self, handlers: DocumentContentHandlers) -> JsResult<()> {
self.assert_not_fully_constructed()?;
self.document_content_handlers
.push(handlers.into_native());

Ok(())
}

pub fn write(&mut self, chunk: &[u8]) -> JsResult<()> {
self.inner_mut()?
.write(chunk)
Expand Down

0 comments on commit 08aec11

Please sign in to comment.