aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-05-07 09:07:12 -0500
committerbors-servo <metajack+bors@gmail.com>2015-05-07 09:07:12 -0500
commit29a43a00b39e544596e3bcce9bdfca2159313ba5 (patch)
tree710ab9f84b0991c81fcb0a0b6ba2af926c442c89
parentc7608f7691f892e985991d85e80f547dac1e9e8f (diff)
parentcc5eee48a61c8a97c02a35cc2bc53e2134b1963c (diff)
downloadservo-29a43a00b39e544596e3bcce9bdfca2159313ba5.tar.gz
servo-29a43a00b39e544596e3bcce9bdfca2159313ba5.zip
Auto merge of #5894 - nox:putforwards, r=jdm
<!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5894) <!-- Reviewable:end -->
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py37
-rw-r--r--components/script/dom/testbinding.rs1
-rw-r--r--components/script/dom/webidls/TestBinding.webidl3
3 files changed, 36 insertions, 5 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index d48db291dd4..a005956e02e 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1335,7 +1335,7 @@ class AttrDefiner(PropertyDefiner):
"native" : accessor})
def setter(attr):
- if attr.readonly:
+ if attr.readonly and not attr.getExtendedAttribute("PutForwards"):
return "JSStrictPropertyOpWrapper {op: None, info: 0 as *const JSJitInfo}"
if self.static:
@@ -2680,7 +2680,6 @@ class CGStaticMethod(CGAbstractStaticBindingMethod):
self.method)
return CGMethodCall(["global.r()"], nativeName, True, self.descriptor, self.method)
-
class CGGenericGetter(CGAbstractBindingMethod):
"""
A class for generating the C++ code for an IDL attribute getter.
@@ -2794,7 +2793,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
self.attr = attr
name = 'set_' + attr.identifier.name
args = [ Argument('*mut JSContext', 'cx'),
- Argument('JSHandleObject', '_obj'),
+ Argument('JSHandleObject', 'obj'),
Argument('*const %s' % descriptor.concreteType, 'this'),
Argument('*mut JSVal', 'argv')]
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
@@ -2835,6 +2834,31 @@ class CGStaticSetter(CGAbstractStaticBindingMethod):
self.attr)
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):
"""
@@ -2863,7 +2887,7 @@ class CGMemberJITInfo(CGThing):
getter = ("get_%s" % self.member.identifier.name)
getterinfal = "infallible" in self.descriptor.getExtendedAttributes(self.member, getter=True)
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)
setter = ("set_%s" % self.member.identifier.name)
# Setters are always fallible, since they have to do a typed unwrap.
@@ -4329,6 +4353,9 @@ class CGDescriptor(CGThing):
hasLenientSetter = True
else:
hasSetter = True
+ elif m.getExtendedAttribute("PutForwards"):
+ cgThings.append(CGSpecializedForwardingSetter(descriptor, m))
+ hasSetter = True
if (not m.isStatic() and
not descriptor.interface.isCallback()):
@@ -4711,7 +4738,7 @@ class CGBindingRoot(CGThing):
'js::jsapi::{JS_GetObjectPrototype, JS_GetProperty, JS_GetPropertyById}',
'js::jsapi::{JS_GetPropertyDescriptorById, JS_GetReservedSlot}',
'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::{JSClass, JSFreeOp, JSFunctionSpec, JSHandleObject, jsid}',
'js::jsapi::{JSNativeWrapper, JSObject, JSPropertyDescriptor, JS_ArrayIterator}',
diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs
index 20451f64648..e06880292b2 100644
--- a/components/script/dom/testbinding.rs
+++ b/components/script/dom/testbinding.rs
@@ -115,6 +115,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
fn GetUsvstringAttributeNullable(self) -> Option<USVString> { Some(USVString("".to_owned())) }
fn SetUsvstringAttributeNullable(self, _: Option<USVString>) {}
fn SetBinaryRenamedAttribute(self, _: DOMString) {}
+ fn ForwardedAttribute(self) -> Temporary<TestBinding> { Temporary::from_rooted(self) }
fn BinaryRenamedAttribute(self) -> DOMString { "".to_owned() }
fn GetEnumAttributeNullable(self) -> Option<TestEnum> { Some(_empty) }
fn GetInterfaceAttributeNullable(self) -> Option<Temporary<Blob>> {
diff --git a/components/script/dom/webidls/TestBinding.webidl b/components/script/dom/webidls/TestBinding.webidl
index 9906de4e696..0ebf0a41126 100644
--- a/components/script/dom/webidls/TestBinding.webidl
+++ b/components/script/dom/webidls/TestBinding.webidl
@@ -112,6 +112,9 @@ interface TestBinding {
attribute (Event or DOMString)? union2AttributeNullable;
[BinaryName="BinaryRenamedAttribute"] attribute DOMString attrToBinaryRename;
+ [PutForwards=booleanAttribute]
+ readonly attribute TestBinding forwardedAttribute;
+
[BinaryName="BinaryRenamedMethod"] void methToBinaryRename();
void receiveVoid();
boolean receiveBoolean();