2014-09-04 08:44:03 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-10-01 08:34:25 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
|
2014-10-06 12:27:24 +00:00
|
|
|
#include "src/base/platform/time.h"
|
2015-04-21 10:21:50 +00:00
|
|
|
#include "src/debug.h"
|
2014-10-06 12:27:24 +00:00
|
|
|
#include "src/flags.h"
|
2015-04-21 10:21:50 +00:00
|
|
|
#include "src/isolate.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
2015-04-29 09:54:34 +00:00
|
|
|
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
|
|
|
|
public:
|
|
|
|
virtual void* Allocate(size_t length) {
|
|
|
|
void* data = AllocateUninitialized(length);
|
|
|
|
return data == NULL ? data : memset(data, 0, length);
|
|
|
|
}
|
|
|
|
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
|
|
|
|
virtual void Free(void* data, size_t) { free(data); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
ArrayBufferAllocator* TestWithIsolate::array_buffer_allocator_ = NULL;
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
// static
|
|
|
|
Isolate* TestWithIsolate::isolate_ = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
TestWithIsolate::TestWithIsolate()
|
|
|
|
: isolate_scope_(isolate()), handle_scope_(isolate()) {}
|
|
|
|
|
|
|
|
|
|
|
|
TestWithIsolate::~TestWithIsolate() {}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
void TestWithIsolate::SetUpTestCase() {
|
|
|
|
Test::SetUpTestCase();
|
|
|
|
EXPECT_EQ(NULL, isolate_);
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
array_buffer_allocator_ = new ArrayBufferAllocator;
|
|
|
|
create_params.array_buffer_allocator = array_buffer_allocator_;
|
|
|
|
isolate_ = v8::Isolate::New(create_params);
|
2014-09-04 08:44:03 +00:00
|
|
|
EXPECT_TRUE(isolate_ != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
void TestWithIsolate::TearDownTestCase() {
|
|
|
|
ASSERT_TRUE(isolate_ != NULL);
|
|
|
|
isolate_->Dispose();
|
|
|
|
isolate_ = NULL;
|
2015-04-29 09:54:34 +00:00
|
|
|
delete array_buffer_allocator_;
|
2014-09-04 08:44:03 +00:00
|
|
|
Test::TearDownTestCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TestWithContext::TestWithContext()
|
|
|
|
: context_(Context::New(isolate())), context_scope_(context_) {}
|
|
|
|
|
|
|
|
|
|
|
|
TestWithContext::~TestWithContext() {}
|
|
|
|
|
|
|
|
|
2014-10-06 12:27:24 +00:00
|
|
|
namespace base {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
inline int64_t GetRandomSeedFromFlag(int random_seed) {
|
|
|
|
return random_seed ? random_seed : TimeTicks::Now().ToInternalValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TestWithRandomNumberGenerator::TestWithRandomNumberGenerator()
|
|
|
|
: rng_(GetRandomSeedFromFlag(internal::FLAG_random_seed)) {}
|
|
|
|
|
|
|
|
|
|
|
|
TestWithRandomNumberGenerator::~TestWithRandomNumberGenerator() {}
|
|
|
|
|
|
|
|
} // namespace base
|
|
|
|
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
TestWithIsolate::~TestWithIsolate() {}
|
|
|
|
|
2015-01-23 16:29:50 +00:00
|
|
|
TestWithIsolateAndZone::~TestWithIsolateAndZone() {}
|
2014-09-04 08:44:03 +00:00
|
|
|
|
|
|
|
Factory* TestWithIsolate::factory() const { return isolate()->factory(); }
|
|
|
|
|
|
|
|
|
2014-12-02 04:48:57 +00:00
|
|
|
base::RandomNumberGenerator* TestWithIsolate::random_number_generator() const {
|
|
|
|
return isolate()->random_number_generator();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
TestWithZone::~TestWithZone() {}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|