aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-08-27 00:38:46 -0600
committerbors-servo <metajack+bors@gmail.com>2015-08-27 00:38:46 -0600
commita897795dabf8d84c2da2935c54346a75987bcec5 (patch)
tree277a3137b4419f4a9c06d6848d366e2b391fb082 /components/script/dom/bindings/codegen/CodegenRust.py
parent98728a6c751a8959459f80286833152e21fa6cfc (diff)
parentd3ab0c290947923e2ceccfcd2eb191e8e97d3a5b (diff)
downloadservo-a897795dabf8d84c2da2935c54346a75987bcec5.tar.gz
servo-a897795dabf8d84c2da2935c54346a75987bcec5.zip
Auto merge of #7387 - Yoric:2240-2, r=Ms2ger
Fixes #2240 - NamedGetter and NamedSetter do not assume that the arg is named `name` I'm not totally sure about how to test this. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7387) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py51
1 files changed, 29 insertions, 22 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 060a0ebdf8c..40c31ac09ef 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -3966,7 +3966,23 @@ class CGProxyIndexedSetter(CGProxySpecialOperation):
CGProxySpecialOperation.__init__(self, descriptor, 'IndexedSetter')
-class CGProxyNamedGetter(CGProxySpecialOperation):
+class CGProxyNamedOperation(CGProxySpecialOperation):
+ """
+ Class to generate a call to a named operation.
+ """
+ def __init__(self, descriptor, name):
+ CGProxySpecialOperation.__init__(self, descriptor, name)
+
+ def define(self):
+ # Our first argument is the id we're getting.
+ argName = self.arguments[0].identifier.name
+ return ("let %s = jsid_to_str(cx, id);\n"
+ "let this = UnwrapProxy(proxy);\n"
+ "let this = &*this;\n" % argName +
+ CGProxySpecialOperation.define(self))
+
+
+class CGProxyNamedGetter(CGProxyNamedOperation):
"""
Class to generate a call to an named getter. If templateValues is not None
the returned value will be wrapped with wrapForType using templateValues.
@@ -3976,7 +3992,16 @@ class CGProxyNamedGetter(CGProxySpecialOperation):
CGProxySpecialOperation.__init__(self, descriptor, 'NamedGetter')
-class CGProxyNamedSetter(CGProxySpecialOperation):
+class CGProxyNamedPresenceChecker(CGProxyNamedGetter):
+ """
+ Class to generate a call that checks whether a named property exists.
+ For now, we just delegate to CGProxyNamedGetter
+ """
+ def __init__(self, descriptor):
+ CGProxyNamedGetter.__init__(self, descriptor)
+
+
+class CGProxyNamedSetter(CGProxyNamedOperation):
"""
Class to generate a call to a named setter.
"""
@@ -3984,7 +4009,7 @@ class CGProxyNamedSetter(CGProxySpecialOperation):
CGProxySpecialOperation.__init__(self, descriptor, 'NamedSetter')
-class CGProxyNamedDeleter(CGProxySpecialOperation):
+class CGProxyNamedDeleter(CGProxyNamedOperation):
"""
Class to generate a call to a named deleter.
"""
@@ -4057,9 +4082,6 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
# properties that shadow prototype properties.
namedGet = ("\n" +
"if RUST_JSID_IS_STRING(id) != 0 && !has_property_on_prototype(cx, proxy, id) {\n" +
- " let name = jsid_to_str(cx, id);\n" +
- " let this = UnwrapProxy(proxy);\n" +
- " let this = &*this;\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "\n" +
"}\n")
else:
@@ -4121,9 +4143,6 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
if not self.descriptor.operations['NamedCreator'] is namedSetter:
raise TypeError("Can't handle creator that's different from the setter")
set += ("if RUST_JSID_IS_STRING(id) != 0 {\n" +
- " let name = jsid_to_str(cx, id);\n" +
- " let this = UnwrapProxy(proxy);\n" +
- " let this = &*this;\n" +
CGIndenter(CGProxyNamedSetter(self.descriptor)).define() +
" (*opresult).code_ = 0; /* SpecialCodes::OkCode */\n" +
" return JSTrue;\n" +
@@ -4132,9 +4151,6 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
"}\n")
else:
set += ("if RUST_JSID_IS_STRING(id) != 0 {\n" +
- " let name = jsid_to_str(cx, id);\n" +
- " let this = UnwrapProxy(proxy);\n" +
- " let this = &*this;\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() +
" if (found) {\n"
# TODO(Issue 5876)
@@ -4165,10 +4181,7 @@ class CGDOMJSProxyHandler_delete(CGAbstractExternMethod):
def getBody(self):
set = ""
if self.descriptor.operations['NamedDeleter']:
- set += ("let name = jsid_to_str(cx, id);\n" +
- "let this = UnwrapProxy(proxy);\n" +
- "let this = &*this;\n" +
- "%s") % (CGProxyNamedDeleter(self.descriptor).define())
+ set += CGProxyNamedDeleter(self.descriptor).define()
set += "return proxyhandler::delete(%s) as u8;" % ", ".join(a.name for a in self.args)
return set
@@ -4253,9 +4266,6 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
namedGetter = self.descriptor.operations['NamedGetter']
if namedGetter:
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 this = UnwrapProxy(proxy);\n" +
- " let this = &*this;\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" +
" *bp = found as u8;\n"
" return JSTrue;\n"
@@ -4329,9 +4339,6 @@ if !expando.ptr.is_null() {
namedGetter = self.descriptor.operations['NamedGetter']
if namedGetter:
getNamed = ("if (RUST_JSID_IS_STRING(id) != 0) {\n" +
- " let name = jsid_to_str(cx, id);\n" +
- " let this = UnwrapProxy(proxy);\n" +
- " let this = &*this;\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() +
"}\n")
else: