tor-browser

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

short-circuit-compound-assignment-scope-lookup.js (7231B)


      1 // SKIP test262 export
      2 // Pending review.
      3 
      4 // Test scope lookups are executed in the correct order.
      5 
      6 function createScope() {
      7  let log = [];
      8  let environment = {};
      9  let scope = new Proxy(environment, new Proxy({
     10    has(target, property) {
     11      log.push({target, property});
     12      return Reflect.has(target, property);
     13    },
     14    get(target, property, receiver) {
     15      log.push({target, property, receiver});
     16      return Reflect.get(target, property, receiver);
     17    },
     18    set(target, property, value, receiver) {
     19      log.push({target, property, value, receiver});
     20      return Reflect.set(target, property, value, receiver);
     21    },
     22    getOwnPropertyDescriptor(target, property) {
     23      log.push({target, property});
     24      return Reflect.getOwnPropertyDescriptor(target, property);
     25    },
     26    defineProperty(target, property, descriptor) {
     27      log.push({target, property, descriptor});
     28      return Reflect.defineProperty(target, property, descriptor);
     29    },
     30  }, {
     31    get(target, property, receiver) {
     32      log.push(property);
     33      return Reflect.get(target, property, receiver);
     34    }
     35  }));
     36 
     37  return {log, environment, scope};
     38 }
     39 
     40 // AndAssignExpr
     41 {
     42  let {log, environment, scope} = createScope();
     43 
     44  environment.a = true;
     45 
     46  with (scope) {
     47    a &&= false;
     48  }
     49  assertEq(environment.a, false);
     50 
     51  with (scope) {
     52    a &&= true;
     53  }
     54  assertEq(environment.a, false);
     55 
     56  assertDeepEq(log.slice(), [
     57    // Execution Contexts, 8.3.2 ResolveBinding ( name [ , env ] )
     58    // Lexical Environments, 8.1.2.1 GetIdentifierReference ( lex, name, strict )
     59    // Object Environment Records, 8.1.1.2.1 HasBinding ( N )
     60    "has", {target: environment, property: "a"},
     61    "get", {target: environment, property: Symbol.unscopables, receiver: scope},
     62 
     63    // Reference Type, 6.2.4.8 GetValue ( V )
     64    // Object Environment Records, 8.1.1.2.6 GetBindingValue ( N, S )
     65    "has", {target: environment, property: "a"},
     66    "get", {target: environment, property: "a", receiver: scope},
     67 
     68    // Reference Type, 6.2.4.9 PutValue ( V, W )
     69    // Object Environment Records, 8.1.1.2.5 SetMutableBinding ( N, V, S )
     70    "set", {target: environment, property: "a", value: false, receiver: scope},
     71 
     72    // Ordinary Objects, 9.1.9 [[Set]] ( P, V, Receiver )
     73    // Ordinary Objects, 9.1.9.1 OrdinarySet ( O, P, V, Receiver )
     74    // Ordinary Objects, 9.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
     75    "getOwnPropertyDescriptor", {target: environment, property: "a"},
     76    "defineProperty", {target: environment, property: "a", descriptor: {value: false}},
     77 
     78    // Execution Contexts, 8.3.2 ResolveBinding ( name [ , env ] )
     79    // Lexical Environments, 8.1.2.1 GetIdentifierReference ( lex, name, strict )
     80    // Object Environment Records, 8.1.1.2.1 HasBinding ( N )
     81    "has", {target: environment, property: "a"},
     82    "get", {target: environment, property: Symbol.unscopables, receiver: scope},
     83 
     84    // Reference Type, 6.2.4.8 GetValue ( V )
     85    // Object Environment Records, 8.1.1.2.6 GetBindingValue ( N, S )
     86    "has", {target: environment, property: "a"},
     87    "get", {target: environment, property: "a", receiver: scope},
     88  ]);
     89 }
     90 
     91 // OrAssignExpr
     92 {
     93  let {log, environment, scope} = createScope();
     94 
     95  environment.a = false;
     96 
     97  with (scope) {
     98    a ||= true;
     99  }
    100  assertEq(environment.a, true);
    101 
    102  with (scope) {
    103    a ||= false;
    104  }
    105  assertEq(environment.a, true);
    106 
    107  assertDeepEq(log.slice(), [
    108    // Execution Contexts, 8.3.2 ResolveBinding ( name [ , env ] )
    109    // Lexical Environments, 8.1.2.1 GetIdentifierReference ( lex, name, strict )
    110    // Object Environment Records, 8.1.1.2.1 HasBinding ( N )
    111    "has", {target: environment, property: "a"},
    112    "get", {target: environment, property: Symbol.unscopables, receiver: scope},
    113 
    114    // Reference Type, 6.2.4.8 GetValue ( V )
    115    // Object Environment Records, 8.1.1.2.6 GetBindingValue ( N, S )
    116    "has", {target: environment, property: "a"},
    117    "get", {target: environment, property: "a", receiver: scope},
    118 
    119    // Reference Type, 6.2.4.9 PutValue ( V, W )
    120    // Object Environment Records, 8.1.1.2.5 SetMutableBinding ( N, V, S )
    121    "set", {target: environment, property: "a", value: true, receiver: scope},
    122 
    123    // Ordinary Objects, 9.1.9 [[Set]] ( P, V, Receiver )
    124    // Ordinary Objects, 9.1.9.1 OrdinarySet ( O, P, V, Receiver )
    125    // Ordinary Objects, 9.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
    126    "getOwnPropertyDescriptor", {target: environment, property: "a"},
    127    "defineProperty", {target: environment, property: "a", descriptor: {value: true}},
    128 
    129    // Execution Contexts, 8.3.2 ResolveBinding ( name [ , env ] )
    130    // Lexical Environments, 8.1.2.1 GetIdentifierReference ( lex, name, strict )
    131    // Object Environment Records, 8.1.1.2.1 HasBinding ( N )
    132    "has", {target: environment, property: "a"},
    133    "get", {target: environment, property: Symbol.unscopables, receiver: scope},
    134 
    135    // Reference Type, 6.2.4.8 GetValue ( V )
    136    // Object Environment Records, 8.1.1.2.6 GetBindingValue ( N, S )
    137    "has", {target: environment, property: "a"},
    138    "get", {target: environment, property: "a", receiver: scope},
    139  ]);
    140 }
    141 
    142 // CoalesceAssignExpr
    143 {
    144  let {log, environment, scope} = createScope();
    145 
    146  environment.a = null;
    147 
    148  with (scope) {
    149    a ??= true;
    150  }
    151  assertEq(environment.a, true);
    152 
    153  with (scope) {
    154    a ??= false;
    155  }
    156  assertEq(environment.a, true);
    157 
    158  assertDeepEq(log.slice(), [
    159    // Execution Contexts, 8.3.2 ResolveBinding ( name [ , env ] )
    160    // Lexical Environments, 8.1.2.1 GetIdentifierReference ( lex, name, strict )
    161    // Object Environment Records, 8.1.1.2.1 HasBinding ( N )
    162    "has", {target: environment, property: "a"},
    163    "get", {target: environment, property: Symbol.unscopables, receiver: scope},
    164 
    165    // Reference Type, 6.2.4.8 GetValue ( V )
    166    // Object Environment Records, 8.1.1.2.6 GetBindingValue ( N, S )
    167    "has", {target: environment, property: "a"},
    168    "get", {target: environment, property: "a", receiver: scope},
    169 
    170    // Reference Type, 6.2.4.9 PutValue ( V, W )
    171    // Object Environment Records, 8.1.1.2.5 SetMutableBinding ( N, V, S )
    172    "set", {target: environment, property: "a", value: true, receiver: scope},
    173 
    174    // Ordinary Objects, 9.1.9 [[Set]] ( P, V, Receiver )
    175    // Ordinary Objects, 9.1.9.1 OrdinarySet ( O, P, V, Receiver )
    176    // Ordinary Objects, 9.1.9.2 OrdinarySetWithOwnDescriptor ( O, P, V, Receiver, ownDesc )
    177    "getOwnPropertyDescriptor", {target: environment, property: "a"},
    178    "defineProperty", {target: environment, property: "a", descriptor: {value: true}},
    179 
    180    // Execution Contexts, 8.3.2 ResolveBinding ( name [ , env ] )
    181    // Lexical Environments, 8.1.2.1 GetIdentifierReference ( lex, name, strict )
    182    // Object Environment Records, 8.1.1.2.1 HasBinding ( N )
    183    "has", {target: environment, property: "a"},
    184    "get", {target: environment, property: Symbol.unscopables, receiver: scope},
    185 
    186    // Reference Type, 6.2.4.8 GetValue ( V )
    187    // Object Environment Records, 8.1.1.2.6 GetBindingValue ( N, S )
    188    "has", {target: environment, property: "a"},
    189    "get", {target: environment, property: "a", receiver: scope},
    190  ]);
    191 }
    192 
    193 if (typeof reportCompare === "function")
    194  reportCompare(0, 0);