| 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 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // | 27 // |
| 28 // Tests of logging functions from log.h | 28 // Tests of logging functions from log.h |
| 29 | 29 |
| 30 #ifdef __linux__ | 30 #ifdef __linux__ |
| 31 #include <pthread.h> | 31 #include <pthread.h> |
| 32 #include <signal.h> | 32 #include <signal.h> |
| 33 #include <unistd.h> | 33 #include <unistd.h> |
| 34 #include <cmath> | 34 #include <cmath> |
| 35 #endif // __linux__ | 35 #endif // __linux__ |
| 36 | 36 |
| 37 // TODO(dcarney): remove |
| 38 #define V8_ALLOW_ACCESS_TO_PERSISTENT_ARROW |
| 39 #define V8_ALLOW_ACCESS_TO_RAW_HANDLE_CONSTRUCTOR |
| 40 #define V8_ALLOW_ACCESS_TO_PERSISTENT_IMPLICIT |
| 41 |
| 37 #include "v8.h" | 42 #include "v8.h" |
| 38 #include "log.h" | 43 #include "log.h" |
| 39 #include "cpu-profiler.h" | 44 #include "cpu-profiler.h" |
| 40 #include "natives.h" | 45 #include "natives.h" |
| 41 #include "v8threads.h" | 46 #include "v8threads.h" |
| 42 #include "v8utils.h" | 47 #include "v8utils.h" |
| 43 #include "cctest.h" | 48 #include "cctest.h" |
| 44 #include "vm-state-inl.h" | 49 #include "vm-state-inl.h" |
| 45 | 50 |
| 46 using v8::internal::Address; | 51 using v8::internal::Address; |
| 47 using v8::internal::EmbeddedVector; | 52 using v8::internal::EmbeddedVector; |
| 48 using v8::internal::Logger; | 53 using v8::internal::Logger; |
| 49 using v8::internal::StrLength; | 54 using v8::internal::StrLength; |
| 50 | 55 |
| 51 namespace { | 56 namespace { |
| 52 | 57 |
| 53 | 58 |
| 54 class ScopedLoggerInitializer { | 59 class ScopedLoggerInitializer { |
| 55 public: | 60 public: |
| 56 explicit ScopedLoggerInitializer(bool prof_lazy) | 61 explicit ScopedLoggerInitializer(bool prof_lazy) |
| 57 : saved_log_(i::FLAG_log), | 62 : saved_log_(i::FLAG_log), |
| 58 saved_prof_lazy_(i::FLAG_prof_lazy), | 63 saved_prof_lazy_(i::FLAG_prof_lazy), |
| 59 saved_prof_(i::FLAG_prof), | 64 saved_prof_(i::FLAG_prof), |
| 60 saved_prof_auto_(i::FLAG_prof_auto), | 65 saved_prof_auto_(i::FLAG_prof_auto), |
| 61 temp_file_(NULL), | 66 temp_file_(NULL), |
| 62 // Need to run this prior to creating the scope. | 67 // Need to run this prior to creating the scope. |
| 63 trick_to_run_init_flags_(init_flags_(prof_lazy)), | 68 trick_to_run_init_flags_(init_flags_(prof_lazy)), |
| 64 scope_(v8::Isolate::GetCurrent()), | 69 scope_(v8::Isolate::GetCurrent()), |
| 65 env_(v8::Context::New()), | 70 env_(*v8::Context::New()), |
| 66 logger_(i::Isolate::Current()->logger()) { | 71 logger_(i::Isolate::Current()->logger()) { |
| 67 env_->Enter(); | 72 env_->Enter(); |
| 68 } | 73 } |
| 69 | 74 |
| 70 ~ScopedLoggerInitializer() { | 75 ~ScopedLoggerInitializer() { |
| 71 env_->Exit(); | 76 env_->Exit(); |
| 72 logger_->TearDown(); | 77 logger_->TearDown(); |
| 73 if (temp_file_ != NULL) fclose(temp_file_); | 78 if (temp_file_ != NULL) fclose(temp_file_); |
| 74 i::FLAG_prof_lazy = saved_prof_lazy_; | 79 i::FLAG_prof_lazy = saved_prof_lazy_; |
| 75 i::FLAG_prof = saved_prof_; | 80 i::FLAG_prof = saved_prof_; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 virtual size_t length() const { return utf_source_.length(); } | 369 virtual size_t length() const { return utf_source_.length(); } |
| 365 virtual const uint16_t* data() const { return utf_source_.start(); } | 370 virtual const uint16_t* data() const { return utf_source_.start(); } |
| 366 private: | 371 private: |
| 367 i::ScopedVector<uint16_t> utf_source_; | 372 i::ScopedVector<uint16_t> utf_source_; |
| 368 }; | 373 }; |
| 369 | 374 |
| 370 } // namespace | 375 } // namespace |
| 371 | 376 |
| 372 TEST(Issue23768) { | 377 TEST(Issue23768) { |
| 373 v8::HandleScope scope(v8::Isolate::GetCurrent()); | 378 v8::HandleScope scope(v8::Isolate::GetCurrent()); |
| 374 v8::Handle<v8::Context> env = v8::Context::New(); | 379 v8::Handle<v8::Context> env = v8::Context::New(v8::Isolate::GetCurrent()); |
| 375 env->Enter(); | 380 env->Enter(); |
| 376 | 381 |
| 377 SimpleExternalString source_ext_str("(function ext() {})();"); | 382 SimpleExternalString source_ext_str("(function ext() {})();"); |
| 378 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); | 383 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); |
| 379 // Script needs to have a name in order to trigger InitLineEnds execution. | 384 // Script needs to have a name in order to trigger InitLineEnds execution. |
| 380 v8::Handle<v8::String> origin = v8::String::New("issue-23768-test"); | 385 v8::Handle<v8::String> origin = v8::String::New("issue-23768-test"); |
| 381 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source, origin); | 386 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source, origin); |
| 382 CHECK(!evil_script.IsEmpty()); | 387 CHECK(!evil_script.IsEmpty()); |
| 383 CHECK(!evil_script->Run().IsEmpty()); | 388 CHECK(!evil_script->Run().IsEmpty()); |
| 384 i::Handle<i::ExternalTwoByteString> i_source( | 389 i::Handle<i::ExternalTwoByteString> i_source( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 398 | 403 |
| 399 TEST(LogCallbacks) { | 404 TEST(LogCallbacks) { |
| 400 ScopedLoggerInitializer initialize_logger(false); | 405 ScopedLoggerInitializer initialize_logger(false); |
| 401 Logger* logger = initialize_logger.logger(); | 406 Logger* logger = initialize_logger.logger(); |
| 402 | 407 |
| 403 v8::Persistent<v8::FunctionTemplate> obj = | 408 v8::Persistent<v8::FunctionTemplate> obj = |
| 404 v8::Persistent<v8::FunctionTemplate>::New(v8::Isolate::GetCurrent(), | 409 v8::Persistent<v8::FunctionTemplate>::New(v8::Isolate::GetCurrent(), |
| 405 v8::FunctionTemplate::New()); | 410 v8::FunctionTemplate::New()); |
| 406 obj->SetClassName(v8_str("Obj")); | 411 obj->SetClassName(v8_str("Obj")); |
| 407 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); | 412 v8::Handle<v8::ObjectTemplate> proto = obj->PrototypeTemplate(); |
| 408 v8::Local<v8::Signature> signature = v8::Signature::New(obj); | 413 v8::Local<v8::Signature> signature = |
| 414 v8::Signature::New(v8::Handle<v8::FunctionTemplate>(*obj)); |
| 409 proto->Set(v8_str("method1"), | 415 proto->Set(v8_str("method1"), |
| 410 v8::FunctionTemplate::New(ObjMethod1, | 416 v8::FunctionTemplate::New(ObjMethod1, |
| 411 v8::Handle<v8::Value>(), | 417 v8::Handle<v8::Value>(), |
| 412 signature), | 418 signature), |
| 413 static_cast<v8::PropertyAttribute>(v8::DontDelete)); | 419 static_cast<v8::PropertyAttribute>(v8::DontDelete)); |
| 414 | 420 |
| 415 initialize_logger.env()->Global()->Set(v8_str("Obj"), obj->GetFunction()); | 421 initialize_logger.env()->Global()->Set(v8_str("Obj"), obj->GetFunction()); |
| 416 CompileRun("Obj.prototype.method1.toString();"); | 422 CompileRun("Obj.prototype.method1.toString();"); |
| 417 | 423 |
| 418 logger->LogCompiledFunctions(); | 424 logger->LogCompiledFunctions(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 v8::Local<v8::String> s = result->ToString(); | 571 v8::Local<v8::String> s = result->ToString(); |
| 566 i::ScopedVector<char> data(s->Length() + 1); | 572 i::ScopedVector<char> data(s->Length() + 1); |
| 567 CHECK_NE(NULL, data.start()); | 573 CHECK_NE(NULL, data.start()); |
| 568 s->WriteAscii(data.start()); | 574 s->WriteAscii(data.start()); |
| 569 printf("%s\n", data.start()); | 575 printf("%s\n", data.start()); |
| 570 // Make sure that our output is written prior crash due to CHECK failure. | 576 // Make sure that our output is written prior crash due to CHECK failure. |
| 571 fflush(stdout); | 577 fflush(stdout); |
| 572 CHECK(false); | 578 CHECK(false); |
| 573 } | 579 } |
| 574 } | 580 } |
| OLD | NEW |