mirror of
https://github.com/servo/servo.git
synced 2025-06-11 01:50:10 +00:00
Changes for spidermomkey upgrade.
This commit is contained in:
parent
f1bb3dcad0
commit
bd77a4043c
16 changed files with 245 additions and 186 deletions
|
@ -44,15 +44,16 @@ use ipc_channel::router::ROUTER;
|
|||
use js::jsapi::Handle as RawHandle;
|
||||
use js::jsapi::HandleObject;
|
||||
use js::jsapi::HandleValue as RawHandleValue;
|
||||
use js::jsapi::MutableHandleValue;
|
||||
use js::jsapi::Value;
|
||||
use js::jsapi::{CompileModule1, ExceptionStackBehavior, FinishDynamicModuleImport_NoTLA};
|
||||
use js::jsapi::{DynamicImportStatus, SetModuleDynamicImportHook, SetScriptPrivateReferenceHooks};
|
||||
use js::jsapi::{CompileModule1, ExceptionStackBehavior, FinishDynamicModuleImport};
|
||||
use js::jsapi::{SetModuleDynamicImportHook, SetScriptPrivateReferenceHooks};
|
||||
use js::jsapi::{GetModuleResolveHook, JSRuntime, SetModuleResolveHook};
|
||||
use js::jsapi::{GetRequestedModules, SetModuleMetadataHook};
|
||||
use js::jsapi::{GetRequestedModules, SetModuleMetadataHook, GetModuleRequestSpecifier};
|
||||
use js::jsapi::{Heap, JSContext, JS_ClearPendingException, SetModulePrivate};
|
||||
use js::jsapi::{JSAutoRealm, JSObject, JSString};
|
||||
use js::jsapi::{JS_DefineProperty4, JS_IsExceptionPending, JS_NewStringCopyN, JSPROP_ENUMERATE};
|
||||
use js::jsapi::{ModuleEvaluate, ModuleInstantiate};
|
||||
use js::jsapi::{ModuleEvaluate, ModuleLink};
|
||||
use js::jsval::{JSVal, PrivateValue, UndefinedValue};
|
||||
use js::rust::jsapi_wrapped::{GetArrayLength, JS_GetElement};
|
||||
use js::rust::jsapi_wrapped::{GetRequestedModuleSpecifier, JS_GetPendingException};
|
||||
|
@ -71,6 +72,7 @@ use net_traits::{ResourceFetchTiming, ResourceTimingType};
|
|||
use servo_url::ServoUrl;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
@ -475,8 +477,8 @@ impl ModuleTree {
|
|||
let _ac = JSAutoRealm::new(*global.get_cx(), *global.reflector().get_jsobject());
|
||||
|
||||
unsafe {
|
||||
if !ModuleInstantiate(*global.get_cx(), module_record) {
|
||||
warn!("fail to instantiate module");
|
||||
if !ModuleLink(*global.get_cx(), module_record) {
|
||||
warn!("fail to link & instantiate module");
|
||||
|
||||
rooted!(in(*global.get_cx()) let mut exception = UndefinedValue());
|
||||
assert!(JS_GetPendingException(
|
||||
|
@ -501,12 +503,12 @@ impl ModuleTree {
|
|||
&self,
|
||||
global: &GlobalScope,
|
||||
module_record: HandleObject,
|
||||
eval_result: MutableHandleValue,
|
||||
) -> Result<(), RethrowError> {
|
||||
let _ac = JSAutoRealm::new(*global.get_cx(), *global.reflector().get_jsobject());
|
||||
|
||||
unsafe {
|
||||
rooted!(in(*global.get_cx()) let mut rval = UndefinedValue());
|
||||
if !ModuleEvaluate(*global.get_cx(), module_record, rval.handle_mut().into()) {
|
||||
if !ModuleEvaluate(*global.get_cx(), module_record, eval_result) {
|
||||
warn!("fail to evaluate module");
|
||||
|
||||
rooted!(in(*global.get_cx()) let mut exception = UndefinedValue());
|
||||
|
@ -973,6 +975,7 @@ impl ModuleOwner {
|
|||
let network_error = module_tree.get_network_error().borrow().as_ref().cloned();
|
||||
let existing_rethrow_error = module_tree.get_rethrow_error().borrow().as_ref().cloned();
|
||||
|
||||
rooted!(in(*global.get_cx()) let mut rval = UndefinedValue());
|
||||
let execution_err = if network_error.is_none() && existing_rethrow_error.is_none() {
|
||||
let record = module_tree
|
||||
.get_record()
|
||||
|
@ -981,7 +984,7 @@ impl ModuleOwner {
|
|||
.map(|record| record.handle());
|
||||
|
||||
if let Some(record) = record {
|
||||
let evaluated = module_tree.execute_module(&global, record).err();
|
||||
let evaluated = module_tree.execute_module(&global, record, rval.handle_mut().into()).err();
|
||||
|
||||
if let Some(exception) = evaluated.clone() {
|
||||
module_tree.set_rethrow_error(exception);
|
||||
|
@ -996,11 +999,10 @@ impl ModuleOwner {
|
|||
};
|
||||
|
||||
// Ensure any failures related to importing this dynamic module are immediately reported.
|
||||
let status = match (network_error, existing_rethrow_error, execution_err) {
|
||||
match (network_error, existing_rethrow_error, execution_err) {
|
||||
(Some(_), _, _) => unsafe {
|
||||
let err = gen_type_error(&global, "Dynamic import failed".to_owned());
|
||||
JS_SetPendingException(*cx, err.handle(), ExceptionStackBehavior::Capture);
|
||||
DynamicImportStatus::Failed
|
||||
},
|
||||
(None, _, Some(execution_err)) => unsafe {
|
||||
JS_SetPendingException(
|
||||
|
@ -1008,7 +1010,6 @@ impl ModuleOwner {
|
|||
execution_err.handle(),
|
||||
ExceptionStackBehavior::Capture,
|
||||
);
|
||||
DynamicImportStatus::Failed
|
||||
},
|
||||
(None, Some(rethrow_error), _) => unsafe {
|
||||
JS_SetPendingException(
|
||||
|
@ -1016,18 +1017,22 @@ impl ModuleOwner {
|
|||
rethrow_error.handle(),
|
||||
ExceptionStackBehavior::Capture,
|
||||
);
|
||||
DynamicImportStatus::Failed
|
||||
},
|
||||
// do nothing if there's no errors
|
||||
(None, None, None) => DynamicImportStatus::Ok,
|
||||
(None, None, None) => {}
|
||||
};
|
||||
|
||||
debug!("Finishing dynamic import for {:?}", module_identity);
|
||||
|
||||
rooted!(in(*cx) let mut evaluation_promise = ptr::null_mut::<JSObject>());
|
||||
if rval.is_object() {
|
||||
evaluation_promise.set(rval.to_object());
|
||||
}
|
||||
|
||||
unsafe {
|
||||
FinishDynamicModuleImport_NoTLA(
|
||||
FinishDynamicModuleImport(
|
||||
*cx,
|
||||
status,
|
||||
evaluation_promise.handle().into(),
|
||||
module.referencing_private.handle(),
|
||||
module.specifier.handle(),
|
||||
module.promise.reflector().get_jsobject().into_handle(),
|
||||
|
@ -1249,7 +1254,7 @@ unsafe extern "C" fn host_release_top_level_script(value: *const Value) {
|
|||
pub unsafe extern "C" fn host_import_module_dynamically(
|
||||
cx: *mut JSContext,
|
||||
reference_private: RawHandleValue,
|
||||
specifier: RawHandle<*mut JSString>,
|
||||
specifier: RawHandle<*mut JSObject>,
|
||||
promise: RawHandle<*mut JSObject>,
|
||||
) -> bool {
|
||||
// Step 1.
|
||||
|
@ -1339,14 +1344,16 @@ unsafe fn module_script_from_reference_private<'a>(
|
|||
#[allow(unsafe_code)]
|
||||
fn fetch_an_import_module_script_graph(
|
||||
global: &GlobalScope,
|
||||
specifier: RawHandle<*mut JSString>,
|
||||
module_request: RawHandle<*mut JSObject>,
|
||||
reference_private: RawHandleValue,
|
||||
base_url: ServoUrl,
|
||||
options: ScriptFetchOptions,
|
||||
promise: Rc<Promise>,
|
||||
) -> Result<(), RethrowError> {
|
||||
// Step 1.
|
||||
let url = ModuleTree::resolve_module_specifier(*global.get_cx(), &base_url, specifier);
|
||||
let cx = global.get_cx();
|
||||
rooted!(in(*cx) let specifier = unsafe { GetModuleRequestSpecifier(*cx, module_request) });
|
||||
let url = ModuleTree::resolve_module_specifier(*cx, &base_url, specifier.handle().into());
|
||||
|
||||
// Step 2.
|
||||
if url.is_err() {
|
||||
|
@ -1373,7 +1380,7 @@ fn fetch_an_import_module_script_graph(
|
|||
referencing_private: Heap::default(),
|
||||
id: dynamic_module_id,
|
||||
});
|
||||
dynamic_module.specifier.set(specifier.get());
|
||||
dynamic_module.specifier.set(module_request.get());
|
||||
dynamic_module
|
||||
.referencing_private
|
||||
.set(reference_private.get());
|
||||
|
@ -1402,7 +1409,7 @@ fn fetch_an_import_module_script_graph(
|
|||
unsafe extern "C" fn HostResolveImportedModule(
|
||||
cx: *mut JSContext,
|
||||
reference_private: RawHandleValue,
|
||||
specifier: RawHandle<*mut JSString>,
|
||||
specifier: RawHandle<*mut JSObject>,
|
||||
) -> *mut JSObject {
|
||||
let in_realm_proof = AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx));
|
||||
let global_scope = GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof));
|
||||
|
@ -1417,7 +1424,8 @@ unsafe extern "C" fn HostResolveImportedModule(
|
|||
}
|
||||
|
||||
// Step 5.
|
||||
let url = ModuleTree::resolve_module_specifier(*global_scope.get_cx(), &base_url, specifier);
|
||||
rooted!(in(*global_scope.get_cx()) let specifier = GetModuleRequestSpecifier(cx, specifier));
|
||||
let url = ModuleTree::resolve_module_specifier(*global_scope.get_cx(), &base_url, specifier.handle().into());
|
||||
|
||||
// Step 6.
|
||||
assert!(url.is_ok());
|
||||
|
@ -1542,7 +1550,7 @@ struct DynamicModule {
|
|||
#[ignore_malloc_size_of = "Rc is hard"]
|
||||
promise: Rc<Promise>,
|
||||
#[ignore_malloc_size_of = "GC types are hard"]
|
||||
specifier: Heap<*mut JSString>,
|
||||
specifier: Heap<*mut JSObject>,
|
||||
#[ignore_malloc_size_of = "GC types are hard"]
|
||||
referencing_private: Heap<JSVal>,
|
||||
#[ignore_malloc_size_of = "Defined in uuid"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue