diff --git a/src/node_file.cc b/src/node_file.cc index 6d097904f67b89..1b56d2323c9526 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -1406,16 +1406,15 @@ static void ReadLink(const FunctionCallbackInfo& args) { const char* link_path = static_cast(req_wrap_sync.req.ptr); Local error; - MaybeLocal rc = StringBytes::Encode(isolate, - link_path, - encoding, - &error); - if (rc.IsEmpty()) { + Local ret; + if (!StringBytes::Encode(isolate, link_path, encoding, &error) + .ToLocal(&ret)) { + DCHECK(!error.IsEmpty()); env->isolate()->ThrowException(error); return; } - args.GetReturnValue().Set(rc.ToLocalChecked()); + args.GetReturnValue().Set(ret); } } @@ -1916,15 +1915,16 @@ static void MKDir(const FunctionCallbackInfo& args) { } if (!req_wrap_sync.continuation_data()->first_path().empty()) { Local error; + Local ret; std::string first_path(req_wrap_sync.continuation_data()->first_path()); - MaybeLocal path = StringBytes::Encode(env->isolate(), - first_path.c_str(), - UTF8, &error); - if (path.IsEmpty()) { + if (!StringBytes::Encode( + env->isolate(), first_path.c_str(), UTF8, &error) + .ToLocal(&ret)) { + DCHECK(!error.IsEmpty()); env->isolate()->ThrowException(error); return; } - args.GetReturnValue().Set(path.ToLocalChecked()); + args.GetReturnValue().Set(ret); } } else { SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_mkdir, *path, mode); @@ -1965,16 +1965,15 @@ static void RealPath(const FunctionCallbackInfo& args) { const char* link_path = static_cast(req_wrap_sync.req.ptr); Local error; - MaybeLocal rc = StringBytes::Encode(isolate, - link_path, - encoding, - &error); - if (rc.IsEmpty()) { + Local ret; + if (!StringBytes::Encode(isolate, link_path, encoding, &error) + .ToLocal(&ret)) { + DCHECK(!error.IsEmpty()); env->isolate()->ThrowException(error); return; } - args.GetReturnValue().Set(rc.ToLocalChecked()); + args.GetReturnValue().Set(ret); } } @@ -2061,17 +2060,15 @@ static void ReadDir(const FunctionCallbackInfo& args) { } Local error; - MaybeLocal filename = StringBytes::Encode(isolate, - ent.name, - encoding, - &error); - - if (filename.IsEmpty()) { + Local fn; + if (!StringBytes::Encode(isolate, ent.name, encoding, &error) + .ToLocal(&fn)) { + DCHECK(!error.IsEmpty()); isolate->ThrowException(error); return; } - name_v.push_back(filename.ToLocalChecked()); + name_v.push_back(fn); if (with_types) { type_v.emplace_back(Integer::New(isolate, ent.type)); @@ -3092,13 +3089,14 @@ static void Mkdtemp(const FunctionCallbackInfo& args) { return; } Local error; - MaybeLocal rc = - StringBytes::Encode(isolate, req_wrap_sync.req.path, encoding, &error); - if (rc.IsEmpty()) { + Local ret; + if (!StringBytes::Encode(isolate, req_wrap_sync.req.path, encoding, &error) + .ToLocal(&ret)) { + DCHECK(!error.IsEmpty()); env->isolate()->ThrowException(error); return; } - args.GetReturnValue().Set(rc.ToLocalChecked()); + args.GetReturnValue().Set(ret); } } @@ -3410,9 +3408,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo& args) { for (int i = 0; i < legacy_main_extensions_with_main_end; i++) { file_path = *initial_file_path + std::string(legacy_main_extensions[i]); // TODO(anonrig): Remove this when ToNamespacedPath supports std::string - Local local_file_path = - Buffer::Copy(env->isolate(), file_path.c_str(), file_path.size()) - .ToLocalChecked(); + Local local_file_path; + if (!Buffer::Copy(env->isolate(), file_path.c_str(), file_path.size()) + .ToLocal(&local_file_path)) { + return; + } BufferValue buff_file_path(isolate, local_file_path); ToNamespacedPath(env, &buff_file_path); @@ -3445,9 +3445,11 @@ void BindingData::LegacyMainResolve(const FunctionCallbackInfo& args) { i++) { file_path = *initial_file_path + std::string(legacy_main_extensions[i]); // TODO(anonrig): Remove this when ToNamespacedPath supports std::string - Local local_file_path = - Buffer::Copy(env->isolate(), file_path.c_str(), file_path.size()) - .ToLocalChecked(); + Local local_file_path; + if (!Buffer::Copy(env->isolate(), file_path.c_str(), file_path.size()) + .ToLocal(&local_file_path)) { + return; + } BufferValue buff_file_path(isolate, local_file_path); ToNamespacedPath(env, &buff_file_path);