Bug 792215 part 2. Convert old proxy bindings to JSNative getters and setters. r=peterv,ejpbruel

This commit is contained in:
Kannan Vijayan 2012-09-25 14:44:40 -04:00
parent 1b97afe0c2
commit 07bdefab0b
6 changed files with 43 additions and 47 deletions

View File

@ -439,11 +439,9 @@
"NodeFilter interface: operation acceptNode(Node)": true,
"NodeList interface: existence and properties of interface object": true,
"NodeList interface: existence and properties of interface prototype object": true,
"NodeList interface: attribute length": true,
"NodeList interface: calling item(unsigned long) on document.querySelectorAll(\"script\") with too few arguments must throw TypeError": true,
"HTMLCollection interface: existence and properties of interface object": true,
"HTMLCollection interface: existence and properties of interface prototype object": true,
"HTMLCollection interface: attribute length": true,
"HTMLCollection interface: calling item(unsigned long) on document.body.children with too few arguments must throw TypeError": true,
"HTMLCollection interface: calling namedItem(DOMString) on document.body.children with too few arguments must throw TypeError": true,
"DOMStringList interface: existence and properties of interface object": true,
@ -452,7 +450,6 @@
"DOMStringList interface: attribute length": true,
"DOMTokenList interface: existence and properties of interface object": true,
"DOMTokenList interface: existence and properties of interface prototype object": true,
"DOMTokenList interface: attribute length": true,
"Stringification of document.body.classList": true,
"DOMTokenList interface: calling item(unsigned long) on document.body.classList with too few arguments must throw TypeError": true,
"DOMTokenList interface: calling contains(DOMString) on document.body.classList with too few arguments must throw TypeError": true,
@ -460,6 +457,5 @@
"DOMTokenList interface: calling remove(DOMString) on document.body.classList with too few arguments must throw TypeError": true,
"DOMTokenList interface: calling toggle(DOMString) on document.body.classList with too few arguments must throw TypeError": true,
"DOMSettableTokenList interface: existence and properties of interface object": true,
"DOMSettableTokenList interface: existence and properties of interface prototype object": true,
"DOMSettableTokenList interface: attribute value": true
"DOMSettableTokenList interface: existence and properties of interface prototype object": true
}

View File

