From 481f916f3f3048c2d8f8bb6ccb657f89e9f1d679 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Tue, 30 May 2023 00:30:47 -0700 Subject: More comments --- src/bun.js/bindings/CommonJSModuleRecord.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/bun.js/bindings/CommonJSModuleRecord.cpp') diff --git a/src/bun.js/bindings/CommonJSModuleRecord.cpp b/src/bun.js/bindings/CommonJSModuleRecord.cpp index ba49f0e14..d7fe6161a 100644 --- a/src/bun.js/bindings/CommonJSModuleRecord.cpp +++ b/src/bun.js/bindings/CommonJSModuleRecord.cpp @@ -351,6 +351,7 @@ JSC::SourceCode createCommonJSModule( false, false, EvalContextType::None, nullptr, nullptr, ECMAMode::sloppy()); if (UNLIKELY(!executable && !throwScope.exception())) { + // I'm not sure if this case happens, but it's better to be safe than sorry. throwSyntaxError(globalObject, throwScope, "Failed to compile CommonJS module."_s); } @@ -380,6 +381,13 @@ JSC::SourceCode createCommonJSModule( JSValue result = moduleObject->exportsObject(); + // The developer can do something like: + // + // Object.defineProperty(module, 'exports', {get: getter}) + // + // In which case, the exports object is now a GetterSetter object. + // + // We can't return a GetterSetter object to ESM code, so we need to call it. if (!result.isEmpty() && (result.isGetterSetter() || result.isCustomGetterSetter())) { auto* clientData = WebCore::clientData(vm); -- cgit v1.2.3