OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 "bindings/core/v8/ScriptStreamer.h" | 5 #include "bindings/core/v8/ScriptStreamer.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "bindings/core/v8/ScriptSourceCode.h" | 9 #include "bindings/core/v8/ScriptSourceCode.h" |
10 #include "bindings/core/v8/ScriptStreamerThread.h" | 10 #include "bindings/core/v8/ScriptStreamerThread.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 ProcessTasksUntilStreamingComplete(); | 143 ProcessTasksUntilStreamingComplete(); |
144 EXPECT_TRUE(client->Finished()); | 144 EXPECT_TRUE(client->Finished()); |
145 bool error_occurred = false; | 145 bool error_occurred = false; |
146 ScriptSourceCode source_code = GetPendingScript() | 146 ScriptSourceCode source_code = GetPendingScript() |
147 ->GetSource(NullURL(), error_occurred) | 147 ->GetSource(NullURL(), error_occurred) |
148 ->GetScriptSourceCode(); | 148 ->GetScriptSourceCode(); |
149 EXPECT_FALSE(error_occurred); | 149 EXPECT_FALSE(error_occurred); |
150 EXPECT_TRUE(source_code.Streamer()); | 150 EXPECT_TRUE(source_code.Streamer()); |
151 v8::TryCatch try_catch(scope.GetIsolate()); | 151 v8::TryCatch try_catch(scope.GetIsolate()); |
152 v8::Local<v8::Script> script; | 152 v8::Local<v8::Script> script; |
153 EXPECT_TRUE(V8ScriptRunner::CompileScript(source_code, scope.GetIsolate(), | 153 EXPECT_TRUE(V8ScriptRunner::CompileScript(scope.GetScriptState(), source_code, |
154 kSharableCrossOrigin, | 154 kSharableCrossOrigin, |
155 kV8CacheOptionsDefault) | 155 kV8CacheOptionsDefault) |
156 .ToLocal(&script)); | 156 .ToLocal(&script)); |
157 EXPECT_FALSE(try_catch.HasCaught()); | 157 EXPECT_FALSE(try_catch.HasCaught()); |
158 } | 158 } |
159 | 159 |
160 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) { | 160 TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) { |
161 // Test that scripts with parse errors are handled properly. In those cases, | 161 // Test that scripts with parse errors are handled properly. In those cases, |
162 // the V8 side typically finished before loading finishes: make sure we | 162 // the V8 side typically finished before loading finishes: make sure we |
163 // handle it gracefully. | 163 // handle it gracefully. |
(...skipping 19 matching lines...) Expand all Loading... |
183 EXPECT_TRUE(client->Finished()); | 183 EXPECT_TRUE(client->Finished()); |
184 | 184 |
185 bool error_occurred = false; | 185 bool error_occurred = false; |
186 ScriptSourceCode source_code = GetPendingScript() | 186 ScriptSourceCode source_code = GetPendingScript() |
187 ->GetSource(NullURL(), error_occurred) | 187 ->GetSource(NullURL(), error_occurred) |
188 ->GetScriptSourceCode(); | 188 ->GetScriptSourceCode(); |
189 EXPECT_FALSE(error_occurred); | 189 EXPECT_FALSE(error_occurred); |
190 EXPECT_TRUE(source_code.Streamer()); | 190 EXPECT_TRUE(source_code.Streamer()); |
191 v8::TryCatch try_catch(scope.GetIsolate()); | 191 v8::TryCatch try_catch(scope.GetIsolate()); |
192 v8::Local<v8::Script> script; | 192 v8::Local<v8::Script> script; |
193 EXPECT_FALSE(V8ScriptRunner::CompileScript(source_code, scope.GetIsolate(), | 193 EXPECT_FALSE(V8ScriptRunner::CompileScript(scope.GetScriptState(), |
194 kSharableCrossOrigin, | 194 source_code, kSharableCrossOrigin, |
195 kV8CacheOptionsDefault) | 195 kV8CacheOptionsDefault) |
196 .ToLocal(&script)); | 196 .ToLocal(&script)); |
197 EXPECT_TRUE(try_catch.HasCaught()); | 197 EXPECT_TRUE(try_catch.HasCaught()); |
198 } | 198 } |
199 | 199 |
200 TEST_F(ScriptStreamingTest, CancellingStreaming) { | 200 TEST_F(ScriptStreamingTest, CancellingStreaming) { |
201 // Test that the upper layers (PendingScript and up) can be ramped down | 201 // Test that the upper layers (PendingScript and up) can be ramped down |
202 // while streaming is ongoing, and ScriptStreamer handles it gracefully. | 202 // while streaming is ongoing, and ScriptStreamer handles it gracefully. |
203 V8TestingScope scope; | 203 V8TestingScope scope; |
204 ScriptStreamer::StartStreaming( | 204 ScriptStreamer::StartStreaming( |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 ProcessTasksUntilStreamingComplete(); | 336 ProcessTasksUntilStreamingComplete(); |
337 EXPECT_TRUE(client->Finished()); | 337 EXPECT_TRUE(client->Finished()); |
338 bool error_occurred = false; | 338 bool error_occurred = false; |
339 ScriptSourceCode source_code = GetPendingScript() | 339 ScriptSourceCode source_code = GetPendingScript() |
340 ->GetSource(NullURL(), error_occurred) | 340 ->GetSource(NullURL(), error_occurred) |
341 ->GetScriptSourceCode(); | 341 ->GetScriptSourceCode(); |
342 EXPECT_FALSE(error_occurred); | 342 EXPECT_FALSE(error_occurred); |
343 EXPECT_TRUE(source_code.Streamer()); | 343 EXPECT_TRUE(source_code.Streamer()); |
344 v8::TryCatch try_catch(scope.GetIsolate()); | 344 v8::TryCatch try_catch(scope.GetIsolate()); |
345 v8::Local<v8::Script> script; | 345 v8::Local<v8::Script> script; |
346 EXPECT_TRUE(V8ScriptRunner::CompileScript(source_code, scope.GetIsolate(), | 346 EXPECT_TRUE(V8ScriptRunner::CompileScript(scope.GetScriptState(), source_code, |
347 kSharableCrossOrigin, | 347 kSharableCrossOrigin, |
348 kV8CacheOptionsDefault) | 348 kV8CacheOptionsDefault) |
349 .ToLocal(&script)); | 349 .ToLocal(&script)); |
350 EXPECT_FALSE(try_catch.HasCaught()); | 350 EXPECT_FALSE(try_catch.HasCaught()); |
351 } | 351 } |
352 | 352 |
353 TEST_F(ScriptStreamingTest, EncodingChanges) { | 353 TEST_F(ScriptStreamingTest, EncodingChanges) { |
354 // It's possible that the encoding of the Resource changes after we start | 354 // It's possible that the encoding of the Resource changes after we start |
355 // loading it. | 355 // loading it. |
356 V8TestingScope scope; | 356 V8TestingScope scope; |
(...skipping 16 matching lines...) Expand all Loading... |
373 ProcessTasksUntilStreamingComplete(); | 373 ProcessTasksUntilStreamingComplete(); |
374 EXPECT_TRUE(client->Finished()); | 374 EXPECT_TRUE(client->Finished()); |
375 bool error_occurred = false; | 375 bool error_occurred = false; |
376 ScriptSourceCode source_code = GetPendingScript() | 376 ScriptSourceCode source_code = GetPendingScript() |
377 ->GetSource(NullURL(), error_occurred) | 377 ->GetSource(NullURL(), error_occurred) |
378 ->GetScriptSourceCode(); | 378 ->GetScriptSourceCode(); |
379 EXPECT_FALSE(error_occurred); | 379 EXPECT_FALSE(error_occurred); |
380 EXPECT_TRUE(source_code.Streamer()); | 380 EXPECT_TRUE(source_code.Streamer()); |
381 v8::TryCatch try_catch(scope.GetIsolate()); | 381 v8::TryCatch try_catch(scope.GetIsolate()); |
382 v8::Local<v8::Script> script; | 382 v8::Local<v8::Script> script; |
383 EXPECT_TRUE(V8ScriptRunner::CompileScript(source_code, scope.GetIsolate(), | 383 EXPECT_TRUE(V8ScriptRunner::CompileScript(scope.GetScriptState(), source_code, |
384 kSharableCrossOrigin, | 384 kSharableCrossOrigin, |
385 kV8CacheOptionsDefault) | 385 kV8CacheOptionsDefault) |
386 .ToLocal(&script)); | 386 .ToLocal(&script)); |
387 EXPECT_FALSE(try_catch.HasCaught()); | 387 EXPECT_FALSE(try_catch.HasCaught()); |
388 } | 388 } |
389 | 389 |
390 TEST_F(ScriptStreamingTest, EncodingFromBOM) { | 390 TEST_F(ScriptStreamingTest, EncodingFromBOM) { |
391 // Byte order marks should be removed before giving the data to V8. They | 391 // Byte order marks should be removed before giving the data to V8. They |
392 // will also affect encoding detection. | 392 // will also affect encoding detection. |
393 V8TestingScope scope; | 393 V8TestingScope scope; |
(...skipping 17 matching lines...) Expand all Loading... |
411 ProcessTasksUntilStreamingComplete(); | 411 ProcessTasksUntilStreamingComplete(); |
412 EXPECT_TRUE(client->Finished()); | 412 EXPECT_TRUE(client->Finished()); |
413 bool error_occurred = false; | 413 bool error_occurred = false; |
414 ScriptSourceCode source_code = GetPendingScript() | 414 ScriptSourceCode source_code = GetPendingScript() |
415 ->GetSource(NullURL(), error_occurred) | 415 ->GetSource(NullURL(), error_occurred) |
416 ->GetScriptSourceCode(); | 416 ->GetScriptSourceCode(); |
417 EXPECT_FALSE(error_occurred); | 417 EXPECT_FALSE(error_occurred); |
418 EXPECT_TRUE(source_code.Streamer()); | 418 EXPECT_TRUE(source_code.Streamer()); |
419 v8::TryCatch try_catch(scope.GetIsolate()); | 419 v8::TryCatch try_catch(scope.GetIsolate()); |
420 v8::Local<v8::Script> script; | 420 v8::Local<v8::Script> script; |
421 EXPECT_TRUE(V8ScriptRunner::CompileScript(source_code, scope.GetIsolate(), | 421 EXPECT_TRUE(V8ScriptRunner::CompileScript(scope.GetScriptState(), source_code, |
422 kSharableCrossOrigin, | 422 kSharableCrossOrigin, |
423 kV8CacheOptionsDefault) | 423 kV8CacheOptionsDefault) |
424 .ToLocal(&script)); | 424 .ToLocal(&script)); |
425 EXPECT_FALSE(try_catch.HasCaught()); | 425 EXPECT_FALSE(try_catch.HasCaught()); |
426 } | 426 } |
427 | 427 |
428 // A test for crbug.com/711703. Should not crash. | 428 // A test for crbug.com/711703. Should not crash. |
429 TEST_F(ScriptStreamingTest, GarbageCollectDuringStreaming) { | 429 TEST_F(ScriptStreamingTest, GarbageCollectDuringStreaming) { |
430 V8TestingScope scope; | 430 V8TestingScope scope; |
431 ScriptStreamer::StartStreaming( | 431 ScriptStreamer::StartStreaming( |
432 GetPendingScript(), ScriptStreamer::kParsingBlocking, settings_.get(), | 432 GetPendingScript(), ScriptStreamer::kParsingBlocking, settings_.get(), |
433 scope.GetScriptState(), loading_task_runner_); | 433 scope.GetScriptState(), loading_task_runner_); |
434 | 434 |
435 TestPendingScriptClient* client = new TestPendingScriptClient; | 435 TestPendingScriptClient* client = new TestPendingScriptClient; |
436 GetPendingScript()->WatchForLoad(client); | 436 GetPendingScript()->WatchForLoad(client); |
437 EXPECT_FALSE(client->Finished()); | 437 EXPECT_FALSE(client->Finished()); |
438 | 438 |
439 pending_script_ = nullptr; | 439 pending_script_ = nullptr; |
440 ThreadState::Current()->CollectGarbage(BlinkGC::kNoHeapPointersOnStack, | 440 ThreadState::Current()->CollectGarbage(BlinkGC::kNoHeapPointersOnStack, |
441 BlinkGC::kGCWithSweep, | 441 BlinkGC::kGCWithSweep, |
442 BlinkGC::kForcedGC); | 442 BlinkGC::kForcedGC); |
443 } | 443 } |
444 | 444 |
445 } // namespace | 445 } // namespace |
446 | 446 |
447 } // namespace blink | 447 } // namespace blink |
OLD | NEW |