OLD | NEW |
---|---|
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" | 7 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
8 #include "src/flags.h" | 8 #include "src/flags.h" |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 #include "test/unittests/test-utils.h" | 10 #include "test/unittests/test-utils.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 ->NewExternalStringFromOneByte(maybe_resource) | 42 ->NewExternalStringFromOneByte(maybe_resource) |
43 .ToHandleChecked(); | 43 .ToHandleChecked(); |
44 } else { | 44 } else { |
45 source = isolate->factory()->NewStringFromStaticChars("source"); | 45 source = isolate->factory()->NewStringFromStaticChars("source"); |
46 } | 46 } |
47 Handle<Script> script = isolate->factory()->NewScript(source); | 47 Handle<Script> script = isolate->factory()->NewScript(source); |
48 Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo( | 48 Handle<SharedFunctionInfo> shared = isolate->factory()->NewSharedFunctionInfo( |
49 isolate->factory()->NewStringFromStaticChars("f"), MaybeHandle<Code>(), | 49 isolate->factory()->NewStringFromStaticChars("f"), MaybeHandle<Code>(), |
50 false); | 50 false); |
51 SharedFunctionInfo::SetScript(shared, script); | 51 SharedFunctionInfo::SetScript(shared, script); |
52 shared->set_end_position(source->length() - 1); | |
jochen (gone - plz use gerrit)
2016/07/29 12:23:31
is that correct? or should it be just source->leng
| |
52 Handle<JSFunction> function = | 53 Handle<JSFunction> function = |
53 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 54 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
54 shared, handle(isolate->context(), isolate)); | 55 shared, handle(isolate->context(), isolate)); |
55 return scope.CloseAndEscape(function); | 56 return scope.CloseAndEscape(function); |
56 } | 57 } |
57 | 58 |
58 } // namespace | 59 } // namespace |
59 | 60 |
60 TEST_F(CompilerDispatcherJobTest, Construct) { | 61 TEST_F(CompilerDispatcherJobTest, Construct) { |
61 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate()); | |
62 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 62 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
63 i_isolate, CreateFunction(i_isolate, nullptr), FLAG_stack_size)); | 63 i_isolate(), CreateFunction(i_isolate(), nullptr), FLAG_stack_size)); |
64 } | 64 } |
65 | 65 |
66 TEST_F(CompilerDispatcherJobTest, CanParseOnBackgroundThread) { | 66 TEST_F(CompilerDispatcherJobTest, CanParseOnBackgroundThread) { |
67 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate()); | |
68 { | 67 { |
69 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 68 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
70 i_isolate, CreateFunction(i_isolate, nullptr), FLAG_stack_size)); | 69 i_isolate(), CreateFunction(i_isolate(), nullptr), FLAG_stack_size)); |
71 ASSERT_FALSE(job->can_parse_on_background_thread()); | 70 ASSERT_FALSE(job->can_parse_on_background_thread()); |
72 } | 71 } |
73 { | 72 { |
74 ScriptResource script("script", strlen("script")); | 73 ScriptResource script("script", strlen("script")); |
75 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 74 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
76 i_isolate, CreateFunction(i_isolate, &script), FLAG_stack_size)); | 75 i_isolate(), CreateFunction(i_isolate(), &script), FLAG_stack_size)); |
77 ASSERT_TRUE(job->can_parse_on_background_thread()); | 76 ASSERT_TRUE(job->can_parse_on_background_thread()); |
vogelheim
2016/07/29 12:46:18
How can this still work? I don't think this var is
jochen (gone - plz use gerrit)
2016/07/29 12:49:42
it's set in the ctor of the job
| |
78 } | 77 } |
79 } | 78 } |
80 | 79 |
81 TEST_F(CompilerDispatcherJobTest, StateTransitions) { | 80 TEST_F(CompilerDispatcherJobTest, StateTransitions) { |
82 Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate()); | |
83 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | 81 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
84 i_isolate, CreateFunction(i_isolate, nullptr), FLAG_stack_size)); | 82 i_isolate(), CreateFunction(i_isolate(), nullptr), FLAG_stack_size)); |
85 | 83 |
86 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); | 84 ASSERT_TRUE(job->status() == CompileJobStatus::kInitial); |
87 job->PrepareToParseOnMainThread(); | 85 job->PrepareToParseOnMainThread(); |
88 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse); | 86 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToParse); |
89 job->Parse(); | 87 job->Parse(); |
90 ASSERT_TRUE(job->status() == CompileJobStatus::kParsed); | 88 ASSERT_TRUE(job->status() == CompileJobStatus::kParsed); |
89 job->FinalizeParsingOnMainThread(); | |
90 ASSERT_TRUE(job->status() == CompileJobStatus::kReadyToCompile); | |
91 } | |
92 | |
93 TEST_F(CompilerDispatcherJobTest, SyntaxError) { | |
94 ScriptResource script("^^^", strlen("^^^")); | |
95 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | |
96 i_isolate(), CreateFunction(i_isolate(), &script), FLAG_stack_size)); | |
97 | |
98 job->PrepareToParseOnMainThread(); | |
99 job->Parse(); | |
100 job->FinalizeParsingOnMainThread(); | |
101 | |
102 ASSERT_TRUE(job->status() == CompileJobStatus::kFailed); | |
103 ASSERT_FALSE(i_isolate()->has_pending_exception()); | |
104 job->ReportErrorsOnMainThread(); | |
105 ASSERT_TRUE(job->status() == CompileJobStatus::kDone); | |
106 ASSERT_TRUE(i_isolate()->has_pending_exception()); | |
91 } | 107 } |
92 | 108 |
93 } // namespace internal | 109 } // namespace internal |
94 } // namespace v8 | 110 } // namespace v8 |
OLD | NEW |