tor-browser

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

name.js (2190B)


      1 // |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) -- requires shell-options
      2 // Copyright (C) 2022 Chengzhong Wu. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 esid: sec-wrappedfunctioncreate
      6 description: >
      7  The value of WrappedFunction.name is copied from the target function
      8 info: |
      9  WrappedFunctionCreate ( callerRealm: a Realm Record, Target: a function object, )
     10 
     11  ...
     12  7. Let result be CopyNameAndLength(wrapped, Target).
     13  ...
     14 
     15  CopyNameAndLength ( F: a function object, Target: a function object, prefix: a String, optional argCount: a Number, )
     16 
     17  ...
     18  6. Let targetName be ? Get(Target, "name").
     19  7. If Type(targetName) is not String, set targetName to the empty String.
     20  8. Perform ! SetFunctionName(F, targetName, prefix).
     21 
     22  SetFunctionName ( F, name [ , prefix ] )
     23 
     24  ...
     25  6. Return ! DefinePropertyOrThrow(F, "name", PropertyDescriptor { [[Value]]: name, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }).
     26 
     27 includes: [propertyHelper.js]
     28 features: [ShadowRealm]
     29 ---*/
     30 
     31 assert.sameValue(
     32  typeof ShadowRealm.prototype.evaluate,
     33  'function',
     34  'This test must fail if ShadowRealm.prototype.evaluate is not a function'
     35 );
     36 
     37 const r = new ShadowRealm();
     38 
     39 let wrapped = r.evaluate(`
     40 function fn() {}
     41 fn;
     42 `);
     43 verifyProperty(wrapped, "name", {
     44  value: "fn",
     45  enumerable: false,
     46  writable: false,
     47  configurable: true,
     48 });
     49 
     50 // The name property is an accessor.
     51 wrapped = r.evaluate(`
     52 function fn() {}
     53 Object.defineProperty(fn, 'name', {
     54  get: () => "bar",
     55  enumerable: false,
     56  configurable: true,
     57 });
     58 fn;
     59 `);
     60 verifyProperty(wrapped, "name", {
     61  value: "bar",
     62  enumerable: false,
     63  writable: false,
     64  configurable: true,
     65 });
     66 
     67 // The value of fn.name is not a string.
     68 for (const name of [null, undefined, 0, '1n', false, NaN, Infinity, 'Symbol()', '[]', '{}']) {
     69  wrapped = r.evaluate(`
     70 function fn() {}
     71 Object.defineProperty(fn, 'name', {
     72  value: ${String(name)},
     73  enumerable: false,
     74  configurable: true,
     75 });
     76 fn;
     77 `);
     78  verifyProperty(wrapped, "name", {
     79    value: "",
     80    enumerable: false,
     81    writable: false,
     82    configurable: true,
     83  });
     84 }
     85 
     86 reportCompare(0, 0);