| 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 non-primitive |
| 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 |
|
| 14 |
ToPrimitive ( input [ , PreferredType ] ) |
| 15 |
|
| 16 |
1. If PreferredType was not passed, let hint be "default". |
| 17 |
2. Else if PreferredType is hint String, let hint be "string". |
| 18 |
3. Else PreferredType is hint Number, let hint be "number". |
| 19 |
4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). |
| 20 |
5. If exoticToPrim is not undefined, then |
| 21 |
a. Let result be ? Call(exoticToPrim, input, « hint »). |
| 22 |
b. If Type(result) is not Object, return result. |
| 23 |
c. Throw a TypeError exception. |
| 24 |
features: [Symbol.toPrimitive] |
| 25 |
---*/ |
| 26 |
|
| 27 |
var faultyToPrimitive = {}; |
| 28 |
var returnValue; |
| 29 |
faultyToPrimitive[Symbol.toPrimitive] = function() { |
| 30 |
return returnValue; |
| 31 |
}; |
| 32 |
|
| 33 |
returnValue = {}; |
| 34 |
assert.throws(TypeError, function() { |
| 35 |
new Date(faultyToPrimitive); |
| 36 |
}, 'ordinary object'); |
| 37 |
|
| 38 |
returnValue = []; |
| 39 |
assert.throws(TypeError, function() { |
| 40 |
new Date(faultyToPrimitive); |
| 41 |
}, 'Array exotic object'); |
| 42 |
|
| 43 |
returnValue = (function() { |
| 44 |
return arguments; |
| 45 |
}()); |
| 46 |
assert.throws(TypeError, function() { |
| 47 |
new Date(faultyToPrimitive); |
| 48 |
}, 'arguments exotic object'); |