Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Module Import #2913

Merged
merged 1 commit into from
May 9, 2017
Merged

Commits on May 9, 2017

  1. Dynamic Module Import

    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
    Suwei Chen committed May 9, 2017
    Configuration menu
    Copy the full SHA
    2277186 View commit details
    Browse the repository at this point in the history