Update V8 to r4588

We're using WebKit r58033, as used by
http://src.chromium.org/svn/releases/5.0.387.0/DEPS
This requires http://v8.googlecode.com/svn/trunk@4465 but this version has a
crashing bug for ARM. Instead we use http://v8.googlecode.com/svn/trunk@4588,
which is used by http://src.chromium.org/svn/releases/6.0.399.0/DEPS

Note that a trivial bug fix was required in arm/codegen-arm.cc. This is guarded
with ANDROID. See http://code.google.com/p/v8/issues/detail?id=703

Change-Id: I459647a8286c4f8c7405f0c5581ecbf051a6f1e8
diff --git a/include/v8-debug.h b/include/v8-debug.h
index 2e5fb3f..f7b4fa1 100644
--- a/include/v8-debug.h
+++ b/include/v8-debug.h
@@ -237,9 +237,10 @@
   * With this call the debugger is entered and the function specified is called
   * with the execution state as the first argument. This makes it possible to
   * get access to information otherwise not available during normal JavaScript
-  * execution e.g. details on stack frames. The following example show a
-  * JavaScript function which when passed to v8::Debug::Call will return the
-  * current line of JavaScript execution.
+  * execution e.g. details on stack frames. Receiver of the function call will
+  * be the debugger context global object, however this is a subject to change.
+  * The following example show a JavaScript function which when passed to 
+  * v8::Debug::Call will return the current line of JavaScript execution.
   *
   * \code
   *   function frame_source_line(exec_state) {
@@ -302,6 +303,14 @@
    * of this method.
    */
   static void ProcessDebugMessages();
+
+  /**
+   * Debugger is running in it's own context which is entered while debugger
+   * messages are being dispatched. This is an explicit getter for this
+   * debugger context. Note that the content of the debugger context is subject
+   * to change.
+   */
+  static Local<Context> GetDebugContext();
 };
 
 
