Debian Codegraph @

js/src/tests/test262/built-ins/Date/value-symbol-to-prim-return-obj.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 an Object
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 d. Throw a TypeError exception.
26 features: [Symbol.toPrimitive]
27 ---*/
28
29 var y = {};
30 var retVal;
31
32 y[Symbol.toPrimitive] = function() {
33 return retVal;
34 };
35
36 retVal = {};
37 assert.throws(TypeError, function() {
38 new Date(y);
39 }, 'ordinary object');
40
41 retVal = (function() {
42 return arguments;
43 }());
44 assert.throws(TypeError, function() {
45 new Date(y);
46 }, 'arguments exotic object');
47
48 reportCompare(0, 0);