| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 // | 27 // |
| 28 // Tests of logging functions from log.h | 28 // Tests of logging functions from log.h |
| 29 | 29 |
| 30 // TODO(jochen): Remove this after the setting is turned on globally. |
| 31 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 32 |
| 30 #ifdef __linux__ | 33 #ifdef __linux__ |
| 31 #include <pthread.h> | 34 #include <pthread.h> |
| 32 #include <signal.h> | 35 #include <signal.h> |
| 33 #include <unistd.h> | 36 #include <unistd.h> |
| 34 #include <cmath> | 37 #include <cmath> |
| 35 #endif // __linux__ | 38 #endif // __linux__ |
| 36 | 39 |
| 37 #include "src/v8.h" | 40 #include "src/v8.h" |
| 38 | 41 |
| 39 #include "src/log.h" | 42 #include "src/log.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 81 } |
| 79 | 82 |
| 80 ~ScopedLoggerInitializer() { | 83 ~ScopedLoggerInitializer() { |
| 81 env_->Exit(); | 84 env_->Exit(); |
| 82 logger_->TearDown(); | 85 logger_->TearDown(); |
| 83 if (temp_file_ != NULL) fclose(temp_file_); | 86 if (temp_file_ != NULL) fclose(temp_file_); |
| 84 i::FLAG_prof = saved_prof_; | 87 i::FLAG_prof = saved_prof_; |
| 85 i::FLAG_log = saved_log_; | 88 i::FLAG_log = saved_log_; |
| 86 } | 89 } |
| 87 | 90 |
| 88 v8::Handle<v8::Context>& env() { return env_; } | 91 v8::Local<v8::Context>& env() { return env_; } |
| 89 | 92 |
| 90 v8::Isolate* isolate() { return isolate_; } | 93 v8::Isolate* isolate() { return isolate_; } |
| 91 | 94 |
| 92 Logger* logger() { return logger_; } | 95 Logger* logger() { return logger_; } |
| 93 | 96 |
| 94 FILE* StopLoggingGetTempFile() { | 97 FILE* StopLoggingGetTempFile() { |
| 95 temp_file_ = logger_->TearDown(); | 98 temp_file_ = logger_->TearDown(); |
| 96 CHECK(temp_file_); | 99 CHECK(temp_file_); |
| 97 fflush(temp_file_); | 100 fflush(temp_file_); |
| 98 rewind(temp_file_); | 101 rewind(temp_file_); |
| 99 return temp_file_; | 102 return temp_file_; |
| 100 } | 103 } |
| 101 | 104 |
| 102 private: | 105 private: |
| 103 const bool saved_log_; | 106 const bool saved_log_; |
| 104 const bool saved_prof_; | 107 const bool saved_prof_; |
| 105 FILE* temp_file_; | 108 FILE* temp_file_; |
| 106 v8::Isolate* isolate_; | 109 v8::Isolate* isolate_; |
| 107 v8::Isolate::Scope isolate_scope_; | 110 v8::Isolate::Scope isolate_scope_; |
| 108 v8::HandleScope scope_; | 111 v8::HandleScope scope_; |
| 109 v8::Handle<v8::Context> env_; | 112 v8::Local<v8::Context> env_; |
| 110 Logger* logger_; | 113 Logger* logger_; |
| 111 | 114 |
| 112 DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer); | 115 DISALLOW_COPY_AND_ASSIGN(ScopedLoggerInitializer); |
| 113 }; | 116 }; |
| 114 | 117 |
| 115 } // namespace | 118 } // namespace |
| 116 | 119 |
| 117 | 120 |
| 118 static const char* StrNStr(const char* s1, const char* s2, int n) { | 121 static const char* StrNStr(const char* s1, const char* s2, int n) { |
| 119 if (s1[n] == '\0') return strstr(s1, s2); | 122 if (s1[n] == '\0') return strstr(s1, s2); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 virtual size_t length() const { return utf_source_.length(); } | 303 virtual size_t length() const { return utf_source_.length(); } |
| 301 virtual const uint16_t* data() const { return utf_source_.start(); } | 304 virtual const uint16_t* data() const { return utf_source_.start(); } |
| 302 private: | 305 private: |
| 303 i::ScopedVector<uint16_t> utf_source_; | 306 i::ScopedVector<uint16_t> utf_source_; |
| 304 }; | 307 }; |
| 305 | 308 |
| 306 } // namespace | 309 } // namespace |
| 307 | 310 |
| 308 TEST(Issue23768) { | 311 TEST(Issue23768) { |
| 309 v8::HandleScope scope(CcTest::isolate()); | 312 v8::HandleScope scope(CcTest::isolate()); |
| 310 v8::Handle<v8::Context> env = v8::Context::New(CcTest::isolate()); | 313 v8::Local<v8::Context> env = v8::Context::New(CcTest::isolate()); |
| 311 env->Enter(); | 314 env->Enter(); |
| 312 | 315 |
| 313 SimpleExternalString source_ext_str("(function ext() {})();"); | 316 SimpleExternalString source_ext_str("(function ext() {})();"); |
| 314 v8::Local<v8::String> source = | 317 v8::Local<v8::String> source = |
| 315 v8::String::NewExternal(CcTest::isolate(), &source_ext_str); | 318 v8::String::NewExternalTwoByte(CcTest::isolate(), &source_ext_str) |
| 319 .ToLocalChecked(); |
| 316 // Script needs to have a name in order to trigger InitLineEnds execution. | 320 // Script needs to have a name in order to trigger InitLineEnds execution. |
| 317 v8::Handle<v8::String> origin = | 321 v8::Local<v8::String> origin = |
| 318 v8::String::NewFromUtf8(CcTest::isolate(), "issue-23768-test"); | 322 v8::String::NewFromUtf8(CcTest::isolate(), "issue-23768-test", |
| 319 v8::Handle<v8::Script> evil_script = CompileWithOrigin(source, origin); | 323 v8::NewStringType::kNormal) |
| 324 .ToLocalChecked(); |
| 325 v8::Local<v8::Script> evil_script = CompileWithOrigin(source, origin); |
| 320 CHECK(!evil_script.IsEmpty()); | 326 CHECK(!evil_script.IsEmpty()); |
| 321 CHECK(!evil_script->Run().IsEmpty()); | 327 CHECK(!evil_script->Run(env).IsEmpty()); |
| 322 i::Handle<i::ExternalTwoByteString> i_source( | 328 i::Handle<i::ExternalTwoByteString> i_source( |
| 323 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); | 329 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); |
| 324 // This situation can happen if source was an external string disposed | 330 // This situation can happen if source was an external string disposed |
| 325 // by its owner. | 331 // by its owner. |
| 326 i_source->set_resource(NULL); | 332 i_source->set_resource(NULL); |
| 327 | 333 |
| 328 // Must not crash. | 334 // Must not crash. |
| 329 CcTest::i_isolate()->logger()->LogCompiledFunctions(); | 335 CcTest::i_isolate()->logger()->LogCompiledFunctions(); |
| 330 } | 336 } |
| 331 | 337 |
| 332 | 338 |
| 333 static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) { | 339 static void ObjMethod1(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 334 } | 340 } |
| 335 | 341 |
| 336 | 342 |
| 337 TEST(LogCallbacks) { | 343 TEST(LogCallbacks) { |
| 338 SETUP_FLAGS(); | 344 SETUP_FLAGS(); |
| 339 v8::Isolate::CreateParams create_params; | 345 v8::Isolate::CreateParams create_params; |
| 340 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 346 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 341 v8::Isolate* isolate = v8::Isolate::New(create_params); | 347 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 342 { | 348 { |
| 343 ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate); | 349 ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate); |
| 344 Logger* logger = initialize_logger.logger(); | 350 Logger* logger = initialize_logger.logger(); |
| 345 | 351 |
| 346 v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New( | 352 v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New( |
| 347 isolate, v8::FunctionTemplate::New(isolate)); | 353 isolate, v8::FunctionTemplate::New(isolate)); |
| 348 obj->SetClassName(v8_str("Obj")); | 354 obj->SetClassName(v8_str("Obj")); |
| 349 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); | 355 v8::Local<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); |
| 350 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, obj); | 356 v8::Local<v8::Signature> signature = v8::Signature::New(isolate, obj); |
| 351 proto->Set(v8_str("method1"), | 357 proto->Set(v8_str("method1"), |
| 352 v8::FunctionTemplate::New(isolate, ObjMethod1, | 358 v8::FunctionTemplate::New(isolate, ObjMethod1, |
| 353 v8::Handle<v8::Value>(), signature), | 359 v8::Local<v8::Value>(), signature), |
| 354 static_cast<v8::PropertyAttribute>(v8::DontDelete)); | 360 static_cast<v8::PropertyAttribute>(v8::DontDelete)); |
| 355 | 361 |
| 356 initialize_logger.env()->Global()->Set(v8_str("Obj"), obj->GetFunction()); | 362 initialize_logger.env() |
| 363 ->Global() |
| 364 ->Set(initialize_logger.env(), v8_str("Obj"), |
| 365 obj->GetFunction(initialize_logger.env()).ToLocalChecked()) |
| 366 .FromJust(); |
| 357 CompileRun("Obj.prototype.method1.toString();"); | 367 CompileRun("Obj.prototype.method1.toString();"); |
| 358 | 368 |
| 359 logger->LogCompiledFunctions(); | 369 logger->LogCompiledFunctions(); |
| 360 | 370 |
| 361 bool exists = false; | 371 bool exists = false; |
| 362 i::Vector<const char> log( | 372 i::Vector<const char> log( |
| 363 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); | 373 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); |
| 364 CHECK(exists); | 374 CHECK(exists); |
| 365 | 375 |
| 366 i::EmbeddedVector<char, 100> ref_data; | 376 i::EmbeddedVector<char, 100> ref_data; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 394 v8::Isolate::CreateParams create_params; | 404 v8::Isolate::CreateParams create_params; |
| 395 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | 405 create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
| 396 v8::Isolate* isolate = v8::Isolate::New(create_params); | 406 v8::Isolate* isolate = v8::Isolate::New(create_params); |
| 397 { | 407 { |
| 398 ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate); | 408 ScopedLoggerInitializer initialize_logger(saved_log, saved_prof, isolate); |
| 399 Logger* logger = initialize_logger.logger(); | 409 Logger* logger = initialize_logger.logger(); |
| 400 | 410 |
| 401 v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New( | 411 v8::Local<v8::FunctionTemplate> obj = v8::Local<v8::FunctionTemplate>::New( |
| 402 isolate, v8::FunctionTemplate::New(isolate)); | 412 isolate, v8::FunctionTemplate::New(isolate)); |
| 403 obj->SetClassName(v8_str("Obj")); | 413 obj->SetClassName(v8_str("Obj")); |
| 404 v8::Handle<v8::ObjectTemplate> inst = obj->InstanceTemplate(); | 414 v8::Local<v8::ObjectTemplate> inst = obj->InstanceTemplate(); |
| 405 inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter); | 415 inst->SetAccessor(v8_str("prop1"), Prop1Getter, Prop1Setter); |
| 406 inst->SetAccessor(v8_str("prop2"), Prop2Getter); | 416 inst->SetAccessor(v8_str("prop2"), Prop2Getter); |
| 407 | 417 |
| 408 logger->LogAccessorCallbacks(); | 418 logger->LogAccessorCallbacks(); |
| 409 | 419 |
| 410 bool exists = false; | 420 bool exists = false; |
| 411 i::Vector<const char> log( | 421 i::Vector<const char> log( |
| 412 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); | 422 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); |
| 413 CHECK(exists); | 423 CHECK(exists); |
| 414 | 424 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 logger->StringEvent("test-logging-done", ""); | 478 logger->StringEvent("test-logging-done", ""); |
| 469 | 479 |
| 470 // Iterate heap to find compiled functions, will write to log. | 480 // Iterate heap to find compiled functions, will write to log. |
| 471 logger->LogCompiledFunctions(); | 481 logger->LogCompiledFunctions(); |
| 472 logger->StringEvent("test-traversal-done", ""); | 482 logger->StringEvent("test-traversal-done", ""); |
| 473 | 483 |
| 474 bool exists = false; | 484 bool exists = false; |
| 475 i::Vector<const char> log( | 485 i::Vector<const char> log( |
| 476 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); | 486 i::ReadFile(initialize_logger.StopLoggingGetTempFile(), &exists, true)); |
| 477 CHECK(exists); | 487 CHECK(exists); |
| 478 v8::Handle<v8::String> log_str = v8::String::NewFromUtf8( | 488 v8::Local<v8::String> log_str = |
| 479 isolate, log.start(), v8::String::kNormalString, log.length()); | 489 v8::String::NewFromUtf8(isolate, log.start(), |
| 480 initialize_logger.env()->Global()->Set(v8_str("_log"), log_str); | 490 v8::NewStringType::kNormal, log.length()) |
| 491 .ToLocalChecked(); |
| 492 initialize_logger.env() |
| 493 ->Global() |
| 494 ->Set(initialize_logger.env(), v8_str("_log"), log_str) |
| 495 .FromJust(); |
| 481 | 496 |
| 482 i::Vector<const char> source = TestSources::GetScriptsSource(); | 497 i::Vector<const char> source = TestSources::GetScriptsSource(); |
| 483 v8::Handle<v8::String> source_str = v8::String::NewFromUtf8( | 498 v8::Local<v8::String> source_str = |
| 484 isolate, source.start(), v8::String::kNormalString, source.length()); | 499 v8::String::NewFromUtf8(isolate, source.start(), |
| 500 v8::NewStringType::kNormal, source.length()) |
| 501 .ToLocalChecked(); |
| 485 v8::TryCatch try_catch(isolate); | 502 v8::TryCatch try_catch(isolate); |
| 486 v8::Handle<v8::Script> script = CompileWithOrigin(source_str, ""); | 503 v8::Local<v8::Script> script = CompileWithOrigin(source_str, ""); |
| 487 if (script.IsEmpty()) { | 504 if (script.IsEmpty()) { |
| 488 v8::String::Utf8Value exception(try_catch.Exception()); | 505 v8::String::Utf8Value exception(try_catch.Exception()); |
| 489 printf("compile: %s\n", *exception); | 506 printf("compile: %s\n", *exception); |
| 490 CHECK(false); | 507 CHECK(false); |
| 491 } | 508 } |
| 492 v8::Handle<v8::Value> result = script->Run(); | 509 v8::Local<v8::Value> result; |
| 493 if (result.IsEmpty()) { | 510 if (!script->Run(initialize_logger.env()).ToLocal(&result)) { |
| 494 v8::String::Utf8Value exception(try_catch.Exception()); | 511 v8::String::Utf8Value exception(try_catch.Exception()); |
| 495 printf("run: %s\n", *exception); | 512 printf("run: %s\n", *exception); |
| 496 CHECK(false); | 513 CHECK(false); |
| 497 } | 514 } |
| 498 // The result either be a "true" literal or problem description. | 515 // The result either be a "true" literal or problem description. |
| 499 if (!result->IsTrue()) { | 516 if (!result->IsTrue()) { |
| 500 v8::Local<v8::String> s = result->ToString(isolate); | 517 v8::Local<v8::String> s = |
| 518 result->ToString(initialize_logger.env()).ToLocalChecked(); |
| 501 i::ScopedVector<char> data(s->Utf8Length() + 1); | 519 i::ScopedVector<char> data(s->Utf8Length() + 1); |
| 502 CHECK(data.start()); | 520 CHECK(data.start()); |
| 503 s->WriteUtf8(data.start()); | 521 s->WriteUtf8(data.start()); |
| 504 printf("%s\n", data.start()); | 522 printf("%s\n", data.start()); |
| 505 // Make sure that our output is written prior crash due to CHECK failure. | 523 // Make sure that our output is written prior crash due to CHECK failure. |
| 506 fflush(stdout); | 524 fflush(stdout); |
| 507 CHECK(false); | 525 CHECK(false); |
| 508 } | 526 } |
| 509 } | 527 } |
| 510 isolate->Dispose(); | 528 isolate->Dispose(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac" | 597 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac" |
| 580 "(){})();"; | 598 "(){})();"; |
| 581 | 599 |
| 582 CompileRun(source_text); | 600 CompileRun(source_text); |
| 583 | 601 |
| 584 // Must not crash. | 602 // Must not crash. |
| 585 logger->LogCompiledFunctions(); | 603 logger->LogCompiledFunctions(); |
| 586 } | 604 } |
| 587 isolate->Dispose(); | 605 isolate->Dispose(); |
| 588 } | 606 } |
| OLD | NEW |