Update ProxyTraps to use real bools.

This commit is contained in:
Ms2ger 2014-08-26 14:27:11 +02:00
parent b0c2e09ed7
commit 16510963b5
3 changed files with 58 additions and 53 deletions

View file

@ -3547,10 +3547,10 @@ return box_;""" % self.descriptor.concreteType)
class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'),
Argument('jsid', 'id'), Argument('JSBool', 'set'),
Argument('jsid', 'id'), Argument('bool', 'set'),
Argument('*mut JSPropertyDescriptor', 'desc')]
CGAbstractExternMethod.__init__(self, descriptor, "getOwnPropertyDescriptor",
"JSBool", args)
"bool", args)
self.descriptor = descriptor
def getBody(self):
indexedGetter = self.descriptor.operations['IndexedGetter']
@ -3562,7 +3562,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
if indexedGetter:
readonly = toStringBool(self.descriptor.operations['IndexedSetter'] is None)
fillDescriptor = "FillPropertyDescriptor(&mut *desc, proxy, %s);\nreturn 1;" % readonly
fillDescriptor = "FillPropertyDescriptor(&mut *desc, proxy, %s);\nreturn true;" % readonly
templateValues = {'jsvalRef': '(*desc).value', 'successCode': fillDescriptor}
get = ("if index.is_some() {\n" +
" let index = index.unwrap();\n" +
@ -3581,7 +3581,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
# FIXME need to check that this is a 'supported property index'
assert False
setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, false);\n" +
" return 1;\n" +
" return true;\n" +
" }\n")
if self.descriptor.operations['NamedSetter']:
setOrIndexedGet += " if RUST_JSID_IS_STRING(id) {\n"
@ -3589,7 +3589,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
# FIXME need to check that this is a 'supported property name'
assert False
setOrIndexedGet += (" FillPropertyDescriptor(&mut *desc, proxy, false);\n" +
" return 1;\n" +
" return true;\n" +
" }\n")
setOrIndexedGet += "}"
if indexedGetter:
@ -3598,20 +3598,20 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
"}")
setOrIndexedGet += "\n\n"
elif indexedGetter:
setOrIndexedGet += ("if set == 0 {\n" +
setOrIndexedGet += ("if !set {\n" +
CGIndenter(CGGeneric(get)).define() +
"}\n\n")
namedGetter = self.descriptor.operations['NamedGetter']
if namedGetter:
readonly = toStringBool(self.descriptor.operations['NamedSetter'] is None)
fillDescriptor = "FillPropertyDescriptor(&mut *desc, proxy, %s);\nreturn 1;" % readonly
fillDescriptor = "FillPropertyDescriptor(&mut *desc, proxy, %s);\nreturn true;" % readonly
templateValues = {'jsvalRef': '(*desc).value', 'successCode': fillDescriptor}
# Once we start supporting OverrideBuiltins we need to make
# ResolveOwnProperty or EnumerateOwnProperties filter out named
# properties that shadow prototype properties.
namedGet = ("\n" +
"if set == 0 && RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" +
"if !set && RUST_JSID_IS_STRING(id) != 0 && !HasPropertyOnPrototype(cx, proxy, id) {\n" +
" let name = jsid_to_str(cx, id);\n" +
" let this = UnwrapProxy(proxy);\n" +
" let this = JS::from_raw(this);\n" +
@ -3624,19 +3624,19 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
return setOrIndexedGet + """let expando: *mut JSObject = GetExpandoObject(proxy);
//if (!xpc::WrapperFactory::IsXrayWrapper(proxy) && (expando = GetExpandoObject(proxy))) {
if expando.is_not_null() {
let flags = if set != 0 { JSRESOLVE_ASSIGNING } else { 0 } | JSRESOLVE_QUALIFIED;
let flags = if set { JSRESOLVE_ASSIGNING } else { 0 } | JSRESOLVE_QUALIFIED;
if JS_GetPropertyDescriptorById(cx, expando, id, flags, desc) == 0 {
return 0;
return false;
}
if (*desc).obj.is_not_null() {
// Pretend the property lives on the wrapper.
(*desc).obj = proxy;
return 1;
return true;
}
}
""" + namedGet + """
(*desc).obj = ptr::mut_null();
return 1;"""
return true;"""
def definition_body(self):
return CGGeneric(self.getBody())
@ -3646,7 +3646,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'),
Argument('jsid', 'id'),
Argument('*const JSPropertyDescriptor', 'desc')]
CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "JSBool", args)
CGAbstractExternMethod.__init__(self, descriptor, "defineProperty", "bool", args)
self.descriptor = descriptor
def getBody(self):
set = ""
@ -3662,11 +3662,11 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
" let this = JS::from_raw(this);\n" +
" let this = this.root();\n" +
CGIndenter(CGProxyIndexedSetter(self.descriptor)).define() +
" return 1;\n" +
" return true;\n" +
"}\n")
elif self.descriptor.operations['IndexedGetter']:
set += ("if GetArrayIndexFromId(cx, id).is_some() {\n" +
" return 0;\n" +
" return false;\n" +
" //return ThrowErrorMessage(cx, MSG_NO_PROPERTY_SETTER, \"%s\");\n" +
"}\n") % self.descriptor.name
@ -3689,10 +3689,10 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
" let this = this.root();\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() +
" if (found) {\n"
" return 0;\n" +
" return false;\n" +
" //return ThrowErrorMessage(cx, MSG_NO_PROPERTY_SETTER, \"%s\");\n" +
" }\n" +
" return 1;\n"
" return true;\n"
"}\n") % (self.descriptor.name)
return set + """return proxyhandler::defineProperty_(%s);""" % ", ".join(a.name for a in self.args)
@ -3702,8 +3702,8 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
def __init__(self, descriptor):
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'),
Argument('jsid', 'id'), Argument('*mut JSBool', 'bp')]
CGAbstractExternMethod.__init__(self, descriptor, "hasOwn", "JSBool", args)
Argument('jsid', 'id'), Argument('*mut bool', 'bp')]
CGAbstractExternMethod.__init__(self, descriptor, "hasOwn", "bool", args)
self.descriptor = descriptor
def getBody(self):
indexedGetter = self.descriptor.operations['IndexedGetter']
@ -3715,8 +3715,8 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
" let this = JS::from_raw(this);\n" +
" let this = this.root();\n" +
CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" +
" *bp = found as JSBool;\n" +
" return 1;\n" +
" *bp = found;\n" +
" return true;\n" +
"}\n\n")
else:
indexed = ""
@ -3729,8 +3729,8 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
" let this = JS::from_raw(this);\n" +
" let this = this.root();\n" +
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" +
" *bp = found as JSBool;\n"
" return 1;\n"
" *bp = found;\n"
" return true;\n"
"}\n" +
"\n")
else:
@ -3739,15 +3739,15 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
return indexed + """let expando: *mut JSObject = GetExpandoObject(proxy);
if expando.is_not_null() {
let mut b: JSBool = 1;
let ok: JSBool = JS_HasPropertyById(cx, expando, id, &mut b);
*bp = !!b;
if ok == 0 || *bp != 0 {
let ok = JS_HasPropertyById(cx, expando, id, &mut b) != 0;
*bp = b != 0;
if !ok || *bp {
return ok;
}
}
""" + named + """*bp = 0;
return 1;"""
""" + named + """*bp = false;
return true;"""
def definition_body(self):
return CGGeneric(self.getBody())
@ -3757,22 +3757,25 @@ class CGDOMJSProxyHandler_get(CGAbstractExternMethod):
args = [Argument('*mut JSContext', 'cx'), Argument('*mut JSObject', 'proxy'),
Argument('*mut JSObject', 'receiver'), Argument('jsid', 'id'),
Argument('*mut JSVal', 'vp')]
CGAbstractExternMethod.__init__(self, descriptor, "get", "JSBool", args)
CGAbstractExternMethod.__init__(self, descriptor, "get", "bool", args)
self.descriptor = descriptor
def getBody(self):
getFromExpando = """let expando = GetExpandoObject(proxy);
if expando.is_not_null() {
let mut hasProp = 0;
if JS_HasPropertyById(cx, expando, id, &mut hasProp) == 0 {
return 0;
return false;
}
if hasProp != 0 {
return JS_GetPropertyById(cx, expando, id, vp);
return JS_GetPropertyById(cx, expando, id, vp) != 0;
}
}"""
templateValues = {'jsvalRef': '*vp'}
templateValues = {
'jsvalRef': '*vp',
'successCode': 'return true;',
}
indexedGetter = self.descriptor.operations['IndexedGetter']
if indexedGetter:
@ -3811,15 +3814,15 @@ if expando.is_not_null() {
%s
let mut found = false;
if !GetPropertyOnPrototype(cx, proxy, id, &mut found, vp) {
return 0;
return false;
}
if found {
return 1;
return true;
}
%s
*vp = UndefinedValue();
return 1;""" % (getIndexedOrExpando, getNamed)
return true;""" % (getIndexedOrExpando, getNamed)
def definition_body(self):
return CGGeneric(self.getBody())