servo: Merge #4771 - Use snake case for proxyhandler functions (from Ms2ger:snake-proxy); r=jdm

This is the Rust style, and there's no reason to deviate here.

Source-Repo: https://github.com/servo/servo
Source-Revision: 8f351cdc3209c0be2e02b9d08fef502eb7aa04ec
This commit is contained in:
Ms2ger 2015-01-29 09:39:50 -07:00
Родитель ef71a99664
Коммит 23beb77c9c
3 изменённых файлов: 45 добавлений и 42 удалений

Просмотреть файл

@ -2088,22 +2088,22 @@ class CGDefineProxyHandler(CGAbstractMethod):
return CGAbstractMethod.define(self)
def definition_body(self):
customDefineProperty = 'defineProperty_'
customDefineProperty = 'proxyhandler::define_property'
if self.descriptor.operations['IndexedSetter'] or self.descriptor.operations['NamedSetter']:
customDefineProperty = 'defineProperty'
customDelete = 'delete_'
customDelete = 'proxyhandler::delete'
if self.descriptor.operations['NamedDeleter']:
customDelete = 'delete'
body = """\
let traps = ProxyTraps {
getPropertyDescriptor: Some(getPropertyDescriptor as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, bool, *mut JSPropertyDescriptor) -> bool),
getPropertyDescriptor: Some(get_property_descriptor as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, bool, *mut JSPropertyDescriptor) -> bool),
getOwnPropertyDescriptor: Some(getOwnPropertyDescriptor as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, bool, *mut JSPropertyDescriptor) -> bool),
defineProperty: Some(%s as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, *mut JSPropertyDescriptor) -> bool),
getOwnPropertyNames: Some(getOwnPropertyNames_ as unsafe extern "C" fn(*mut JSContext, *mut JSObject, *mut AutoIdVector) -> bool),
getOwnPropertyNames: Some(proxyhandler::get_own_property_names as unsafe extern "C" fn(*mut JSContext, *mut JSObject, *mut AutoIdVector) -> bool),
delete_: Some(%s as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, *mut bool) -> bool),
enumerate: Some(enumerate_ as unsafe extern "C" fn(*mut JSContext, *mut JSObject, *mut AutoIdVector) -> bool),
enumerate: Some(proxyhandler::enumerate as unsafe extern "C" fn(*mut JSContext, *mut JSObject, *mut AutoIdVector) -> bool),
has: None,
hasOwn: Some(hasOwn as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, *mut bool) -> bool),
@ -3631,7 +3631,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
if indexedGetter:
readonly = toStringBool(self.descriptor.operations['IndexedSetter'] is None)
fillDescriptor = "FillPropertyDescriptor(&mut *desc, proxy, %s);\nreturn true;" % readonly
fillDescriptor = "fill_property_descriptor(&mut *desc, proxy, %s);\nreturn true;" % readonly
templateValues = {'jsvalRef': '(*desc).value', 'successCode': fillDescriptor}
get = ("if index.is_some() {\n" +
" let index = index.unwrap();\n" +
@ -3649,7 +3649,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
if not 'IndexedCreator' in self.descriptor.operations:
# FIXME need to check that this is a 'supported property index'
assert False
setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, false);\n" +
setOrIndexedGet += (" fill_property_descriptor(&mut *desc, proxy, false);\n" +
" return true;\n" +
" }\n")
if self.descriptor.operations['NamedSetter']:
@ -3657,7 +3657,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
if not 'NamedCreator' in self.descriptor.operations:
# FIXME need to check that this is a 'supported property name'
assert False
setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, false);\n" +
setOrIndexedGet += (" fill_property_descriptor(&mut *desc, proxy, false);\n" +
" return true;\n" +
" }\n")
setOrIndexedGet += "}"
@ -3674,7 +3674,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
namedGetter = self.descriptor.operations['NamedGetter']
if namedGetter:
readonly = toStringBool(self.descriptor.operations['NamedSetter'] is None)
fillDescriptor = "FillPropertyDescriptor(&mut *desc, proxy, %s);\nreturn true;" % readonly
fillDescriptor = "fill_property_descriptor(&mut *desc, proxy, %s);\nreturn true;" % readonly
templateValues = {'jsvalRef': '(*desc).value', 'successCode': fillDescriptor}
# Once we start supporting OverrideBuiltins we need to make
# ResolveOwnProperty or EnumerateOwnProperties filter out named
@ -3691,7 +3691,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
namedGet = ""
return setOrIndexedGet + """\
let expando: *mut JSObject = GetExpandoObject(proxy);
let expando: *mut JSObject = get_expando_object(proxy);
//if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) {
if !expando.is_null() {
let flags = if set { JSRESOLVE_ASSIGNING } else { 0 } | JSRESOLVE_QUALIFIED;
@ -3764,7 +3764,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
" }\n" +
" return true;\n"
"}\n") % (self.descriptor.name)
return set + """return proxyhandler::defineProperty_(%s);""" % ", ".join(a.name for a in self.args)
return set + """return proxyhandler::define_property(%s);""" % ", ".join(a.name for a in self.args)
def definition_body(self):
return CGGeneric(self.getBody())
@ -3785,7 +3785,7 @@ class CGDOMJSProxyHandler_delete(CGAbstractExternMethod):
"let this = JS::from_raw(this);\n" +
"let this = this.root();\n" +
"%s") % (CGProxyNamedDeleter(self.descriptor).define())
set += "return proxyhandler::delete_(%s);" % ", ".join(a.name for a in self.args)
set += "return proxyhandler::delete(%s);" % ", ".join(a.name for a in self.args)
return set
def definition_body(self):
@ -3829,7 +3829,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
named = ""
return indexed + """\
let expando: *mut JSObject = GetExpandoObject(proxy);
let expando: *mut JSObject = get_expando_object(proxy);
if !expando.is_null() {
let mut b: JSBool = 1;
let ok = JS_HasPropertyById(cx, expando, id, &mut b) != 0;
@ -3854,7 +3854,7 @@ class CGDOMJSProxyHandler_get(CGAbstractExternMethod):
self.descriptor = descriptor
def getBody(self):
getFromExpando = """\
let expando = GetExpandoObject(proxy);
let expando = get_expando_object(proxy);
if !expando.is_null() {
let mut hasProp = 0;
if JS_HasPropertyById(cx, expando, id, &mut hasProp) == 0 {
@ -3946,7 +3946,7 @@ class CGDOMJSProxyHandler_obj_toString(CGAbstractExternMethod):
JSString* jsresult;
return xpc_qsStringToJsstring(cx, result, &jsresult) ? jsresult : NULL;"""
return """_obj_toString(cx, "%s")""" % self.descriptor.name
return """proxyhandler::object_to_string(cx, "%s")""" % self.descriptor.name
def definition_body(self):
return CGGeneric(self.getBody())
@ -4580,10 +4580,8 @@ class CGBindingRoot(CGThing):
'dom::bindings::error::throw_dom_exception',
'dom::bindings::error::throw_type_error',
'dom::bindings::proxyhandler',
'dom::bindings::proxyhandler::{_obj_toString, defineProperty_}',
'dom::bindings::proxyhandler::{FillPropertyDescriptor, GetExpandoObject}',
'dom::bindings::proxyhandler::{delete_, getPropertyDescriptor}',
'dom::bindings::proxyhandler::{getOwnPropertyNames_, enumerate_}',
'dom::bindings::proxyhandler::{fill_property_descriptor, get_expando_object}',
'dom::bindings::proxyhandler::{get_property_descriptor}',
'dom::bindings::str::ByteString',
'page::JSPageInfo',
'libc',

Просмотреть файл

@ -31,10 +31,11 @@ static JSPROXYSLOT_EXPANDO: u32 = 0;
/// with argument `id` and return the result, if it is not `undefined`.
/// Otherwise, walk along the prototype chain to find a property with that
/// name.
pub unsafe extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObject,
id: jsid, set: bool,
desc: *mut JSPropertyDescriptor)
-> bool {
pub unsafe extern fn get_property_descriptor(cx: *mut JSContext,
proxy: *mut JSObject,
id: jsid, set: bool,
desc: *mut JSPropertyDescriptor)
-> bool {
let handler = GetProxyHandler(proxy);
if !InvokeGetOwnPropertyDescriptor(handler, cx, proxy, id, set, desc) {
return false;
@ -54,8 +55,9 @@ pub unsafe extern fn getPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObj
}
/// Defines an expando on the given `proxy`.
pub unsafe extern fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid,
desc: *mut JSPropertyDescriptor) -> bool {
pub unsafe extern fn define_property(cx: *mut JSContext, proxy: *mut JSObject,
id: jsid, desc: *mut JSPropertyDescriptor)
-> bool {
static JSMSG_GETTER_ONLY: libc::c_uint = 160;
//FIXME: Workaround for https://github.com/mozilla/rust/issues/13385
@ -69,15 +71,15 @@ pub unsafe extern fn defineProperty_(cx: *mut JSContext, proxy: *mut JSObject, i
JSMSG_GETTER_ONLY) != 0;
}
let expando = EnsureExpandoObject(cx, proxy);
let expando = ensure_expando_object(cx, proxy);
return JS_DefinePropertyById(cx, expando, id, (*desc).value, (*desc).getter,
(*desc).setter, (*desc).attrs) != 0;
}
/// Deletes an expando off the given `proxy`.
pub unsafe extern fn delete_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid,
bp: *mut bool) -> bool {
let expando = GetExpandoObject(proxy);
pub unsafe extern fn delete(cx: *mut JSContext, proxy: *mut JSObject, id: jsid,
bp: *mut bool) -> bool {
let expando = get_expando_object(proxy);
if expando.is_null() {
*bp = true;
return true;
@ -87,7 +89,7 @@ pub unsafe extern fn delete_(cx: *mut JSContext, proxy: *mut JSObject, id: jsid,
}
/// Returns the stringification of an object with class `name`.
pub fn _obj_toString(cx: *mut JSContext, name: &str) -> *mut JSString {
pub fn object_to_string(cx: *mut JSContext, name: &str) -> *mut JSString {
unsafe {
let result = format!("[object {}]", name);
@ -101,7 +103,7 @@ pub fn _obj_toString(cx: *mut JSContext, name: &str) -> *mut JSString {
}
/// Get the expando object, or null if there is none.
pub fn GetExpandoObject(obj: *mut JSObject) -> *mut JSObject {
pub fn get_expando_object(obj: *mut JSObject) -> *mut JSObject {
unsafe {
assert!(is_dom_proxy(obj));
let val = GetProxyExtra(obj, JSPROXYSLOT_EXPANDO);
@ -115,10 +117,11 @@ pub fn GetExpandoObject(obj: *mut JSObject) -> *mut JSObject {
/// Get the expando object, or create it if it doesn't exist yet.
/// Fails on JSAPI failure.
pub fn EnsureExpandoObject(cx: *mut JSContext, obj: *mut JSObject) -> *mut JSObject {
pub fn ensure_expando_object(cx: *mut JSContext, obj: *mut JSObject)
-> *mut JSObject {
unsafe {
assert!(is_dom_proxy(obj));
let mut expando = GetExpandoObject(obj);
let mut expando = get_expando_object(obj);
if expando.is_null() {
expando = JS_NewObjectWithGivenProto(cx, ptr::null_mut(),
ptr::null_mut(),
@ -133,7 +136,8 @@ pub fn EnsureExpandoObject(cx: *mut JSContext, obj: *mut JSObject) -> *mut JSObj
/// Set the property descriptor's object to `obj` and set it to enumerable,
/// and writable if `readonly` is true.
pub fn FillPropertyDescriptor(desc: &mut JSPropertyDescriptor, obj: *mut JSObject, readonly: bool) {
pub fn fill_property_descriptor(desc: &mut JSPropertyDescriptor,
obj: *mut JSObject, readonly: bool) {
desc.obj = obj;
desc.attrs = if readonly { JSPROP_READONLY } else { 0 } | JSPROP_ENUMERATE;
desc.getter = None;
@ -142,14 +146,14 @@ pub fn FillPropertyDescriptor(desc: &mut JSPropertyDescriptor, obj: *mut JSObjec
}
/// No-op required hook.
pub unsafe extern fn getOwnPropertyNames_(_cx: *mut JSContext,
_obj: *mut JSObject,
_v: *mut AutoIdVector) -> bool {
pub unsafe extern fn get_own_property_names(_cx: *mut JSContext,
_obj: *mut JSObject,
_v: *mut AutoIdVector) -> bool {
true
}
/// No-op required hook.
pub unsafe extern fn enumerate_(_cx: *mut JSContext, _obj: *mut JSObject,
_v: *mut AutoIdVector) -> bool {
pub unsafe extern fn enumerate(_cx: *mut JSContext, _obj: *mut JSObject,
_v: *mut AutoIdVector) -> bool {
true
}

Просмотреть файл

@ -7,7 +7,7 @@ use dom::bindings::conversions::{ToJSValConvertible};
use dom::bindings::js::{JS, JSRef, Temporary, Root};
use dom::bindings::js::{OptionalRootable, OptionalRootedRootable, ResultRootable};
use dom::bindings::js::{OptionalRootedReference, OptionalOptionalRootedRootable};
use dom::bindings::proxyhandler::{getPropertyDescriptor, FillPropertyDescriptor};
use dom::bindings::proxyhandler::{get_property_descriptor, fill_property_descriptor};
use dom::bindings::utils::{Reflectable, WindowProxyHandler};
use dom::bindings::utils::{GetArrayIndexFromId};
use dom::document::{Document, DocumentHelpers};
@ -116,7 +116,7 @@ unsafe extern fn getOwnPropertyDescriptor(cx: *mut JSContext, proxy: *mut JSObje
if let Some(window) = window {
let window = window.root();
(*desc).value = window.to_jsval(cx);
FillPropertyDescriptor(&mut *desc, proxy, true);
fill_property_descriptor(&mut *desc, proxy, true);
return true;
}
@ -194,7 +194,8 @@ unsafe extern fn set(cx: *mut JSContext, proxy: *mut JSObject, _receiver: *mut J
}
static PROXY_HANDLER: ProxyTraps = ProxyTraps {
getPropertyDescriptor: Some(getPropertyDescriptor as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, bool, *mut JSPropertyDescriptor) -> bool),
getPropertyDescriptor: Some(get_property_descriptor
as unsafe extern "C" fn(*mut JSContext, *mut JSObject, jsid, bool, *mut JSPropertyDescriptor) -> bool),
getOwnPropertyDescriptor: Some(getOwnPropertyDescriptor
as unsafe extern "C" fn(*mut JSContext, *mut JSObject,
jsid, bool, *mut JSPropertyDescriptor)