Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b51b6f2
[core][rewriter] dpsc: partially implement WrapAccess
velzie Jul 23, 2025
3d35c62
[core][rewriter] dpsc: implement WrapSet and remove WrapThis
velzie Jul 23, 2025
5f07a12
[core][rewriter] dpsc: implement WrapGetComputed
velzie Jul 23, 2025
237bf13
[core][rewriter] dpsc: fix nested WrapGet s
velzie Jul 24, 2025
4115c03
[core][rewriter] dpsc: implement WrapSetComputed
velzie Jul 24, 2025
f7b9a73
[core][rewriter] dpsc: fix nested computed gets
velzie Jul 24, 2025
8006807
[core][rewriter] dspc: change eval() from a replace rewrite to an ins…
velzie Jul 24, 2025
215fd12
[core][rewriter] dpsc: nuke strictchecker
velzie Jul 24, 2025
08a99dd
[core][rewriter] fix dpsc wrapget (#3)
r58Playz Jul 25, 2025
a06492b
Merge branch 'main' of https://github.com/HeyPuter/browser.js into dpsc
velzie Jul 25, 2025
7d4f36e
[core] add dpsc types to config
velzie Jul 25, 2025
718a7fe
Merge branch 'dpsc' of https://github.com/HeyPuter/browser.js into dpsc
velzie Jul 25, 2025
f879594
[core][rewriter] dpsc: fix bad rewrite with wrapcomputedgetleft
velzie Jul 25, 2025
7215171
[core][rewriter] dpsc: switch from computed wraps to dynamic property…
velzie Jul 25, 2025
787265b
[core] add dpsc globals
velzie Jul 25, 2025
144d048
[core] NUKE GLOBALPROXY
velzie Jul 25, 2025
0519d52
[puter] merge with upstream
velzie Aug 4, 2025
d7ac6ec
[core] dpsc: proxy location for document.location too
velzie Aug 5, 2025
19ad307
[core][rewriter] dpsc: fix eval rewrite
velzie Aug 5, 2025
b3cc3b8
[core][rewriter] dpsc: handle the comma operator correctly in wrapped…
velzie Aug 5, 2025
0205265
[core] dpsc: oops
velzie Aug 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rewriter/js/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub struct Config {
pub prefix: String,

pub wrapfn: String,
pub wrapthisfn: String,
pub wrappropertybase: String,
pub wrappropertyfn: String,
pub importfn: String,
pub rewritefn: String,
pub setrealmfn: String,
Expand Down
57 changes: 39 additions & 18 deletions rewriter/js/src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ use crate::{
rewrite::Rewrite,
};

// const STRICTCHECKER: &str = "(function(a){arguments[0]=false;return a})(true)";
const STRICTCHECKER: &str = "(function(){return!this;})()";

macro_rules! change {
($span:expr, $($ty:tt)*) => {
$crate::changes::JsChange::new($span, $crate::changes::JsChangeType::$($ty)*)
Expand All @@ -30,21 +27,34 @@ pub(crate) use change;
#[derive(Debug, PartialEq, Eq)]
pub enum JsChangeType<'alloc: 'data, 'data> {
/// insert `${cfg.wrapfn}(`
WrapFnLeft { wrap: bool },
/// insert `,strictchecker)`
WrapFnRight { wrap: bool },
WrapFnLeft {
enclose: bool,
},
/// insert `)`
WrapFnRight {
enclose: bool,
},

WrapPropertyLeft,
WrapPropertyRight,
RewriteProperty {
ident: Atom<'data>,
},

/// insert `${cfg.setrealmfn}({}).`
SetRealmFn,
/// insert `${cfg.wrapthis}(`
WrapThisFn,
/// insert `$scramerr(ident);`
ScramErrFn { ident: Atom<'data> },
ScramErrFn {
ident: Atom<'data>,
},
/// insert `$scramitize(`
ScramitizeFn,
/// insert `eval(${cfg.rewritefn}(`
EvalRewriteFn,
/// insert `: ${cfg.wrapfn}(ident)`
ShorthandObj { ident: Atom<'data> },
ShorthandObj {
ident: Atom<'data>,
},
/// insert scramtag
SourceTag,

Expand All @@ -59,10 +69,15 @@ pub enum JsChangeType<'alloc: 'data, 'data> {
},

/// insert `)`
ClosingParen { semi: bool, replace: bool },
ClosingParen {
semi: bool,
replace: bool,
},

/// replace span with text
Replace { text: &'alloc str },
Replace {
text: &'alloc str,
},
/// replace span with ""
Delete,
}
Expand Down Expand Up @@ -91,24 +106,28 @@ impl<'alloc: 'data, 'data> Transform<'data> for JsChange<'alloc, 'data> {
(cfg, flags): &Self::ToLowLevelData,
offset: i32,
) -> TransformLL<'data> {
dbg!(&&self);
use JsChangeType as Ty;
use TransformLL as LL;
match self.ty {
Ty::WrapFnLeft { wrap } => LL::insert(if wrap {
Ty::WrapFnLeft { enclose } => LL::insert(if enclose {
transforms!["(", &cfg.wrapfn, "("]
} else {
transforms![&cfg.wrapfn, "("]
}),
Ty::WrapFnRight { wrap } => LL::insert(if wrap {
transforms![",", STRICTCHECKER, "))"]
Ty::WrapFnRight { enclose } => LL::insert(if enclose {
transforms!["))"]
} else {
transforms![",", STRICTCHECKER, ")"]
transforms![")"]
}),
Ty::WrapPropertyLeft => LL::insert(transforms![&cfg.wrappropertyfn, "(("]),
Ty::WrapPropertyRight => LL::insert(transforms!["))"]),
Ty::RewriteProperty { ident } => LL::replace(transforms![&cfg.wrappropertybase,ident]),

Ty::SetRealmFn => LL::insert(transforms![&cfg.setrealmfn, "({})."]),
Ty::WrapThisFn => LL::insert(transforms![&cfg.wrapthisfn, "("]),
Ty::ScramErrFn { ident } => LL::insert(transforms!["$scramerr(", ident, ");"]),
Ty::ScramitizeFn => LL::insert(transforms![" $scramitize("]),
Ty::EvalRewriteFn => LL::replace(transforms!["eval(", &cfg.rewritefn, "("]),
Ty::EvalRewriteFn => LL::insert(transforms![&cfg.rewritefn, "("]),
Ty::ShorthandObj { ident } => {
LL::insert(transforms![":", &cfg.wrapfn, "(", ident, ")"])
}
Expand Down Expand Up @@ -164,6 +183,8 @@ impl Ord for JsChange<'_, '_> {
Ordering::Equal => match (&self.ty, &other.ty) {
(Ty::ScramErrFn { .. }, _) => Ordering::Less,
(_, Ty::ScramErrFn { .. }) => Ordering::Greater,
(Ty::WrapFnRight { .. }, _) => Ordering::Less,
(_, Ty::WrapFnRight { .. }) => Ordering::Greater,
_ => Ordering::Equal,
},
x => x,
Expand Down
47 changes: 27 additions & 20 deletions rewriter/js/src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@ pub(crate) use rewrite;

#[derive(Debug, PartialEq, Eq)]
pub(crate) enum RewriteType<'alloc: 'data, 'data> {
/// `(cfg.wrapfn(ident,strictchecker))` | `cfg.wrapfn(ident,strictchecker)`
/// `(cfg.wrapfn(ident))` | `cfg.wrapfn(ident)`
WrapFn {
wrap: bool,
enclose: bool,
},
/// `cfg.setrealmfn({}).ident`
SetRealmFn,
/// `cfg.wrapthis(this)`
WrapThisFn,

/// `(cfg.importfn("cfg.base"))`
ImportFn,
/// `cfg.metafn("cfg.base")`
MetaFn,

RewriteProperty {
ident: Atom<'data>,
},
WrapProperty,

// dead code only if debug is disabled
#[allow(dead_code)]
/// `$scramerr(name)`
Expand Down Expand Up @@ -60,6 +64,7 @@ pub(crate) enum RewriteType<'alloc: 'data, 'data> {
Delete,
}

#[derive(Debug)]
pub(crate) struct Rewrite<'alloc, 'data> {
span: Span,
ty: RewriteType<'alloc, 'data>,
Expand All @@ -77,6 +82,8 @@ impl<'alloc: 'data, 'data> Rewrite<'alloc, 'data> {

impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
fn into_inner(self, span: Span) -> SmallVec<[JsChange<'alloc, 'data>; 2]> {

dbg!(&self);
macro_rules! span {
(start) => {
Span::new(span.start, span.start)
Expand All @@ -90,24 +97,24 @@ impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
($span1:ident $span2:ident end) => {
Span::new($span1.end, $span2.end)
};
($span1:ident $span2:ident between) => {
Span::new($span1.end, $span2.start)
};
}

match self {
Self::WrapFn { wrap } => smallvec![
change!(span!(start), WrapFnLeft { wrap }),
change!(span!(end), WrapFnRight { wrap }),
Self::WrapFn { enclose } => smallvec![
change!(span!(start), WrapFnLeft { enclose }),
change!(span!(end), WrapFnRight { enclose }),
],
Self::RewriteProperty { ident } => smallvec![
change!(span, RewriteProperty { ident }),
],
Self::WrapProperty => smallvec![
change!(span!(start), WrapPropertyLeft),
change!(span!(end), WrapPropertyRight),
],
Self::SetRealmFn => smallvec![change!(span, SetRealmFn)],
Self::WrapThisFn => smallvec![
change!(span!(start), WrapThisFn),
change!(
span!(end),
ClosingParen {
semi: false,
replace: false
}
),
],
Self::ImportFn => smallvec![change!(span, ImportFn)],
Self::MetaFn => smallvec![change!(span, MetaFn)],
Self::ScramErr { ident } => smallvec![change!(span!(end), ScramErrFn { ident })],
Expand All @@ -122,12 +129,12 @@ impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
)
],
Self::Eval { inner } => smallvec![
change!(span!(span inner start), EvalRewriteFn),
change!(Span::new(inner.start, inner.start), EvalRewriteFn),
change!(
span!(inner span end),
Span::new(inner.end, inner.end),
ClosingParen {
semi: false,
replace: true
replace: false,
}
)
],
Expand Down
Loading
Loading