Update to SpiderMonkey 66.

This commit is contained in:
Josh Matthews 2019-05-06 11:38:34 -04:00
parent d0d3401361
commit 4328713f71
31 changed files with 150 additions and 144 deletions

16
Cargo.lock generated
View file

@ -2803,21 +2803,21 @@ dependencies = [
[[package]]
name = "mozjs"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
version = "0.11.0"
source = "git+https://github.com/servo/rust-mozjs?rev=357d1db91e4e49c3f148fe05fdfae5f8f0834ca8#357d1db91e4e49c3f148fe05fdfae5f8f0834ca8"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs_sys 0.61.13 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs_sys 0.66.0 (git+https://github.com/servo/mozjs?rev=e21c05b415dfc246175ff8d5fc48b0e8c5b4e9e9)",
"num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mozjs_sys"
version = "0.61.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
version = "0.66.0"
source = "git+https://github.com/servo/mozjs?rev=e21c05b415dfc246175ff8d5fc48b0e8c5b4e9e9#e21c05b415dfc246175ff8d5fc48b0e8c5b4e9e9"
dependencies = [
"bindgen 0.49.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3593,7 +3593,7 @@ dependencies = [
"mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"mozangle 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"mozjs 0.11.0 (git+https://github.com/servo/rust-mozjs?rev=357d1db91e4e49c3f148fe05fdfae5f8f0834ca8)",
"msg 0.0.1",
"net_traits 0.0.1",
"num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -5593,8 +5593,8 @@ dependencies = [
"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
"checksum mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9de3eca27871df31c33b807f834b94ef7d000956f57aa25c5aed9c5f0aae8f6f"
"checksum mozangle 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ba1ce5212fd56a71cfbc463aedd4ece76090d98b96d5122f84dedffa0cc508"
"checksum mozjs 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "622108d35f4fdd68b3aa39bfe9bedaee5fa9efd19711d046e1d56ff607c0a36f"
"checksum mozjs_sys 0.61.13 (registry+https://github.com/rust-lang/crates.io-index)" = "c7d35502544cf3e70b305e028c6ca9e4c3d5a48264af220f8341598f54d189ba"
"checksum mozjs 0.11.0 (git+https://github.com/servo/rust-mozjs?rev=357d1db91e4e49c3f148fe05fdfae5f8f0834ca8)" = "<none>"
"checksum mozjs_sys 0.66.0 (git+https://github.com/servo/mozjs?rev=e21c05b415dfc246175ff8d5fc48b0e8c5b4e9e9)" = "<none>"
"checksum msdos_time 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aad9dfe950c057b1bfe9c1f2aa51583a8468ef2a5baba2ebbe06d775efeb7729"
"checksum muldiv 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "451a9a05d2a32c566c897835e0ea95cf79ed2fdfe957924045a1721a36c9980f"
"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88"

View file

@ -65,7 +65,7 @@ indexmap = "1.0.2"
ipc-channel = "0.11"
itertools = "0.8"
jstraceable_derive = {path = "../jstraceable_derive"}
js = {package = "mozjs", version = "0.10.1"}
js = {package = "mozjs", git = "https://github.com/servo/rust-mozjs", rev = "357d1db91e4e49c3f148fe05fdfae5f8f0834ca8"}
keyboard-types = "0.4.4"
lazy_static = "1"
libc = "0.2"

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::globalscope::GlobalScope;
use js::jsapi::{GetCurrentRealmOrNull, JSAutoCompartment};
use js::jsapi::{GetCurrentRealmOrNull, JSAutoRealm};
pub struct AlreadyInCompartment(());
@ -20,7 +20,7 @@ impl AlreadyInCompartment {
#[derive(Clone, Copy)]
pub enum InCompartment<'a> {
Already(&'a AlreadyInCompartment),
Entered(&'a JSAutoCompartment),
Entered(&'a JSAutoRealm),
}
impl<'a> InCompartment<'a> {
@ -28,7 +28,7 @@ impl<'a> InCompartment<'a> {
InCompartment::Already(token)
}
pub fn entered(token: &JSAutoCompartment) -> InCompartment {
pub fn entered(token: &JSAutoRealm) -> InCompartment {
InCompartment::Entered(token)
}
}

View file

@ -23,7 +23,7 @@ use devtools_traits::{AutoMargins, CachedConsoleMessage, CachedConsoleMessageTyp
use devtools_traits::{ComputedNodeLayout, ConsoleAPI, PageError};
use devtools_traits::{EvaluateJSReply, Modification, NodeInfo, TimelineMarker};
use ipc_channel::ipc::IpcSender;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSAutoRealm;
use js::jsval::UndefinedValue;
use js::rust::wrappers::ObjectClassName;
use msg::constellation_msg::PipelineId;
@ -37,7 +37,7 @@ pub fn handle_evaluate_js(global: &GlobalScope, eval: String, reply: IpcSender<E
let result = unsafe {
let cx = global.get_cx();
let globalhandle = global.reflector().get_jsobject();
let _ac = JSAutoCompartment::new(cx, globalhandle.get());
let _ac = JSAutoRealm::new(cx, globalhandle.get());
rooted!(in(cx) let mut rval = UndefinedValue());
global.evaluate_js_on_global_with_result(&eval, rval.handle_mut());

View file

@ -14,7 +14,7 @@ use crate::dom::bindings::root::DomRoot;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use js::jsapi::JS_GetArrayBufferViewBuffer;
use js::jsapi::{Heap, JSAutoCompartment, JSContext, JSObject};
use js::jsapi::{Heap, JSAutoRealm, JSContext, JSObject};
use js::rust::wrappers::JS_DetachArrayBuffer;
use js::rust::CustomAutoRooterGuard;
use js::typedarray::{CreateWith, Float32Array};
@ -127,7 +127,7 @@ impl AudioBuffer {
#[allow(unsafe_code)]
unsafe fn restore_js_channel_data(&self, cx: *mut JSContext) -> bool {
let global = self.global();
let _ac = JSAutoCompartment::new(cx, global.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, global.reflector().get_jsobject().get());
for (i, channel) in self.js_channels.borrow_mut().iter().enumerate() {
if !channel.get().is_null() {
// Already have data in JS array.

View file

@ -14,9 +14,9 @@ use crate::dom::bindings::utils::AsCCharPtrPtr;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use js::jsapi::Heap;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSAutoRealm;
use js::jsapi::{AddRawValueRoot, IsCallable, JSContext, JSObject};
use js::jsapi::{JSCompartment, JS_EnterCompartment, JS_LeaveCompartment, RemoveRawValueRoot};
use js::jsapi::{EnterRealm, LeaveRealm, Realm, RemoveRawValueRoot};
use js::jsval::{JSVal, ObjectValue, UndefinedValue};
use js::rust::wrappers::{JS_GetProperty, JS_WrapObject};
use js::rust::{MutableHandleObject, Runtime};
@ -229,7 +229,7 @@ pub struct CallSetup {
/// The `JSContext` used for the call.
cx: *mut JSContext,
/// The compartment we were in before the call.
old_compartment: *mut JSCompartment,
old_realm: *mut Realm,
/// The exception handling used for the call.
handling: ExceptionHandling,
/// <https://heycam.github.io/webidl/#es-invoking-callback-functions>
@ -255,7 +255,7 @@ impl CallSetup {
CallSetup {
exception_global: global,
cx: cx,
old_compartment: unsafe { JS_EnterCompartment(cx, callback.callback()) },
old_realm: unsafe { EnterRealm(cx, callback.callback()) },
handling: handling,
entry_script: Some(aes),
incumbent_script: ais,
@ -271,9 +271,9 @@ impl CallSetup {
impl Drop for CallSetup {
fn drop(&mut self) {
unsafe {
JS_LeaveCompartment(self.cx, self.old_compartment);
LeaveRealm(self.cx, self.old_realm);
if self.handling == ExceptionHandling::Report {
let _ac = JSAutoCompartment::new(
let _ac = JSAutoRealm::new(
self.cx,
self.exception_global.reflector().get_jsobject().get(),
);

View file

@ -458,7 +458,7 @@ class CGMethodCall(CGThing):
pickFirstSignature("%s.get().is_object() && "
"{ rooted!(in(cx) let obj = %s.get().to_object()); "
"let mut is_date = false; "
"assert!(JS_ObjectIsDate(cx, obj.handle(), &mut is_date)); "
"assert!(ObjectIsDate(cx, obj.handle(), &mut is_date)); "
"is_date }" %
(distinguishingArg, distinguishingArg),
lambda s: (s[1][distinguishingIndex].type.isDate() or
@ -795,7 +795,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
# our own implementation code.
templateBody = fill(
"""
{ // Scope for our JSAutoCompartment.
{ // Scope for our JSAutoRealm.
rooted!(in(cx) let globalObj = CurrentGlobalOrNull(cx));
let promiseGlobal = GlobalScope::from_object_maybe_wrapped(globalObj.handle().get());
@ -2709,7 +2709,7 @@ assert!(!scope.get().is_null());
assert!(((*get_object_class(scope.get())).flags & JSCLASS_IS_GLOBAL) != 0);
rooted!(in(cx) let mut proto = ptr::null_mut::<JSObject>());
let _ac = JSAutoCompartment::new(cx, scope.get());
let _ac = JSAutoRealm::new(cx, scope.get());
GetProtoObject(cx, scope, proto.handle_mut());
assert!(!proto.is_null());
@ -2764,7 +2764,7 @@ assert!(!obj.is_null());
(*raw).init_reflector(obj.get());
let _ac = JSAutoCompartment::new(cx, obj.get());
let _ac = JSAutoRealm::new(cx, obj.get());
rooted!(in(cx) let mut proto = ptr::null_mut::<JSObject>());
GetProtoObject(cx, obj.handle(), proto.handle_mut());
assert!(JS_SplicePrototype(cx, obj.handle(), proto.handle()));
@ -2883,7 +2883,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
name = self.descriptor.interface.identifier.name
if self.descriptor.interface.isNamespace():
if self.descriptor.interface.getExtendedAttribute("ProtoObjectHack"):
proto = "JS_GetObjectPrototype(cx, global)"
proto = "GetRealmObjectPrototype(cx)"
else:
proto = "JS_NewPlainObject(cx)"
if self.properties.static_methods.length():
@ -2919,11 +2919,12 @@ assert!((*cache)[PrototypeList::Constructor::%(id)s as usize].is_null());
parentName = self.descriptor.getParentName()
if not parentName:
if self.descriptor.interface.getExtendedAttribute("ExceptionClass"):
getPrototypeProto = "prototype_proto.set(JS_GetErrorPrototype(cx))"
protoGetter = "GetRealmErrorPrototype"
elif self.descriptor.interface.isIteratorInterface():
getPrototypeProto = "prototype_proto.set(JS_GetIteratorPrototype(cx))"
protoGetter = "GetRealmIteratorPrototype"
else:
getPrototypeProto = "prototype_proto.set(JS_GetObjectPrototype(cx, global))"
protoGetter = "GetRealmObjectPrototype"
getPrototypeProto = "prototype_proto.set(%s(cx))" % protoGetter
else:
getPrototypeProto = ("%s::GetProtoObject(cx, global, prototype_proto.handle_mut())" %
toBindingNamespace(parentName))
@ -2981,14 +2982,13 @@ assert!((*cache)[PrototypeList::ID::%(id)s as usize].is_null());
else:
properties["length"] = 0
parentName = self.descriptor.getParentName()
code.append(CGGeneric("rooted!(in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());"))
if parentName:
parentName = toBindingNamespace(parentName)
code.append(CGGeneric("""
rooted!(in(cx) let mut interface_proto = ptr::null_mut::<JSObject>());
%s::GetConstructorObject(cx, global, interface_proto.handle_mut());""" % parentName))
else:
code.append(CGGeneric("""
rooted!(in(cx) let interface_proto = JS_GetFunctionPrototype(cx, global));"""))
code.append(CGGeneric("interface_proto.set(GetRealmFunctionPrototype(cx));"))
code.append(CGGeneric("""\
assert!(!interface_proto.is_null());
@ -5544,7 +5544,7 @@ if args.callee() == new_target.get() {
rooted!(in(cx) let mut prototype = ptr::null_mut::<JSObject>());
{
rooted!(in(cx) let mut proto_val = UndefinedValue());
let _ac = JSAutoCompartment::new(cx, new_target.get());
let _ac = JSAutoRealm::new(cx, new_target.get());
if !JS_GetProperty(cx, new_target.handle(), b"prototype\\0".as_ptr() as *const _, proto_val.handle_mut()) {
return false;
}
@ -5765,7 +5765,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::jsapi::Heap',
'js::jsapi::INTERNED_STRING_TO_JSID',
'js::jsapi::IsCallable',
'js::jsapi::JSAutoCompartment',
'js::jsapi::JSAutoRealm',
'js::jsapi::JSCLASS_FOREGROUND_FINALIZE',
'js::jsapi::JSCLASS_RESERVED_SLOTS_SHIFT',
'js::jsapi::JSClass',
@ -5804,11 +5804,10 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::rust::wrappers::JS_DefineProperty',
'js::rust::wrappers::JS_DefinePropertyById2',
'js::jsapi::JS_ForwardGetPropertyTo',
'js::jsapi::JS_GetErrorPrototype',
'js::rust::wrappers::JS_GetFunctionPrototype',
'js::jsapi::JS_GetGlobalForObject',
'js::jsapi::JS_GetIteratorPrototype',
'js::rust::wrappers::JS_GetObjectPrototype',
'js::jsapi::GetRealmErrorPrototype',
'js::jsapi::GetRealmFunctionPrototype',
'js::jsapi::GetRealmIteratorPrototype',
'js::jsapi::GetRealmObjectPrototype',
'js::rust::wrappers::JS_GetProperty',
'js::jsapi::JS_GetPropertyById',
'js::jsapi::JS_GetPropertyDescriptorById',
@ -5819,7 +5818,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::jsapi::JS_NewObject',
'js::rust::wrappers::JS_NewObjectWithGivenProto',
'js::rust::wrappers::JS_NewObjectWithoutMetadata',
'js::rust::wrappers::JS_ObjectIsDate',
'js::rust::wrappers::ObjectIsDate',
'js::rust::wrappers::JS_SetImmutablePrototype',
'js::rust::wrappers::JS_SetProperty',
'js::rust::wrappers::JS_SetPrototype',

View file

@ -81,7 +81,7 @@ use html5ever::interface::QualName;
use html5ever::LocalName;
use js::glue::UnwrapObject;
use js::jsapi::{CallArgs, CurrentGlobalOrNull};
use js::jsapi::{JSAutoCompartment, JSContext, JSObject};
use js::jsapi::{JSAutoRealm, JSContext, JSObject};
use js::rust::HandleObject;
use js::rust::MutableHandleObject;
use std::ptr;
@ -115,7 +115,7 @@ where
}
{
let _ac = JSAutoCompartment::new(window.get_cx(), callee.get());
let _ac = JSAutoRealm::new(window.get_cx(), callee.get());
rooted!(in(window.get_cx()) let mut constructor = ptr::null_mut::<JSObject>());
rooted!(in(window.get_cx()) let global_object = CurrentGlobalOrNull(window.get_cx()));

View file

@ -16,11 +16,9 @@ use js::error::throw_type_error;
use js::glue::{UncheckedUnwrapObject, RUST_SYMBOL_TO_JSID};
use js::jsapi::HandleObject as RawHandleObject;
use js::jsapi::MutableHandleValue as RawMutableHandleValue;
use js::jsapi::{Class, ClassOps, CompartmentOptions};
use js::jsapi::{GetGlobalForObjectCrossCompartment, GetWellKnownSymbol};
use js::jsapi::{
JSAutoCompartment, JSClass, JSContext, JSFunctionSpec, JSObject, JSFUN_CONSTRUCTOR,
};
use js::jsapi::{Class, ClassOps, RealmOptions};
use js::jsapi::{GetNonCCWObjectGlobal, GetWellKnownSymbol};
use js::jsapi::{JSAutoRealm, JSClass, JSContext, JSFunctionSpec, JSObject, JSFUN_CONSTRUCTOR};
use js::jsapi::{JSPropertySpec, JSString, JSTracer, JS_AtomizeAndPinString};
use js::jsapi::{JS_GetFunctionObject, JS_NewFunction, JS_NewGlobalObject};
use js::jsapi::{JS_NewObject, JS_NewPlainObject};
@ -29,8 +27,8 @@ use js::jsapi::{ObjectOps, OnNewGlobalHookOption, SymbolCode};
use js::jsapi::{TrueHandleValue, Value};
use js::jsapi::{JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_RESOLVING};
use js::jsval::{JSVal, PrivateValue};
use js::rust::wrappers::{JS_DefineProperty, JS_DefineProperty2};
use js::rust::wrappers::{JS_DefineProperty3, JS_DefineProperty4, JS_DefinePropertyById4};
use js::rust::wrappers::{JS_DefineProperty, JS_DefineProperty5};
use js::rust::wrappers::{JS_DefineProperty3, JS_DefineProperty4, JS_DefinePropertyById5};
use js::rust::wrappers::{JS_FireOnNewGlobalObject, JS_GetPrototype};
use js::rust::wrappers::{JS_LinkConstructorAndPrototype, JS_NewObjectWithUniqueType};
use js::rust::{define_methods, define_properties, get_object_class};
@ -138,7 +136,7 @@ pub unsafe fn create_global_object(
) {
assert!(rval.is_null());
let mut options = CompartmentOptions::default();
let mut options = RealmOptions::default();
options.creationOptions_.traceGlobal_ = Some(trace);
options.creationOptions_.sharedMemoryAndAtomics_ = true;
@ -160,7 +158,7 @@ pub unsafe fn create_global_object(
let val = PrivateValue(Box::into_raw(proto_array) as *const libc::c_void);
JS_SetReservedSlot(rval.get(), DOM_PROTOTYPE_SLOT, &val);
let _ac = JSAutoCompartment::new(cx, rval.get());
let _ac = JSAutoRealm::new(cx, rval.get());
JS_FireOnNewGlobalObject(cx, rval.handle());
}
@ -209,7 +207,7 @@ pub unsafe fn create_interface_prototype_object(
assert!(!unscopable_symbol.is_null());
rooted!(in(cx) let unscopable_id = RUST_SYMBOL_TO_JSID(unscopable_symbol));
assert!(JS_DefinePropertyById4(
assert!(JS_DefinePropertyById5(
cx,
rval.handle(),
unscopable_id.handle(),
@ -275,7 +273,7 @@ pub unsafe fn create_named_constructors(
constructor.set(JS_GetFunctionObject(fun));
assert!(!constructor.is_null());
assert!(JS_DefineProperty2(
assert!(JS_DefineProperty3(
cx,
constructor.handle(),
b"prototype\0".as_ptr() as *const libc::c_char,
@ -360,7 +358,7 @@ pub unsafe fn define_on_global_object(
obj: HandleObject,
) {
assert_eq!(*name.last().unwrap(), b'\0');
assert!(JS_DefineProperty2(
assert!(JS_DefineProperty3(
cx,
global,
name.as_ptr() as *const libc::c_char,
@ -442,7 +440,7 @@ unsafe fn has_instance(
}
// Step 2.
let global = GetGlobalForObjectCrossCompartment(interface_object.get());
let global = GetNonCCWObjectGlobal(interface_object.get());
assert!(!global.is_null());
let proto_or_iface_array = get_proto_or_iface_array(global);
rooted!(in(cx) let prototype = (*proto_or_iface_array)[object_class.proto_id as usize]);
@ -488,7 +486,7 @@ unsafe fn define_name(cx: *mut JSContext, obj: HandleObject, name: &[u8]) {
assert_eq!(*name.last().unwrap(), b'\0');
rooted!(in(cx) let name = JS_AtomizeAndPinString(cx, name.as_ptr() as *const libc::c_char));
assert!(!name.is_null());
assert!(JS_DefineProperty3(
assert!(JS_DefineProperty4(
cx,
obj,
b"name\0".as_ptr() as *const libc::c_char,
@ -498,7 +496,7 @@ unsafe fn define_name(cx: *mut JSContext, obj: HandleObject, name: &[u8]) {
}
unsafe fn define_length(cx: *mut JSContext, obj: HandleObject, length: i32) {
assert!(JS_DefineProperty4(
assert!(JS_DefineProperty5(
cx,
obj,
b"length\0".as_ptr() as *const libc::c_char,

View file

@ -22,7 +22,7 @@ use js::jsapi::MutableHandleObject as RawMutableHandleObject;
use js::jsapi::StructuredCloneScope;
use js::jsapi::TransferableOwnership;
use js::jsapi::JS_STRUCTURED_CLONE_VERSION;
use js::jsapi::{JSAutoCompartment, JSContext};
use js::jsapi::{JSAutoRealm, JSContext};
use js::jsapi::{JSObject, JS_ClearPendingException};
use js::jsapi::{JSStructuredCloneCallbacks, JSStructuredCloneReader, JSStructuredCloneWriter};
use js::jsapi::{JS_ReadBytes, JS_WriteBytes};
@ -220,6 +220,14 @@ unsafe extern "C" fn free_transfer_callback(
) {
}
unsafe extern "C" fn can_transfer_callback(
_cx: *mut JSContext,
_obj: RawHandleObject,
_closure: *mut raw::c_void,
) -> bool {
false
}
unsafe extern "C" fn report_error_callback(_cx: *mut JSContext, _errorid: u32) {}
static STRUCTURED_CLONE_CALLBACKS: JSStructuredCloneCallbacks = JSStructuredCloneCallbacks {
@ -229,6 +237,7 @@ static STRUCTURED_CLONE_CALLBACKS: JSStructuredCloneCallbacks = JSStructuredClon
readTransfer: Some(read_transfer_callback),
writeTransfer: Some(write_transfer_callback),
freeTransfer: Some(free_transfer_callback),
canTransfer: Some(can_transfer_callback),
};
struct StructuredCloneHolder {
@ -299,7 +308,7 @@ impl StructuredCloneData {
fn read_clone(global: &GlobalScope, data: *mut u64, nbytes: size_t, rval: MutableHandleValue) {
let cx = global.get_cx();
let globalhandle = global.reflector().get_jsobject();
let _ac = JSAutoCompartment::new(cx, globalhandle.get());
let _ac = JSAutoRealm::new(cx, globalhandle.get());
let mut sc_holder = StructuredCloneHolder { blob: None };
let sc_holder_ptr = &mut sc_holder as *mut _;
unsafe {

View file

@ -20,8 +20,8 @@ use js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_ST
use js::jsapi::HandleId as RawHandleId;
use js::jsapi::HandleObject as RawHandleObject;
use js::jsapi::MutableHandleObject as RawMutableHandleObject;
use js::jsapi::{CallArgs, DOMCallbacks, GetGlobalForObjectCrossCompartment};
use js::jsapi::{Heap, JSAutoCompartment, JSContext};
use js::jsapi::{CallArgs, DOMCallbacks, GetNonCCWObjectGlobal};
use js::jsapi::{Heap, JSAutoRealm, JSContext};
use js::jsapi::{JSJitInfo, JSObject, JSTracer, JSWrapObjectCallbacks};
use js::jsapi::{JS_EnumerateStandardClasses, JS_GetLatin1StringCharsAndLength};
use js::jsapi::{JS_IsExceptionPending, JS_IsGlobalObject};
@ -408,7 +408,7 @@ unsafe extern "C" fn pre_wrap(
_object_passed_to_wrap: RawHandleObject,
rval: RawMutableHandleObject,
) {
let _ac = JSAutoCompartment::new(cx, obj.get());
let _ac = JSAutoRealm::new(cx, obj.get());
let obj = ToWindowProxyIfWindow(obj.get());
assert!(!obj.is_null());
rval.set(obj)
@ -455,12 +455,11 @@ unsafe fn generic_call(
return false;
}
let obj = if thisobj.get().is_object() {
rooted!(in(cx) let obj = if thisobj.get().is_object() {
thisobj.get().to_object()
} else {
GetGlobalForObjectCrossCompartment(JS_CALLEE(cx, vp).to_object_or_null())
};
rooted!(in(cx) let obj = obj);
GetNonCCWObjectGlobal(JS_CALLEE(cx, vp).to_object_or_null())
});
let depth = (*info).depth;
let proto_check =
|class: &'static DOMClass| class.interface_chain[depth as usize] as u16 == proto_id;

View file

@ -116,7 +116,7 @@ where
fn response(&mut self, response: BluetoothResponseResult) {
let promise = self.promise.take().expect("bt promise is missing").root();
// JSAutoCompartment needs to be manually made.
// JSAutoRealm needs to be manually made.
// Otherwise, Servo will crash.
match response {
Ok(response) => self.receiver.root().handle_response(response, &promise),

View file

@ -82,7 +82,7 @@ use crate::dom::htmlvideoelement::HTMLVideoElement;
use crate::dom::svgsvgelement::SVGSVGElement;
use crate::script_thread::ScriptThread;
use html5ever::{LocalName, Prefix, QualName};
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSAutoRealm;
use servo_config::pref;
fn create_svg_element(
@ -156,10 +156,8 @@ fn create_html_element(
// Step 6.1.1
unsafe {
let _ac = JSAutoCompartment::new(
cx,
global.reflector().get_jsobject().get(),
);
let _ac =
JSAutoRealm::new(cx, global.reflector().get_jsobject().get());
throw_dom_exception(cx, &global, error);
report_pending_exception(cx, true);
}

View file

@ -37,9 +37,9 @@ use html5ever::{LocalName, Namespace, Prefix};
use js::conversions::ToJSValConvertible;
use js::glue::UnwrapObject;
use js::jsapi::{HandleValueArray, Heap, IsCallable, IsConstructor};
use js::jsapi::{JSAutoCompartment, JSContext, JSObject};
use js::jsapi::{JSAutoRealm, JSContext, JSObject};
use js::jsval::{JSVal, NullValue, ObjectValue, UndefinedValue};
use js::rust::wrappers::{Construct1, JS_GetProperty, JS_SameValue};
use js::rust::wrappers::{Construct1, JS_GetProperty, SameValue};
use js::rust::{HandleObject, HandleValue, MutableHandleValue};
use std::cell::Cell;
use std::collections::{HashMap, VecDeque};
@ -324,7 +324,7 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
// Steps 10.1 - 10.2
rooted!(in(cx) let mut prototype = UndefinedValue());
{
let _ac = JSAutoCompartment::new(cx, constructor.get());
let _ac = JSAutoRealm::new(cx, constructor.get());
if let Err(error) = self.check_prototype(constructor.handle(), prototype.handle_mut()) {
self.element_definition_is_running.set(false);
return Err(error);
@ -334,7 +334,7 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
// Steps 10.3 - 10.4
rooted!(in(cx) let proto_object = prototype.to_object());
let callbacks = {
let _ac = JSAutoCompartment::new(cx, proto_object.get());
let _ac = JSAutoRealm::new(cx, proto_object.get());
match unsafe { self.get_callbacks(proto_object.handle()) } {
Ok(callbacks) => callbacks,
Err(error) => {
@ -346,7 +346,7 @@ impl CustomElementRegistryMethods for CustomElementRegistry {
// Step 10.5 - 10.6
let observed_attributes = if callbacks.attribute_changed_callback.is_some() {
let _ac = JSAutoCompartment::new(cx, constructor.get());
let _ac = JSAutoRealm::new(cx, constructor.get());
match self.get_observed_attributes(constructor.handle()) {
Ok(attributes) => attributes,
Err(error) => {
@ -535,7 +535,7 @@ impl CustomElementDefinition {
rooted!(in(cx) let mut element = ptr::null_mut::<JSObject>());
{
// Go into the constructor's compartment
let _ac = JSAutoCompartment::new(cx, self.constructor.callback());
let _ac = JSAutoRealm::new(cx, self.constructor.callback());
let args = HandleValueArray::new();
if unsafe { !Construct1(cx, constructor.handle(), &args, element.handle_mut()) } {
return Err(Error::JSFailed);
@ -665,7 +665,7 @@ fn run_upgrade_constructor(
rooted!(in(cx) let mut construct_result = ptr::null_mut::<JSObject>());
{
// Go into the constructor's compartment
let _ac = JSAutoCompartment::new(cx, constructor.callback());
let _ac = JSAutoRealm::new(cx, constructor.callback());
let args = HandleValueArray::new();
// Step 7.1
if unsafe {
@ -682,7 +682,7 @@ fn run_upgrade_constructor(
let mut same = false;
rooted!(in(cx) let construct_result_val = ObjectValue(construct_result.get()));
if unsafe {
!JS_SameValue(
!SameValue(
cx,
construct_result_val.handle(),
element_val.handle(),

View file

@ -33,7 +33,7 @@ use dom_struct::dom_struct;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use js::jsapi::JS_AddInterruptCallback;
use js::jsapi::{JSAutoCompartment, JSContext};
use js::jsapi::{JSAutoRealm, JSContext};
use js::jsval::UndefinedValue;
use js::rust::HandleValue;
use msg::constellation_msg::{PipelineId, TopLevelBrowsingContextId};
@ -433,8 +433,7 @@ impl DedicatedWorkerGlobalScope {
WorkerScriptMsg::DOMMessage(data) => {
let scope = self.upcast::<WorkerGlobalScope>();
let target = self.upcast();
let _ac =
JSAutoCompartment::new(scope.get_cx(), scope.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(scope.get_cx(), scope.reflector().get_jsobject().get());
rooted!(in(scope.get_cx()) let mut message = UndefinedValue());
data.read(scope.upcast(), message.handle_mut());
MessageEvent::dispatch_jsval(target, scope.upcast(), message.handle(), None, None);

View file

@ -28,7 +28,7 @@ use http::header::{self, HeaderName, HeaderValue};
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use js::conversions::ToJSValConvertible;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSAutoRealm;
use js::jsval::UndefinedValue;
use mime::{self, Mime};
use net_traits::request::{CacheMode, CorsSettings, CredentialsMode};
@ -222,7 +222,7 @@ impl EventSourceContext {
};
// Steps 4-5
let event = {
let _ac = JSAutoCompartment::new(
let _ac = JSAutoRealm::new(
event_source.global().get_cx(),
event_source.reflector().get_jsobject().get(),
);

View file

@ -34,10 +34,10 @@ use crate::dom::virtualmethods::VirtualMethods;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use fnv::FnvHasher;
use js::jsapi::{JSAutoCompartment, JSFunction, JS_GetFunctionObject};
use js::jsapi::{JSAutoRealm, JSFunction, JS_GetFunctionObject, SourceText};
use js::rust::wrappers::CompileFunction;
use js::rust::{AutoObjectVectorWrapper, CompileOptionsWrapper};
use libc::{c_char, size_t};
use libc::c_char;
use servo_atoms::Atom;
use servo_url::ServoUrl;
use std::collections::hash_map::Entry::{Occupied, Vacant};
@ -45,6 +45,7 @@ use std::collections::HashMap;
use std::default::Default;
use std::ffi::CString;
use std::hash::BuildHasherDefault;
use std::marker::PhantomData;
use std::mem;
use std::ops::{Deref, DerefMut};
use std::ptr;
@ -505,7 +506,7 @@ impl EventTarget {
let scopechain = AutoObjectVectorWrapper::new(cx);
let _ac = JSAutoCompartment::new(cx, window.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, window.reflector().get_jsobject().get());
rooted!(in(cx) let mut handler = ptr::null_mut::<JSFunction>());
let rv = unsafe {
CompileFunction(
@ -515,15 +516,19 @@ impl EventTarget {
name.as_ptr(),
args.len() as u32,
args.as_ptr(),
body.as_ptr(),
body.len() as size_t,
&mut SourceText {
units_: body.as_ptr() as *const _,
length_: body.len() as u32,
ownsUnits_: false,
_phantom_0: PhantomData,
},
handler.handle_mut().into(),
)
};
if !rv || handler.get().is_null() {
// Step 1.8.2
unsafe {
let _ac = JSAutoCompartment::new(cx, self.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, self.reflector().get_jsobject().get());
// FIXME(#13152): dispatch error event.
report_pending_exception(cx, false);
}

View file

@ -28,7 +28,7 @@ use base64;
use dom_struct::dom_struct;
use encoding_rs::{Encoding, UTF_8};
use js::jsapi::Heap;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSAutoRealm;
use js::jsapi::JSContext;
use js::jsapi::JSObject;
use js::jsval::{self, JSVal};
@ -262,8 +262,7 @@ impl FileReader {
FileReader::perform_readastext(&fr.result, data, &blob_contents)
},
FileReaderFunction::ReadAsArrayBuffer => {
let _ac =
JSAutoCompartment::new(fr.global().get_cx(), *fr.reflector().get_jsobject());
let _ac = JSAutoRealm::new(fr.global().get_cx(), *fr.reflector().get_jsobject());
FileReader::perform_readasarraybuffer(
&fr.result,
fr.global().get_cx(),

View file

@ -42,11 +42,11 @@ use dom_struct::dom_struct;
use ipc_channel::ipc::IpcSender;
use js::glue::{IsWrapper, UnwrapObject};
use js::jsapi::JSObject;
use js::jsapi::{CurrentGlobalOrNull, GetGlobalForObjectCrossCompartment};
use js::jsapi::{CurrentGlobalOrNull, GetNonCCWObjectGlobal};
use js::jsapi::{HandleObject, Heap};
use js::jsapi::{JSAutoCompartment, JSContext};
use js::jsapi::{JSAutoRealm, JSContext};
use js::panic::maybe_resume_unwind;
use js::rust::wrappers::Evaluate2;
use js::rust::wrappers::EvaluateUtf8;
use js::rust::{get_object_class, CompileOptionsWrapper, ParentRuntime, Runtime};
use js::rust::{HandleValue, MutableHandleValue};
use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
@ -230,7 +230,7 @@ impl GlobalScope {
#[allow(unsafe_code)]
pub unsafe fn from_object(obj: *mut JSObject) -> DomRoot<Self> {
assert!(!obj.is_null());
let global = GetGlobalForObjectCrossCompartment(obj);
let global = GetNonCCWObjectGlobal(obj);
global_scope_from_global(global)
}
@ -540,19 +540,18 @@ impl GlobalScope {
|| {
let cx = self.get_cx();
let globalhandle = self.reflector().get_jsobject();
let code: Vec<u16> = code.encode_utf16().collect();
let filename = CString::new(filename).unwrap();
let _ac = JSAutoCompartment::new(cx, globalhandle.get());
let _ac = JSAutoRealm::new(cx, globalhandle.get());
let _aes = AutoEntryScript::new(self);
let options = CompileOptionsWrapper::new(cx, filename.as_ptr(), line_number);
debug!("evaluating Dom string");
let result = unsafe {
Evaluate2(
EvaluateUtf8(
cx,
options.ptr,
code.as_ptr(),
code.as_ptr() as *const _,
code.len() as libc::size_t,
rval,
)

View file

@ -31,7 +31,7 @@ use js::jsapi::HandleValueArray;
use js::jsapi::Heap;
use js::jsapi::IsCallable;
use js::jsapi::IsConstructor;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSAutoRealm;
use js::jsapi::JSObject;
use js::jsapi::JS_ClearPendingException;
use js::jsapi::JS_IsExceptionPending;
@ -252,7 +252,7 @@ impl PaintWorkletGlobalScope {
);
let cx = self.worklet_global.get_cx();
let _ac = JSAutoCompartment::new(cx, self.worklet_global.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, self.worklet_global.reflector().get_jsobject().get());
// TODO: Steps 1-2.1.
// Step 2.2-5.1.

View file

@ -22,7 +22,7 @@ use dom_struct::dom_struct;
use js::conversions::ToJSValConvertible;
use js::jsapi::{AddRawValueRoot, CallArgs, GetFunctionNativeReserved};
use js::jsapi::{Heap, JS_ClearPendingException};
use js::jsapi::{JSAutoCompartment, JSContext, JSObject, JS_GetFunctionObject};
use js::jsapi::{JSAutoRealm, JSContext, JSObject, JS_GetFunctionObject};
use js::jsapi::{JS_NewFunction, NewFunctionWithReserved, PromiseState};
use js::jsapi::{RemoveRawValueRoot, SetFunctionNativeReserved};
use js::jsval::{Int32Value, JSVal, ObjectValue, UndefinedValue};
@ -82,7 +82,7 @@ impl Drop for Promise {
impl Promise {
pub fn new(global: &GlobalScope) -> Rc<Promise> {
let compartment =
JSAutoCompartment::new(global.get_cx(), global.reflector().get_jsobject().get());
JSAutoRealm::new(global.get_cx(), global.reflector().get_jsobject().get());
let comp = InCompartment::Entered(&compartment);
Promise::new_in_current_compartment(global, comp)
}
@ -142,7 +142,7 @@ impl Promise {
cx: *mut JSContext,
value: HandleValue,
) -> Fallible<Rc<Promise>> {
let _ac = JSAutoCompartment::new(cx, global.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, global.reflector().get_jsobject().get());
rooted!(in(cx) let p = CallOriginalPromiseResolve(cx, value));
assert!(!p.handle().is_null());
Ok(Promise::new_with_js_promise(p.handle(), cx))
@ -154,7 +154,7 @@ impl Promise {
cx: *mut JSContext,
value: HandleValue,
) -> Fallible<Rc<Promise>> {
let _ac = JSAutoCompartment::new(cx, global.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, global.reflector().get_jsobject().get());
rooted!(in(cx) let p = CallOriginalPromiseReject(cx, value));
assert!(!p.handle().is_null());
Ok(Promise::new_with_js_promise(p.handle(), cx))
@ -166,7 +166,7 @@ impl Promise {
T: ToJSValConvertible,
{
let cx = self.global().get_cx();
let _ac = JSAutoCompartment::new(cx, self.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, self.reflector().get_jsobject().get());
rooted!(in(cx) let mut v = UndefinedValue());
unsafe {
val.to_jsval(cx, v.handle_mut());
@ -187,7 +187,7 @@ impl Promise {
T: ToJSValConvertible,
{
let cx = self.global().get_cx();
let _ac = JSAutoCompartment::new(cx, self.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, self.reflector().get_jsobject().get());
rooted!(in(cx) let mut v = UndefinedValue());
unsafe {
val.to_jsval(cx, v.handle_mut());
@ -198,7 +198,7 @@ impl Promise {
#[allow(unsafe_code)]
pub fn reject_error(&self, error: Error) {
let cx = self.global().get_cx();
let _ac = JSAutoCompartment::new(cx, self.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, self.reflector().get_jsobject().get());
rooted!(in(cx) let mut v = UndefinedValue());
unsafe {
error.to_jsval(cx, &self.global(), v.handle_mut());

View file

@ -28,7 +28,7 @@ use devtools_traits::DevtoolScriptControlMsg;
use dom_struct::dom_struct;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use js::jsapi::{JSAutoCompartment, JSContext, JS_AddInterruptCallback};
use js::jsapi::{JSAutoRealm, JSContext, JS_AddInterruptCallback};
use js::jsval::UndefinedValue;
use msg::constellation_msg::PipelineId;
use net_traits::request::{CredentialsMode, Destination, Referrer, RequestBuilder};
@ -406,8 +406,7 @@ impl ServiceWorkerGlobalScope {
CommonWorker(WorkerScriptMsg::DOMMessage(data)) => {
let scope = self.upcast::<WorkerGlobalScope>();
let target = self.upcast();
let _ac =
JSAutoCompartment::new(scope.get_cx(), scope.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(scope.get_cx(), scope.reflector().get_jsobject().get());
rooted!(in(scope.get_cx()) let mut message = UndefinedValue());
data.read(scope.upcast(), message.handle_mut());
ExtendableMessageEvent::dispatch_jsval(target, scope.upcast(), message.handle());

View file

@ -27,7 +27,7 @@ use crate::task_source::websocket::WebsocketTaskSource;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use js::jsapi::{JSAutoCompartment, JSObject};
use js::jsapi::{JSAutoRealm, JSObject};
use js::jsval::UndefinedValue;
use js::rust::CustomAutoRooterGuard;
use js::typedarray::{ArrayBuffer, ArrayBufferView, CreateWith};
@ -570,7 +570,7 @@ impl TaskOnce for MessageReceivedTask {
// global.get_cx() returns a valid `JSContext` pointer, so this is safe.
unsafe {
let cx = global.get_cx();
let _ac = JSAutoCompartment::new(cx, ws.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, ws.reflector().get_jsobject().get());
rooted!(in(cx) let mut message = UndefinedValue());
match self.message {
MessageData::Text(text) => text.to_jsval(cx, message.handle_mut()),

View file

@ -76,10 +76,10 @@ use embedder_traits::EmbedderMsg;
use euclid::{Point2D, Rect, Size2D, TypedPoint2D, TypedScale, TypedSize2D, Vector2D};
use ipc_channel::ipc::{channel, IpcSender};
use ipc_channel::router::ROUTER;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSAutoRealm;
use js::jsapi::JSContext;
use js::jsapi::JSPROP_ENUMERATE;
use js::jsapi::JS_GC;
use js::jsapi::{GCReason, JS_GC};
use js::jsval::JSVal;
use js::jsval::UndefinedValue;
use js::rust::wrappers::JS_DefineProperty;
@ -901,7 +901,7 @@ impl WindowMethods for Window {
#[allow(unsafe_code)]
fn Gc(&self) {
unsafe {
JS_GC(self.get_cx());
JS_GC(self.get_cx(), GCReason::API);
}
}
@ -2213,7 +2213,7 @@ impl Window {
// Steps 7.2.-7.5.
let cx = this.get_cx();
let obj = this.reflector().get_jsobject();
let _ac = JSAutoCompartment::new(cx, obj.get());
let _ac = JSAutoRealm::new(cx, obj.get());
rooted!(in(cx) let mut message_clone = UndefinedValue());
serialize_with_transfer_result.read(
this.upcast(),

View file

@ -31,7 +31,7 @@ use js::jsapi::HandleValue as RawHandleValue;
use js::jsapi::MutableHandle as RawMutableHandle;
use js::jsapi::MutableHandleObject as RawMutableHandleObject;
use js::jsapi::MutableHandleValue as RawMutableHandleValue;
use js::jsapi::{JSAutoCompartment, JSContext, JSErrNum, JSFreeOp, JSObject};
use js::jsapi::{JSAutoRealm, JSContext, JSErrNum, JSFreeOp, JSObject};
use js::jsapi::{JSTracer, JS_DefinePropertyById, JSPROP_ENUMERATE, JSPROP_READONLY};
use js::jsapi::{JS_ForwardGetPropertyTo, JS_ForwardSetPropertyTo};
use js::jsapi::{JS_GetOwnPropertyDescriptorById, JS_IsExceptionPending};
@ -148,7 +148,7 @@ impl WindowProxy {
((*get_object_class(window_jsobject.get())).flags & JSCLASS_IS_GLOBAL),
0
);
let _ac = JSAutoCompartment::new(cx, window_jsobject.get());
let _ac = JSAutoRealm::new(cx, window_jsobject.get());
// Create a new window proxy.
rooted!(in(cx) let js_proxy = NewWindowProxy(cx, window_jsobject, handler));
@ -219,7 +219,7 @@ impl WindowProxy {
((*get_object_class(window_jsobject.get())).flags & JSCLASS_IS_GLOBAL),
0
);
let _ac = JSAutoCompartment::new(cx, window_jsobject.get());
let _ac = JSAutoRealm::new(cx, window_jsobject.get());
// Create a new window proxy.
rooted!(in(cx) let js_proxy = NewWindowProxy(cx, window_jsobject, handler));
@ -548,7 +548,7 @@ impl WindowProxy {
((*get_object_class(window_jsobject.get())).flags & JSCLASS_IS_GLOBAL),
0
);
let _ac = JSAutoCompartment::new(cx, window_jsobject.get());
let _ac = JSAutoRealm::new(cx, window_jsobject.get());
// The old window proxy no longer owns this browsing context.
SetProxyReservedSlot(old_js_proxy.get(), 0, &PrivateValue(ptr::null_mut()));

View file

@ -25,7 +25,7 @@ use crossbeam_channel::{unbounded, Sender};
use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg};
use dom_struct::dom_struct;
use ipc_channel::ipc;
use js::jsapi::{JSAutoCompartment, JSContext, JS_RequestInterruptCallback};
use js::jsapi::{JSAutoRealm, JSContext, JS_RequestInterruptCallback};
use js::jsval::UndefinedValue;
use js::rust::HandleValue;
use script_traits::WorkerScriptLoadOrigin;
@ -137,7 +137,7 @@ impl Worker {
let global = worker.global();
let target = worker.upcast();
let _ac = JSAutoCompartment::new(global.get_cx(), target.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(global.get_cx(), target.reflector().get_jsobject().get());
rooted!(in(global.get_cx()) let mut message = UndefinedValue());
data.read(&global, message.handle_mut());
MessageEvent::dispatch_jsval(target, &global, message.handle(), None, None);

View file

@ -37,7 +37,7 @@ use crossbeam_channel::Receiver;
use devtools_traits::{DevtoolScriptControlMsg, WorkerId};
use dom_struct::dom_struct;
use ipc_channel::ipc::IpcSender;
use js::jsapi::{JSAutoCompartment, JSContext};
use js::jsapi::{JSAutoRealm, JSContext};
use js::jsval::UndefinedValue;
use js::panic::maybe_resume_unwind;
use js::rust::{HandleValue, ParentRuntime};
@ -401,7 +401,7 @@ impl WorkerGlobalScope {
// https://github.com/servo/servo/issues/6422
println!("evaluate_script failed");
unsafe {
let _ac = JSAutoCompartment::new(
let _ac = JSAutoRealm::new(
self.runtime.cx(),
self.reflector().get_jsobject().get(),
);

View file

@ -46,7 +46,7 @@ use dom_struct::dom_struct;
use js::jsapi::JSGCParamKey;
use js::jsapi::JSTracer;
use js::jsapi::JS_GetGCParameter;
use js::jsapi::JS_GC;
use js::jsapi::{GCReason, JS_GC};
use msg::constellation_msg::PipelineId;
use net_traits::request::Destination;
use net_traits::request::RequestBuilder;
@ -568,7 +568,7 @@ impl WorkletThread {
self.current_memory_usage(),
self.gc_threshold
);
unsafe { JS_GC(self.runtime.cx()) };
unsafe { JS_GC(self.runtime.cx(), GCReason::API) };
self.gc_threshold = max(MIN_GC_THRESHOLD, self.current_memory_usage() * 2);
debug!(
"END GC (usage = {}, threshold = {}).",

View file

@ -26,7 +26,7 @@ use crate::network_listener::{
use crate::task_source::TaskSourceName;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JSAutoRealm;
use net_traits::request::RequestBuilder;
use net_traits::request::{Request as NetTraitsRequest, ServiceWorkersMode};
use net_traits::CoreResourceMsg::Fetch as NetTraitsFetch;
@ -210,10 +210,10 @@ impl FetchResponseListener for FetchContext {
.expect("fetch promise is missing")
.root();
// JSAutoCompartment needs to be manually made.
// JSAutoRealm needs to be manually made.
// Otherwise, Servo will crash.
let promise_cx = promise.global().get_cx();
let _ac = JSAutoCompartment::new(promise_cx, promise.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(promise_cx, promise.reflector().get_jsobject().get());
match fetch_metadata {
// Step 4.1
Err(_) => {
@ -263,7 +263,7 @@ impl FetchResponseListener for FetchContext {
let response = self.response_object.root();
let global = response.global();
let cx = global.get_cx();
let _ac = JSAutoCompartment::new(cx, global.reflector().get_jsobject().get());
let _ac = JSAutoRealm::new(cx, global.reflector().get_jsobject().get());
response.finish(mem::replace(&mut self.body, vec![]));
// TODO
// ... trailerObject is not supported in Servo yet.

View file

@ -37,7 +37,9 @@ use js::jsapi::{
JSJitCompilerOption, JS_SetOffthreadIonCompilationEnabled, JS_SetParallelParsingEnabled,
};
use js::jsapi::{JSObject, PromiseRejectionHandlingState, SetPreserveWrapperCallback};
use js::jsapi::{SetBuildIdOp, SetEnqueuePromiseJobCallback, SetPromiseRejectionTrackerCallback};
use js::jsapi::{
SetEnqueuePromiseJobCallback, SetProcessBuildIdOp, SetPromiseRejectionTrackerCallback,
};
use js::panic::wrap_panic;
use js::rust::wrappers::{GetPromiseIsHandled, GetPromiseResult};
use js::rust::Handle;
@ -137,15 +139,15 @@ pub trait ScriptPort {
#[allow(unsafe_code)]
unsafe extern "C" fn enqueue_job(
cx: *mut JSContext,
_promise: HandleObject,
job: HandleObject,
_allocation_site: HandleObject,
_incumbent_global: HandleObject,
incumbent_global: HandleObject,
_data: *mut c_void,
) -> bool {
wrap_panic(
AssertUnwindSafe(|| {
//XXXjdm - use a different global now?
let global = GlobalScope::from_object(job.get());
let global = GlobalScope::from_object(incumbent_global.get());
let pipeline = global.pipeline_id();
global.enqueue_microtask(Microtask::Promise(EnqueuedPromiseCallback {
callback: PromiseJobCallback::new(cx, job.get()),
@ -360,7 +362,7 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option<ParentRuntime>) -> Runtime {
SetGCSliceCallback(cx, Some(gc_slice_callback));
}
unsafe extern "C" fn empty_wrapper_callback(_: *mut JSContext, _: *mut JSObject) -> bool {
unsafe extern "C" fn empty_wrapper_callback(_: *mut JSContext, _: HandleObject) -> bool {
true
}
SetDOMCallbacks(cx, &DOM_CALLBACKS);
@ -384,7 +386,7 @@ unsafe fn new_rt_and_cx_with_parent(parent: Option<ParentRuntime>) -> Runtime {
// If WASM is enabled without setting the buildIdOp,
// initializing a module will report an out of memory error.
// https://dxr.mozilla.org/mozilla-central/source/js/src/wasm/WasmTypes.cpp#458
SetBuildIdOp(cx, Some(servo_build_id));
SetProcessBuildIdOp(Some(servo_build_id));
}
cx_opts.set_wasmBaseline_(pref!(js.wasm.baseline.enabled));
cx_opts.set_wasmIon_(pref!(js.wasm.ion.enabled));

View file

@ -99,7 +99,7 @@ use hyper_serde::Serde;
use ipc_channel::ipc::{self, IpcSender};
use ipc_channel::router::ROUTER;
use js::glue::GetWindowProxyClass;
use js::jsapi::{JSAutoCompartment, JSContext, JS_SetWrapObjectCallbacks};
use js::jsapi::{JSAutoRealm, JSContext, JS_SetWrapObjectCallbacks};
use js::jsapi::{JSTracer, SetWindowProxyClass};
use js::jsval::UndefinedValue;
use js::rust::ParentRuntime;
@ -1971,7 +1971,7 @@ impl ScriptThread {
fn handle_exit_fullscreen(&self, id: PipelineId) {
let document = self.documents.borrow().find_document(id);
if let Some(document) = document {
let _ac = JSAutoCompartment::new(
let _ac = JSAutoRealm::new(
document.global().get_cx(),
document.reflector().get_jsobject().get(),
);
@ -3278,7 +3278,7 @@ impl ScriptThread {
let script_source = percent_decode(encoded.as_bytes()).decode_utf8_lossy();
// Script source is ready to be evaluated (11.)
let _ac = JSAutoCompartment::new(
let _ac = JSAutoRealm::new(
global_scope.get_cx(),
global_scope.reflector().get_jsobject().get(),
);