module: fix for empty object in InternalModuleReadJSON

Fixes: https://github.com/nodejs/node/issues/30245
PR-URL: https://github.com/nodejs/node/pull/30256
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
This commit is contained in:
Guy Bedford authored and Myles Borins committed 2019-11-16 23:59:11 -08:00
1 parent ae5aa3ee83
commit caedcd9ef9
6 files changed
+14 -5

No files matched your search

+1
View File
@@ -217,6 +217,7 @@ constexpr size_t kFsStatsBufferLength =
V(done_string, "done") \
V(duration_string, "duration") \
V(emit_warning_string, "emitWarning") \
V(empty_object_string, "{}") \
V(encoding_string, "encoding") \
V(entries_string, "entries") \
V(entry_type_string, "entryType") \
+1 -2
View File
@@ -18,7 +18,6 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "node_file.h"
#include "aliased_buffer.h"
#include "memory_tracker-inl.h"
@@ -787,7 +786,7 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
size == SearchString(&chars[start], size, "\"main\"") &&
size == SearchString(&chars[start], size, "\"exports\"") &&
size == SearchString(&chars[start], size, "\"type\""))) {
return;
args.GetReturnValue().Set(env->empty_object_string());
} else {
Local<String> chars_string =
String::NewFromUtf8(isolate,
+8
View File
@@ -0,0 +1,8 @@
// Flags: --experimental-modules
import '../common/index.mjs';
import { strictEqual } from 'assert';
import asdf from
'../fixtures/es-modules/package-type-module/nested-default-type/module.js';
strictEqual(asdf, 'asdf');
@@ -0,0 +1 @@
module.exports = 'asdf';
@@ -0,0 +1 @@
{}
+2 -3
View File
@@ -8,9 +8,8 @@ const { readFileSync } = require('fs');
const { strictEqual } = require('assert');
strictEqual(internalModuleReadJSON('nosuchfile'), undefined);
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), undefined);
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')),
undefined);
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), '{}');
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), '{}');
{
const filename = fixtures.path('require-bin/package.json');
strictEqual(internalModuleReadJSON(filename), readFileSync(filename, 'utf8'));