Chromium Code Reviews
Help | Chromium Project | Sign in
(162)

Side by Side Diff: include/v8.h

Issue 11190050: Heavy cleanup of the external pointer API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 1 year, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/api.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #define V8EXPORT __attribute__ ((visibility("default"))) 69 #define V8EXPORT __attribute__ ((visibility("default")))
70 #else 70 #else
71 #define V8EXPORT 71 #define V8EXPORT
72 #endif 72 #endif
73 #else 73 #else
74 #define V8EXPORT 74 #define V8EXPORT
75 #endif 75 #endif
76 76
77 #endif // _WIN32 77 #endif // _WIN32
78 78
79 // TODO(svenpanne) Remove this when the Chrome's v8 bindings have been adapted.
80 #define V8_DISABLE_DEPRECATIONS 1
81
82 #if defined(__GNUC__) && !defined(V8_DISABLE_DEPRECATIONS)
83 #define V8_DEPRECATED(func) func __attribute__ ((deprecated))
84 #elif defined(_MSC_VER) && !defined(V8_DISABLE_DEPRECATIONS)
85 #define V8_DEPRECATED(func) __declspec(deprecated) func
86 #else
87 #define V8_DEPRECATED(func) func
88 #endif
89
79 /** 90 /**
80 * The v8 JavaScript engine. 91 * The v8 JavaScript engine.
81 */ 92 */
82 namespace v8 { 93 namespace v8 {
83 94
84 class Context; 95 class Context;
85 class String; 96 class String;
86 class StringObject; 97 class StringObject;
87 class Value; 98 class Value;
88 class Utils; 99 class Utils;
(...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 */ 1591 */
1581 V8EXPORT Local<Value> GetConstructor(); 1592 V8EXPORT Local<Value> GetConstructor();
1582 1593
1583 /** 1594 /**
1584 * Returns the name of the function invoked as a constructor for this object. 1595 * Returns the name of the function invoked as a constructor for this object.
1585 */ 1596 */
1586 V8EXPORT Local<String> GetConstructorName(); 1597 V8EXPORT Local<String> GetConstructorName();
1587 1598
1588 /** Gets the number of internal fields for this Object. */ 1599 /** Gets the number of internal fields for this Object. */
1589 V8EXPORT int InternalFieldCount(); 1600 V8EXPORT int InternalFieldCount();
1590 /** Gets the value in an internal field. */ 1601
1602 /** Gets the value from an internal field. */
1591 inline Local<Value> GetInternalField(int index); 1603 inline Local<Value> GetInternalField(int index);
1604
1592 /** Sets the value in an internal field. */ 1605 /** Sets the value in an internal field. */
1593 V8EXPORT void SetInternalField(int index, Handle<Value> value); 1606 V8EXPORT void SetInternalField(int index, Handle<Value> value);
1594 1607
1595 /** Gets a native pointer from an internal field. */ 1608 /**
1596 inline void* GetPointerFromInternalField(int index); 1609 * Gets a native pointer from an internal field. Deprecated. If your pointer
1610 * is always 2-byte-aligned, use GetAlignedPointerFromInternalField instead,
1611 * otherwise use a combination of GetInternalField, External::Cast and
1612 * External::Value.
1613 */
1614 V8_DEPRECATED(void* GetPointerFromInternalField(int index));
1597 1615
1598 /** Sets a native pointer in an internal field. */ 1616 /**
1599 V8EXPORT void SetPointerInInternalField(int index, void* value); 1617 * Sets a native pointer in an internal field. Deprecated. If your pointer is
1618 * always 2-byte aligned, use SetAlignedPointerInInternalField instead,
1619 * otherwise use a combination of External::New and SetInternalField.
1620 */
1621 inline V8_DEPRECATED(void SetPointerInInternalField(int index, void* value));
1622
1623 /**
1624 * Gets a 2-byte-aligned native pointer from an internal field. This field
1625 * must have been set by SetAlignedPointerInInternalField, everything else
1626 * leads to undefined behavior.
1627 */
1628 inline void* GetAlignedPointerFromInternalField(int index);
1629
1630 /**
1631 * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such
1632 * a field, you must use GetAlignedPointerFromInternalField, everything else
Michael Starzinger 2012/10/25 09:41:53 Can we rephrase the comment so that it doesn't use
Sven Panne 2012/10/25 14:23:08 Done here and at similar places.
1633 * leads to undefined behavior.
1634 */
1635 V8EXPORT void SetAlignedPointerInInternalField(int index, void* value);
1600 1636
1601 // Testers for local properties. 1637 // Testers for local properties.
1602 V8EXPORT bool HasOwnProperty(Handle<String> key); 1638 V8EXPORT bool HasOwnProperty(Handle<String> key);
1603 V8EXPORT bool HasRealNamedProperty(Handle<String> key); 1639 V8EXPORT bool HasRealNamedProperty(Handle<String> key);
1604 V8EXPORT bool HasRealIndexedProperty(uint32_t index); 1640 V8EXPORT bool HasRealIndexedProperty(uint32_t index);
1605 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); 1641 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key);
1606 1642
1607 /** 1643 /**
1608 * If result.IsEmpty() no real property was located in the prototype chain. 1644 * If result.IsEmpty() no real property was located in the prototype chain.
1609 * This means interceptors in the prototype chain are not called. 1645 * This means interceptors in the prototype chain are not called.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 */ 1756 */
1721 V8EXPORT Local<Value> CallAsConstructor(int argc, 1757 V8EXPORT Local<Value> CallAsConstructor(int argc,
1722 Handle<Value> argv[]); 1758 Handle<Value> argv[]);
1723 1759
1724 V8EXPORT static Local<Object> New(); 1760 V8EXPORT static Local<Object> New();
1725 static inline Object* Cast(Value* obj); 1761 static inline Object* Cast(Value* obj);
1726 1762
1727 private: 1763 private:
1728 V8EXPORT Object(); 1764 V8EXPORT Object();
1729 V8EXPORT static void CheckCast(Value* obj); 1765 V8EXPORT static void CheckCast(Value* obj);
1730 V8EXPORT Local<Value> CheckedGetInternalField(int index); 1766 V8EXPORT Local<Value> SlowGetInternalField(int index);
1731 V8EXPORT void* SlowGetPointerFromInternalField(int index); 1767 V8EXPORT void* SlowGetAlignedPointerFromInternalField(int index);
1732
1733 /**
1734 * If quick access to the internal field is possible this method
1735 * returns the value. Otherwise an empty handle is returned.
1736 */
1737 inline Local<Value> UncheckedGetInternalField(int index);
1738 }; 1768 };
1739 1769
1740 1770
1741 /** 1771 /**
1742 * An instance of the built-in array constructor (ECMA-262, 15.4.2). 1772 * An instance of the built-in array constructor (ECMA-262, 15.4.2).
1743 */ 1773 */
1744 class Array : public Object { 1774 class Array : public Object {
1745 public: 1775 public:
1746 V8EXPORT uint32_t Length() const; 1776 V8EXPORT uint32_t Length() const;
1747 1777
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1938 V8EXPORT Flags GetFlags() const; 1968 V8EXPORT Flags GetFlags() const;
1939 1969
1940 static inline RegExp* Cast(v8::Value* obj); 1970 static inline RegExp* Cast(v8::Value* obj);
1941 1971
1942 private: 1972 private:
1943 V8EXPORT static void CheckCast(v8::Value* obj); 1973 V8EXPORT static void CheckCast(v8::Value* obj);
1944 }; 1974 };
1945 1975
1946 1976
1947 /** 1977 /**
1948 * A JavaScript value that wraps a C++ void*. This type of value is 1978 * A JavaScript value that wraps a C++ void*. This type of value is mainly used
1949 * mainly used to associate C++ data structures with JavaScript 1979 * to associate C++ data structures with JavaScript objects.
1950 * objects.
1951 *
1952 * The Wrap function V8 will return the most optimal Value object wrapping the
1953 * C++ void*. The type of the value is not guaranteed to be an External object
1954 * and no assumptions about its type should be made. To access the wrapped
1955 * value Unwrap should be used, all other operations on that object will lead
1956 * to unpredictable results.
1957 */ 1980 */
1958 class External : public Value { 1981 class External : public Value {
1959 public: 1982 public:
1960 V8EXPORT static Local<Value> Wrap(void* data); 1983 /** Deprecated, use New instead. */
1961 static inline void* Unwrap(Handle<Value> obj); 1984 V8_DEPRECATED(static inline Local<Value> Wrap(void* value));
1985
1986 /** Deprecated, use a combination of Cast and Value instead. */
1987 V8_DEPRECATED(static inline void* Unwrap(Handle<Value> obj));
1962 1988
1963 V8EXPORT static Local<External> New(void* value); 1989 V8EXPORT static Local<External> New(void* value);
1964 static inline External* Cast(Value* obj); 1990 static inline External* Cast(Value* obj);
1965 V8EXPORT void* Value() const; 1991 V8EXPORT void* Value() const;
1966 private: 1992 private:
1967 V8EXPORT External();
1968 V8EXPORT static void CheckCast(v8::Value* obj); 1993 V8EXPORT static void CheckCast(v8::Value* obj);
1969 static inline void* QuickUnwrap(Handle<v8::Value> obj);
1970 V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj);
1971 }; 1994 };
1972 1995
1973 1996
1974 // --- Templates --- 1997 // --- Templates ---
1975 1998
1976 1999
1977 /** 2000 /**
1978 * The superclass of object and function templates. 2001 * The superclass of object and function templates.
1979 */ 2002 */
1980 class V8EXPORT Template : public Data { 2003 class V8EXPORT Template : public Data {
(...skipping 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after
3737 */ 3760 */
3738 void Exit(); 3761 void Exit();
3739 3762
3740 /** Returns true if the context has experienced an out of memory situation. */ 3763 /** Returns true if the context has experienced an out of memory situation. */
3741 bool HasOutOfMemoryException(); 3764 bool HasOutOfMemoryException();
3742 3765
3743 /** Returns true if V8 has a current context. */ 3766 /** Returns true if V8 has a current context. */
3744 static bool InContext(); 3767 static bool InContext();
3745 3768
3746 /** 3769 /**
3747 * Associate an additional data object with the context. This is mainly used 3770 * Gets embedder data with index 0. Deprecated, use GetEmbedderData with index
3748 * with the debugger to provide additional information on the context through 3771 * 0 instead.
3749 * the debugger API.
3750 */ 3772 */
3751 void SetData(Handle<Value> data); 3773 V8_DEPRECATED(inline Local<Value> GetData());
3752 Local<Value> GetData(); 3774
3775 /**
3776 * Sets embedder data with index 0. Deprecated, use SetEmbedderData with index
3777 * 0 instead.
3778 */
3779 V8_DEPRECATED(inline void SetData(Handle<Value> value));
3780
3781 /**
3782 * Gets the embedder data with the given index, which must have been set by a
3783 * previous call to SetEmbedderData with the same index. Note that index 0
3784 * currently has a special meaning for Chrome's debugger.
3785 */
3786 inline Local<Value> GetEmbedderData(int index);
3787
3788 /**
3789 * Sets the embedder data with the given index, growing the data as
3790 * needed. Note that index 0 currently has a special meaning for Chrome's
3791 * debugger.
3792 */
3793 void SetEmbedderData(int index, Handle<Value> value);
3794
3795 /**
3796 * Gets a 2-byte-aligned native pointer from the embedder data with the given
3797 * index, which must have bees set by a previous call to
3798 * SetAlignedPointerInEmbedderData with the same index. Note that index 0
3799 * currently has a special meaning for Chrome's debugger.
3800 */
3801 inline void* GetAlignedPointerFromEmbedderData(int index);
3802
3803 /**
3804 * Sets a 2-byte-aligned native pointer in the embedder data with the given
3805 * index, growing the data as needed. Note that index 0 currently has a
3806 * special meaning for Chrome's debugger.
3807 */
3808 void SetAlignedPointerInEmbedderData(int index, void* value);
3753 3809
3754 /** 3810 /**
3755 * Control whether code generation from strings is allowed. Calling 3811 * Control whether code generation from strings is allowed. Calling
3756 * this method with false will disable 'eval' and the 'Function' 3812 * this method with false will disable 'eval' and the 'Function'
3757 * constructor for code running in this context. If 'eval' or the 3813 * constructor for code running in this context. If 'eval' or the
3758 * 'Function' constructor are used an exception will be thrown. 3814 * 'Function' constructor are used an exception will be thrown.
3759 * 3815 *
3760 * If code generation from strings is not allowed the 3816 * If code generation from strings is not allowed the
3761 * V8::AllowCodeGenerationFromStrings callback will be invoked if 3817 * V8::AllowCodeGenerationFromStrings callback will be invoked if
3762 * set before blocking the call to 'eval' or the 'Function' 3818 * set before blocking the call to 'eval' or the 'Function'
(...skipping 28 matching lines...) Expand all
3791 inline ~Scope() { context_->Exit(); } 3847 inline ~Scope() { context_->Exit(); }
3792 private: 3848 private:
3793 Handle<Context> context_; 3849 Handle<Context> context_;
3794 }; 3850 };
3795 3851
3796 private: 3852 private:
3797 friend class Value; 3853 friend class Value;
3798 friend class Script; 3854 friend class Script;
3799 friend class Object; 3855 friend class Object;
3800 friend class Function; 3856 friend class Function;
3857
3858 Local<Value> SlowGetEmbedderData(int index);
3859 void* SlowGetAlignedPointerFromEmbedderData(int index);
3801 }; 3860 };
3802 3861
3803 3862
3804 /** 3863 /**
3805 * Multiple threads in V8 are allowed, but only one thread at a time 3864 * Multiple threads in V8 are allowed, but only one thread at a time
3806 * is allowed to use any given V8 isolate. See Isolate class 3865 * is allowed to use any given V8 isolate. See Isolate class
3807 * comments. The definition of 'using V8 isolate' includes 3866 * comments. The definition of 'using V8 isolate' includes
3808 * accessing handles or holding onto object pointers obtained 3867 * accessing handles or holding onto object pointers obtained
3809 * from V8 handles while in the particular V8 isolate. It is up 3868 * from V8 handles while in the particular V8 isolate. It is up
3810 * to the user of V8 to ensure (perhaps with locking) that this 3869 * to the user of V8 to ensure (perhaps with locking) that this
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
4024 4083
4025 // Smi constants for 32-bit systems. 4084 // Smi constants for 32-bit systems.
4026 template <> struct SmiTagging<4> { 4085 template <> struct SmiTagging<4> {
4027 static const int kSmiShiftSize = 0; 4086 static const int kSmiShiftSize = 0;
4028 static const int kSmiValueSize = 31; 4087 static const int kSmiValueSize = 31;
4029 static inline int SmiToInt(internal::Object* value) { 4088 static inline int SmiToInt(internal::Object* value) {
4030 int shift_bits = kSmiTagSize + kSmiShiftSize; 4089 int shift_bits = kSmiTagSize + kSmiShiftSize;
4031 // Throw away top 32 bits and shift down (requires >> to be sign extending). 4090 // Throw away top 32 bits and shift down (requires >> to be sign extending).
4032 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; 4091 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits;
4033 } 4092 }
4034
4035 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi
4036 // with a plain reinterpret_cast.
4037 static const uintptr_t kEncodablePointerMask = 0x1;
4038 static const int kPointerToSmiShift = 0;
4039 }; 4093 };
4040 4094
4041 // Smi constants for 64-bit systems. 4095 // Smi constants for 64-bit systems.
4042 template <> struct SmiTagging<8> { 4096 template <> struct SmiTagging<8> {
4043 static const int kSmiShiftSize = 31; 4097 static const int kSmiShiftSize = 31;
4044 static const int kSmiValueSize = 32; 4098 static const int kSmiValueSize = 32;
4045 static inline int SmiToInt(internal::Object* value) { 4099 static inline int SmiToInt(internal::Object* value) {
4046 int shift_bits = kSmiTagSize + kSmiShiftSize; 4100 int shift_bits = kSmiTagSize + kSmiShiftSize;
4047 // Shift down and throw away top 32 bits. 4101 // Shift down and throw away top 32 bits.
4048 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); 4102 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits);
4049 } 4103 }
4050
4051 // To maximize the range of pointers that can be encoded
4052 // in the available 32 bits, we require them to be 8 bytes aligned.
4053 // This gives 2 ^ (32 + 3) = 32G address space covered.
4054 // It might be not enough to cover stack allocated objects on some platforms.
4055 static const int kPointerAlignment = 3;
4056
4057 static const uintptr_t kEncodablePointerMask =
4058 ~(uintptr_t(0xffffffff) << kPointerAlignment);
4059
4060 static const int kPointerToSmiShift =
4061 kSmiTagSize + kSmiShiftSize - kPointerAlignment;
4062 }; 4104 };
4063 4105
4064 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; 4106 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging;
4065 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; 4107 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
4066 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; 4108 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
4067 const uintptr_t kEncodablePointerMask =
4068 PlatformSmiTagging::kEncodablePointerMask;
4069 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift;
4070 4109
4071 /** 4110 /**
4072 * This class exports constants and functionality from within v8 that 4111 * This class exports constants and functionality from within v8 that
4073 * is necessary to implement inline functions in the v8 api. Don't 4112 * is necessary to implement inline functions in the v8 api. Don't
4074 * depend on functions and constants defined here. 4113 * depend on functions and constants defined here.
4075 */ 4114 */
4076 class Internals { 4115 class Internals {
4077 public: 4116 public:
4078 // These values match non-compiler-dependent values defined within 4117 // These values match non-compiler-dependent values defined within
4079 // the implementation of v8. 4118 // the implementation of v8.
4080 static const int kHeapObjectMapOffset = 0; 4119 static const int kHeapObjectMapOffset = 0;
4081 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; 4120 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize;
4082 static const int kStringResourceOffset = 3 * kApiPointerSize; 4121 static const int kStringResourceOffset = 3 * kApiPointerSize;
4083 4122
4084 static const int kOddballKindOffset = 3 * kApiPointerSize; 4123 static const int kOddballKindOffset = 3 * kApiPointerSize;
4085 static const int kForeignAddressOffset = kApiPointerSize; 4124 static const int kForeignAddressOffset = kApiPointerSize;
4086 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; 4125 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
4126 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
4127 static const int kContextHeaderSize = 2 * kApiPointerSize;
4128 static const int kContextEmbedderDataIndex = 54;
4087 static const int kFullStringRepresentationMask = 0x07; 4129 static const int kFullStringRepresentationMask = 0x07;
4088 static const int kStringEncodingMask = 0x4; 4130 static const int kStringEncodingMask = 0x4;
4089 static const int kExternalTwoByteRepresentationTag = 0x02; 4131 static const int kExternalTwoByteRepresentationTag = 0x02;
4090 static const int kExternalAsciiRepresentationTag = 0x06; 4132 static const int kExternalAsciiRepresentationTag = 0x06;
4091 4133
4092 static const int kIsolateStateOffset = 0; 4134 static const int kIsolateStateOffset = 0;
4093 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; 4135 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize;
4094 static const int kIsolateRootsOffset = 3 * kApiPointerSize; 4136 static const int kIsolateRootsOffset = 3 * kApiPointerSize;
4095 static const int kUndefinedValueRootIndex = 5; 4137 static const int kUndefinedValueRootIndex = 5;
4096 static const int kNullValueRootIndex = 7; 4138 static const int kNullValueRootIndex = 7;
4097 static const int kTrueValueRootIndex = 8; 4139 static const int kTrueValueRootIndex = 8;
4098 static const int kFalseValueRootIndex = 9; 4140 static const int kFalseValueRootIndex = 9;
4099 static const int kEmptySymbolRootIndex = 117; 4141 static const int kEmptySymbolRootIndex = 118;
4100 4142
4101 static const int kJSObjectType = 0xaa; 4143 static const int kJSObjectType = 0xaa;
4102 static const int kFirstNonstringType = 0x80; 4144 static const int kFirstNonstringType = 0x80;
4103 static const int kOddballType = 0x82; 4145 static const int kOddballType = 0x82;
4104 static const int kForeignType = 0x85; 4146 static const int kForeignType = 0x85;
4105 4147
4106 static const int kUndefinedOddballKind = 5; 4148 static const int kUndefinedOddballKind = 5;
4107 static const int kNullOddballKind = 3; 4149 static const int kNullOddballKind = 3;
4108 4150
4109 static inline bool HasHeapObjectTag(internal::Object* value) { 4151 static inline bool HasHeapObjectTag(internal::Object* value) {
4110 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == 4152 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
4111 kHeapObjectTag); 4153 kHeapObjectTag);
4112 } 4154 }
4113 4155
4114 static inline bool HasSmiTag(internal::Object* value) {
4115 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag);
4116 }
4117
4118 static inline int SmiValue(internal::Object* value) { 4156 static inline int SmiValue(internal::Object* value) {
4119 return PlatformSmiTagging::SmiToInt(value); 4157 return PlatformSmiTagging::SmiToInt(value);
4120 } 4158 }
4121 4159
4122 static inline int GetInstanceType(internal::Object* obj) { 4160 static inline int GetInstanceType(internal::Object* obj) {
4123 typedef internal::Object O; 4161 typedef internal::Object O;
4124 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); 4162 O* map = ReadField<O*>(obj, kHeapObjectMapOffset);
4125 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); 4163 return ReadField<uint8_t>(map, kMapInstanceTypeOffset);
4126 } 4164 }
4127 4165
4128 static inline int GetOddballKind(internal::Object* obj) { 4166 static inline int GetOddballKind(internal::Object* obj) {
4129 typedef internal::Object O; 4167 typedef internal::Object O;
4130 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); 4168 return SmiValue(ReadField<O*>(obj, kOddballKindOffset));
4131 } 4169 }
4132 4170
4133 static inline void* GetExternalPointerFromSmi(internal::Object* value) {
4134 const uintptr_t address = reinterpret_cast<uintptr_t>(value);
4135 return reinterpret_cast<void*>(address >> kPointerToSmiShift);
4136 }
4137
4138 static inline void* GetExternalPointer(internal::Object* obj) {
4139 if (HasSmiTag(obj)) {
4140 return GetExternalPointerFromSmi(obj);
4141 } else if (GetInstanceType(obj) == kForeignType) {
4142 return ReadField<void*>(obj, kForeignAddressOffset);
4143 } else {
4144 return NULL;
4145 }
4146 }
4147
4148 static inline bool IsExternalTwoByteString(int instance_type) { 4171 static inline bool IsExternalTwoByteString(int instance_type) {
4149 int representation = (instance_type & kFullStringRepresentationMask); 4172 int representation = (instance_type & kFullStringRepresentationMask);
4150 return representation == kExternalTwoByteRepresentationTag; 4173 return representation == kExternalTwoByteRepresentationTag;
4151 } 4174 }
4152 4175
4153 static inline bool IsInitialized(v8::Isolate* isolate) { 4176 static inline bool IsInitialized(v8::Isolate* isolate) {
4154 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; 4177 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset;
4155 return *reinterpret_cast<int*>(addr) == 1; 4178 return *reinterpret_cast<int*>(addr) == 1;
4156 } 4179 }
4157 4180
(...skipping 13 matching lines...) Expand all
4171 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; 4194 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
4172 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); 4195 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
4173 } 4196 }
4174 4197
4175 template <typename T> 4198 template <typename T>
4176 static inline T ReadField(Object* ptr, int offset) { 4199 static inline T ReadField(Object* ptr, int offset) {
4177 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; 4200 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag;
4178 return *reinterpret_cast<T*>(addr); 4201 return *reinterpret_cast<T*>(addr);
4179 } 4202 }
4180 4203
4204 template <typename T>
4205 static inline T ReadEmbedderData(Context* context, int index) {
4206 typedef internal::Object O;
4207 typedef internal::Internals I;
4208 O* ctx = *reinterpret_cast<O**>(context);
4209 int embedder_data_offset = I::kContextHeaderSize +
4210 (internal::kApiPointerSize * I::kContextEmbedderDataIndex);
4211 O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset);
4212 int value_offset =
4213 I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index);
4214 return I::ReadField<T>(embedder_data, value_offset);
4215 }
4216
4181 static inline bool CanCastToHeapObject(void* o) { return false; } 4217 static inline bool CanCastToHeapObject(void* o) { return false; }
4182 static inline bool CanCastToHeapObject(Context* o) { return true; } 4218 static inline bool CanCastToHeapObject(Context* o) { return true; }
4183 static inline bool CanCastToHeapObject(String* o) { return true; } 4219 static inline bool CanCastToHeapObject(String* o) { return true; }
4184 static inline bool CanCastToHeapObject(Object* o) { return true; } 4220 static inline bool CanCastToHeapObject(Object* o) { return true; }
4185 static inline bool CanCastToHeapObject(Message* o) { return true; } 4221 static inline bool CanCastToHeapObject(Message* o) { return true; }
4186 static inline bool CanCastToHeapObject(StackTrace* o) { return true; } 4222 static inline bool CanCastToHeapObject(StackTrace* o) { return true; }
4187 static inline bool CanCastToHeapObject(StackFrame* o) { return true; } 4223 static inline bool CanCastToHeapObject(StackFrame* o) { return true; }
4188 }; 4224 };
4189 4225
4190 } // namespace internal 4226 } // namespace internal
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
4352 } 4388 }
4353 4389
4354 4390
4355 void Template::Set(const char* name, v8::Handle<Data> value) { 4391 void Template::Set(const char* name, v8::Handle<Data> value) {
4356 Set(v8::String::New(name), value); 4392 Set(v8::String::New(name), value);
4357 } 4393 }
4358 4394
4359 4395
4360 Local<Value> Object::GetInternalField(int index) { 4396 Local<Value> Object::GetInternalField(int index) {
4361 #ifndef V8_ENABLE_CHECKS 4397 #ifndef V8_ENABLE_CHECKS
4362 Local<Value> quick_result = UncheckedGetInternalField(index);
4363 if (!quick_result.IsEmpty()) return quick_result;
4364 #endif
4365 return CheckedGetInternalField(index);
4366 }
4367
4368
4369 Local<Value> Object::UncheckedGetInternalField(int index) {
4370 typedef internal::Object O; 4398 typedef internal::Object O;
4371 typedef internal::Internals I; 4399 typedef internal::Internals I;
4372 O* obj = *reinterpret_cast<O**>(this); 4400 O* obj = *reinterpret_cast<O**>(this);
4401 // Fast path: If the object is a plain JSObject, which is the common case, we
4402 // know where to find the internal fields and can return the value directly.
4373 if (I::GetInstanceType(obj) == I::kJSObjectType) { 4403 if (I::GetInstanceType(obj) == I::kJSObjectType) {
4374 // If the object is a plain JSObject, which is the common case,
4375 // we know where to find the internal fields and can return the
4376 // value directly.
4377 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); 4404 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
4378 O* value = I::ReadField<O*>(obj, offset); 4405 O* value = I::ReadField<O*>(obj, offset);
4379 O** result = HandleScope::CreateHandle(value); 4406 O** result = HandleScope::CreateHandle(value);
4380 return Local<Value>(reinterpret_cast<Value*>(result)); 4407 return Local<Value>(reinterpret_cast<Value*>(result));
4381 } else {
4382 return Local<Value>();
4383 } 4408 }
4409 #endif
4410 return SlowGetInternalField(index);
4384 } 4411 }
4385 4412
4386 4413
4387 void* External::Unwrap(Handle<v8::Value> obj) { 4414 void Object::SetPointerInInternalField(int index, void* value) {
4388 #ifdef V8_ENABLE_CHECKS 4415 SetInternalField(index, External::New(value));
4389 return FullUnwrap(obj);
4390 #else
4391 return QuickUnwrap(obj);
4392 #endif
4393 } 4416 }
4394 4417
4395 4418
4396 void* External::QuickUnwrap(Handle<v8::Value> wrapper) { 4419 void* Object::GetAlignedPointerFromInternalField(int index) {
4420 #ifndef V8_ENABLE_CHECKS
4397 typedef internal::Object O; 4421 typedef internal::Object O;
4398 O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); 4422 typedef internal::Internals I;
4399 return internal::Internals::GetExternalPointer(obj); 4423 O* obj = *reinterpret_cast<O**>(this);
4424 // Fast path: If the object is a plain JSObject, which is the common case, we
4425 // know where to find the internal fields and can return the value directly.
4426 if (I::GetInstanceType(obj) == I::kJSObjectType) {
4427 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
4428 return I::ReadField<void*>(obj, offset);
4429 }
4430 #endif
4431 return SlowGetAlignedPointerFromInternalField(index);
4400 } 4432 }
4401 4433
4402 4434
4403 void* Object::GetPointerFromInternalField(int index) {
4404 typedef internal::Object O;
4405 typedef internal::Internals I;
4406
4407 O* obj = *reinterpret_cast<O**>(this);
4408
4409 if (I::GetInstanceType(obj) == I::kJSObjectType) {
4410 // If the object is a plain JSObject, which is the common case,
4411 // we know where to find the internal fields and can return the
4412 // value directly.
4413 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index);
4414 O* value = I::ReadField<O*>(obj, offset);
4415 return I::GetExternalPointer(value);
4416 }
4417
4418 return SlowGetPointerFromInternalField(index);
4419 }
4420
4421
4422 String* String::Cast(v8::Value* value) { 4435 String* String::Cast(v8::Value* value) {
4423 #ifdef V8_ENABLE_CHECKS 4436 #ifdef V8_ENABLE_CHECKS
4424 CheckCast(value); 4437 CheckCast(value);
4425 #endif 4438 #endif
4426 return static_cast<String*>(value); 4439 return static_cast<String*>(value);
4427 } 4440 }
4428 4441
4429 4442
4430 Local<String> String::Empty(Isolate* isolate) { 4443 Local<String> String::Empty(Isolate* isolate) {
4431 typedef internal::Object* S; 4444 typedef internal::Object* S;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
4600 4613
4601 4614
4602 Function* Function::Cast(v8::Value* value) { 4615 Function* Function::Cast(v8::Value* value) {
4603 #ifdef V8_ENABLE_CHECKS 4616 #ifdef V8_ENABLE_CHECKS
4604 CheckCast(value); 4617 CheckCast(value);
4605 #endif 4618 #endif
4606 return static_cast<Function*>(value); 4619 return static_cast<Function*>(value);
4607 } 4620 }
4608 4621
4609 4622
4623 Local<Value> External::Wrap(void* value) {
4624 return External::New(value);
4625 }
4626
4627
4628 void* External::Unwrap(Handle<v8::Value> obj) {
4629 return External::Cast(*obj)->Value();
4630 }
4631
4632
4610 External* External::Cast(v8::Value* value) { 4633 External* External::Cast(v8::Value* value) {
4611 #ifdef V8_ENABLE_CHECKS 4634 #ifdef V8_ENABLE_CHECKS
4612 CheckCast(value); 4635 CheckCast(value);
4613 #endif 4636 #endif
4614 return static_cast<External*>(value); 4637 return static_cast<External*>(value);
4615 } 4638 }
4616 4639
4617 4640
4618 Isolate* AccessorInfo::GetIsolate() const { 4641 Isolate* AccessorInfo::GetIsolate() const {
4619 return *reinterpret_cast<Isolate**>(&args_[-3]); 4642 return *reinterpret_cast<Isolate**>(&args_[-3]);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4676 I::SetEmbedderData(this, data); 4699 I::SetEmbedderData(this, data);
4677 } 4700 }
4678 4701
4679 4702
4680 void* Isolate::GetData() { 4703 void* Isolate::GetData() {
4681 typedef internal::Internals I; 4704 typedef internal::Internals I;
4682 return I::GetEmbedderData(this); 4705 return I::GetEmbedderData(this);
4683 } 4706 }
4684 4707
4685 4708
4709 Local<Value> Context::GetData() {
4710 return GetEmbedderData(0);
4711 }
4712
4713 void Context::SetData(Handle<Value> data) {
4714 SetEmbedderData(0, data);
4715 }
4716
4717
4718 Local<Value> Context::GetEmbedderData(int index) {
4719 #ifndef V8_ENABLE_CHECKS
4720 typedef internal::Object O;
4721 typedef internal::Internals I;
4722 O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index));
4723 return Local<Value>(reinterpret_cast<Value*>(result));
4724 #else
4725 return SlowGetEmbedderData(index);
4726 #endif
4727 }
4728
4729
4730 void* Context::GetAlignedPointerFromEmbedderData(int index) {
4731 #ifndef V8_ENABLE_CHECKS
4732 typedef internal::Internals I;
4733 return I::ReadEmbedderData<void*>(this, index);
4734 #else
4735 return SlowGetAlignedPointerFromEmbedderData(index);
4736 #endif
4737 }
4738
4739
4686 /** 4740 /**
4687 * \example shell.cc 4741 * \example shell.cc
4688 * A simple shell that takes a list of expressions on the 4742 * A simple shell that takes a list of expressions on the
4689 * command-line and executes them. 4743 * command-line and executes them.
4690 */ 4744 */
4691 4745
4692 4746
4693 /** 4747 /**
4694 * \example process.cc 4748 * \example process.cc
4695 */ 4749 */
4696 4750
4697 4751
4698 } // namespace v8 4752 } // namespace v8
4699 4753
4700 4754
4701 #undef V8EXPORT 4755 #undef V8EXPORT
4702 #undef TYPE_CHECK 4756 #undef TYPE_CHECK
4703 4757
4704 4758
4705 #endif // V8_H_ 4759 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/api.cc » ('J')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1280:2d3e6564b7b6