diff --git a/include/v8-profiler.h b/include/v8-profiler.h
new file mode 100644
index 0000000..eca6548
--- /dev/null
+++ b/include/v8-profiler.h
@@ -0,0 +1,176 @@
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_V8_PROFILER_H_
+#define V8_V8_PROFILER_H_
+
+#include "v8.h"
+
+#ifdef _WIN32
+// Setup for Windows DLL export/import. See v8.h in this directory for
+// information on how to build/use V8 as a DLL.
+#if defined(BUILDING_V8_SHARED) && defined(USING_V8_SHARED)
+#error both BUILDING_V8_SHARED and USING_V8_SHARED are set - please check the\
+  build configuration to ensure that at most one of these is set
+#endif
+
+#ifdef BUILDING_V8_SHARED
+#define V8EXPORT __declspec(dllexport)
+#elif USING_V8_SHARED
+#define V8EXPORT __declspec(dllimport)
+#else
+#define V8EXPORT
+#endif
+
+#else  // _WIN32
+
+// Setup for Linux shared library export. See v8.h in this directory for
+// information on how to build/use V8 as shared library.
+#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(V8_SHARED)
+#define V8EXPORT __attribute__ ((visibility("default")))
+#else  // defined(__GNUC__) && (__GNUC__ >= 4)
+#define V8EXPORT
+#endif  // defined(__GNUC__) && (__GNUC__ >= 4)
+
+#endif  // _WIN32
+
+
+/**
+ * Profiler support for the V8 JavaScript engine.
+ */
+namespace v8 {
+
+
+/**
+ * CpuProfileNode represents a node in a call graph.
+ */
+class V8EXPORT CpuProfileNode {
+ public:
+  /** Returns function name (empty string for anonymous functions.) */
+  Handle<String> GetFunctionName() const;
+
+  /** Returns resource name for script from where the function originates. */
+  Handle<String> GetScriptResourceName() const;
+
+  /**
+   * Returns the number, 1-based, of the line where the function originates.
+   * kNoLineNumberInfo if no line number information is available.
+   */
+  int GetLineNumber() const;
+
+  /**
+   * Returns total (self + children) execution time of the function,
+   * in milliseconds, estimated by samples count.
+   */
+  double GetTotalTime() const;
+
+  /**
+   * Returns self execution time of the function, in milliseconds,
+   * estimated by samples count.
+   */
+  double GetSelfTime() const;
+
+  /** Returns the count of samples where function exists. */
+  double GetTotalSamplesCount() const;
+
+  /** Returns the count of samples where function was currently executing. */
+  double GetSelfSamplesCount() const;
+
+  /** Returns function entry UID. */
+  unsigned GetCallUid() const;
+
+  /** Returns child nodes count of the node. */
+  int GetChildrenCount() const;
+
+  /** Retrieves a child node by index. */
+  const CpuProfileNode* GetChild(int index) const;
+
+  static const int kNoLineNumberInfo = 0;
+};
+
+
+/**
+ * CpuProfile contains a CPU profile in a form of two call trees:
+ *  - top-down (from main() down to functions that do all the work);
+ *  - bottom-up call graph (in backward direction).
+ */
+class V8EXPORT CpuProfile {
+ public:
+  /** Returns CPU profile UID (assigned by the profiler.) */
+  unsigned GetUid() const;
+
+  /** Returns CPU profile title. */
+  Handle<String> GetTitle() const;
+
+  /** Returns the root node of the bottom up call tree. */
+  const CpuProfileNode* GetBottomUpRoot() const;
+
+  /** Returns the root node of the top down call tree. */
+  const CpuProfileNode* GetTopDownRoot() const;
+};
+
+
+/**
+ * Interface for controlling CPU profiling.
+ */
+class V8EXPORT CpuProfiler {
+ public:
+  /**
+   * Returns the number of profiles collected (doesn't include
+   * profiles that are being collected at the moment of call.)
+   */
+  static int GetProfilesCount();
+
+  /** Returns a profile by index. */
+  static const CpuProfile* GetProfile(int index);
+
+  /** Returns a profile by uid. */
+  static const CpuProfile* FindProfile(unsigned uid);
+
+  /**
+   * Starts collecting CPU profile. Title may be an empty string. It
+   * is allowed to have several profiles being collected at
+   * once. Attempts to start collecting several profiles with the same
+   * title are silently ignored.
+   */
+  static void StartProfiling(Handle<String> title);
+
+  /**
+   * Stops collecting CPU profile with a given title and returns it.
+   * If the title given is empty, finishes the last profile started.
+   */
+  static const CpuProfile* StopProfiling(Handle<String> title);
+};
+
+
+}  // namespace v8
+
+
+#undef V8EXPORT
+
+
+#endif  // V8_V8_PROFILER_H_
diff --git a/include/v8.h b/include/v8.h
index 9c80ce2..c07ba1f 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -261,6 +261,10 @@
     return Handle<T>(T::Cast(*that));
   }
 
+  template <class S> inline Handle<S> As() {
+    return Handle<S>::Cast(*this);
+  }
+
  private:
   T* val_;
 };
@@ -295,6 +299,10 @@
     return Local<T>(T::Cast(*that));
   }
 
+  template <class S> inline Local<S> As() {
+    return Local<S>::Cast(*this);
+  }
+
   /** Create a local handle for the content of another handle.
    *  The referee is kept alive by the local handle even when
    *  the original handle is destroyed/disposed.
@@ -368,6 +376,10 @@
     return Persistent<T>(T::Cast(*that));
   }
 
+  template <class S> inline Persistent<S> As() {
+    return Persistent<S>::Cast(*this);
+  }
+
   /**
    * Creates a new persistent handle for an existing local or
    * persistent handle.
@@ -538,13 +550,13 @@
    * Compiles the specified script (context-independent).
    *
    * \param source Script source code.
-   * \param origin Script origin, owned by caller, no references are kept 
+   * \param origin Script origin, owned by caller, no references are kept
    *   when New() returns
    * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
    *   using pre_data speeds compilation if it's done multiple times.
    *   Owned by caller, no references are kept when New() returns.
    * \param script_data Arbitrary data associated with script. Using
-   *   this has same effect as calling SetData(), but allows data to be 
+   *   this has same effect as calling SetData(), but allows data to be
    *   available to compile event handlers.
    * \return Compiled script object (context independent; when run it
    *   will use the currently entered context).
@@ -559,7 +571,7 @@
    * object (typically a string) as the script's origin.
    *
    * \param source Script source code.
-   * \patam file_name file name object (typically a string) to be used 
+   * \param file_name file name object (typically a string) to be used
    *   as the script's origin.
    * \return Compiled script object (context independent; when run it
    *   will use the currently entered context).
@@ -571,7 +583,7 @@
    * Compiles the specified script (bound to current context).
    *
    * \param source Script source code.
-   * \param origin Script origin, owned by caller, no references are kept 
+   * \param origin Script origin, owned by caller, no references are kept
    *   when Compile() returns
    * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
    *   using pre_data speeds compilation if it's done multiple times.
@@ -755,6 +767,11 @@
   bool IsInt32() const;
 
   /**
+   * Returns true if this value is a 32-bit unsigned integer.
+   */
+  bool IsUint32() const;
+
+  /**
    * Returns true if this value is a Date.
    */
   bool IsDate() const;
