Skip to content

Commit 3205b19

Browse files
authored
lib: remove aix directory case for package reader
PR-URL: #48605 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]>
1 parent d9438cc commit 3205b19

File tree

4 files changed

+12
-56
lines changed

4 files changed

+12
-56
lines changed

‎lib/internal/modules/package_json_reader.js‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const{kEmptyObject, setOwnProperty } = require('internal/util');
1515
const{ fileURLToPath, pathToFileURL }=require('internal/url');
1616

1717
constcache=newSafeMap();
18-
constisAIX=process.platform==='aix';
1918

2019
letmanifest;
2120

@@ -45,10 +44,7 @@ function read(jsonPath,{base, specifier, isESM } = kEmptyObject){
4544
returncache.get(jsonPath);
4645
}
4746

48-
const{
49-
0: string,
50-
1: containsKeys,
51-
}=internalModuleReadJSON(
47+
conststring=internalModuleReadJSON(
5248
toNamespacedPath(jsonPath),
5349
);
5450
constresult={
@@ -62,14 +58,7 @@ function read(jsonPath,{base, specifier, isESM } = kEmptyObject){
6258
imports: undefined,
6359
};
6460

65-
// Folder read operation succeeds in AIX.
66-
// For libuv change, see https://github.com/libuv/libuv/pull/2025.
67-
// https://github.com/nodejs/node/pull/48477#issuecomment-1604586650
68-
// TODO(anonrig): Follow-up on this change and remove it since it is a
69-
// semver-major change.
70-
constisResultValid=isAIX&&!isESM ? containsKeys : string!==undefined;
71-
72-
if(isResultValid){
61+
if(string!==undefined){
7362
letparsed;
7463
try{
7564
parsed=JSONParse(string);

‎src/node_file.cc‎

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ namespace fs{
5757

5858
using v8::Array;
5959
using v8::BigInt;
60-
using v8::Boolean;
6160
using v8::Context;
6261
using v8::EscapableHandleScope;
6362
using v8::Function;
@@ -1035,15 +1034,13 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args){
10351034
env, permission::PermissionScope::kFileSystemRead, path.ToStringView());
10361035

10371036
if (strlen(*path) != path.length()){
1038-
args.GetReturnValue().Set(Array::New(isolate));
10391037
return; // Contains a nul byte.
10401038
}
10411039
uv_fs_t open_req;
10421040
constint fd = uv_fs_open(loop, &open_req, *path, O_RDONLY, 0, nullptr);
10431041
uv_fs_req_cleanup(&open_req);
10441042

10451043
if (fd < 0){
1046-
args.GetReturnValue().Set(Array::New(isolate));
10471044
return;
10481045
}
10491046

@@ -1070,7 +1067,6 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args){
10701067
uv_fs_req_cleanup(&read_req);
10711068

10721069
if (numchars < 0){
1073-
args.GetReturnValue().Set(Array::New(isolate));
10741070
return;
10751071
}
10761072
offset += numchars;
@@ -1082,42 +1078,10 @@ static void InternalModuleReadJSON(const FunctionCallbackInfo<Value>& args){
10821078
}
10831079
constsize_t size = offset - start;
10841080

1085-
// TODO(anonrig): Follow-up on removing the following changes for AIX.
1086-
char* p = &chars[start];
1087-
char* pe = &chars[size];
1088-
char* pos[2];
1089-
char** ppos = &pos[0];
1090-
1091-
while (p < pe){
1092-
char c = *p++;
1093-
if (c == '\\' && p < pe && *p == '"') p++;
1094-
if (c != '"') continue;
1095-
*ppos++ = p;
1096-
if (ppos < &pos[2]) continue;
1097-
ppos = &pos[0];
1098-
1099-
char* s = &pos[0][0];
1100-
char* se = &pos[1][-1]; // Exclude quote.
1101-
size_t n = se - s;
1102-
1103-
if (n == 4){
1104-
if (0 == memcmp(s, "main", 4)) break;
1105-
if (0 == memcmp(s, "name", 4)) break;
1106-
if (0 == memcmp(s, "type", 4)) break;
1107-
} elseif (n == 7){
1108-
if (0 == memcmp(s, "exports", 7)) break;
1109-
if (0 == memcmp(s, "imports", 7)) break;
1110-
}
1111-
}
1112-
1113-
Local<Value> return_value[] ={
1081+
args.GetReturnValue().Set(
11141082
String::NewFromUtf8(
11151083
isolate, &chars[start], v8::NewStringType::kNormal, size)
1116-
.ToLocalChecked(),
1117-
Boolean::New(isolate, p < pe ? true : false)};
1118-
1119-
args.GetReturnValue().Set(
1120-
Array::New(isolate, return_value, arraysize(return_value)));
1084+
.ToLocalChecked());
11211085
}
11221086

11231087
// Used to speed up module loading. Returns 0 if the path refers to

‎test/parallel/test-module-binding.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ const{readFileSync } = require('fs');
99
const{ strictEqual, deepStrictEqual }=require('assert');
1010

1111
{
12-
strictEqual(internalModuleReadJSON('nosuchfile')[0],undefined);
12+
strictEqual(internalModuleReadJSON('nosuchfile'),undefined);
1313
}
1414
{
15-
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt'))[0],'');
15+
strictEqual(internalModuleReadJSON(fixtures.path('empty.txt')),'');
1616
}
1717
{
18-
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt'))[0],'');
18+
strictEqual(internalModuleReadJSON(fixtures.path('empty-with-bom.txt')),'');
1919
}
2020
{
2121
constfilename=fixtures.path('require-bin/package.json');
22-
constreturnValue=JSON.parse(internalModuleReadJSON(filename)[0]);
22+
constreturnValue=JSON.parse(internalModuleReadJSON(filename));
2323
constfile=JSON.parse(readFileSync(filename,'utf-8'));
2424
constexpectedValue=filterOwnProperties(file,['name','main','exports','imports','type']);
2525
deepStrictEqual({

‎test/parallel/test-module-loading-error.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ assert.throws(
8484
message: 'The argument \'id\' must be a non-empty string. Received \'\''
8585
});
8686

87+
// Folder read operation succeeds in AIX.
88+
// For libuv change, see https://github.com/libuv/libuv/pull/2025.
89+
// https://github.com/nodejs/node/pull/48477#issuecomment-1604586650
8790
assert.throws(
8891
()=>{require('../fixtures/packages/is-dir');},
89-
{
92+
common.isAIX ? {code: 'ERR_INVALID_PACKAGE_CONFIG'} : {
9093
code: 'MODULE_NOT_FOUND',
9194
message: /Cannotfindmodule'\.\.\/fixtures\/packages\/is-dir'/
9295
}

0 commit comments

Comments
(0)