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 | 5 |
6 #include "config.h" | 6 #include "config.h" |
7 #include "bindings/core/v8/ScriptStreamer.h" | 7 #include "bindings/core/v8/ScriptStreamer.h" |
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 ScriptState* scriptState() const { return m_scope.scriptState(); } | 80 ScriptState* scriptState() const { return m_scope.scriptState(); } |
81 v8::Isolate* isolate() const { return m_scope.isolate(); } | 81 v8::Isolate* isolate() const { return m_scope.isolate(); } |
82 | 82 |
83 PendingScript& pendingScript() const { return m_pendingScript->get(); } | 83 PendingScript& pendingScript() const { return m_pendingScript->get(); } |
84 | 84 |
85 protected: | 85 protected: |
86 void appendData(const char* data) | 86 void appendData(const char* data) |
87 { | 87 { |
88 m_resource->appendData(data, strlen(data)); | 88 m_resource->appendData(data, strlen(data)); |
89 // Yield control to the background thread, so that V8 gets a change to | 89 // Yield control to the background thread, so that V8 gets a chance to |
90 // process the data before the main thread adds more. Note that we | 90 // process the data before the main thread adds more. Note that we |
91 // cannot fully control in what kind of chunks the data is passed to V8 | 91 // cannot fully control in what kind of chunks the data is passed to V8 |
92 // (if the V8 is not requesting more data between two appendData calls, | 92 // (if V8 is not requesting more data between two appendData calls, it |
93 // V8 will get both chunks together). | 93 // will get both chunks together). |
94 Platform::current()->yieldCurrentThread(); | 94 Platform::current()->yieldCurrentThread(); |
95 } | 95 } |
96 | 96 |
97 void appendPadding() | 97 void appendPadding() |
98 { | 98 { |
99 for (int i = 0; i < 10; ++i) { | 99 for (int i = 0; i < 10; ++i) { |
100 appendData(" /* this is padding to make the script long enough, so " | 100 appendData(" /* this is padding to make the script long enough, so " |
101 "that V8's buffer gets filled and it starts processing " | 101 "that V8's buffer gets filled and it starts processing " |
102 "the data */ "); | 102 "the data */ "); |
103 } | 103 } |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 bool errorOccurred = false; | 357 bool errorOccurred = false; |
358 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); | 358 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
359 EXPECT_FALSE(errorOccurred); | 359 EXPECT_FALSE(errorOccurred); |
360 EXPECT_TRUE(sourceCode.streamer()); | 360 EXPECT_TRUE(sourceCode.streamer()); |
361 v8::TryCatch tryCatch; | 361 v8::TryCatch tryCatch; |
362 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is
olate()); | 362 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is
olate()); |
363 EXPECT_FALSE(script.IsEmpty()); | 363 EXPECT_FALSE(script.IsEmpty()); |
364 EXPECT_FALSE(tryCatch.HasCaught()); | 364 EXPECT_FALSE(tryCatch.HasCaught()); |
365 } | 365 } |
366 | 366 |
| 367 |
| 368 TEST_P(ScriptStreamingTest, EncodingFromBOM) |
| 369 { |
| 370 // Byte order marks should be removed before giving the data to V8. They |
| 371 // will also affect encoding detection. |
| 372 m_resource->setEncoding("windows-1252"); // This encoding is wrong on purpos
e. |
| 373 |
| 374 ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.sc
riptState(), PendingScript::ParsingBlocking); |
| 375 TestScriptResourceClient client; |
| 376 pendingScript().watchForLoad(&client); |
| 377 |
| 378 // \xef\xbb\xbf is the UTF-8 byte order mark. \xec\x92\x81 are the raw bytes |
| 379 // for \uc481. |
| 380 appendData("\xef\xbb\xbf function foo() { var foob\xec\x92\x81r = 13; return
foob\xec\x92\x81r; } foo();"); |
| 381 |
| 382 finish(); |
| 383 processTasksUntilStreamingComplete(); |
| 384 EXPECT_TRUE(client.finished()); |
| 385 bool errorOccurred = false; |
| 386 ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurre
d); |
| 387 EXPECT_FALSE(errorOccurred); |
| 388 EXPECT_TRUE(sourceCode.streamer()); |
| 389 v8::TryCatch tryCatch; |
| 390 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, is
olate()); |
| 391 EXPECT_FALSE(script.IsEmpty()); |
| 392 EXPECT_FALSE(tryCatch.HasCaught()); |
| 393 } |
| 394 |
367 INSTANTIATE_TEST_CASE_P(ScriptStreamingInstantiation, ScriptStreamingTest, ::tes
ting::Values(false, true)); | 395 INSTANTIATE_TEST_CASE_P(ScriptStreamingInstantiation, ScriptStreamingTest, ::tes
ting::Values(false, true)); |
368 | 396 |
369 } // namespace | 397 } // namespace |
370 | 398 |
371 } // namespace blink | 399 } // namespace blink |
OLD | NEW |