Skip to content

Commit ec227c9

Browse files
guybedfordtargos
authored andcommitted
module: fix for empty object in InternalModuleReadJSON
Fixes: #30245 PR-URL: #30256 Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Jan Krems <[email protected]>
1 parent 62e7cf0 commit ec227c9

File tree

6 files changed

+14
-5
lines changed

6 files changed

+14
-5
lines changed

src/env.h

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ constexpr size_t kFsStatsBufferLength =
214214
V(done_string, "done") \
215215
V(duration_string, "duration") \
216216
V(emit_warning_string, "emitWarning") \
217+
V(empty_object_string, "{}") \
217218
V(encoding_string, "encoding") \
218219
V(entries_string, "entries") \
219220
V(entry_type_string, "entryType") \

src/node_file.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21-
2221
#include "node_file.h"
2322
#include "aliased_buffer.h"
2423
#include "memory_tracker-inl.h"
@@ -787,7 +786,7 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
787786
size == SearchString(&chars[start], size, "\"main\"") &&
788787
size == SearchString(&chars[start], size, "\"exports\"") &&
789788
size == SearchString(&chars[start], size, "\"type\""))) {
790-
return;
789+
args.GetReturnValue().Set(env->empty_object_string());
791790
} else {
792791
Local<String> chars_string =
793792
String::NewFromUtf8(isolate,
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Flags: --experimental-modules
2+
import '../common/index.mjs';
3+
import { strictEqual } from 'assert';
4+
5+
import asdf from
6+
'../fixtures/es-modules/package-type-module/nested-default-type/module.js';
7+
8+
strictEqual(asdf, 'asdf');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 'asdf';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

test/parallel/test-module-binding.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ const { readFileSync } = require('fs');
88
const { strictEqual } = require('assert');
99

1010
strictEqual(internalModuleReadJSON('nosuchfile'), undefined);
11-
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), undefined);
12-
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')),
13-
undefined);
11+
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), '{}');
12+
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), '{}');
1413
{
1514
const filename = fixtures.path('require-bin/package.json');
1615
strictEqual(internalModuleReadJSON(filename), readFileSync(filename, 'utf8'));

0 commit comments

Comments
 (0)