Skip to content

Commit

Permalink
require entered realm, use aes, to append native promise handler
Browse files Browse the repository at this point in the history
  • Loading branch information
gterzian committed Jun 4, 2020
1 parent bd5796c commit 48d4aec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
27 changes: 14 additions & 13 deletions components/script/body.rs
Expand Up @@ -10,7 +10,6 @@ use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::refcounted::Trusted;
use crate::dom::bindings::reflector::DomObject;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::settings_stack::AutoIncumbentScript;
use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::bindings::trace::RootedTraceableBox;
use crate::dom::blob::{normalize_type_string, Blob};
Expand Down Expand Up @@ -137,11 +136,9 @@ impl TransmitBodyConnectHandler {

let handler = PromiseNativeHandler::new(&global, Some(promise_handler), Some(rejection_handler));

// Enter a realm, and a script,
// before appending the native handler.
let _realm = enter_realm(&*global);
let _ais = AutoIncumbentScript::new(&*global);
promise.append_native_handler(&handler);
let realm = enter_realm(&*global);
let comp = InRealm::Entered(&realm);
promise.append_native_handler(&handler, comp);
}),
&self.canceller,
);
Expand Down Expand Up @@ -556,11 +553,9 @@ impl Callback for ConsumeBodyPromiseHandler {
let handler =
PromiseNativeHandler::new(&global, Some(promise_handler), Some(rejection_handler));

// Enter a realm, and a script,
// before appending the native handler.
let _realm = enter_realm(&*global);
let _ais = AutoIncumbentScript::new(&*global);
read_promise.append_native_handler(&handler);
let realm = enter_realm(&*global);
let comp = InRealm::Entered(&realm);
read_promise.append_native_handler(&handler, comp);
}
}
}
Expand All @@ -581,7 +576,12 @@ pub fn consume_body<T: BodyMixin + DomObject>(object: &T, body_type: BodyType) -
return promise;
}

consume_body_with_promise(object, body_type, promise.clone());
consume_body_with_promise(
object,
body_type,
promise.clone(),
InRealm::Already(&in_realm_proof),
);

promise
}
Expand All @@ -592,6 +592,7 @@ fn consume_body_with_promise<T: BodyMixin + DomObject>(
object: &T,
body_type: BodyType,
promise: Rc<Promise>,
comp: InRealm,
) {
let global = object.global();

Expand Down Expand Up @@ -637,7 +638,7 @@ fn consume_body_with_promise<T: BodyMixin + DomObject>(
Some(rejection_handler),
);
// We are already in a realm and a script.
read_promise.append_native_handler(&handler);
read_promise.append_native_handler(&handler, comp);
}

// https://fetch.spec.whatwg.org/#concept-body-package-data
Expand Down
4 changes: 3 additions & 1 deletion components/script/dom/promise.rs
Expand Up @@ -14,6 +14,7 @@
use crate::dom::bindings::conversions::root_from_object;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{DomObject, MutDomObject, Reflector};
use crate::dom::bindings::settings_stack::AutoEntryScript;
use crate::dom::bindings::utils::AsCCharPtrPtr;
use crate::dom::globalscope::GlobalScope;
use crate::dom::promisenativehandler::PromiseNativeHandler;
Expand Down Expand Up @@ -242,7 +243,8 @@ impl Promise {
}

#[allow(unsafe_code)]
pub fn append_native_handler(&self, handler: &PromiseNativeHandler) {
pub fn append_native_handler(&self, handler: &PromiseNativeHandler, _comp: InRealm) {
let _ais = AutoEntryScript::new(&*handler.global());
let cx = self.global().get_cx();
rooted!(in(*cx) let resolve_func =
create_native_handler_function(*cx,
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/testbinding.rs
Expand Up @@ -1003,8 +1003,8 @@ impl TestBindingMethods for TestBinding {
resolve.map(SimpleHandler::new),
reject.map(SimpleHandler::new),
);
let p = Promise::new_in_current_realm(&global, comp);
p.append_native_handler(&handler);
let p = Promise::new_in_current_realm(&global, comp.clone());
p.append_native_handler(&handler, comp);
return p;

#[derive(JSTraceable, MallocSizeOf)]
Expand Down
20 changes: 10 additions & 10 deletions components/script/script_module.rs
Expand Up @@ -321,13 +321,13 @@ impl ModuleTree {
))),
);

let _realm = enter_realm(&*owner.global());
AlreadyInRealm::assert(&*owner.global());
let _ais = AutoIncumbentScript::new(&*owner.global());
let global = owner.global();
let realm = enter_realm(&*global);
let comp = InRealm::Entered(&realm);

let promise = promise.as_ref().unwrap();

promise.append_native_handler(&handler);
promise.append_native_handler(&handler, comp);
}
}

Expand Down Expand Up @@ -723,13 +723,13 @@ impl ModuleOwner {
))),
);

let realm = enter_realm(&*self.global());
let global = self.global();
let realm = enter_realm(&*global);
let comp = InRealm::Entered(&realm);
let _ais = AutoIncumbentScript::new(&*self.global());

let promise = Promise::new_in_current_realm(&self.global(), comp);

promise.append_native_handler(&handler);
promise.append_native_handler(&handler, comp);

promise
}
Expand Down Expand Up @@ -1362,8 +1362,7 @@ fn fetch_module_descendants_and_link(
unsafe {
let global = owner.global();

let _realm = enter_realm(&*global);
AlreadyInRealm::assert(&*global);
let realm = enter_realm(&*global);
let _ais = AutoIncumbentScript::new(&*global);

let abv = RootedObjectVectorWrapper::new(*global.get_cx());
Expand Down Expand Up @@ -1402,7 +1401,8 @@ fn fetch_module_descendants_and_link(
))),
);

promise_all.append_native_handler(&handler);
let comp = InRealm::Entered(&realm);
promise_all.append_native_handler(&handler, comp);

return Some(promise_all);
}
Expand Down

0 comments on commit 48d4aec

Please sign in to comment.