mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
Upgraded to SM 60
This commit is contained in:
parent
d34403047e
commit
74c1e00d81
290 changed files with 26572 additions and 1178 deletions
|
@ -5,8 +5,6 @@
|
|||
use dom::bindings::refcounted::Trusted;
|
||||
use dom::bindings::reflector::DomObject;
|
||||
use dom::bindings::structuredclone::StructuredCloneData;
|
||||
use js::jsapi::{JSRuntime, JS_RequestInterruptCallback};
|
||||
use js::rust::Runtime;
|
||||
use script_runtime::CommonScriptMsg;
|
||||
|
||||
/// Messages used to control the worker event loops
|
||||
|
@ -28,25 +26,3 @@ impl<T: DomObject> SimpleWorkerErrorHandler<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct SharedRt {
|
||||
rt: *mut JSRuntime
|
||||
}
|
||||
|
||||
impl SharedRt {
|
||||
pub fn new(rt: &Runtime) -> SharedRt {
|
||||
SharedRt {
|
||||
rt: rt.rt()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn request_interrupt(&self) {
|
||||
unsafe {
|
||||
JS_RequestInterruptCallback(self.rt);
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(unsafe_code)]
|
||||
unsafe impl Send for SharedRt {}
|
||||
|
|
|
@ -11,7 +11,7 @@ use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
|||
use dom::bindings::root::DomRoot;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use js::jsapi::{DetachDataDisposition, Heap, JSAutoCompartment, JSContext, JSObject};
|
||||
use js::jsapi::{Heap, JSAutoCompartment, JSContext, JSObject};
|
||||
use js::jsapi::JS_GetArrayBufferViewBuffer;
|
||||
use js::rust::CustomAutoRooterGuard;
|
||||
use js::rust::wrappers::JS_DetachArrayBuffer;
|
||||
|
@ -167,7 +167,7 @@ impl AudioBuffer {
|
|||
JS_GetArrayBufferViewBuffer(cx, channel.handle(), &mut is_shared));
|
||||
// This buffer is always created unshared
|
||||
debug_assert!(!is_shared);
|
||||
let _ = JS_DetachArrayBuffer(cx, view_buffer.handle(), DetachDataDisposition::KeepData);
|
||||
let _ = JS_DetachArrayBuffer(cx, view_buffer.handle());
|
||||
data
|
||||
} else {
|
||||
return None;
|
||||
|
|
|
@ -1775,7 +1775,7 @@ class AttrDefiner(PropertyDefiner):
|
|||
if len(array) == 0:
|
||||
return ""
|
||||
|
||||
flags = "JSPROP_ENUMERATE | JSPROP_SHARED"
|
||||
flags = "JSPROP_ENUMERATE"
|
||||
if self.unforgeable:
|
||||
flags += " | JSPROP_PERMANENT"
|
||||
|
||||
|
@ -1822,15 +1822,18 @@ class AttrDefiner(PropertyDefiner):
|
|||
' JSPropertySpec {\n'
|
||||
' name: %s as *const u8 as *const libc::c_char,\n'
|
||||
' flags: (%s) as u8,\n'
|
||||
' getter: %s,\n'
|
||||
' setter: %s\n'
|
||||
' }',
|
||||
' JSPropertySpec {\n'
|
||||
' name: 0 as *const libc::c_char,\n'
|
||||
' flags: 0,\n'
|
||||
' getter: JSNativeWrapper { op: None, info: 0 as *const JSJitInfo },\n'
|
||||
' setter: JSNativeWrapper { op: None, info: 0 as *const JSJitInfo }\n'
|
||||
' __bindgen_anon_1: JSPropertySpec__bindgen_ty_1 {\n'
|
||||
' accessors: JSPropertySpec__bindgen_ty_1__bindgen_ty_1 {\n'
|
||||
' getter: JSPropertySpec__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1 {\n'
|
||||
' native: %s,\n'
|
||||
' },\n'
|
||||
' setter: JSPropertySpec__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2 {\n'
|
||||
' native: %s,\n'
|
||||
' }\n'
|
||||
' }\n'
|
||||
' }\n'
|
||||
' }',
|
||||
' JSPropertySpec::ZERO',
|
||||
'JSPropertySpec',
|
||||
PropertyDefiner.getControllingCondition, specData)
|
||||
|
||||
|
@ -2124,7 +2127,7 @@ class CGDOMJSClass(CGThing):
|
|||
"domClass": DOMClass(self.descriptor),
|
||||
"enumerateHook": "None",
|
||||
"finalizeHook": FINALIZE_HOOK_NAME,
|
||||
"flags": "0",
|
||||
"flags": "JSCLASS_FOREGROUND_FINALIZE",
|
||||
"name": str_to_const_array(self.descriptor.interface.identifier.name),
|
||||
"resolveHook": "None",
|
||||
"slots": "1",
|
||||
|
@ -2133,7 +2136,7 @@ class CGDOMJSClass(CGThing):
|
|||
if self.descriptor.isGlobal():
|
||||
assert not self.descriptor.weakReferenceable
|
||||
args["enumerateHook"] = "Some(enumerate_global)"
|
||||
args["flags"] = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL"
|
||||
args["flags"] = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL | JSCLASS_FOREGROUND_FINALIZE"
|
||||
args["slots"] = "JSCLASS_GLOBAL_SLOT_COUNT + 1"
|
||||
args["resolveHook"] = "Some(resolve_global)"
|
||||
args["traceHook"] = "js::jsapi::JS_GlobalObjectTraceHook"
|
||||
|
@ -2143,9 +2146,8 @@ class CGDOMJSClass(CGThing):
|
|||
static CLASS_OPS: js::jsapi::JSClassOps = js::jsapi::JSClassOps {
|
||||
addProperty: None,
|
||||
delProperty: None,
|
||||
getProperty: None,
|
||||
setProperty: None,
|
||||
enumerate: %(enumerateHook)s,
|
||||
newEnumerate: None,
|
||||
resolve: %(resolveHook)s,
|
||||
mayResolve: None,
|
||||
finalize: Some(%(finalizeHook)s),
|
||||
|
@ -2583,10 +2585,11 @@ def CreateBindingJSObject(descriptor, parent=None):
|
|||
let handler = RegisterBindings::PROXY_HANDLERS[PrototypeList::Proxies::%s as usize];
|
||||
rooted!(in(cx) let private = PrivateValue(raw as *const libc::c_void));
|
||||
let obj = NewProxyObject(cx, handler,
|
||||
private.handle(),
|
||||
Handle::from_raw(UndefinedHandleValue),
|
||||
proto.get(), %s.get(),
|
||||
ptr::null_mut(), ptr::null_mut());
|
||||
assert!(!obj.is_null());
|
||||
SetProxyReservedSlot(obj, 0, &private.get());
|
||||
rooted!(in(cx) let obj = obj);\
|
||||
""" % (descriptor.name, parent)
|
||||
else:
|
||||
|
@ -2594,11 +2597,13 @@ rooted!(in(cx) let obj = obj);\
|
|||
" cx, &Class.base as *const JSClass, proto.handle()));\n"
|
||||
"assert!(!obj.is_null());\n"
|
||||
"\n"
|
||||
"JS_SetReservedSlot(obj.get(), DOM_OBJECT_SLOT,\n"
|
||||
" PrivateValue(raw as *const libc::c_void));")
|
||||
"let val = PrivateValue(raw as *const libc::c_void);\n"
|
||||
"\n"
|
||||
"JS_SetReservedSlot(obj.get(), DOM_OBJECT_SLOT, &val);")
|
||||
if descriptor.weakReferenceable:
|
||||
create += """
|
||||
JS_SetReservedSlot(obj.get(), DOM_WEAK_SLOT, PrivateValue(ptr::null()));"""
|
||||
let val = PrivateValue(ptr::null());
|
||||
JS_SetReservedSlot(obj.get(), DOM_WEAK_SLOT, &val);"""
|
||||
return create
|
||||
|
||||
|
||||
|
@ -2652,9 +2657,10 @@ ensure_expando_object(cx, obj.handle().into(), expando.handle_mut());
|
|||
else:
|
||||
copyFunc = "JS_InitializePropertiesFromCompatibleNativeObject"
|
||||
copyCode += """\
|
||||
let mut slot = UndefinedValue();
|
||||
JS_GetReservedSlot(proto.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, &mut slot);
|
||||
rooted!(in(cx) let mut unforgeable_holder = ptr::null_mut::<JSObject>());
|
||||
unforgeable_holder.handle_mut().set(
|
||||
JS_GetReservedSlot(proto.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT).to_object());
|
||||
unforgeable_holder.handle_mut().set(slot.to_object());
|
||||
assert!(%(copyFunc)s(cx, %(obj)s.handle(), unforgeable_holder.handle()));
|
||||
""" % {'copyFunc': copyFunc, 'obj': obj}
|
||||
|
||||
|
@ -3013,7 +3019,7 @@ assert!((*cache)[PrototypeList::Constructor::%(id)s as usize].is_null());
|
|||
CGGeneric(fill(
|
||||
"""
|
||||
assert!(${defineFn}(cx, prototype.handle(), ${prop}, aliasedVal.handle(),
|
||||
JSPROP_ENUMERATE, None, None));
|
||||
JSPROP_ENUMERATE as u32));
|
||||
""",
|
||||
defineFn=defineFn,
|
||||
prop=prop))
|
||||
|
@ -3078,8 +3084,8 @@ assert!(!unforgeable_holder.is_null());
|
|||
""" % {'holderClass': holderClass, 'holderProto': holderProto}))
|
||||
code.append(InitUnforgeablePropertiesOnHolder(self.descriptor, self.properties))
|
||||
code.append(CGGeneric("""\
|
||||
JS_SetReservedSlot(prototype.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT,
|
||||
ObjectValue(unforgeable_holder.get()))"""))
|
||||
let val = ObjectValue(unforgeable_holder.get());
|
||||
JS_SetReservedSlot(prototype.get(), DOM_PROTO_UNFORGEABLE_HOLDER_SLOT, &val)"""))
|
||||
|
||||
return CGList(code, "\n")
|
||||
|
||||
|
@ -3533,11 +3539,13 @@ class CGAbstractStaticBindingMethod(CGAbstractMethod):
|
|||
self.exposureSet = descriptor.interface.exposureSet
|
||||
|
||||
def definition_body(self):
|
||||
preamble = "let global = GlobalScope::from_object(JS_CALLEE(cx, vp).to_object());\n"
|
||||
preamble = """\
|
||||
let args = CallArgs::from_vp(vp, argc);
|
||||
let global = GlobalScope::from_object(args.callee());
|
||||
"""
|
||||
if len(self.exposureSet) == 1:
|
||||
preamble += """
|
||||
let global = DomRoot::downcast::<dom::types::%s>(global).unwrap();
|
||||
""" % list(self.exposureSet)[0]
|
||||
preamble += ("let global = DomRoot::downcast::<dom::types::%s>(global).unwrap();\n" %
|
||||
list(self.exposureSet)[0])
|
||||
return CGList([CGGeneric(preamble), self.generate_code()])
|
||||
|
||||
def generate_code(self):
|
||||
|
@ -3741,7 +3749,7 @@ class CGSpecializedReplaceableSetter(CGSpecializedSetter):
|
|||
assert all(ord(c) < 128 for c in name)
|
||||
return CGGeneric("""\
|
||||
JS_DefineProperty(cx, obj, %s as *const u8 as *const libc::c_char,
|
||||
HandleValue::from_raw(args.get(0)), JSPROP_ENUMERATE, None, None)""" % name)
|
||||
HandleValue::from_raw(args.get(0)), JSPROP_ENUMERATE as u32)""" % name)
|
||||
|
||||
|
||||
class CGMemberJITInfo(CGThing):
|
||||
|
@ -4959,7 +4967,9 @@ class CGProxyUnwrap(CGAbstractMethod):
|
|||
obj = js::UnwrapObject(obj);
|
||||
}*/
|
||||
//MOZ_ASSERT(IsProxy(obj));
|
||||
let box_ = GetProxyPrivate(obj.get()).to_private() as *const %s;
|
||||
let mut slot = UndefinedValue();
|
||||
GetProxyReservedSlot(obj.get(), 0, &mut slot);
|
||||
let box_ = slot.to_private() as *const %s;
|
||||
return box_;""" % self.descriptor.concreteType)
|
||||
|
||||
|
||||
|
@ -4985,7 +4995,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
|||
attrs += " | JSPROP_READONLY"
|
||||
# FIXME(#11868) Should assign to desc.value, desc.get() is a copy.
|
||||
fillDescriptor = ("desc.get().value = result_root.get();\n"
|
||||
"fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), %s);\n"
|
||||
"fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), (%s) as u32);\n"
|
||||
"return true;" % attrs)
|
||||
templateValues = {
|
||||
'jsvalRef': 'result_root.handle_mut()',
|
||||
|
@ -5011,7 +5021,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
|||
attrs = "0"
|
||||
# FIXME(#11868) Should assign to desc.value, desc.get() is a copy.
|
||||
fillDescriptor = ("desc.get().value = result_root.get();\n"
|
||||
"fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), %s);\n"
|
||||
"fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), (%s) as u32);\n"
|
||||
"return true;" % attrs)
|
||||
templateValues = {
|
||||
'jsvalRef': 'result_root.handle_mut()',
|
||||
|
@ -5425,7 +5435,9 @@ finalize_global(obj);
|
|||
"""
|
||||
elif descriptor.weakReferenceable:
|
||||
release += """\
|
||||
let weak_box_ptr = JS_GetReservedSlot(obj, DOM_WEAK_SLOT).to_private() as *mut WeakBox<%s>;
|
||||
let mut slot = UndefinedValue();
|
||||
JS_GetReservedSlot(obj, DOM_WEAK_SLOT, &mut slot);
|
||||
let weak_box_ptr = slot.to_private() as *mut WeakBox<%s>;
|
||||
if !weak_box_ptr.is_null() {
|
||||
let count = {
|
||||
let weak_box = &*weak_box_ptr;
|
||||
|
@ -5736,6 +5748,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
|||
'js::jsapi::INTERNED_STRING_TO_JSID',
|
||||
'js::jsapi::IsCallable',
|
||||
'js::jsapi::JSAutoCompartment',
|
||||
'js::jsapi::JSCLASS_FOREGROUND_FINALIZE',
|
||||
'js::jsapi::JSCLASS_RESERVED_SLOTS_SHIFT',
|
||||
'js::jsapi::JSClass',
|
||||
'js::jsapi::JSContext',
|
||||
|
@ -5757,8 +5770,11 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
|||
'js::jsapi::JSPROP_ENUMERATE',
|
||||
'js::jsapi::JSPROP_PERMANENT',
|
||||
'js::jsapi::JSPROP_READONLY',
|
||||
'js::jsapi::JSPROP_SHARED',
|
||||
'js::jsapi::JSPropertySpec',
|
||||
'js::jsapi::JSPropertySpec__bindgen_ty_1',
|
||||
'js::jsapi::JSPropertySpec__bindgen_ty_1__bindgen_ty_1',
|
||||
'js::jsapi::JSPropertySpec__bindgen_ty_1__bindgen_ty_1__bindgen_ty_1',
|
||||
'js::jsapi::JSPropertySpec__bindgen_ty_1__bindgen_ty_1__bindgen_ty_2',
|
||||
'js::jsapi::JSString',
|
||||
'js::jsapi::JSTracer',
|
||||
'js::jsapi::JSType',
|
||||
|
@ -5778,7 +5794,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
|||
'js::rust::wrappers::JS_GetProperty',
|
||||
'js::jsapi::JS_GetPropertyById',
|
||||
'js::jsapi::JS_GetPropertyDescriptorById',
|
||||
'js::jsapi::JS_GetReservedSlot',
|
||||
'js::glue::JS_GetReservedSlot',
|
||||
'js::jsapi::JS_HasProperty',
|
||||
'js::jsapi::JS_HasPropertyById',
|
||||
'js::rust::wrappers::JS_InitializePropertiesFromCompatibleNativeObject',
|
||||
|
@ -5813,12 +5829,14 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
|||
'js::jsval::ObjectOrNullValue',
|
||||
'js::jsval::PrivateValue',
|
||||
'js::jsval::UndefinedValue',
|
||||
'js::jsapi::UndefinedHandleValue',
|
||||
'js::glue::AppendToAutoIdVector',
|
||||
'js::glue::CallJitGetterOp',
|
||||
'js::glue::CallJitMethodOp',
|
||||
'js::glue::CallJitSetterOp',
|
||||
'js::glue::CreateProxyHandler',
|
||||
'js::glue::GetProxyPrivate',
|
||||
'js::glue::GetProxyReservedSlot',
|
||||
'js::glue::SetProxyReservedSlot',
|
||||
'js::rust::wrappers::NewProxyObject',
|
||||
'js::glue::ProxyTraps',
|
||||
'js::glue::RUST_JSID_IS_INT',
|
||||
|
|
|
@ -61,8 +61,6 @@ pub unsafe fn define_constants(
|
|||
obj,
|
||||
spec.name.as_ptr() as *const libc::c_char,
|
||||
value.handle(),
|
||||
JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT,
|
||||
None,
|
||||
None));
|
||||
(JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT) as u32));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,12 +45,13 @@ pub use js::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvert
|
|||
pub use js::conversions::ConversionBehavior;
|
||||
use js::conversions::latin1_to_string;
|
||||
use js::error::throw_type_error;
|
||||
use js::glue::{GetProxyPrivate, IsWrapper};
|
||||
use js::glue::{IsWrapper, UnwrapObject};
|
||||
use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT};
|
||||
use js::glue::{UnwrapObject, RUST_JSID_IS_STRING, RUST_JSID_TO_STRING};
|
||||
use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING};
|
||||
use js::glue::GetProxyReservedSlot;
|
||||
use js::glue::JS_GetReservedSlot;
|
||||
use js::jsapi::{Heap, JSContext, JSObject, JSString};
|
||||
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetReservedSlot};
|
||||
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_IsExceptionPending};
|
||||
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetTwoByteStringCharsAndLength, JS_IsExceptionPending};
|
||||
use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars};
|
||||
use js::jsval::{ObjectValue, StringValue, UndefinedValue};
|
||||
use js::rust::{HandleId, HandleObject, HandleValue, MutableHandleValue};
|
||||
|
@ -347,11 +348,12 @@ pub const DOM_OBJECT_SLOT: u32 = 0;
|
|||
|
||||
/// Get the private pointer of a DOM object from a given reflector.
|
||||
pub unsafe fn private_from_object(obj: *mut JSObject) -> *const libc::c_void {
|
||||
let value = if is_dom_object(obj) {
|
||||
JS_GetReservedSlot(obj, DOM_OBJECT_SLOT)
|
||||
let mut value = UndefinedValue();
|
||||
if is_dom_object(obj) {
|
||||
JS_GetReservedSlot(obj, DOM_OBJECT_SLOT, &mut value);
|
||||
} else {
|
||||
debug_assert!(is_dom_proxy(obj));
|
||||
GetProxyPrivate(obj)
|
||||
GetProxyReservedSlot(obj, 0, &mut value);
|
||||
};
|
||||
if value.is_undefined() {
|
||||
ptr::null()
|
||||
|
|
|
@ -157,7 +157,7 @@ impl ErrorInfo {
|
|||
}
|
||||
|
||||
let filename = {
|
||||
let filename = (*report).filename as *const u8;
|
||||
let filename = (*report)._base.filename as *const u8;
|
||||
if !filename.is_null() {
|
||||
let length = (0..).find(|idx| *filename.offset(*idx) == 0).unwrap();
|
||||
let filename = from_raw_parts(filename, length as usize);
|
||||
|
@ -167,14 +167,14 @@ impl ErrorInfo {
|
|||
}
|
||||
};
|
||||
|
||||
let lineno = (*report).lineno;
|
||||
let column = (*report).column;
|
||||
let lineno = (*report)._base.lineno;
|
||||
let column = (*report)._base.column;
|
||||
|
||||
let message = {
|
||||
let message = (*report).ucmessage;
|
||||
let message = (*report)._base.message_.data_ as *const u8;
|
||||
let length = (0..).find(|idx| *message.offset(*idx) == 0).unwrap();
|
||||
let message = from_raw_parts(message, length as usize);
|
||||
String::from_utf16_lossy(message)
|
||||
String::from_utf8_lossy(message).into_owned()
|
||||
};
|
||||
|
||||
Some(ErrorInfo {
|
||||
|
|
|
@ -16,7 +16,7 @@ use js::jsapi::{Class, ClassOps, CompartmentOptions};
|
|||
use js::jsapi::{GetGlobalForObjectCrossCompartment, GetWellKnownSymbol};
|
||||
use js::jsapi::{JSAutoCompartment, JSClass, JSContext, JSFunctionSpec, JSObject, JSFUN_CONSTRUCTOR};
|
||||
use js::jsapi::{JSPROP_PERMANENT, JSPROP_READONLY, JSPROP_RESOLVING};
|
||||
use js::jsapi::{JSPropertySpec, JSString, JSTracer, JSVersion, JS_AtomizeAndPinString};
|
||||
use js::jsapi::{JSPropertySpec, JSString, JSTracer, JS_AtomizeAndPinString};
|
||||
use js::jsapi::{JS_GetFunctionObject, JS_NewFunction, JS_NewGlobalObject};
|
||||
use js::jsapi::{JS_NewObject, JS_NewPlainObject};
|
||||
use js::jsapi::{JS_NewStringCopyN, JS_SetReservedSlot};
|
||||
|
@ -27,11 +27,12 @@ use js::jsapi::MutableHandleValue as RawMutableHandleValue;
|
|||
use js::jsval::{JSVal, PrivateValue};
|
||||
use js::rust::{HandleObject, HandleValue, MutableHandleObject};
|
||||
use js::rust::{define_methods, define_properties, get_object_class};
|
||||
use js::rust::wrappers::{JS_DefineProperty, JS_DefineProperty1, JS_DefineProperty2};
|
||||
use js::rust::wrappers::{JS_DefineProperty4, JS_DefinePropertyById3};
|
||||
use js::rust::wrappers::{JS_DefineProperty, JS_DefineProperty2};
|
||||
use js::rust::wrappers::{JS_DefineProperty3, JS_DefineProperty4, JS_DefinePropertyById4};
|
||||
use js::rust::wrappers::{JS_FireOnNewGlobalObject, JS_GetPrototype};
|
||||
use js::rust::wrappers::{JS_LinkConstructorAndPrototype, JS_NewObjectWithUniqueType};
|
||||
use libc;
|
||||
use std::convert::TryFrom;
|
||||
use std::ptr;
|
||||
|
||||
/// The class of a non-callback interface object.
|
||||
|
@ -92,9 +93,8 @@ impl InterfaceConstructorBehavior {
|
|||
InterfaceConstructorBehavior(ClassOps {
|
||||
addProperty: None,
|
||||
delProperty: None,
|
||||
getProperty: None,
|
||||
setProperty: None,
|
||||
enumerate: None,
|
||||
newEnumerate: None,
|
||||
resolve: None,
|
||||
mayResolve: None,
|
||||
finalize: None,
|
||||
|
@ -110,9 +110,8 @@ impl InterfaceConstructorBehavior {
|
|||
InterfaceConstructorBehavior(ClassOps {
|
||||
addProperty: None,
|
||||
delProperty: None,
|
||||
getProperty: None,
|
||||
setProperty: None,
|
||||
enumerate: None,
|
||||
newEnumerate: None,
|
||||
resolve: None,
|
||||
mayResolve: None,
|
||||
finalize: None,
|
||||
|
@ -138,7 +137,6 @@ pub unsafe fn create_global_object(
|
|||
assert!(rval.is_null());
|
||||
|
||||
let mut options = CompartmentOptions::default();
|
||||
options.behaviors_.version_ = JSVersion::JSVERSION_ECMA_5;
|
||||
options.creationOptions_.traceGlobal_ = Some(trace);
|
||||
options.creationOptions_.sharedMemoryAndAtomics_ = true;
|
||||
|
||||
|
@ -151,12 +149,12 @@ pub unsafe fn create_global_object(
|
|||
|
||||
// Initialize the reserved slots before doing anything that can GC, to
|
||||
// avoid getting trace hooks called on a partially initialized object.
|
||||
JS_SetReservedSlot(rval.get(), DOM_OBJECT_SLOT, PrivateValue(private));
|
||||
let private_val = PrivateValue(private);
|
||||
JS_SetReservedSlot(rval.get(), DOM_OBJECT_SLOT, &private_val);
|
||||
let proto_array: Box<ProtoOrIfaceArray> =
|
||||
Box::new([0 as *mut JSObject; PrototypeList::PROTO_OR_IFACE_LENGTH]);
|
||||
JS_SetReservedSlot(rval.get(),
|
||||
DOM_PROTOTYPE_SLOT,
|
||||
PrivateValue(Box::into_raw(proto_array) as *const libc::c_void));
|
||||
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());
|
||||
JS_FireOnNewGlobalObject(cx, rval.handle());
|
||||
|
@ -197,9 +195,9 @@ 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_DefinePropertyById3(
|
||||
assert!(JS_DefinePropertyById4(
|
||||
cx, rval.handle(), unscopable_id.handle(), unscopable_obj.handle(),
|
||||
JSPROP_READONLY, None, None))
|
||||
JSPROP_READONLY as u32))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,7 +223,7 @@ pub unsafe fn create_noncallback_interface_object(
|
|||
rval);
|
||||
assert!(JS_LinkConstructorAndPrototype(cx, rval.handle(), interface_prototype_object));
|
||||
define_name(cx, rval.handle(), name);
|
||||
define_length(cx, rval.handle(), length);
|
||||
define_length(cx, rval.handle(), i32::try_from(length).expect("overflow"));
|
||||
define_on_global_object(cx, global, name, rval.handle());
|
||||
}
|
||||
|
||||
|
@ -249,13 +247,11 @@ pub unsafe fn create_named_constructors(
|
|||
constructor.set(JS_GetFunctionObject(fun));
|
||||
assert!(!constructor.is_null());
|
||||
|
||||
assert!(JS_DefineProperty1(cx,
|
||||
assert!(JS_DefineProperty2(cx,
|
||||
constructor.handle(),
|
||||
b"prototype\0".as_ptr() as *const libc::c_char,
|
||||
interface_prototype_object,
|
||||
JSPROP_PERMANENT | JSPROP_READONLY,
|
||||
None,
|
||||
None));
|
||||
(JSPROP_PERMANENT | JSPROP_READONLY) as u32));
|
||||
|
||||
define_on_global_object(cx, global, name, constructor.handle());
|
||||
}
|
||||
|
@ -329,12 +325,11 @@ pub unsafe fn define_on_global_object(
|
|||
name: &[u8],
|
||||
obj: HandleObject) {
|
||||
assert_eq!(*name.last().unwrap(), b'\0');
|
||||
assert!(JS_DefineProperty1(cx,
|
||||
assert!(JS_DefineProperty2(cx,
|
||||
global,
|
||||
name.as_ptr() as *const libc::c_char,
|
||||
obj,
|
||||
JSPROP_RESOLVING,
|
||||
None, None));
|
||||
JSPROP_RESOLVING));
|
||||
}
|
||||
|
||||
const OBJECT_OPS: ObjectOps = ObjectOps {
|
||||
|
@ -345,16 +340,13 @@ const OBJECT_OPS: ObjectOps = ObjectOps {
|
|||
setProperty: None,
|
||||
getOwnPropertyDescriptor: None,
|
||||
deleteProperty: None,
|
||||
watch: None,
|
||||
unwatch: None,
|
||||
getElements: None,
|
||||
enumerate: None,
|
||||
funToString: Some(fun_to_string_hook),
|
||||
};
|
||||
|
||||
unsafe extern "C" fn fun_to_string_hook(cx: *mut JSContext,
|
||||
obj: RawHandleObject,
|
||||
_indent: u32)
|
||||
_is_to_source: bool)
|
||||
-> *mut JSString {
|
||||
let js_class = get_object_class(obj.get());
|
||||
assert!(!js_class.is_null());
|
||||
|
@ -444,9 +436,7 @@ unsafe fn create_unscopable_object(
|
|||
rval.handle(),
|
||||
name.as_ptr() as *const libc::c_char,
|
||||
HandleValue::from_raw(TrueHandleValue),
|
||||
JSPROP_READONLY,
|
||||
None,
|
||||
None
|
||||
JSPROP_READONLY as u32,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -455,21 +445,19 @@ 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_DefineProperty2(cx,
|
||||
assert!(JS_DefineProperty3(cx,
|
||||
obj,
|
||||
b"name\0".as_ptr() as *const libc::c_char,
|
||||
name.handle().into(),
|
||||
JSPROP_READONLY,
|
||||
None, None));
|
||||
JSPROP_READONLY as u32));
|
||||
}
|
||||
|
||||
unsafe fn define_length(cx: *mut JSContext, obj: HandleObject, length: u32) {
|
||||
unsafe fn define_length(cx: *mut JSContext, obj: HandleObject, length: i32) {
|
||||
assert!(JS_DefineProperty4(cx,
|
||||
obj,
|
||||
b"length\0".as_ptr() as *const libc::c_char,
|
||||
length,
|
||||
JSPROP_READONLY,
|
||||
None, None));
|
||||
JSPROP_READONLY as u32));
|
||||
}
|
||||
|
||||
unsafe extern "C" fn invalid_constructor(
|
||||
|
|
|
@ -5,10 +5,13 @@
|
|||
//! The `MozMap` (open-ended dictionary) type.
|
||||
|
||||
use dom::bindings::conversions::jsid_to_string;
|
||||
use dom::bindings::error::report_pending_exception;
|
||||
use dom::bindings::str::DOMString;
|
||||
use js::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible};
|
||||
use js::jsapi::JSContext;
|
||||
use js::jsapi::JSITER_HIDDEN;
|
||||
use js::jsapi::JSITER_OWNONLY;
|
||||
use js::jsapi::JSITER_SYMBOLS;
|
||||
use js::jsapi::JSPROP_ENUMERATE;
|
||||
use js::jsapi::JS_NewPlainObject;
|
||||
use js::jsval::ObjectValue;
|
||||
|
@ -58,7 +61,13 @@ impl<T, C> FromJSValConvertible for MozMap<T>
|
|||
|
||||
rooted!(in(cx) let object = value.to_object());
|
||||
let ids = IdVector::new(cx);
|
||||
assert!(GetPropertyKeys(cx, object.handle(), JSITER_OWNONLY, ids.get()));
|
||||
if !GetPropertyKeys(cx, object.handle(), JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, ids.get()) {
|
||||
// TODO: can GetPropertyKeys fail?
|
||||
// (it does so if the object has duplicate keys)
|
||||
// https://github.com/servo/servo/issues/21462
|
||||
report_pending_exception(cx, false);
|
||||
return Ok(ConversionResult::Failure("Getting MozMap value property keys failed".into()));
|
||||
}
|
||||
|
||||
let mut map = HashMap::new();
|
||||
for id in &*ids {
|
||||
|
@ -74,8 +83,11 @@ impl<T, C> FromJSValConvertible for MozMap<T>
|
|||
ConversionResult::Failure(message) => return Ok(ConversionResult::Failure(message)),
|
||||
};
|
||||
|
||||
let key = jsid_to_string(cx, id.handle()).unwrap();
|
||||
map.insert(key, property);
|
||||
// TODO: Is this guaranteed to succeed?
|
||||
// https://github.com/servo/servo/issues/21463
|
||||
if let Some(key) = jsid_to_string(cx, id.handle()) {
|
||||
map.insert(key, property);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(ConversionResult::Success(MozMap {
|
||||
|
@ -100,9 +112,7 @@ impl<T: ToJSValConvertible> ToJSValConvertible for MozMap<T> {
|
|||
key.as_ptr(),
|
||||
key.len(),
|
||||
js_value.handle(),
|
||||
JSPROP_ENUMERATE,
|
||||
None,
|
||||
None));
|
||||
JSPROP_ENUMERATE as u32));
|
||||
}
|
||||
|
||||
rval.set(ObjectValue(js_object.handle().get()));
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
|
||||
use dom::bindings::conversions::is_dom_proxy;
|
||||
use dom::bindings::utils::delete_property_by_id;
|
||||
use js::glue::{GetProxyHandler, GetProxyHandlerFamily, SetProxyExtra};
|
||||
use js::glue::GetProxyExtra;
|
||||
use js::glue::{GetProxyHandler, GetProxyHandlerFamily};
|
||||
use js::glue::{GetProxyPrivate, SetProxyPrivate};
|
||||
use js::glue::InvokeGetOwnPropertyDescriptor;
|
||||
use js::jsapi::{DOMProxyShadowsResult, JSContext, JSObject, PropertyDescriptor, JSPROP_GETTER};
|
||||
use js::jsapi::{JSErrNum, JS_StrictPropertyStub, SetDOMProxyInformation};
|
||||
use js::jsapi::{DOMProxyShadowsResult, JSContext, JSObject, PropertyDescriptor};
|
||||
use js::jsapi::{JSErrNum, SetDOMProxyInformation};
|
||||
use js::jsapi::GetObjectProto;
|
||||
use js::jsapi::GetStaticPrototype;
|
||||
use js::jsapi::Handle as RawHandle;
|
||||
|
@ -24,14 +24,13 @@ use js::jsapi::MutableHandle as RawMutableHandle;
|
|||
use js::jsapi::MutableHandleObject as RawMutableHandleObject;
|
||||
use js::jsapi::ObjectOpResult;
|
||||
use js::jsval::ObjectValue;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::{Handle, HandleObject, MutableHandle, MutableHandleObject};
|
||||
use js::rust::wrappers::JS_AlreadyHasOwnPropertyById;
|
||||
use js::rust::wrappers::JS_NewObjectWithGivenProto;
|
||||
use std::ptr;
|
||||
|
||||
|
||||
static JSPROXYSLOT_EXPANDO: u32 = 0;
|
||||
|
||||
/// Determine if this id shadows any existing properties for this proxy.
|
||||
pub unsafe extern "C" fn shadow_check_callback(cx: *mut JSContext,
|
||||
object: RawHandleObject,
|
||||
|
@ -61,7 +60,6 @@ pub unsafe extern "C" fn shadow_check_callback(cx: *mut JSContext,
|
|||
/// Initialize the infrastructure for DOM proxy objects.
|
||||
pub unsafe fn init() {
|
||||
SetDOMProxyInformation(GetProxyHandlerFamily(),
|
||||
JSPROXYSLOT_EXPANDO,
|
||||
Some(shadow_check_callback));
|
||||
}
|
||||
|
||||
|
@ -99,11 +97,6 @@ pub unsafe extern "C" fn define_property(cx: *mut JSContext,
|
|||
desc: RawHandle<PropertyDescriptor>,
|
||||
result: *mut ObjectOpResult)
|
||||
-> bool {
|
||||
if (desc.get().attrs & JSPROP_GETTER) != 0 && desc.get().setter == Some(JS_StrictPropertyStub) {
|
||||
(*result).code_ = JSErrNum::JSMSG_GETTER_ONLY as ::libc::uintptr_t;
|
||||
return true;
|
||||
}
|
||||
|
||||
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
|
||||
ensure_expando_object(cx, proxy, expando.handle_mut());
|
||||
JS_DefinePropertyById(cx, expando.handle().into(), id, desc, result)
|
||||
|
@ -165,7 +158,8 @@ pub unsafe extern "C" fn get_prototype_if_ordinary(_: *mut JSContext,
|
|||
/// Get the expando object, or null if there is none.
|
||||
pub unsafe fn get_expando_object(obj: RawHandleObject, mut expando: MutableHandleObject) {
|
||||
assert!(is_dom_proxy(obj.get()));
|
||||
let val = GetProxyExtra(obj.get(), JSPROXYSLOT_EXPANDO);
|
||||
let ref mut val = UndefinedValue();
|
||||
GetProxyPrivate(obj.get(), val);
|
||||
expando.set(if val.is_undefined() {
|
||||
ptr::null_mut()
|
||||
} else {
|
||||
|
@ -182,7 +176,7 @@ pub unsafe fn ensure_expando_object(cx: *mut JSContext, obj: RawHandleObject, mu
|
|||
expando.set(JS_NewObjectWithGivenProto(cx, ptr::null_mut(), HandleObject::null()));
|
||||
assert!(!expando.is_null());
|
||||
|
||||
SetProxyExtra(obj.get(), JSPROXYSLOT_EXPANDO, &ObjectValue(expando.get()));
|
||||
SetProxyPrivate(obj.get(), &ObjectValue(expando.get()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,14 +11,21 @@ use dom::bindings::reflector::DomObject;
|
|||
use dom::bindings::root::DomRoot;
|
||||
use dom::blob::{Blob, BlobImpl};
|
||||
use dom::globalscope::GlobalScope;
|
||||
use js::glue::CopyJSStructuredCloneData;
|
||||
use js::glue::DeleteJSAutoStructuredCloneBuffer;
|
||||
use js::glue::GetLengthOfJSStructuredCloneData;
|
||||
use js::glue::NewJSAutoStructuredCloneBuffer;
|
||||
use js::glue::WriteBytesToJSStructuredCloneData;
|
||||
use js::jsapi::{JSAutoCompartment, JSContext};
|
||||
use js::jsapi::{JSStructuredCloneCallbacks, JSStructuredCloneReader, JSStructuredCloneWriter};
|
||||
use js::jsapi::{JS_ClearPendingException, JSObject};
|
||||
use js::jsapi::{JS_ReadBytes, JS_WriteBytes};
|
||||
use js::jsapi::{JS_ReadUint32Pair, JS_WriteUint32Pair};
|
||||
use js::jsapi::CloneDataPolicy;
|
||||
use js::jsapi::HandleObject as RawHandleObject;
|
||||
use js::jsapi::JS_STRUCTURED_CLONE_VERSION;
|
||||
use js::jsapi::MutableHandleObject as RawMutableHandleObject;
|
||||
use js::jsapi::StructuredCloneScope;
|
||||
use js::jsapi::TransferableOwnership;
|
||||
use js::rust::{Handle, HandleValue, MutableHandleValue};
|
||||
use js::rust::wrappers::{JS_WriteStructuredClone, JS_ReadStructuredClone};
|
||||
|
@ -207,26 +214,39 @@ pub enum StructuredCloneData {
|
|||
}
|
||||
|
||||
impl StructuredCloneData {
|
||||
// TODO: should this be unsafe?
|
||||
/// Writes a structured clone. Returns a `DataClone` error if that fails.
|
||||
pub fn write(cx: *mut JSContext, message: HandleValue) -> Fallible<StructuredCloneData> {
|
||||
let mut data = ptr::null_mut();
|
||||
let mut nbytes = 0;
|
||||
let result = unsafe {
|
||||
JS_WriteStructuredClone(cx,
|
||||
message,
|
||||
&mut data,
|
||||
&mut nbytes,
|
||||
&STRUCTURED_CLONE_CALLBACKS,
|
||||
ptr::null_mut(),
|
||||
HandleValue::undefined())
|
||||
};
|
||||
if !result {
|
||||
unsafe {
|
||||
unsafe {
|
||||
let scbuf = NewJSAutoStructuredCloneBuffer(StructuredCloneScope::DifferentProcess,
|
||||
&STRUCTURED_CLONE_CALLBACKS);
|
||||
let scdata = &mut ((*scbuf).data_);
|
||||
let policy = CloneDataPolicy {
|
||||
// TODO: SAB?
|
||||
sharedArrayBuffer_: false,
|
||||
};
|
||||
let result = JS_WriteStructuredClone(cx,
|
||||
message,
|
||||
scdata,
|
||||
StructuredCloneScope::DifferentProcess,
|
||||
policy,
|
||||
&STRUCTURED_CLONE_CALLBACKS,
|
||||
ptr::null_mut(),
|
||||
HandleValue::undefined());
|
||||
if !result {
|
||||
JS_ClearPendingException(cx);
|
||||
return Err(Error::DataClone);
|
||||
}
|
||||
return Err(Error::DataClone);
|
||||
|
||||
let nbytes = GetLengthOfJSStructuredCloneData(scdata);
|
||||
let mut data = Vec::with_capacity(nbytes);
|
||||
CopyJSStructuredCloneData(scdata, data.as_mut_ptr());
|
||||
data.set_len(nbytes);
|
||||
|
||||
DeleteJSAutoStructuredCloneBuffer(scbuf);
|
||||
|
||||
Ok(StructuredCloneData::Vector(data))
|
||||
}
|
||||
Ok(StructuredCloneData::Struct(data, nbytes))
|
||||
}
|
||||
|
||||
/// Converts a StructuredCloneData to Vec<u8> for inter-thread sharing
|
||||
|
@ -254,13 +274,21 @@ impl StructuredCloneData {
|
|||
let mut sc_holder = StructuredCloneHolder { blob: None };
|
||||
let sc_holder_ptr = &mut sc_holder as *mut _;
|
||||
unsafe {
|
||||
let scbuf = NewJSAutoStructuredCloneBuffer(StructuredCloneScope::DifferentProcess,
|
||||
&STRUCTURED_CLONE_CALLBACKS);
|
||||
let scdata = &mut ((*scbuf).data_);
|
||||
|
||||
WriteBytesToJSStructuredCloneData(data as *const u8, nbytes, scdata);
|
||||
|
||||
assert!(JS_ReadStructuredClone(cx,
|
||||
data,
|
||||
nbytes,
|
||||
scdata,
|
||||
JS_STRUCTURED_CLONE_VERSION,
|
||||
StructuredCloneScope::DifferentProcess,
|
||||
rval,
|
||||
&STRUCTURED_CLONE_CALLBACKS,
|
||||
sc_holder_ptr as *mut raw::c_void));
|
||||
|
||||
DeleteJSAutoStructuredCloneBuffer(scbuf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ use canvas_traits::webgl::{WebGLSLVersion, WebGLSender, WebGLShaderId, WebGLText
|
|||
use canvas_traits::webgl::{WebGLVersion, WebGLVertexArrayId};
|
||||
use cssparser::RGBA;
|
||||
use devtools_traits::{CSSError, TimelineMarkerType, WorkerId};
|
||||
use dom::abstractworker::SharedRt;
|
||||
use dom::bindings::cell::DomRefCell;
|
||||
use dom::bindings::error::Error;
|
||||
use dom::bindings::refcounted::{Trusted, TrustedPromise};
|
||||
|
@ -77,7 +76,6 @@ use net_traits::response::{Response, ResponseBody};
|
|||
use net_traits::response::HttpsState;
|
||||
use net_traits::storage_thread::StorageType;
|
||||
use offscreen_gl_context::GLLimits;
|
||||
use parking_lot::RwLock;
|
||||
use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
||||
use profile_traits::time::ProfilerChan as TimeProfilerChan;
|
||||
use script_layout_interface::OpaqueStyleAndLayoutData;
|
||||
|
@ -103,7 +101,7 @@ use std::hash::{BuildHasher, Hash};
|
|||
use std::ops::{Deref, DerefMut};
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize};
|
||||
use std::sync::mpsc::{Receiver, Sender};
|
||||
use std::time::{SystemTime, Instant};
|
||||
|
@ -397,7 +395,6 @@ unsafe_no_jsmanaged_fields!(Stylesheet);
|
|||
unsafe_no_jsmanaged_fields!(HttpsState);
|
||||
unsafe_no_jsmanaged_fields!(Request);
|
||||
unsafe_no_jsmanaged_fields!(RequestInit);
|
||||
unsafe_no_jsmanaged_fields!(SharedRt);
|
||||
unsafe_no_jsmanaged_fields!(StyleSharedRwLock);
|
||||
unsafe_no_jsmanaged_fields!(USVString);
|
||||
unsafe_no_jsmanaged_fields!(ReferrerPolicy);
|
||||
|
@ -594,12 +591,6 @@ unsafe impl<U> JSTraceable for TypedSize2D<f32, U> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for Mutex<Option<SharedRt>> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for StyleLocked<FontFaceRule> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
|
@ -666,12 +657,6 @@ unsafe impl JSTraceable for StyleLocked<PropertyDeclarationBlock> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for RwLock<SharedRt> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl JSTraceable for StyleLocked<MediaList> {
|
||||
unsafe fn trace(&self, _trc: *mut JSTracer) {
|
||||
// Do nothing.
|
||||
|
|
|
@ -16,20 +16,20 @@ use dom::windowproxy;
|
|||
use js;
|
||||
use js::JS_CALLEE;
|
||||
use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper};
|
||||
use js::glue::{GetCrossCompartmentWrapper, WrapperNew};
|
||||
use js::glue::{GetCrossCompartmentWrapper, JS_GetReservedSlot, WrapperNew};
|
||||
use js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING};
|
||||
use js::glue::{RUST_JSID_TO_INT, RUST_JSID_TO_STRING, UnwrapObject};
|
||||
use js::jsapi::{CallArgs, DOMCallbacks, GetGlobalForObjectCrossCompartment};
|
||||
use js::jsapi::{Heap, JSAutoCompartment, JSContext};
|
||||
use js::jsapi::{JSJitInfo, JSObject, JSTracer, JSWrapObjectCallbacks};
|
||||
use js::jsapi::{JS_EnumerateStandardClasses, JS_GetLatin1StringCharsAndLength};
|
||||
use js::jsapi::{JS_GetReservedSlot, JS_IsExceptionPending, JS_IsGlobalObject};
|
||||
use js::jsapi::{JS_ResolveStandardClass, ToWindowProxyIfWindow};
|
||||
use js::jsapi::{JS_StringHasLatin1Chars, ObjectOpResult};
|
||||
use js::jsapi::{JS_IsExceptionPending, JS_IsGlobalObject};
|
||||
use js::jsapi::{JS_ResolveStandardClass, JS_StringHasLatin1Chars, ObjectOpResult};
|
||||
use js::jsapi::HandleId as RawHandleId;
|
||||
use js::jsapi::HandleObject as RawHandleObject;
|
||||
use js::jsapi::MutableHandleObject as RawMutableHandleObject;
|
||||
use js::jsval::{JSVal, UndefinedValue};
|
||||
use js::rust::{GCMethods, ToString, get_object_class, is_dom_class};
|
||||
use js::rust::{GCMethods, ToString, ToWindowProxyIfWindow, get_object_class, is_dom_class};
|
||||
use js::rust::{Handle, HandleId, HandleObject, HandleValue, MutableHandleValue};
|
||||
use js::rust::wrappers::JS_DeletePropertyById;
|
||||
use js::rust::wrappers::JS_ForwardGetPropertyTo;
|
||||
|
@ -124,7 +124,9 @@ unsafe impl Sync for DOMJSClass {}
|
|||
pub fn get_proto_or_iface_array(global: *mut JSObject) -> *mut ProtoOrIfaceArray {
|
||||
unsafe {
|
||||
assert_ne!(((*get_object_class(global)).flags & JSCLASS_DOM_GLOBAL), 0);
|
||||
JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT).to_private() as *mut ProtoOrIfaceArray
|
||||
let mut slot = UndefinedValue();
|
||||
JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT, &mut slot);
|
||||
slot.to_private() as *mut ProtoOrIfaceArray
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,14 +389,14 @@ unsafe extern "C" fn wrap(cx: *mut JSContext,
|
|||
}
|
||||
|
||||
unsafe extern "C" fn pre_wrap(cx: *mut JSContext,
|
||||
_existing: RawHandleObject,
|
||||
_scope: RawHandleObject,
|
||||
obj: RawHandleObject,
|
||||
_object_passed_to_wrap: RawHandleObject)
|
||||
-> *mut JSObject {
|
||||
_object_passed_to_wrap: RawHandleObject,
|
||||
rval: RawMutableHandleObject) {
|
||||
let _ac = JSAutoCompartment::new(cx, obj.get());
|
||||
let obj = ToWindowProxyIfWindow(obj.get());
|
||||
assert!(!obj.is_null());
|
||||
obj
|
||||
rval.set(obj)
|
||||
}
|
||||
|
||||
/// Callback table for use with JS_SetWrapObjectCallbacks
|
||||
|
|
|
@ -15,8 +15,10 @@ use dom::bindings::cell::DomRefCell;
|
|||
use dom::bindings::reflector::DomObject;
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
use js::jsapi::{JSTracer, JS_GetReservedSlot, JS_SetReservedSlot};
|
||||
use js::glue::JS_GetReservedSlot;
|
||||
use js::jsapi::{JSTracer, JS_SetReservedSlot};
|
||||
use js::jsval::PrivateValue;
|
||||
use js::jsval::UndefinedValue;
|
||||
use libc::c_void;
|
||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||
use std::cell::{Cell, UnsafeCell};
|
||||
|
@ -53,16 +55,17 @@ pub trait WeakReferenceable: DomObject + Sized {
|
|||
fn downgrade(&self) -> WeakRef<Self> {
|
||||
unsafe {
|
||||
let object = self.reflector().get_jsobject().get();
|
||||
let mut ptr = JS_GetReservedSlot(object,
|
||||
DOM_WEAK_SLOT)
|
||||
.to_private() as *mut WeakBox<Self>;
|
||||
let mut slot = UndefinedValue();
|
||||
JS_GetReservedSlot(object, DOM_WEAK_SLOT, &mut slot);
|
||||
let mut ptr = slot.to_private() as *mut WeakBox<Self>;
|
||||
if ptr.is_null() {
|
||||
trace!("Creating new WeakBox holder for {:p}.", self);
|
||||
ptr = Box::into_raw(Box::new(WeakBox {
|
||||
count: Cell::new(1),
|
||||
value: Cell::new(Some(ptr::NonNull::from(self))),
|
||||
}));
|
||||
JS_SetReservedSlot(object, DOM_WEAK_SLOT, PrivateValue(ptr as *const c_void));
|
||||
let val = PrivateValue(ptr as *const c_void);
|
||||
JS_SetReservedSlot(object, DOM_WEAK_SLOT, &val);
|
||||
}
|
||||
let box_ = &*ptr;
|
||||
assert!(box_.value.get().is_some());
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use devtools;
|
||||
use devtools_traits::DevtoolScriptControlMsg;
|
||||
use dom::abstractworker::{SharedRt, SimpleWorkerErrorHandler, WorkerScriptMsg};
|
||||
use dom::abstractworker::{SimpleWorkerErrorHandler, WorkerScriptMsg};
|
||||
use dom::abstractworkerglobalscope::{SendableWorkerScriptChan, WorkerThreadWorkerChan};
|
||||
use dom::bindings::cell::DomRefCell;
|
||||
use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding;
|
||||
|
@ -25,7 +25,8 @@ use dom::workerglobalscope::WorkerGlobalScope;
|
|||
use dom_struct::dom_struct;
|
||||
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
|
||||
use ipc_channel::router::ROUTER;
|
||||
use js::jsapi::{JS_SetInterruptCallback, JSAutoCompartment, JSContext};
|
||||
use js::jsapi::{JSAutoCompartment, JSContext};
|
||||
use js::jsapi::JS_AddInterruptCallback;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::HandleValue;
|
||||
use msg::constellation_msg::TopLevelBrowsingContextId;
|
||||
|
@ -37,7 +38,7 @@ use script_traits::{TimerEvent, TimerSource, WorkerGlobalScopeInit, WorkerScript
|
|||
use servo_rand::random;
|
||||
use servo_url::ServoUrl;
|
||||
use std::mem::replace;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel};
|
||||
use std::thread;
|
||||
|
@ -153,7 +154,6 @@ impl DedicatedWorkerGlobalScope {
|
|||
pub fn run_worker_scope(init: WorkerGlobalScopeInit,
|
||||
worker_url: ServoUrl,
|
||||
from_devtools_receiver: IpcReceiver<DevtoolScriptControlMsg>,
|
||||
worker_rt_for_mainthread: Arc<Mutex<Option<SharedRt>>>,
|
||||
worker: TrustedWorkerAddress,
|
||||
parent_sender: Box<ScriptChan + Send>,
|
||||
own_sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
||||
|
@ -206,7 +206,6 @@ impl DedicatedWorkerGlobalScope {
|
|||
let source = String::from_utf8_lossy(&bytes);
|
||||
|
||||
let runtime = unsafe { new_rt_and_cx() };
|
||||
*worker_rt_for_mainthread.lock().unwrap() = Some(SharedRt::new(&runtime));
|
||||
|
||||
let (devtools_mpsc_chan, devtools_mpsc_port) = channel();
|
||||
ROUTER.route_ipc_receiver_to_mpsc_sender(from_devtools_receiver, devtools_mpsc_chan);
|
||||
|
@ -229,7 +228,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
|
||||
unsafe {
|
||||
// Handle interrupt requests
|
||||
JS_SetInterruptCallback(scope.runtime(), Some(interrupt_callback));
|
||||
JS_AddInterruptCallback(scope.get_cx(), Some(interrupt_callback));
|
||||
}
|
||||
|
||||
if scope.is_closing() {
|
||||
|
|
|
@ -31,8 +31,7 @@ use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL};
|
|||
use js::glue::{IsWrapper, UnwrapObject};
|
||||
use js::jsapi::{CurrentGlobalOrNull, GetGlobalForObjectCrossCompartment};
|
||||
use js::jsapi::{JSAutoCompartment, JSContext};
|
||||
use js::jsapi::{JSObject, JS_GetContext};
|
||||
use js::jsapi::JS_GetObjectRuntime;
|
||||
use js::jsapi::JSObject;
|
||||
use js::panic::maybe_resume_unwind;
|
||||
use js::rust::{CompileOptionsWrapper, Runtime, get_object_class};
|
||||
use js::rust::{HandleValue, MutableHandleValue};
|
||||
|
@ -229,16 +228,8 @@ impl GlobalScope {
|
|||
GlobalScope::from_object(obj)
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn get_cx(&self) -> *mut JSContext {
|
||||
unsafe {
|
||||
let runtime = JS_GetObjectRuntime(
|
||||
self.reflector().get_jsobject().get());
|
||||
assert!(!runtime.is_null());
|
||||
let context = JS_GetContext(runtime);
|
||||
assert!(!context.is_null());
|
||||
context
|
||||
}
|
||||
Runtime::get()
|
||||
}
|
||||
|
||||
pub fn crypto(&self) -> DomRoot<Crypto> {
|
||||
|
|
|
@ -21,12 +21,11 @@ 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_GetContext, JS_GetFunctionObject};
|
||||
use js::jsapi::{JS_GetObjectRuntime, JS_NewFunction};
|
||||
use js::jsapi::{NewFunctionWithReserved, PromiseState};
|
||||
use js::jsapi::{JSAutoCompartment, JSContext, JSObject, JS_GetFunctionObject};
|
||||
use js::jsapi::{JS_NewFunction, NewFunctionWithReserved, PromiseState};
|
||||
use js::jsapi::{RemoveRawValueRoot, SetFunctionNativeReserved};
|
||||
use js::jsval::{JSVal, UndefinedValue, ObjectValue, Int32Value};
|
||||
use js::rust::{HandleObject, HandleValue, MutableHandleObject};
|
||||
use js::rust::{HandleObject, HandleValue, MutableHandleObject, Runtime};
|
||||
use js::rust::wrappers::{AddPromiseReactions, CallOriginalPromiseResolve, CallOriginalPromiseReject};
|
||||
use js::rust::wrappers::{GetPromiseState, IsPromiseObject};
|
||||
use js::rust::wrappers::{NewPromiseObject, ResolvePromise, RejectPromise};
|
||||
|
@ -67,9 +66,7 @@ impl Drop for Promise {
|
|||
unsafe {
|
||||
let object = self.permanent_js_root.get().to_object();
|
||||
assert!(!object.is_null());
|
||||
let runtime = JS_GetObjectRuntime(object);
|
||||
assert!(!runtime.is_null());
|
||||
let cx = JS_GetContext(runtime);
|
||||
let cx = Runtime::get();
|
||||
assert!(!cx.is_null());
|
||||
RemoveRawValueRoot(cx, self.permanent_js_root.get_unsafe());
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ use dom::workerglobalscope::WorkerGlobalScope;
|
|||
use dom_struct::dom_struct;
|
||||
use ipc_channel::ipc::{self, IpcSender, IpcReceiver};
|
||||
use ipc_channel::router::ROUTER;
|
||||
use js::jsapi::{JS_SetInterruptCallback, JSAutoCompartment, JSContext};
|
||||
use js::jsapi::{JSAutoCompartment, JSContext, JS_AddInterruptCallback};
|
||||
use js::jsval::UndefinedValue;
|
||||
use net_traits::{load_whole_resource, IpcSend, CustomResponseMediator};
|
||||
use net_traits::request::{CredentialsMode, Destination, RequestInit};
|
||||
|
@ -197,7 +197,7 @@ impl ServiceWorkerGlobalScope {
|
|||
|
||||
unsafe {
|
||||
// Handle interrupt requests
|
||||
JS_SetInterruptCallback(scope.runtime(), Some(interrupt_callback));
|
||||
JS_AddInterruptCallback(scope.get_cx(), Some(interrupt_callback));
|
||||
}
|
||||
|
||||
scope.execute_script(DOMString::from(source));
|
||||
|
|
|
@ -60,9 +60,12 @@ use euclid::{Point2D, Vector2D, Rect, Size2D, TypedPoint2D, TypedScale, TypedSiz
|
|||
use fetch;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use ipc_channel::router::ROUTER;
|
||||
use js::jsapi::{JSAutoCompartment, JSContext};
|
||||
use js::jsapi::{JS_GC, JS_GetRuntime, JSPROP_ENUMERATE};
|
||||
use js::jsval::{JSVal, UndefinedValue};
|
||||
use js::jsapi::JSAutoCompartment;
|
||||
use js::jsapi::JSContext;
|
||||
use js::jsapi::JSPROP_ENUMERATE;
|
||||
use js::jsapi::JS_GC;
|
||||
use js::jsval::JSVal;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::HandleValue;
|
||||
use js::rust::wrappers::JS_DefineProperty;
|
||||
use layout_image::fetch_image_for_layout;
|
||||
|
@ -595,9 +598,7 @@ impl WindowMethods for Window {
|
|||
obj,
|
||||
"opener\0".as_ptr() as *const libc::c_char,
|
||||
value,
|
||||
JSPROP_ENUMERATE,
|
||||
None,
|
||||
None));
|
||||
JSPROP_ENUMERATE as u32));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-window-closed
|
||||
|
@ -878,7 +879,7 @@ impl WindowMethods for Window {
|
|||
#[allow(unsafe_code)]
|
||||
fn Gc(&self) {
|
||||
unsafe {
|
||||
JS_GC(JS_GetRuntime(self.get_cx()));
|
||||
JS_GC(self.get_cx());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ use embedder_traits::EmbedderMsg;
|
|||
use ipc_channel::ipc;
|
||||
use js::JSCLASS_IS_GLOBAL;
|
||||
use js::glue::{CreateWrapperProxyHandler, ProxyTraps};
|
||||
use js::glue::{GetProxyPrivate, SetProxyExtra, GetProxyExtra};
|
||||
use js::glue::{GetProxyPrivate, SetProxyReservedSlot, GetProxyReservedSlot};
|
||||
use js::jsapi::{JSAutoCompartment, JSContext, JSErrNum, JSFreeOp, JSObject};
|
||||
use js::jsapi::{JSPROP_ENUMERATE, JSPROP_READONLY, JSTracer, JS_DefinePropertyById};
|
||||
use js::jsapi::{JS_ForwardGetPropertyTo, JS_ForwardSetPropertyTo};
|
||||
|
@ -156,7 +156,7 @@ impl WindowProxy {
|
|||
|
||||
// The window proxy owns the browsing context.
|
||||
// When we finalize the window proxy, it drops the browsing context it owns.
|
||||
SetProxyExtra(js_proxy.get(), 0, &PrivateValue((&*window_proxy).as_void_ptr()));
|
||||
SetProxyReservedSlot(js_proxy.get(), 0, &PrivateValue((&*window_proxy).as_void_ptr()));
|
||||
|
||||
// Notify the JS engine about the new window proxy binding.
|
||||
SetWindowProxy(cx, window_jsobject, js_proxy.handle());
|
||||
|
@ -205,7 +205,7 @@ impl WindowProxy {
|
|||
|
||||
// The window proxy owns the browsing context.
|
||||
// When we finalize the window proxy, it drops the browsing context it owns.
|
||||
SetProxyExtra(js_proxy.get(), 0, &PrivateValue((&*window_proxy).as_void_ptr()));
|
||||
SetProxyReservedSlot(js_proxy.get(), 0, &PrivateValue((&*window_proxy).as_void_ptr()));
|
||||
|
||||
// Notify the JS engine about the new window proxy binding.
|
||||
SetWindowProxy(cx, window_jsobject, js_proxy.handle());
|
||||
|
@ -460,7 +460,7 @@ impl WindowProxy {
|
|||
let _ac = JSAutoCompartment::new(cx, window_jsobject.get());
|
||||
|
||||
// The old window proxy no longer owns this browsing context.
|
||||
SetProxyExtra(old_js_proxy.get(), 0, &PrivateValue(ptr::null_mut()));
|
||||
SetProxyReservedSlot(old_js_proxy.get(), 0, &PrivateValue(ptr::null_mut()));
|
||||
|
||||
// Brain transpant the window proxy.
|
||||
// We need to do this, because the Window and WindowProxy
|
||||
|
@ -475,7 +475,7 @@ impl WindowProxy {
|
|||
debug!("Transplanted proxy is {:p}.", new_js_proxy.get());
|
||||
|
||||
// Transfer ownership of this browsing context from the old window proxy to the new one.
|
||||
SetProxyExtra(new_js_proxy.get(), 0, &PrivateValue(self.as_void_ptr()));
|
||||
SetProxyReservedSlot(new_js_proxy.get(), 0, &PrivateValue(self.as_void_ptr()));
|
||||
|
||||
// Notify the JS engine about the new window proxy binding.
|
||||
SetWindowProxy(cx, window_jsobject, new_js_proxy.handle());
|
||||
|
@ -523,7 +523,9 @@ unsafe fn GetSubframeWindowProxy(
|
|||
) -> Option<(DomRoot<WindowProxy>, u32)> {
|
||||
let index = get_array_index_from_id(cx, Handle::from_raw(id));
|
||||
if let Some(index) = index {
|
||||
rooted!(in(cx) let target = GetProxyPrivate(*proxy).to_object());
|
||||
let mut slot = UndefinedValue();
|
||||
GetProxyPrivate(*proxy, &mut slot);
|
||||
rooted!(in(cx) let target = slot.to_object());
|
||||
if let Ok(win) = root_from_handleobject::<Window>(target.handle()) {
|
||||
let browsing_context_id = win.window_proxy().browsing_context_id();
|
||||
let (result_sender, result_receiver) = ipc::channel().unwrap();
|
||||
|
@ -538,7 +540,7 @@ unsafe fn GetSubframeWindowProxy(
|
|||
return result_receiver.recv().ok()
|
||||
.and_then(|maybe_bcid| maybe_bcid)
|
||||
.and_then(ScriptThread::find_window_proxy)
|
||||
.map(|proxy| (proxy, JSPROP_ENUMERATE | JSPROP_READONLY));
|
||||
.map(|proxy| (proxy, (JSPROP_ENUMERATE | JSPROP_READONLY) as u32));
|
||||
} else if let Ok(win) = root_from_handleobject::<DissimilarOriginWindow>(target.handle()) {
|
||||
let browsing_context_id = win.window_proxy().browsing_context_id();
|
||||
let (result_sender, result_receiver) = ipc::channel().unwrap();
|
||||
|
@ -551,7 +553,7 @@ unsafe fn GetSubframeWindowProxy(
|
|||
return result_receiver.recv().ok()
|
||||
.and_then(|maybe_bcid| maybe_bcid)
|
||||
.and_then(ScriptThread::find_window_proxy)
|
||||
.map(|proxy| (proxy, JSPROP_READONLY));
|
||||
.map(|proxy| (proxy, JSPROP_READONLY as u32));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -573,7 +575,9 @@ unsafe extern "C" fn getOwnPropertyDescriptor(cx: *mut JSContext,
|
|||
return true;
|
||||
}
|
||||
|
||||
rooted!(in(cx) let target = GetProxyPrivate(proxy.get()).to_object());
|
||||
let mut slot = UndefinedValue();
|
||||
GetProxyPrivate(proxy.get(), &mut slot);
|
||||
rooted!(in(cx) let target = slot.to_object());
|
||||
if !JS_GetOwnPropertyDescriptorById(cx, target.handle().into(), id, desc) {
|
||||
return false;
|
||||
}
|
||||
|
@ -603,7 +607,9 @@ unsafe extern "C" fn defineProperty(cx: *mut JSContext,
|
|||
return true;
|
||||
}
|
||||
|
||||
rooted!(in(cx) let target = GetProxyPrivate(*proxy.ptr).to_object());
|
||||
let mut slot = UndefinedValue();
|
||||
GetProxyPrivate(*proxy.ptr, &mut slot);
|
||||
rooted!(in(cx) let target = slot.to_object());
|
||||
JS_DefinePropertyById(cx, target.handle().into(), id, desc, res)
|
||||
}
|
||||
|
||||
|
@ -619,7 +625,9 @@ unsafe extern "C" fn has(cx: *mut JSContext,
|
|||
return true;
|
||||
}
|
||||
|
||||
rooted!(in(cx) let target = GetProxyPrivate(*proxy.ptr).to_object());
|
||||
let mut slot = UndefinedValue();
|
||||
GetProxyPrivate(*proxy.ptr, &mut slot);
|
||||
rooted!(in(cx) let target = slot.to_object());
|
||||
let mut found = false;
|
||||
if !JS_HasPropertyById(cx, target.handle().into(), id, &mut found) {
|
||||
return false;
|
||||
|
@ -642,7 +650,9 @@ unsafe extern "C" fn get(cx: *mut JSContext,
|
|||
return true;
|
||||
}
|
||||
|
||||
rooted!(in(cx) let target = GetProxyPrivate(*proxy.ptr).to_object());
|
||||
let mut slot = UndefinedValue();
|
||||
GetProxyPrivate(*proxy.ptr, &mut slot);
|
||||
rooted!(in(cx) let target = slot.to_object());
|
||||
JS_ForwardGetPropertyTo(cx, target.handle().into(), id, receiver, vp)
|
||||
}
|
||||
|
||||
|
@ -660,7 +670,9 @@ unsafe extern "C" fn set(cx: *mut JSContext,
|
|||
return true;
|
||||
}
|
||||
|
||||
rooted!(in(cx) let target = GetProxyPrivate(*proxy.ptr).to_object());
|
||||
let mut slot = UndefinedValue();
|
||||
GetProxyPrivate(*proxy.ptr, &mut slot);
|
||||
rooted!(in(cx) let target = slot.to_object());
|
||||
JS_ForwardSetPropertyTo(cx,
|
||||
target.handle().into(),
|
||||
id,
|
||||
|
@ -750,7 +762,9 @@ unsafe extern "C" fn has_xorigin(cx: *mut JSContext,
|
|||
bp: *mut bool)
|
||||
-> bool
|
||||
{
|
||||
rooted!(in(cx) let target = GetProxyPrivate(*proxy.ptr).to_object());
|
||||
let mut slot = UndefinedValue();
|
||||
GetProxyPrivate(*proxy.ptr, &mut slot);
|
||||
rooted!(in(cx) let target = slot.to_object());
|
||||
let mut found = false;
|
||||
JS_HasOwnPropertyById(cx, target.handle().into(), id, &mut found);
|
||||
if found {
|
||||
|
@ -864,7 +878,9 @@ static XORIGIN_PROXY_HANDLER: ProxyTraps = ProxyTraps {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe extern fn finalize(_fop: *mut JSFreeOp, obj: *mut JSObject) {
|
||||
let this = GetProxyExtra(obj, 0).to_private() as *mut WindowProxy;
|
||||
let mut slot = UndefinedValue();
|
||||
GetProxyReservedSlot(obj, 0, &mut slot);
|
||||
let this = slot.to_private() as *mut WindowProxy;
|
||||
if this.is_null() {
|
||||
// GC during obj creation or after transplanting.
|
||||
return;
|
||||
|
@ -876,7 +892,9 @@ unsafe extern fn finalize(_fop: *mut JSFreeOp, obj: *mut JSObject) {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
unsafe extern fn trace(trc: *mut JSTracer, obj: *mut JSObject) {
|
||||
let this = GetProxyExtra(obj, 0).to_private() as *const WindowProxy;
|
||||
let mut slot = UndefinedValue();
|
||||
GetProxyReservedSlot(obj, 0, &mut slot);
|
||||
let this = slot.to_private() as *const WindowProxy;
|
||||
if this.is_null() {
|
||||
// GC during obj creation or after transplanting.
|
||||
return;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg};
|
||||
use dom::abstractworker::{SharedRt, SimpleWorkerErrorHandler};
|
||||
use dom::abstractworker::SimpleWorkerErrorHandler;
|
||||
use dom::abstractworker::WorkerScriptMsg;
|
||||
use dom::bindings::codegen::Bindings::WorkerBinding;
|
||||
use dom::bindings::codegen::Bindings::WorkerBinding::WorkerMethods;
|
||||
|
@ -21,12 +21,12 @@ use dom::messageevent::MessageEvent;
|
|||
use dom::workerglobalscope::prepare_workerscope_init;
|
||||
use dom_struct::dom_struct;
|
||||
use ipc_channel::ipc;
|
||||
use js::jsapi::{JSAutoCompartment, JSContext};
|
||||
use js::jsapi::{JSAutoCompartment, JSContext, JS_RequestInterruptCallback};
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::rust::HandleValue;
|
||||
use script_traits::WorkerScriptLoadOrigin;
|
||||
use std::cell::Cell;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::mpsc::{Sender, channel};
|
||||
use task::TaskOnce;
|
||||
|
@ -43,8 +43,6 @@ pub struct Worker {
|
|||
sender: Sender<(TrustedWorkerAddress, WorkerScriptMsg)>,
|
||||
#[ignore_malloc_size_of = "Arc"]
|
||||
closing: Arc<AtomicBool>,
|
||||
#[ignore_malloc_size_of = "Defined in rust-mozjs"]
|
||||
runtime: Arc<Mutex<Option<SharedRt>>>,
|
||||
terminated: Cell<bool>,
|
||||
}
|
||||
|
||||
|
@ -55,7 +53,6 @@ impl Worker {
|
|||
eventtarget: EventTarget::new_inherited(),
|
||||
sender: sender,
|
||||
closing: closing,
|
||||
runtime: Arc::new(Mutex::new(None)),
|
||||
terminated: Cell::new(false),
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +103,7 @@ impl Worker {
|
|||
let init = prepare_workerscope_init(global, Some(devtools_sender));
|
||||
|
||||
DedicatedWorkerGlobalScope::run_worker_scope(
|
||||
init, worker_url, devtools_receiver, worker.runtime.clone(), worker_ref,
|
||||
init, worker_url, devtools_receiver, worker_ref,
|
||||
global.script_chan(), sender, receiver, worker_load_origin, closing);
|
||||
|
||||
Ok(worker)
|
||||
|
@ -155,6 +152,7 @@ impl WorkerMethods for Worker {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
// https://html.spec.whatwg.org/multipage/#terminate-a-worker
|
||||
fn Terminate(&self) {
|
||||
// Step 1
|
||||
|
@ -166,9 +164,8 @@ impl WorkerMethods for Worker {
|
|||
self.terminated.set(true);
|
||||
|
||||
// Step 3
|
||||
if let Some(runtime) = *self.runtime.lock().unwrap() {
|
||||
runtime.request_interrupt();
|
||||
}
|
||||
let cx = self.global().get_cx();
|
||||
unsafe { JS_RequestInterruptCallback(cx) };
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#handler-worker-onmessage
|
||||
|
|
|
@ -26,7 +26,7 @@ use dom::workernavigator::WorkerNavigator;
|
|||
use dom_struct::dom_struct;
|
||||
use fetch;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use js::jsapi::{JSAutoCompartment, JSContext, JSRuntime};
|
||||
use js::jsapi::{JSAutoCompartment, JSContext};
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::panic::maybe_resume_unwind;
|
||||
use js::rust::HandleValue;
|
||||
|
@ -139,10 +139,6 @@ impl WorkerGlobalScope {
|
|||
&self.from_devtools_receiver
|
||||
}
|
||||
|
||||
pub fn runtime(&self) -> *mut JSRuntime {
|
||||
self.runtime.rt()
|
||||
}
|
||||
|
||||
pub fn get_cx(&self) -> *mut JSContext {
|
||||
self.runtime.cx()
|
||||
}
|
||||
|
|
|
@ -517,14 +517,14 @@ impl WorkletThread {
|
|||
/// The current memory usage of the thread
|
||||
#[allow(unsafe_code)]
|
||||
fn current_memory_usage(&self) -> u32 {
|
||||
unsafe { JS_GetGCParameter(self.runtime.rt(), JSGCParamKey::JSGC_BYTES) }
|
||||
unsafe { JS_GetGCParameter(self.runtime.cx(), JSGCParamKey::JSGC_BYTES) }
|
||||
}
|
||||
|
||||
/// Perform a GC.
|
||||
#[allow(unsafe_code)]
|
||||
fn gc(&mut self) {
|
||||
debug!("BEGIN GC (usage = {}, threshold = {}).", self.current_memory_usage(), self.gc_threshold);
|
||||
unsafe { JS_GC(self.runtime.rt()) };
|
||||
unsafe { JS_GC(self.runtime.cx()) };
|
||||
self.gc_threshold = max(MIN_GC_THRESHOLD, self.current_memory_usage() * 2);
|
||||
debug!("END GC (usage = {}, threshold = {}).", self.current_memory_usage(), self.gc_threshold);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue