tor-browser

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

custom-primitive.js (1466B)


      1 // |reftest| async
      2 // Copyright (C) 2018 Leo Balter. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 /*---
      5 description: >
      6    Import a custom toString and valueOf bindings
      7 esid: sec-finishdynamicimport
      8 info: |
      9    Runtime Semantics: FinishDynamicImport ( referencingScriptOrModule, specifier, promiseCapability, completion )
     10 
     11    2. Otherwise,
     12        a. Assert: completion is a normal completion and completion.[[Value]] is undefined.
     13        b. Let moduleRecord be ! HostResolveImportedModule(referencingScriptOrModule, specifier).
     14        c. Assert: Evaluate has already been invoked on moduleRecord and successfully completed.
     15        d. Let namespace be GetModuleNamespace(moduleRecord).
     16        ...
     17        f. Otherwise, perform ! Call(promiseCapability.[[Resolve]], undefined, « namespace.[[Value]] »).
     18 flags: [async]
     19 features: [dynamic-import]
     20 includes: [asyncHelpers.js]
     21 ---*/
     22 
     23 async function fn() {
     24    const str = await import('./custom-tostring_FIXTURE.js');
     25    const value = await import('./custom-valueof_FIXTURE.js');
     26 
     27    assert.sameValue(String(str), '1612', 'namespace uses the imported toString');
     28    assert.sameValue(Number(str), 1612, 'namespace fallsback to toString as its prototype is null');
     29 
     30    assert.sameValue(Number(value), 42, 'namespace uses the imported valueOf');
     31    assert.sameValue(String(value), '42', 'namespace fallsback to valueOf as its prototype is null');
     32 }
     33 
     34 asyncTest(fn);