зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1020460 - Array.prototype.toSource should be generic. r=jorendorff
This commit is contained in:
Родитель
699946fc90
Коммит
23cb593656
|
@ -0,0 +1,8 @@
|
|||
load(libdir + 'asserts.js');
|
||||
|
||||
assertEq(Array.prototype.toSource.call([1, 'hi']), '[1, "hi"]');
|
||||
assertEq(Array.prototype.toSource.call({1: 10, 0: 42, length: 2}), "[42, 10]");
|
||||
assertEq(Array.prototype.toSource.call({1: 10, 0: 42, length: 1}), "[42]");
|
||||
assertThrowsInstanceOf(() => Array.prototype.toSource.call("someString"), TypeError);
|
||||
assertThrowsInstanceOf(() => Array.prototype.toSource.call(42), TypeError);
|
||||
assertThrowsInstanceOf(() => Array.prototype.toSource.call(undefined), TypeError);
|
|
@ -56,7 +56,6 @@ function test(str, f) {
|
|||
assertEq(threw, true);
|
||||
}
|
||||
|
||||
test("new Array(1,2,3)", function(a) Array.prototype.toSource.call(a));
|
||||
test("new Boolean(true)", function(b) Boolean.prototype.toSource.call(b));
|
||||
test("new Boolean(true)", function(b) Boolean.prototype.toString.call(b));
|
||||
test("new Boolean(true)", function(b) Boolean.prototype.valueOf.call(b));
|
||||
|
|
|
@ -860,16 +860,17 @@ AddLengthProperty(ExclusiveContext *cx, HandleObject obj)
|
|||
}
|
||||
|
||||
#if JS_HAS_TOSOURCE
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
IsArray(HandleValue v)
|
||||
{
|
||||
return v.isObject() && v.toObject().is<ArrayObject>();
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
array_toSource_impl(JSContext *cx, CallArgs args)
|
||||
static bool
|
||||
array_toSource(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
JS_ASSERT(IsArray(args.thisv()));
|
||||
JS_CHECK_RECURSION(cx, return false);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
|
||||
if (!args.thisv().isObject()) {
|
||||
ReportIncompatible(cx, args);
|
||||
return false;
|
||||
}
|
||||
|
||||
Rooted<JSObject*> obj(cx, &args.thisv().toObject());
|
||||
RootedValue elt(cx);
|
||||
|
@ -935,13 +936,6 @@ array_toSource_impl(JSContext *cx, CallArgs args)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
array_toSource(JSContext *cx, unsigned argc, Value *vp)
|
||||
{
|
||||
JS_CHECK_RECURSION(cx, return false);
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
return CallNonGenericMethod<IsArray, array_toSource_impl>(cx, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct EmptySeparatorOp
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
var BUGNUMBER = 387501;
|
||||
var summary =
|
||||
'Array.prototype.toString|toLocaleString are generic, ' +
|
||||
'Array.prototype.toSource is not generic';
|
||||
'Array.prototype.toString|toLocaleString|toSource are generic';
|
||||
var actual = '';
|
||||
var expect = '';
|
||||
|
||||
|
@ -30,11 +29,13 @@ function test()
|
|||
actual = Array.prototype.toLocaleString.call((new String('foo')));
|
||||
assertEq(actual, expect, summary);
|
||||
|
||||
assertEq('["f", "o", "o"]', Array.prototype.toSource.call(new String('foo')));
|
||||
|
||||
if (typeof Array.prototype.toSource != 'undefined')
|
||||
{
|
||||
try
|
||||
{
|
||||
Array.prototype.toSource.call(new String('foo'));
|
||||
Array.prototype.toSource.call('foo');
|
||||
throw new Error("didn't throw");
|
||||
}
|
||||
catch(ex)
|
||||
|
|
|
@ -18,17 +18,7 @@ var y =
|
|||
configurable: true
|
||||
});
|
||||
f.__proto__ = [];
|
||||
|
||||
try
|
||||
{
|
||||
uneval(y);
|
||||
throw new Error("didn't throw");
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
assertEq(ex instanceof TypeError, true,
|
||||
"wrong exception thrown: expected TypeError, got " + ex);
|
||||
}
|
||||
uneval(y);
|
||||
|
||||
if (typeof reportCompare === "function")
|
||||
reportCompare(true, true);
|
||||
|
|
Загрузка…
Ссылка в новой задаче