Use mozjs exposed function to generate SourceText

This commit is contained in:
CYBAI 2020-03-26 13:23:23 +09:00
parent 5f71be281d
commit 018b23d43b
3 changed files with 9 additions and 30 deletions

View file

@ -36,7 +36,8 @@ use crate::dom::workerglobalscope::WorkerGlobalScope;
use crate::realms::{enter_realm, InRealm}; use crate::realms::{enter_realm, InRealm};
use dom_struct::dom_struct; use dom_struct::dom_struct;
use fnv::FnvHasher; use fnv::FnvHasher;
use js::jsapi::{JS_GetFunctionObject, SourceText}; use js::jsapi::JS_GetFunctionObject;
use js::rust::transform_u16_to_source_text;
use js::rust::wrappers::CompileFunction; use js::rust::wrappers::CompileFunction;
use js::rust::{CompileOptionsWrapper, RootedObjectVectorWrapper}; use js::rust::{CompileOptionsWrapper, RootedObjectVectorWrapper};
use libc::c_char; use libc::c_char;
@ -47,7 +48,6 @@ use std::collections::HashMap;
use std::default::Default; use std::default::Default;
use std::ffi::CString; use std::ffi::CString;
use std::hash::BuildHasherDefault; use std::hash::BuildHasherDefault;
use std::marker::PhantomData;
use std::mem; use std::mem;
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::rc::Rc; use std::rc::Rc;
@ -539,12 +539,7 @@ impl EventTarget {
name.as_ptr(), name.as_ptr(),
args.len() as u32, args.len() as u32,
args.as_ptr(), args.as_ptr(),
&mut SourceText { &mut transform_u16_to_source_text(&body),
units_: body.as_ptr() as *const _,
length_: body.len() as u32,
ownsUnits_: false,
_phantom_0: PhantomData,
},
) )
}); });
if handler.get().is_null() { if handler.get().is_null() {

View file

@ -67,9 +67,10 @@ use ipc_channel::router::ROUTER;
use js::glue::{IsWrapper, UnwrapObjectDynamic}; use js::glue::{IsWrapper, UnwrapObjectDynamic};
use js::jsapi::{CurrentGlobalOrNull, GetNonCCWObjectGlobal}; use js::jsapi::{CurrentGlobalOrNull, GetNonCCWObjectGlobal};
use js::jsapi::{HandleObject, Heap}; use js::jsapi::{HandleObject, Heap};
use js::jsapi::{JSContext, JSObject, SourceText}; use js::jsapi::{JSContext, JSObject};
use js::jsval::{JSVal, UndefinedValue}; use js::jsval::{JSVal, UndefinedValue};
use js::panic::maybe_resume_unwind; use js::panic::maybe_resume_unwind;
use js::rust::transform_str_to_source_text;
use js::rust::wrappers::Evaluate2; use js::rust::wrappers::Evaluate2;
use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime}; use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime};
use js::rust::{HandleValue, MutableHandleValue}; use js::rust::{HandleValue, MutableHandleValue};
@ -97,7 +98,6 @@ use std::cell::{Cell, RefCell, RefMut};
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::collections::{HashMap, VecDeque}; use std::collections::{HashMap, VecDeque};
use std::ffi::CString; use std::ffi::CString;
use std::marker::PhantomData;
use std::mem; use std::mem;
use std::ops::Index; use std::ops::Index;
use std::rc::Rc; use std::rc::Rc;
@ -2166,12 +2166,7 @@ impl GlobalScope {
Evaluate2( Evaluate2(
*cx, *cx,
options.ptr, options.ptr,
&mut SourceText { &mut transform_str_to_source_text(code),
units_: code.as_ptr() as *const _,
length_: code.len() as u32,
ownsUnits_: false,
_phantom_0: PhantomData,
},
rval, rval,
) )
}; };

View file

@ -46,13 +46,14 @@ use js::jsapi::{
CompileModule, ExceptionStackBehavior, GetModuleResolveHook, JSRuntime, SetModuleResolveHook, CompileModule, ExceptionStackBehavior, GetModuleResolveHook, JSRuntime, SetModuleResolveHook,
}; };
use js::jsapi::{GetRequestedModules, SetModuleMetadataHook}; use js::jsapi::{GetRequestedModules, SetModuleMetadataHook};
use js::jsapi::{GetWaitForAllPromise, ModuleEvaluate, ModuleInstantiate, SourceText}; use js::jsapi::{GetWaitForAllPromise, ModuleEvaluate, ModuleInstantiate};
use js::jsapi::{Heap, JSContext, JS_ClearPendingException, SetModulePrivate}; use js::jsapi::{Heap, JSContext, JS_ClearPendingException, SetModulePrivate};
use js::jsapi::{JSAutoRealm, JSObject, JSString}; use js::jsapi::{JSAutoRealm, JSObject, JSString};
use js::jsapi::{SetModuleDynamicImportHook, SetScriptPrivateReferenceHooks}; use js::jsapi::{SetModuleDynamicImportHook, SetScriptPrivateReferenceHooks};
use js::jsval::{JSVal, PrivateValue, UndefinedValue}; use js::jsval::{JSVal, PrivateValue, UndefinedValue};
use js::rust::jsapi_wrapped::{GetRequestedModuleSpecifier, JS_GetPendingException}; use js::rust::jsapi_wrapped::{GetRequestedModuleSpecifier, JS_GetPendingException};
use js::rust::jsapi_wrapped::{JS_GetArrayLength, JS_GetElement}; use js::rust::jsapi_wrapped::{JS_GetArrayLength, JS_GetElement};
use js::rust::transform_u16_to_source_text;
use js::rust::wrappers::JS_SetPendingException; use js::rust::wrappers::JS_SetPendingException;
use js::rust::CompileOptionsWrapper; use js::rust::CompileOptionsWrapper;
use js::rust::IntoHandle; use js::rust::IntoHandle;
@ -68,7 +69,6 @@ use servo_url::ServoUrl;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::ffi; use std::ffi;
use std::marker::PhantomData;
use std::rc::Rc; use std::rc::Rc;
use std::str::FromStr; use std::str::FromStr;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -76,15 +76,6 @@ use url::ParseError as UrlParseError;
use indexmap::IndexSet; use indexmap::IndexSet;
pub fn get_source_text(source: &[u16]) -> SourceText<u16> {
SourceText {
units_: source.as_ptr() as *const _,
length_: source.len() as u32,
ownsUnits_: false,
_phantom_0: PhantomData,
}
}
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn gen_type_error(global: &GlobalScope, string: String) -> ModuleError { unsafe fn gen_type_error(global: &GlobalScope, string: String) -> ModuleError {
rooted!(in(*global.get_cx()) let mut thrown = UndefinedValue()); rooted!(in(*global.get_cx()) let mut thrown = UndefinedValue());
@ -368,13 +359,11 @@ impl ModuleTree {
let compile_options = let compile_options =
unsafe { CompileOptionsWrapper::new(*global.get_cx(), url_cstr.as_ptr(), 1) }; unsafe { CompileOptionsWrapper::new(*global.get_cx(), url_cstr.as_ptr(), 1) };
let mut source = get_source_text(&module);
unsafe { unsafe {
rooted!(in(*global.get_cx()) let mut module_script = CompileModule( rooted!(in(*global.get_cx()) let mut module_script = CompileModule(
*global.get_cx(), *global.get_cx(),
compile_options.ptr, compile_options.ptr,
&mut source, &mut transform_u16_to_source_text(&module),
)); ));
if module_script.is_null() { if module_script.is_null() {