mirror of
https://github.com/servo/servo.git
synced 2025-06-08 08:33:26 +00:00
Generate forwarded setters
This commit is contained in:
parent
15c4372a8b
commit
cc5eee48a6
3 changed files with 36 additions and 5 deletions
|
@ -1335,7 +1335,7 @@ class AttrDefiner(PropertyDefiner):
|
||||||
"native" : accessor})
|
"native" : accessor})
|
||||||
|
|
||||||
def setter(attr):
|
def setter(attr):
|
||||||
if attr.readonly:
|
if attr.readonly and not attr.getExtendedAttribute("PutForwards"):
|
||||||
return "JSStrictPropertyOpWrapper {op: None, info: 0 as *const JSJitInfo}"
|
return "JSStrictPropertyOpWrapper {op: None, info: 0 as *const JSJitInfo}"
|
||||||
|
|
||||||
if self.static:
|
if self.static:
|
||||||
|
@ -2680,7 +2680,6 @@ class CGStaticMethod(CGAbstractStaticBindingMethod):
|
||||||
self.method)
|
self.method)
|
||||||
return CGMethodCall(["global.r()"], nativeName, True, self.descriptor, self.method)
|
return CGMethodCall(["global.r()"], nativeName, True, self.descriptor, self.method)
|
||||||
|
|
||||||
|
|
||||||
class CGGenericGetter(CGAbstractBindingMethod):
|
class CGGenericGetter(CGAbstractBindingMethod):
|
||||||
"""
|
"""
|
||||||
A class for generating the C++ code for an IDL attribute getter.
|
A class for generating the C++ code for an IDL attribute getter.
|
||||||
|
@ -2794,7 +2793,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
|
||||||
self.attr = attr
|
self.attr = attr
|
||||||
name = 'set_' + attr.identifier.name
|
name = 'set_' + attr.identifier.name
|
||||||
args = [ Argument('*mut JSContext', 'cx'),
|
args = [ Argument('*mut JSContext', 'cx'),
|
||||||
Argument('JSHandleObject', '_obj'),
|
Argument('JSHandleObject', 'obj'),
|
||||||
Argument('*const %s' % descriptor.concreteType, 'this'),
|
Argument('*const %s' % descriptor.concreteType, 'this'),
|
||||||
Argument('*mut JSVal', 'argv')]
|
Argument('*mut JSVal', 'argv')]
|
||||||
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
|
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
|
||||||
|
@ -2835,6 +2834,31 @@ class CGStaticSetter(CGAbstractStaticBindingMethod):
|
||||||
self.attr)
|
self.attr)
|
||||||
return CGList([checkForArg, call])
|
return CGList([checkForArg, call])
|
||||||
|
|
||||||
|
class CGSpecializedForwardingSetter(CGSpecializedSetter):
|
||||||
|
"""
|
||||||
|
A class for generating the code for an IDL attribute forwarding setter.
|
||||||
|
"""
|
||||||
|
def __init__(self, descriptor, attr):
|
||||||
|
CGSpecializedSetter.__init__(self, descriptor, attr)
|
||||||
|
|
||||||
|
def definition_body(self):
|
||||||
|
attrName = self.attr.identifier.name
|
||||||
|
forwardToAttrName = self.attr.getExtendedAttribute("PutForwards")[0]
|
||||||
|
# JS_GetProperty and JS_SetProperty can only deal with ASCII
|
||||||
|
assert all(ord(c) < 128 for c in attrName)
|
||||||
|
assert all(ord(c) < 128 for c in forwardToAttrName)
|
||||||
|
return CGGeneric("""\
|
||||||
|
let mut v = UndefinedValue();
|
||||||
|
if JS_GetProperty(cx, *obj.unnamed_field1, b"%s".as_ptr() as *const i8, &mut v) == 0 {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if !v.is_object() {
|
||||||
|
throw_type_error(cx, "Value.%s is not an object.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
let target_obj = v.to_object();
|
||||||
|
JS_SetProperty(cx, target_obj, b"%s".as_ptr() as *const i8, argv.offset(0))
|
||||||
|
""" % (attrName, attrName, forwardToAttrName))
|
||||||
|
|
||||||
class CGMemberJITInfo(CGThing):
|
class CGMemberJITInfo(CGThing):
|
||||||
"""
|
"""
|
||||||
|
@ -2863,7 +2887,7 @@ class CGMemberJITInfo(CGThing):
|
||||||
getter = ("get_%s" % self.member.identifier.name)
|
getter = ("get_%s" % self.member.identifier.name)
|
||||||
getterinfal = "infallible" in self.descriptor.getExtendedAttributes(self.member, getter=True)
|
getterinfal = "infallible" in self.descriptor.getExtendedAttributes(self.member, getter=True)
|
||||||
result = self.defineJitInfo(getterinfo, getter, getterinfal)
|
result = self.defineJitInfo(getterinfo, getter, getterinfal)
|
||||||
if not self.member.readonly:
|
if not self.member.readonly or self.member.getExtendedAttribute("PutForwards"):
|
||||||
setterinfo = ("%s_setterinfo" % self.member.identifier.name)
|
setterinfo = ("%s_setterinfo" % self.member.identifier.name)
|
||||||
setter = ("set_%s" % self.member.identifier.name)
|
setter = ("set_%s" % self.member.identifier.name)
|
||||||
# Setters are always fallible, since they have to do a typed unwrap.
|
# Setters are always fallible, since they have to do a typed unwrap.
|
||||||
|
@ -4329,6 +4353,9 @@ class CGDescriptor(CGThing):
|
||||||
hasLenientSetter = True
|
hasLenientSetter = True
|
||||||
else:
|
else:
|
||||||
hasSetter = True
|
hasSetter = True
|
||||||
|
elif m.getExtendedAttribute("PutForwards"):
|
||||||
|
cgThings.append(CGSpecializedForwardingSetter(descriptor, m))
|
||||||
|
hasSetter = True
|
||||||
|
|
||||||
if (not m.isStatic() and
|
if (not m.isStatic() and
|
||||||
not descriptor.interface.isCallback()):
|
not descriptor.interface.isCallback()):
|
||||||
|
@ -4711,7 +4738,7 @@ class CGBindingRoot(CGThing):
|
||||||
'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}',
|
'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}',
|
||||||
'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}',
|
'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}',
|
||||||
'js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_IsExceptionPending}',
|
'js::jsapi::{JS_HasProperty, JS_HasPropertyById, JS_IsExceptionPending}',
|
||||||
'js::jsapi::{JS_NewObject, JS_ObjectIsCallable, JS_SetPrototype}',
|
'js::jsapi::{JS_NewObject, JS_ObjectIsCallable, JS_SetProperty, JS_SetPrototype}',
|
||||||
'js::jsapi::{JS_SetReservedSlot, JS_WrapValue, JSBool, JSContext}',
|
'js::jsapi::{JS_SetReservedSlot, JS_WrapValue, JSBool, JSContext}',
|
||||||
'js::jsapi::{JSClass, JSFreeOp, JSFunctionSpec, JSHandleObject, jsid}',
|
'js::jsapi::{JSClass, JSFreeOp, JSFunctionSpec, JSHandleObject, jsid}',
|
||||||
'js::jsapi::{JSNativeWrapper, JSObject, JSPropertyDescriptor, JS_ArrayIterator}',
|
'js::jsapi::{JSNativeWrapper, JSObject, JSPropertyDescriptor, JS_ArrayIterator}',
|
||||||
|
|
|
@ -115,6 +115,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
||||||
fn GetUsvstringAttributeNullable(self) -> Option<USVString> { Some(USVString("".to_owned())) }
|
fn GetUsvstringAttributeNullable(self) -> Option<USVString> { Some(USVString("".to_owned())) }
|
||||||
fn SetUsvstringAttributeNullable(self, _: Option<USVString>) {}
|
fn SetUsvstringAttributeNullable(self, _: Option<USVString>) {}
|
||||||
fn SetBinaryRenamedAttribute(self, _: DOMString) {}
|
fn SetBinaryRenamedAttribute(self, _: DOMString) {}
|
||||||
|
fn ForwardedAttribute(self) -> Temporary<TestBinding> { Temporary::from_rooted(self) }
|
||||||
fn BinaryRenamedAttribute(self) -> DOMString { "".to_owned() }
|
fn BinaryRenamedAttribute(self) -> DOMString { "".to_owned() }
|
||||||
fn GetEnumAttributeNullable(self) -> Option<TestEnum> { Some(_empty) }
|
fn GetEnumAttributeNullable(self) -> Option<TestEnum> { Some(_empty) }
|
||||||
fn GetInterfaceAttributeNullable(self) -> Option<Temporary<Blob>> {
|
fn GetInterfaceAttributeNullable(self) -> Option<Temporary<Blob>> {
|
||||||
|
|
|
@ -112,6 +112,9 @@ interface TestBinding {
|
||||||
attribute (Event or DOMString)? union2AttributeNullable;
|
attribute (Event or DOMString)? union2AttributeNullable;
|
||||||
[BinaryName="BinaryRenamedAttribute"] attribute DOMString attrToBinaryRename;
|
[BinaryName="BinaryRenamedAttribute"] attribute DOMString attrToBinaryRename;
|
||||||
|
|
||||||
|
[PutForwards=booleanAttribute]
|
||||||
|
readonly attribute TestBinding forwardedAttribute;
|
||||||
|
|
||||||
[BinaryName="BinaryRenamedMethod"] void methToBinaryRename();
|
[BinaryName="BinaryRenamedMethod"] void methToBinaryRename();
|
||||||
void receiveVoid();
|
void receiveVoid();
|
||||||
boolean receiveBoolean();
|
boolean receiveBoolean();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue