Debian Codegraph @

js/src/tests/test262/built-ins/Date/value-symbol-to-prim-return-prim.js

raw
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 description: >
6 Behavior when coercion via `Symbol.toPrimitive` yields a primitive value
7 info: |
8 [...]
9 3. If NewTarget is not undefined, then
10 a. If Type(value) is Object and value has a [[DateValue]] internal slot,
11 then
12 [...]
13 b. Else,
14 i. Let v be ? ToPrimitive(value).
15
16 ES6 Section 7.1.1 ToPrimitive ( input [, PreferredType] )
17
18 [...]
19 4. Let exoticToPrim be GetMethod(input, @@toPrimitive).
20 5. ReturnIfAbrupt(exoticToPrim).
21 6. If exoticToPrim is not undefined, then
22 a. Let result be Call(exoticToPrim, input, «hint»).
23 b. ReturnIfAbrupt(result).
24 c. If Type(result) is not Object, return result.
25 features: [Symbol.toPrimitive]
26 ---*/
27
28 var y = {};
29 var retVal;
30
31 y[Symbol.toPrimitive] = function() {
32 return retVal;
33 };
34
35 retVal = 1234;
36 assert.sameValue(new Date(y).valueOf(), 1234);
37
38 retVal = '2016-06-03T19:03:52.872Z';
39 assert.sameValue(new Date(y).valueOf(), 1464980632872);
40
41 retVal = Symbol.toPrimitive;
42 assert.throws(TypeError, function() {
43 new Date(y);
44 });
45
46 reportCompare(0, 0);