Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(382)

Unified Diff: include/v8.h

Issue 11366132: Rollback of r12868, r12849 in trunk branch. (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index dae18897ef636d2bdcd20144431d5a9111e66001..89d2974c05435bf051b5501e4ef4b2a1660da0ac 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -76,17 +76,6 @@
#endif // _WIN32
-// TODO(svenpanne) Remove this when the Chrome's v8 bindings have been adapted.
-#define V8_DISABLE_DEPRECATIONS 1
-
-#if defined(__GNUC__) && !defined(V8_DISABLE_DEPRECATIONS)
-#define V8_DEPRECATED(func) func __attribute__ ((deprecated))
-#elif defined(_MSC_VER) && !defined(V8_DISABLE_DEPRECATIONS)
-#define V8_DEPRECATED(func) __declspec(deprecated) func
-#else
-#define V8_DEPRECATED(func) func
-#endif
-
/**
* The v8 JavaScript engine.
*/
@@ -1600,41 +1589,16 @@ class Object : public Value {
/** Gets the number of internal fields for this Object. */
V8EXPORT int InternalFieldCount();
-
- /** Gets the value from an internal field. */
+ /** Gets the value in an internal field. */
inline Local<Value> GetInternalField(int index);
-
/** Sets the value in an internal field. */
V8EXPORT void SetInternalField(int index, Handle<Value> value);
- /**
- * Gets a native pointer from an internal field. Deprecated. If the pointer is
- * always 2-byte-aligned, use GetAlignedPointerFromInternalField instead,
- * otherwise use a combination of GetInternalField, External::Cast and
- * External::Value.
- */
- V8EXPORT V8_DEPRECATED(void* GetPointerFromInternalField(int index));
-
- /**
- * Sets a native pointer in an internal field. Deprecated. If the pointer is
- * always 2-byte aligned, use SetAlignedPointerInInternalField instead,
- * otherwise use a combination of External::New and SetInternalField.
- */
- inline V8_DEPRECATED(void SetPointerInInternalField(int index, void* value));
+ /** Gets a native pointer from an internal field. */
+ inline void* GetPointerFromInternalField(int index);
- /**
- * Gets a 2-byte-aligned native pointer from an internal field. This field
- * must have been set by SetAlignedPointerInInternalField, everything else
- * leads to undefined behavior.
- */
- inline void* GetAlignedPointerFromInternalField(int index);
-
- /**
- * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such
- * a field, GetAlignedPointerFromInternalField must be used, everything else
- * leads to undefined behavior.
- */
- V8EXPORT void SetAlignedPointerInInternalField(int index, void* value);
+ /** Sets a native pointer in an internal field. */
+ V8EXPORT void SetPointerInInternalField(int index, void* value);
// Testers for local properties.
V8EXPORT bool HasOwnProperty(Handle<String> key);
@@ -1765,8 +1729,14 @@ class Object : public Value {
private:
V8EXPORT Object();
V8EXPORT static void CheckCast(Value* obj);
- V8EXPORT Local<Value> SlowGetInternalField(int index);
- V8EXPORT void* SlowGetAlignedPointerFromInternalField(int index);
+ V8EXPORT Local<Value> CheckedGetInternalField(int index);
+ V8EXPORT void* SlowGetPointerFromInternalField(int index);
+
+ /**
+ * If quick access to the internal field is possible this method
+ * returns the value. Otherwise an empty handle is returned.
+ */
+ inline Local<Value> UncheckedGetInternalField(int index);
};
@@ -1977,22 +1947,29 @@ class RegExp : public Object {
/**
- * A JavaScript value that wraps a C++ void*. This type of value is mainly used
- * to associate C++ data structures with JavaScript objects.
+ * A JavaScript value that wraps a C++ void*. This type of value is
+ * mainly used to associate C++ data structures with JavaScript
+ * objects.
+ *
+ * The Wrap function V8 will return the most optimal Value object wrapping the
+ * C++ void*. The type of the value is not guaranteed to be an External object
+ * and no assumptions about its type should be made. To access the wrapped
+ * value Unwrap should be used, all other operations on that object will lead
+ * to unpredictable results.
*/
class External : public Value {
public:
- /** Deprecated, use New instead. */
- V8_DEPRECATED(static inline Local<Value> Wrap(void* value));
-
- /** Deprecated, use a combination of Cast and Value instead. */
- V8_DEPRECATED(static inline void* Unwrap(Handle<Value> obj));
+ V8EXPORT static Local<Value> Wrap(void* data);
+ static inline void* Unwrap(Handle<Value> obj);
V8EXPORT static Local<External> New(void* value);
static inline External* Cast(Value* obj);
V8EXPORT void* Value() const;
private:
+ V8EXPORT External();
V8EXPORT static void CheckCast(v8::Value* obj);
+ static inline void* QuickUnwrap(Handle<v8::Value> obj);
+ V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj);
};
@@ -3773,45 +3750,12 @@ class V8EXPORT Context {
static bool InContext();
/**
- * Gets embedder data with index 0. Deprecated, use GetEmbedderData with index
- * 0 instead.
- */
- V8_DEPRECATED(inline Local<Value> GetData());
-
- /**
- * Sets embedder data with index 0. Deprecated, use SetEmbedderData with index
- * 0 instead.
+ * Associate an additional data object with the context. This is mainly used
+ * with the debugger to provide additional information on the context through
+ * the debugger API.
*/
- V8_DEPRECATED(inline void SetData(Handle<Value> value));
-
- /**
- * Gets the embedder data with the given index, which must have been set by a
- * previous call to SetEmbedderData with the same index. Note that index 0
- * currently has a special meaning for Chrome's debugger.
- */
- inline Local<Value> GetEmbedderData(int index);
-
- /**
- * Sets the embedder data with the given index, growing the data as
- * needed. Note that index 0 currently has a special meaning for Chrome's
- * debugger.
- */
- void SetEmbedderData(int index, Handle<Value> value);
-
- /**
- * Gets a 2-byte-aligned native pointer from the embedder data with the given
- * index, which must have bees set by a previous call to
- * SetAlignedPointerInEmbedderData with the same index. Note that index 0
- * currently has a special meaning for Chrome's debugger.
- */
- inline void* GetAlignedPointerFromEmbedderData(int index);
-
- /**
- * Sets a 2-byte-aligned native pointer in the embedder data with the given
- * index, growing the data as needed. Note that index 0 currently has a
- * special meaning for Chrome's debugger.
- */
- void SetAlignedPointerInEmbedderData(int index, void* value);
+ void SetData(Handle<Value> data);
+ Local<Value> GetData();
/**
* Control whether code generation from strings is allowed. Calling
@@ -3860,9 +3804,6 @@ class V8EXPORT Context {
friend class Script;
friend class Object;
friend class Function;
-
- Local<Value> SlowGetEmbedderData(int index);
- void* SlowGetAlignedPointerFromEmbedderData(int index);
};
@@ -4096,6 +4037,11 @@ template <> struct SmiTagging<4> {
// Throw away top 32 bits and shift down (requires >> to be sign extending).
return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
}
+
+ // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi
+ // with a plain reinterpret_cast.
+ static const uintptr_t kEncodablePointerMask = 0x1;
+ static const int kPointerToSmiShift = 0;
};
// Smi constants for 64-bit systems.
@@ -4107,11 +4053,26 @@ template <> struct SmiTagging<8> {
// Shift down and throw away top 32 bits.
return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
}
+
+ // To maximize the range of pointers that can be encoded
+ // in the available 32 bits, we require them to be 8 bytes aligned.
+ // This gives 2 ^ (32 + 3) = 32G address space covered.
+ // It might be not enough to cover stack allocated objects on some platforms.
+ static const int kPointerAlignment = 3;
+
+ static const uintptr_t kEncodablePointerMask =
+ ~(uintptr_t(0xffffffff) << kPointerAlignment);
+
+ static const int kPointerToSmiShift =
+ kSmiTagSize + kSmiShiftSize - kPointerAlignment;
};
typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
+const uintptr_t kEncodablePointerMask =
+ PlatformSmiTagging::kEncodablePointerMask;
+const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift;
/**
* This class exports constants and functionality from within v8 that
@@ -4129,9 +4090,6 @@ class Internals {
static const int kOddballKindOffset = 3 * kApiPointerSize;
static const int kForeignAddressOffset = kApiPointerSize;
static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
- static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
- static const int kContextHeaderSize = 2 * kApiPointerSize;
- static const int kContextEmbedderDataIndex = 54;
static const int kFullStringRepresentationMask = 0x07;
static const int kStringEncodingMask = 0x4;
static const int kExternalTwoByteRepresentationTag = 0x02;
@@ -4144,7 +4102,7 @@ class Internals {
static const int kNullValueRootIndex = 7;
static const int kTrueValueRootIndex = 8;
static const int kFalseValueRootIndex = 9;
- static const int kEmptySymbolRootIndex = 118;
+ static const int kEmptySymbolRootIndex = 117;
static const int kJSObjectType = 0xaa;
static const int kFirstNonstringType = 0x80;
@@ -4159,6 +4117,10 @@ class Internals {
kHeapObjectTag);
}
+ static inline bool HasSmiTag(internal::Object* value) {
+ return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
+ }
+
static inline int SmiValue(internal::Object* value) {
return PlatformSmiTagging::SmiToInt(value);
}
@@ -4174,6 +4136,21 @@ class Internals {
return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
}
+ static inline void* GetExternalPointerFromSmi(internal::Object* value) {
+ const uintptr_t address = reinterpret_cast<uintptr_t>(value);
+ return reinterpret_cast<void*>(address >> kPointerToSmiShift);
+ }
+
+ static inline void* GetExternalPointer(internal::Object* obj) {
+ if (HasSmiTag(obj)) {
+ return GetExternalPointerFromSmi(obj);
+ } else if (GetInstanceType(obj) == kForeignType) {
+ return ReadField<void*>(obj, kForeignAddressOffset);
+ } else {
+ return NULL;
+ }
+ }
+
static inline bool IsExternalTwoByteString(int instance_type) {
int representation = (instance_type & kFullStringRepresentationMask);
return representation == kExternalTwoByteRepresentationTag;
@@ -4207,19 +4184,6 @@ class Internals {
return *reinterpret_cast<T*>(addr);
}
- template <typename T>
- static inline T ReadEmbedderData(Context* context, int index) {
- typedef internal::Object O;
- typedef internal::Internals I;
- O* ctx = *reinterpret_cast<O**>(context);
- int embedder_data_offset = I::kContextHeaderSize +
- (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
- O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
- int value_offset =
- I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
- return I::ReadField<T>(embedder_data, value_offset);
- }
-
static inline bool CanCastToHeapObject(void* o) { return false; }
static inline bool CanCastToHeapObject(Context* o) { return true; }
static inline bool CanCastToHeapObject(String* o) { return true; }
@@ -4417,40 +4381,63 @@ void Template::Set(const char* name, v8::Handle<Data> value) {
Local<Value> Object::GetInternalField(int index) {
#ifndef V8_ENABLE_CHECKS
+ Local<Value> quick_result = UncheckedGetInternalField(index);
+ if (!quick_result.IsEmpty()) return quick_result;
+#endif
+ return CheckedGetInternalField(index);
+}
+
+
+Local<Value> Object::UncheckedGetInternalField(int index) {
typedef internal::Object O;
typedef internal::Internals I;
O* obj = *reinterpret_cast<O**>(this);
- // Fast path: If the object is a plain JSObject, which is the common case, we
- // know where to find the internal fields and can return the value directly.
if (I::GetInstanceType(obj) == I::kJSObjectType) {
+ // If the object is a plain JSObject, which is the common case,
+ // we know where to find the internal fields and can return the
+ // value directly.
int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
O* value = I::ReadField<O*>(obj, offset);
O** result = HandleScope::CreateHandle(value);
return Local<Value>(reinterpret_cast<Value*>(result));
+ } else {
+ return Local<Value>();
}
+}
+
+
+void* External::Unwrap(Handle<v8::Value> obj) {
+#ifdef V8_ENABLE_CHECKS
+ return FullUnwrap(obj);
+#else
+ return QuickUnwrap(obj);
#endif
- return SlowGetInternalField(index);
}
-void Object::SetPointerInInternalField(int index, void* value) {
- SetInternalField(index, External::New(value));
+void* External::QuickUnwrap(Handle<v8::Value> wrapper) {
+ typedef internal::Object O;
+ O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper));
+ return internal::Internals::GetExternalPointer(obj);
}
-void* Object::GetAlignedPointerFromInternalField(int index) {
-#ifndef V8_ENABLE_CHECKS
+void* Object::GetPointerFromInternalField(int index) {
typedef internal::Object O;
typedef internal::Internals I;
+
O* obj = *reinterpret_cast<O**>(this);
- // Fast path: If the object is a plain JSObject, which is the common case, we
- // know where to find the internal fields and can return the value directly.
+
if (I::GetInstanceType(obj) == I::kJSObjectType) {
+ // If the object is a plain JSObject, which is the common case,
+ // we know where to find the internal fields and can return the
+ // value directly.
int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
- return I::ReadField<void*>(obj, offset);
+ O* value = I::ReadField<O*>(obj, offset);
+ return I::GetExternalPointer(value);
}
-#endif
- return SlowGetAlignedPointerFromInternalField(index);
+
+ return SlowGetPointerFromInternalField(index);
}
@@ -4642,16 +4629,6 @@ Function* Function::Cast(v8::Value* value) {
}
-Local<Value> External::Wrap(void* value) {
- return External::New(value);
-}
-
-
-void* External::Unwrap(Handle<v8::Value> obj) {
- return External::Cast(*obj)->Value();
-}
-
-
External* External::Cast(v8::Value* value) {
#ifdef V8_ENABLE_CHECKS
CheckCast(value);
@@ -4728,37 +4705,6 @@ void* Isolate::GetData() {
}
-Local<Value> Context::GetData() {
- return GetEmbedderData(0);
-}
-
-void Context::SetData(Handle<Value> data) {
- SetEmbedderData(0, data);
-}
-
-
-Local<Value> Context::GetEmbedderData(int index) {
-#ifndef V8_ENABLE_CHECKS
- typedef internal::Object O;
- typedef internal::Internals I;
- O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index));
- return Local<Value>(reinterpret_cast<Value*>(result));
-#else
- return SlowGetEmbedderData(index);
-#endif
-}
-
-
-void* Context::GetAlignedPointerFromEmbedderData(int index) {
-#ifndef V8_ENABLE_CHECKS
- typedef internal::Internals I;
- return I::ReadEmbedderData<void*>(this, index);
-#else
- return SlowGetAlignedPointerFromEmbedderData(index);
-#endif
-}
-
-
/**
* \example shell.cc
* A simple shell that takes a list of expressions on the
« no previous file with comments | « no previous file | src/api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698