Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeChampion committed Nov 21, 2024
1 parent 1716599 commit 6c15a7e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
Binary file modified pkg/csp_nonce_html_transformer_bg.wasm
Binary file not shown.
8 changes: 4 additions & 4 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ unsafe impl Sync for HandlerJsErrorWrap {}
macro_rules! make_handler {
($handler:ident, $JsArgType:ident, $this:ident, $stack_ptr:ident) => {
move |arg: &mut _| {
let (js_arg, anchor) = $JsArgType::from_native(arg, $stack_ptr);
let (js_arg, anchor) = $JsArgType::from_native(arg);
let js_arg = JsValue::from(js_arg);

let res = match $handler.call1(&$this, &js_arg) {
Expand All @@ -44,7 +44,7 @@ macro_rules! make_handler {
pub(crate) use make_handler;

pub trait IntoNativeHandlers<T> {
fn into_native(self, stack_ptr: *mut u8) -> T;
fn into_native(self) -> T;
}

#[wasm_bindgen]
Expand All @@ -62,7 +62,7 @@ extern "C" {
}

impl IntoNativeHandlers<NativeElementContentHandlers<'static>> for ElementContentHandlers {
fn into_native(self, stack_ptr: *mut u8) -> NativeElementContentHandlers<'static> {
fn into_native(self) -> NativeElementContentHandlers<'static> {
let handlers: Rc<JsValue> = Rc::new((&self).into());
let mut native = NativeElementContentHandlers::default();

Expand Down Expand Up @@ -103,7 +103,7 @@ extern "C" {
}

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

Expand Down
6 changes: 2 additions & 4 deletions src/html_rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,17 @@ impl HTMLRewriter {
let selector = selector.parse::<Selector>().into_js_result()?;

self.selectors.push(selector);
let stack_ptr = self.asyncify_stack_ptr();
self.element_content_handlers
.push(handlers.into_native(stack_ptr));
.push(handlers.into_native());

Ok(())
}

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

Ok(())
}
Expand Down
8 changes: 2 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ impl Drop for Anchor<'_> {
struct NativeRefWrap<R> {
inner_ptr: *mut R,
poisoned: Rc<Cell<bool>>,
#[allow(dead_code)]
stack_ptr: *mut u8,
}

impl<R> NativeRefWrap<R> {
pub fn wrap<I>(inner: &mut I, stack_ptr: *mut u8) -> (Self, Anchor) {
pub fn wrap<I>(inner: &mut I) -> (Self, Anchor) {
let wrap = NativeRefWrap {
inner_ptr: unsafe { mem::transmute(inner) },
poisoned: Rc::new(Cell::new(false)),
stack_ptr,
};

let anchor = Anchor::new(Rc::clone(&wrap.poisoned));
Expand Down Expand Up @@ -172,9 +169,8 @@ macro_rules! impl_from_native {
#[allow(dead_code)]
pub(crate) fn from_native<'r>(
inner: &'r mut $Ty,
stack_ptr: *mut u8,
) -> (Self, Anchor<'r>) {
let (ref_wrap, anchor) = NativeRefWrap::wrap(inner, stack_ptr);
let (ref_wrap, anchor) = NativeRefWrap::wrap(inner);

($JsTy(ref_wrap), anchor)
}
Expand Down

0 comments on commit 6c15a7e

Please sign in to comment.