Adapt Servo for mozjs 0.6 and the changes introduced in servo/rust-mozjs#393

This commit is contained in:
Marcin Mielniczuk 2018-03-28 21:28:30 +02:00
parent e04d517bff
commit 356c57e628
48 changed files with 403 additions and 307 deletions

View file

@ -10,13 +10,13 @@ use dom::bindings::root::{Dom, DomRoot};
use dom::bindings::settings_stack::{AutoEntryScript, AutoIncumbentScript};
use dom::bindings::utils::AsCCharPtrPtr;
use dom::globalscope::GlobalScope;
use js::jsapi::{Heap, MutableHandleObject};
use js::jsapi::{IsCallable, JSContext, JSObject, JS_WrapObject, AddRawValueRoot};
use js::jsapi::{IsCallable, JSContext, JSObject, AddRawValueRoot};
use js::jsapi::{JSCompartment, JS_EnterCompartment, JS_LeaveCompartment, RemoveRawValueRoot};
use js::jsapi::Heap;
use js::jsapi::JSAutoCompartment;
use js::jsapi::JS_GetProperty;
use js::jsval::{JSVal, UndefinedValue, ObjectValue};
use js::rust::Runtime;
use js::rust::{MutableHandleObject, Runtime};
use js::rust::wrappers::{JS_WrapObject, JS_GetProperty};
use std::default::Default;
use std::ffi::CString;
use std::mem::drop;
@ -206,7 +206,7 @@ impl CallbackInterface {
/// Wraps the reflector for `p` into the compartment of `cx`.
pub fn wrap_call_this_object<T: DomObject>(cx: *mut JSContext,
p: &T,
rval: MutableHandleObject) {
mut rval: MutableHandleObject) {
rval.set(p.reflector().get_jsobject().get());
assert!(!rval.get().is_null());

View file

@ -2326,11 +2326,11 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
'dom::bindings::trace::RootedTraceableBox',
'dom::types::*',
'js::error::throw_type_error',
'js::jsapi::HandleValue',
'js::rust::HandleValue',
'js::jsapi::Heap',
'js::jsapi::JSContext',
'js::jsapi::JSObject',
'js::jsapi::MutableHandleValue',
'js::rust::MutableHandleValue',
'js::jsval::JSVal',
'js::typedarray'
]
@ -2590,7 +2590,7 @@ def CopyUnforgeablePropertiesToInstance(descriptor):
if descriptor.proxy:
copyCode += """\
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
ensure_expando_object(cx, obj.handle(), expando.handle_mut());
ensure_expando_object(cx, obj.handle().into(), expando.handle_mut());
"""
obj = "expando"
else:
@ -2887,13 +2887,13 @@ assert!(!prototype_proto.is_null());""" % getPrototypeProto)]
code.append(CGGeneric("""
rooted!(in(cx) let mut prototype = ptr::null_mut::<JSObject>());
create_interface_prototype_object(cx,
prototype_proto.handle(),
prototype_proto.handle().into(),
&PrototypeClass,
%(methods)s,
%(attrs)s,
%(consts)s,
%(unscopables)s,
prototype.handle_mut());
prototype.handle_mut().into());
assert!(!prototype.is_null());
assert!((*cache)[PrototypeList::ID::%(id)s as usize].is_null());
(*cache)[PrototypeList::ID::%(id)s as usize] = prototype.get();
@ -2922,7 +2922,7 @@ assert!(!interface_proto.is_null());
rooted!(in(cx) let mut interface = ptr::null_mut::<JSObject>());
create_noncallback_interface_object(cx,
global,
global.into(),
interface_proto.handle(),
&INTERFACE_OBJECT_CLASS,
%(static_methods)s,
@ -3044,7 +3044,7 @@ class CGGetPerInterfaceObject(CGAbstractMethod):
def __init__(self, descriptor, name, idPrefix="", pub=False):
args = [Argument('*mut JSContext', 'cx'),
Argument('HandleObject', 'global'),
Argument('MutableHandleObject', 'rval')]
Argument('MutableHandleObject', 'mut rval')]
CGAbstractMethod.__init__(self, descriptor, name,
'void', args, pub=pub, unsafe=True)
self.id = idPrefix + "::" + MakeNativeName(self.descriptor.name)
@ -4080,7 +4080,8 @@ pub enum %s {
inner = string.Template("""\
use dom::bindings::conversions::ToJSValConvertible;
use js::jsapi::{JSContext, MutableHandleValue};
use js::jsapi::JSContext;
use js::rust::MutableHandleValue;
use js::jsval::JSVal;
pub const pairs: &'static [(&'static str, super::${ident})] = &[
@ -4856,7 +4857,7 @@ class CGProxyNamedOperation(CGProxySpecialOperation):
def define(self):
# Our first argument is the id we're getting.
argName = self.arguments[0].identifier.name
return ("let %s = jsid_to_string(cx, id).expect(\"Not a string-convertible JSID?\");\n"
return ("let %s = jsid_to_string(cx, Handle::from_raw(id)).expect(\"Not a string-convertible JSID?\");\n"
"let this = UnwrapProxy(proxy);\n"
"let this = &*this;\n" % argName +
CGProxySpecialOperation.define(self))
@ -4899,7 +4900,7 @@ class CGProxyNamedDeleter(CGProxyNamedOperation):
class CGProxyUnwrap(CGAbstractMethod):
def __init__(self, descriptor):
args = [Argument('HandleObject', 'obj')]
args = [Argument('RawHandleObject', 'obj')]
CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy",
'*const ' + descriptor.concreteType, args,
alwaysInline=True, unsafe=True)
@ -4916,9 +4917,9 @@ return box_;""" % self.descriptor.concreteType)
class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', 'proxy'),
Argument('HandleId', 'id'),
Argument('MutableHandle<PropertyDescriptor>', 'desc')]
args = [Argument('*mut JSContext', 'cx'), Argument('RawHandleObject', 'proxy'),
Argument('RawHandleId', 'id'),
Argument('RawMutableHandle<PropertyDescriptor>', 'desc')]
CGAbstractExternMethod.__init__(self, descriptor, "getOwnPropertyDescriptor",
"bool", args)
self.descriptor = descriptor
@ -4929,14 +4930,14 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
get = ""
if indexedGetter:
get = "let index = get_array_index_from_id(cx, id);\n"
get = "let index = get_array_index_from_id(cx, Handle::from_raw(id));\n"
attrs = "JSPROP_ENUMERATE"
if self.descriptor.operations['IndexedSetter'] is None:
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(desc, proxy.get(), %s);\n"
"fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), %s);\n"
"return true;" % attrs)
templateValues = {
'jsvalRef': 'result_root.handle_mut()',
@ -4962,7 +4963,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(desc, proxy.get(), %s);\n"
"fill_property_descriptor(MutableHandle::from_raw(desc), proxy.get(), %s);\n"
"return true;" % attrs)
templateValues = {
'jsvalRef': 'result_root.handle_mut()',
@ -4980,7 +4981,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
namedGet = """
if %s {
let mut has_on_proto = false;
if !has_property_on_prototype(cx, proxy, id, &mut has_on_proto) {
if !has_property_on_prototype(cx, proxy_lt, id_lt, &mut has_on_proto) {
return false;
}
if !has_on_proto {
@ -4996,8 +4997,10 @@ if %s {
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
get_expando_object(proxy, expando.handle_mut());
//if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) {
let proxy_lt = Handle::from_raw(proxy);
let id_lt = Handle::from_raw(id);
if !expando.is_null() {
if !JS_GetPropertyDescriptorById(cx, expando.handle(), id, desc) {
if !JS_GetPropertyDescriptorById(cx, expando.handle().into(), id, desc) {
return false;
}
if !desc.obj.is_null() {
@ -5016,9 +5019,9 @@ return true;"""
class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', 'proxy'),
Argument('HandleId', 'id'),
Argument('Handle<PropertyDescriptor>', 'desc'),
args = [Argument('*mut JSContext', 'cx'), Argument('RawHandleObject', 'proxy'),
Argument('RawHandleId', 'id'),
Argument('RawHandle<PropertyDescriptor>', 'desc'),
Argument('*mut ObjectOpResult', 'opresult')]
CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "bool", args)
self.descriptor = descriptor
@ -5028,7 +5031,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
indexedSetter = self.descriptor.operations['IndexedSetter']
if indexedSetter:
set += ("let index = get_array_index_from_id(cx, id);\n" +
set += ("let index = get_array_index_from_id(cx, Handle::from_raw(id));\n" +
"if let Some(index) = index {\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = &*this;\n" +
@ -5036,7 +5039,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
" return (*opresult).succeed();\n" +
"}\n")
elif self.descriptor.operations['IndexedGetter']:
set += ("if get_array_index_from_id(cx, id).is_some() {\n" +
set += ("if get_array_index_from_id(cx, Handle::from_raw(id)).is_some() {\n" +
" return (*opresult).failNoIndexedSetter();\n" +
"}\n")
@ -5065,8 +5068,8 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
class CGDOMJSProxyHandler_delete(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', 'proxy'),
Argument('HandleId', 'id'),
args = [Argument('*mut JSContext', 'cx'), Argument('RawHandleObject', 'proxy'),
Argument('RawHandleId', 'id'),
Argument('*mut ObjectOpResult', 'res')]
CGAbstractExternMethod.__init__(self, descriptor, "delete", "bool", args)
self.descriptor = descriptor
@ -5088,7 +5091,7 @@ class CGDOMJSProxyHandler_delete(CGAbstractExternMethod):
class CGDOMJSProxyHandler_ownPropertyKeys(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'),
Argument('HandleObject', 'proxy'),
Argument('RawHandleObject', 'proxy'),
Argument('*mut AutoIdVector', 'props')]
CGAbstractExternMethod.__init__(self, descriptor, "own_property_keys", "bool", args)
self.descriptor = descriptor
@ -5143,7 +5146,7 @@ class CGDOMJSProxyHandler_getOwnEnumerablePropertyKeys(CGAbstractExternMethod):
assert (descriptor.operations["IndexedGetter"] and
descriptor.interface.getExtendedAttribute("LegacyUnenumerableNamedProperties"))
args = [Argument('*mut JSContext', 'cx'),
Argument('HandleObject', 'proxy'),
Argument('RawHandleObject', 'proxy'),
Argument('*mut AutoIdVector', 'props')]
CGAbstractExternMethod.__init__(self, descriptor,
"getOwnEnumerablePropertyKeys", "bool", args)
@ -5183,15 +5186,15 @@ class CGDOMJSProxyHandler_getOwnEnumerablePropertyKeys(CGAbstractExternMethod):
class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', 'proxy'),
Argument('HandleId', 'id'), Argument('*mut bool', 'bp')]
args = [Argument('*mut JSContext', 'cx'), Argument('RawHandleObject', 'proxy'),
Argument('RawHandleId', 'id'), Argument('*mut bool', 'bp')]
CGAbstractExternMethod.__init__(self, descriptor, "hasOwn", "bool", args)
self.descriptor = descriptor
def getBody(self):
indexedGetter = self.descriptor.operations['IndexedGetter']
if indexedGetter:
indexed = ("let index = get_array_index_from_id(cx, id);\n" +
indexed = ("let index = get_array_index_from_id(cx, Handle::from_raw(id));\n" +
"if let Some(index) = index {\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = &*this;\n" +
@ -5210,7 +5213,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
named = """\
if %s {
let mut has_on_proto = false;
if !has_property_on_prototype(cx, proxy, id, &mut has_on_proto) {
if !has_property_on_prototype(cx, proxy_lt, id_lt, &mut has_on_proto) {
return false;
}
if !has_on_proto {
@ -5226,9 +5229,11 @@ if %s {
return indexed + """\
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
let proxy_lt = Handle::from_raw(proxy);
let id_lt = Handle::from_raw(id);
get_expando_object(proxy, expando.handle_mut());
if !expando.is_null() {
let ok = JS_HasPropertyById(cx, expando.handle(), id, bp);
let ok = JS_HasPropertyById(cx, expando.handle().into(), id, bp);
if !ok || *bp {
return ok;
}
@ -5243,9 +5248,9 @@ return true;"""
class CGDOMJSProxyHandler_get(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', 'proxy'),
Argument('HandleValue', 'receiver'), Argument('HandleId', 'id'),
Argument('MutableHandleValue', 'vp')]
args = [Argument('*mut JSContext', 'cx'), Argument('RawHandleObject', 'proxy'),
Argument('RawHandleValue', 'receiver'), Argument('RawHandleId', 'id'),
Argument('RawMutableHandleValue', 'vp')]
CGAbstractExternMethod.__init__(self, descriptor, "get", "bool", args)
self.descriptor = descriptor
@ -5256,23 +5261,23 @@ rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
get_expando_object(proxy, expando.handle_mut());
if !expando.is_null() {
let mut hasProp = false;
if !JS_HasPropertyById(cx, expando.handle(), id, &mut hasProp) {
if !JS_HasPropertyById(cx, expando.handle().into(), id, &mut hasProp) {
return false;
}
if hasProp {
return JS_ForwardGetPropertyTo(cx, expando.handle(), id, receiver, vp);
return JS_ForwardGetPropertyTo(cx, expando.handle().into(), id, receiver, vp);
}
}"""
templateValues = {
'jsvalRef': 'vp',
'jsvalRef': 'vp_lt',
'successCode': 'return true;',
}
indexedGetter = self.descriptor.operations['IndexedGetter']
if indexedGetter:
getIndexedOrExpando = ("let index = get_array_index_from_id(cx, id);\n" +
getIndexedOrExpando = ("let index = get_array_index_from_id(cx, id_lt);\n" +
"if let Some(index) = index {\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = &*this;\n" +
@ -5305,10 +5310,14 @@ if !expando.is_null() {
return """\
//MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
//"Should not have a XrayWrapper here");
let proxy_lt = Handle::from_raw(proxy);
let vp_lt = MutableHandle::from_raw(vp);
let id_lt = Handle::from_raw(id);
let receiver_lt = Handle::from_raw(receiver);
%s
let mut found = false;
if !get_property_on_prototype(cx, proxy, receiver, id, &mut found, vp) {
if !get_property_on_prototype(cx, proxy_lt, receiver_lt, id_lt, &mut found, vp_lt) {
return false;
}
@ -5325,7 +5334,7 @@ return true;""" % (getIndexedOrExpando, getNamed)
class CGDOMJSProxyHandler_className(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'), Argument('HandleObject', '_proxy')]
args = [Argument('*mut JSContext', 'cx'), Argument('RawHandleObject', '_proxy')]
CGAbstractExternMethod.__init__(self, descriptor, "className", "*const i8", args, doesNotPanic=True)
self.descriptor = descriptor
@ -5660,16 +5669,20 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::error::throw_type_error',
'js::error::throw_internal_error',
'js::jsapi::AutoIdVector',
'js::jsapi::Call',
'js::rust::wrappers::Call',
'js::jsapi::CallArgs',
'js::jsapi::CurrentGlobalOrNull',
'js::jsapi::FreeOp',
'js::jsapi::GetPropertyKeys',
'js::rust::wrappers::GetPropertyKeys',
'js::jsapi::GetWellKnownSymbol',
'js::jsapi::Handle',
'js::jsapi::HandleId',
'js::jsapi::HandleObject',
'js::jsapi::HandleValue',
'js::rust::Handle',
'js::jsapi::Handle as RawHandle',
'js::rust::HandleId',
'js::jsapi::HandleId as RawHandleId',
'js::rust::HandleObject',
'js::jsapi::HandleObject as RawHandleObject',
'js::rust::HandleValue',
'js::jsapi::HandleValue as RawHandleValue',
'js::jsapi::HandleValueArray',
'js::jsapi::Heap',
'js::jsapi::INTERNED_STRING_TO_JSID',
@ -5704,37 +5717,40 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::jsapi::JSTypedMethodJitInfo',
'js::jsapi::JSValueType',
'js::jsapi::JS_AtomizeAndPinString',
'js::jsapi::JS_CallFunctionValue',
'js::jsapi::JS_CopyPropertiesFrom',
'js::jsapi::JS_DefineProperty',
'js::jsapi::JS_DefinePropertyById2',
'js::rust::wrappers::JS_CallFunctionValue',
'js::rust::wrappers::JS_CopyPropertiesFrom',
'js::rust::wrappers::JS_DefineProperty',
'js::rust::wrappers::JS_DefinePropertyById2',
'js::jsapi::JS_ForwardGetPropertyTo',
'js::jsapi::JS_GetErrorPrototype',
'js::jsapi::JS_GetFunctionPrototype',
'js::rust::wrappers::JS_GetFunctionPrototype',
'js::jsapi::JS_GetGlobalForObject',
'js::jsapi::JS_GetIteratorPrototype',
'js::jsapi::JS_GetObjectPrototype',
'js::jsapi::JS_GetProperty',
'js::rust::wrappers::JS_GetObjectPrototype',
'js::rust::wrappers::JS_GetProperty',
'js::jsapi::JS_GetPropertyById',
'js::jsapi::JS_GetPropertyDescriptorById',
'js::jsapi::JS_GetReservedSlot',
'js::jsapi::JS_HasProperty',
'js::jsapi::JS_HasPropertyById',
'js::jsapi::JS_InitializePropertiesFromCompatibleNativeObject',
'js::rust::wrappers::JS_InitializePropertiesFromCompatibleNativeObject',
'js::jsapi::JS_NewObject',
'js::jsapi::JS_NewObjectWithGivenProto',
'js::jsapi::JS_NewObjectWithoutMetadata',
'js::jsapi::JS_ObjectIsDate',
'js::jsapi::JS_SetImmutablePrototype',
'js::jsapi::JS_SetProperty',
'js::jsapi::JS_SetPrototype',
'js::rust::wrappers::JS_NewObjectWithGivenProto',
'js::rust::wrappers::JS_NewObjectWithoutMetadata',
'js::rust::wrappers::JS_ObjectIsDate',
'js::rust::wrappers::JS_SetImmutablePrototype',
'js::rust::wrappers::JS_SetProperty',
'js::rust::wrappers::JS_SetPrototype',
'js::jsapi::JS_SetReservedSlot',
'js::jsapi::JS_SplicePrototype',
'js::jsapi::JS_WrapValue',
'js::jsapi::JS_WrapObject',
'js::jsapi::MutableHandle',
'js::jsapi::MutableHandleObject',
'js::jsapi::MutableHandleValue',
'js::rust::wrappers::JS_SplicePrototype',
'js::rust::wrappers::JS_WrapValue',
'js::rust::wrappers::JS_WrapObject',
'js::rust::MutableHandle',
'js::jsapi::MutableHandle as RawMutableHandle',
'js::rust::MutableHandleObject',
'js::jsapi::MutableHandleObject as RawMutableHandleObject',
'js::rust::MutableHandleValue',
'js::jsapi::MutableHandleValue as RawMutableHandleValue',
'js::jsapi::ObjectOpResult',
'js::jsapi::PropertyDescriptor',
'js::jsapi::Rooted',
@ -5755,7 +5771,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::glue::CallJitSetterOp',
'js::glue::CreateProxyHandler',
'js::glue::GetProxyPrivate',
'js::glue::NewProxyObject',
'js::rust::wrappers::NewProxyObject',
'js::glue::ProxyTraps',
'js::glue::RUST_JSID_IS_INT',
'js::glue::RUST_JSID_IS_STRING',
@ -6241,7 +6257,7 @@ class CGDictionary(CGThing):
"}\n"
"\n"
"impl ToJSValConvertible for ${selfName} {\n"
" unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {\n"
" unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {\n"
" rooted!(in(cx) let obj = JS_NewObject(cx, ptr::null()));\n"
"${insertMembers}"
" rval.set(ObjectOrNullValue(obj.get()))\n"
@ -7132,7 +7148,8 @@ class GlobalGenRoots():
def InterfaceObjectMap(config):
mods = [
"dom::bindings::codegen",
"js::jsapi::{HandleObject, JSContext}",
"js::jsapi::JSContext",
"js::rust::HandleObject",
"phf",
]
imports = CGList([CGGeneric("use %s;" % mod) for mod in mods], "\n")
@ -7166,7 +7183,7 @@ class GlobalGenRoots():
pairs.append((ctor.identifier.name, binding, binding))
pairs.sort(key=operator.itemgetter(0))
mappings = [
CGGeneric('"%s": "codegen::Bindings::%s::%s::DefineDOMInterface as unsafe fn(_, _)"' % pair)
CGGeneric('"%s": "codegen::Bindings::%s::%s::DefineDOMInterface"' % pair)
for pair in pairs
]
return CGWrapper(

View file

@ -4,9 +4,11 @@
//! WebIDL constants.
use js::jsapi::{HandleObject, JSContext, JSPROP_ENUMERATE, JSPROP_PERMANENT};
use js::jsapi::{JSPROP_READONLY, JS_DefineProperty};
use js::jsapi::{JSContext, JSPROP_ENUMERATE, JSPROP_PERMANENT};
use js::jsapi::JSPROP_READONLY;
use js::jsval::{BooleanValue, DoubleValue, Int32Value, JSVal, NullValue, UInt32Value};
use js::rust::HandleObject;
use js::rust::wrappers::JS_DefineProperty;
use libc;
/// Representation of an IDL constant.

View file

@ -41,19 +41,21 @@ use dom::bindings::str::{ByteString, DOMString, USVString};
use dom::bindings::trace::{JSTraceable, RootedTraceableBox};
use dom::bindings::utils::DOMClass;
use js;
pub use js::conversions::{FromJSValConvertible, ToJSValConvertible, ConversionResult};
pub use js::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible};
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::{RUST_JSID_IS_INT, RUST_JSID_TO_INT};
use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING, UnwrapObject};
use js::jsapi::{HandleId, HandleObject, HandleValue, Heap, JSContext, JSObject, JSString};
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetProperty, JS_GetReservedSlot};
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_IsArrayObject, JS_IsExceptionPending};
use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars, MutableHandleValue};
use js::glue::{UnwrapObject, RUST_JSID_IS_STRING, RUST_JSID_TO_STRING};
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_NewStringCopyN, JS_StringHasLatin1Chars};
use js::jsval::{ObjectValue, StringValue, UndefinedValue};
use js::rust::{ToString, get_object_class, is_dom_class, is_dom_object, maybe_wrap_value};
use js::rust::{HandleId, HandleObject, HandleValue, MutableHandleValue};
use js::rust::{get_object_class, is_dom_class, is_dom_object, maybe_wrap_value, ToString};
use js::rust::wrappers::{JS_GetProperty, JS_IsArrayObject};
use libc;
use num_traits::Float;
use servo_config::opts;
@ -149,12 +151,13 @@ impl<T> FromJSValConvertible for RootedTraceableBox<Heap<T>>
///
/// Handling of invalid UTF-16 in strings depends on the relevant option.
pub unsafe fn jsid_to_string(cx: *mut JSContext, id: HandleId) -> Option<DOMString> {
if RUST_JSID_IS_STRING(id) {
return Some(jsstring_to_str(cx, RUST_JSID_TO_STRING(id)));
let id_raw = id.into();
if RUST_JSID_IS_STRING(id_raw) {
return Some(jsstring_to_str(cx, RUST_JSID_TO_STRING(id_raw)));
}
if RUST_JSID_IS_INT(id) {
return Some(RUST_JSID_TO_INT(id).to_string().into());
if RUST_JSID_IS_INT(id_raw) {
return Some(RUST_JSID_TO_INT(id_raw).to_string().into());
}
None
@ -269,7 +272,7 @@ impl FromJSValConvertible for USVString {
// http://heycam.github.io/webidl/#es-ByteString
impl ToJSValConvertible for ByteString {
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
let jsstr = JS_NewStringCopyN(cx,
self.as_ptr() as *const libc::c_char,
self.len() as libc::size_t);
@ -319,7 +322,7 @@ impl FromJSValConvertible for ByteString {
impl ToJSValConvertible for Reflector {
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
let obj = self.get_jsobject().get();
assert!(!obj.is_null());
rval.set(ObjectValue(obj));
@ -485,7 +488,7 @@ pub unsafe fn is_array_like(cx: *mut JSContext, value: HandleValue) -> bool {
pub unsafe fn get_property_jsval(cx: *mut JSContext,
object: HandleObject,
name: &str,
rval: MutableHandleValue)
mut rval: MutableHandleValue)
-> Fallible<()>
{
rval.set(UndefinedValue());

View file

@ -12,15 +12,15 @@ use dom::bindings::str::USVString;
use dom::domexception::{DOMErrorName, DOMException};
use dom::globalscope::GlobalScope;
use js::error::{throw_range_error, throw_type_error};
use js::jsapi::HandleObject;
use js::jsapi::JSContext;
use js::jsapi::JS_ClearPendingException;
use js::jsapi::JS_ErrorFromException;
use js::jsapi::JS_GetPendingException;
use js::jsapi::JS_IsExceptionPending;
use js::jsapi::JS_SetPendingException;
use js::jsapi::MutableHandleValue;
use js::jsval::UndefinedValue;
use js::rust::HandleObject;
use js::rust::MutableHandleValue;
use js::rust::wrappers::JS_ErrorFromException;
use js::rust::wrappers::JS_GetPendingException;
use js::rust::wrappers::JS_SetPendingException;
use libc::c_uint;
use std::slice::from_raw_parts;

View file

@ -4,7 +4,8 @@
//! Machinery to conditionally expose things.
use js::jsapi::{HandleObject, JSContext};
use js::jsapi::JSContext;
use js::rust::HandleObject;
use servo_config::prefs::PREFS;
/// A container with a condition.

View file

@ -82,8 +82,8 @@ use html5ever::interface::QualName;
use js::glue::UnwrapObject;
use js::jsapi::{CallArgs, CurrentGlobalOrNull};
use js::jsapi::{JSAutoCompartment, JSContext, JSObject};
use js::jsapi::HandleObject;
use js::jsapi::MutableHandleObject;
use js::rust::HandleObject;
use js::rust::MutableHandleObject;
use script_thread::ScriptThread;
use std::ptr;

View file

@ -6,27 +6,31 @@
use dom::bindings::codegen::InterfaceObjectMap::Globals;
use dom::bindings::codegen::PrototypeList;
use dom::bindings::constant::{ConstantSpec, define_constants};
use dom::bindings::conversions::{DOM_OBJECT_SLOT, get_dom_class};
use dom::bindings::constant::{define_constants, ConstantSpec};
use dom::bindings::conversions::{get_dom_class, DOM_OBJECT_SLOT};
use dom::bindings::guard::Guard;
use dom::bindings::utils::{DOM_PROTOTYPE_SLOT, ProtoOrIfaceArray, get_proto_or_iface_array};
use dom::bindings::utils::{get_proto_or_iface_array, ProtoOrIfaceArray, DOM_PROTOTYPE_SLOT};
use js::error::throw_type_error;
use js::glue::{RUST_SYMBOL_TO_JSID, UncheckedUnwrapObject};
use js::glue::{UncheckedUnwrapObject, RUST_SYMBOL_TO_JSID};
use js::jsapi::{Class, ClassOps, CompartmentOptions};
use js::jsapi::{GetGlobalForObjectCrossCompartment, GetWellKnownSymbol, HandleObject, HandleValue};
use js::jsapi::{JSAutoCompartment, JSClass, JSContext, JSFUN_CONSTRUCTOR, JSFunctionSpec, JSObject};
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::{JS_DefineProperty, JS_DefineProperty1, JS_DefineProperty2};
use js::jsapi::{JS_DefineProperty4, JS_DefinePropertyById3, JS_FireOnNewGlobalObject};
use js::jsapi::{JS_GetFunctionObject, JS_GetPrototype};
use js::jsapi::{JS_LinkConstructorAndPrototype, JS_NewFunction, JS_NewGlobalObject};
use js::jsapi::{JS_NewObject, JS_NewObjectWithUniqueType, JS_NewPlainObject};
use js::jsapi::{JS_NewStringCopyN, JS_SetReservedSlot, MutableHandleObject};
use js::jsapi::{MutableHandleValue, ObjectOps, OnNewGlobalHookOption, SymbolCode};
use js::jsapi::{JS_GetFunctionObject, JS_NewFunction, JS_NewGlobalObject};
use js::jsapi::{JS_NewObject, JS_NewPlainObject};
use js::jsapi::{JS_NewStringCopyN, JS_SetReservedSlot};
use js::jsapi::{ObjectOps, OnNewGlobalHookOption, SymbolCode};
use js::jsapi::{TrueHandleValue, Value};
use js::jsapi::HandleObject as RawHandleObject;
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_FireOnNewGlobalObject, JS_GetPrototype};
use js::rust::wrappers::{JS_LinkConstructorAndPrototype, JS_NewObjectWithUniqueType};
use libc;
use std::ptr;
@ -130,7 +134,7 @@ pub unsafe fn create_global_object(
class: &'static JSClass,
private: *const libc::c_void,
trace: TraceHook,
rval: MutableHandleObject) {
mut rval: MutableHandleObject) {
assert!(rval.is_null());
let mut options = CompartmentOptions::default();
@ -164,10 +168,10 @@ pub unsafe fn create_callback_interface_object(
global: HandleObject,
constants: &[Guard<&[ConstantSpec]>],
name: &[u8],
rval: MutableHandleObject) {
mut rval: MutableHandleObject) {
assert!(!constants.is_empty());
rval.set(JS_NewObject(cx, ptr::null()));
assert!(!rval.ptr.is_null());
assert!(!rval.is_null());
define_guarded_constants(cx, rval.handle(), constants);
define_name(cx, rval.handle(), name);
define_on_global_object(cx, global, name, rval.handle());
@ -265,9 +269,9 @@ pub unsafe fn create_object(
methods: &[Guard<&'static [JSFunctionSpec]>],
properties: &[Guard<&'static [JSPropertySpec]>],
constants: &[Guard<&[ConstantSpec]>],
rval: MutableHandleObject) {
mut rval: MutableHandleObject) {
rval.set(JS_NewObjectWithUniqueType(cx, class, proto));
assert!(!rval.ptr.is_null());
assert!(!rval.is_null());
define_guarded_methods(cx, rval.handle(), methods);
define_guarded_properties(cx, rval.handle(), properties);
define_guarded_constants(cx, rval.handle(), constants);
@ -349,7 +353,7 @@ const OBJECT_OPS: ObjectOps = ObjectOps {
};
unsafe extern "C" fn fun_to_string_hook(cx: *mut JSContext,
obj: HandleObject,
obj: RawHandleObject,
_indent: u32)
-> *mut JSString {
let js_class = get_object_class(obj.get());
@ -363,10 +367,12 @@ unsafe extern "C" fn fun_to_string_hook(cx: *mut JSContext,
/// Hook for instanceof on interface objects.
unsafe extern "C" fn has_instance_hook(cx: *mut JSContext,
obj: HandleObject,
value: MutableHandleValue,
obj: RawHandleObject,
value: RawMutableHandleValue,
rval: *mut bool) -> bool {
match has_instance(cx, obj, value.handle()) {
let obj_raw = HandleObject::from_raw(obj);
let val_raw = HandleValue::from_raw(value.handle());
match has_instance(cx, obj_raw, val_raw) {
Ok(result) => {
*rval = result;
true
@ -386,6 +392,8 @@ unsafe fn has_instance(
// Step 1.
return Ok(false);
}
rooted!(in(cx) let mut value_out = value.to_object());
rooted!(in(cx) let mut value = value.to_object());
let js_class = get_object_class(interface_object.get());
@ -407,7 +415,8 @@ unsafe fn has_instance(
assert!(!prototype.is_null());
// Step 3 only concern legacy callback interface objects (i.e. NodeFilter).
while JS_GetPrototype(cx, value.handle(), value.handle_mut()) {
while JS_GetPrototype(cx, value.handle(), value_out.handle_mut()) {
*value = *value_out;
if value.is_null() {
// Step 5.2.
return Ok(false);
@ -423,16 +432,22 @@ unsafe fn has_instance(
unsafe fn create_unscopable_object(
cx: *mut JSContext,
names: &[&[u8]],
rval: MutableHandleObject) {
mut rval: MutableHandleObject) {
assert!(!names.is_empty());
assert!(rval.is_null());
rval.set(JS_NewPlainObject(cx));
assert!(!rval.ptr.is_null());
assert!(!rval.is_null());
for &name in names {
assert_eq!(*name.last().unwrap(), b'\0');
assert!(JS_DefineProperty(
cx, rval.handle(), name.as_ptr() as *const libc::c_char, TrueHandleValue,
JSPROP_READONLY, None, None));
cx,
rval.handle(),
name.as_ptr() as *const libc::c_char,
HandleValue::from_raw(TrueHandleValue),
JSPROP_READONLY,
None,
None
));
}
}
@ -443,7 +458,7 @@ unsafe fn define_name(cx: *mut JSContext, obj: HandleObject, name: &[u8]) {
assert!(JS_DefineProperty2(cx,
obj,
b"name\0".as_ptr() as *const libc::c_char,
name.handle(),
name.handle().into(),
JSPROP_READONLY,
None, None));
}

View file

@ -15,8 +15,9 @@ use dom::bindings::trace::{JSTraceable, RootedTraceableBox};
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use js::conversions::ToJSValConvertible;
use js::jsapi::{HandleValue, Heap, JSContext, MutableHandleObject, JSObject};
use js::jsapi::{Heap, JSContext, JSObject};
use js::jsval::UndefinedValue;
use js::rust::{HandleValue, MutableHandleObject};
use std::cell::Cell;
use std::ptr;
use std::ptr::NonNull;
@ -111,7 +112,7 @@ impl<T: DomObject + JSTraceable + Iterable> IterableIterator<T> {
}
fn dict_return(cx: *mut JSContext,
result: MutableHandleObject,
mut result: MutableHandleObject,
done: bool,
value: HandleValue) -> Fallible<()> {
let mut dict = unsafe { IterableKeyOrValueResult::empty(cx) };
@ -126,7 +127,7 @@ fn dict_return(cx: *mut JSContext,
}
fn key_and_value_return(cx: *mut JSContext,
result: MutableHandleObject,
mut result: MutableHandleObject,
key: HandleValue,
value: HandleValue) -> Fallible<()> {
let mut dict = unsafe { IterableKeyAndValueResult::empty(cx) };

View file

@ -6,19 +6,19 @@
use dom::bindings::conversions::jsid_to_string;
use dom::bindings::str::DOMString;
use js::conversions::{FromJSValConvertible, ToJSValConvertible, ConversionResult};
use js::jsapi::GetPropertyKeys;
use js::jsapi::HandleValue;
use js::conversions::{ConversionResult, FromJSValConvertible, ToJSValConvertible};
use js::jsapi::JSContext;
use js::jsapi::JSITER_OWNONLY;
use js::jsapi::JSPROP_ENUMERATE;
use js::jsapi::JS_DefineUCProperty2;
use js::jsapi::JS_GetPropertyById;
use js::jsapi::JS_NewPlainObject;
use js::jsapi::MutableHandleValue;
use js::jsval::ObjectValue;
use js::jsval::UndefinedValue;
use js::rust::HandleValue;
use js::rust::IdVector;
use js::rust::MutableHandleValue;
use js::rust::wrappers::GetPropertyKeys;
use js::rust::wrappers::JS_DefineUCProperty2;
use js::rust::wrappers::JS_GetPropertyById;
use std::collections::HashMap;
use std::ops::Deref;
@ -86,7 +86,7 @@ impl<T, C> FromJSValConvertible for MozMap<T>
impl<T: ToJSValConvertible> ToJSValConvertible for MozMap<T> {
#[inline]
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {
rooted!(in(cx) let js_object = JS_NewPlainObject(cx));
assert!(!js_object.handle().is_null());

View file

@ -6,7 +6,8 @@
use dom::bindings::guard::Guard;
use dom::bindings::interface::{create_object, define_on_global_object};
use js::jsapi::{HandleObject, JSClass, JSContext, JSFunctionSpec, MutableHandleObject};
use js::jsapi::{JSClass, JSContext, JSFunctionSpec};
use js::rust::{HandleObject, MutableHandleObject};
use libc;
/// The class of a namespace object.

View file

@ -11,15 +11,22 @@ use dom::bindings::utils::delete_property_by_id;
use js::glue::{GetProxyHandler, GetProxyHandlerFamily, SetProxyExtra};
use js::glue::GetProxyExtra;
use js::glue::InvokeGetOwnPropertyDescriptor;
use js::jsapi::{DOMProxyShadowsResult, JSContext, JSObject, JSPROP_GETTER, PropertyDescriptor};
use js::jsapi::{Handle, HandleId, HandleObject, MutableHandle, ObjectOpResult};
use js::jsapi::{JSErrNum, JS_AlreadyHasOwnPropertyById, JS_StrictPropertyStub};
use js::jsapi::{JS_DefinePropertyById, JS_NewObjectWithGivenProto, SetDOMProxyInformation};
use js::jsapi::{DOMProxyShadowsResult, JSContext, JSObject, PropertyDescriptor, JSPROP_GETTER};
use js::jsapi::{JSErrNum, JS_StrictPropertyStub, SetDOMProxyInformation};
use js::jsapi::GetObjectProto;
use js::jsapi::GetStaticPrototype;
use js::jsapi::Handle as RawHandle;
use js::jsapi::HandleId as RawHandleId;
use js::jsapi::HandleObject as RawHandleObject;
use js::jsapi::JS_DefinePropertyById;
use js::jsapi::JS_GetPropertyDescriptorById;
use js::jsapi::MutableHandleObject;
use js::jsapi::MutableHandle as RawMutableHandle;
use js::jsapi::MutableHandleObject as RawMutableHandleObject;
use js::jsapi::ObjectOpResult;
use js::jsval::ObjectValue;
use js::rust::{Handle, HandleObject, MutableHandle, MutableHandleObject};
use js::rust::wrappers::JS_AlreadyHasOwnPropertyById;
use js::rust::wrappers::JS_NewObjectWithGivenProto;
use std::ptr;
@ -27,8 +34,8 @@ 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: HandleObject,
id: HandleId)
object: RawHandleObject,
id: RawHandleId)
-> DOMProxyShadowsResult {
// TODO: support OverrideBuiltins when #12978 is fixed.
@ -36,7 +43,9 @@ pub unsafe extern "C" fn shadow_check_callback(cx: *mut JSContext,
get_expando_object(object, expando.handle_mut());
if !expando.get().is_null() {
let mut has_own = false;
if !JS_AlreadyHasOwnPropertyById(cx, expando.handle(), id, &mut has_own) {
let raw_id = Handle::from_raw(id);
if !JS_AlreadyHasOwnPropertyById(cx, expando.handle(), raw_id, &mut has_own) {
return DOMProxyShadowsResult::ShadowCheckFailed;
}
@ -61,9 +70,9 @@ pub unsafe fn init() {
/// Otherwise, walk along the prototype chain to find a property with that
/// name.
pub unsafe extern "C" fn get_property_descriptor(cx: *mut JSContext,
proxy: HandleObject,
id: HandleId,
desc: MutableHandle<PropertyDescriptor>)
proxy: RawHandleObject,
id: RawHandleId,
desc: RawMutableHandle<PropertyDescriptor>)
-> bool {
let handler = GetProxyHandler(proxy.get());
if !InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, desc) {
@ -74,20 +83,20 @@ pub unsafe extern "C" fn get_property_descriptor(cx: *mut JSContext,
}
rooted!(in(cx) let mut proto = ptr::null_mut::<JSObject>());
if !GetObjectProto(cx, proxy, proto.handle_mut()) {
if !GetObjectProto(cx, proxy, proto.handle_mut().into()) {
// FIXME(#11868) Should assign to desc.obj, desc.get() is a copy.
desc.get().obj = ptr::null_mut();
return true;
}
JS_GetPropertyDescriptorById(cx, proto.handle(), id, desc)
JS_GetPropertyDescriptorById(cx, proto.handle().into(), id, desc)
}
/// Defines an expando on the given `proxy`.
pub unsafe extern "C" fn define_property(cx: *mut JSContext,
proxy: HandleObject,
id: HandleId,
desc: Handle<PropertyDescriptor>,
proxy: RawHandleObject,
id: RawHandleId,
desc: RawHandle<PropertyDescriptor>,
result: *mut ObjectOpResult)
-> bool {
if (desc.get().attrs & JSPROP_GETTER) != 0 && desc.get().setter == Some(JS_StrictPropertyStub) {
@ -97,13 +106,13 @@ pub unsafe extern "C" fn define_property(cx: *mut JSContext,
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
ensure_expando_object(cx, proxy, expando.handle_mut());
JS_DefinePropertyById(cx, expando.handle(), id, desc, result)
JS_DefinePropertyById(cx, expando.handle().into(), id, desc, result)
}
/// Deletes an expando off the given `proxy`.
pub unsafe extern "C" fn delete(cx: *mut JSContext,
proxy: HandleObject,
id: HandleId,
proxy: RawHandleObject,
id: RawHandleId,
bp: *mut ObjectOpResult)
-> bool {
rooted!(in(cx) let mut expando = ptr::null_mut::<JSObject>());
@ -113,12 +122,12 @@ pub unsafe extern "C" fn delete(cx: *mut JSContext,
return true;
}
delete_property_by_id(cx, expando.handle(), id, bp)
delete_property_by_id(cx, expando.handle(), Handle::from_raw(id), bp)
}
/// Controls whether the Extensible bit can be changed
pub unsafe extern "C" fn prevent_extensions(_cx: *mut JSContext,
_proxy: HandleObject,
_proxy: RawHandleObject,
result: *mut ObjectOpResult)
-> bool {
(*result).code_ = JSErrNum::JSMSG_CANT_PREVENT_EXTENSIONS as ::libc::uintptr_t;
@ -127,7 +136,7 @@ pub unsafe extern "C" fn prevent_extensions(_cx: *mut JSContext,
/// Reports whether the object is Extensible
pub unsafe extern "C" fn is_extensible(_cx: *mut JSContext,
_proxy: HandleObject,
_proxy: RawHandleObject,
succeeded: *mut bool)
-> bool {
*succeeded = true;
@ -144,9 +153,9 @@ pub unsafe extern "C" fn is_extensible(_cx: *mut JSContext,
/// `[[GetPrototypeOf]]` behavior. An alternative implementation will be
/// necessary for the Location object.
pub unsafe extern "C" fn get_prototype_if_ordinary(_: *mut JSContext,
proxy: HandleObject,
proxy: RawHandleObject,
is_ordinary: *mut bool,
proto: MutableHandleObject)
proto: RawMutableHandleObject)
-> bool {
*is_ordinary = true;
proto.set(GetStaticPrototype(proxy.get()));
@ -154,7 +163,7 @@ 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: HandleObject, expando: MutableHandleObject) {
pub unsafe fn get_expando_object(obj: RawHandleObject, mut expando: MutableHandleObject) {
assert!(is_dom_proxy(obj.get()));
let val = GetProxyExtra(obj.get(), JSPROXYSLOT_EXPANDO);
expando.set(if val.is_undefined() {
@ -166,7 +175,7 @@ pub unsafe fn get_expando_object(obj: HandleObject, expando: MutableHandleObject
/// Get the expando object, or create it if it doesn't exist yet.
/// Fails on JSAPI failure.
pub unsafe fn ensure_expando_object(cx: *mut JSContext, obj: HandleObject, expando: MutableHandleObject) {
pub unsafe fn ensure_expando_object(cx: *mut JSContext, obj: RawHandleObject, mut expando: MutableHandleObject) {
assert!(is_dom_proxy(obj.get()));
get_expando_object(obj, expando);
if expando.is_null() {

View file

@ -7,7 +7,8 @@
use dom::bindings::conversions::DerivedFrom;
use dom::bindings::root::DomRoot;
use dom::globalscope::GlobalScope;
use js::jsapi::{HandleObject, JSContext, JSObject, Heap};
use js::jsapi::{JSContext, JSObject, Heap};
use js::rust::HandleObject;
use std::default::Default;
/// Create the reflector for a new DOM object and yield ownership to the

View file

@ -11,13 +11,17 @@ use dom::bindings::reflector::DomObject;
use dom::bindings::root::DomRoot;
use dom::blob::{Blob, BlobImpl};
use dom::globalscope::GlobalScope;
use js::jsapi::{Handle, HandleObject, HandleValue, MutableHandleValue, JSAutoCompartment, JSContext};
use js::jsapi::{JSAutoCompartment, JSContext};
use js::jsapi::{JSStructuredCloneCallbacks, JSStructuredCloneReader, JSStructuredCloneWriter};
use js::jsapi::{JS_ClearPendingException, JSObject, JS_ReadStructuredClone};
use js::jsapi::{JS_ClearPendingException, JSObject};
use js::jsapi::{JS_ReadBytes, JS_WriteBytes};
use js::jsapi::{JS_ReadUint32Pair, JS_WriteUint32Pair};
use js::jsapi::{JS_STRUCTURED_CLONE_VERSION, JS_WriteStructuredClone};
use js::jsapi::{MutableHandleObject, TransferableOwnership};
use js::jsapi::HandleObject as RawHandleObject;
use js::jsapi::JS_STRUCTURED_CLONE_VERSION;
use js::jsapi::MutableHandleObject as RawMutableHandleObject;
use js::jsapi::TransferableOwnership;
use js::rust::{Handle, HandleValue, MutableHandleValue};
use js::rust::wrappers::{JS_WriteStructuredClone, JS_ReadStructuredClone};
use libc::size_t;
use std::os::raw;
use std::ptr;
@ -137,10 +141,10 @@ unsafe extern "C" fn read_callback(cx: *mut JSContext,
unsafe extern "C" fn write_callback(_cx: *mut JSContext,
w: *mut JSStructuredCloneWriter,
obj: HandleObject,
obj: RawHandleObject,
_closure: *mut raw::c_void)
-> bool {
if let Ok(blob) = root_from_handleobject::<Blob>(obj) {
if let Ok(blob) = root_from_handleobject::<Blob>(Handle::from_raw(obj)) {
return write_blob(blob, w).is_ok()
}
return false
@ -152,13 +156,13 @@ unsafe extern "C" fn read_transfer_callback(_cx: *mut JSContext,
_content: *mut raw::c_void,
_extra_data: u64,
_closure: *mut raw::c_void,
_return_object: MutableHandleObject)
_return_object: RawMutableHandleObject)
-> bool {
false
}
unsafe extern "C" fn write_transfer_callback(_cx: *mut JSContext,
_obj: Handle<*mut JSObject>,
_obj: RawHandleObject,
_closure: *mut raw::c_void,
_tag: *mut u32,
_ownership: *mut TransferableOwnership,

View file

@ -59,9 +59,9 @@ use hyper::mime::Mime;
use hyper::status::StatusCode;
use ipc_channel::ipc::{IpcReceiver, IpcSender};
use js::glue::{CallObjectTracer, CallValueTracer};
use js::jsapi::{GCTraceKindToAscii, Heap, Handle, JSObject, JSTracer, TraceKind};
use js::jsapi::{GCTraceKindToAscii, Heap, JSObject, JSTracer, TraceKind};
use js::jsval::JSVal;
use js::rust::{GCMethods, Runtime};
use js::rust::{GCMethods, Handle, Runtime};
use js::typedarray::TypedArray;
use js::typedarray::TypedArrayElement;
use metrics::{InteractiveMetrics, InteractiveWindow};

View file

@ -20,16 +20,24 @@ use js::glue::{GetCrossCompartmentWrapper, 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::{HandleId, HandleObject, HandleValue, Heap, JSAutoCompartment, JSContext};
use js::jsapi::{Heap, JSAutoCompartment, JSContext};
use js::jsapi::{JSJitInfo, JSObject, JSTracer, JSWrapObjectCallbacks};
use js::jsapi::{JS_DeletePropertyById, JS_EnumerateStandardClasses};
use js::jsapi::{JS_ForwardGetPropertyTo, JS_GetLatin1StringCharsAndLength};
use js::jsapi::{JS_GetProperty, JS_GetPrototype, JS_GetReservedSlot, JS_HasProperty};
use js::jsapi::{JS_HasPropertyById, JS_IsExceptionPending, JS_IsGlobalObject};
use js::jsapi::{JS_ResolveStandardClass, JS_SetProperty, ToWindowProxyIfWindow};
use js::jsapi::{JS_StringHasLatin1Chars, MutableHandleValue, ObjectOpResult};
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::HandleId as RawHandleId;
use js::jsapi::HandleObject as RawHandleObject;
use js::jsval::{JSVal, UndefinedValue};
use js::rust::{GCMethods, ToString, 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;
use js::rust::wrappers::JS_GetProperty;
use js::rust::wrappers::JS_GetPrototype;
use js::rust::wrappers::JS_HasProperty;
use js::rust::wrappers::JS_HasPropertyById;
use js::rust::wrappers::JS_SetProperty;
use libc;
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use std::ffi::CString;
@ -144,8 +152,7 @@ pub unsafe fn get_property_on_prototype(cx: *mut JSContext,
return false;
}
*found = has_property;
let no_output = vp.ptr.is_null();
if !has_property || no_output {
if !has_property {
return true;
}
@ -155,9 +162,10 @@ pub unsafe fn get_property_on_prototype(cx: *mut JSContext,
/// Get an array index from the given `jsid`. Returns `None` if the given
/// `jsid` is not an integer.
pub fn get_array_index_from_id(_cx: *mut JSContext, id: HandleId) -> Option<u32> {
let raw_id = id.into();
unsafe {
if RUST_JSID_IS_INT(id) {
return Some(RUST_JSID_TO_INT(id) as u32);
if RUST_JSID_IS_INT(raw_id) {
return Some(RUST_JSID_TO_INT(raw_id) as u32);
}
None
}
@ -320,13 +328,13 @@ pub unsafe fn trace_global(tracer: *mut JSTracer, obj: *mut JSObject) {
}
/// Enumerate lazy properties of a global object.
pub unsafe extern "C" fn enumerate_global(cx: *mut JSContext, obj: HandleObject) -> bool {
pub unsafe extern "C" fn enumerate_global(cx: *mut JSContext, obj: RawHandleObject) -> bool {
assert!(JS_IsGlobalObject(obj.get()));
if !JS_EnumerateStandardClasses(cx, obj) {
return false;
}
for init_fun in InterfaceObjectMap::MAP.values() {
init_fun(cx, obj);
init_fun(cx, Handle::from_raw(obj));
}
true
}
@ -334,8 +342,8 @@ pub unsafe extern "C" fn enumerate_global(cx: *mut JSContext, obj: HandleObject)
/// Resolve a lazy global property, for interface objects and named constructors.
pub unsafe extern "C" fn resolve_global(
cx: *mut JSContext,
obj: HandleObject,
id: HandleId,
obj: RawHandleObject,
id: RawHandleId,
rval: *mut bool)
-> bool {
assert!(JS_IsGlobalObject(obj.get()));
@ -361,7 +369,7 @@ pub unsafe extern "C" fn resolve_global(
let bytes = slice::from_raw_parts(ptr, length as usize);
if let Some(init_fun) = InterfaceObjectMap::MAP.get(bytes) {
init_fun(cx, obj);
init_fun(cx, Handle::from_raw(obj));
*rval = true;
} else {
*rval = false;
@ -370,8 +378,8 @@ pub unsafe extern "C" fn resolve_global(
}
unsafe extern "C" fn wrap(cx: *mut JSContext,
_existing: HandleObject,
obj: HandleObject)
_existing: RawHandleObject,
obj: RawHandleObject)
-> *mut JSObject {
// FIXME terrible idea. need security wrappers
// https://github.com/servo/servo/issues/2382
@ -379,9 +387,9 @@ unsafe extern "C" fn wrap(cx: *mut JSContext,
}
unsafe extern "C" fn pre_wrap(cx: *mut JSContext,
_existing: HandleObject,
obj: HandleObject,
_object_passed_to_wrap: HandleObject)
_existing: RawHandleObject,
obj: RawHandleObject,
_object_passed_to_wrap: RawHandleObject)
-> *mut JSObject {
let _ac = JSAutoCompartment::new(cx, obj.get());
let obj = ToWindowProxyIfWindow(obj.get());
@ -409,7 +417,7 @@ unsafe fn generic_call(cx: *mut JSContext,
vp: *mut JSVal,
is_lenient: bool,
call: unsafe extern fn(*const JSJitInfo, *mut JSContext,
HandleObject, *mut libc::c_void, u32,
RawHandleObject, *mut libc::c_void, u32,
*mut JSVal)
-> bool)
-> bool {
@ -447,7 +455,7 @@ unsafe fn generic_call(cx: *mut JSContext,
}
}
};
call(info, cx, obj.handle(), this as *mut libc::c_void, argc, vp)
call(info, cx, obj.handle().into(), this as *mut libc::c_void, argc, vp)
}
/// Generic method of IDL interface.
@ -476,7 +484,7 @@ pub unsafe extern "C" fn generic_lenient_getter(cx: *mut JSContext,
unsafe extern "C" fn call_setter(info: *const JSJitInfo,
cx: *mut JSContext,
handle: HandleObject,
handle: RawHandleObject,
this: *mut libc::c_void,
argc: u32,
vp: *mut JSVal)