Skip to content

Commit

Permalink
Fixes #2240 - NamedGetter and NamedSetter do not assume that the argu…
Browse files Browse the repository at this point in the history
…ment is named `name`
  • Loading branch information
Yoric committed Aug 26, 2015
1 parent 9e52dd8 commit d3ab0c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
51 changes: 29 additions & 22 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -3966,7 +3966,23 @@ def __init__(self, descriptor):
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.
Expand All @@ -3976,15 +3992,24 @@ def __init__(self, descriptor, templateValues=None):
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.
"""
def __init__(self, descriptor):
CGProxySpecialOperation.__init__(self, descriptor, 'NamedSetter')


class CGProxyNamedDeleter(CGProxySpecialOperation):
class CGProxyNamedDeleter(CGProxyNamedOperation):
"""
Class to generate a call to a named deleter.
"""
Expand Down Expand Up @@ -4057,9 +4082,6 @@ def getBody(self):
# 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:
Expand Down Expand Up @@ -4121,9 +4143,6 @@ def getBody(self):
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" +
Expand All @@ -4132,9 +4151,6 @@ def getBody(self):
"}\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)
Expand Down Expand Up @@ -4165,10 +4181,7 @@ def __init__(self, descriptor):
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

Expand Down Expand Up @@ -4253,9 +4266,6 @@ def getBody(self):
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"
Expand Down Expand Up @@ -4329,9 +4339,6 @@ def getBody(self):
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:
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/webidls/TestBindingProxy.webidl
Expand Up @@ -15,9 +15,9 @@
interface TestBindingProxy : TestBinding {
readonly attribute unsigned long length;

getter DOMString getNamedItem(DOMString name);
getter DOMString getNamedItem(DOMString item_name);

setter creator void setNamedItem(DOMString name, DOMString value);
setter creator void setNamedItem(DOMString item_name, DOMString value);

getter DOMString getItem(unsigned long index);

Expand Down

0 comments on commit d3ab0c2

Please sign in to comment.