From 528cbb5ccd169abf8b206ea7695ed024d93fa3cd Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 4 Nov 2019 19:40:11 -0500 Subject: [PATCH 1/5] module: empty object fix in InternalModuleReadJSON for #30245 --- src/env.h | 1 + src/node_file.cc | 3 +-- test/es-module/test-esm-default-type.mjs | 8 ++++++++ .../package-type-module/nested-default-type/module.js | 1 + .../package-type-module/nested-default-type/package.json | 1 + 5 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test/es-module/test-esm-default-type.mjs create mode 100644 test/fixtures/es-modules/package-type-module/nested-default-type/module.js create mode 100644 test/fixtures/es-modules/package-type-module/nested-default-type/package.json diff --git a/src/env.h b/src/env.h index a649675c7cc902..ec348c23e77ca5 100644 --- a/src/env.h +++ b/src/env.h @@ -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") \ diff --git a/src/node_file.cc b/src/node_file.cc index 8b6a90989f8d29..48b382986c0bb5 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -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& 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 chars_string = String::NewFromUtf8(isolate, diff --git a/test/es-module/test-esm-default-type.mjs b/test/es-module/test-esm-default-type.mjs new file mode 100644 index 00000000000000..7e63dab3490d04 --- /dev/null +++ b/test/es-module/test-esm-default-type.mjs @@ -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'); diff --git a/test/fixtures/es-modules/package-type-module/nested-default-type/module.js b/test/fixtures/es-modules/package-type-module/nested-default-type/module.js new file mode 100644 index 00000000000000..683f2d8ba623a7 --- /dev/null +++ b/test/fixtures/es-modules/package-type-module/nested-default-type/module.js @@ -0,0 +1 @@ +module.exports = 'asdf'; diff --git a/test/fixtures/es-modules/package-type-module/nested-default-type/package.json b/test/fixtures/es-modules/package-type-module/nested-default-type/package.json new file mode 100644 index 00000000000000..0967ef424bce67 --- /dev/null +++ b/test/fixtures/es-modules/package-type-module/nested-default-type/package.json @@ -0,0 +1 @@ +{} From 67e1a5d9345dd1b457a4e29e76c7d460b8261bbf Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 4 Nov 2019 21:37:50 -0500 Subject: [PATCH 2/5] fixup module binding test --- test/parallel/test-module-binding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-module-binding.js b/test/parallel/test-module-binding.js index 07c4965f2204f3..01394a2095eb1e 100644 --- a/test/parallel/test-module-binding.js +++ b/test/parallel/test-module-binding.js @@ -8,7 +8,7 @@ const { readFileSync } = require('fs'); const { strictEqual } = require('assert'); strictEqual(internalModuleReadJSON('nosuchfile'), undefined); -strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), undefined); +strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), {}); strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), undefined); { From cd1a6d4e28e88f3916901ee1f8f7ad4e76fac95e Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 4 Nov 2019 21:38:58 -0500 Subject: [PATCH 3/5] fixup assertion --- test/parallel/test-module-binding.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-module-binding.js b/test/parallel/test-module-binding.js index 01394a2095eb1e..d4a44364591b31 100644 --- a/test/parallel/test-module-binding.js +++ b/test/parallel/test-module-binding.js @@ -5,10 +5,10 @@ const fixtures = require('../common/fixtures'); const { internalBinding } = require('internal/test/binding'); const { internalModuleReadJSON } = internalBinding('fs'); const { readFileSync } = require('fs'); -const { strictEqual } = require('assert'); +const { deepEqual, strictEqual } = require('assert'); strictEqual(internalModuleReadJSON('nosuchfile'), undefined); -strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), {}); +deepEqual(internalModuleReadJSON(fixtures.path('empty.txt')), {}); strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), undefined); { From d334de0d022aa9a097ff1605b97d8be5e39a6351 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 4 Nov 2019 22:30:37 -0500 Subject: [PATCH 4/5] fixup empty object comparison --- test/parallel/test-module-binding.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-module-binding.js b/test/parallel/test-module-binding.js index d4a44364591b31..c2c5174ab67e86 100644 --- a/test/parallel/test-module-binding.js +++ b/test/parallel/test-module-binding.js @@ -8,7 +8,7 @@ const { readFileSync } = require('fs'); const { deepEqual, strictEqual } = require('assert'); strictEqual(internalModuleReadJSON('nosuchfile'), undefined); -deepEqual(internalModuleReadJSON(fixtures.path('empty.txt')), {}); +strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), '{}'); strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), undefined); { From 7ec31437297a6ab17ea8bfde66e7698bb93ad36e Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Mon, 4 Nov 2019 22:59:57 -0500 Subject: [PATCH 5/5] moar fixups --- test/parallel/test-module-binding.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-module-binding.js b/test/parallel/test-module-binding.js index c2c5174ab67e86..d0e122605ddc00 100644 --- a/test/parallel/test-module-binding.js +++ b/test/parallel/test-module-binding.js @@ -5,12 +5,11 @@ const fixtures = require('../common/fixtures'); const { internalBinding } = require('internal/test/binding'); const { internalModuleReadJSON } = internalBinding('fs'); const { readFileSync } = require('fs'); -const { deepEqual, strictEqual } = require('assert'); +const { strictEqual } = require('assert'); strictEqual(internalModuleReadJSON('nosuchfile'), undefined); strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), '{}'); -strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), - undefined); +strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), '{}'); { const filename = fixtures.path('require-bin/package.json'); strictEqual(internalModuleReadJSON(filename), readFileSync(filename, 'utf8'));