@@ -178,11 +178,11 @@ void Channel::Unlink() {
178178 publish_fn_.Reset ();
179179}
180180
181- Channel* Channel::Get (Environment* env, const char * name) {
181+ BaseObjectPtr< Channel> Channel::Get (Environment* env, std::string_view name) {
182182 Realm* realm = env->principal_realm ();
183183 BindingData* binding = realm->GetBindingData <BindingData>();
184184 if (binding == nullptr ) {
185- return nullptr ;
185+ return {} ;
186186 }
187187 uint32_t index = binding->GetOrCreateChannelIndex (std::string (name));
188188
@@ -208,22 +208,24 @@ Channel* Channel::Get(Environment* env, const char* name) {
208208 .ToLocalChecked ()
209209 ->NewInstance (context)
210210 .ToLocal (&wrap)) {
211- return nullptr ;
211+ return {} ;
212212 }
213213
214214 binding->channels_ [index] = MakeDetachedBaseObject<Channel>(
215215 env, wrap, binding, index, std::string (name));
216216 }
217217
218- Channel* channel = binding->channels_ [index]. get () ;
218+ auto & channel = binding->channels_ [index];
219219
220220 // Late-bind: link to the JS channel when the callback is available.
221221 if (!binding->link_callback_ .IsEmpty () && !channel->IsLinked ()) {
222222 Isolate* isolate = env->isolate ();
223223 HandleScope handle_scope (isolate);
224224 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+ };
227229 Local<Value> result;
228230 if (binding->link_callback_ .Get (isolate)
229231 ->Call (context, v8::Undefined (isolate), arraysize (argv), argv)
0 commit comments