TEST_F(ScriptStreamingTest, SuppressingStreaming) { // If we notice during streaming that there is a code cache, streaming // is suppressed (V8 doesn't parse while the script is loading), and the // upper layer (ScriptResourceClient) should get a notification when the // script is loaded. ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.scriptState(), PendingScript::ParsingBlocking); TestScriptResourceClient client; pendingScript().watchForLoad(&client); appendData("function foo() {"); appendPadding(); m_resource->setCachedMetadata(V8ScriptRunner::tagForCodeCache(), "X", 1, Resource::CacheLocally); appendPadding(); finish(); processTasksUntilStreamingComplete(); EXPECT_TRUE(client.finished()); bool errorOccurred = false; ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurred); EXPECT_FALSE(errorOccurred); // ScriptSourceCode doesn't refer to the streamer, since we have suppressed // the streaming and resumed the non-streaming code path for script // compilation. EXPECT_FALSE(sourceCode.streamer()); }
TEST_F(ScriptStreamingTest, CompilingStreamedScript) { // Test that we can successfully compile a streamed script. ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.scriptState(), PendingScript::ParsingBlocking); TestScriptResourceClient client; pendingScript().watchForLoad(&client); appendData("function foo() {"); appendPadding(); appendData("return 5; }"); appendPadding(); appendData("foo();"); EXPECT_FALSE(client.finished()); finish(); // Process tasks on the main thread until the streaming background thread // has completed its tasks. processTasksUntilStreamingComplete(); EXPECT_TRUE(client.finished()); bool errorOccurred = false; ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurred); EXPECT_FALSE(errorOccurred); EXPECT_TRUE(sourceCode.streamer()); v8::TryCatch tryCatch; v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, isolate()); EXPECT_FALSE(script.IsEmpty()); EXPECT_FALSE(tryCatch.HasCaught()); }
LIBRARY_API void Chabu_ByteBuffer_putString(struct Chabu_ByteBuffer_Data* data, const char* const value){ int len = Common_strnlen(value, 0x100 ); Chabu_ByteBuffer_putIntBe( data, len ); memcpy( data->data + data->position, value, len ); data->position += len; appendPadding( data, Common_AlignUp4(len)-len ); }
TEST_F(ScriptStreamingTest, CompilingStreamedScriptWithParseError) { // Test that scripts with parse errors are handled properly. In those cases, // the V8 side typically finished before loading finishes: make sure we // handle it gracefully. ScriptStreamer::startStreaming(pendingScript(), m_settings.get(), m_scope.scriptState(), PendingScript::ParsingBlocking); TestScriptResourceClient client; pendingScript().watchForLoad(&client); appendData("function foo() {"); appendData("this is the part which will be a parse error"); // V8 won't realize the parse error until it actually starts parsing the // script, and this happens only when its buffer is filled. appendPadding(); EXPECT_FALSE(client.finished()); // Force the V8 side to finish before the loading. processTasksUntilStreamingComplete(); EXPECT_FALSE(client.finished()); finish(); EXPECT_TRUE(client.finished()); bool errorOccurred = false; ScriptSourceCode sourceCode = pendingScript().getSource(KURL(), errorOccurred); EXPECT_FALSE(errorOccurred); EXPECT_TRUE(sourceCode.streamer()); v8::TryCatch tryCatch; v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(sourceCode, isolate()); EXPECT_TRUE(script.IsEmpty()); EXPECT_TRUE(tryCatch.HasCaught()); }
LIBRARY_API void Chabu_ByteBuffer_putStringFromBuffer(struct Chabu_ByteBuffer_Data* data, struct Chabu_ByteBuffer_Data* stringBuffer){ int length = Chabu_ByteBuffer_remaining( stringBuffer ); Chabu_ByteBuffer_putIntBe( data, length ); Chabu_ByteBuffer_xferAllPossible( data, stringBuffer ); appendPadding( data, Common_AlignUp4(length)-length ); }