GeezerVison is showing github.com — src: implement constants binding directly · nodejs/node@1b84dde
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node_binding.cc +1-5Lines changed: 1 addition & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 34 | 34 | V(builtins) \ | 35 | 35 | V(cares_wrap) \ | 36 | 36 | V(config) \ | | 37 | + V(constants) \ | 37 | 38 | V(contextify) \ | 38 | 39 | V(credentials) \ | 39 | 40 | V(encoding_binding) \ | @@ -619,7 +620,6 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) { | 619 | 620 | Realm* realm = Realm::GetCurrent(args); | 620 | 621 | Isolate* isolate = realm->isolate(); | 621 | 622 | HandleScope scope(isolate); | 622 | | - Local<Context> context = realm->context(); | 623 | 623 |
| 624 | 624 | CHECK(args[0]->IsString()); | 625 | 625 |
| @@ -631,10 +631,6 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) { | 631 | 631 | if (mod != nullptr) { | 632 | 632 | exports = InitInternalBinding(realm, mod); | 633 | 633 | 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); | 638 | 634 | } else { | 639 | 635 | return THROW_ERR_INVALID_MODULE(isolate, "No such binding: %s", *module_v); | 640 | 636 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/node_constants.cc +16-4Lines changed: 16 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 63 | 63 |
| 64 | 64 | namespace node { | 65 | 65 |
| | 66 | +using v8::Context; | | 67 | +using v8::Isolate; | 66 | 68 | using v8::Local; | | 69 | +using v8::Null; | 67 | 70 | using v8::Object; | | 71 | +using v8::Value; | 68 | 72 |
| 69 | | -namespace { | | 73 | +namespace constants { | 70 | 74 |
| 71 | 75 | void DefineErrnoConstants(Local<Object> target) { | 72 | 76 | #ifdef E2BIG | @@ -1270,10 +1274,14 @@ void DefineTraceConstants(Local<Object> target) { | 1270 | 1274 | NODE_DEFINE_CONSTANT(target, TRACE_EVENT_PHASE_LINK_IDS); | 1271 | 1275 | } | 1272 | 1276 |
| 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); | 1274 | 1283 |
| 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()); | 1277 | 1285 |
| 1278 | 1286 | Local<Object> os_constants = Object::New(isolate); | 1279 | 1287 | CHECK(os_constants->SetPrototype(env->context(), | @@ -1353,4 +1361,8 @@ void DefineConstants(v8::Isolate* isolate, Local<Object> target) { | 1353 | 1361 | trace_constants).Check(); | 1354 | 1362 | } | 1355 | 1363 |
| | 1364 | +} // namespace constants | 1356 | 1365 | } // namespace node | | 1366 | + | | 1367 | +NODE_BINDING_CONTEXT_AWARE_INTERNAL(constants, | | 1368 | + node::constants::CreatePerContextProperties) |
Collapse file Copy file name to clipboardExpand all lines: src/node_constants.h -5Lines changed: 0 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 74 | 74 | #endif // NODE_OPENSSL_DEFAULT_CIPHER_LIST | 75 | 75 | #endif // HAVE_OPENSSL | 76 | 76 |
| 77 | | -namespace node { | 78 | | - | 79 | | -void DefineConstants(v8::Isolate* isolate, v8::Local<v8::Object> target); | 80 | | -} // namespace node | 81 | | - | 82 | 77 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | 83 | 78 |
| 84 | 79 | #endif // SRC_NODE_CONSTANTS_H_ |
|