| 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 15382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15393 v8::Local<v8::String> source = | 15393 v8::Local<v8::String> source = |
| 15394 v8::String::NewExternal(context->GetIsolate(), uc16_resource); | 15394 v8::String::NewExternal(context->GetIsolate(), uc16_resource); |
| 15395 v8::Script::Compile(source); | 15395 v8::Script::Compile(source); |
| 15396 } | 15396 } |
| 15397 } | 15397 } |
| 15398 | 15398 |
| 15399 | 15399 |
| 15400 #ifndef V8_INTERPRETED_REGEXP | 15400 #ifndef V8_INTERPRETED_REGEXP |
| 15401 | 15401 |
| 15402 struct RegExpInterruptionData { | 15402 struct RegExpInterruptionData { |
| 15403 int loop_count; | 15403 v8::base::Atomic32 loop_count; |
| 15404 UC16VectorResource* string_resource; | 15404 UC16VectorResource* string_resource; |
| 15405 v8::Persistent<v8::String> string; | 15405 v8::Persistent<v8::String> string; |
| 15406 } regexp_interruption_data; | 15406 } regexp_interruption_data; |
| 15407 | 15407 |
| 15408 | 15408 |
| 15409 class RegExpInterruptionThread : public v8::base::Thread { | 15409 class RegExpInterruptionThread : public v8::base::Thread { |
| 15410 public: | 15410 public: |
| 15411 explicit RegExpInterruptionThread(v8::Isolate* isolate) | 15411 explicit RegExpInterruptionThread(v8::Isolate* isolate) |
| 15412 : Thread(Options("TimeoutThread")), isolate_(isolate) {} | 15412 : Thread(Options("TimeoutThread")), isolate_(isolate) {} |
| 15413 | 15413 |
| 15414 virtual void Run() { | 15414 virtual void Run() { |
| 15415 for (regexp_interruption_data.loop_count = 0; | 15415 for (v8::base::NoBarrier_Store(®exp_interruption_data.loop_count, 0); |
| 15416 regexp_interruption_data.loop_count < 7; | 15416 v8::base::NoBarrier_Load(®exp_interruption_data.loop_count) < 7; |
| 15417 regexp_interruption_data.loop_count++) { | 15417 v8::base::NoBarrier_AtomicIncrement( |
| 15418 ®exp_interruption_data.loop_count, 1)) { |
| 15418 v8::base::OS::Sleep(50); // Wait a bit before requesting GC. | 15419 v8::base::OS::Sleep(50); // Wait a bit before requesting GC. |
| 15419 reinterpret_cast<i::Isolate*>(isolate_)->stack_guard()->RequestGC(); | 15420 reinterpret_cast<i::Isolate*>(isolate_)->stack_guard()->RequestGC(); |
| 15420 } | 15421 } |
| 15421 v8::base::OS::Sleep(50); // Wait a bit before terminating. | 15422 v8::base::OS::Sleep(50); // Wait a bit before terminating. |
| 15422 v8::V8::TerminateExecution(isolate_); | 15423 v8::V8::TerminateExecution(isolate_); |
| 15423 } | 15424 } |
| 15424 | 15425 |
| 15425 private: | 15426 private: |
| 15426 v8::Isolate* isolate_; | 15427 v8::Isolate* isolate_; |
| 15427 }; | 15428 }; |
| 15428 | 15429 |
| 15429 | 15430 |
| 15430 void RunBeforeGC(v8::GCType type, v8::GCCallbackFlags flags) { | 15431 void RunBeforeGC(v8::GCType type, v8::GCCallbackFlags flags) { |
| 15431 if (regexp_interruption_data.loop_count != 2) return; | 15432 if (v8::base::NoBarrier_Load(®exp_interruption_data.loop_count) != 2) { |
| 15433 return; |
| 15434 } |
| 15432 v8::HandleScope scope(CcTest::isolate()); | 15435 v8::HandleScope scope(CcTest::isolate()); |
| 15433 v8::Local<v8::String> string = v8::Local<v8::String>::New( | 15436 v8::Local<v8::String> string = v8::Local<v8::String>::New( |
| 15434 CcTest::isolate(), regexp_interruption_data.string); | 15437 CcTest::isolate(), regexp_interruption_data.string); |
| 15435 string->MakeExternal(regexp_interruption_data.string_resource); | 15438 string->MakeExternal(regexp_interruption_data.string_resource); |
| 15436 } | 15439 } |
| 15437 | 15440 |
| 15438 | 15441 |
| 15439 // Test that RegExp execution can be interrupted. Specifically, we test | 15442 // Test that RegExp execution can be interrupted. Specifically, we test |
| 15440 // * interrupting with GC | 15443 // * interrupting with GC |
| 15441 // * turn the subject string from one-byte internal to two-byte external string | 15444 // * turn the subject string from one-byte internal to two-byte external string |
| (...skipping 8258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 23700 " var foobXXXXX"; // Too many bytes which look like incomplete chars! | 23703 " var foobXXXXX"; // Too many bytes which look like incomplete chars! |
| 23701 char chunk2[] = | 23704 char chunk2[] = |
| 23702 "r = 13;\n" | 23705 "r = 13;\n" |
| 23703 " return foob\xeb\x91\x80\x80\x80r;\n" | 23706 " return foob\xeb\x91\x80\x80\x80r;\n" |
| 23704 "}\n"; | 23707 "}\n"; |
| 23705 for (int i = 0; i < 5; ++i) chunk1[strlen(chunk1) - 5 + i] = reference[i]; | 23708 for (int i = 0; i < 5; ++i) chunk1[strlen(chunk1) - 5 + i] = reference[i]; |
| 23706 | 23709 |
| 23707 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; | 23710 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; |
| 23708 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, false); | 23711 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, false); |
| 23709 } | 23712 } |
| OLD | NEW |