@ -825,7 +825,6 @@ PropDesc::initFromPropertyDescriptor(const PropertyDescriptor &desc)
isUndefined_ = false;
pd_.setUndefined();
attrs = uint8_t(desc.attrs);
JS_ASSERT_IF(attrs & JSPROP_READONLY, !(attrs & (JSPROP_GETTER | JSPROP_SETTER)));
if (desc.attrs & (JSPROP_GETTER | JSPROP_SETTER)) {
hasGet_ = true;
get_ = ((desc.attrs & JSPROP_GETTER) && desc.getter)

View File

@ -178,8 +178,8 @@ def writeArgumentUnboxing(f, i, name, type, optional, rvdeclared,
isSetter = (i is None)
if isSetter:
argPtr = "vp"
argVal = "*vp"
argPtr = "argv"
argVal = "*argv"
elif optional:
if typeName == "[jsval]":
val = "JSVAL_VOID"
@ -429,16 +429,8 @@ def writeStub(f, customMethodCalls, member, stubName, writeThisUnwrapping, write
isNotxpcom = isMethod and member.notxpcom
isGetter = isAttr and not isSetter
signature = "static JSBool\n"
if isAttr:
# JSPropertyOp signature.
if isSetter:
signature += "%s(JSContext *cx, JSHandleObject obj, JSHandleId id, JSBool strict,%s JSMutableHandleValue vp_)\n"
else:
signature += "%s(JSContext *cx, JSHandleObject obj, JSHandleId id,%s JSMutableHandleValue vp_)\n"
else:
# JSFastNative.
signature += "%s(JSContext *cx, unsigned argc,%s jsval *vp)\n"
signature = ("static JSBool\n"
"%s(JSContext *cx, unsigned argc,%s jsval *vp)\n")
customMethodCall = customMethodCalls.get(stubName, None)
@ -470,7 +462,7 @@ def writeStub(f, customMethodCalls, member, stubName, writeThisUnwrapping, write
argumentValues = (customMethodCall['additionalArgumentValues']
% header.methodNativeName(member))
if isAttr:
callTemplate += (" return %s(cx, obj, id%s, %s, vp_);\n"
callTemplate += (" return %s(cx, obj, id%s, %s, vp);\n"
% (templateName, ", strict" if isSetter else "", argumentValues))
else:
callTemplate += (" return %s(cx, argc, %s, vp);\n"
@ -504,15 +496,10 @@ def writeStub(f, customMethodCalls, member, stubName, writeThisUnwrapping, write
f.write("{\n")
f.write(" XPC_QS_ASSERT_CONTEXT_OK(cx);\n")
# Convert JSMutableHandleValue to jsval*
if isAttr:
f.write(" jsval *vp = vp_.address();\n")
# For methods, compute "this".
if isMethod:
f.write(" JSObject *obj = JS_THIS_OBJECT(cx, vp);\n"
" if (!obj)\n"
" return JS_FALSE;\n")
# Compute "this".
f.write(" JSObject *obj = JS_THIS_OBJECT(cx, vp);\n"
" if (!obj)\n"
" return JS_FALSE;\n")
selfname = writeThisUnwrapping(f, member, isMethod, isGetter, customMethodCall)
@ -523,14 +510,20 @@ def writeStub(f, customMethodCalls, member, stubName, writeThisUnwrapping, write
requiredArgs = inArgs
while requiredArgs and member.params[requiredArgs-1].optional:
requiredArgs -= 1
if requiredArgs:
f.write(" if (argc < %d)\n" % requiredArgs)
f.write(" return xpc_qsThrow(cx, "
"NS_ERROR_XPC_NOT_ENOUGH_ARGS);\n")
elif isSetter:
inArgs = requiredArgs = 1
else:
inArgs = requiredArgs = 0
# Convert in-parameters.
if inArgs > 0:
f.write(" jsval *argv = JS_ARGV(cx, vp);\n")
if requiredArgs:
f.write(" if (argc < %d)\n" % requiredArgs)
f.write(" return xpc_qsThrow(cx, "
"NS_ERROR_XPC_NOT_ENOUGH_ARGS);\n")
# Convert in-parameters.
if inArgs > 0:
f.write(" jsval *argv = JS_ARGV(cx, vp);\n")
if isMethod:
for i in range(inArgs):
param = member.params[i]
argName = 'arg%d' % i
@ -632,7 +625,8 @@ def writeStub(f, customMethodCalls, member, stubName, writeThisUnwrapping, write
if isMethod or isGetter:
writeResultWrapping(f, member, 'vp', '*vp')
else:
f.write(" return JS_TRUE;\n")
f.write(" JS_SET_RVAL(cx, vp, JS::UndefinedValue());\n"
" return JS_TRUE;\n")
# Epilog.
f.write("}\n\n")

View File

@ -210,14 +210,17 @@ ListBase<LC>::instanceIsListObject(JSContext *cx, JSObject *obj, JSObject *calle
template<class LC>
JSBool
ListBase<LC>::length_getter(JSContext *cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp)
ListBase<LC>::length_getter(JSContext *cx, unsigned argc, JS::Value *vp)
{
JSObject *obj = JS_THIS_OBJECT(cx, vp);
if (!obj)
return false;
if (!instanceIsListObject(cx, obj, NULL))
return false;
uint32_t length;
getListObject(obj)->GetLength(&length);
MOZ_ASSERT(int32_t(length) >= 0);
vp.set(UINT_TO_JSVAL(length));
JS_SET_RVAL(cx, vp, UINT_TO_JSVAL(length));
return true;
}
@ -361,12 +364,16 @@ ListBase<LC>::getPrototype(JSContext *cx, XPCWrappedNativeScope *scope,
for (size_t n = 0; n < sProtoPropertiesCount; ++n) {
MOZ_ASSERT(sProtoProperties[n].getter);
jsid id = sProtoProperties[n].id;
unsigned attrs = JSPROP_ENUMERATE | JSPROP_SHARED;
unsigned attrs = JSPROP_ENUMERATE | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS;
if (!sProtoProperties[n].setter)
attrs |= JSPROP_READONLY;
if (!JS_DefinePropertyById(cx, interfacePrototype, id, JSVAL_VOID,
sProtoProperties[n].getter, sProtoProperties[n].setter, attrs))
(JSPropertyOp) sProtoProperties[n].getter,
(JSStrictPropertyOp) sProtoProperties[n].setter,
attrs))
{
return NULL;
}
}
for (size_t n = 0; n < sProtoMethodsCount; ++n) {
@ -763,12 +770,12 @@ ListBase<LC>::resolveNativeName(JSContext *cx, JSObject *proxy, jsid id, JSPrope
for (size_t n = 0; n < sProtoPropertiesCount; ++n) {
if (id == sProtoProperties[n].id) {
desc->attrs = JSPROP_ENUMERATE | JSPROP_SHARED;
desc->attrs = JSPROP_ENUMERATE | JSPROP_SHARED | JSPROP_NATIVE_ACCESSORS;
if (!sProtoProperties[n].setter)
desc->attrs |= JSPROP_READONLY;
desc->obj = proxy;
desc->setter = sProtoProperties[n].setter;
desc->getter = sProtoProperties[n].getter;
desc->setter = (JSStrictPropertyOp) sProtoProperties[n].setter;
desc->getter = (JSPropertyOp) sProtoProperties[n].getter;
return true;
}
}

View File

@ -117,8 +117,8 @@ private:
struct Properties {
jsid &id;
JSPropertyOp getter;
JSStrictPropertyOp setter;
JSNative getter;
JSNative setter;
};
struct Methods {
jsid &id;
@ -133,7 +133,7 @@ private:
static JSObject *ensureExpandoObject(JSContext *cx, JSObject *obj);
static JSBool length_getter(JSContext *cx, JSHandleObject obj, JSHandleId id, JSMutableHandleValue vp);
static JSBool length_getter(JSContext *cx, unsigned argc, JS::Value *vp);
static inline bool getItemAt(ListType *list, uint32_t i, IndexGetterType &item);
static inline bool setItemAt(JSContext *cx, ListType *list, uint32_t i, IndexSetterType item);

View File

@ -599,7 +599,7 @@ def writeAttrStubs(f, classname, attr):
getterName = classname + '_' + header.attributeNativeName(attr, True)
writeBindingStub(f, classname, attr, getterName)
if attr.readonly:
setterName = 'xpc_qsGetterOnlyPropertyStub'
setterName = 'xpc_qsGetterOnlyNativeStub'
else:
setterName = (classname + '_'
+ header.attributeNativeName(attr, False))