Skip to content

Commit 0567596

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 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 e7a5b33 commit 0567596

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
@@ -414,16 +414,38 @@ void Initialize(Local<Object> target,
414414
}
415415
#undef V
416416

417-
#define V(name) \
418-
target->Set(context, \
419-
FIXED_ONE_BYTE_STRING(env->isolate(), #name), \
420-
Integer::New(env->isolate(), Promise::PromiseState::name)) \
421-
.FromJust()
422-
V(kPending);
423-
V(kFulfilled);
424-
V(kRejected);
417+
{
418+
Local<Object> constants = Object::New(isolate);
419+
#define V(name) \
420+
constants \
421+
->Set(context, \
422+
FIXED_ONE_BYTE_STRING(isolate, #name), \
423+
Integer::New(isolate, Promise::PromiseState::name)) \
424+
.Check();
425+
426+
V(kPending);
427+
V(kFulfilled);
428+
V(kRejected);
425429
#undef V
426430

431+
#define V(name) \
432+
constants \
433+
->Set(context, \
434+
FIXED_ONE_BYTE_STRING(isolate, #name), \
435+
Integer::New(isolate, PropertyFilter::name)) \
436+
.Check();
437+
438+
V(ALL_PROPERTIES);
439+
V(ONLY_WRITABLE);
440+
V(ONLY_ENUMERABLE);
441+
V(ONLY_CONFIGURABLE);
442+
V(SKIP_STRINGS);
443+
V(SKIP_SYMBOLS);
444+
#undef V
445+
446+
target->Set(context, env->constants_string(), constants).Check();
447+
}
448+
427449
SetMethodNoSideEffect(context, target, "getHiddenValue", GetHiddenValue);
428450
SetMethod(context, target, "setHiddenValue", SetHiddenValue);
429451
SetMethodNoSideEffect(
@@ -439,16 +461,6 @@ void Initialize(Local<Object> target,
439461

440462
SetMethod(
441463
context, target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer);
442-
Local<Object> constants = Object::New(env->isolate());
443-
NODE_DEFINE_CONSTANT(constants, ALL_PROPERTIES);
444-
NODE_DEFINE_CONSTANT(constants, ONLY_WRITABLE);
445-
NODE_DEFINE_CONSTANT(constants, ONLY_ENUMERABLE);
446-
NODE_DEFINE_CONSTANT(constants, ONLY_CONFIGURABLE);
447-
NODE_DEFINE_CONSTANT(constants, SKIP_STRINGS);
448-
NODE_DEFINE_CONSTANT(constants, SKIP_SYMBOLS);
449-
target->Set(context,
450-
FIXED_ONE_BYTE_STRING(env->isolate(), "propertyFilter"),
451-
constants).Check();
452464

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

0 commit comments

Comments
 (0)