| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -178,11 +178,11 @@ void Channel::Unlink() { | |||
| 178 | 178 | publish_fn_.Reset(); | |
| 179 | 179 | } | |
| 180 | 180 | ||
| 181 | - Channel* Channel::Get(Environment* env, const char* name) { | ||
| 181 | + BaseObjectPtr<Channel> Channel::Get(Environment* env, std::string_view name) { | ||
| 182 | 182 | Realm* realm = env->principal_realm(); | |
| 183 | 183 | BindingData* binding = realm->GetBindingData<BindingData>(); | |
| 184 | 184 | if (binding == nullptr) { | |
| 185 | - return nullptr; | ||
| 185 | + return {}; | ||
| 186 | 186 | } | |
| 187 | 187 | uint32_t index = binding->GetOrCreateChannelIndex(std::string(name)); | |
| 188 | 188 | ||
@@ -208,22 +208,24 @@ Channel* Channel::Get(Environment* env, const char* name) { | |||
| 208 | 208 | .ToLocalChecked() | |
| 209 | 209 | ->NewInstance(context) | |
| 210 | 210 | .ToLocal(&wrap)) { | |
| 211 | - return nullptr; | ||
| 211 | + return {}; | ||
| 212 | 212 | } | |
| 213 | 213 | ||
| 214 | 214 | binding->channels_[index] = MakeDetachedBaseObject<Channel>( | |
| 215 | 215 | env, wrap, binding, index, std::string(name)); | |
| 216 | 216 | } | |
| 217 | 217 | ||
| 218 | - Channel* channel = binding->channels_[index].get(); | ||
| 218 | + auto& channel = binding->channels_[index]; | ||
| 219 | 219 | ||
| 220 | 220 | // Late-bind: link to the JS channel when the callback is available. | |
| 221 | 221 | if (!binding->link_callback_.IsEmpty() && !channel->IsLinked()) { | |
| 222 | 222 | Isolate* isolate = env->isolate(); | |
| 223 | 223 | HandleScope handle_scope(isolate); | |
| 224 | 224 | Local<Context> context = env->context(); | |
| 225 | - Local<String> js_name = String::NewFromUtf8(isolate, name).ToLocalChecked(); | ||
| 226 | - Local<Value> argv[] = {js_name, Integer::NewFromUnsigned(isolate, index)}; | ||
| 225 | + Local<Value> argv[] = { | ||
| 226 | + ToV8Value(context, name).ToLocalChecked(), | ||
| 227 | + Integer::NewFromUnsigned(isolate, index), | ||
| 228 | + }; | ||
| 227 | 229 | Local<Value> result; | |
| 228 | 230 | if (binding->link_callback_.Get(isolate) | |
| 229 | 231 | ->Call(context, v8::Undefined(isolate), arraysize(argv), argv) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,8 +73,7 @@ class Channel : public BaseObject { | |||
| 73 | 73 | uint32_t index, | |
| 74 | 74 | std::string name); | |
| 75 | 75 | ||
| 76 | - // Returns a non-owning pointer. Lifetime is managed by BindingData. | ||
| 77 | - static Channel* Get(Environment* env, const char* name); | ||
| 76 | + static BaseObjectPtr<Channel> Get(Environment* env, std::string_view name); | ||
| 78 | 77 | ||
| 79 | 78 | inline bool HasSubscribers() const { | |
| 80 | 79 | return binding_data_ != nullptr && binding_data_->subscribers_[index_] > 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -304,12 +304,10 @@ BaseObjectPtr<diagnostics_channel::Channel> Permission::GetOrCreateChannel( | |||
| 304 | 304 | channels_.erase(it); | |
| 305 | 305 | } | |
| 306 | 306 | auto channel_name = GetDiagnosticsChannelName(scope); | |
| 307 | - diagnostics_channel::Channel* ch = | ||
| 308 | - diagnostics_channel::Channel::Get(env, channel_name.data()); | ||
| 309 | - if (ch != nullptr) { | ||
| 307 | + if (auto ch = diagnostics_channel::Channel::Get(env, channel_name)) { | ||
| 310 | 308 | channels_.emplace(scope, | |
| 311 | 309 | BaseObjectWeakPtr<diagnostics_channel::Channel>(ch)); | |
| 312 | - return BaseObjectPtr<diagnostics_channel::Channel>(ch); | ||
| 310 | + return ch; | ||
| 313 | 311 | } | |
| 314 | 312 | return {}; | |
| 315 | 313 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | #include "gtest/gtest.h" | |
| 4 | 4 | #include "node_test_fixture.h" | |
| 5 | 5 | ||
| 6 | + using node::BaseObjectPtr; | ||
| 6 | 7 | using node::diagnostics_channel::Channel; | |
| 7 | 8 | ||
| 8 | 9 | class DiagnosticsChannelTest : public EnvironmentTestFixture {}; | |
@@ -279,15 +280,15 @@ TEST_F(DiagnosticsChannelTest, NativeChannelsGrowSubscriberStorage) { | |||
| 279 | 280 | "globalThis.__dc.subscribe('test:cctest:grow:0', " | |
| 280 | 281 | " globalThis.__firstSubscriber);"); | |
| 281 | 282 | ||
| 282 | - Channel* first = Channel::Get(*env, "test:cctest:grow:0"); | ||
| 283 | - ASSERT_NE(first, nullptr); | ||
| 283 | + auto first = Channel::Get(*env, "test:cctest:grow:0"); | ||
| 284 | + ASSERT_TRUE(first); | ||
| 284 | 285 | ASSERT_TRUE(first->HasSubscribers()); | |
| 285 | 286 | ||
| 286 | - Channel* last = nullptr; | ||
| 287 | + BaseObjectPtr<Channel> last; | ||
| 287 | 288 | for (size_t i = 1; i <= 1024; i++) { | |
| 288 | 289 | std::string name = "test:cctest:grow:" + std::to_string(i); | |
| 289 | 290 | last = Channel::Get(*env, name.c_str()); | |
| 290 | - ASSERT_NE(last, nullptr); | ||
| 291 | + ASSERT_TRUE(last); | ||
| 291 | 292 | } | |
| 292 | 293 | ||
| 293 | 294 | RunJS(isolate_, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments