| OLD | NEW | 
|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 | 
| (...skipping 20969 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 20980   delete task; | 20980   delete task; | 
| 20981 | 20981 | 
| 20982   const v8::ScriptCompiler::CachedData* cached_data = source.GetCachedData(); | 20982   const v8::ScriptCompiler::CachedData* cached_data = source.GetCachedData(); | 
| 20983   CHECK(cached_data != NULL); | 20983   CHECK(cached_data != NULL); | 
| 20984   CHECK(cached_data->data != NULL); | 20984   CHECK(cached_data->data != NULL); | 
| 20985   CHECK(!cached_data->rejected); | 20985   CHECK(!cached_data->rejected); | 
| 20986   CHECK_GT(cached_data->length, 0); | 20986   CHECK_GT(cached_data->length, 0); | 
| 20987 } | 20987 } | 
| 20988 | 20988 | 
| 20989 | 20989 | 
| 20990 TEST(StreamingWithDebuggingDoesNotProduceParserCache) { | 20990 TEST(StreamingWithDebuggingEnabledLate) { | 
| 20991   // If the debugger is active, we should just not produce parser cache at | 20991   // The streaming parser can only parse lazily, i.e. inner functions are not | 
| 20992   // all. This is a regeression test: We used to produce a parser cache without | 20992   // fully parsed. However, we may compile inner functions eagerly when | 
| 20993   // any data in it (just headers). | 20993   // debugging. Make sure that we can deal with this when turning on debugging | 
|  | 20994   // after streaming parser has already finished parsing. | 
| 20994   i::FLAG_min_preparse_length = 0; | 20995   i::FLAG_min_preparse_length = 0; | 
| 20995   const char* chunks[] = {"function foo() { ret", "urn 13; } f", "oo(); ", | 20996   const char* chunks[] = {"with({x:1}) {", | 
|  | 20997                           "  var foo = function foo(y) {", | 
|  | 20998                           "    return x + y;", | 
|  | 20999                           "  };", | 
|  | 21000                           "  foo(2);", | 
|  | 21001                           "}", | 
| 20996                           NULL}; | 21002                           NULL}; | 
| 20997 | 21003 | 
| 20998   LocalContext env; | 21004   LocalContext env; | 
| 20999   v8::Isolate* isolate = env->GetIsolate(); | 21005   v8::Isolate* isolate = env->GetIsolate(); | 
| 21000   v8::HandleScope scope(isolate); | 21006   v8::HandleScope scope(isolate); | 
| 21001 | 21007   v8::TryCatch try_catch(isolate); | 
| 21002   // Make the debugger active by setting a breakpoint. |  | 
| 21003   CompileRun("function break_here() { }"); |  | 
| 21004   i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast( |  | 
| 21005       v8::Utils::OpenHandle(*env->Global()->Get(v8_str("break_here")))); |  | 
| 21006   EnableDebugger(); |  | 
| 21007   v8::internal::Debug* debug = CcTest::i_isolate()->debug(); |  | 
| 21008   int position = 0; |  | 
| 21009   debug->SetBreakPoint(func, i::Handle<i::Object>(v8::internal::Smi::FromInt(1), |  | 
| 21010                                                   CcTest::i_isolate()), |  | 
| 21011                        &position); |  | 
| 21012 | 21008 | 
| 21013   v8::ScriptCompiler::StreamedSource source( | 21009   v8::ScriptCompiler::StreamedSource source( | 
| 21014       new TestSourceStream(chunks), | 21010       new TestSourceStream(chunks), | 
| 21015       v8::ScriptCompiler::StreamedSource::ONE_BYTE); | 21011       v8::ScriptCompiler::StreamedSource::ONE_BYTE); | 
| 21016   v8::ScriptCompiler::ScriptStreamingTask* task = | 21012   v8::ScriptCompiler::ScriptStreamingTask* task = | 
| 21017       v8::ScriptCompiler::StartStreamingScript( | 21013       v8::ScriptCompiler::StartStreamingScript(isolate, &source); | 
| 21018           isolate, &source, v8::ScriptCompiler::kProduceParserCache); |  | 
| 21019 | 21014 | 
| 21020   // TestSourceStream::GetMoreData won't block, so it's OK to just run the |  | 
| 21021   // task here in the main thread. |  | 
| 21022   task->Run(); | 21015   task->Run(); | 
| 21023   delete task; | 21016   delete task; | 
| 21024 | 21017 | 
| 21025   // Check that we got no cached data. | 21018   CHECK(!try_catch.HasCaught()); | 
| 21026   CHECK(source.GetCachedData() == NULL); | 21019 | 
|  | 21020   v8::ScriptOrigin origin(v8_str("http://foo.com")); | 
|  | 21021   char* full_source = TestSourceStream::FullSourceString(chunks); | 
|  | 21022 | 
|  | 21023   EnableDebugger(); | 
|  | 21024 | 
|  | 21025   v8::Handle<Script> script = v8::ScriptCompiler::Compile( | 
|  | 21026       isolate, &source, v8_str(full_source), origin); | 
|  | 21027 | 
|  | 21028   Maybe<uint32_t> result = | 
|  | 21029       script->Run(env.local()).ToLocalChecked()->Uint32Value(env.local()); | 
|  | 21030   CHECK_EQ(3, result.FromMaybe(0)); | 
|  | 21031 | 
|  | 21032   delete[] full_source; | 
|  | 21033 | 
| 21027   DisableDebugger(); | 21034   DisableDebugger(); | 
| 21028 } | 21035 } | 
| 21029 | 21036 | 
| 21030 | 21037 | 
| 21031 TEST(StreamingScriptWithInvalidUtf8) { | 21038 TEST(StreamingScriptWithInvalidUtf8) { | 
| 21032   // Regression test for a crash: test that invalid UTF-8 bytes in the end of a | 21039   // Regression test for a crash: test that invalid UTF-8 bytes in the end of a | 
| 21033   // chunk don't produce a crash. | 21040   // chunk don't produce a crash. | 
| 21034   const char* reference = "\xec\x92\x81\x80\x80"; | 21041   const char* reference = "\xec\x92\x81\x80\x80"; | 
| 21035   char chunk1[] = | 21042   char chunk1[] = | 
| 21036       "function foo() {\n" | 21043       "function foo() {\n" | 
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 21918 | 21925 | 
| 21919   v8::TryCatch try_catch(CcTest::isolate()); | 21926   v8::TryCatch try_catch(CcTest::isolate()); | 
| 21920   timeout_thread.Start(); | 21927   timeout_thread.Start(); | 
| 21921 | 21928 | 
| 21922   CompileRun( | 21929   CompileRun( | 
| 21923       "var ab = new SharedArrayBuffer(4);" | 21930       "var ab = new SharedArrayBuffer(4);" | 
| 21924       "var i32a = new Int32Array(ab);" | 21931       "var i32a = new Int32Array(ab);" | 
| 21925       "Atomics.futexWait(i32a, 0, 0);"); | 21932       "Atomics.futexWait(i32a, 0, 0);"); | 
| 21926   CHECK(try_catch.HasTerminated()); | 21933   CHECK(try_catch.HasTerminated()); | 
| 21927 } | 21934 } | 
| OLD | NEW | 
|---|