{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/4740","repository_url":"https://api.github.com/repos/Microsoft/ChakraCore","labels_url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/4740/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/4740/comments","events_url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/4740/events","html_url":"https://github.com/Microsoft/ChakraCore/issues/4740","id":299965357,"number":4740,"title":"Suggestion: Internalise Module record map","user":{"login":"rhuanjl","id":30090552,"avatar_url":"https://avatars3.githubusercontent.com/u/30090552?v=4","gravatar_id":"","url":"https://api.github.com/users/rhuanjl","html_url":"https://github.com/rhuanjl","followers_url":"https://api.github.com/users/rhuanjl/followers","following_url":"https://api.github.com/users/rhuanjl/following{/other_user}","gists_url":"https://api.github.com/users/rhuanjl/gists{/gist_id}","starred_url":"https://api.github.com/users/rhuanjl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhuanjl/subscriptions","organizations_url":"https://api.github.com/users/rhuanjl/orgs","repos_url":"https://api.github.com/users/rhuanjl/repos","events_url":"https://api.github.com/users/rhuanjl/events{/privacy}","received_events_url":"https://api.github.com/users/rhuanjl/received_events","type":"User","site_admin":false},"labels":[{"id":307793018,"url":"https://api.github.com/repos/Microsoft/ChakraCore/labels/Suggestion","name":"Suggestion","color":"fad8c7","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-02-24T19:19:14Z","updated_at":"2018-02-28T02:26:02Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Currently for any embedder to implement ESModules with CC they have to create a map (key = normalised specifier, value = module record) of module records which they have to hold.\r\n\r\n**Whenever a module is requested the host must always perform the following steps:**\r\n1. Normalise the specifier\r\n2. Check if a module record with this normalised specifier is in the map \r\n2. If yes return existing module record\r\n3. If no:\r\n    a) Initialise a new module record (providing the normalised specifier as one of the parameters)\r\n    b) Schedule a call to ParseModuleSource for the new record\r\n    c) add the module record to map\r\n    d) return the record\r\n\r\n**Suggestion**\r\nConsidering that the module record map will be functionally identical for all hosts I propose that it should be internalised into ChakraCore.\r\n\r\n**Steps this would entail:**\r\n1. Add a module record map (key = normalised specifier, value = module record) as an internal property of a SourceContext\r\n2. When JsInitializeModuleRecord is called check the internal map for the record - if it exists return it instead of creating a new record\r\n3. When JsParseModuleSource is called do an early return of JsNoError if it's already Parsed rather than JsErrorModuleParsed (optional change as this point could just be documented instead) - point being to allow the host to always schedule a JsParseModuleSource job when asked for a module and not need to check first simply relying on CC to only do it if it's needed\r\n\r\n**Impact**\r\n1. Face of the API would remain the same\r\n2. If used in the current \"correct\" way would still function the same way -i.e. this is not a breaking change\r\n3. This would remove the requirement for boilerplate code from host implementations AND make the API simpler to understand\r\n4. A host would now be able to perform the following simpler steps when a module is requested:\r\n    1. Normalise the specifier\r\n    2. Initialise a module record (no existence check required as CC would now do it)\r\n    3. Schedule a call to JsParseModuleSource for the record (no already-parsed check required as CC can do that)\r\n    4. return the record"},"comment":{"url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/comments/369099309","html_url":"https://github.com/Microsoft/ChakraCore/issues/4740#issuecomment-369099309","issue_url":"https://api.github.com/repos/Microsoft/ChakraCore/issues/4740","id":369099309,"user":{"login":"liminzhu","id":1158954,"avatar_url":"https://avatars3.githubusercontent.com/u/1158954?v=4","gravatar_id":"","url":"https://api.github.com/users/liminzhu","html_url":"https://github.com/liminzhu","followers_url":"https://api.github.com/users/liminzhu/followers","following_url":"https://api.github.com/users/liminzhu/following{/other_user}","gists_url":"https://api.github.com/users/liminzhu/gists{/gist_id}","starred_url":"https://api.github.com/users/liminzhu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liminzhu/subscriptions","organizations_url":"https://api.github.com/users/liminzhu/orgs","repos_url":"https://api.github.com/users/liminzhu/repos","events_url":"https://api.github.com/users/liminzhu/events{/privacy}","received_events_url":"https://api.github.com/users/liminzhu/received_events","type":"User","site_admin":false},"created_at":"2018-02-28T02:26:02Z","updated_at":"2018-02-28T02:26:02Z","author_association":"MEMBER","body":"Normalized specifier is still host business though. VM wants to get a moduleRecord back from [HostResolveImportedModule](https://tc39.github.io/ecma262/#sec-hostresolveimportedmodule), but doesn't really care what the normalized specifier for that is. Host (however weird it may sound) is free to use the same specifier for two different modules or give VMs two moduleRecords of the same module. \r\n\r\nI can be wrong on this, but the normalized specifier Chakra takes from `JsInitializeModuleRecord` might just be a debugging string for us?"}}
{"actor":{"display_login":"liminzhu"}}