mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 07:30:02 -04:00
add setRealm rewriting
This commit is contained in:
parent
6d498950e3
commit
5024e19c08
3 changed files with 28 additions and 1 deletions
|
@ -52,6 +52,7 @@ fn get_config(scramjet: &Object) -> Config {
|
|||
importfn: get_str(config, "importfn"),
|
||||
rewritefn: get_str(config, "rewritefn"),
|
||||
metafn: get_str(config, "metafn"),
|
||||
setrealmfn: get_str(config, "setrealmfn"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,7 @@ fn dorewrite(source_text: &str) -> String {
|
|||
importfn: "$import".to_string(),
|
||||
rewritefn: "$rewrite".to_string(),
|
||||
metafn: "$meta".to_string(),
|
||||
setrealmfn: "$setrealm".to_string(),
|
||||
},
|
||||
)
|
||||
.as_slice(),
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use oxc_allocator::Allocator;
|
||||
use oxc_ast::{
|
||||
ast::{AssignmentTarget, Expression, IdentifierReference, ObjectPropertyKind},
|
||||
ast::{
|
||||
AssignmentTarget, Expression, IdentifierReference, MemberExpression, ObjectPropertyKind,
|
||||
},
|
||||
visit::walk,
|
||||
Visit,
|
||||
};
|
||||
|
@ -38,6 +40,7 @@ pub struct Config {
|
|||
pub wrapfn: String,
|
||||
pub importfn: String,
|
||||
pub rewritefn: String,
|
||||
pub setrealmfn: String,
|
||||
pub metafn: String,
|
||||
pub encode: EncodeFn,
|
||||
}
|
||||
|
@ -100,6 +103,28 @@ impl<'a> Visit<'a> for Rewriter {
|
|||
self.walk_member_expression(&it.callee);
|
||||
walk::walk_arguments(self, &it.arguments);
|
||||
}
|
||||
fn visit_member_expression(&mut self, it: &oxc_ast::ast::MemberExpression<'a>) {
|
||||
match it {
|
||||
MemberExpression::StaticMemberExpression(s) => {
|
||||
if s.property.name == "postMessage" {
|
||||
self.jschanges.push(JsChange::GenericChange {
|
||||
span: s.property.span,
|
||||
// an empty object will let us safely reconstruct the realm later
|
||||
text: format!("{}({{}}).{}", self.config.setrealmfn, s.property.name),
|
||||
});
|
||||
|
||||
return; // unwise to walk the rest of the tree
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// TODO
|
||||
// you could break this with ["postMessage"] etc
|
||||
// however this code only exists because of recaptcha whatever
|
||||
// and it would slow down js execution a lot
|
||||
}
|
||||
}
|
||||
walk::walk_member_expression(self, it);
|
||||
}
|
||||
fn visit_this_expression(&mut self, it: &oxc_ast::ast::ThisExpression) {
|
||||
self.jschanges.push(JsChange::GenericChange {
|
||||
span: it.span,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue