Skip to content

Commit

Permalink
Remove XRay related stuff from codegen (fixes #1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngsankha committed Apr 6, 2014
1 parent 4386bae commit 9a4bec3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 207 deletions.
111 changes: 2 additions & 109 deletions src/components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -1525,27 +1525,6 @@ def stringDecl(const):
'ConstantSpec',
PropertyDefiner.getControllingPref, specData, doIdArrays)

class CGNativePropertyHooks(CGThing):
"""
Generate a NativePropertyHooks for a given descriptor
"""
def __init__(self, descriptor):
CGThing.__init__(self)
self.descriptor = descriptor

def define(self):
if self.descriptor.concrete and self.descriptor.proxy:
resolveOwnProperty = "ResolveOwnProperty"
enumerateOwnProperties = "EnumerateOwnProperties"
else:
enumerateOwnProperties = resolveOwnProperty = "0 as *u8"
parent = self.descriptor.interface.parent
parentHooks = ("&" + toBindingNamespace(parent.identifier.name) + "::NativeHooks"
if parent else '0 as *NativePropertyHooks')
return """
static NativeHooks: NativePropertyHooks = NativePropertyHooks { resolve_own_property: /*%s*/ 0 as *u8, resolve_property: ResolveProperty, enumerate_own_properties: /*%s*/ 0 as *u8, enumerate_properties: /*EnumerateProperties*/ 0 as *u8, proto_hooks: /*%s*/ 0 as *NativePropertyHooks };
""" % (resolveOwnProperty, enumerateOwnProperties, parentHooks)

# We'll want to insert the indent at the beginnings of lines, but we
# don't want to indent empty lines. So only indent lines that have a
# non-newline character on them.
Expand Down Expand Up @@ -1656,8 +1635,7 @@ def DOMClass(descriptor):
protoList.extend(['PrototypeList::id::IDCount'] * (descriptor.config.maxProtoChainLength - len(protoList)))
prototypeChainString = ', '.join(protoList)
return """DOMClass {
interface_chain: [ %s ],
native_hooks: &NativeHooks as *NativePropertyHooks
interface_chain: [ %s ]
}""" % prototypeChainString

class CGDOMJSClass(CGThing):
Expand Down Expand Up @@ -2336,11 +2314,6 @@ def definition_body(self):
""" % (FINALIZE_HOOK_NAME,
('Some(%s)' % TRACE_HOOK_NAME),
self.descriptor.name)
else:
body += """ js_info.dom_static.attribute_ids.insert(PrototypeList::id::%s as uint,
slice::cast_to_mut(slice::from_slice(sAttributes_ids)));
""" % self.descriptor.name
body = "" #XXXjdm xray stuff isn't necessary yet

return (body + """ let cx = js_info.js_context.deref().ptr;
let receiver = js_info.js_compartment.global_obj;
Expand Down Expand Up @@ -3685,72 +3658,6 @@ def declare(self, cgClass):
result += "}"
return result


class CGXrayHelper(CGAbstractExternMethod):
def __init__(self, descriptor, name, args, properties):
CGAbstractExternMethod.__init__(self, descriptor, name, "bool", args)
self.properties = properties

def definition_body(self):
varNames = self.properties.variableNames(True)

setup = ("let window = global_object_for_js_object(wrapper);\n"
"let js_info = window.get().page().js_info();\n")

methods = self.properties.methods
if methods.hasNonChromeOnly() or methods.hasChromeOnly():
methodArgs = "Some(zip_copies(%(methods)s, *method_ids))" % varNames
setup += "let method_ids = js_info.get_ref().dom_static.method_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
else:
methodArgs = "None"
methodArgs = CGGeneric(methodArgs)

attrs = self.properties.attrs
if attrs.hasNonChromeOnly() or attrs.hasChromeOnly():
attrArgs = "Some(zip_copies(%(attrs)s, *attr_ids))" % varNames
setup += "let attr_ids = js_info.get_ref().dom_static.attribute_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
else:
attrArgs = "None"
attrArgs = CGGeneric(attrArgs)

consts = self.properties.consts
if consts.hasNonChromeOnly() or consts.hasChromeOnly():
constArgs = "Some(zip_copies(%(consts)s, *const_ids))" % varNames
setup += "let const_ids = js_info.get_ref().dom_static.constant_ids.get(&(PrototypeList::id::ClientRect as uint));\n"
else:
constArgs = "None"
constArgs = CGGeneric(constArgs)

prefixArgs = CGGeneric(self.getPrefixArgs())

return CGIndenter(
CGWrapper(CGList([prefixArgs, methodArgs, attrArgs, constArgs], ", "),
pre=(setup + "return Xray%s(" % self.name),
post=");",
reindent=True)).define()

class CGResolveProperty(CGXrayHelper):
def __init__(self, descriptor, properties):
args = [Argument('*JSContext', 'cx'), Argument('*JSObject', 'wrapper'),
Argument('jsid', 'id'), Argument('bool', 'set'),
Argument('*mut JSPropertyDescriptor', 'desc')]
CGXrayHelper.__init__(self, descriptor, "ResolveProperty", args,
properties)

