Version 1.2.5.

Fixed bug in initial boundary check for Boyer-Moore text search (issue 349).

Fixed compilation issues with MinGW and gcc 4.3+ and added support for armv7 and cortex-a8 architectures.  Patches by Lei Zhang and Craig Schlenter.

Added a script cache to the debugger.

Optimized compilation performance by improving internal data structures and avoiding expensive property load optimizations for code that's infrequently executed.

Exposed the calling JavaScript context through the static API function Context::GetCalling().


git-svn-id: http://v8.googlecode.com/svn/trunk@2050 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
diff --git a/src/api.cc b/src/api.cc
index c16920b..48a9d1a 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -99,7 +99,6 @@
 // --- E x c e p t i o n   B e h a v i o r ---
 
 
-static bool has_shut_down = false;
 static FatalErrorCallback exception_behavior = NULL;
 
 
@@ -123,7 +122,7 @@
 // When V8 cannot allocated memory FatalProcessOutOfMemory is called.
 // The default fatal error handler is called and execution is stopped.
 void i::V8::FatalProcessOutOfMemory(const char* location) {
-  has_shut_down = true;
+  i::V8::SetFatalError();
   FatalErrorCallback callback = GetFatalErrorHandler();
   {
     LEAVE_V8;
@@ -142,13 +141,13 @@
 bool Utils::ReportApiFailure(const char* location, const char* message) {
   FatalErrorCallback callback = GetFatalErrorHandler();
   callback(location, message);
-  has_shut_down = true;
+  i::V8::SetFatalError();
   return false;
 }
 
 
 bool V8::IsDead() {
-  return has_shut_down;
+  return i::V8::IsDead();
 }
 
 
@@ -186,7 +185,8 @@
  * yet been done.
  */
 static inline bool IsDeadCheck(const char* location) {
-  return has_shut_down ? ReportV8Dead(location) : false;
+  return !i::V8::IsRunning()
+      && i::V8::IsDead() ? ReportV8Dead(location) : false;
 }
 
 
@@ -205,9 +205,14 @@
 static i::StringInputBuffer write_input_buffer;
 
 
-static void EnsureInitialized(const char* location) {
-  if (IsDeadCheck(location)) return;
-  ApiCheck(v8::V8::Initialize(), location, "Error initializing V8");
+static inline bool EnsureInitialized(const char* location) {
+  if (i::V8::IsRunning()) {
+    return true;
+  }
+  if (IsDeadCheck(location)) {
+    return false;
+  }
+  return ApiCheck(v8::V8::Initialize(), location, "Error initializing V8");
 }
 
 
@@ -225,29 +230,25 @@
 
 
 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() {
-  if (IsDeadCheck("v8::Undefined()")) return v8::Handle<v8::Primitive>();
-  EnsureInitialized("v8::Undefined()");
+  if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>();
   return v8::Handle<Primitive>(ToApi<Primitive>(i::Factory::undefined_value()));
 }
 
 
 v8::Handle<v8::Primitive> ImplementationUtilities::Null() {
-  if (IsDeadCheck("v8::Null()")) return v8::Handle<v8::Primitive>();
-  EnsureInitialized("v8::Null()");
+  if (!EnsureInitialized("v8::Null()")) return v8::Handle<v8::Primitive>();
   return v8::Handle<Primitive>(ToApi<Primitive>(i::Factory::null_value()));
 }
 
 
 v8::Handle<v8::Boolean> ImplementationUtilities::True() {
-  if (IsDeadCheck("v8::True()")) return v8::Handle<v8::Boolean>();
-  EnsureInitialized("v8::True()");
+  if (!EnsureInitialized("v8::True()")) return v8::Handle<v8::Boolean>();
   return v8::Handle<v8::Boolean>(ToApi<Boolean>(i::Factory::true_value()));
 }
 
 
 v8::Handle<v8::Boolean> ImplementationUtilities::False() {
-  if (IsDeadCheck("v8::False()")) return v8::Handle<v8::Boolean>();
-  EnsureInitialized("v8::False()");
+  if (!EnsureInitialized("v8::False()")) return v8::Handle<v8::Boolean>();
   return v8::Handle<v8::Boolean>(ToApi<Boolean>(i::Factory::false_value()));
 }
 
@@ -373,21 +374,21 @@
 
 bool V8::IsGlobalNearDeath(void** obj) {
   LOG_API("IsGlobalNearDeath");
-  if (has_shut_down) return false;
+  if (!i::V8::IsRunning()) return false;
   return i::GlobalHandles::IsNearDeath(reinterpret_cast<i::Object**>(obj));
 }
 
 
 bool V8::IsGlobalWeak(void** obj) {
   LOG_API("IsGlobalWeak");
-  if (has_shut_down) return false;
+  if (!i::V8::IsRunning()) return false;
   return i::GlobalHandles::IsWeak(reinterpret_cast<i::Object**>(obj));
 }
 
 
 void V8::DisposeGlobal(void** obj) {
   LOG_API("DisposeGlobal");
-  if (has_shut_down) return;
+  if (!i::V8::IsRunning()) return;
   i::Object** ptr = reinterpret_cast<i::Object**>(obj);
   if ((*ptr)->IsGlobalContext()) i::Heap::NotifyContextDisposed();
   i::GlobalHandles::Destroy(ptr);
@@ -431,7 +432,7 @@
 
 
 void Context::Exit() {
-  if (has_shut_down) return;
+  if (!i::V8::IsRunning()) return;
   if (!ApiCheck(thread_local.LeaveLastContext(),
                 "v8::Context::Exit()",
                 "Cannot exit non-entered context")) {
@@ -2450,7 +2451,7 @@
 // --- E n v i r o n m e n t ---
 
 bool v8::V8::Initialize() {
-  if (i::V8::HasBeenSetup()) return true;
+  if (i::V8::IsRunning()) return true;
   ENTER_V8;
   HandleScope scope;
   if (i::Snapshot::Initialize()) {
@@ -3123,12 +3124,23 @@
 #endif
 }
 
+
 void V8::ResumeProfiler() {
 #ifdef ENABLE_LOGGING_AND_PROFILING
   i::Logger::ResumeProfiler();
 #endif
 }
 
+
+bool V8::IsProfilerPaused() {
+#ifdef ENABLE_LOGGING_AND_PROFILING
+  return i::Logger::IsProfilerPaused();
+#else
+  return true;
+#endif
+}
+
+
 int V8::GetLogLines(int from_pos, char* dest_buf, int max_size) {
 #ifdef ENABLE_LOGGING_AND_PROFILING
   return i::Logger::GetLogLines(from_pos, dest_buf, max_size);
@@ -3320,7 +3332,7 @@
 
 
 void Debug::DebugBreak() {
-  if (!i::V8::HasBeenSetup()) return;
+  if (!i::V8::IsRunning()) return;
   i::StackGuard::DebugBreak();
 }
 
@@ -3362,7 +3374,7 @@
 
 void Debug::SendCommand(const uint16_t* command, int length,
                         ClientData* client_data) {
-  if (!i::V8::HasBeenSetup()) return;
+  if (!i::V8::IsRunning()) return;
   i::Debugger::ProcessCommand(i::Vector<const uint16_t>(command, length),
                               client_data);
 }
@@ -3378,7 +3390,7 @@
 
 Handle<Value> Debug::Call(v8::Handle<v8::Function> fun,
                           v8::Handle<v8::Value> data) {
-  if (!i::V8::HasBeenSetup()) return Handle<Value>();
+  if (!i::V8::IsRunning()) return Handle<Value>();
   ON_BAILOUT("v8::Debug::Call()", return Handle<Value>());
   ENTER_V8;
   i::Handle<i::Object> result;