mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
auto merge of #4772 : Ms2ger/servo/snake-utils, r=jdm
This is the Rust style, and there's no reason to deviate here.
This commit is contained in:
commit
d026457fdd
4 changed files with 117 additions and 104 deletions
|
@ -336,7 +336,7 @@ class CGMethodCall(CGThing):
|
||||||
|
|
||||||
# Check for vanilla JS objects
|
# Check for vanilla JS objects
|
||||||
# XXXbz Do we need to worry about security wrappers?
|
# XXXbz Do we need to worry about security wrappers?
|
||||||
pickFirstSignature("%s.is_object() && !IsPlatformObject(%s.to_object())" %
|
pickFirstSignature("%s.is_object() && !is_platform_object(%s.to_object())" %
|
||||||
(distinguishingArg, distinguishingArg),
|
(distinguishingArg, distinguishingArg),
|
||||||
lambda s: (s[1][distinguishingIndex].type.isCallback() or
|
lambda s: (s[1][distinguishingIndex].type.isCallback() or
|
||||||
s[1][distinguishingIndex].type.isCallbackInterface() or
|
s[1][distinguishingIndex].type.isCallbackInterface() or
|
||||||
|
@ -719,7 +719,7 @@ def getJSToNativeConversionTemplate(type, descriptorProvider, failureCode=None,
|
||||||
handleInvalidEnumValueCode = "return 1;"
|
handleInvalidEnumValueCode = "return 1;"
|
||||||
|
|
||||||
template = (
|
template = (
|
||||||
"match FindEnumStringIndex(cx, ${val}, %(values)s) {\n"
|
"match find_enum_string_index(cx, ${val}, %(values)s) {\n"
|
||||||
" Err(_) => { %(exceptionCode)s },\n"
|
" Err(_) => { %(exceptionCode)s },\n"
|
||||||
" Ok(None) => { %(handleInvalidEnumValueCode)s },\n"
|
" Ok(None) => { %(handleInvalidEnumValueCode)s },\n"
|
||||||
" Ok(Some(index)) => {\n"
|
" Ok(Some(index)) => {\n"
|
||||||
|
@ -1811,7 +1811,7 @@ assert!(!obj.is_null());\
|
||||||
""" % (descriptor.name, parent)
|
""" % (descriptor.name, parent)
|
||||||
else:
|
else:
|
||||||
if descriptor.isGlobal():
|
if descriptor.isGlobal():
|
||||||
create += "let obj = CreateDOMGlobal(aCx, &Class.base as *const js::Class as *const JSClass);\n"
|
create += "let obj = create_dom_global(aCx, &Class.base as *const js::Class as *const JSClass);\n"
|
||||||
else:
|
else:
|
||||||
create += ("let obj = with_compartment(aCx, proto, || {\n"
|
create += ("let obj = with_compartment(aCx, proto, || {\n"
|
||||||
" JS_NewObject(aCx, &Class.base as *const js::Class as *const JSClass, &*proto, &*%s)\n"
|
" JS_NewObject(aCx, &Class.base as *const js::Class as *const JSClass, &*proto, &*%s)\n"
|
||||||
|
@ -1905,9 +1905,9 @@ class CGAbstractExternMethod(CGAbstractMethod):
|
||||||
|
|
||||||
class PropertyArrays():
|
class PropertyArrays():
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
self.staticMethods = MethodDefiner(descriptor, "StaticMethods",
|
self.static_methods = MethodDefiner(descriptor, "StaticMethods",
|
||||||
static=True)
|
static=True)
|
||||||
self.staticAttrs = AttrDefiner(descriptor, "StaticAttributes",
|
self.static_attrs = AttrDefiner(descriptor, "StaticAttributes",
|
||||||
static=True)
|
static=True)
|
||||||
self.methods = MethodDefiner(descriptor, "Methods", static=False)
|
self.methods = MethodDefiner(descriptor, "Methods", static=False)
|
||||||
self.attrs = AttrDefiner(descriptor, "Attributes", static=False)
|
self.attrs = AttrDefiner(descriptor, "Attributes", static=False)
|
||||||
|
@ -1916,7 +1916,7 @@ class PropertyArrays():
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def arrayNames():
|
def arrayNames():
|
||||||
return [ "staticMethods", "staticAttrs", "methods", "attrs", "consts" ]
|
return ["static_methods", "static_attrs", "methods", "attrs", "consts"]
|
||||||
|
|
||||||
def variableNames(self):
|
def variableNames(self):
|
||||||
names = {}
|
names = {}
|
||||||
|
@ -1991,7 +1991,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
constructHook = CONSTRUCT_HOOK_NAME
|
constructHook = CONSTRUCT_HOOK_NAME
|
||||||
constructArgs = methodLength(self.descriptor.interface.ctor())
|
constructArgs = methodLength(self.descriptor.interface.ctor())
|
||||||
else:
|
else:
|
||||||
constructHook = "ThrowingConstructor"
|
constructHook = "throwing_constructor"
|
||||||
constructArgs = 0
|
constructArgs = 0
|
||||||
|
|
||||||
constructor = 'Some((%s as NonNullJSNative, "%s", %d))' % (
|
constructor = 'Some((%s as NonNullJSNative, "%s", %d))' % (
|
||||||
|
@ -2001,7 +2001,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
constructor = 'None'
|
constructor = 'None'
|
||||||
|
|
||||||
call = """\
|
call = """\
|
||||||
return CreateInterfaceObjects2(aCx, aGlobal, aReceiver, parentProto,
|
return do_create_interface_objects(aCx, aGlobal, aReceiver, parentProto,
|
||||||
&PrototypeClass, %s,
|
&PrototypeClass, %s,
|
||||||
%s,
|
%s,
|
||||||
&sNativeProperties);""" % (constructor, domClass)
|
&sNativeProperties);""" % (constructor, domClass)
|
||||||
|
@ -2034,7 +2034,7 @@ class CGGetPerInterfaceObject(CGAbstractMethod):
|
||||||
assert!(((*JS_GetClass(aGlobal)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
assert!(((*JS_GetClass(aGlobal)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
||||||
|
|
||||||
/* Check to see whether the interface objects are already installed */
|
/* Check to see whether the interface objects are already installed */
|
||||||
let protoOrIfaceArray = GetProtoOrIfaceArray(aGlobal);
|
let protoOrIfaceArray = get_proto_or_iface_array(aGlobal);
|
||||||
let cachedObject: *mut JSObject = *protoOrIfaceArray.offset(%s as int);
|
let cachedObject: *mut JSObject = *protoOrIfaceArray.offset(%s as int);
|
||||||
if cachedObject.is_null() {
|
if cachedObject.is_null() {
|
||||||
let tmp: *mut JSObject = CreateInterfaceObjects(aCx, aGlobal, aReceiver);
|
let tmp: *mut JSObject = CreateInterfaceObjects(aCx, aGlobal, aReceiver);
|
||||||
|
@ -3627,7 +3627,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
||||||
|
|
||||||
setOrIndexedGet = ""
|
setOrIndexedGet = ""
|
||||||
if indexedGetter or indexedSetter:
|
if indexedGetter or indexedSetter:
|
||||||
setOrIndexedGet += "let index = GetArrayIndexFromId(cx, id);\n"
|
setOrIndexedGet += "let index = get_array_index_from_id(cx, id);\n"
|
||||||
|
|
||||||
if indexedGetter:
|
if indexedGetter:
|
||||||
readonly = toStringBool(self.descriptor.operations['IndexedSetter'] is None)
|
readonly = toStringBool(self.descriptor.operations['IndexedSetter'] is None)
|
||||||
|
@ -3680,7 +3680,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
||||||
# ResolveOwnProperty or EnumerateOwnProperties filter out named
|
# ResolveOwnProperty or EnumerateOwnProperties filter out named
|
||||||
# properties that shadow prototype properties.
|
# properties that shadow prototype properties.
|
||||||
namedGet = ("\n" +
|
namedGet = ("\n" +
|
||||||
"if !set && RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" +
|
"if !set && RUST_JSID_IS_STRING(id) != 0 && !has_property_on_prototype(cx, proxy, id) {\n" +
|
||||||
" let name = jsid_to_str(cx, id);\n" +
|
" let name = jsid_to_str(cx, id);\n" +
|
||||||
" let this = UnwrapProxy(proxy);\n" +
|
" let this = UnwrapProxy(proxy);\n" +
|
||||||
" let this = JS::from_raw(this);\n" +
|
" let this = JS::from_raw(this);\n" +
|
||||||
|
@ -3725,7 +3725,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
||||||
if indexedSetter:
|
if indexedSetter:
|
||||||
if not (self.descriptor.operations['IndexedCreator'] is indexedSetter):
|
if not (self.descriptor.operations['IndexedCreator'] is indexedSetter):
|
||||||
raise TypeError("Can't handle creator that's different from the setter")
|
raise TypeError("Can't handle creator that's different from the setter")
|
||||||
set += ("let index = GetArrayIndexFromId(cx, id);\n" +
|
set += ("let index = get_array_index_from_id(cx, id);\n" +
|
||||||
"if index.is_some() {\n" +
|
"if index.is_some() {\n" +
|
||||||
" let index = index.unwrap();\n" +
|
" let index = index.unwrap();\n" +
|
||||||
" let this = UnwrapProxy(proxy);\n" +
|
" let this = UnwrapProxy(proxy);\n" +
|
||||||
|
@ -3735,7 +3735,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
||||||
" return true;\n" +
|
" return true;\n" +
|
||||||
"}\n")
|
"}\n")
|
||||||
elif self.descriptor.operations['IndexedGetter']:
|
elif self.descriptor.operations['IndexedGetter']:
|
||||||
set += ("if GetArrayIndexFromId(cx, id).is_some() {\n" +
|
set += ("if get_array_index_from_id(cx, id).is_some() {\n" +
|
||||||
" return false;\n" +
|
" return false;\n" +
|
||||||
" //return ThrowErrorMessage(cx, MSG_NO_PROPERTY_SETTER, \"%s\");\n" +
|
" //return ThrowErrorMessage(cx, MSG_NO_PROPERTY_SETTER, \"%s\");\n" +
|
||||||
"}\n") % self.descriptor.name
|
"}\n") % self.descriptor.name
|
||||||
|
@ -3800,7 +3800,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
||||||
def getBody(self):
|
def getBody(self):
|
||||||
indexedGetter = self.descriptor.operations['IndexedGetter']
|
indexedGetter = self.descriptor.operations['IndexedGetter']
|
||||||
if indexedGetter:
|
if indexedGetter:
|
||||||
indexed = ("let index = GetArrayIndexFromId(cx, id);\n" +
|
indexed = ("let index = get_array_index_from_id(cx, id);\n" +
|
||||||
"if index.is_some() {\n" +
|
"if index.is_some() {\n" +
|
||||||
" let index = index.unwrap();\n" +
|
" let index = index.unwrap();\n" +
|
||||||
" let this = UnwrapProxy(proxy);\n" +
|
" let this = UnwrapProxy(proxy);\n" +
|
||||||
|
@ -3815,7 +3815,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
||||||
|
|
||||||
namedGetter = self.descriptor.operations['NamedGetter']
|
namedGetter = self.descriptor.operations['NamedGetter']
|
||||||
if namedGetter:
|
if namedGetter:
|
||||||
named = ("if RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" +
|
named = ("if RUST_JSID_IS_STRING(id) != 0 && !has_property_on_prototype(cx, proxy, id) {\n" +
|
||||||
" let name = jsid_to_str(cx, id);\n" +
|
" let name = jsid_to_str(cx, id);\n" +
|
||||||
" let this = UnwrapProxy(proxy);\n" +
|
" let this = UnwrapProxy(proxy);\n" +
|
||||||
" let this = JS::from_raw(this);\n" +
|
" let this = JS::from_raw(this);\n" +
|
||||||
|
@ -3873,7 +3873,7 @@ if !expando.is_null() {
|
||||||
|
|
||||||
indexedGetter = self.descriptor.operations['IndexedGetter']
|
indexedGetter = self.descriptor.operations['IndexedGetter']
|
||||||
if indexedGetter:
|
if indexedGetter:
|
||||||
getIndexedOrExpando = ("let index = GetArrayIndexFromId(cx, id);\n" +
|
getIndexedOrExpando = ("let index = get_array_index_from_id(cx, id);\n" +
|
||||||
"if index.is_some() {\n" +
|
"if index.is_some() {\n" +
|
||||||
" let index = index.unwrap();\n" +
|
" let index = index.unwrap();\n" +
|
||||||
" let this = UnwrapProxy(proxy);\n" +
|
" let this = UnwrapProxy(proxy);\n" +
|
||||||
|
@ -3908,7 +3908,7 @@ if !expando.is_null() {
|
||||||
|
|
||||||
%s
|
%s
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
if !GetPropertyOnPrototype(cx, proxy, id, &mut found, vp) {
|
if !get_property_on_prototype(cx, proxy, id, &mut found, vp) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4548,17 +4548,17 @@ class CGBindingRoot(CGThing):
|
||||||
'dom::bindings::js::{JS, JSRef, Root, RootedReference, Temporary}',
|
'dom::bindings::js::{JS, JSRef, Root, RootedReference, Temporary}',
|
||||||
'dom::bindings::js::{OptionalRootable, OptionalRootedRootable, ResultRootable}',
|
'dom::bindings::js::{OptionalRootable, OptionalRootedRootable, ResultRootable}',
|
||||||
'dom::bindings::js::{OptionalRootedReference, OptionalOptionalRootedRootable}',
|
'dom::bindings::js::{OptionalRootedReference, OptionalOptionalRootedRootable}',
|
||||||
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
|
'dom::bindings::utils::{create_dom_global, do_create_interface_objects}',
|
||||||
'dom::bindings::utils::ConstantSpec',
|
'dom::bindings::utils::ConstantSpec',
|
||||||
'dom::bindings::utils::{DOMClass}',
|
'dom::bindings::utils::{DOMClass}',
|
||||||
'dom::bindings::utils::{DOMJSClass, JSCLASS_DOM_GLOBAL}',
|
'dom::bindings::utils::{DOMJSClass, JSCLASS_DOM_GLOBAL}',
|
||||||
'dom::bindings::utils::{FindEnumStringIndex, GetArrayIndexFromId}',
|
'dom::bindings::utils::{find_enum_string_index, get_array_index_from_id}',
|
||||||
'dom::bindings::utils::{GetPropertyOnPrototype, GetProtoOrIfaceArray}',
|
'dom::bindings::utils::{get_property_on_prototype, get_proto_or_iface_array}',
|
||||||
'dom::bindings::utils::HasPropertyOnPrototype',
|
'dom::bindings::utils::has_property_on_prototype',
|
||||||
'dom::bindings::utils::IsPlatformObject',
|
'dom::bindings::utils::is_platform_object',
|
||||||
'dom::bindings::utils::{Reflectable}',
|
'dom::bindings::utils::{Reflectable}',
|
||||||
'dom::bindings::utils::{squirrel_away_unique}',
|
'dom::bindings::utils::{squirrel_away_unique}',
|
||||||
'dom::bindings::utils::{ThrowingConstructor}',
|
'dom::bindings::utils::throwing_constructor',
|
||||||
'dom::bindings::utils::get_dictionary_property',
|
'dom::bindings::utils::get_dictionary_property',
|
||||||
'dom::bindings::utils::{NativeProperties, NativePropertyHooks}',
|
'dom::bindings::utils::{NativeProperties, NativePropertyHooks}',
|
||||||
'dom::bindings::utils::ConstantVal::{IntVal, UintVal}',
|
'dom::bindings::utils::ConstantVal::{IntVal, UintVal}',
|
||||||
|
|
|
@ -24,7 +24,7 @@ use js::glue::{IsWrapper, RUST_JSID_IS_INT, RUST_JSID_TO_INT};
|
||||||
use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewFunction};
|
use js::jsapi::{JS_AlreadyHasOwnProperty, JS_NewFunction};
|
||||||
use js::jsapi::{JS_DefineProperties, JS_ForwardGetPropertyTo};
|
use js::jsapi::{JS_DefineProperties, JS_ForwardGetPropertyTo};
|
||||||
use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAndLength};
|
use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAndLength};
|
||||||
use js::jsapi::{JS_ObjectIsRegExp, JS_ObjectIsDate, JSHandleObject};
|
use js::jsapi::JSHandleObject;
|
||||||
use js::jsapi::JS_GetFunctionObject;
|
use js::jsapi::JS_GetFunctionObject;
|
||||||
use js::jsapi::{JS_HasPropertyById, JS_GetPrototype};
|
use js::jsapi::{JS_HasPropertyById, JS_GetPrototype};
|
||||||
use js::jsapi::{JS_GetProperty, JS_HasProperty};
|
use js::jsapi::{JS_GetProperty, JS_HasProperty};
|
||||||
|
@ -55,12 +55,14 @@ pub struct GlobalStaticData {
|
||||||
pub windowproxy_handler: WindowProxyHandler,
|
pub windowproxy_handler: WindowProxyHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GlobalStaticData {
|
||||||
/// Creates a new GlobalStaticData.
|
/// Creates a new GlobalStaticData.
|
||||||
pub fn GlobalStaticData() -> GlobalStaticData {
|
pub fn new() -> GlobalStaticData {
|
||||||
GlobalStaticData {
|
GlobalStaticData {
|
||||||
windowproxy_handler: browsercontext::new_window_proxy_handler(),
|
windowproxy_handler: browsercontext::new_window_proxy_handler(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Leak the given pointer.
|
/// Leak the given pointer.
|
||||||
pub unsafe fn squirrel_away_unique<T>(x: Box<T>) -> *const T {
|
pub unsafe fn squirrel_away_unique<T>(x: Box<T>) -> *const T {
|
||||||
|
@ -152,7 +154,7 @@ unsafe impl Sync for DOMJSClass {}
|
||||||
|
|
||||||
/// Returns the ProtoOrIfaceArray for the given global object.
|
/// Returns the ProtoOrIfaceArray for the given global object.
|
||||||
/// Fails if `global` is not a DOM global object.
|
/// Fails if `global` is not a DOM global object.
|
||||||
pub fn GetProtoOrIfaceArray(global: *mut JSObject) -> *mut *mut JSObject {
|
pub fn get_proto_or_iface_array(global: *mut JSObject) -> *mut *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
||||||
JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT).to_private() as *mut *mut JSObject
|
JS_GetReservedSlot(global, DOM_PROTOTYPE_SLOT).to_private() as *mut *mut JSObject
|
||||||
|
@ -169,9 +171,9 @@ pub struct NativeProperties {
|
||||||
/// Constants for the interface.
|
/// Constants for the interface.
|
||||||
pub consts: Option<&'static [ConstantSpec]>,
|
pub consts: Option<&'static [ConstantSpec]>,
|
||||||
/// Static methods for the interface.
|
/// Static methods for the interface.
|
||||||
pub staticMethods: Option<&'static [JSFunctionSpec]>,
|
pub static_methods: Option<&'static [JSFunctionSpec]>,
|
||||||
/// Static attributes for the interface.
|
/// Static attributes for the interface.
|
||||||
pub staticAttrs: Option<&'static [JSPropertySpec]>,
|
pub static_attrs: Option<&'static [JSPropertySpec]>,
|
||||||
}
|
}
|
||||||
unsafe impl Sync for NativeProperties {}
|
unsafe impl Sync for NativeProperties {}
|
||||||
|
|
||||||
|
@ -182,24 +184,26 @@ pub type NonNullJSNative =
|
||||||
/// Creates the *interface prototype object* and the *interface object* (if
|
/// Creates the *interface prototype object* and the *interface object* (if
|
||||||
/// needed).
|
/// needed).
|
||||||
/// Fails on JSAPI failure.
|
/// Fails on JSAPI failure.
|
||||||
pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
pub fn do_create_interface_objects(cx: *mut JSContext, global: *mut JSObject,
|
||||||
protoProto: *mut JSObject,
|
receiver: *mut JSObject,
|
||||||
protoClass: &'static JSClass,
|
proto_proto: *mut JSObject,
|
||||||
|
proto_class: &'static JSClass,
|
||||||
constructor: Option<(NonNullJSNative, &'static str, u32)>,
|
constructor: Option<(NonNullJSNative, &'static str, u32)>,
|
||||||
domClass: *const DOMClass,
|
dom_class: *const DOMClass,
|
||||||
members: &'static NativeProperties) -> *mut JSObject {
|
members: &'static NativeProperties)
|
||||||
let proto = CreateInterfacePrototypeObject(cx, global, protoProto,
|
-> *mut JSObject {
|
||||||
protoClass, members);
|
let proto = create_interface_prototype_object(cx, global, proto_proto,
|
||||||
|
proto_class, members);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
|
JS_SetReservedSlot(proto, DOM_PROTO_INSTANCE_CLASS_SLOT,
|
||||||
PrivateValue(domClass as *const libc::c_void));
|
PrivateValue(dom_class as *const libc::c_void));
|
||||||
}
|
}
|
||||||
|
|
||||||
match constructor {
|
match constructor {
|
||||||
Some((native, name, nargs)) => {
|
Some((native, name, nargs)) => {
|
||||||
let s = CString::from_slice(name.as_bytes());
|
let s = CString::from_slice(name.as_bytes());
|
||||||
CreateInterfaceObject(cx, global, receiver,
|
create_interface_object(cx, global, receiver,
|
||||||
native, nargs, proto,
|
native, nargs, proto,
|
||||||
members, s.as_ptr())
|
members, s.as_ptr())
|
||||||
},
|
},
|
||||||
|
@ -211,31 +215,36 @@ pub fn CreateInterfaceObjects2(cx: *mut JSContext, global: *mut JSObject, receiv
|
||||||
|
|
||||||
/// Creates the *interface object*.
|
/// Creates the *interface object*.
|
||||||
/// Fails on JSAPI failure.
|
/// Fails on JSAPI failure.
|
||||||
fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *mut JSObject,
|
fn create_interface_object(cx: *mut JSContext, global: *mut JSObject,
|
||||||
constructorNative: NonNullJSNative,
|
receiver: *mut JSObject,
|
||||||
ctorNargs: u32, proto: *mut JSObject,
|
constructor_native: NonNullJSNative,
|
||||||
|
ctor_nargs: u32, proto: *mut JSObject,
|
||||||
members: &'static NativeProperties,
|
members: &'static NativeProperties,
|
||||||
name: *const libc::c_char) {
|
name: *const libc::c_char) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let fun = JS_NewFunction(cx, Some(constructorNative), ctorNargs,
|
let fun = JS_NewFunction(cx, Some(constructor_native), ctor_nargs,
|
||||||
JSFUN_CONSTRUCTOR, global, name);
|
JSFUN_CONSTRUCTOR, global, name);
|
||||||
assert!(!fun.is_null());
|
assert!(!fun.is_null());
|
||||||
|
|
||||||
let constructor = JS_GetFunctionObject(fun);
|
let constructor = JS_GetFunctionObject(fun);
|
||||||
assert!(!constructor.is_null());
|
assert!(!constructor.is_null());
|
||||||
|
|
||||||
match members.staticMethods {
|
match members.static_methods {
|
||||||
Some(staticMethods) => DefineMethods(cx, constructor, staticMethods),
|
Some(static_methods) => {
|
||||||
|
define_methods(cx, constructor, static_methods)
|
||||||
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match members.staticAttrs {
|
match members.static_attrs {
|
||||||
Some(staticProperties) => DefineProperties(cx, constructor, staticProperties),
|
Some(static_properties) => {
|
||||||
|
define_properties(cx, constructor, static_properties)
|
||||||
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match members.consts {
|
match members.consts {
|
||||||
Some(constants) => DefineConstants(cx, constructor, constants),
|
Some(constants) => define_constants(cx, constructor, constants),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,10 +252,10 @@ fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *m
|
||||||
assert!(JS_LinkConstructorAndPrototype(cx, constructor, proto) != 0);
|
assert!(JS_LinkConstructorAndPrototype(cx, constructor, proto) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut alreadyDefined = 0;
|
let mut already_defined = 0;
|
||||||
assert!(JS_AlreadyHasOwnProperty(cx, receiver, name, &mut alreadyDefined) != 0);
|
assert!(JS_AlreadyHasOwnProperty(cx, receiver, name, &mut already_defined) != 0);
|
||||||
|
|
||||||
if alreadyDefined == 0 {
|
if already_defined == 0 {
|
||||||
assert!(JS_DefineProperty(cx, receiver, name,
|
assert!(JS_DefineProperty(cx, receiver, name,
|
||||||
ObjectValue(&*constructor),
|
ObjectValue(&*constructor),
|
||||||
None, None, 0) != 0);
|
None, None, 0) != 0);
|
||||||
|
@ -256,7 +265,8 @@ fn CreateInterfaceObject(cx: *mut JSContext, global: *mut JSObject, receiver: *m
|
||||||
|
|
||||||
/// Defines constants on `obj`.
|
/// Defines constants on `obj`.
|
||||||
/// Fails on JSAPI failure.
|
/// Fails on JSAPI failure.
|
||||||
fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: &'static [ConstantSpec]) {
|
fn define_constants(cx: *mut JSContext, obj: *mut JSObject,
|
||||||
|
constants: &'static [ConstantSpec]) {
|
||||||
for spec in constants.iter() {
|
for spec in constants.iter() {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(JS_DefineProperty(cx, obj, spec.name.as_ptr() as *const libc::c_char,
|
assert!(JS_DefineProperty(cx, obj, spec.name.as_ptr() as *const libc::c_char,
|
||||||
|
@ -270,7 +280,8 @@ fn DefineConstants(cx: *mut JSContext, obj: *mut JSObject, constants: &'static [
|
||||||
/// Defines methods on `obj`. The last entry of `methods` must contain zeroed
|
/// Defines methods on `obj`. The last entry of `methods` must contain zeroed
|
||||||
/// memory.
|
/// memory.
|
||||||
/// Fails on JSAPI failure.
|
/// Fails on JSAPI failure.
|
||||||
fn DefineMethods(cx: *mut JSContext, obj: *mut JSObject, methods: &'static [JSFunctionSpec]) {
|
fn define_methods(cx: *mut JSContext, obj: *mut JSObject,
|
||||||
|
methods: &'static [JSFunctionSpec]) {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(JS_DefineFunctions(cx, obj, methods.as_ptr()) != 0);
|
assert!(JS_DefineFunctions(cx, obj, methods.as_ptr()) != 0);
|
||||||
}
|
}
|
||||||
|
@ -279,7 +290,8 @@ fn DefineMethods(cx: *mut JSContext, obj: *mut JSObject, methods: &'static [JSFu
|
||||||
/// Defines attributes on `obj`. The last entry of `properties` must contain
|
/// Defines attributes on `obj`. The last entry of `properties` must contain
|
||||||
/// zeroed memory.
|
/// zeroed memory.
|
||||||
/// Fails on JSAPI failure.
|
/// Fails on JSAPI failure.
|
||||||
fn DefineProperties(cx: *mut JSContext, obj: *mut JSObject, properties: &'static [JSPropertySpec]) {
|
fn define_properties(cx: *mut JSContext, obj: *mut JSObject,
|
||||||
|
properties: &'static [JSPropertySpec]) {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(JS_DefineProperties(cx, obj, properties.as_ptr()) != 0);
|
assert!(JS_DefineProperties(cx, obj, properties.as_ptr()) != 0);
|
||||||
}
|
}
|
||||||
|
@ -287,36 +299,39 @@ fn DefineProperties(cx: *mut JSContext, obj: *mut JSObject, properties: &'static
|
||||||
|
|
||||||
/// Creates the *interface prototype object*.
|
/// Creates the *interface prototype object*.
|
||||||
/// Fails on JSAPI failure.
|
/// Fails on JSAPI failure.
|
||||||
fn CreateInterfacePrototypeObject(cx: *mut JSContext, global: *mut JSObject,
|
fn create_interface_prototype_object(cx: *mut JSContext, global: *mut JSObject,
|
||||||
parentProto: *mut JSObject,
|
parent_proto: *mut JSObject,
|
||||||
protoClass: &'static JSClass,
|
proto_class: &'static JSClass,
|
||||||
members: &'static NativeProperties) -> *mut JSObject {
|
members: &'static NativeProperties)
|
||||||
|
-> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ourProto = JS_NewObjectWithUniqueType(cx, protoClass, &*parentProto, &*global);
|
let our_proto = JS_NewObjectWithUniqueType(cx, proto_class,
|
||||||
assert!(!ourProto.is_null());
|
&*parent_proto, &*global);
|
||||||
|
assert!(!our_proto.is_null());
|
||||||
|
|
||||||
match members.methods {
|
match members.methods {
|
||||||
Some(methods) => DefineMethods(cx, ourProto, methods),
|
Some(methods) => define_methods(cx, our_proto, methods),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match members.attrs {
|
match members.attrs {
|
||||||
Some(properties) => DefineProperties(cx, ourProto, properties),
|
Some(properties) => define_properties(cx, our_proto, properties),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
match members.consts {
|
match members.consts {
|
||||||
Some(constants) => DefineConstants(cx, ourProto, constants),
|
Some(constants) => define_constants(cx, our_proto, constants),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
return ourProto;
|
return our_proto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A throwing constructor, for those interfaces that have neither
|
/// A throwing constructor, for those interfaces that have neither
|
||||||
/// `NoInterfaceObject` nor `Constructor`.
|
/// `NoInterfaceObject` nor `Constructor`.
|
||||||
pub unsafe extern fn ThrowingConstructor(cx: *mut JSContext, _argc: c_uint, _vp: *mut JSVal) -> JSBool {
|
pub unsafe extern fn throwing_constructor(cx: *mut JSContext, _argc: c_uint,
|
||||||
|
_vp: *mut JSVal) -> JSBool {
|
||||||
throw_type_error(cx, "Illegal constructor.");
|
throw_type_error(cx, "Illegal constructor.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -324,10 +339,11 @@ pub unsafe extern fn ThrowingConstructor(cx: *mut JSContext, _argc: c_uint, _vp:
|
||||||
/// Construct and cache the ProtoOrIfaceArray for the given global.
|
/// Construct and cache the ProtoOrIfaceArray for the given global.
|
||||||
/// Fails if the argument is not a DOM global.
|
/// Fails if the argument is not a DOM global.
|
||||||
pub fn initialize_global(global: *mut JSObject) {
|
pub fn initialize_global(global: *mut JSObject) {
|
||||||
let protoArray = box () ([0 as *mut JSObject; PrototypeList::ID::Count as uint]);
|
let proto_array = box ()
|
||||||
|
([0 as *mut JSObject; PrototypeList::ID::Count as uint]);
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
assert!(((*JS_GetClass(global)).flags & JSCLASS_DOM_GLOBAL) != 0);
|
||||||
let box_ = squirrel_away_unique(protoArray);
|
let box_ = squirrel_away_unique(proto_array);
|
||||||
JS_SetReservedSlot(global,
|
JS_SetReservedSlot(global,
|
||||||
DOM_PROTOTYPE_SLOT,
|
DOM_PROTOTYPE_SLOT,
|
||||||
PrivateValue(box_ as *const libc::c_void));
|
PrivateValue(box_ as *const libc::c_void));
|
||||||
|
@ -394,8 +410,9 @@ impl Reflector {
|
||||||
/// set to true and `*vp` to the value, otherwise `*found` is set to false.
|
/// set to true and `*vp` to the value, otherwise `*found` is set to false.
|
||||||
///
|
///
|
||||||
/// Returns false on JSAPI failure.
|
/// Returns false on JSAPI failure.
|
||||||
pub fn GetPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, found: *mut bool,
|
pub fn get_property_on_prototype(cx: *mut JSContext, proxy: *mut JSObject,
|
||||||
vp: *mut JSVal) -> bool {
|
id: jsid, found: *mut bool, vp: *mut JSVal)
|
||||||
|
-> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
//let proto = GetObjectProto(proxy);
|
//let proto = GetObjectProto(proxy);
|
||||||
let proto = JS_GetPrototype(proxy);
|
let proto = JS_GetPrototype(proxy);
|
||||||
|
@ -403,13 +420,13 @@ pub fn GetPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid
|
||||||
*found = false;
|
*found = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let mut hasProp = 0;
|
let mut has_property = 0;
|
||||||
if JS_HasPropertyById(cx, proto, id, &mut hasProp) == 0 {
|
if JS_HasPropertyById(cx, proto, id, &mut has_property) == 0 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*found = hasProp != 0;
|
*found = has_property != 0;
|
||||||
let no_output = vp.is_null();
|
let no_output = vp.is_null();
|
||||||
if hasProp == 0 || no_output {
|
if has_property == 0 || no_output {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +436,7 @@ pub fn GetPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid
|
||||||
|
|
||||||
/// Get an array index from the given `jsid`. Returns `None` if the given
|
/// Get an array index from the given `jsid`. Returns `None` if the given
|
||||||
/// `jsid` is not an integer.
|
/// `jsid` is not an integer.
|
||||||
pub fn GetArrayIndexFromId(_cx: *mut JSContext, id: jsid) -> Option<u32> {
|
pub fn get_array_index_from_id(_cx: *mut JSContext, id: jsid) -> Option<u32> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if RUST_JSID_IS_INT(id) != 0 {
|
if RUST_JSID_IS_INT(id) != 0 {
|
||||||
return Some(RUST_JSID_TO_INT(id) as u32);
|
return Some(RUST_JSID_TO_INT(id) as u32);
|
||||||
|
@ -445,9 +462,10 @@ pub fn GetArrayIndexFromId(_cx: *mut JSContext, id: jsid) -> Option<u32> {
|
||||||
/// Find the index of a string given by `v` in `values`.
|
/// Find the index of a string given by `v` in `values`.
|
||||||
/// Returns `Err(())` on JSAPI failure (there is a pending exception), and
|
/// Returns `Err(())` on JSAPI failure (there is a pending exception), and
|
||||||
/// `Ok(None)` if there was no matching string.
|
/// `Ok(None)` if there was no matching string.
|
||||||
pub fn FindEnumStringIndex(cx: *mut JSContext,
|
pub fn find_enum_string_index(cx: *mut JSContext,
|
||||||
v: JSVal,
|
v: JSVal,
|
||||||
values: &[&'static str]) -> Result<Option<uint>, ()> {
|
values: &[&'static str])
|
||||||
|
-> Result<Option<uint>, ()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let jsstr = JS_ValueToString(cx, v);
|
let jsstr = JS_ValueToString(cx, v);
|
||||||
if jsstr.is_null() {
|
if jsstr.is_null() {
|
||||||
|
@ -471,7 +489,7 @@ pub fn FindEnumStringIndex(cx: *mut JSContext,
|
||||||
|
|
||||||
/// Returns wether `obj` is a platform object
|
/// Returns wether `obj` is a platform object
|
||||||
/// http://heycam.github.io/webidl/#dfn-platform-object
|
/// http://heycam.github.io/webidl/#dfn-platform-object
|
||||||
pub fn IsPlatformObject(obj: *mut JSObject) -> bool {
|
pub fn is_platform_object(obj: *mut JSObject) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
// Fast-path the common case
|
// Fast-path the common case
|
||||||
let mut clasp = JS_GetClass(obj);
|
let mut clasp = JS_GetClass(obj);
|
||||||
|
@ -534,21 +552,16 @@ pub fn get_dictionary_property(cx: *mut JSContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether `proxy` has a property `id` on its prototype.
|
/// Returns whether `proxy` has a property `id` on its prototype.
|
||||||
pub fn HasPropertyOnPrototype(cx: *mut JSContext, proxy: *mut JSObject, id: jsid) -> bool {
|
pub fn has_property_on_prototype(cx: *mut JSContext, proxy: *mut JSObject,
|
||||||
|
id: jsid) -> bool {
|
||||||
// MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler);
|
// MOZ_ASSERT(js::IsProxy(proxy) && js::GetProxyHandler(proxy) == handler);
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
return !GetPropertyOnPrototype(cx, proxy, id, &mut found, ptr::null_mut()) || found;
|
return !get_property_on_prototype(cx, proxy, id, &mut found, ptr::null_mut()) || found;
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns whether `obj` can be converted to a callback interface per IDL.
|
|
||||||
pub fn IsConvertibleToCallbackInterface(cx: *mut JSContext, obj: *mut JSObject) -> bool {
|
|
||||||
unsafe {
|
|
||||||
JS_ObjectIsDate(cx, obj) == 0 && JS_ObjectIsRegExp(cx, obj) == 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a DOM global object with the given class.
|
/// Create a DOM global object with the given class.
|
||||||
pub fn CreateDOMGlobal(cx: *mut JSContext, class: *const JSClass) -> *mut JSObject {
|
pub fn create_dom_global(cx: *mut JSContext, class: *const JSClass)
|
||||||
|
-> *mut JSObject {
|
||||||
unsafe {
|
unsafe {
|
||||||
let obj = JS_NewGlobalObject(cx, class, ptr::null_mut());
|
let obj = JS_NewGlobalObject(cx, class, ptr::null_mut());
|
||||||
if obj.is_null() {
|
if obj.is_null() {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use dom::bindings::js::{OptionalRootable, OptionalRootedRootable, ResultRootable
|
||||||
use dom::bindings::js::{OptionalRootedReference, OptionalOptionalRootedRootable};
|
use dom::bindings::js::{OptionalRootedReference, OptionalOptionalRootedRootable};
|
||||||
use dom::bindings::proxyhandler::{get_property_descriptor, fill_property_descriptor};
|
use dom::bindings::proxyhandler::{get_property_descriptor, fill_property_descriptor};
|
||||||
use dom::bindings::utils::{Reflectable, WindowProxyHandler};
|
use dom::bindings::utils::{Reflectable, WindowProxyHandler};
|
||||||
use dom::bindings::utils::{GetArrayIndexFromId};
|
use dom::bindings::utils::get_array_index_from_id;
|
||||||
use dom::document::{Document, DocumentHelpers};
|
use dom::document::{Document, DocumentHelpers};
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use dom::window::WindowHelpers;
|
use dom::window::WindowHelpers;
|
||||||
|
@ -100,7 +100,7 @@ impl SessionHistoryEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn GetSubframeWindow(cx: *mut JSContext, proxy: *mut JSObject, id: jsid) -> Option<Temporary<Window>> {
|
unsafe fn GetSubframeWindow(cx: *mut JSContext, proxy: *mut JSObject, id: jsid) -> Option<Temporary<Window>> {
|
||||||
let index = GetArrayIndexFromId(cx, id);
|
let index = get_array_index_from_id(cx, id);
|
||||||
if let Some(index) = index {
|
if let Some(index) = index {
|
||||||
let target = GetProxyPrivate(proxy).to_object();
|
let target = GetProxyPrivate(proxy).to_object();
|
||||||
let win: Root<Window> = unwrap_jsmanaged(target).unwrap().root();
|
let win: Root<Window> = unwrap_jsmanaged(target).unwrap().root();
|
||||||
|
@ -139,7 +139,7 @@ unsafe extern fn getOwnPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObje
|
||||||
|
|
||||||
|
|
||||||
unsafe extern fn defineProperty(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, desc: *mut JSPropertyDescriptor) -> bool {
|
unsafe extern fn defineProperty(cx: *mut JSContext, proxy: *mut JSObject, id: jsid, desc: *mut JSPropertyDescriptor) -> bool {
|
||||||
if GetArrayIndexFromId(cx, id).is_some() {
|
if get_array_index_from_id(cx, id).is_some() {
|
||||||
// Spec says to Reject whether this is a supported index or not,
|
// Spec says to Reject whether this is a supported index or not,
|
||||||
// since we have no indexed setter or indexed creator. That means
|
// since we have no indexed setter or indexed creator. That means
|
||||||
// throwing in strict mode (FIXME: Bug 828137), doing nothing in
|
// throwing in strict mode (FIXME: Bug 828137), doing nothing in
|
||||||
|
@ -182,7 +182,7 @@ unsafe extern fn get(cx: *mut JSContext, proxy: *mut JSObject, receiver: *mut JS
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern fn set(cx: *mut JSContext, proxy: *mut JSObject, _receiver: *mut JSObject, id: jsid, _strict: bool, vp: *mut JSVal) -> bool {
|
unsafe extern fn set(cx: *mut JSContext, proxy: *mut JSObject, _receiver: *mut JSObject, id: jsid, _strict: bool, vp: *mut JSVal) -> bool {
|
||||||
if GetArrayIndexFromId(cx, id).is_some() {
|
if get_array_index_from_id(cx, id).is_some() {
|
||||||
// Reject (which means throw if and only if strict) the set.
|
// Reject (which means throw if and only if strict) the set.
|
||||||
// FIXME: Throw
|
// FIXME: Throw
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -133,7 +133,7 @@ impl Page {
|
||||||
constellation_chan: ConstellationChan,
|
constellation_chan: ConstellationChan,
|
||||||
js_context: Rc<Cx>) -> Page {
|
js_context: Rc<Cx>) -> Page {
|
||||||
let js_info = JSPageInfo {
|
let js_info = JSPageInfo {
|
||||||
dom_static: GlobalStaticData(),
|
dom_static: GlobalStaticData::new(),
|
||||||
js_context: js_context,
|
js_context: js_context,
|
||||||
};
|
};
|
||||||
let layout_rpc: Box<LayoutRPC> = {
|
let layout_rpc: Box<LayoutRPC> = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue