tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

coerce-symbol-to-prim-invocation.js (1448B)


      1 // Copyright (C) 2015 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 es6id: 12.10.3
      5 description: Invocation of `Symbol.toPrimitive` method during coercion
      6 info: |
      7    [...]
      8    7. Return the result of performing Abstract Equality Comparison rval ==
      9       lval.
     10 
     11    ES6 Section 7.2.12 Abstract Equality Comparison
     12 
     13    [...]
     14    10. If Type(x) is either String, Number, or Symbol and Type(y) is Object,
     15        then return the result of the comparison x == ToPrimitive(y).
     16 
     17    ES6 Section 7.1.1 ToPrimitive ( input [, PreferredType] )
     18 
     19    1. If PreferredType was not passed, let hint be "default".
     20    [...]
     21    4. Let exoticToPrim be GetMethod(input, @@toPrimitive).
     22    5. ReturnIfAbrupt(exoticToPrim).
     23    6. If exoticToPrim is not undefined, then
     24       a. Let result be Call(exoticToPrim, input, «hint»).
     25       [...]
     26 features: [Symbol.toPrimitive]
     27 ---*/
     28 
     29 var y = {};
     30 var callCount = 0;
     31 var thisVal, args;
     32 
     33 y[Symbol.toPrimitive] = function() {
     34  callCount += 1;
     35  thisVal = this;
     36  args = arguments;
     37 };
     38 
     39 0 == y;
     40 
     41 assert.sameValue(callCount, 1, 'method invoked exactly once');
     42 assert.sameValue(thisVal, y, '`this` value is the object being compared');
     43 assert.sameValue(args.length, 1, 'method invoked with exactly one argument');
     44 assert.sameValue(
     45  args[0],
     46  'default',
     47  'method invoked with the string "default" as the first argument'
     48 );
     49 
     50 reportCompare(0, 0);