OLD | NEW |
---|---|
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // TODO(mythria): Remove this define after this flag is turned on globally | |
29 #define V8_IMMINENT_DEPRECATION_WARNINGS | |
30 | |
28 #include "src/v8.h" | 31 #include "src/v8.h" |
29 #include "test/cctest/cctest.h" | 32 #include "test/cctest/cctest.h" |
30 | 33 |
31 #include "src/base/platform/platform.h" | 34 #include "src/base/platform/platform.h" |
32 | 35 |
33 | 36 |
34 v8::base::Semaphore* semaphore = NULL; | 37 v8::base::Semaphore* semaphore = NULL; |
35 | 38 |
36 | 39 |
37 void Signal(const v8::FunctionCallbackInfo<v8::Value>& args) { | 40 void Signal(const v8::FunctionCallbackInfo<v8::Value>& args) { |
38 semaphore->Signal(); | 41 semaphore->Signal(); |
39 } | 42 } |
40 | 43 |
41 | 44 |
42 void TerminateCurrentThread(const v8::FunctionCallbackInfo<v8::Value>& args) { | 45 void TerminateCurrentThread(const v8::FunctionCallbackInfo<v8::Value>& args) { |
43 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 46 CHECK(!args.GetIsolate()->IsExecutionTerminating()); |
44 v8::V8::TerminateExecution(args.GetIsolate()); | 47 args.GetIsolate()->TerminateExecution(); |
45 } | 48 } |
46 | 49 |
47 | 50 |
48 void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { | 51 void Fail(const v8::FunctionCallbackInfo<v8::Value>& args) { |
49 CHECK(false); | 52 CHECK(false); |
50 } | 53 } |
51 | 54 |
52 | 55 |
53 void Loop(const v8::FunctionCallbackInfo<v8::Value>& args) { | 56 void Loop(const v8::FunctionCallbackInfo<v8::Value>& args) { |
54 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 57 CHECK(!args.GetIsolate()->IsExecutionTerminating()); |
55 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 58 v8::MaybeLocal<v8::Value> result = |
56 args.GetIsolate(), "try { doloop(); fail(); } catch(e) { fail(); }"); | 59 CompileRun(args.GetIsolate()->GetCurrentContext(), |
57 v8::Handle<v8::Value> result = v8::Script::Compile(source)->Run(); | 60 "try { doloop(); fail(); } catch(e) { fail(); }"); |
58 CHECK(result.IsEmpty()); | 61 CHECK(result.IsEmpty()); |
59 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 62 CHECK(args.GetIsolate()->IsExecutionTerminating()); |
60 } | 63 } |
61 | 64 |
62 | 65 |
63 void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) { | 66 void DoLoop(const v8::FunctionCallbackInfo<v8::Value>& args) { |
64 v8::TryCatch try_catch(args.GetIsolate()); | 67 v8::TryCatch try_catch(args.GetIsolate()); |
65 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 68 CHECK(!args.GetIsolate()->IsExecutionTerminating()); |
66 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), | 69 v8::MaybeLocal<v8::Value> result = |
67 "function f() {" | 70 CompileRun(args.GetIsolate()->GetCurrentContext(), |
68 " var term = true;" | 71 "function f() {" |
69 " try {" | 72 " var term = true;" |
70 " while(true) {" | 73 " try {" |
71 " if (term) terminate();" | 74 " while(true) {" |
72 " term = false;" | 75 " if (term) terminate();" |
73 " }" | 76 " term = false;" |
74 " fail();" | 77 " }" |
75 " } catch(e) {" | 78 " fail();" |
76 " fail();" | 79 " } catch(e) {" |
77 " }" | 80 " fail();" |
78 "}" | 81 " }" |
79 "f()"))->Run(); | 82 "}" |
83 "f()"); | |
84 CHECK(result.IsEmpty()); | |
80 CHECK(try_catch.HasCaught()); | 85 CHECK(try_catch.HasCaught()); |
81 CHECK(try_catch.Exception()->IsNull()); | 86 CHECK(try_catch.Exception()->IsNull()); |
82 CHECK(try_catch.Message().IsEmpty()); | 87 CHECK(try_catch.Message().IsEmpty()); |
83 CHECK(!try_catch.CanContinue()); | 88 CHECK(!try_catch.CanContinue()); |
84 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 89 CHECK(args.GetIsolate()->IsExecutionTerminating()); |
85 } | 90 } |
86 | 91 |
87 | 92 |
88 void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) { | 93 void DoLoopNoCall(const v8::FunctionCallbackInfo<v8::Value>& args) { |
89 v8::TryCatch try_catch(args.GetIsolate()); | 94 v8::TryCatch try_catch(args.GetIsolate()); |
90 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 95 CHECK(!args.GetIsolate()->IsExecutionTerminating()); |
91 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), | 96 v8::MaybeLocal<v8::Value> result = |
92 "var term = true;" | 97 CompileRun(args.GetIsolate()->GetCurrentContext(), |
93 "while(true) {" | 98 "var term = true;" |
94 " if (term) terminate();" | 99 "while(true) {" |
95 " term = false;" | 100 " if (term) terminate();" |
96 "}"))->Run(); | 101 " term = false;" |
102 "}"); | |
103 CHECK(result.IsEmpty()); | |
97 CHECK(try_catch.HasCaught()); | 104 CHECK(try_catch.HasCaught()); |
98 CHECK(try_catch.Exception()->IsNull()); | 105 CHECK(try_catch.Exception()->IsNull()); |
99 CHECK(try_catch.Message().IsEmpty()); | 106 CHECK(try_catch.Message().IsEmpty()); |
100 CHECK(!try_catch.CanContinue()); | 107 CHECK(!try_catch.CanContinue()); |
101 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 108 CHECK(args.GetIsolate()->IsExecutionTerminating()); |
102 } | 109 } |
103 | 110 |
104 | 111 |
105 v8::Handle<v8::ObjectTemplate> CreateGlobalTemplate( | 112 v8::Local<v8::ObjectTemplate> CreateGlobalTemplate( |
106 v8::Isolate* isolate, | 113 v8::Isolate* isolate, v8::FunctionCallback terminate, |
107 v8::FunctionCallback terminate, | |
108 v8::FunctionCallback doloop) { | 114 v8::FunctionCallback doloop) { |
109 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); | 115 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); |
110 global->Set(v8::String::NewFromUtf8(isolate, "terminate"), | 116 global->Set(v8_str("terminate"), |
111 v8::FunctionTemplate::New(isolate, terminate)); | 117 v8::FunctionTemplate::New(isolate, terminate)); |
112 global->Set(v8::String::NewFromUtf8(isolate, "fail"), | 118 global->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail)); |
113 v8::FunctionTemplate::New(isolate, Fail)); | 119 global->Set(v8_str("loop"), v8::FunctionTemplate::New(isolate, Loop)); |
114 global->Set(v8::String::NewFromUtf8(isolate, "loop"), | 120 global->Set(v8_str("doloop"), v8::FunctionTemplate::New(isolate, doloop)); |
115 v8::FunctionTemplate::New(isolate, Loop)); | |
116 global->Set(v8::String::NewFromUtf8(isolate, "doloop"), | |
117 v8::FunctionTemplate::New(isolate, doloop)); | |
118 return global; | 121 return global; |
119 } | 122 } |
120 | 123 |
121 | 124 |
122 // Test that a single thread of JavaScript execution can terminate | 125 // Test that a single thread of JavaScript execution can terminate |
123 // itself. | 126 // itself. |
124 TEST(TerminateOnlyV8ThreadFromThreadItself) { | 127 TEST(TerminateOnlyV8ThreadFromThreadItself) { |
125 v8::HandleScope scope(CcTest::isolate()); | 128 v8::HandleScope scope(CcTest::isolate()); |
126 v8::Handle<v8::ObjectTemplate> global = | 129 v8::Local<v8::ObjectTemplate> global = |
127 CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop); | 130 CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop); |
128 v8::Handle<v8::Context> context = | 131 v8::Local<v8::Context> context = |
129 v8::Context::New(CcTest::isolate(), NULL, global); | 132 v8::Context::New(CcTest::isolate(), NULL, global); |
130 v8::Context::Scope context_scope(context); | 133 v8::Context::Scope context_scope(context); |
131 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 134 CHECK(!CcTest::isolate()->IsExecutionTerminating()); |
132 // Run a loop that will be infinite if thread termination does not work. | 135 // Run a loop that will be infinite if thread termination does not work. |
133 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 136 v8::MaybeLocal<v8::Value> result = |
134 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); | 137 CompileRun(CcTest::isolate()->GetCurrentContext(), |
135 v8::Script::Compile(source)->Run(); | 138 "try { loop(); fail(); } catch(e) { fail(); }"); |
139 CHECK(result.IsEmpty()); | |
136 // Test that we can run the code again after thread termination. | 140 // Test that we can run the code again after thread termination. |
137 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 141 CHECK(!CcTest::isolate()->IsExecutionTerminating()); |
138 v8::Script::Compile(source)->Run(); | 142 result = CompileRun(CcTest::isolate()->GetCurrentContext(), |
143 "try { loop(); fail(); } catch(e) { fail(); }"); | |
144 CHECK(result.IsEmpty()); | |
139 } | 145 } |
140 | 146 |
141 | 147 |
142 // Test that a single thread of JavaScript execution can terminate | 148 // Test that a single thread of JavaScript execution can terminate |
143 // itself in a loop that performs no calls. | 149 // itself in a loop that performs no calls. |
144 TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) { | 150 TEST(TerminateOnlyV8ThreadFromThreadItselfNoLoop) { |
145 v8::HandleScope scope(CcTest::isolate()); | 151 v8::HandleScope scope(CcTest::isolate()); |
146 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( | 152 v8::Local<v8::ObjectTemplate> global = CreateGlobalTemplate( |
147 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); | 153 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); |
148 v8::Handle<v8::Context> context = | 154 v8::Local<v8::Context> context = |
149 v8::Context::New(CcTest::isolate(), NULL, global); | 155 v8::Context::New(CcTest::isolate(), NULL, global); |
150 v8::Context::Scope context_scope(context); | 156 v8::Context::Scope context_scope(context); |
151 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 157 CHECK(!CcTest::isolate()->IsExecutionTerminating()); |
152 // Run a loop that will be infinite if thread termination does not work. | 158 // Run a loop that will be infinite if thread termination does not work. |
153 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 159 static const char* source = "try { loop(); fail(); } catch(e) { fail(); }"; |
154 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); | 160 v8::MaybeLocal<v8::Value> result = |
155 v8::Script::Compile(source)->Run(); | 161 CompileRun(CcTest::isolate()->GetCurrentContext(), source); |
156 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 162 CHECK(result.IsEmpty()); |
163 CHECK(!CcTest::isolate()->IsExecutionTerminating()); | |
157 // Test that we can run the code again after thread termination. | 164 // Test that we can run the code again after thread termination. |
158 v8::Script::Compile(source)->Run(); | 165 result = CompileRun(CcTest::isolate()->GetCurrentContext(), source); |
166 CHECK(result.IsEmpty()); | |
159 } | 167 } |
160 | 168 |
161 | 169 |
162 class TerminatorThread : public v8::base::Thread { | 170 class TerminatorThread : public v8::base::Thread { |
163 public: | 171 public: |
164 explicit TerminatorThread(i::Isolate* isolate) | 172 explicit TerminatorThread(i::Isolate* isolate) |
165 : Thread(Options("TerminatorThread")), | 173 : Thread(Options("TerminatorThread")), |
166 isolate_(reinterpret_cast<v8::Isolate*>(isolate)) {} | 174 isolate_(reinterpret_cast<v8::Isolate*>(isolate)) {} |
167 void Run() { | 175 void Run() { |
168 semaphore->Wait(); | 176 semaphore->Wait(); |
169 CHECK(!v8::V8::IsExecutionTerminating(isolate_)); | 177 CHECK(!isolate_->IsExecutionTerminating()); |
170 v8::V8::TerminateExecution(isolate_); | 178 isolate_->TerminateExecution(); |
171 } | 179 } |
172 | 180 |
173 private: | 181 private: |
174 v8::Isolate* isolate_; | 182 v8::Isolate* isolate_; |
175 }; | 183 }; |
176 | 184 |
177 | 185 |
178 // Test that a single thread of JavaScript execution can be terminated | 186 // Test that a single thread of JavaScript execution can be terminated |
179 // from the side by another thread. | 187 // from the side by another thread. |
180 TEST(TerminateOnlyV8ThreadFromOtherThread) { | 188 TEST(TerminateOnlyV8ThreadFromOtherThread) { |
181 semaphore = new v8::base::Semaphore(0); | 189 semaphore = new v8::base::Semaphore(0); |
182 TerminatorThread thread(CcTest::i_isolate()); | 190 TerminatorThread thread(CcTest::i_isolate()); |
183 thread.Start(); | 191 thread.Start(); |
184 | 192 |
185 v8::HandleScope scope(CcTest::isolate()); | 193 v8::HandleScope scope(CcTest::isolate()); |
186 v8::Handle<v8::ObjectTemplate> global = | 194 v8::Local<v8::ObjectTemplate> global = |
187 CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop); | 195 CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop); |
188 v8::Handle<v8::Context> context = | 196 v8::Local<v8::Context> context = |
189 v8::Context::New(CcTest::isolate(), NULL, global); | 197 v8::Context::New(CcTest::isolate(), NULL, global); |
190 v8::Context::Scope context_scope(context); | 198 v8::Context::Scope context_scope(context); |
191 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 199 CHECK(!CcTest::isolate()->IsExecutionTerminating()); |
192 // Run a loop that will be infinite if thread termination does not work. | 200 // Run a loop that will be infinite if thread termination does not work. |
193 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 201 v8::MaybeLocal<v8::Value> result = |
194 CcTest::isolate(), "try { loop(); fail(); } catch(e) { fail(); }"); | 202 CompileRun(CcTest::isolate()->GetCurrentContext(), |
195 v8::Script::Compile(source)->Run(); | 203 "try { loop(); fail(); } catch(e) { fail(); }"); |
196 | 204 CHECK(result.IsEmpty()); |
197 thread.Join(); | 205 thread.Join(); |
198 delete semaphore; | 206 delete semaphore; |
199 semaphore = NULL; | 207 semaphore = NULL; |
200 } | 208 } |
201 | 209 |
202 | 210 |
203 int call_count = 0; | 211 int call_count = 0; |
204 | 212 |
205 | 213 |
206 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | 214 void TerminateOrReturnObject(const v8::FunctionCallbackInfo<v8::Value>& args) { |
207 if (++call_count == 10) { | 215 if (++call_count == 10) { |
208 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 216 CHECK(!args.GetIsolate()->IsExecutionTerminating()); |
209 v8::V8::TerminateExecution(args.GetIsolate()); | 217 args.GetIsolate()->TerminateExecution(); |
210 return; | 218 return; |
211 } | 219 } |
212 v8::Local<v8::Object> result = v8::Object::New(args.GetIsolate()); | 220 v8::Local<v8::Object> result = v8::Object::New(args.GetIsolate()); |
213 result->Set(v8::String::NewFromUtf8(args.GetIsolate(), "x"), | 221 CHECK(result->Set(args.GetIsolate()->GetCurrentContext(), v8_str("x"), |
214 v8::Integer::New(args.GetIsolate(), 42)); | 222 v8::Integer::New(args.GetIsolate(), 42)) |
223 .FromJust()); | |
215 args.GetReturnValue().Set(result); | 224 args.GetReturnValue().Set(result); |
216 } | 225 } |
217 | 226 |
218 | 227 |
219 void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) { | 228 void LoopGetProperty(const v8::FunctionCallbackInfo<v8::Value>& args) { |
220 v8::TryCatch try_catch(args.GetIsolate()); | 229 v8::TryCatch try_catch(args.GetIsolate()); |
221 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 230 CHECK(!args.GetIsolate()->IsExecutionTerminating()); |
222 v8::Script::Compile( | 231 v8::MaybeLocal<v8::Value> result = |
223 v8::String::NewFromUtf8(args.GetIsolate(), | 232 CompileRun(args.GetIsolate()->GetCurrentContext(), |
224 "function f() {" | 233 "function f() {" |
225 " try {" | 234 " try {" |
226 " while(true) {" | 235 " while(true) {" |
227 " terminate_or_return_object().x;" | 236 " terminate_or_return_object().x;" |
228 " }" | 237 " }" |
229 " fail();" | 238 " fail();" |
230 " } catch(e) {" | 239 " } catch(e) {" |
231 " (function() {})();" // trigger stack check. | 240 " (function() {})();" // trigger stack check. |
232 " fail();" | 241 " fail();" |
233 " }" | 242 " }" |
234 "}" | 243 "}" |
235 "f()"))->Run(); | 244 "f()"); |
245 CHECK(result.IsEmpty()); | |
236 CHECK(try_catch.HasCaught()); | 246 CHECK(try_catch.HasCaught()); |
237 CHECK(try_catch.Exception()->IsNull()); | 247 CHECK(try_catch.Exception()->IsNull()); |
238 CHECK(try_catch.Message().IsEmpty()); | 248 CHECK(try_catch.Message().IsEmpty()); |
239 CHECK(!try_catch.CanContinue()); | 249 CHECK(!try_catch.CanContinue()); |
240 CHECK(v8::V8::IsExecutionTerminating(args.GetIsolate())); | 250 CHECK(args.GetIsolate()->IsExecutionTerminating()); |
241 } | 251 } |
242 | 252 |
243 | 253 |
244 // Test that we correctly handle termination exceptions if they are | 254 // Test that we correctly handle termination exceptions if they are |
245 // triggered by the creation of error objects in connection with ICs. | 255 // triggered by the creation of error objects in connection with ICs. |
246 TEST(TerminateLoadICException) { | 256 TEST(TerminateLoadICException) { |
247 v8::Isolate* isolate = CcTest::isolate(); | 257 v8::Isolate* isolate = CcTest::isolate(); |
248 v8::HandleScope scope(isolate); | 258 v8::HandleScope scope(isolate); |
249 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); | 259 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate); |
250 global->Set( | 260 global->Set(v8_str("terminate_or_return_object"), |
251 v8::String::NewFromUtf8(isolate, "terminate_or_return_object"), | 261 v8::FunctionTemplate::New(isolate, TerminateOrReturnObject)); |
252 v8::FunctionTemplate::New(isolate, TerminateOrReturnObject)); | 262 global->Set(v8_str("fail"), v8::FunctionTemplate::New(isolate, Fail)); |
253 global->Set(v8::String::NewFromUtf8(isolate, "fail"), | 263 global->Set(v8_str("loop"), |
254 v8::FunctionTemplate::New(isolate, Fail)); | |
255 global->Set(v8::String::NewFromUtf8(isolate, "loop"), | |
256 v8::FunctionTemplate::New(isolate, LoopGetProperty)); | 264 v8::FunctionTemplate::New(isolate, LoopGetProperty)); |
257 | 265 |
258 v8::Handle<v8::Context> context = | 266 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
259 v8::Context::New(isolate, NULL, global); | |
260 v8::Context::Scope context_scope(context); | 267 v8::Context::Scope context_scope(context); |
261 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 268 CHECK(!isolate->IsExecutionTerminating()); |
262 // Run a loop that will be infinite if thread termination does not work. | 269 // Run a loop that will be infinite if thread termination does not work. |
263 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | 270 static const char* source = "try { loop(); fail(); } catch(e) { fail(); }"; |
264 isolate, "try { loop(); fail(); } catch(e) { fail(); }"); | |
265 call_count = 0; | 271 call_count = 0; |
266 v8::Script::Compile(source)->Run(); | 272 v8::MaybeLocal<v8::Value> result = |
273 CompileRun(isolate->GetCurrentContext(), source); | |
274 CHECK(result.IsEmpty()); | |
267 // Test that we can run the code again after thread termination. | 275 // Test that we can run the code again after thread termination. |
268 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 276 CHECK(!isolate->IsExecutionTerminating()); |
269 call_count = 0; | 277 call_count = 0; |
270 v8::Script::Compile(source)->Run(); | 278 result = CompileRun(isolate->GetCurrentContext(), source); |
279 CHECK(result.IsEmpty()); | |
271 } | 280 } |
272 | 281 |
273 | 282 |
274 v8::Persistent<v8::String> reenter_script_1; | 283 v8::Persistent<v8::String> reenter_script_1; |
275 v8::Persistent<v8::String> reenter_script_2; | 284 v8::Persistent<v8::String> reenter_script_2; |
276 | 285 |
277 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { | 286 void ReenterAfterTermination(const v8::FunctionCallbackInfo<v8::Value>& args) { |
278 v8::TryCatch try_catch(args.GetIsolate()); | 287 v8::TryCatch try_catch(args.GetIsolate()); |
279 v8::Isolate* isolate = args.GetIsolate(); | 288 v8::Isolate* isolate = args.GetIsolate(); |
280 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 289 CHECK(!isolate->IsExecutionTerminating()); |
281 v8::Local<v8::String> script = | 290 v8::Local<v8::String> script = |
282 v8::Local<v8::String>::New(isolate, reenter_script_1); | 291 v8::Local<v8::String>::New(isolate, reenter_script_1); |
283 v8::Script::Compile(script)->Run(); | 292 v8::MaybeLocal<v8::Value> result = CompileRun(script); |
293 CHECK(result.IsEmpty()); | |
284 CHECK(try_catch.HasCaught()); | 294 CHECK(try_catch.HasCaught()); |
285 CHECK(try_catch.Exception()->IsNull()); | 295 CHECK(try_catch.Exception()->IsNull()); |
286 CHECK(try_catch.Message().IsEmpty()); | 296 CHECK(try_catch.Message().IsEmpty()); |
287 CHECK(!try_catch.CanContinue()); | 297 CHECK(!try_catch.CanContinue()); |
288 CHECK(v8::V8::IsExecutionTerminating(isolate)); | 298 CHECK(isolate->IsExecutionTerminating()); |
289 script = v8::Local<v8::String>::New(isolate, reenter_script_2); | 299 script = v8::Local<v8::String>::New(isolate, reenter_script_2); |
290 v8::Script::Compile(script)->Run(); | 300 v8::MaybeLocal<v8::Script> compiled_script = |
301 v8::Script::Compile(isolate->GetCurrentContext(), script); | |
302 CHECK(compiled_script.IsEmpty()); | |
291 } | 303 } |
292 | 304 |
293 | 305 |
294 // Test that reentry into V8 while the termination exception is still pending | 306 // Test that reentry into V8 while the termination exception is still pending |
295 // (has not yet unwound the 0-level JS frame) does not crash. | 307 // (has not yet unwound the 0-level JS frame) does not crash. |
296 TEST(TerminateAndReenterFromThreadItself) { | 308 TEST(TerminateAndReenterFromThreadItself) { |
297 v8::Isolate* isolate = CcTest::isolate(); | 309 v8::Isolate* isolate = CcTest::isolate(); |
298 v8::HandleScope scope(isolate); | 310 v8::HandleScope scope(isolate); |
299 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( | 311 v8::Local<v8::ObjectTemplate> global = CreateGlobalTemplate( |
300 isolate, TerminateCurrentThread, ReenterAfterTermination); | 312 isolate, TerminateCurrentThread, ReenterAfterTermination); |
301 v8::Handle<v8::Context> context = | 313 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
302 v8::Context::New(isolate, NULL, global); | |
303 v8::Context::Scope context_scope(context); | 314 v8::Context::Scope context_scope(context); |
304 CHECK(!v8::V8::IsExecutionTerminating()); | 315 CHECK(!v8::Isolate::GetCurrent()->IsExecutionTerminating()); |
305 // Create script strings upfront as it won't work when terminating. | 316 // Create script strings upfront as it won't work when terminating. |
306 reenter_script_1.Reset(isolate, v8_str( | 317 reenter_script_1.Reset(isolate, v8_str( |
307 "function f() {" | 318 "function f() {" |
308 " var term = true;" | 319 " var term = true;" |
309 " try {" | 320 " try {" |
310 " while(true) {" | 321 " while(true) {" |
311 " if (term) terminate();" | 322 " if (term) terminate();" |
312 " term = false;" | 323 " term = false;" |
313 " }" | 324 " }" |
314 " fail();" | 325 " fail();" |
315 " } catch(e) {" | 326 " } catch(e) {" |
316 " fail();" | 327 " fail();" |
317 " }" | 328 " }" |
318 "}" | 329 "}" |
319 "f()")); | 330 "f()")); |
320 reenter_script_2.Reset(isolate, v8_str("function f() { fail(); } f()")); | 331 reenter_script_2.Reset(isolate, v8_str("function f() { fail(); } f()")); |
321 CompileRun("try { loop(); fail(); } catch(e) { fail(); }"); | 332 CompileRun("try { loop(); fail(); } catch(e) { fail(); }"); |
322 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 333 CHECK(!isolate->IsExecutionTerminating()); |
323 // Check we can run JS again after termination. | 334 // Check we can run JS again after termination. |
324 CHECK(CompileRun("function f() { return true; } f()")->IsTrue()); | 335 CHECK(CompileRun("function f() { return true; } f()")->IsTrue()); |
325 reenter_script_1.Reset(); | 336 reenter_script_1.Reset(); |
326 reenter_script_2.Reset(); | 337 reenter_script_2.Reset(); |
327 } | 338 } |
328 | 339 |
329 | 340 |
330 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 341 void DoLoopCancelTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
331 v8::TryCatch try_catch(args.GetIsolate()); | 342 v8::TryCatch try_catch(args.GetIsolate()); |
332 CHECK(!v8::V8::IsExecutionTerminating()); | 343 CHECK(!v8::Isolate::GetCurrent()->IsExecutionTerminating()); |
333 v8::Script::Compile(v8::String::NewFromUtf8(args.GetIsolate(), | 344 v8::MaybeLocal<v8::Value> result = |
334 "var term = true;" | 345 CompileRun(args.GetIsolate()->GetCurrentContext(), |
335 "while(true) {" | 346 "var term = true;" |
336 " if (term) terminate();" | 347 "while(true) {" |
337 " term = false;" | 348 " if (term) terminate();" |
338 "}" | 349 " term = false;" |
339 "fail();"))->Run(); | 350 "}" |
351 "fail();"); | |
352 CHECK(result.IsEmpty()); | |
340 CHECK(try_catch.HasCaught()); | 353 CHECK(try_catch.HasCaught()); |
341 CHECK(try_catch.Exception()->IsNull()); | 354 CHECK(try_catch.Exception()->IsNull()); |
342 CHECK(try_catch.Message().IsEmpty()); | 355 CHECK(try_catch.Message().IsEmpty()); |
343 CHECK(!try_catch.CanContinue()); | 356 CHECK(!try_catch.CanContinue()); |
344 CHECK(v8::V8::IsExecutionTerminating()); | 357 CHECK(v8::Isolate::GetCurrent()->IsExecutionTerminating()); |
345 CHECK(try_catch.HasTerminated()); | 358 CHECK(try_catch.HasTerminated()); |
346 v8::V8::CancelTerminateExecution(CcTest::isolate()); | 359 CcTest::isolate()->CancelTerminateExecution(); |
347 CHECK(!v8::V8::IsExecutionTerminating()); | 360 CHECK(!v8::Isolate::GetCurrent()->IsExecutionTerminating()); |
348 } | 361 } |
349 | 362 |
350 | 363 |
351 // Test that a single thread of JavaScript execution can terminate | 364 // Test that a single thread of JavaScript execution can terminate |
352 // itself and then resume execution. | 365 // itself and then resume execution. |
353 TEST(TerminateCancelTerminateFromThreadItself) { | 366 TEST(TerminateCancelTerminateFromThreadItself) { |
354 v8::Isolate* isolate = CcTest::isolate(); | 367 v8::Isolate* isolate = CcTest::isolate(); |
355 v8::HandleScope scope(isolate); | 368 v8::HandleScope scope(isolate); |
356 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( | 369 v8::Local<v8::ObjectTemplate> global = CreateGlobalTemplate( |
357 isolate, TerminateCurrentThread, DoLoopCancelTerminate); | 370 isolate, TerminateCurrentThread, DoLoopCancelTerminate); |
358 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); | 371 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
359 v8::Context::Scope context_scope(context); | 372 v8::Context::Scope context_scope(context); |
360 CHECK(!v8::V8::IsExecutionTerminating(CcTest::isolate())); | 373 CHECK(!CcTest::isolate()->IsExecutionTerminating()); |
361 v8::Handle<v8::String> source = v8::String::NewFromUtf8( | |
362 isolate, "try { doloop(); } catch(e) { fail(); } 'completed';"); | |
363 // Check that execution completed with correct return value. | 374 // Check that execution completed with correct return value. |
364 CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed"))); | 375 CHECK(CompileRun(isolate->GetCurrentContext(), |
376 "try { doloop(); } catch(e) { fail(); } 'completed';") | |
377 .ToLocalChecked() | |
378 ->Equals(isolate->GetCurrentContext(), v8_str("completed")) | |
379 .FromJust()); | |
rmcilroy
2015/09/17 11:33:20
nit - I think this is a bit too much in the CHECK,
mythria
2015/09/21 10:08:38
Done.
| |
365 } | 380 } |
366 | 381 |
367 | 382 |
368 void MicrotaskShouldNotRun(const v8::FunctionCallbackInfo<v8::Value>& info) { | 383 void MicrotaskShouldNotRun(const v8::FunctionCallbackInfo<v8::Value>& info) { |
369 CHECK(false); | 384 CHECK(false); |
370 } | 385 } |
371 | 386 |
372 | 387 |
373 void MicrotaskLoopForever(const v8::FunctionCallbackInfo<v8::Value>& info) { | 388 void MicrotaskLoopForever(const v8::FunctionCallbackInfo<v8::Value>& info) { |
374 v8::Isolate* isolate = info.GetIsolate(); | 389 v8::Isolate* isolate = info.GetIsolate(); |
375 v8::HandleScope scope(isolate); | 390 v8::HandleScope scope(isolate); |
376 // Enqueue another should-not-run task to ensure we clean out the queue | 391 // Enqueue another should-not-run task to ensure we clean out the queue |
377 // when we terminate. | 392 // when we terminate. |
378 isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun)); | 393 isolate->EnqueueMicrotask( |
394 v8::Function::New(isolate->GetCurrentContext(), MicrotaskShouldNotRun) | |
395 .ToLocalChecked()); | |
379 CompileRun("terminate(); while (true) { }"); | 396 CompileRun("terminate(); while (true) { }"); |
380 CHECK(v8::V8::IsExecutionTerminating()); | 397 CHECK(v8::Isolate::GetCurrent()->IsExecutionTerminating()); |
381 } | 398 } |
382 | 399 |
383 | 400 |
384 TEST(TerminateFromOtherThreadWhileMicrotaskRunning) { | 401 TEST(TerminateFromOtherThreadWhileMicrotaskRunning) { |
385 semaphore = new v8::base::Semaphore(0); | 402 semaphore = new v8::base::Semaphore(0); |
386 TerminatorThread thread(CcTest::i_isolate()); | 403 TerminatorThread thread(CcTest::i_isolate()); |
387 thread.Start(); | 404 thread.Start(); |
388 | 405 |
389 v8::Isolate* isolate = CcTest::isolate(); | 406 v8::Isolate* isolate = CcTest::isolate(); |
390 isolate->SetAutorunMicrotasks(false); | 407 isolate->SetAutorunMicrotasks(false); |
391 v8::HandleScope scope(isolate); | 408 v8::HandleScope scope(isolate); |
392 v8::Handle<v8::ObjectTemplate> global = | 409 v8::Local<v8::ObjectTemplate> global = |
393 CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop); | 410 CreateGlobalTemplate(CcTest::isolate(), Signal, DoLoop); |
394 v8::Handle<v8::Context> context = | 411 v8::Local<v8::Context> context = |
395 v8::Context::New(CcTest::isolate(), NULL, global); | 412 v8::Context::New(CcTest::isolate(), NULL, global); |
396 v8::Context::Scope context_scope(context); | 413 v8::Context::Scope context_scope(context); |
397 isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskLoopForever)); | 414 isolate->EnqueueMicrotask( |
415 v8::Function::New(isolate->GetCurrentContext(), MicrotaskLoopForever) | |
416 .ToLocalChecked()); | |
398 // The second task should never be run because we bail out if we're | 417 // The second task should never be run because we bail out if we're |
399 // terminating. | 418 // terminating. |
400 isolate->EnqueueMicrotask(v8::Function::New(isolate, MicrotaskShouldNotRun)); | 419 isolate->EnqueueMicrotask( |
420 v8::Function::New(isolate->GetCurrentContext(), MicrotaskShouldNotRun) | |
421 .ToLocalChecked()); | |
401 isolate->RunMicrotasks(); | 422 isolate->RunMicrotasks(); |
402 | 423 |
403 v8::V8::CancelTerminateExecution(isolate); | 424 isolate->CancelTerminateExecution(); |
404 isolate->RunMicrotasks(); // should not run MicrotaskShouldNotRun | 425 isolate->RunMicrotasks(); // should not run MicrotaskShouldNotRun |
405 | 426 |
406 thread.Join(); | 427 thread.Join(); |
407 delete semaphore; | 428 delete semaphore; |
408 semaphore = NULL; | 429 semaphore = NULL; |
409 } | 430 } |
410 | 431 |
411 | 432 |
412 static int callback_counter = 0; | 433 static int callback_counter = 0; |
413 | 434 |
414 | 435 |
415 static void CounterCallback(v8::Isolate* isolate, void* data) { | 436 static void CounterCallback(v8::Isolate* isolate, void* data) { |
416 callback_counter++; | 437 callback_counter++; |
417 } | 438 } |
418 | 439 |
419 | 440 |
420 TEST(PostponeTerminateException) { | 441 TEST(PostponeTerminateException) { |
421 v8::Isolate* isolate = CcTest::isolate(); | 442 v8::Isolate* isolate = CcTest::isolate(); |
422 v8::HandleScope scope(isolate); | 443 v8::HandleScope scope(isolate); |
423 v8::Handle<v8::ObjectTemplate> global = | 444 v8::Local<v8::ObjectTemplate> global = |
424 CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop); | 445 CreateGlobalTemplate(CcTest::isolate(), TerminateCurrentThread, DoLoop); |
425 v8::Handle<v8::Context> context = | 446 v8::Local<v8::Context> context = |
426 v8::Context::New(CcTest::isolate(), NULL, global); | 447 v8::Context::New(CcTest::isolate(), NULL, global); |
427 v8::Context::Scope context_scope(context); | 448 v8::Context::Scope context_scope(context); |
428 | 449 |
429 v8::TryCatch try_catch(isolate); | 450 v8::TryCatch try_catch(isolate); |
430 static const char* terminate_and_loop = | 451 static const char* terminate_and_loop = |
431 "terminate(); for (var i = 0; i < 10000; i++);"; | 452 "terminate(); for (var i = 0; i < 10000; i++);"; |
432 | 453 |
433 { // Postpone terminate execution interrupts. | 454 { // Postpone terminate execution interrupts. |
434 i::PostponeInterruptsScope p1(CcTest::i_isolate(), | 455 i::PostponeInterruptsScope p1(CcTest::i_isolate(), |
435 i::StackGuard::TERMINATE_EXECUTION) ; | 456 i::StackGuard::TERMINATE_EXECUTION) ; |
(...skipping 25 matching lines...) Expand all Loading... | |
461 // Now the previously requested terminate execution interrupt should trigger. | 482 // Now the previously requested terminate execution interrupt should trigger. |
462 CompileRun("for (var i = 0; i < 10000; i++);"); | 483 CompileRun("for (var i = 0; i < 10000; i++);"); |
463 CHECK(try_catch.HasTerminated()); | 484 CHECK(try_catch.HasTerminated()); |
464 CHECK_EQ(2, callback_counter); | 485 CHECK_EQ(2, callback_counter); |
465 } | 486 } |
466 | 487 |
467 | 488 |
468 TEST(ErrorObjectAfterTermination) { | 489 TEST(ErrorObjectAfterTermination) { |
469 v8::Isolate* isolate = CcTest::isolate(); | 490 v8::Isolate* isolate = CcTest::isolate(); |
470 v8::HandleScope scope(isolate); | 491 v8::HandleScope scope(isolate); |
471 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); | 492 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); |
472 v8::Context::Scope context_scope(context); | 493 v8::Context::Scope context_scope(context); |
473 v8::V8::TerminateExecution(isolate); | 494 isolate->TerminateExecution(); |
474 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("error")); | 495 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("error")); |
475 // TODO(yangguo): crbug/403509. Check for empty handle instead. | 496 // TODO(yangguo): crbug/403509. Check for empty handle instead. |
476 CHECK(error->IsUndefined()); | 497 CHECK(error->IsUndefined()); |
477 } | 498 } |
478 | 499 |
479 | 500 |
480 void InnerTryCallTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { | 501 void InnerTryCallTerminate(const v8::FunctionCallbackInfo<v8::Value>& args) { |
481 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 502 CHECK(!args.GetIsolate()->IsExecutionTerminating()); |
482 v8::Handle<v8::Object> global = CcTest::global(); | 503 v8::Local<v8::Object> global = CcTest::global(); |
483 v8::Handle<v8::Function> loop = | 504 v8::Local<v8::Function> loop = v8::Local<v8::Function>::Cast( |
484 v8::Handle<v8::Function>::Cast(global->Get(v8_str("loop"))); | 505 global->Get(CcTest::isolate()->GetCurrentContext(), v8_str("loop")) |
506 .ToLocalChecked()); | |
485 i::MaybeHandle<i::Object> result = | 507 i::MaybeHandle<i::Object> result = |
486 i::Execution::TryCall(v8::Utils::OpenHandle((*loop)), | 508 i::Execution::TryCall(v8::Utils::OpenHandle((*loop)), |
487 v8::Utils::OpenHandle((*global)), 0, NULL, NULL); | 509 v8::Utils::OpenHandle((*global)), 0, NULL, NULL); |
488 CHECK(result.is_null()); | 510 CHECK(result.is_null()); |
489 // TryCall ignores terminate execution, but rerequests the interrupt. | 511 // TryCall ignores terminate execution, but rerequests the interrupt. |
490 CHECK(!v8::V8::IsExecutionTerminating(args.GetIsolate())); | 512 CHECK(!args.GetIsolate()->IsExecutionTerminating()); |
491 CHECK(CompileRun("1 + 1;").IsEmpty()); | 513 CHECK(CompileRun("1 + 1;").IsEmpty()); |
492 } | 514 } |
493 | 515 |
494 | 516 |
495 TEST(TerminationInInnerTryCall) { | 517 TEST(TerminationInInnerTryCall) { |
496 v8::Isolate* isolate = CcTest::isolate(); | 518 v8::Isolate* isolate = CcTest::isolate(); |
497 v8::HandleScope scope(isolate); | 519 v8::HandleScope scope(isolate); |
498 v8::Handle<v8::ObjectTemplate> global_template = CreateGlobalTemplate( | 520 v8::Local<v8::ObjectTemplate> global_template = CreateGlobalTemplate( |
499 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); | 521 CcTest::isolate(), TerminateCurrentThread, DoLoopNoCall); |
500 global_template->Set( | 522 global_template->Set( |
501 v8_str("inner_try_call_terminate"), | 523 v8_str("inner_try_call_terminate"), |
502 v8::FunctionTemplate::New(isolate, InnerTryCallTerminate)); | 524 v8::FunctionTemplate::New(isolate, InnerTryCallTerminate)); |
503 v8::Handle<v8::Context> context = | 525 v8::Local<v8::Context> context = |
504 v8::Context::New(CcTest::isolate(), NULL, global_template); | 526 v8::Context::New(CcTest::isolate(), NULL, global_template); |
505 v8::Context::Scope context_scope(context); | 527 v8::Context::Scope context_scope(context); |
506 { | 528 { |
507 v8::TryCatch try_catch(isolate); | 529 v8::TryCatch try_catch(isolate); |
508 CompileRun("inner_try_call_terminate()"); | 530 CompileRun("inner_try_call_terminate()"); |
509 CHECK(try_catch.HasTerminated()); | 531 CHECK(try_catch.HasTerminated()); |
510 } | 532 } |
511 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value()); | 533 CHECK_EQ(4, CompileRun("2 + 2") |
512 CHECK(!v8::V8::IsExecutionTerminating()); | 534 ->ToInt32(v8::Isolate::GetCurrent()->GetCurrentContext()) |
535 .ToLocalChecked() | |
536 ->Int32Value(v8::Isolate::GetCurrent()->GetCurrentContext()) | |
537 .FromJust()); | |
rmcilroy
2015/09/17 11:33:20
ditto here.
mythria
2015/09/21 10:08:38
Done.
| |
538 CHECK(!v8::Isolate::GetCurrent()->IsExecutionTerminating()); | |
513 } | 539 } |
514 | 540 |
515 | 541 |
516 TEST(TerminateAndTryCall) { | 542 TEST(TerminateAndTryCall) { |
517 i::FLAG_allow_natives_syntax = true; | 543 i::FLAG_allow_natives_syntax = true; |
518 v8::Isolate* isolate = CcTest::isolate(); | 544 v8::Isolate* isolate = CcTest::isolate(); |
519 v8::HandleScope scope(isolate); | 545 v8::HandleScope scope(isolate); |
520 v8::Handle<v8::ObjectTemplate> global = CreateGlobalTemplate( | 546 v8::Local<v8::ObjectTemplate> global = CreateGlobalTemplate( |
521 isolate, TerminateCurrentThread, DoLoopCancelTerminate); | 547 isolate, TerminateCurrentThread, DoLoopCancelTerminate); |
522 v8::Handle<v8::Context> context = v8::Context::New(isolate, NULL, global); | 548 v8::Local<v8::Context> context = v8::Context::New(isolate, NULL, global); |
523 v8::Context::Scope context_scope(context); | 549 v8::Context::Scope context_scope(context); |
524 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 550 CHECK(!isolate->IsExecutionTerminating()); |
525 v8::TryCatch try_catch(isolate); | 551 v8::TryCatch try_catch(isolate); |
526 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 552 CHECK(!isolate->IsExecutionTerminating()); |
527 // Terminate execution has been triggered inside TryCall, but re-requested | 553 // Terminate execution has been triggered inside TryCall, but re-requested |
528 // to trigger later. | 554 // to trigger later. |
529 CHECK(CompileRun("terminate(); reference_error();").IsEmpty()); | 555 CHECK(CompileRun("terminate(); reference_error();").IsEmpty()); |
530 CHECK(try_catch.HasCaught()); | 556 CHECK(try_catch.HasCaught()); |
531 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 557 CHECK(!isolate->IsExecutionTerminating()); |
532 CHECK(CcTest::global()->Get(v8_str("terminate"))->IsFunction()); | 558 CHECK(CcTest::global() |
559 ->Get(isolate->GetCurrentContext(), v8_str("terminate")) | |
560 .ToLocalChecked() | |
561 ->IsFunction()); | |
rmcilroy
2015/09/17 11:33:20
ditto here.
mythria
2015/09/21 10:08:38
Done.
| |
533 // The first stack check after terminate has been re-requested fails. | 562 // The first stack check after terminate has been re-requested fails. |
534 CHECK(CompileRun("1 + 1").IsEmpty()); | 563 CHECK(CompileRun("1 + 1").IsEmpty()); |
535 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 564 CHECK(!isolate->IsExecutionTerminating()); |
536 // V8 then recovers. | 565 // V8 then recovers. |
537 CHECK_EQ(4, CompileRun("2 + 2")->ToInt32()->Int32Value()); | 566 CHECK_EQ(4, CompileRun("2 + 2") |
538 CHECK(!v8::V8::IsExecutionTerminating(isolate)); | 567 ->ToInt32(v8::Isolate::GetCurrent()->GetCurrentContext()) |
568 .ToLocalChecked() | |
569 ->Int32Value(v8::Isolate::GetCurrent()->GetCurrentContext()) | |
570 .FromJust()); | |
rmcilroy
2015/09/17 11:33:20
ditto here.
mythria
2015/09/21 10:08:38
Done.
| |
571 CHECK(!isolate->IsExecutionTerminating()); | |
539 } | 572 } |
OLD | NEW |