Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename internalModuleReadFile to internalModuleReadJSON. #17084

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const fs = require('fs');
const internalFS = require('internal/fs');
const path = require('path');
const {
internalModuleReadFile,
internalModuleReadJSON,
internalModuleStat
} = process.binding('fs');
const preserveSymlinks = !!process.binding('config').preserveSymlinks;
Expand Down Expand Up @@ -114,7 +114,7 @@ function readPackage(requestPath) {
return entry;

const jsonPath = path.resolve(requestPath, 'package.json');
const json = internalModuleReadFile(path.toNamespacedPath(jsonPath));
const json = internalModuleReadJSON(path.toNamespacedPath(jsonPath));

if (json === undefined) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void FillStatsArray(double* fields, const uv_stat_t* s) {
// a string or undefined when the file cannot be opened. Returns an empty
// string when the file does not contain the substring '"main"' because that
// is the property we care about.
static void InternalModuleReadFile(const FunctionCallbackInfo<Value>& args) {
static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
uv_loop_t* loop = env->event_loop();

Expand Down Expand Up @@ -1430,7 +1430,7 @@ void InitFs(Local<Object> target,
env->SetMethod(target, "rmdir", RMDir);
env->SetMethod(target, "mkdir", MKDir);
env->SetMethod(target, "readdir", ReadDir);
env->SetMethod(target, "internalModuleReadFile", InternalModuleReadFile);
env->SetMethod(target, "internalModuleReadJSON", InternalModuleReadJSON);
env->SetMethod(target, "internalModuleStat", InternalModuleStat);
env->SetMethod(target, "stat", Stat);
env->SetMethod(target, "lstat", LStat);
Expand Down
10 changes: 5 additions & 5 deletions test/parallel/test-module-binding.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';
require('../common');
const fixtures = require('../common/fixtures');
const { internalModuleReadFile } = process.binding('fs');
const { internalModuleReadJSON } = process.binding('fs');
const { readFileSync } = require('fs');
const { strictEqual } = require('assert');

strictEqual(internalModuleReadFile('nosuchfile'), undefined);
strictEqual(internalModuleReadFile(fixtures.path('empty.txt')), '');
strictEqual(internalModuleReadFile(fixtures.path('empty-with-bom.txt')), '');
strictEqual(internalModuleReadJSON('nosuchfile'), undefined);
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')), '');
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')), '');
{
Copy link
Member Author

@jdalton jdalton Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👆 These tests highlight the mixed signals being sent:
They test .txt, but the method is being shaped via #15767 to be json-only.

const filename = fixtures.path('require-bin/package.json');
strictEqual(internalModuleReadFile(filename), readFileSync(filename, 'utf8'));
strictEqual(internalModuleReadJSON(filename), readFileSync(filename, 'utf8'));
}