@@ -838,12 +855,29 @@
    * \param start The starting position within the string at which
    * copying begins.
    * \param length The number of bytes to copy from the string.
-   * \return The number of characters copied to the buffer
+   * \param nchars_ref The number of characters written, can be NULL.
+   * \param hints Various hints that might affect performance of this or
+   *    subsequent operations.
+   * \return The number of bytes copied to the buffer
    * excluding the NULL terminator.
    */
-  int Write(uint16_t* buffer, int start = 0, int length = -1) const;  // UTF-16
-  int WriteAscii(char* buffer, int start = 0, int length = -1) const;  // ASCII
-  int WriteUtf8(char* buffer, int length = -1) const; // UTF-8
+  enum WriteHints {
+    NO_HINTS = 0,
+    HINT_MANY_WRITES_EXPECTED = 1
+  };
+
+  int Write(uint16_t* buffer,
+            int start = 0,
+            int length = -1,
+            WriteHints hints = NO_HINTS) const;  // UTF-16
+  int WriteAscii(char* buffer,
+                 int start = 0,
+                 int length = -1,
+                 WriteHints hints = NO_HINTS) const;  // ASCII
+  int WriteUtf8(char* buffer,
+                int length = -1,
+                int* nchars_ref = NULL,
+                WriteHints hints = NO_HINTS) const; // UTF-8
 
   /**
    * A zero length string.
@@ -1178,6 +1212,9 @@
            Handle<Value> value,
            PropertyAttribute attribs = None);
 
+  bool Set(uint32_t index,
+           Handle<Value> value);
+
   // Sets a local property on this object bypassing interceptors and
   // overriding accessors or read-only properties.
   //
@@ -1192,6 +1229,8 @@
 
   Local<Value> Get(Handle<Value> key);
 
+  Local<Value> Get(uint32_t index);
+
   // TODO(1245389): Replace the type-specific versions of these
   // functions with generic ones that accept a Handle<Value> key.
   bool Has(Handle<String> key);
@@ -2136,12 +2175,26 @@
 // --- G a r b a g e C o l l e c t i o n  C a l l b a c k s
 
 /**
- * Applications can register a callback function which is called
- * before and after a major garbage collection.  Allocations are not
- * allowed in the callback function, you therefore cannot manipulate
+ * Applications can register callback functions which will be called
+ * before and after a garbage collection.  Allocations are not
+ * allowed in the callback functions, you therefore cannot manipulate
  * objects (set or delete properties for example) since it is possible
  * such operations will result in the allocation of objects.
  */
+enum GCType {
+  kGCTypeScavenge = 1 << 0,
+  kGCTypeMarkSweepCompact = 1 << 1,
+  kGCTypeAll = kGCTypeScavenge | kGCTypeMarkSweepCompact
+};
+
+enum GCCallbackFlags {
+  kNoGCCallbackFlags = 0,
+  kGCCallbackFlagCompacted = 1 << 0
+};
+
+typedef void (*GCPrologueCallback)(GCType type, GCCallbackFlags flags);
+typedef void (*GCEpilogueCallback)(GCType type, GCCallbackFlags flags);
+
 typedef void (*GCCallback)();
 
 
