Skip to content

Commit

Permalink
Add support for named deleter
Browse files Browse the repository at this point in the history
Closes #4469.
  • Loading branch information
brunoabinader committed Dec 29, 2014
1 parent 366ea4f commit ab618dd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 30 deletions.
45 changes: 43 additions & 2 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -2089,13 +2089,18 @@ def definition_body(self):
customDefineProperty = 'defineProperty_'
if self.descriptor.operations['IndexedSetter'] or self.descriptor.operations['NamedSetter']:
customDefineProperty = 'defineProperty'

customDelete = 'delete_'
if self.descriptor.operations['NamedDeleter']:
customDelete = 'delete'

body = """\
let traps = ProxyTraps {
getPropertyDescriptor: Some(getPropertyDescriptor),
getOwnPropertyDescriptor: Some(getOwnPropertyDescriptor),
defineProperty: Some(%s),
getOwnPropertyNames: Some(getOwnPropertyNames_),
delete_: Some(delete_),
delete_: Some(%s),
enumerate: Some(enumerate_),
has: None,
Expand Down Expand Up @@ -2123,7 +2128,7 @@ def definition_body(self):
};
CreateProxyHandler(&traps, &Class as *const _ as *const _)
""" % (customDefineProperty, FINALIZE_HOOK_NAME,
""" % (customDefineProperty, customDelete, FINALIZE_HOOK_NAME,
TRACE_HOOK_NAME)
return CGGeneric(body)

Expand Down Expand Up @@ -3580,6 +3585,14 @@ class CGProxyNamedSetter(CGProxySpecialOperation):
def __init__(self, descriptor):
CGProxySpecialOperation.__init__(self, descriptor, 'NamedSetter')

class CGProxyNamedDeleter(CGProxySpecialOperation):
"""
Class to generate a call to a named deleter.
"""
def __init__(self, descriptor):
CGProxySpecialOperation.__init__(self, descriptor, 'NamedDeleter')


class CGProxyUnwrap(CGAbstractMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSObject', 'obj')]
Expand Down Expand Up @@ -3748,6 +3761,28 @@ def getBody(self):
def definition_body(self):
return CGGeneric(self.getBody())

class CGDOMJSProxyHandler_delete(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'),
Argument('jsid', 'id'),
Argument('*mut bool', 'bp')]
CGAbstractExternMethod.__init__(self, descriptor, "delete", "bool", args)
self.descriptor = 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 = JS::from_raw(this);\n" +
"let this = this.root();\n" +
"%s") % (CGProxyNamedDeleter(self.descriptor).define())
set += "return proxyhandler::delete_(%s);" % ", ".join(a.name for a in self.args)
return set

def definition_body(self):
return CGGeneric(self.getBody())

class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'),
Expand Down Expand Up @@ -4164,6 +4199,12 @@ def __init__(self, descriptor):
if descriptor.operations['IndexedSetter'] or descriptor.operations['NamedSetter']:
cgThings.append(CGDOMJSProxyHandler_defineProperty(descriptor))

# We want to prevent indexed deleters from compiling at all.
assert not descriptor.operations['IndexedDeleter']

if descriptor.operations['NamedDeleter']:
cgThings.append(CGDOMJSProxyHandler_delete(descriptor))

#cgThings.append(CGDOMJSProxyHandler(descriptor))
#cgThings.append(CGIsMethod(descriptor))
pass
Expand Down

This file was deleted.

This file was deleted.

5 comments on commit ab618dd

@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.

merging brunoabinader/servo/named-deleter = ab618dd 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.

brunoabinader/servo/named-deleter = ab618dd merged ok, testing candidate = f76a460

@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 = f76a460

Please sign in to comment.