| 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: Invocation of `Symbol.toPrimitive` method of object 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 |
[...] |
| 14 |
|
| 15 |
|
| 16 |
ToPrimitive ( input [ , PreferredType ] ) |
| 17 |
|
| 18 |
1. If PreferredType was not passed, let hint be "default". |
| 19 |
2. Else if PreferredType is hint String, let hint be "string". |
| 20 |
3. Else PreferredType is hint Number, let hint be "number". |
| 21 |
4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive). |
| 22 |
5. If exoticToPrim is not undefined, then |
| 23 |
a. Let result be ? Call(exoticToPrim, input, « hint »). |
| 24 |
[...] |
| 25 |
features: [Symbol.toPrimitive] |
| 26 |
---*/ |
| 27 |
|
| 28 |
var spyToPrimitive = {}; |
| 29 |
var callCount = 0; |
| 30 |
var thisValue, args; |
| 31 |
spyToPrimitive[Symbol.toPrimitive] = function() { |
| 32 |
thisValue = this; |
| 33 |
args = arguments; |
| 34 |
callCount += 1; |
| 35 |
}; |
| 36 |
|
| 37 |
new Date(spyToPrimitive); |
| 38 |
|
| 39 |
assert.sameValue(callCount, 1, 'function invoked exactly once'); |
| 40 |
assert.sameValue(thisValue, spyToPrimitive, 'function "this" value'); |
| 41 |
assert.sameValue(args.length, 1, 'function invoked with exactly one argument'); |
| 42 |
assert.sameValue(args[0], 'default', 'argument value'); |