Chromium Code Reviews| Index: test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc |
| diff --git a/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc b/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc |
| index 246645aea93d2d0e62b3af5d86da396ce95c7dcc..921d65ad0bcb4d08a3bd3baa829baa680167263c 100644 |
| --- a/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc |
| +++ b/test/unittests/compiler-dispatcher/compiler-dispatcher-unittest.cc |
| @@ -21,34 +21,72 @@ |
| namespace v8 { |
| namespace internal { |
| +class CompilerDispatcherTestFlags { |
| + public: |
| + static void SetFlagsForTest() { |
| + old_compiler_dispatcher_flag_ = i::FLAG_compiler_dispatcher; |
| + i::FLAG_compiler_dispatcher = true; |
| + old_ignition_flag_ = i::FLAG_ignition; |
| + i::FLAG_ignition = true; |
| + old_allow_natives_syntax_flag_ = i::FLAG_allow_natives_syntax; |
| + i::FLAG_allow_natives_syntax = true; |
| + } |
| + |
| + static void RestoreFlags() { |
| + i::FLAG_compiler_dispatcher = old_compiler_dispatcher_flag_; |
| + i::FLAG_ignition = old_ignition_flag_; |
| + i::FLAG_allow_natives_syntax = old_allow_natives_syntax_flag_; |
| + } |
| + |
| + private: |
| + static bool old_compiler_dispatcher_flag_; |
| + static bool old_ignition_flag_; |
| + static bool old_allow_natives_syntax_flag_; |
| + |
| + DISALLOW_IMPLICIT_CONSTRUCTORS(CompilerDispatcherTestFlags); |
| +}; |
| + |
| +bool CompilerDispatcherTestFlags::old_compiler_dispatcher_flag_; |
| +bool CompilerDispatcherTestFlags::old_ignition_flag_; |
| +bool CompilerDispatcherTestFlags::old_allow_natives_syntax_flag_; |
| + |
| class CompilerDispatcherTest : public TestWithContext { |
| public: |
| CompilerDispatcherTest() = default; |
| ~CompilerDispatcherTest() override = default; |
| static void SetUpTestCase() { |
| - old_flag_ = i::FLAG_ignition; |
| - i::FLAG_compiler_dispatcher = true; |
| - old_ignition_flag_ = i::FLAG_ignition; |
| - i::FLAG_ignition = true; |
| + CompilerDispatcherTestFlags::SetFlagsForTest(); |
| TestWithContext::SetUpTestCase(); |
| } |
| static void TearDownTestCase() { |
| TestWithContext::TearDownTestCase(); |
| - i::FLAG_compiler_dispatcher = old_flag_; |
| - i::FLAG_ignition = old_ignition_flag_; |
| + CompilerDispatcherTestFlags::RestoreFlags(); |
| } |
| private: |
| - static bool old_flag_; |
| - static bool old_ignition_flag_; |
| - |
| DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherTest); |
| }; |
| -bool CompilerDispatcherTest::old_flag_; |
| -bool CompilerDispatcherTest::old_ignition_flag_; |
| +class CompilerDispatcherTestWithoutContext : public v8::TestWithIsolate { |
| + public: |
| + CompilerDispatcherTestWithoutContext() = default; |
| + ~CompilerDispatcherTestWithoutContext() override = default; |
| + |
| + static void SetUpTestCase() { |
| + CompilerDispatcherTestFlags::SetFlagsForTest(); |
| + TestWithContext::SetUpTestCase(); |
| + } |
| + |
| + static void TearDownTestCase() { |
| + TestWithContext::TearDownTestCase(); |
| + CompilerDispatcherTestFlags::RestoreFlags(); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(CompilerDispatcherTestWithoutContext); |
| +}; |
| namespace { |
| @@ -900,5 +938,65 @@ TEST_F(CompilerDispatcherTest, FinishAllNow) { |
| platform.ClearIdleTask(); |
| } |
| +static const char kExtensionSource[] = "native function Dummy();"; |
|
jochen (gone - plz use gerrit)
2017/02/08 18:52:58
put this (and the class) in an anonymous namespace
rmcilroy
2017/02/08 22:49:23
Done.
|
| + |
| +class MockNativeFunctionExtension : public Extension { |
| + public: |
| + MockNativeFunctionExtension() |
| + : Extension("mock-extension", kExtensionSource), function_(&Dummy) {} |
| + |
| + virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate( |
| + v8::Isolate* isolate, v8::Local<v8::String> name) { |
| + return v8::FunctionTemplate::New(isolate, function_); |
| + } |
| + |
| + static void Dummy(const v8::FunctionCallbackInfo<v8::Value>& args) { return; } |
| + |
| + private: |
| + v8::FunctionCallback function_; |
| +}; |
|
jochen (gone - plz use gerrit)
2017/02/08 18:52:58
disallow copy/assign
rmcilroy
2017/02/08 22:49:23
Done.
|
| + |
| +TEST_F(CompilerDispatcherTestWithoutContext, CompileExtensionWithoutContext) { |
| + MockPlatform platform; |
| + CompilerDispatcher dispatcher(i_isolate(), &platform, FLAG_stack_size); |
| + Local<v8::Context> context = v8::Context::New(isolate()); |
| + |
| + MockNativeFunctionExtension extension; |
| + Handle<String> script_str = |
| + i_isolate() |
| + ->factory() |
| + ->NewStringFromUtf8(CStrVector(kExtensionSource)) |
| + .ToHandleChecked(); |
| + Handle<Script> script = i_isolate()->factory()->NewScript(script_str); |
| + script->set_type(Script::TYPE_EXTENSION); |
| + |
| + ParseInfo parse_info(script); |
| + parse_info.set_extension(&extension); |
| + |
| + std::shared_ptr<DeferredHandles> handles; |
| + Handle<SharedFunctionInfo> shared; |
| + { |
| + v8::Context::Scope scope(context); |
| + ASSERT_TRUE(Compiler::ParseAndAnalyze(&parse_info)); |
| + |
| + shared = i_isolate()->factory()->NewSharedFunctionInfoForLiteral( |
| + parse_info.literal(), script); |
| + parse_info.set_shared_info(shared); |
| + |
| + ASSERT_FALSE(platform.IdleTaskPending()); |
| + ASSERT_TRUE(dispatcher.Enqueue(shared, parse_info.literal(), |
| + parse_info.zone_shared(), handles, handles)); |
| + ASSERT_TRUE(platform.IdleTaskPending()); |
| + } |
| + // Exit the context scope before running the idle task. |
| + |
| + // Since time doesn't progress on the MockPlatform, this is enough idle time |
| + // to finish compiling the function. |
| + platform.RunIdleTask(1000.0, 0.0); |
| + |
| + ASSERT_FALSE(dispatcher.IsEnqueued(shared)); |
| + ASSERT_TRUE(shared->is_compiled()); |
| +} |
| + |
| } // namespace internal |
| } // namespace v8 |