Skip to content

Commit f06e8e9

Browse files
committed
src,lib: group properties used as constants from util binding
Properties used as constants in `util` internal binding are scattered. This suggests using an object holding all of them for better maintenance. Signed-off-by: Daeyeon Jeong <[email protected]> PR-URL: #45539 Backport-PR-URL: #45674 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 18d9474 commit f06e8e9

File tree

6 files changed

+50
-36
lines changed

6 files changed

+50
-36
lines changed

lib/buffer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ const {
6767
kStringMaxLength
6868
} = internalBinding('buffer');
6969
const {
70-
getOwnNonIndexProperties,
71-
propertyFilter: {
70+
constants: {
7271
ALL_PROPERTIES,
73-
ONLY_ENUMERABLE
72+
ONLY_ENUMERABLE,
7473
},
74+
getOwnNonIndexProperties,
7575
} = internalBinding('util');
7676
const {
7777
customInspectSymbol,

lib/internal/util/comparisons.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ const {
4646
isFloat64Array,
4747
} = types;
4848
const {
49-
getOwnNonIndexProperties,
50-
propertyFilter: {
49+
constants: {
5150
ONLY_ENUMERABLE,
52-
SKIP_SYMBOLS
53-
}
51+
SKIP_SYMBOLS,
52+
},
53+
getOwnNonIndexProperties,
5454
} = internalBinding('util');
5555

5656
const kStrict = true;

lib/internal/util/inspect.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@ const {
9797
} = primordials;
9898

9999
const {
100+
constants: {
101+
ALL_PROPERTIES,
102+
ONLY_ENUMERABLE,
103+
kPending,
104+
kRejected,
105+
},
100106
getOwnNonIndexProperties,
101107
getPromiseDetails,
102108
getProxyDetails,
103-
kPending,
104-
kRejected,
105109
previewEntries,
106110
getConstructorName: internalGetConstructorName,
107111
getExternalValue,
108-
propertyFilter: {
109-
ALL_PROPERTIES,
110-
ONLY_ENUMERABLE
111-
}
112112
} = internalBinding('util');
113113

114114
const {

lib/internal/webstreams/util.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ const {
4040
} = require('util');
4141

4242
const {
43+
constants: {
44+
kPending,
45+
},
4346
getPromiseDetails,
44-
kPending,
4547
} = internalBinding('util');
4648

4749
const assert = require('internal/assert');

lib/repl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ const {
166166
setupReverseSearch,
167167
} = require('internal/repl/utils');
168168
const {
169-
getOwnNonIndexProperties,
170-
propertyFilter: {
169+
constants: {
171170
ALL_PROPERTIES,
172-
SKIP_SYMBOLS
173-
}
171+
SKIP_SYMBOLS,
172+
},
173+
getOwnNonIndexProperties,
174174
} = internalBinding('util');
175175
const {
176176
startSigintWatchdog,

src/node_util.cc

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -379,16 +379,38 @@ void Initialize(Local<Object> target,
379379
.Check();
380380
}
381381

382-
#define V(name) \
383-
target->Set(context, \
384-
FIXED_ONE_BYTE_STRING(env->isolate(), #name), \
385-
Integer::New(env->isolate(), Promise::PromiseState::name)) \
386-
.FromJust()
387-
V(kPending);
388-
V(kFulfilled);
389-
V(kRejected);
382+
{
383+
Local<Object> constants = Object::New(isolate);
384+
#define V(name) \
385+
constants \
386+
->Set(context, \
387+
FIXED_ONE_BYTE_STRING(isolate, #name), \
388+
Integer::New(isolate, Promise::PromiseState::name)) \
389+
.Check();
390+
391+
V(kPending);
392+
V(kFulfilled);
393+
V(kRejected);
394+
#undef V
395+
396+
#define V(name) \
397+
constants \
398+
->Set(context, \
399+
FIXED_ONE_BYTE_STRING(isolate, #name), \
400+
Integer::New(isolate, PropertyFilter::name)) \
401+
.Check();
402+
403+
V(ALL_PROPERTIES);
404+
V(ONLY_WRITABLE);
405+
V(ONLY_ENUMERABLE);
406+
V(ONLY_CONFIGURABLE);
407+
V(SKIP_STRINGS);
408+
V(SKIP_SYMBOLS);
390409
#undef V
391410

411+
target->Set(context, env->constants_string(), constants).Check();
412+
}
413+
392414
SetMethodNoSideEffect(
393415
context, target, "getPromiseDetails", GetPromiseDetails);
394416
SetMethodNoSideEffect(context, target, "getProxyDetails", GetProxyDetails);
@@ -402,16 +424,6 @@ void Initialize(Local<Object> target,
402424

403425
SetMethod(
404426
context, target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer);
405-
Local<Object> constants = Object::New(env->isolate());
406-
NODE_DEFINE_CONSTANT(constants, ALL_PROPERTIES);
407-
NODE_DEFINE_CONSTANT(constants, ONLY_WRITABLE);
408-
NODE_DEFINE_CONSTANT(constants, ONLY_ENUMERABLE);
409-
NODE_DEFINE_CONSTANT(constants, ONLY_CONFIGURABLE);
410-
NODE_DEFINE_CONSTANT(constants, SKIP_STRINGS);
411-
NODE_DEFINE_CONSTANT(constants, SKIP_SYMBOLS);
412-
target->Set(context,
413-
FIXED_ONE_BYTE_STRING(env->isolate(), "propertyFilter"),
414-
constants).Check();
415427

416428
Local<String> should_abort_on_uncaught_toggle =
417429
FIXED_ONE_BYTE_STRING(env->isolate(), "shouldAbortOnUncaughtToggle");

0 commit comments

Comments
 (0)