Stage 2 Draft / August 31, 2022

JavaScript Module Blocks

This document is a diff on top of the Modules Host Hooks Refactor.

1

2

3

4

5

6

7

8

9

10

11

12

13 ECMAScript Language: Expressions

13.1

13.2 Primary Expression

Syntax

PrimaryExpression[Yield, Await] : this IdentifierReference[?Yield, ?Await] Literal ArrayLiteral[?Yield, ?Await] ObjectLiteral[?Yield, ?Await] FunctionExpression ClassExpression[?Yield, ?Await] GeneratorExpression AsyncFunctionExpression AsyncGeneratorExpression ModuleBlockExpression RegularExpressionLiteral TemplateLiteral[?Yield, ?Await, ~Tagged] CoverParenthesizedExpressionAndArrowParameterList[?Yield, ?Await]

13.2.1

13.2.2

13.2.3

13.2.4

13.2.5

13.2.6

13.2.7

13.2.8

13.2.9

13.2.10 Module Block Expression

Syntax

ModuleBlockExpression : module [no LineTerminator here] { ModuleBodyopt }

13.2.10.1 Runtime Semantics: Evaluation

ModuleBlockExpression : module { ModuleBody }
  1. Let moduleBlock be OrdinaryObjectCreate(%ModuleBlock.prototype%, « [[ModuleRecord]], [[SourceText]] »).
  2. Let body be the source text matched by ModuleBody.
  3. Let realm be the current Realm Record.
  4. Let currentScriptOrModule be GetActiveScriptOrModule().
  5. If currentScriptOrModule is null, let hostDefined be null.
  6. Else, let hostDefined be currentScriptOrModule.[[HostDefined]].
  7. Let moduleRecord be ParseModule(body, realm, hostDefined).
  8. Assert: moduleRecord is a Module Record, because parse errors would have been reported when parsing the outer script or module.
  9. Set moduleBlock.[[ModuleRecord]] to moduleRecord.
  10. Set moduleBlock.[[SourceText]] to the source text matched by ModuleBlockExpression.
  11. Return moduleBlock.

13.3 Left-Hand-Side Expressions

13.3.1

13.3.2

13.3.3

13.3.4

13.3.5

13.3.6

13.3.7

13.3.8

13.3.9

13.3.10 Import Calls

13.3.10.1 Runtime Semantics: Evaluation

ImportCall : import ( AssignmentExpression )
  1. Let referencingScriptOrModule be GetActiveScriptOrModule().
  2. Let argRef be the result of evaluating AssignmentExpression.
  3. Let specifier be ? GetValue(argRef).
  4. Let promiseCapability be ! NewPromiseCapability(%Promise%).
  5. Let state be a new Record { [[Action]]: dynamic-import, [[PromiseCapability]]: promiseCapability }.
  6. If Type(specifier) is Object and specifier has a [[ModuleRecord]] internal slot, then
    1. If specifier.[[ModuleRecord]].[[Realm]] is not the current Realm Record, then
      1. Perform ! Call(promiseCapability.[[Reject]], undefined, « a newly created TypeError object »).
    2. Else,
      1. Perform ContinueDynamicImport(state, specifier.[[ModuleRecord]]).
  7. Else,
    1. Let specifierString be Completion(ToString(specifier)).
    2. IfAbruptRejectPromise(specifierString, promiseCapability).
    3. If referencingScriptOrModule is not null and there exists a Record record in referencingScriptOrModule.[[LoadedModules]] such that record.[[Specifier]] is specifierString, then
      1. Perform ContinueDynamicImport(state, record.[[Module]]).
    4. Else,
      1. Perform HostLoadImportedModule(referencingScriptOrModule, specifierString, state.[[HostDefined]], state).
  8. Return promiseCapability.[[Promise]].

14

15

16

17

18

19

20

21 Fundamental Objects

21.1

21.2

21.3

21.4

21.5

21.6 ModuleBlock Objects

21.6.1 The ModuleBlock Constructor

The ModuleBlock constructor:

  • is %ModuleBlock%.
  • is the initial value of the "ModuleBlock" property of the global object.
  • is not intended to be called as a function and will throw an exception when called in that manner.
  • is not intended to be used with the new operator or to be subclassed. It may be used as the value of an extends clause of a class definition but a super call to the ModuleBlock constructor will cause an exception.

21.6.1.1 ModuleBlock ( body )

  1. Throw a TypeError exception.

21.6.1.2 ModuleBlock.prototype

The initial value of ModuleBlock.prototype is the ModuleBlock prototype object.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

21.6.2 Properties of the ModuleBlock Prototype Object

The ModuleBlock prototype object:

21.6.2.1 ModuleBlock.prototype.toString ( )

The following steps are taken:

  1. Let module be the this value.
  2. If Type(module) is Object and has the internal slot [[ModuleRecord]], then
    1. Return module.[[SourceText]].
  3. Throw a TypeError exception.

A Copyright & Software License

Copyright Notice

© 2022 Surma, Dan Ehrenberg, Nicolò Ribaudo

Software License

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.