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

Unified Diff: test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc

Issue 2190333002: Teach compiler jobs how to actually parse (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
diff --git a/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc b/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
index a2b7c8f0e27015ec31132472a0b274ab6881530c..6c5f24e1c12a008bfadca8d2b1c91d2bdcc84a19 100644
--- a/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
+++ b/test/unittests/compiler-dispatcher/compiler-dispatcher-job-unittest.cc
@@ -5,6 +5,7 @@
#include <memory>
#include "src/compiler-dispatcher/compiler-dispatcher-job.h"
+#include "src/flags.h"
#include "src/isolate-inl.h"
#include "test/unittests/test-utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -14,20 +15,78 @@ namespace internal {
typedef TestWithContext CompilerDispatcherJobTest;
+namespace {
+
+class ScriptResource : public v8::String::ExternalOneByteStringResource {
+ public:
+ ScriptResource(const char* data, size_t length)
+ : data_(data), length_(length) {}
+
+ const char* data() const { return data_; }
+ size_t length() const { return length_; }
+
+ private:
+ const char* data_;
+ size_t length_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScriptResource);
+};
+
+Handle<JSFunction> CreateFunction(
+ Isolate* isolate, ExternalOneByteString::Resource* maybe_resource) {
+ HandleScope scope(isolate);
+ Handle<String> source;
+ if (maybe_resource) {
+ source = isolate->factory()
+ ->NewExternalStringFromOneByte(maybe_resource)
+ .ToHandleChecked();
+ } else {
+ source = isolate->factory()->NewStringFromStaticChars("source");
+ }
+ Handle<Script> script = isolate->factory()->NewScript(source);
+ Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo(
+ isolate->factory()->NewStringFromStaticChars("f"), MaybeHandle<Code>(),
+ false);
+ SharedFunctionInfo::SetScript(shared, script);
+ Handle<JSFunction> function =
+ isolate->factory()->NewFunctionFromSharedFunctionInfo(
+ shared, handle(isolate->context(), isolate));
+ return scope.CloseAndEscape(function);
+}
+
+} // namespace
+
TEST_F(CompilerDispatcherJobTest, Construct) {
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate());
- std::unique_ptr<CompilerDispatcherJob> job(
- new CompilerDispatcherJob(i_isolate, i_isolate->object_function()));
+ std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
+ i_isolate, CreateFunction(i_isolate, nullptr), FLAG_stack_size));
+}
+
+TEST_F(CompilerDispatcherJobTest, CanParseOnBackgroundThread) {
+ Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate());
+ {
+ std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
+ i_isolate, CreateFunction(i_isolate, nullptr), FLAG_stack_size));
+ ASSERT_FALSE(job->can_parse_on_background_thread());
+ }
+ {
+ ScriptResource script("script", strlen("script"));
+ std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
+ i_isolate, CreateFunction(i_isolate, &script), FLAG_stack_size));
+ ASSERT_TRUE(job->can_parse_on_background_thread());
+ }
}
-TEST_F(CompilerDispatcherJobTest, PrepareToParse) {
+TEST_F(CompilerDispatcherJobTest, StateTransitions) {
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate());
- std::unique_ptr<CompilerDispatcherJob> job(
- new CompilerDispatcherJob(i_isolate, i_isolate->object_function()));
+ std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
+ i_isolate, CreateFunction(i_isolate, nullptr), FLAG_stack_size));
ASSERT_TRUE(job->status() == CompileJobStatus::kInitial);
job->PrepareToParseOnMainThread();
ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse);
+ job->Parse();
+ ASSERT_TRUE(job->status() == CompileJobStatus::kParsed);
}
} // namespace internal

Powered by Google App Engine
This is Rietveld 408576698