refactor: remove deprecated CreateWithCopiedBuffer (#13436)

* refactor: remove deprecated CreateWithCopiedBuffer

* fix: add missing vector includes

* fix std::vector<char> allocation
This commit is contained in:
Shelley Vohr 2018-06-26 15:08:27 -07:00 committed by GitHub
parent 39e6943f1e
commit 1dde9492c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 13 deletions

View file

@ -239,8 +239,10 @@ void GetUploadData(base::ListValue* upload_data_list,
if (reader->AsBytesReader()) {
const net::UploadBytesElementReader* bytes_reader =
reader->AsBytesReader();
std::unique_ptr<base::Value> bytes(base::Value::CreateWithCopiedBuffer(
bytes_reader->bytes(), bytes_reader->length()));
auto vec =
std::vector<char>(bytes_reader->bytes(),
bytes_reader->bytes() + bytes_reader->length());
auto bytes = std::make_unique<base::Value>(vec);
upload_data_dict->Set("bytes", std::move(bytes));
} else if (reader->AsFileReader()) {
const net::UploadFileElementReader* file_reader = reader->AsFileReader();

View file

@ -6,6 +6,7 @@
#include <string>
#include <utility>
#include <vector>
#include "atom/common/native_mate_converters/value_converter.h"
#include "native_mate/dictionary.h"
@ -25,8 +26,10 @@ Converter<scoped_refptr<network::ResourceRequestBody>>::ToV8(
auto post_data_dict = std::make_unique<base::DictionaryValue>();
auto type = element.type();
if (type == network::DataElement::TYPE_BYTES) {
auto bytes = base::Value::CreateWithCopiedBuffer(
element.bytes(), static_cast<size_t>(element.length()));
auto vec = std::vector<char>(
element.bytes(),
element.bytes() + static_cast<size_t>(element.length()));
auto bytes = std::make_unique<base::Value>(vec);
post_data_dict->SetString("type", "rawData");
post_data_dict->Set("bytes", std::move(bytes));
} else if (type == network::DataElement::TYPE_FILE) {

View file

@ -8,6 +8,7 @@
#include <memory>
#include <string>
#include <utility>
#include <vector>
#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<v8::Array> val,
base::Value* V8ValueConverter::FromNodeBuffer(v8::Local<v8::Value> value,
FromV8ValueState* state,
v8::Isolate* isolate) const {
return base::Value::CreateWithCopiedBuffer(node::Buffer::Data(value),
node::Buffer::Length(value))
.release();
auto vec = std::vector<char>(
node::Buffer::Data(value),
node::Buffer::Data(value) + node::Buffer::Length(value));
return std::make_unique<base::Value>(vec).release();
}
base::Value* V8ValueConverter::FromV8Object(v8::Local<v8::Object> val,