| 1 |
// Copyright (C) 2016 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
/*--- |
| 4 |
esid: sec-date-value |
| 5 |
es6id: 20.3.2.2 |
| 6 |
description: Exotic `Symbol.toPrimitive` method returns a String value |
| 7 |
info: | |
| 8 |
3. If NewTarget is not undefined, then |
| 9 |
a. If Type(value) is Object and value has a [[DateValue]] internal slot, then |
| 10 |
i. Let tv be thisTimeValue(value). |
| 11 |
b. Else, |
| 12 |
i. Let v be ? ToPrimitive(value). |
| 13 |
ii. If Type(v) is String, then |
| 14 |
1. Let tv be the result of parsing v as a date, in exactly the same |
| 15 |
manner as for the parse method (20.3.3.2). If the parse resulted |
| 16 |
in an abrupt completion, tv is the Completion Record. |
| 17 |
|
| 18 |
ToPrimitive ( input [ , PreferredType ] ) |
| 19 |
|
| 20 |
1. If PreferredType was not passed, let hint be "default". |
| 21 |
2. Else if PreferredType is hint String, let hint be "string". |
| 22 |
3. Else PreferredType is hint Number, let hint be "number". |
| 23 |
4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). |
| 24 |
5. If exoticToPrim is not undefined, then |
| 25 |
a. Let result be ? Call(exoticToPrim, input, « hint »). |
| 26 |
b. If Type(result) is not Object, return result. |
| 27 |
features: [Symbol.toPrimitive] |
| 28 |
---*/ |
| 29 |
|
| 30 |
var stringToPrimitive = {}; |
| 31 |
stringToPrimitive[Symbol.toPrimitive] = function() { |
| 32 |
return '2016-06-05T18:40:00.000Z'; |
| 33 |
}; |
| 34 |
|
| 35 |
assert.sameValue(new Date(stringToPrimitive).getTime(), 1465152000000); |