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

Side by Side Diff: src/api.cc

Issue 1116633002: Pass ArrayBuffer::Allocator via Isolate::CreateParams (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « samples/shell.cc ('k') | src/bootstrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project 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 "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 script->Run(); 313 script->Run();
314 if (i::FLAG_profile_deserialization) { 314 if (i::FLAG_profile_deserialization) {
315 i::PrintF("Executing custom snapshot script took %0.3f ms\n", 315 i::PrintF("Executing custom snapshot script took %0.3f ms\n",
316 timer.Elapsed().InMillisecondsF()); 316 timer.Elapsed().InMillisecondsF());
317 } 317 }
318 timer.Stop(); 318 timer.Stop();
319 return !try_catch.HasCaught(); 319 return !try_catch.HasCaught();
320 } 320 }
321 321
322 322
323 namespace {
324
325 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
326 public:
327 virtual void* Allocate(size_t length) {
328 void* data = AllocateUninitialized(length);
329 return data == NULL ? data : memset(data, 0, length);
330 }
331 virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
332 virtual void Free(void* data, size_t) { free(data); }
333 };
334
335 } // namespace
336
337
323 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { 338 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) {
324 i::Isolate* internal_isolate = new i::Isolate(true); 339 i::Isolate* internal_isolate = new i::Isolate(true);
340 ArrayBufferAllocator allocator;
341 internal_isolate->set_array_buffer_allocator(&allocator);
325 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); 342 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate);
326 StartupData result = {NULL, 0}; 343 StartupData result = {NULL, 0};
327 { 344 {
328 base::ElapsedTimer timer; 345 base::ElapsedTimer timer;
329 timer.Start(); 346 timer.Start();
330 Isolate::Scope isolate_scope(isolate); 347 Isolate::Scope isolate_scope(isolate);
331 internal_isolate->Init(NULL); 348 internal_isolate->Init(NULL);
332 Persistent<Context> context; 349 Persistent<Context> context;
333 i::Snapshot::Metadata metadata; 350 i::Snapshot::Metadata metadata;
334 { 351 {
(...skipping 6400 matching lines...) Expand 10 before | Expand all | Expand 10 after
6735 } 6752 }
6736 } 6753 }
6737 6754
6738 6755
6739 Isolate* Isolate::GetCurrent() { 6756 Isolate* Isolate::GetCurrent() {
6740 i::Isolate* isolate = i::Isolate::Current(); 6757 i::Isolate* isolate = i::Isolate::Current();
6741 return reinterpret_cast<Isolate*>(isolate); 6758 return reinterpret_cast<Isolate*>(isolate);
6742 } 6759 }
6743 6760
6744 6761
6762 Isolate* Isolate::New() {
6763 Isolate::CreateParams create_params;
6764 return New(create_params);
6765 }
6766
6767
6745 Isolate* Isolate::New(const Isolate::CreateParams& params) { 6768 Isolate* Isolate::New(const Isolate::CreateParams& params) {
6746 i::Isolate* isolate = new i::Isolate(false); 6769 i::Isolate* isolate = new i::Isolate(false);
6747 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); 6770 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
6771 if (params.array_buffer_allocator != NULL) {
6772 isolate->set_array_buffer_allocator(params.array_buffer_allocator);
6773 } else {
6774 isolate->set_array_buffer_allocator(i::V8::ArrayBufferAllocator());
6775 }
6748 if (params.snapshot_blob != NULL) { 6776 if (params.snapshot_blob != NULL) {
6749 isolate->set_snapshot_blob(params.snapshot_blob); 6777 isolate->set_snapshot_blob(params.snapshot_blob);
6750 } else { 6778 } else {
6751 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob()); 6779 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob());
6752 } 6780 }
6753 if (params.entry_hook) { 6781 if (params.entry_hook) {
6754 isolate->set_function_entry_hook(params.entry_hook); 6782 isolate->set_function_entry_hook(params.entry_hook);
6755 } 6783 }
6756 if (params.code_event_handler) { 6784 if (params.code_event_handler) {
6757 isolate->InitializeLoggingAndCounters(); 6785 isolate->InitializeLoggingAndCounters();
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
8012 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8040 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8013 Address callback_address = 8041 Address callback_address =
8014 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8042 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8015 VMState<EXTERNAL> state(isolate); 8043 VMState<EXTERNAL> state(isolate);
8016 ExternalCallbackScope call_scope(isolate, callback_address); 8044 ExternalCallbackScope call_scope(isolate, callback_address);
8017 callback(info); 8045 callback(info);
8018 } 8046 }
8019 8047
8020 8048
8021 } } // namespace v8::internal 8049 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « samples/shell.cc ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698