From 1dde9492c988b588aee63564b7b0d7f34d6f1898 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 26 Jun 2018 15:08:27 -0700 Subject: [PATCH] refactor: remove deprecated CreateWithCopiedBuffer (#13436) * refactor: remove deprecated CreateWithCopiedBuffer * fix: add missing vector includes * fix std::vector allocation --- .../native_mate_converters/net_converter.cc | 6 ++++-- .../network_converter.cc | 7 +++++-- .../v8_value_converter.cc | 20 ++++++++++--------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/atom/common/native_mate_converters/net_converter.cc b/atom/common/native_mate_converters/net_converter.cc index 0d99d69b39b..055fc910105 100644 --- a/atom/common/native_mate_converters/net_converter.cc +++ b/atom/common/native_mate_converters/net_converter.cc @@ -239,8 +239,10 @@ void GetUploadData(base::ListValue* upload_data_list, if (reader->AsBytesReader()) { const net::UploadBytesElementReader* bytes_reader = reader->AsBytesReader(); - std::unique_ptr bytes(base::Value::CreateWithCopiedBuffer( - bytes_reader->bytes(), bytes_reader->length())); + auto vec = + std::vector(bytes_reader->bytes(), + bytes_reader->bytes() + bytes_reader->length()); + auto bytes = std::make_unique(vec); upload_data_dict->Set("bytes", std::move(bytes)); } else if (reader->AsFileReader()) { const net::UploadFileElementReader* file_reader = reader->AsFileReader(); diff --git a/atom/common/native_mate_converters/network_converter.cc b/atom/common/native_mate_converters/network_converter.cc index 1f98a5b8ebd..8fe31b56eeb 100644 --- a/atom/common/native_mate_converters/network_converter.cc +++ b/atom/common/native_mate_converters/network_converter.cc @@ -6,6 +6,7 @@ #include #include +#include #include "atom/common/native_mate_converters/value_converter.h" #include "native_mate/dictionary.h" @@ -25,8 +26,10 @@ Converter>::ToV8( auto post_data_dict = std::make_unique(); auto type = element.type(); if (type == network::DataElement::TYPE_BYTES) { - auto bytes = base::Value::CreateWithCopiedBuffer( - element.bytes(), static_cast(element.length())); + auto vec = std::vector( + element.bytes(), + element.bytes() + static_cast(element.length())); + auto bytes = std::make_unique(vec); post_data_dict->SetString("type", "rawData"); post_data_dict->Set("bytes", std::move(bytes)); } else if (type == network::DataElement::TYPE_FILE) { diff --git a/atom/common/native_mate_converters/v8_value_converter.cc b/atom/common/native_mate_converters/v8_value_converter.cc index fbc410bdcb7..4662b1679b9 100644 --- a/atom/common/native_mate_converters/v8_value_converter.cc +++ b/atom/common/native_mate_converters/v8_value_converter.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include "base/logging.h" #include "base/values.h" @@ -345,8 +346,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state, if (val->IsRegExp()) { if (!reg_exp_allowed_) // JSON.stringify converts to an object. - return FromV8Object(val->ToObject(context).ToLocalChecked(), - state, isolate); + return FromV8Object(val->ToObject(context).ToLocalChecked(), state, + isolate); return new base::Value( *v8::String::Utf8Value(val->ToString(context).ToLocalChecked())); } @@ -359,8 +360,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state, if (!function_allowed_) // JSON.stringify refuses to convert function(){}. return nullptr; - return FromV8Object(val->ToObject(context).ToLocalChecked(), - state, isolate); + return FromV8Object(val->ToObject(context).ToLocalChecked(), state, + isolate); } if (node::Buffer::HasInstance(val)) { @@ -368,8 +369,8 @@ base::Value* V8ValueConverter::FromV8ValueImpl(FromV8ValueState* state, } if (val->IsObject()) { - return FromV8Object(val->ToObject(context).ToLocalChecked(), - state, isolate); + return FromV8Object(val->ToObject(context).ToLocalChecked(), state, + isolate); } LOG(ERROR) << "Unexpected v8 value type encountered."; @@ -418,9 +419,10 @@ base::Value* V8ValueConverter::FromV8Array(v8::Local val, base::Value* V8ValueConverter::FromNodeBuffer(v8::Local value, FromV8ValueState* state, v8::Isolate* isolate) const { - return base::Value::CreateWithCopiedBuffer(node::Buffer::Data(value), - node::Buffer::Length(value)) - .release(); + auto vec = std::vector( + node::Buffer::Data(value), + node::Buffer::Data(value) + node::Buffer::Length(value)); + return std::make_unique(vec).release(); } base::Value* V8ValueConverter::FromV8Object(v8::Local val,