MCPcopy Index your code
hub / github.com/nodejs/node / #loadSync

Method #loadSync

lib/internal/modules/esm/loader.js:817–841  ·  view source on GitHub ↗

* Similar to load but this is always run synchronously. If there are asynchronous hooks * from module.register(), this blocks on the loader thread for it to return synchronously. * * This is here to support `require()` in imported CJS and `module.registerHooks()` hooks. * @param

(url, context)

Source from the content-addressed store, hash-verified

815 * @returns {LoadResult}
816 */
817 #loadSync(url, context) {
818 // Use an output parameter to track the state and avoid polluting the user-visible resolve results.
819 const out = {
820 isSourceLoadedSynchronously: true,
821 __proto__: null,
822 };
823 let result;
824 if (syncLoadHooks.length) {
825 // Has module.registerHooks() hooks, chain the asynchronous hooks in the default step.
826 // TODO(joyeecheung): construct the ModuleLoadContext in the loaders directly instead
827 // of converting them from plain objects in the hooks.
828 result = loadWithSyncHooks(
829 url,
830 context.format,
831 context.importAttributes,
832 this.#defaultConditions,
833 this.#loadAndMaybeBlockOnLoaderThread.bind(this, out),
834 validateLoadSloppy,
835 );
836 } else {
837 result = this.#loadAndMaybeBlockOnLoaderThread(out, url, context);
838 }
839 result.isSourceLoadedSynchronously = out.isSourceLoadedSynchronously;
840 return result;
841 }
842
843 validateLoadResult(url, format) {
844 if (format == null) {

Calls 2

bindMethod · 0.45

Tested by

no test coverage detected