mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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: https://github.com/nodejs/node/pull/48186 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
1 parent
06d49c1f10
commit
1b84ddeec2
3 files changed
+17
-14
No files matched your search
+1
-5
@@ -34,6 +34,7 @@
|
||||
V(builtins) \
|
||||
V(cares_wrap) \
|
||||
V(config) \
|
||||
V(constants) \
|
||||
V(contextify) \
|
||||
V(credentials) \
|
||||
V(encoding_binding) \
|
||||
@@ -619,7 +620,6 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
|
||||
Realm* realm = Realm::GetCurrent(args);
|
||||
Isolate* isolate = realm->isolate();
|
||||
HandleScope scope(isolate);
|
||||
Local<Context> context = realm->context();
|
||||
|
||||
CHECK(args[0]->IsString());
|
||||
|
||||
@@ -631,10 +631,6 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
|
||||
if (mod != nullptr) {
|
||||
exports = InitInternalBinding(realm, mod);
|
||||
realm->internal_bindings.insert(mod);
|
||||
} else if (!strcmp(*module_v, "constants")) {
|
||||
exports = Object::New(isolate);
|
||||
CHECK(exports->SetPrototype(context, Null(isolate)).FromJust());
|
||||
DefineConstants(isolate, exports);
|
||||
} else {
|
||||
return THROW_ERR_INVALID_MODULE(isolate, "No such binding: %s", *module_v);
|
||||
}
|
||||
|
||||
+16
-4
@@ -63,10 +63,14 @@
|
||||
|
||||
namespace node {
|
||||
|
||||
using v8::Context;
|
||||
using v8::Isolate;
|
||||
using v8::Local;
|
||||
using v8::Null;
|
||||
using v8::Object;
|
||||
using v8::Value;
|
||||
|
||||
namespace {
|
||||
namespace constants {
|
||||
|
||||
void DefineErrnoConstants(Local<Object> target) {
|
||||
#ifdef E2BIG
|
||||
@@ -1270,10 +1274,14 @@ void DefineTraceConstants(Local<Object> target) {
|
||||
NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_LINK_IDS);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
void CreatePerContextProperties(Local<Object> target,
|
||||
Local<Value> unused,
|
||||
Local<Context> context,
|
||||
void* priv) {
|
||||
Isolate* isolate = context->GetIsolate();
|
||||
Environment* env = Environment::GetCurrent(context);
|
||||
|
||||
void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
|
||||
Environment* env = Environment::GetCurrent(isolate);
|
||||
CHECK(target->SetPrototype(env->context(), Null(env->isolate())).FromJust());
|
||||
|
||||
Local<Object> os_constants = Object::New(isolate);
|
||||
CHECK(os_constants->SetPrototype(env->context(),
|
||||
@@ -1353,4 +1361,8 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) {
|
||||
trace_constants).Check();
|
||||
}
|
||||
|
||||
} // namespace constants
|
||||
} // namespace node
|
||||
|
||||
NODE_BINDING_CONTEXT_AWARE_INTERNAL(constants,
|
||||
node::constants::CreatePerContextProperties)
|
||||
@@ -74,11 +74,6 @@
|
||||
#endif // NODE_OPENSSL_DEFAULT_CIPHER_LIST
|
||||
#endif // HAVE_OPENSSL
|
||||
|
||||
namespace node {
|
||||
|
||||
void DefineConstants(v8::Isolate* isolate, v8::Local<v8::Object> target);
|
||||
} // namespace node
|
||||
|
||||
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
||||
|
||||
#endif // SRC_NODE_CONSTANTS_H_
|
||||
Reference in new issue
Block a user