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

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;