This PR adds support for import() dynamic module import sematic.
Per https://github.com/tc39/proposal-dynamic-import:
"A call to import(specifier) returns a promise for the module namespace object of the requested module, which is created after fetching, instantiating, and evaluating all of the module's dependencies, as well as the module itself.
"Here specifier will be interpreted the same way as in an import declaration (i.e., the same strings will work in both places). However, while specifier is a string it is not necessarily a string literal; thus code like import(`./language-packs/${navigator.language}.js`) will work—something impossible to accomplish with the usual import declarations.
"import() is proposed to work in both scripts and modules. This gives script code an easy asynchronous entry point into the module world, allowing it to start running module code."
This PR includes following changes:
- Update parser and bytecode generator to support import() sematic in module and in script
- Add new bytecode 'ImportCall'
- Add runtime function for import() that:
○ Uses caller from stack to look up module record or source context that are associated with the module or script from which 'import()' is called
○ Requests host to load target module source file (gets module record in return)
○ Creates promise unless the module record has one
○ Resolves/rejects promise if appropriates
○ Returns promise
- Add new host callback ('FetchImportedModuleFromScript') for fetching imported module from script (accepts source context)
- Add 'promiseCapability' field to module record class
- Update SourceTextModuleRecord's methods to accept callback from host and to handle dynamically imported module and its promise capability
- Update exception checks and assertions to cover new usage scenario of importing and evaluating module code with active script
Add unit tests for dynamic import functionality