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

src,lib: group properties used as constants from util binding #45539

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/buffer.js
Expand Up @@ -67,11 +67,11 @@ const {
kStringMaxLength
} = internalBinding('buffer');
const {
getOwnNonIndexProperties,
propertyFilter: {
constants: {
ALL_PROPERTIES,
ONLY_ENUMERABLE
ONLY_ENUMERABLE,
},
getOwnNonIndexProperties,
} = internalBinding('util');
const {
customInspectSymbol,
Expand Down
8 changes: 5 additions & 3 deletions lib/internal/bootstrap/node.js
Expand Up @@ -80,12 +80,14 @@ const {
validateInteger,
} = require('internal/validators');
const {
constants: {
kExitCode,
kExiting,
kHasExitCode,
},
privateSymbols: {
exit_info_private_symbol,
},
kExitCode,
kExiting,
kHasExitCode,
} = internalBinding('util');

setupProcessObject();
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/util/comparisons.js
Expand Up @@ -46,11 +46,11 @@ const {
isFloat64Array,
} = types;
const {
getOwnNonIndexProperties,
propertyFilter: {
constants: {
ONLY_ENUMERABLE,
SKIP_SYMBOLS
}
SKIP_SYMBOLS,
},
getOwnNonIndexProperties,
} = internalBinding('util');

const kStrict = true;
Expand Down
12 changes: 6 additions & 6 deletions lib/internal/util/inspect.js
Expand Up @@ -97,18 +97,18 @@ const {
} = primordials;

const {
constants: {
ALL_PROPERTIES,
ONLY_ENUMERABLE,
kPending,
kRejected,
},
getOwnNonIndexProperties,
getPromiseDetails,
getProxyDetails,
kPending,
kRejected,
previewEntries,
getConstructorName: internalGetConstructorName,
getExternalValue,
propertyFilter: {
ALL_PROPERTIES,
ONLY_ENUMERABLE
}
} = internalBinding('util');

const {
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/webstreams/util.js
Expand Up @@ -40,8 +40,10 @@ const {
} = require('util');

const {
constants: {
kPending,
},
getPromiseDetails,
kPending,
} = internalBinding('util');

const assert = require('internal/assert');
Expand Down
8 changes: 4 additions & 4 deletions lib/repl.js
Expand Up @@ -166,11 +166,11 @@ const {
setupReverseSearch,
} = require('internal/repl/utils');
const {
getOwnNonIndexProperties,
propertyFilter: {
constants: {
ALL_PROPERTIES,
SKIP_SYMBOLS
}
SKIP_SYMBOLS,
},
getOwnNonIndexProperties,
} = internalBinding('util');
const {
startSigintWatchdog,
Expand Down
66 changes: 40 additions & 26 deletions src/node_util.cc
Expand Up @@ -23,6 +23,7 @@ using v8::Isolate;
using v8::KeyCollectionMode;
using v8::Local;
using v8::Object;
using v8::ObjectTemplate;
using v8::ONLY_CONFIGURABLE;
using v8::ONLY_ENUMERABLE;
using v8::ONLY_WRITABLE;
Expand Down Expand Up @@ -364,7 +365,7 @@ void Initialize(Local<Object> target,
Isolate* isolate = env->isolate();

{
Local<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate);
Local<ObjectTemplate> tmpl = ObjectTemplate::New(isolate);
#define V(PropertyName, _) \
tmpl->Set(FIXED_ONE_BYTE_STRING(env->isolate(), #PropertyName), \
env->PropertyName());
Expand All @@ -379,27 +380,50 @@ void Initialize(Local<Object> target,
.Check();
}

#define V(name) \
target->Set(context, \
FIXED_ONE_BYTE_STRING(env->isolate(), #name), \
Integer::New(env->isolate(), Promise::PromiseState::name)) \
.FromJust()
V(kPending);
V(kFulfilled);
V(kRejected);
{
Local<Object> constants = Object::New(isolate);
#define V(name) \
constants \
->Set(context, \
FIXED_ONE_BYTE_STRING(isolate, #name), \
Integer::New(isolate, Promise::PromiseState::name)) \
.Check();

V(kPending);
V(kFulfilled);
V(kRejected);
#undef V

#define V(name) \
target \
constants \
->Set(context, \
FIXED_ONE_BYTE_STRING(env->isolate(), #name), \
Integer::New(env->isolate(), Environment::ExitInfoField::name)) \
.FromJust()
V(kExiting);
V(kExitCode);
V(kHasExitCode);
FIXED_ONE_BYTE_STRING(isolate, #name), \
Integer::New(isolate, Environment::ExitInfoField::name)) \
.Check();

V(kExiting);
V(kExitCode);
V(kHasExitCode);
#undef V

#define V(name) \
constants \
->Set(context, \
FIXED_ONE_BYTE_STRING(isolate, #name), \
Integer::New(isolate, PropertyFilter::name)) \
.Check();

V(ALL_PROPERTIES);
V(ONLY_WRITABLE);
V(ONLY_ENUMERABLE);
V(ONLY_CONFIGURABLE);
V(SKIP_STRINGS);
V(SKIP_SYMBOLS);
#undef V

target->Set(context, env->constants_string(), constants).Check();
}

SetMethodNoSideEffect(
context, target, "getPromiseDetails", GetPromiseDetails);
SetMethodNoSideEffect(context, target, "getProxyDetails", GetProxyDetails);
Expand All @@ -413,16 +437,6 @@ void Initialize(Local<Object> target,

SetMethod(
context, target, "arrayBufferViewHasBuffer", ArrayBufferViewHasBuffer);
Local<Object> constants = Object::New(env->isolate());
NODE_DEFINE_CONSTANT(constants, ALL_PROPERTIES);
NODE_DEFINE_CONSTANT(constants, ONLY_WRITABLE);
NODE_DEFINE_CONSTANT(constants, ONLY_ENUMERABLE);
NODE_DEFINE_CONSTANT(constants, ONLY_CONFIGURABLE);
NODE_DEFINE_CONSTANT(constants, SKIP_STRINGS);
NODE_DEFINE_CONSTANT(constants, SKIP_SYMBOLS);
target->Set(context,
FIXED_ONE_BYTE_STRING(env->isolate(), "propertyFilter"),
constants).Check();

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