@@ -2277,7 +2330,27 @@
 
   /**
    * Enables the host application to receive a notification before a
-   * major garbage colletion.  Allocations are not allowed in the
+   * garbage collection.  Allocations are not allowed in the
+   * callback function, you therefore cannot manipulate objects (set
+   * or delete properties for example) since it is possible such
+   * operations will result in the allocation of objects. It is possible
+   * to specify the GCType filter for your callback. But it is not possible to
+   * register the same callback function two times with different
+   * GCType filters.
+   */
+  static void AddGCPrologueCallback(
+      GCPrologueCallback callback, GCType gc_type_filter = kGCTypeAll);
+
+  /**
+   * This function removes callback which was installed by
+   * AddGCPrologueCallback function.
+   */
+  static void RemoveGCPrologueCallback(GCPrologueCallback callback);
+
+  /**
+   * The function is deprecated. Please use AddGCPrologueCallback instead.
+   * Enables the host application to receive a notification before a
+   * garbage collection.  Allocations are not allowed in the
    * callback function, you therefore cannot manipulate objects (set
    * or delete properties for example) since it is possible such
    * operations will result in the allocation of objects.
@@ -2286,6 +2359,26 @@
 
   /**
    * Enables the host application to receive a notification after a
+   * garbage collection.  Allocations are not allowed in the
+   * callback function, you therefore cannot manipulate objects (set
+   * or delete properties for example) since it is possible such
+   * operations will result in the allocation of objects. It is possible
+   * to specify the GCType filter for your callback. But it is not possible to
+   * register the same callback function two times with different
+   * GCType filters.
+   */
+  static void AddGCEpilogueCallback(
+      GCEpilogueCallback callback, GCType gc_type_filter = kGCTypeAll);
+
+  /**
+   * This function removes callback which was installed by
+   * AddGCEpilogueCallback function.
+   */
+  static void RemoveGCEpilogueCallback(GCEpilogueCallback callback);
+
+  /**
+   * The function is deprecated. Please use AddGCEpilogueCallback instead.
+   * Enables the host application to receive a notification after a
    * major garbage collection.  Allocations are not allowed in the
    * callback function, you therefore cannot manipulate objects (set
    * or delete properties for example) since it is possible such
@@ -2400,6 +2493,14 @@
   static int GetLogLines(int from_pos, char* dest_buf, int max_size);
 
   /**
+   * The minimum allowed size for a log lines buffer.  If the size of
+   * the buffer given will not be enough to hold a line of the maximum
+   * length, an attempt to find a log line end in GetLogLines will
+   * fail, and an empty result will be returned.
+   */
+  static const int kMinimumSizeForLogLinesBuffer = 2048;
+
+  /**
    * Retrieve the V8 thread id of the calling thread.
    *
    * The thread id for a thread should only be retrieved after the V8
@@ -2442,6 +2543,16 @@
   static void TerminateExecution();
 
   /**
+   * Is V8 terminating JavaScript execution.
+   *
+   * Returns true if JavaScript execution is currently terminating
+   * because of a call to TerminateExecution.  In that case there are
+   * still JavaScript frames on the stack and the termination
+   * exception is still active.
+   */
+  static bool IsExecutionTerminating();
+
+  /**
    * Releases any resources used by v8 and stops any utility threads
    * that may be running.  Note that disposing v8 is permanent, it
    * cannot be reinitialized.
@@ -2473,6 +2584,14 @@
    */
   static void LowMemoryNotification();
 
+  /**
+   * Optional notification that a context has been disposed. V8 uses
+   * these notifications to guide the GC heuristic. Returns the number
+   * of context disposals - including this one - since the last time
+   * V8 had a chance to clean up.
+   */
+  static int ContextDisposedNotification();
+
  private:
   V8();
 
@@ -2895,7 +3014,7 @@
 
 // Internal constants for 64-bit systems.
 template <> struct InternalConstants<8> {
-  static const int kStringResourceOffset = 2 * sizeof(void*);
+  static const int kStringResourceOffset = 3 * sizeof(void*);
 };
 
 /**
@@ -3259,7 +3378,7 @@
 
 
 Local<Value> AccessorInfo::Data() const {
-  return Local<Value>(reinterpret_cast<Value*>(&args_[-3]));
+  return Local<Value>(reinterpret_cast<Value*>(&args_[-2]));
 }