* Retrieves the host-defined option ID based on the provided importModuleDynamically and hint. * @param {VmImportModuleDynamicallyCallback | undefined} importModuleDynamically - * The importModuleDynamically function or undefined. * @param {string} hint - The hint for the option ID. * @returns
(importModuleDynamically, hint)
| 58 | * ID. |
| 59 | */ |
| 60 | function getHostDefinedOptionId(importModuleDynamically, hint) { |
| 61 | if (importModuleDynamically === vm_dynamic_import_main_context_default || |
| 62 | importModuleDynamically === vm_dynamic_import_default_internal) { |
| 63 | return importModuleDynamically; |
| 64 | } |
| 65 | |
| 66 | if (importModuleDynamically !== undefined) { |
| 67 | // Check that it's either undefined or a function before we pass |
| 68 | // it into the native constructor. |
| 69 | validateFunction(importModuleDynamically, |
| 70 | 'options.importModuleDynamically'); |
| 71 | } |
| 72 | if (importModuleDynamically === undefined) { |
| 73 | // We need a default host defined options that are the same for all |
| 74 | // scripts not needing custom module callbacks so that the isolate |
| 75 | // compilation cache can be hit. |
| 76 | return vm_dynamic_import_no_callback; |
| 77 | } |
| 78 | // We should've thrown here immediately when we introduced |
| 79 | // --experimental-vm-modules and importModuleDynamically, but since |
| 80 | // users are already using this callback to throw a similar error, |
| 81 | // we also defer the error to the time when an actual import() is called |
| 82 | // to avoid breaking them. To ensure that the isolate compilation |
| 83 | // cache can still be hit, use a constant sentinel symbol here. |
| 84 | if (!getOptionValue('--experimental-vm-modules')) { |
| 85 | return vm_dynamic_import_missing_flag; |
| 86 | } |
| 87 | |
| 88 | return Symbol(hint); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Registers a dynamically imported module for customization. |
no test coverage detected
searching dependent graphs…