tor-browser

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

desc-to-string.js (1859B)


      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-symbol-constructor
      5 description: The first argument is coerced to a String value (from an object)
      6 info: |
      7    1. If NewTarget is not undefined, throw a TypeError exception.
      8    2. If description is undefined, let descString be undefined.
      9    2. Else, let descString be ? ToString(description).
     10    3. Return a new unique Symbol value whose [[Description]] value is
     11       descString.
     12 features: [Symbol]
     13 ---*/
     14 
     15 var calls, val;
     16 
     17 val = {
     18  toString: function() {
     19    calls += 'toString';
     20    return {};
     21  },
     22  valueOf: function() {
     23    calls += 'valueOf';
     24  }
     25 };
     26 
     27 calls = '';
     28 Symbol(val);
     29 assert.sameValue(calls, 'toStringvalueOf');
     30 
     31 val = {
     32  toString: function() {
     33    calls += 'toString';
     34  },
     35  valueOf: function() {
     36    calls += 'valueOf';
     37  }
     38 };
     39 
     40 calls = '';
     41 Symbol(val);
     42 assert.sameValue(calls, 'toString');
     43 
     44 val = {
     45  toString: null,
     46  valueOf: function() {
     47    calls += 'valueOf';
     48  }
     49 };
     50 
     51 calls = '';
     52 Symbol(val);
     53 assert.sameValue(calls, 'valueOf');
     54 
     55 val = {
     56  toString: null,
     57  valueOf: function() {
     58    calls += 'valueOf';
     59    return {};
     60  }
     61 };
     62 
     63 calls = '';
     64 assert.throws(TypeError, function() {
     65  Symbol(val);
     66 }, '`toString` is not callable, and `valueOf` returns a non-primitive value');
     67 assert.sameValue(
     68  calls, 'valueOf', 'invocation pattern for non-callable `toString`'
     69 );
     70 
     71 val = {
     72  toString: function() {
     73    calls += 'toString';
     74    return {};
     75  },
     76  valueOf: function() {
     77    calls += 'valueOf';
     78    return {};
     79  }
     80 };
     81 
     82 calls = '';
     83 assert.throws(TypeError, function() {
     84  Symbol(val);
     85 }, '`toString` nor `valueOf` both return non-primitive values');
     86 assert.sameValue(
     87  calls,
     88  'toStringvalueOf',
     89  'invocation pattern for non-callable `toString` and `valueOf`'
     90 );
     91 
     92 reportCompare(0, 0);