Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: content/child/v8_value_converter_impl.cc

Issue 2799093006: Remove base::BinaryValue (Closed)
Patch Set: Rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/v8_value_converter_impl.h" 5 #include "content/child/v8_value_converter_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 if (!maybe.IsJust() || !maybe.FromJust()) 332 if (!maybe.IsJust() || !maybe.FromJust())
333 LOG(ERROR) << "Failed to set property with key " << key; 333 LOG(ERROR) << "Failed to set property with key " << key;
334 } 334 }
335 335
336 return result; 336 return result;
337 } 337 }
338 338
339 v8::Local<v8::Value> V8ValueConverterImpl::ToArrayBuffer( 339 v8::Local<v8::Value> V8ValueConverterImpl::ToArrayBuffer(
340 v8::Isolate* isolate, 340 v8::Isolate* isolate,
341 v8::Local<v8::Object> creation_context, 341 v8::Local<v8::Object> creation_context,
342 const base::BinaryValue* value) const { 342 const base::Value* value) const {
343 DCHECK(creation_context->CreationContext() == isolate->GetCurrentContext()); 343 DCHECK(creation_context->CreationContext() == isolate->GetCurrentContext());
344 v8::Local<v8::ArrayBuffer> buffer = 344 v8::Local<v8::ArrayBuffer> buffer =
345 v8::ArrayBuffer::New(isolate, value->GetSize()); 345 v8::ArrayBuffer::New(isolate, value->GetSize());
346 memcpy(buffer->GetContents().Data(), value->GetBuffer(), value->GetSize()); 346 memcpy(buffer->GetContents().Data(), value->GetBuffer(), value->GetSize());
347 return buffer; 347 return buffer;
348 } 348 }
349 349
350 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8ValueImpl( 350 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8ValueImpl(
351 FromV8ValueState* state, 351 FromV8ValueState* state,
352 v8::Local<v8::Value> val, 352 v8::Local<v8::Value> val,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 v8::Local<v8::Object> val, 495 v8::Local<v8::Object> val,
496 v8::Isolate* isolate) const { 496 v8::Isolate* isolate) const {
497 if (strategy_) { 497 if (strategy_) {
498 std::unique_ptr<base::Value> out; 498 std::unique_ptr<base::Value> out;
499 if (strategy_->FromV8ArrayBuffer(val, &out, isolate)) 499 if (strategy_->FromV8ArrayBuffer(val, &out, isolate))
500 return out; 500 return out;
501 } 501 }
502 502
503 if (val->IsArrayBuffer()) { 503 if (val->IsArrayBuffer()) {
504 auto contents = val.As<v8::ArrayBuffer>()->GetContents(); 504 auto contents = val.As<v8::ArrayBuffer>()->GetContents();
505 return base::BinaryValue::CreateWithCopiedBuffer( 505 return base::Value::CreateWithCopiedBuffer(
506 static_cast<const char*>(contents.Data()), contents.ByteLength()); 506 static_cast<const char*>(contents.Data()), contents.ByteLength());
507 } else if (val->IsArrayBufferView()) { 507 } else if (val->IsArrayBufferView()) {
508 v8::Local<v8::ArrayBufferView> view = val.As<v8::ArrayBufferView>(); 508 v8::Local<v8::ArrayBufferView> view = val.As<v8::ArrayBufferView>();
509 size_t byte_length = view->ByteLength(); 509 size_t byte_length = view->ByteLength();
510 std::vector<char> buffer(byte_length); 510 std::vector<char> buffer(byte_length);
511 view->CopyContents(buffer.data(), buffer.size()); 511 view->CopyContents(buffer.data(), buffer.size());
512 return base::MakeUnique<base::BinaryValue>(std::move(buffer)); 512 return base::MakeUnique<base::Value>(std::move(buffer));
513 } else { 513 } else {
514 NOTREACHED() << "Only ArrayBuffer and ArrayBufferView should get here."; 514 NOTREACHED() << "Only ArrayBuffer and ArrayBufferView should get here.";
515 return nullptr; 515 return nullptr;
516 } 516 }
517 } 517 }
518 518
519 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8Object( 519 std::unique_ptr<base::Value> V8ValueConverterImpl::FromV8Object(
520 v8::Local<v8::Object> val, 520 v8::Local<v8::Object> val,
521 FromV8ValueState* state, 521 FromV8ValueState* state,
522 v8::Isolate* isolate) const { 522 v8::Isolate* isolate) const {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 continue; 615 continue;
616 616
617 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), 617 result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()),
618 std::move(child)); 618 std::move(child));
619 } 619 }
620 620
621 return std::move(result); 621 return std::move(result);
622 } 622 }
623 623
624 } // namespace content 624 } // namespace content
OLDNEW
« no previous file with comments | « content/child/v8_value_converter_impl.h ('k') | content/child/v8_value_converter_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698