def getPrefixArgs(self):
return "cx, wrapper, id, desc"


class CGEnumerateProperties(CGXrayHelper):
def __init__(self, descriptor, properties):
args = [Argument('JSContext*', 'cx'), Argument('JSObject*', 'wrapper'),
Argument('JS::AutoIdVector&', 'props')]
CGXrayHelper.__init__(self, descriptor, "EnumerateProperties", args,
properties)

def getPrefixArgs(self):
return "props"

class CGProxySpecialOperation(CGPerSignatureCall):
"""
Base class for classes for calling an indexed or named special operation
Expand Down Expand Up @@ -4294,25 +4201,12 @@ def __init__(self, descriptor):
CGConstant(m for m in descriptor.interface.members if m.isConst()),
public=True))

# Set up our Xray callbacks as needed.
if descriptor.interface.hasInterfacePrototypeObject():
if descriptor.concrete and descriptor.proxy:
#cgThings.append(CGResolveOwnProperty(descriptor))
#cgThings.append(CGEnumerateOwnProperties(descriptor))
pass
cgThings.append(CGResolveProperty(descriptor, properties))
#cgThings.append(CGEnumerateProperties(descriptor, properties))

if descriptor.interface.hasInterfaceObject():
cgThings.append(CGDefineDOMInterfaceMethod(descriptor))
if (descriptor.interface.getExtendedAttribute("PrefControlled") is not None):
#cgThings.append(CGPrefEnabled(descriptor))
pass

if descriptor.interface.hasInterfacePrototypeObject():
cgThings.append(CGNativePropertyHooks(descriptor))
pass

if descriptor.concrete:
if descriptor.proxy:
#cgThings.append(CGProxyIsProxy(descriptor))
Expand Down Expand Up @@ -4746,13 +4640,12 @@ def makeEnumTypedef(e):
'dom::bindings::utils::{GetPropertyOnPrototype, GetProtoOrIfaceArray}',
'dom::bindings::utils::{HasPropertyOnPrototype, IntVal}',
'dom::bindings::utils::{jsid_to_str}',
'dom::bindings::utils::{NativePropertyHooks}',
'dom::bindings::utils::global_object_for_js_object',
'dom::bindings::utils::{Reflectable}',
'dom::bindings::utils::{squirrel_away_unique}',
'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}',
'dom::bindings::utils::{unwrap_object, VoidVal, with_gc_disabled}',
'dom::bindings::utils::{with_gc_enabled, XrayResolveProperty}',
'dom::bindings::utils::{with_gc_enabled}',
'dom::bindings::trace::Traceable',
'dom::bindings::callback::{CallbackContainer,CallbackInterface}',
'dom::bindings::callback::{CallSetup,ExceptionHandling}',
Expand Down
104 changes: 6 additions & 98 deletions src/components/script/dom/bindings/utils.rs
Expand Up @@ -24,11 +24,11 @@ use js::jsapi::{JS_DefineProperties, JS_ForwardGetPropertyTo};
use js::jsapi::{JS_GetClass, JS_LinkConstructorAndPrototype, JS_GetStringCharsAndLength};
use js::jsapi::{JS_ObjectIsRegExp, JS_ObjectIsDate};
use js::jsapi::{JS_InternString, JS_GetFunctionObject};
use js::jsapi::{JS_HasPropertyById, JS_GetPrototype, JS_GetGlobalForObject};
use js::jsapi::{JS_HasPropertyById, JS_GetPrototype};
use js::jsapi::{JS_DefineFunctions, JS_DefineProperty};
use js::jsapi::{JS_ValueToString, JS_GetReservedSlot, JS_SetReservedSlot};
use js::jsapi::{JSContext, JSObject, JSBool, jsid, JSClass, JSNative};
use js::jsapi::{JSFunctionSpec, JSPropertySpec, JSPropertyDescriptor};
use js::jsapi::{JSFunctionSpec, JSPropertySpec};
use js::jsapi::{JS_NewGlobalObject, JS_InitStandardClasses};
use js::jsapi::{JSString};
use js::jsapi::{JS_AllowGC, JS_InhibitGC};
Expand All @@ -37,24 +37,17 @@ use js::jsval::JSVal;
use js::jsval::{PrivateValue, ObjectValue, NullValue, Int32Value};
use js::jsval::{UInt32Value, DoubleValue, BooleanValue, UndefinedValue};
use js::{JSPROP_ENUMERATE, JSCLASS_IS_GLOBAL, JSCLASS_IS_DOMJSCLASS};
use js::{JSPROP_PERMANENT, JSID_VOID, JSPROP_NATIVE_ACCESSORS, JSPROP_GETTER};
use js::JSPROP_SETTER;
use js::JSPROP_PERMANENT;
use js::{JSFUN_CONSTRUCTOR, JSPROP_READONLY};
use js;

pub struct GlobalStaticData {
proxy_handlers: HashMap<uint, *libc::c_void>,
attribute_ids: HashMap<uint, ~[jsid]>,
method_ids: HashMap<uint, ~[jsid]>,
constant_ids: HashMap<uint, ~[jsid]>
proxy_handlers: HashMap<uint, *libc::c_void>
}

pub fn GlobalStaticData() -> GlobalStaticData {
GlobalStaticData {
proxy_handlers: HashMap::new(),
attribute_ids: HashMap::new(),
method_ids: HashMap::new(),
constant_ids: HashMap::new()
proxy_handlers: HashMap::new()
}
}

Expand Down Expand Up @@ -167,40 +160,6 @@ pub static DOM_PROTOTYPE_SLOT: u32 = js::JSCLASS_GLOBAL_SLOT_COUNT;
// changes.
pub static JSCLASS_DOM_GLOBAL: u32 = js::JSCLASS_USERBIT1;

pub struct NativeProperties {
staticMethods: *JSFunctionSpec,
staticMethodIds: *jsid,
staticMethodsSpecs: *JSFunctionSpec,
staticAttributes: *JSPropertySpec,
staticAttributeIds: *jsid,
staticAttributeSpecs: *JSPropertySpec,
methods: *JSFunctionSpec,
methodIds: *jsid,
methodsSpecs: *JSFunctionSpec,
attributes: *JSPropertySpec,
attributeIds: *jsid,
attributeSpecs: *JSPropertySpec,
unforgeableAttributes: *JSPropertySpec,
unforgeableAttributeIds: *jsid,
unforgeableAttributeSpecs: *JSPropertySpec,
constants: *ConstantSpec,
constantIds: *jsid,
constantSpecs: *ConstantSpec
}

pub struct NativePropertyHooks {
resolve_own_property: *u8,
resolve_property: extern "C" fn(*JSContext, *JSObject, jsid, bool, *mut JSPropertyDescriptor) -> bool,
enumerate_own_properties: *u8,
enumerate_properties: *u8,
proto_hooks: *NativePropertyHooks
}

pub struct JSNativeHolder {
native: js::jsapi::JSNative,
propertyHooks: *NativePropertyHooks
}

#[deriving(Clone)]
pub enum ConstantVal {
IntVal(i32),
Expand All @@ -220,9 +179,7 @@ pub struct ConstantSpec {
pub struct DOMClass {
// A list of interfaces that this object implements, in order of decreasing
// derivedness.
interface_chain: [PrototypeList::id::ID, ..MAX_PROTO_CHAIN_LENGTH],

native_hooks: *NativePropertyHooks
interface_chain: [PrototypeList::id::ID, ..MAX_PROTO_CHAIN_LENGTH]
}

pub struct DOMJSClass {
Expand Down Expand Up @@ -491,55 +448,6 @@ pub fn GetArrayIndexFromId(_cx: *JSContext, id: jsid) -> Option<u32> {
}*/
}

pub fn XrayResolveProperty(cx: *JSContext,
wrapper: *JSObject,
id: jsid,
desc: *mut JSPropertyDescriptor,
_methods: Option<~[(JSFunctionSpec, jsid)]>,
attributes: Option<~[(JSPropertySpec, jsid)]>,
_constants: Option<~[(ConstantSpec, jsid)]>) -> bool
{
unsafe {
match attributes {
Some(attrs) => {
for &elem in attrs.iter() {
let (attr, attr_id) = elem;
if attr_id == JSID_VOID || attr_id != id {
continue;
}

(*desc).attrs = (attr.flags & !(JSPROP_NATIVE_ACCESSORS as u8)) as u32;
let global = JS_GetGlobalForObject(cx, wrapper);
let fun = JS_NewFunction(cx, attr.getter.op, 0, 0, global, ptr::null());
if fun.is_null() {
return false;
}

RUST_SET_JITINFO(fun, attr.getter.info);
let funobj = JS_GetFunctionObject(fun);
(*desc).getter = Some(cast::transmute(funobj));
(*desc).attrs |= JSPROP_GETTER;
if attr.setter.op.is_some() {
let fun = JS_NewFunction(cx, attr.setter.op, 1, 0, global, ptr::null());
if fun.is_null() {
return false
}

RUST_SET_JITINFO(fun, attr.setter.info);
let funobj = JS_GetFunctionObject(fun);
(*desc).setter = Some(cast::transmute(funobj));
(*desc).attrs |= JSPROP_SETTER;
} else {
(*desc).setter = None;
}
}
}
None => ()
}
return true;
}
}

fn InternJSString(cx: *JSContext, chars: *libc::c_char) -> Option<jsid> {
unsafe {
let s = JS_InternString(cx, chars);
Expand Down

5 comments on commit 9a4bec3

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from Ms2ger
at ngsankha@9a4bec3

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging sankha93/servo/rmxray = 9a4bec3 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sankha93/servo/rmxray = 9a4bec3 merged ok, testing candidate = 86c83f7

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 86c83f7

Please sign in to comment.