tor-browser

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

short-circuit-number-object.js (2224B)


      1 // Copyright (C) 2019 Leo Balter. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: >
      6    Short circuit if the CoalesceExpressionHead is not undefined or null (object)
      7 esid: sec-conditional-operator
      8 info: |
      9    ConditionalExpression :
     10        ShortCircuitExpression
     11        ShortCircuitExpression ? AssignmentExpression : AssignmentExpression
     12 
     13    ShortCircuitExpression :
     14        LogicalORExpression
     15        CoalesceExpression
     16 
     17    CoalesceExpression :
     18        CoalesceExpressionHead ?? BitwiseORExpression
     19 
     20    CoalesceExpressionHead :
     21        CoalesceExpression
     22        BitwiseORExpression
     23 
     24    Runtime Semantics: Evaluation
     25 
     26    CoalesceExpression:CoalesceExpressionHead??BitwiseORExpression
     27 
     28    1. Let lref be the result of evaluating CoalesceExpressionHead.
     29    2. Let lval be ? GetValue(lref).
     30    3. If lval is undefined or null,
     31        a. Let rref be the result of evaluating BitwiseORExpression.
     32        b. Return ? GetValue(rref).
     33    4. Otherwise, return lval.
     34 features: [coalesce-expression]
     35 ---*/
     36 
     37 var x;
     38 var obj = {
     39    toString() {
     40        return null;
     41    },
     42    valueOf() {
     43        return null;
     44    }
     45 };
     46 
     47 x = undefined;
     48 x = obj ?? 1;
     49 assert.sameValue(x, obj, 'obj ?? 1');
     50 
     51 x = undefined;
     52 x = obj ?? null;
     53 assert.sameValue(x, obj, 'obj ?? null');
     54 
     55 x = undefined;
     56 x = obj ?? undefined;
     57 assert.sameValue(x, obj, 'obj ?? undefined');
     58 
     59 x = undefined;
     60 x = obj ?? null ?? undefined;
     61 assert.sameValue(x, obj, 'obj ?? null ?? undefined');
     62 
     63 x = undefined;
     64 x = obj ?? undefined ?? null;
     65 assert.sameValue(x, obj, 'obj ?? undefined ?? null');
     66 
     67 x = undefined;
     68 x = obj ?? null ?? null;
     69 assert.sameValue(x, obj, 'obj ?? null ?? null');
     70 
     71 x = undefined;
     72 x = obj ?? undefined ?? undefined;
     73 assert.sameValue(x, obj, 'obj ?? null ?? null');
     74 
     75 x = undefined;
     76 x = null ?? obj ?? null;
     77 assert.sameValue(x, obj, 'null ?? obj ?? null');
     78 
     79 x = undefined;
     80 x = null ?? obj ?? undefined;
     81 assert.sameValue(x, obj, 'null ?? obj ?? undefined');
     82 
     83 x = undefined;
     84 x = undefined ?? obj ?? null;
     85 assert.sameValue(x, obj, 'undefined ?? obj ?? null');
     86 
     87 x = undefined;
     88 x = undefined ?? obj ?? undefined;
     89 assert.sameValue(x, obj, 'undefined ?? obj ?? undefined');
     90 
     91 reportCompare(0, 0);