зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1381433 - Throw when Date.prototype.toString is called with non-Date object per ES2018 spec draft. r=till, r=bgrins
This commit is contained in:
Родитель
a370f55f9c
Коммит
254fb3bbde
|
@ -73,15 +73,6 @@ var inputTests = [
|
|||
},
|
||||
|
||||
// 7
|
||||
{
|
||||
input: "Date.prototype",
|
||||
output: /Object \{.*\}/,
|
||||
printOutput: "Invalid Date",
|
||||
inspectable: true,
|
||||
variablesViewLabel: "Object",
|
||||
},
|
||||
|
||||
// 8
|
||||
{
|
||||
input: "new Number(43)",
|
||||
output: "Number { 43 }",
|
||||
|
@ -90,7 +81,7 @@ var inputTests = [
|
|||
variablesViewLabel: "Number { 43 }"
|
||||
},
|
||||
|
||||
// 9
|
||||
// 8
|
||||
{
|
||||
input: "new String('hello')",
|
||||
output: /String { "hello", 6 more.* }/,
|
||||
|
@ -99,7 +90,7 @@ var inputTests = [
|
|||
variablesViewLabel: "String"
|
||||
},
|
||||
|
||||
// 10
|
||||
// 9
|
||||
{
|
||||
input: "(function () { var s = new String('hello'); s.whatever = 23; " +
|
||||
" return s;})()",
|
||||
|
@ -109,7 +100,7 @@ var inputTests = [
|
|||
variablesViewLabel: "String"
|
||||
},
|
||||
|
||||
// 11
|
||||
// 10
|
||||
{
|
||||
input: "(function () { var s = new String('hello'); s[8] = 'x'; " +
|
||||
" return s;})()",
|
||||
|
@ -119,7 +110,7 @@ var inputTests = [
|
|||
variablesViewLabel: "String"
|
||||
},
|
||||
|
||||
// 12
|
||||
// 11
|
||||
{
|
||||
// XXX: Can't test fulfilled and rejected promises, because promises get
|
||||
// settled on the next tick of the event loop.
|
||||
|
@ -130,7 +121,7 @@ var inputTests = [
|
|||
variablesViewLabel: "Promise"
|
||||
},
|
||||
|
||||
// 13
|
||||
// 12
|
||||
{
|
||||
input: "(function () { var p = new Promise(function () {}); " +
|
||||
"p.foo = 1; return p; }())",
|
||||
|
@ -140,7 +131,7 @@ var inputTests = [
|
|||
variablesViewLabel: "Promise"
|
||||
},
|
||||
|
||||
// 14
|
||||
// 13
|
||||
{
|
||||
input: "new Object({1: 'this\\nis\\nsupposed\\nto\\nbe\\na\\nvery" +
|
||||
"\\nlong\\nstring\\n,shown\\non\\na\\nsingle\\nline', " +
|
||||
|
@ -152,7 +143,7 @@ var inputTests = [
|
|||
variablesViewLabel: "Object[4]"
|
||||
},
|
||||
|
||||
// 15
|
||||
// 14
|
||||
{
|
||||
input: "new Proxy({a:1},[1,2,3])",
|
||||
output: 'Proxy { <target>: Object, <handler>: Array[3] }',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// |jit-test| error: InternalError
|
||||
// |jit-test| error: TypeError
|
||||
|
||||
var Date_toString = newGlobal().Date.prototype.toString;
|
||||
(function f(){ f(Date_toString.call({})); })();
|
||||
|
|
|
@ -153,7 +153,7 @@ test("new Date()", d => justDontThrow(Date.prototype.toLocaleFormat.call(d)));
|
|||
test("new Date()", d => justDontThrow(Date.prototype.toTimeString.call(d)));
|
||||
test("new Date()", d => justDontThrow(Date.prototype.toDateString.call(d)));
|
||||
test("new Date()", d => justDontThrow(Date.prototype.toSource.call(d)));
|
||||
test("new Date()", d => justDontThrow(Date.prototype.toString.call(d)), true);
|
||||
test("new Date()", d => justDontThrow(Date.prototype.toString.call(d)));
|
||||
test("new Date()", d => justDontThrow(Date.prototype.valueOf.call(d)));
|
||||
|
||||
throw "done";
|
||||
|
|
|
@ -2940,47 +2940,20 @@ date_toSource(JSContext* cx, unsigned argc, Value* vp)
|
|||
}
|
||||
#endif
|
||||
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
IsObject(HandleValue v)
|
||||
{
|
||||
return v.isObject();
|
||||
}
|
||||
|
||||
// ES6 20.3.4.41.
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
date_toString_impl(JSContext* cx, const CallArgs& args)
|
||||
{
|
||||
// Step 1.
|
||||
RootedObject obj(cx, &args.thisv().toObject());
|
||||
|
||||
// Step 2.
|
||||
ESClass cls;
|
||||
if (!GetBuiltinClass(cx, obj, &cls))
|
||||
return false;
|
||||
|
||||
double tv;
|
||||
if (cls != ESClass::Date) {
|
||||
// Step 2.
|
||||
tv = GenericNaN();
|
||||
} else {
|
||||
// Step 3.
|
||||
RootedValue unboxed(cx);
|
||||
if (!Unbox(cx, obj, &unboxed))
|
||||
return false;
|
||||
|
||||
tv = unboxed.toNumber();
|
||||
}
|
||||
|
||||
// Step 4.
|
||||
return FormatDate(cx, tv, FormatSpec::DateTime, args.rval());
|
||||
// Steps 1-2.
|
||||
return FormatDate(cx, args.thisv().toObject().as<DateObject>().UTCTime().toNumber(),
|
||||
FormatSpec::DateTime, args.rval());
|
||||
}
|
||||
|
||||
bool
|
||||
date_toString(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
// Step 1.
|
||||
CallArgs args = CallArgsFromVp(argc, vp);
|
||||
return CallNonGenericMethod<IsObject, date_toString_impl>(cx, args);
|
||||
return CallNonGenericMethod<IsDate, date_toString_impl>(cx, args);
|
||||
}
|
||||
|
||||
MOZ_ALWAYS_INLINE bool
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
var BUGNUMBER = 861219;
|
||||
var summary = 'Date.prototype.toString is a generic function';
|
||||
|
||||
// Revised in ECMA 2018, Date.prototype.toString is no longer generic (bug 1381433).
|
||||
|
||||
print(BUGNUMBER + ": " + summary);
|
||||
|
||||
for (var thisValue of [{}, [], /foo/, Date.prototype, new Proxy(new Date(), {})])
|
||||
assertEq(Date.prototype.toString.call(thisValue), "Invalid Date");
|
||||
assertThrowsInstanceOf(() => Date.prototype.toString.call(thisValue), TypeError);
|
||||
|
||||
for (var prim of [null, undefined, 0, 1.2, true, false, "foo", Symbol.iterator])
|
||||
assertThrowsInstanceOf(() => Date.prototype.toString.call(prim), TypeError);
|
||||
|
|
Загрузка…
Ссылка в новой задаче