value-symbol-to-prim-invocation.js (1356B)
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: Invocation of `Symbol.toPrimitive` method 6 info: | 7 [...] 8 3. If NewTarget is not undefined, then 9 a. If Type(value) is Object and value has a [[DateValue]] internal slot, 10 then 11 [...] 12 b. Else, 13 i. Let v be ? ToPrimitive(value). 14 [...] 15 16 ES6 Section 7.1.1 ToPrimitive ( input [, PreferredType] ) 17 18 1. If PreferredType was not passed, let hint be "default". 19 [...] 20 4. Let exoticToPrim be GetMethod(input, @@toPrimitive). 21 5. ReturnIfAbrupt(exoticToPrim). 22 6. If exoticToPrim is not undefined, then 23 a. Let result be Call(exoticToPrim, input, «hint»). 24 [...] 25 features: [Symbol.toPrimitive] 26 ---*/ 27 28 var y = {}; 29 var callCount = 0; 30 var thisVal, args; 31 32 y[Symbol.toPrimitive] = function() { 33 callCount += 1; 34 thisVal = this; 35 args = arguments; 36 }; 37 38 new Date(y); 39 40 assert.sameValue(callCount, 1, 'method invoked exactly once'); 41 assert.sameValue(thisVal, y, '`this` value is the object being compared'); 42 assert.sameValue(args.length, 1, 'method invoked with exactly one argument'); 43 assert.sameValue( 44 args[0], 45 'default', 46 'method invoked with the string "default" as the first argument' 47 ); 48 49 reportCompare(0, 0);