Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b84dde

Browse filesBrowse files
joyeecheungRafaelGSS
authored andcommitted
src: implement constants binding directly
Instead of adding a special case for it in the internal binding loader, just implement it as usual using a per-context property initializer. PR-URL: #48186 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 06d49c1 commit 1b84dde
Copy full SHA for 1b84dde

File tree

Expand file treeCollapse file tree

3 files changed

+17
-14
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+17
-14
lines changed
Open diff view settings
Collapse file

‎src/node_binding.cc‎

Copy file name to clipboardExpand all lines: src/node_binding.cc
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
V(builtins) \
3535
V(cares_wrap) \
3636
V(config) \
37+
V(constants) \
3738
V(contextify) \
3839
V(credentials) \
3940
V(encoding_binding) \
@@ -619,7 +620,6 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
619620
Realm* realm = Realm::GetCurrent(args);
620621
Isolate* isolate = realm->isolate();
621622
HandleScope scope(isolate);
622-
Local<Context> context = realm->context();
623623

624624
CHECK(args[0]->IsString());
625625

@@ -631,10 +631,6 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
631631
if (mod != nullptr) {
632632
exports = InitInternalBinding(realm, mod);
633633
realm->internal_bindings.insert(mod);
634-
} else if (!strcmp(*module_v, "constants")) {
635-
exports = Object::New(isolate);
636-
CHECK(exports->SetPrototype(context, Null(isolate)).FromJust());
637-
DefineConstants(isolate, exports);
638634
} else {
639635
return THROW_ERR_INVALID_MODULE(isolate, "No such binding: %s", *module_v);
640636
}
Collapse file

‎src/node_constants.cc‎

Copy file name to clipboardExpand all lines: src/node_constants.cc
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@
6363

6464
namespace node {
6565

66+
using v8::Context;
67+
using v8::Isolate;
6668
using v8::Local;
69+
using v8::Null;
6770
using v8::Object;
71+
using v8::Value;
6872

69-
namespace {
73+
namespace constants {
7074

7175
void DefineErrnoConstants(Local<Object> target) {
7276
#ifdef E2BIG
@@ -1270,10 +1274,14 @@ void DefineTraceConstants(Local<Object> target) {
12701274
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_LINK_IDS);
12711275
}
12721276

1273-
} // anonymous namespace
1277+
void CreatePerContextProperties(Local<Object> target,
1278+
Local<Value> unused,
1279+
Local<Context> context,
1280+
void* priv) {
1281+
Isolate* isolate = context->GetIsolate();
1282+
Environment* env = Environment::GetCurrent(context);
12741283

1275-
void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
1276-
Environment* env = Environment::GetCurrent(isolate);
1284+
CHECK(target->SetPrototype(env->context(), Null(env->isolate())).FromJust());
12771285

12781286
Local<Object> os_constants = Object::New(isolate);
12791287
CHECK(os_constants->SetPrototype(env->context(),
@@ -1353,4 +1361,8 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
13531361
trace_constants).Check();
13541362
}
13551363

1364+
} // namespace constants
13561365
} // namespace node
1366+
1367+
NODE_BINDING_CONTEXT_AWARE_INTERNAL(constants,
1368+
node::constants::CreatePerContextProperties)
Collapse file

‎src/node_constants.h‎

Copy file name to clipboardExpand all lines: src/node_constants.h
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@
7474
#endif // NODE_OPENSSL_DEFAULT_CIPHER_LIST
7575
#endif // HAVE_OPENSSL
7676

77-
namespace node {
78-
79-
void DefineConstants(v8::Isolate* isolate, v8::Local<v8::Object> target);
80-
} // namespace node
81-
8277
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
8378

8479
#endif // SRC_NODE_CONSTANTS_H_

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.