summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/ShadowRealm/prototype/importValue/throws-if-import-value-does-not-exist.js
blob: 314c20680889b1e3b0e0a7d53b92159d0739d241 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// |reftest| shell-option(--enable-shadow-realms) skip-if(!xulRuntime.shell) module async -- requires shell-options
// Copyright (C) 2021 Rick Waldron. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-realmimportvalue
description: >
  ShadowRealm.prototype.importValue rejects when export name does not exist
info: |
  RealmImportValue ( specifierString, exportNameString, callerRealm, evalRealm, evalContext )

    Assert: Type(specifierString) is String.
    Assert: Type(exportNameString) is String.
    Assert: callerRealm is a ShadowRealm Record.
    Assert: evalRealm is a ShadowRealm Record.
    Assert: evalContext is an execution context associated to a ShadowRealm instance's [[ExecutionContext]].
    Let innerCapability be ! NewPromiseCapability(%Promise%).
    Let runningContext be the running execution context.
    If runningContext is not already suspended, suspend runningContext.
    Push evalContext onto the execution context stack; evalContext is now the running execution context.
    Perform ! HostImportModuleDynamically(null, specifierString, innerCapability).
    Suspend evalContext and remove it from the execution context stack.
    Resume the context that is now on the top of the execution context stack as the running
    execution context.
    Let steps be the steps of an ExportGetter function as described below.

  An ExportGetter function is an anonymous built-in function with a [[ExportNameString]]
  internal slot. When an ExportGetter function is called with argument exports,
  it performs the following steps:

    Assert: exports is a module namespace exotic object.
    Let f be the active function object.
    Let string be f.[[ExportNameString]].
    Assert: Type(string) is String.
    Let hasOwn be ? HasOwnProperty(exports, string).
    If hasOwn is false, throw a TypeError exception.
    ...

flags: [async, module]
features: [ShadowRealm]
---*/

assert.sameValue(
  typeof ShadowRealm.prototype.importValue,
  'function',
  'This test must fail if ShadowRealm.prototype.importValue is not a function'
);

const r = new ShadowRealm();

r.importValue('./import-value_FIXTURE.js', 'y')
  .then(
    () => {
      throw new Test262Error("Expected rejection");
    },
    err => {
      assert.sameValue(Object.getPrototypeOf(err), TypeError.prototype, 'should be rejected with TypeError');
    }
  )
  .then($DONE, $DONE);