Bug 1315135. Remove the RegExp (and some Date) special casing from our dictionary conversions and Web IDL overload resolution. r=peterv

This commit is contained in:
Boris Zbarsky 2016-11-23 22:57:29 -05:00
Родитель 55195fe393
Коммит 099ef6f007
4 изменённых файлов: 31 добавлений и 82 удалений

Просмотреть файл

@ -236,50 +236,10 @@ UnwrapObject(JSObject* obj, U& value)
PrototypeTraits<PrototypeID>::Depth);
}
inline bool
IsNotDateOrRegExp(JSContext* cx, JS::Handle<JSObject*> obj,
bool* notDateOrRegExp)
{
MOZ_ASSERT(obj);
js::ESClass cls;
if (!js::GetBuiltinClass(cx, obj, &cls)) {
return false;
}
*notDateOrRegExp = cls != js::ESClass::Date && cls != js::ESClass::RegExp;
return true;
}
MOZ_ALWAYS_INLINE bool
IsObjectValueConvertibleToDictionary(JSContext* cx,
JS::Handle<JS::Value> objVal,
bool* convertible)
IsConvertibleToDictionary(JS::Handle<JS::Value> val)
{
JS::Rooted<JSObject*> obj(cx, &objVal.toObject());
return IsNotDateOrRegExp(cx, obj, convertible);
}
MOZ_ALWAYS_INLINE bool
IsConvertibleToDictionary(JSContext* cx, JS::Handle<JS::Value> val,
bool* convertible)
{
if (val.isNullOrUndefined()) {
*convertible = true;
return true;
}
if (!val.isObject()) {
*convertible = false;
return true;
}
return IsObjectValueConvertibleToDictionary(cx, val, convertible);
}
MOZ_ALWAYS_INLINE bool
IsConvertibleToCallbackInterface(JSContext* cx, JS::Handle<JSObject*> obj,
bool* convertible)
{
return IsNotDateOrRegExp(cx, obj, convertible);
return val.isNullOrUndefined() || val.isObject();
}
// The items in the protoAndIfaceCache are indexed by the prototypes::id::ID,

Просмотреть файл

@ -5783,30 +5783,24 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
exceptionCode=exceptionCode)
if failureCode is not None:
if isDefinitelyObject:
dictionaryTest = "IsObjectValueConvertibleToDictionary"
# This means we're part of an overload or union conversion, and
# should simply skip stuff if our value is not convertible to
# dictionary, instead of trying and throwing. If we're either
# isDefinitelyObject or isNullOrUndefined then we're convertible to
# dictionary and don't need to check here.
if isDefinitelyObject or isNullOrUndefined:
template = conversionCode
else:
dictionaryTest = "IsConvertibleToDictionary"
template = fill("""
{ // scope for isConvertible
bool isConvertible;
if (!${testConvertible}(cx, ${val}, &isConvertible)) {
$*{exceptionCode}
}
if (!isConvertible) {
$*{failureCode}
}
$*{conversionCode}
}
""",
testConvertible=dictionaryTest,
val=val,
exceptionCode=exceptionCode,
failureCode=failureCode,
conversionCode=conversionCode)
template = fill(
"""
if (!IsConvertibleToDictionary(${val})) {
$*{failureCode}
}
$*{conversionCode}
""",
val=val,
failureCode=failureCode,
conversionCode=conversionCode)
else:
template = conversionCode
@ -8030,12 +8024,12 @@ class CGMethodCall(CGThing):
# 1) A platform object that's not a platform array object, being
# passed to an interface or "object" arg.
# 2) A Date object being passed to a Date or "object" arg.
# 3) A RegExp object being passed to a RegExp or "object" arg.
# 4) A callable object being passed to a callback or "object" arg.
# 5) An iterable object being passed to a sequence arg.
# 6) Any non-Date and non-RegExp object being passed to a
# array or callback interface or dictionary or
# "object" arg.
# XXXbz This is actually gone from the spec now, but we still
# have some APIs using Date.
# 3) A callable object being passed to a callback or "object" arg.
# 4) An iterable object being passed to a sequence arg.
# 5) Any object being passed to a array or callback interface or
# dictionary or "object" arg.
# First grab all the overloads that have a non-callback interface
# (which includes typed arrays and arraybuffers) at the
@ -12591,14 +12585,8 @@ class CGDictionary(CGThing):
else:
body += dedent(
"""
{ // scope for isConvertible
bool isConvertible;
if (!IsConvertibleToDictionary(cx, val, &isConvertible)) {
return false;
}
if (!isConvertible) {
return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
}
if (!IsConvertibleToDictionary(val)) {
return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
}
""")

Просмотреть файл

@ -163,7 +163,8 @@ def WebIDLTest(parser, harness):
"Promise<any>", "Promise<any>?",
"USVString", "ArrayBuffer", "ArrayBufferView", "SharedArrayBuffer",
"Uint8Array", "Uint16Array" ]
# When we can parse Date and RegExp, we need to add them here.
# When we can parse Date, we need to add it here.
# XXXbz we can, and should really do that...
# Try to categorize things a bit to keep list lengths down
def allBut(list1, list2):

Просмотреть файл

@ -44,9 +44,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=882653
[ 'document.createTreeWalker(document, 0xFFFFFFFF, { acceptNode: 5 }).nextNode()',
"Property 'acceptNode' is not callable.",
"non-callable callback interface operation property" ],
[ '(new TextDecoder).decode(new Uint8Array(), new RegExp())',
[ '(new TextDecoder).decode(new Uint8Array(), 5)',
"Argument 2 of TextDecoder.decode can't be converted to a dictionary.",
"regexp passed for a dictionary" ],
"primitive passed for a dictionary" ],
[ 'URL.createObjectURL(null, null)',
"Argument 1 is not valid for any of the 2-argument overloads of URL.createObjectURL.",
"overload resolution failure" ],