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

Side by Side Diff: test/unittests/test-utils.cc

Issue 2101413002: Provide a convenience array buffer allocator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 5 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 | « test/unittests/test-utils.h ('k') | tools/parser-shell.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 "test/unittests/test-utils.h" 5 #include "test/unittests/test-utils.h"
6 6
7 #include "include/libplatform/libplatform.h" 7 #include "include/libplatform/libplatform.h"
8 #include "src/base/platform/time.h" 8 #include "src/base/platform/time.h"
9 #include "src/debug/debug.h" 9 #include "src/debug/debug.h"
10 #include "src/flags.h" 10 #include "src/flags.h"
11 #include "src/isolate.h" 11 #include "src/isolate.h"
12 #include "src/v8.h" 12 #include "src/v8.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 15
16 class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { 16 // static
17 public: 17 v8::ArrayBuffer::Allocator* TestWithIsolate::array_buffer_allocator_ = nullptr;
18 virtual void* Allocate(size_t length) {
19 void* data = AllocateUninitialized(length);
20 return data == NULL ? data : memset(data, 0, length);
21 }
22 virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
23 virtual void Free(void* data, size_t) { free(data); }
24 };
25
26 18
27 // static 19 // static
28 ArrayBufferAllocator* TestWithIsolate::array_buffer_allocator_ = NULL; 20 Isolate* TestWithIsolate::isolate_ = nullptr;
29
30 // static
31 Isolate* TestWithIsolate::isolate_ = NULL;
32
33 21
34 TestWithIsolate::TestWithIsolate() 22 TestWithIsolate::TestWithIsolate()
35 : isolate_scope_(isolate()), handle_scope_(isolate()) {} 23 : isolate_scope_(isolate()), handle_scope_(isolate()) {}
36 24
37 25
38 TestWithIsolate::~TestWithIsolate() {} 26 TestWithIsolate::~TestWithIsolate() {}
39 27
40 28
41 // static 29 // static
42 void TestWithIsolate::SetUpTestCase() { 30 void TestWithIsolate::SetUpTestCase() {
43 Test::SetUpTestCase(); 31 Test::SetUpTestCase();
44 EXPECT_EQ(NULL, isolate_); 32 EXPECT_EQ(NULL, isolate_);
45 v8::Isolate::CreateParams create_params; 33 v8::Isolate::CreateParams create_params;
46 array_buffer_allocator_ = new ArrayBufferAllocator; 34 array_buffer_allocator_ = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
47 create_params.array_buffer_allocator = array_buffer_allocator_; 35 create_params.array_buffer_allocator = array_buffer_allocator_;
48 isolate_ = v8::Isolate::New(create_params); 36 isolate_ = v8::Isolate::New(create_params);
49 EXPECT_TRUE(isolate_ != NULL); 37 EXPECT_TRUE(isolate_ != NULL);
50 } 38 }
51 39
52 40
53 // static 41 // static
54 void TestWithIsolate::TearDownTestCase() { 42 void TestWithIsolate::TearDownTestCase() {
55 ASSERT_TRUE(isolate_ != NULL); 43 ASSERT_TRUE(isolate_ != NULL);
56 v8::Platform* platform = internal::V8::GetCurrentPlatform(); 44 v8::Platform* platform = internal::V8::GetCurrentPlatform();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 87
100 base::RandomNumberGenerator* TestWithIsolate::random_number_generator() const { 88 base::RandomNumberGenerator* TestWithIsolate::random_number_generator() const {
101 return isolate()->random_number_generator(); 89 return isolate()->random_number_generator();
102 } 90 }
103 91
104 92
105 TestWithZone::~TestWithZone() {} 93 TestWithZone::~TestWithZone() {}
106 94
107 } // namespace internal 95 } // namespace internal
108 } // namespace v8 96 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/test-utils.h ('k') | tools/parser-shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698