diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2009-10-16 14:05:12 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2009-10-16 14:30:27 +0200 |
commit | 8e6d978bba0f3c52b297573157e4547ed9d291d1 (patch) | |
tree | b568b8d396ea5c57c60bd26bff536baa84d2b872 /deps/v8/include | |
parent | 5f82c4baf0e5aadb86f6bfc7f54f8e534ae0338a (diff) | |
download | node-new-8e6d978bba0f3c52b297573157e4547ed9d291d1.tar.gz |
Upgrade v8 to 1.3.16
and apply my V8 patch for debugging.
Diffstat (limited to 'deps/v8/include')
-rw-r--r-- | deps/v8/include/v8.h | 115 |
1 files changed, 84 insertions, 31 deletions
diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index adb9f43176..d923f97855 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -756,7 +756,7 @@ class V8EXPORT Value : public Data { /** JS == */ bool Equals(Handle<Value> that) const; bool StrictEquals(Handle<Value> that) const; - + private: inline bool QuickIsString() const; bool FullIsString() const; @@ -919,6 +919,12 @@ class V8EXPORT String : public Primitive { static Local<String> NewSymbol(const char* data, int length = -1); /** + * Creates a new string by concatenating the left and the right strings + * passed in as parameters. + */ + static Local<String> Concat(Handle<String> left, Handle<String>right); + + /** * Creates a new external string using the data defined in the given * resource. The resource is deleted when the external string is no * longer live on V8's heap. The caller of this function should not @@ -1036,7 +1042,7 @@ class V8EXPORT String : public Primitive { Value(const Value&); void operator=(const Value&); }; - + private: void VerifyExternalStringResource(ExternalStringResource* val) const; static void CheckCast(v8::Value* obj); @@ -1063,6 +1069,7 @@ class V8EXPORT Number : public Primitive { class V8EXPORT Integer : public Number { public: static Local<Integer> New(int32_t value); + static inline Local<Integer> NewFromUnsigned(uint32_t value); int64_t Value() const; static inline Integer* Cast(v8::Value* obj); private: @@ -1193,7 +1200,7 @@ class V8EXPORT Object : public Value { /** Gets a native pointer from an internal field. */ inline void* GetPointerFromInternalField(int index); - + /** Sets a native pointer in an internal field. */ void SetPointerInInternalField(int index, void* value); @@ -1246,7 +1253,7 @@ class V8EXPORT Object : public Value { bool SetHiddenValue(Handle<String> key, Handle<Value> value); Local<Value> GetHiddenValue(Handle<String> key); bool DeleteHiddenValue(Handle<String> key); - + /** * Returns true if this is an instance of an api function (one * created from a function created from a function template) and has @@ -1277,10 +1284,11 @@ class V8EXPORT Object : public Value { Object(); static void CheckCast(Value* obj); Local<Value> CheckedGetInternalField(int index); + void* SlowGetPointerFromInternalField(int index); /** * If quick access to the internal field is possible this method - * returns the value. Otherwise an empty handle is returned. + * returns the value. Otherwise an empty handle is returned. */ inline Local<Value> UncheckedGetInternalField(int index); }; @@ -2719,12 +2727,37 @@ const int kHeapObjectTag = 1; const int kHeapObjectTagSize = 2; const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; - // Tag information for Smi. const int kSmiTag = 0; const int kSmiTagSize = 1; const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; +template <size_t ptr_size> struct SmiConstants; + +// Smi constants for 32-bit systems. +template <> struct SmiConstants<4> { + static const int kSmiShiftSize = 0; + static const int kSmiValueSize = 31; + static inline int SmiToInt(internal::Object* value) { + int shift_bits = kSmiTagSize + kSmiShiftSize; + // Throw away top 32 bits and shift down (requires >> to be sign extending). + return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; + } +}; + +// Smi constants for 64-bit systems. +template <> struct SmiConstants<8> { + static const int kSmiShiftSize = 31; + static const int kSmiValueSize = 32; + static inline int SmiToInt(internal::Object* value) { + int shift_bits = kSmiTagSize + kSmiShiftSize; + // Shift down and throw away top 32 bits. + return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); + } +}; + +const int kSmiShiftSize = SmiConstants<sizeof(void*)>::kSmiShiftSize; +const int kSmiValueSize = SmiConstants<sizeof(void*)>::kSmiValueSize; /** * This class exports constants and functionality from within v8 that @@ -2743,7 +2776,6 @@ class Internals { static const int kJSObjectHeaderSize = 3 * sizeof(void*); static const int kFullStringRepresentationMask = 0x07; static const int kExternalTwoByteRepresentationTag = 0x03; - static const int kAlignedPointerShift = 2; // These constants are compiler dependent so their values must be // defined within the implementation. @@ -2761,7 +2793,23 @@ class Internals { } static inline int SmiValue(internal::Object* value) { - return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> kSmiTagSize; + return SmiConstants<sizeof(void*)>::SmiToInt(value); + } + + static inline int GetInstanceType(internal::Object* obj) { + typedef internal::Object O; + O* map = ReadField<O*>(obj, kHeapObjectMapOffset); + return ReadField<uint8_t>(map, kMapInstanceTypeOffset); + } + + static inline void* GetExternalPointer(internal::Object* obj) { + if (HasSmiTag(obj)) { + return obj; + } else if (GetInstanceType(obj) == kProxyType) { + return ReadField<void*>(obj, kProxyProxyOffset); + } else { + return NULL; + } } static inline bool IsExternalTwoByteString(int instance_type) { @@ -2921,9 +2969,7 @@ Local<Value> Object::UncheckedGetInternalField(int index) { typedef internal::Object O; typedef internal::Internals I; O* obj = *reinterpret_cast<O**>(this); - O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); - int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); - if (instance_type == I::kJSObjectType) { + 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. @@ -2948,25 +2994,27 @@ void* External::Unwrap(Handle<v8::Value> obj) { void* External::QuickUnwrap(Handle<v8::Value> wrapper) { typedef internal::Object O; - typedef internal::Internals I; O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); - if (I::HasSmiTag(obj)) { - int value = I::SmiValue(obj) << I::kAlignedPointerShift; - return reinterpret_cast<void*>(value); - } else { - O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); - int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); - if (instance_type == I::kProxyType) { - return I::ReadField<void*>(obj, I::kProxyProxyOffset); - } else { - return NULL; - } - } + return internal::Internals::GetExternalPointer(obj); } void* Object::GetPointerFromInternalField(int index) { - return External::Unwrap(GetInternalField(index)); + typedef internal::Object O; + typedef internal::Internals I; + + O* obj = *reinterpret_cast<O**>(this); + + 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 + (sizeof(void*) * index); + O* value = I::ReadField<O*>(obj, offset); + return I::GetExternalPointer(value); + } + + return SlowGetPointerFromInternalField(index); } @@ -2982,10 +3030,8 @@ String::ExternalStringResource* String::GetExternalStringResource() const { typedef internal::Object O; typedef internal::Internals I; O* obj = *reinterpret_cast<O**>(const_cast<String*>(this)); - O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); - int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); String::ExternalStringResource* result; - if (I::IsExternalTwoByteString(instance_type)) { + if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { void* value = I::ReadField<void*>(obj, I::kStringResourceOffset); result = reinterpret_cast<String::ExternalStringResource*>(value); } else { @@ -3011,9 +3057,7 @@ bool Value::QuickIsString() const { typedef internal::Internals I; O* obj = *reinterpret_cast<O**>(const_cast<Value*>(this)); if (!I::HasHeapObjectTag(obj)) return false; - O* map = I::ReadField<O*>(obj, I::kHeapObjectMapOffset); - int instance_type = I::ReadField<uint8_t>(map, I::kMapInstanceTypeOffset); - return (instance_type < I::kFirstNonstringType); + return (I::GetInstanceType(obj) < I::kFirstNonstringType); } @@ -3025,6 +3069,15 @@ Number* Number::Cast(v8::Value* value) { } +Local<Integer> Integer::NewFromUnsigned(uint32_t value) { + bool fits_into_int32_t = (value & (1 << 31)) == 0; + if (fits_into_int32_t) { + return Integer::New(static_cast<int32_t>(value)); + } + return Local<Integer>::Cast(Number::New(value)); +} + + Integer* Integer::Cast(v8::Value* value) { #ifdef V8_ENABLE_CHECKS CheckCast(value); |