Upgrade to 3.29
Update V8 to 3.29.88.17 and update makefiles to support building on
all the relevant platforms.
Bug: 17370214
Change-Id: Ia3407c157fd8d72a93e23d8318ccaf6ecf77fa4e
diff --git a/src/handles.h b/src/handles.h
index 960696b..577e83a 100644
--- a/src/handles.h
+++ b/src/handles.h
@@ -1,39 +1,78 @@
// Copyright 2011 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.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#ifndef V8_HANDLES_H_
#define V8_HANDLES_H_
-#include "allocation.h"
-#include "apiutils.h"
+#include "src/objects.h"
namespace v8 {
namespace internal {
+// A Handle can be converted into a MaybeHandle. Converting a MaybeHandle
+// into a Handle requires checking that it does not point to NULL. This
+// ensures NULL checks before use.
+// Do not use MaybeHandle as argument type.
+
+template<typename T>
+class MaybeHandle {
+ public:
+ INLINE(MaybeHandle()) : location_(NULL) { }
+
+ // Constructor for handling automatic up casting from Handle.
+ // Ex. Handle<JSArray> can be passed when MaybeHandle<Object> is expected.
+ template <class S> MaybeHandle(Handle<S> handle) {
+#ifdef DEBUG
+ T* a = NULL;
+ S* b = NULL;
+ a = b; // Fake assignment to enforce type checks.
+ USE(a);
+#endif
+ this->location_ = reinterpret_cast<T**>(handle.location());
+ }
+
+ // Constructor for handling automatic up casting.
+ // Ex. MaybeHandle<JSArray> can be passed when Handle<Object> is expected.
+ template <class S> MaybeHandle(MaybeHandle<S> maybe_handle) {
+#ifdef DEBUG
+ T* a = NULL;
+ S* b = NULL;
+ a = b; // Fake assignment to enforce type checks.
+ USE(a);
+#endif
+ location_ = reinterpret_cast<T**>(maybe_handle.location_);
+ }
+
+ INLINE(void Assert() const) { DCHECK(location_ != NULL); }
+ INLINE(void Check() const) { CHECK(location_ != NULL); }
+
+ INLINE(Handle<T> ToHandleChecked()) const {
+ Check();
+ return Handle<T>(location_);
+ }
+
+ // Convert to a Handle with a type that can be upcasted to.
+ template <class S> INLINE(bool ToHandle(Handle<S>* out)) {
+ if (location_ == NULL) {
+ *out = Handle<T>::null();
+ return false;
+ } else {
+ *out = Handle<T>(location_);
+ return true;
+ }
+ }
+
+ bool is_null() const { return location_ == NULL; }
+
+ protected:
+ T** location_;
+
+ // MaybeHandles of different classes are allowed to access each
+ // other's location_.
+ template<class S> friend class MaybeHandle;
+};
+
// ----------------------------------------------------------------------------
// A Handle provides a reference to an object that survives relocation by
// the garbage collector.
@@ -47,7 +86,9 @@
INLINE(explicit Handle(T* obj));
INLINE(Handle(T* obj, Isolate* isolate));
- INLINE(Handle()) : location_(NULL) {}
+ // TODO(yangguo): Values that contain empty handles should be declared as
+ // MaybeHandle to force validation before being used as handles.
+ INLINE(Handle()) : location_(NULL) { }
// Constructor for handling automatic up casting.
// Ex. Handle<JSFunction> can be passed when Handle<Object> is expected.
@@ -58,43 +99,73 @@
a = b; // Fake assignment to enforce type checks.
USE(a);
#endif
- location_ = reinterpret_cast<T**>(handle.location());
+ location_ = reinterpret_cast<T**>(handle.location_);
}
- INLINE(T* operator ->() const) { return operator*(); }
+ INLINE(T* operator->() const) { return operator*(); }
// Check if this handle refers to the exact same object as the other handle.
- bool is_identical_to(const Handle<T> other) const {
- return operator*() == *other;
- }
+ INLINE(bool is_identical_to(const Handle<T> other) const);
// Provides the C++ dereference operator.
INLINE(T* operator*() const);
// Returns the address to where the raw pointer is stored.
- T** location() const {
- ASSERT(location_ == NULL ||
- reinterpret_cast<Address>(*location_) != kZapValue);
- return location_;
- }
+ INLINE(T** location() const);
template <class S> static Handle<T> cast(Handle<S> that) {
- T::cast(*that);
- return Handle<T>(reinterpret_cast<T**>(that.location()));
+ T::cast(*reinterpret_cast<T**>(that.location_));
+ return Handle<T>(reinterpret_cast<T**>(that.location_));
}
+ // TODO(yangguo): Values that contain empty handles should be declared as
+ // MaybeHandle to force validation before being used as handles.
static Handle<T> null() { return Handle<T>(); }
bool is_null() const { return location_ == NULL; }
// Closes the given scope, but lets this handle escape. See
// implementation in api.h.
- inline Handle<T> EscapeFrom(v8::HandleScope* scope);
+ inline Handle<T> EscapeFrom(v8::EscapableHandleScope* scope);
+
+#ifdef DEBUG
+ enum DereferenceCheckMode { INCLUDE_DEFERRED_CHECK, NO_DEFERRED_CHECK };
+
+ bool IsDereferenceAllowed(DereferenceCheckMode mode) const;
+#endif // DEBUG
private:
T** location_;
+
+ // Handles of different classes are allowed to access each other's location_.
+ template<class S> friend class Handle;
};
+// Convenience wrapper.
+template<class T>
+inline Handle<T> handle(T* t, Isolate* isolate) {
+ return Handle<T>(t, isolate);
+}
+
+
+// Convenience wrapper.
+template<class T>
+inline Handle<T> handle(T* t) {
+ return Handle<T>(t, t->GetIsolate());
+}
+
+
+// Key comparison function for Map handles.
+inline bool operator<(const Handle<Map>& lhs, const Handle<Map>& rhs) {
+ // This is safe because maps don't move.
+ return *lhs < *rhs;
+}
+
+
+class DeferredHandles;
+class HandleScopeImplementer;
+
+
// A stack-allocated class that governs a number of local handles.
// After a handle scope has been created, all local handles will be
// allocated within that handle scope until either the handle scope is
@@ -109,24 +180,23 @@
// for which the handle scope has been deleted is undefined.
class HandleScope {
public:
- inline HandleScope();
explicit inline HandleScope(Isolate* isolate);
inline ~HandleScope();
// Counts the number of allocated handles.
- static int NumberOfHandles();
+ static int NumberOfHandles(Isolate* isolate);
// Creates a new handle with the given value.
template <typename T>
- static inline T** CreateHandle(T* value, Isolate* isolate);
+ static inline T** CreateHandle(Isolate* isolate, T* value);
// Deallocates any extensions used by the current scope.
static void DeleteExtensions(Isolate* isolate);
- static Address current_next_address();
- static Address current_limit_address();
- static Address current_level_address();
+ static Address current_next_address(Isolate* isolate);
+ static Address current_limit_address(Isolate* isolate);
+ static Address current_level_address(Isolate* isolate);
// Closes the HandleScope (invalidating all handles
// created in the scope of the HandleScope) and returns
@@ -144,159 +214,84 @@
void* operator new(size_t size);
void operator delete(void* size_t);
- inline void CloseScope();
-
Isolate* isolate_;
Object** prev_next_;
Object** prev_limit_;
- // Extend the handle scope making room for more handles.
- static internal::Object** Extend();
+ // Close the handle scope resetting limits to a previous state.
+ static inline void CloseScope(Isolate* isolate,
+ Object** prev_next,
+ Object** prev_limit);
+ // Extend the handle scope making room for more handles.
+ static internal::Object** Extend(Isolate* isolate);
+
+#ifdef ENABLE_HANDLE_ZAPPING
// Zaps the handles in the half-open interval [start, end).
- static void ZapRange(internal::Object** start, internal::Object** end);
+ static void ZapRange(Object** start, Object** end);
+#endif
friend class v8::HandleScope;
- friend class v8::ImplementationUtilities;
+ friend class v8::internal::DeferredHandles;
+ friend class v8::internal::HandleScopeImplementer;
+ friend class v8::internal::Isolate;
};
-// ----------------------------------------------------------------------------
-// Handle operations.
-// They might invoke garbage collection. The result is an handle to
-// an object of expected type, or the handle is an error if running out
-// of space or encountering an internal error.
-
-// Flattens a string.
-void FlattenString(Handle<String> str);
-
-// Flattens a string and returns the underlying external or sequential
-// string.
-Handle<String> FlattenGetString(Handle<String> str);
-
-int Utf8Length(Handle<String> str);
-
-Handle<Object> SetProperty(Handle<Object> object,
- Handle<Object> key,
- Handle<Object> value,
- PropertyAttributes attributes,
- StrictModeFlag strict_mode);
-
-Handle<Object> ForceSetProperty(Handle<JSObject> object,
- Handle<Object> key,
- Handle<Object> value,
- PropertyAttributes attributes);
-
-Handle<Object> ForceDeleteProperty(Handle<JSObject> object,
- Handle<Object> key);
-
-Handle<Object> GetProperty(Handle<JSReceiver> obj,
- const char* name);
-
-Handle<Object> GetProperty(Handle<Object> obj,
- Handle<Object> key);
-
-Handle<Object> GetPropertyWithInterceptor(Handle<JSObject> receiver,
- Handle<JSObject> holder,
- Handle<String> name,
- PropertyAttributes* attributes);
-
-Handle<Object> SetPrototype(Handle<JSObject> obj, Handle<Object> value);
-
-Handle<Object> LookupSingleCharacterStringFromCode(uint32_t index);
-
-Handle<JSObject> Copy(Handle<JSObject> obj);
-
-Handle<Object> SetAccessor(Handle<JSObject> obj, Handle<AccessorInfo> info);
-
-Handle<FixedArray> AddKeysFromJSArray(Handle<FixedArray>,
- Handle<JSArray> array);
-
-// Get the JS object corresponding to the given script; create it
-// if none exists.
-Handle<JSValue> GetScriptWrapper(Handle<Script> script);
-
-// Script line number computations.
-void InitScriptLineEnds(Handle<Script> script);
-// For string calculates an array of line end positions. If the string
-// does not end with a new line character, this character may optionally be
-// imagined.
-Handle<FixedArray> CalculateLineEnds(Handle<String> string,
- bool with_imaginary_last_new_line);
-int GetScriptLineNumber(Handle<Script> script, int code_position);
-// The safe version does not make heap allocations but may work much slower.
-int GetScriptLineNumberSafe(Handle<Script> script, int code_position);
-int GetScriptColumnNumber(Handle<Script> script, int code_position);
-
-// Computes the enumerable keys from interceptors. Used for debug mirrors and
-// by GetKeysInFixedArrayFor below.
-v8::Handle<v8::Array> GetKeysForNamedInterceptor(Handle<JSReceiver> receiver,
- Handle<JSObject> object);
-v8::Handle<v8::Array> GetKeysForIndexedInterceptor(Handle<JSReceiver> receiver,
- Handle<JSObject> object);
-
-enum KeyCollectionType { LOCAL_ONLY, INCLUDE_PROTOS };
-
-// Computes the enumerable keys for a JSObject. Used for implementing
-// "for (n in object) { }".
-Handle<FixedArray> GetKeysInFixedArrayFor(Handle<JSReceiver> object,
- KeyCollectionType type,
- bool* threw);
-Handle<JSArray> GetKeysFor(Handle<JSReceiver> object, bool* threw);
-Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
- bool cache_result);
-
-// Computes the union of keys and return the result.
-// Used for implementing "for (n in object) { }"
-Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first,
- Handle<FixedArray> second);
-
-Handle<String> SubString(Handle<String> str,
- int start,
- int end,
- PretenureFlag pretenure = NOT_TENURED);
-
-// Sets the expected number of properties for the function's instances.
-void SetExpectedNofProperties(Handle<JSFunction> func, int nof);
-
-// Sets the prototype property for a function instance.
-void SetPrototypeProperty(Handle<JSFunction> func, Handle<JSObject> value);
-
-// Sets the expected number of properties based on estimate from compiler.
-void SetExpectedNofPropertiesFromEstimate(Handle<SharedFunctionInfo> shared,
- int estimate);
+class DeferredHandles;
-Handle<JSGlobalProxy> ReinitializeJSGlobalProxy(
- Handle<JSFunction> constructor,
- Handle<JSGlobalProxy> global);
+class DeferredHandleScope {
+ public:
+ explicit DeferredHandleScope(Isolate* isolate);
+ // The DeferredHandles object returned stores the Handles created
+ // since the creation of this DeferredHandleScope. The Handles are
+ // alive as long as the DeferredHandles object is alive.
+ DeferredHandles* Detach();
+ ~DeferredHandleScope();
-Handle<Object> SetPrototype(Handle<JSFunction> function,
- Handle<Object> prototype);
+ private:
+ Object** prev_limit_;
+ Object** prev_next_;
+ HandleScopeImplementer* impl_;
-Handle<ObjectHashSet> ObjectHashSetAdd(Handle<ObjectHashSet> table,
- Handle<Object> key);
+#ifdef DEBUG
+ bool handles_detached_;
+ int prev_level_;
+#endif
-Handle<ObjectHashSet> ObjectHashSetRemove(Handle<ObjectHashSet> table,
- Handle<Object> key);
+ friend class HandleScopeImplementer;
+};
-Handle<ObjectHashTable> PutIntoObjectHashTable(Handle<ObjectHashTable> table,
- Handle<Object> key,
- Handle<Object> value);
-class NoHandleAllocation BASE_EMBEDDED {
+// Seal off the current HandleScope so that new handles can only be created
+// if a new HandleScope is entered.
+class SealHandleScope BASE_EMBEDDED {
public:
#ifndef DEBUG
- NoHandleAllocation() {}
- ~NoHandleAllocation() {}
+ explicit SealHandleScope(Isolate* isolate) {}
+ ~SealHandleScope() {}
#else
- inline NoHandleAllocation();
- inline ~NoHandleAllocation();
+ explicit inline SealHandleScope(Isolate* isolate);
+ inline ~SealHandleScope();
private:
+ Isolate* isolate_;
+ Object** limit_;
int level_;
#endif
};
+struct HandleScopeData {
+ internal::Object** next;
+ internal::Object** limit;
+ int level;
+
+ void Initialize() {
+ next = limit = NULL;
+ level = 0;
+ }
+};
+
} } // namespace v8::internal
#endif // V8_HANDLES_H_