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
|
|
|
|
2015-07-15 12:26:06 +00:00
|
|
|
#include "include/libplatform/libplatform.h"
|
2017-11-13 12:04:57 +00:00
|
|
|
#include "include/v8.h"
|
2018-07-23 11:42:37 +00:00
|
|
|
#include "src/api-inl.h"
|
2014-10-06 12:27:24 +00:00
|
|
|
#include "src/base/platform/time.h"
|
|
|
|
#include "src/flags.h"
|
2015-04-21 10:21:50 +00:00
|
|
|
#include "src/isolate.h"
|
2017-02-09 08:35:03 +00:00
|
|
|
#include "src/objects-inl.h"
|
2015-07-15 12:26:06 +00:00
|
|
|
#include "src/v8.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
2015-04-29 09:54:34 +00:00
|
|
|
// static
|
2016-06-29 07:39:45 +00:00
|
|
|
v8::ArrayBuffer::Allocator* TestWithIsolate::array_buffer_allocator_ = nullptr;
|
2015-04-29 09:54:34 +00:00
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
// static
|
2016-06-29 07:39:45 +00:00
|
|
|
Isolate* TestWithIsolate::isolate_ = nullptr;
|
2014-09-04 08:44:03 +00:00
|
|
|
|
|
|
|
TestWithIsolate::TestWithIsolate()
|
|
|
|
: isolate_scope_(isolate()), handle_scope_(isolate()) {}
|
|
|
|
|
|
|
|
|
|
|
|
TestWithIsolate::~TestWithIsolate() {}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
void TestWithIsolate::SetUpTestCase() {
|
|
|
|
Test::SetUpTestCase();
|
|
|
|
EXPECT_EQ(NULL, isolate_);
|
2018-02-17 07:44:01 +00:00
|
|
|
// Make BigInt64Array / BigUint64Array available for testing.
|
|
|
|
i::FLAG_harmony_bigint = true;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
2016-06-29 07:39:45 +00:00
|
|
|
array_buffer_allocator_ = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
|
2015-04-29 09:54:34 +00:00
|
|
|
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);
|
2015-07-15 12:26:06 +00:00
|
|
|
v8::Platform* platform = internal::V8::GetCurrentPlatform();
|
|
|
|
ASSERT_TRUE(platform != NULL);
|
|
|
|
while (platform::PumpMessageLoop(platform, isolate_)) continue;
|
2014-09-04 08:44:03 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2017-11-13 12:04:57 +00:00
|
|
|
Local<Value> TestWithIsolate::RunJS(const char* source) {
|
|
|
|
Local<Script> script =
|
|
|
|
v8::Script::Compile(
|
|
|
|
isolate()->GetCurrentContext(),
|
|
|
|
v8::String::NewFromUtf8(isolate(), source, v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked())
|
|
|
|
.ToLocalChecked();
|
|
|
|
return script->Run(isolate()->GetCurrentContext()).ToLocalChecked();
|
|
|
|
}
|
2014-09-04 08:44:03 +00:00
|
|
|
|
|
|
|
TestWithContext::TestWithContext()
|
|
|
|
: context_(Context::New(isolate())), context_scope_(context_) {}
|
|
|
|
|
|
|
|
TestWithContext::~TestWithContext() {}
|
|
|
|
|
2018-08-13 15:35:29 +00:00
|
|
|
v8::Local<v8::String> TestWithContext::NewString(const char* string) {
|
|
|
|
return v8::String::NewFromUtf8(v8_isolate(), string,
|
|
|
|
v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked();
|
|
|
|
}
|
|
|
|
|
2017-11-14 09:15:41 +00:00
|
|
|
void TestWithContext::SetGlobalProperty(const char* name,
|
|
|
|
v8::Local<v8::Value> value) {
|
|
|
|
CHECK(v8_context()
|
|
|
|
->Global()
|
2018-08-13 15:35:29 +00:00
|
|
|
->Set(v8_context(), NewString(name), value)
|
2017-11-14 09:15:41 +00:00
|
|
|
.FromJust());
|
|
|
|
}
|
|
|
|
|
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(); }
|
|
|
|
|
2018-07-20 09:19:29 +00:00
|
|
|
Handle<Object> TestWithIsolate::RunJSInternal(const char* source) {
|
|
|
|
return Utils::OpenHandle(*::v8::TestWithIsolate::RunJS(source));
|
|
|
|
}
|
|
|
|
|
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() {}
|
|
|
|
|
2016-10-10 05:53:31 +00:00
|
|
|
TestWithNativeContext::~TestWithNativeContext() {}
|
|
|
|
|
|
|
|
Handle<Context> TestWithNativeContext::native_context() const {
|
|
|
|
return isolate()->native_context();
|
|
|
|
}
|
|
|
|
|
2017-03-14 13:33:13 +00:00
|
|
|
SaveFlags::SaveFlags() { non_default_flags_ = FlagList::argv(); }
|
|
|
|
|
|
|
|
SaveFlags::~SaveFlags() {
|
|
|
|
FlagList::ResetAllFlags();
|
2017-08-30 07:24:59 +00:00
|
|
|
int argc = static_cast<int>(non_default_flags_->size());
|
2017-03-14 13:33:13 +00:00
|
|
|
FlagList::SetFlagsFromCommandLine(
|
2017-08-30 07:24:59 +00:00
|
|
|
&argc, const_cast<char**>(non_default_flags_->data()),
|
2017-03-14 13:33:13 +00:00
|
|
|
false /* remove_flags */);
|
|
|
|
for (auto flag = non_default_flags_->begin();
|
|
|
|
flag != non_default_flags_->end(); ++flag) {
|
|
|
|
delete[] * flag;
|
|
|
|
}
|
|
|
|
delete non_default_flags_;
|
|
|
|
}
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|