tor-browser

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

privatefieldput-primitive-receiver.js (1750B)


      1 // Copyright (C) 2020 Caio Lima (Igalia S.L). All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 description: PrivateField calls ToObject when receiver is a primitive
      6 esid: sec-putvalue
      7 info: |
      8  PutValue ( V, W )
      9    ...
     10    6. If IsPropertyReference(V), then
     11      a. If HasPrimitiveBase(V), then
     12        i. Assert: In this case, base will never be null or undefined.
     13        ii. Let base be ToObject(base).
     14      b. If IsPrivateReference(V), then
     15        i. Return ? PrivateFieldSet(field, base, W).
     16    ...
     17 
     18  PrivateFieldSet (P, O, value )
     19    1. Assert: P is a Private Name.
     20    2. Assert: Type(O) is Object.
     21    3. Let entry be PrivateFieldFind(P, O).
     22    4. If entry is empty, throw a TypeError exception.
     23    5. Set entry.[[PrivateFieldValue]] to value.
     24 
     25 features: [class, class-fields-private, BigInt]
     26 ---*/
     27 
     28 let count = 0;
     29 
     30 class C {
     31  #p = 1;
     32 
     33  method(v) {
     34    count++;
     35    try {
     36      count++;
     37      this.#p = v;
     38    } catch (e) {
     39      count++;
     40      if (e instanceof TypeError) {
     41        throw new Test262Error();
     42      }
     43    }
     44  }
     45 }
     46 
     47 assert.throws(Test262Error, () => {
     48  new C().method.call(15, 0);
     49 });
     50 assert.sameValue(count, 3);
     51 
     52 assert.throws(Test262Error, () => {
     53  new C().method.call('Test262', 0);
     54 });
     55 assert.sameValue(count, 6);
     56 
     57 assert.throws(Test262Error, () => {
     58  new C().method.call(Symbol('Test262'), 0);
     59 });
     60 assert.sameValue(count, 9);
     61 
     62 assert.throws(Test262Error, () => {
     63  new C().method.call(15n, 0);
     64 });
     65 assert.sameValue(count, 12);
     66 
     67 assert.throws(Test262Error, () => {
     68  new C().method.call(null, 0);
     69 });
     70 assert.sameValue(count, 15);
     71 
     72 assert.throws(Test262Error, () => {
     73  new C().method.call(undefined, 0);
     74 });
     75 assert.sameValue(count, 18);
     76 
     77 
     78 reportCompare(0, 0);