OLD | NEW |
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 Loading... |
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 | |
90 /** | 79 /** |
91 * The v8 JavaScript engine. | 80 * The v8 JavaScript engine. |
92 */ | 81 */ |
93 namespace v8 { | 82 namespace v8 { |
94 | 83 |
95 class Context; | 84 class Context; |
96 class String; | 85 class String; |
97 class StringObject; | 86 class StringObject; |
98 class Value; | 87 class Value; |
99 class Utils; | 88 class Utils; |
(...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 */ | 1594 */ |
1606 V8EXPORT Local<Value> GetConstructor(); | 1595 V8EXPORT Local<Value> GetConstructor(); |
1607 | 1596 |
1608 /** | 1597 /** |
1609 * Returns the name of the function invoked as a constructor for this object. | 1598 * Returns the name of the function invoked as a constructor for this object. |
1610 */ | 1599 */ |
1611 V8EXPORT Local<String> GetConstructorName(); | 1600 V8EXPORT Local<String> GetConstructorName(); |
1612 | 1601 |
1613 /** Gets the number of internal fields for this Object. */ | 1602 /** Gets the number of internal fields for this Object. */ |
1614 V8EXPORT int InternalFieldCount(); | 1603 V8EXPORT int InternalFieldCount(); |
1615 | 1604 /** Gets the value in an internal field. */ |
1616 /** Gets the value from an internal field. */ | |
1617 inline Local<Value> GetInternalField(int index); | 1605 inline Local<Value> GetInternalField(int index); |
1618 | |
1619 /** Sets the value in an internal field. */ | 1606 /** Sets the value in an internal field. */ |
1620 V8EXPORT void SetInternalField(int index, Handle<Value> value); | 1607 V8EXPORT void SetInternalField(int index, Handle<Value> value); |
1621 | 1608 |
1622 /** | 1609 /** Gets a native pointer from an internal field. */ |
1623 * Gets a native pointer from an internal field. Deprecated. If the pointer is | 1610 inline void* GetPointerFromInternalField(int index); |
1624 * always 2-byte-aligned, use GetAlignedPointerFromInternalField instead, | |
1625 * otherwise use a combination of GetInternalField, External::Cast and | |
1626 * External::Value. | |
1627 */ | |
1628 V8EXPORT V8_DEPRECATED(void* GetPointerFromInternalField(int index)); | |
1629 | 1611 |
1630 /** | 1612 /** Sets a native pointer in an internal field. */ |
1631 * Sets a native pointer in an internal field. Deprecated. If the pointer is | 1613 V8EXPORT void SetPointerInInternalField(int index, void* value); |
1632 * always 2-byte aligned, use SetAlignedPointerInInternalField instead, | |
1633 * otherwise use a combination of External::New and SetInternalField. | |
1634 */ | |
1635 inline V8_DEPRECATED(void SetPointerInInternalField(int index, void* value)); | |
1636 | |
1637 /** | |
1638 * Gets a 2-byte-aligned native pointer from an internal field. This field | |
1639 * must have been set by SetAlignedPointerInInternalField, everything else | |
1640 * leads to undefined behavior. | |
1641 */ | |
1642 inline void* GetAlignedPointerFromInternalField(int index); | |
1643 | |
1644 /** | |
1645 * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such | |
1646 * a field, GetAlignedPointerFromInternalField must be used, everything else | |
1647 * leads to undefined behavior. | |
1648 */ | |
1649 V8EXPORT void SetAlignedPointerInInternalField(int index, void* value); | |
1650 | 1614 |
1651 // Testers for local properties. | 1615 // Testers for local properties. |
1652 V8EXPORT bool HasOwnProperty(Handle<String> key); | 1616 V8EXPORT bool HasOwnProperty(Handle<String> key); |
1653 V8EXPORT bool HasRealNamedProperty(Handle<String> key); | 1617 V8EXPORT bool HasRealNamedProperty(Handle<String> key); |
1654 V8EXPORT bool HasRealIndexedProperty(uint32_t index); | 1618 V8EXPORT bool HasRealIndexedProperty(uint32_t index); |
1655 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); | 1619 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); |
1656 | 1620 |
1657 /** | 1621 /** |
1658 * If result.IsEmpty() no real property was located in the prototype chain. | 1622 * If result.IsEmpty() no real property was located in the prototype chain. |
1659 * This means interceptors in the prototype chain are not called. | 1623 * This means interceptors in the prototype chain are not called. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1770 */ | 1734 */ |
1771 V8EXPORT Local<Value> CallAsConstructor(int argc, | 1735 V8EXPORT Local<Value> CallAsConstructor(int argc, |
1772 Handle<Value> argv[]); | 1736 Handle<Value> argv[]); |
1773 | 1737 |
1774 V8EXPORT static Local<Object> New(); | 1738 V8EXPORT static Local<Object> New(); |
1775 static inline Object* Cast(Value* obj); | 1739 static inline Object* Cast(Value* obj); |
1776 | 1740 |
1777 private: | 1741 private: |
1778 V8EXPORT Object(); | 1742 V8EXPORT Object(); |
1779 V8EXPORT static void CheckCast(Value* obj); | 1743 V8EXPORT static void CheckCast(Value* obj); |
1780 V8EXPORT Local<Value> SlowGetInternalField(int index); | 1744 V8EXPORT Local<Value> CheckedGetInternalField(int index); |
1781 V8EXPORT void* SlowGetAlignedPointerFromInternalField(int index); | 1745 V8EXPORT void* SlowGetPointerFromInternalField(int index); |
| 1746 |
| 1747 /** |
| 1748 * If quick access to the internal field is possible this method |
| 1749 * returns the value. Otherwise an empty handle is returned. |
| 1750 */ |
| 1751 inline Local<Value> UncheckedGetInternalField(int index); |
1782 }; | 1752 }; |
1783 | 1753 |
1784 | 1754 |
1785 /** | 1755 /** |
1786 * An instance of the built-in array constructor (ECMA-262, 15.4.2). | 1756 * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
1787 */ | 1757 */ |
1788 class Array : public Object { | 1758 class Array : public Object { |
1789 public: | 1759 public: |
1790 V8EXPORT uint32_t Length() const; | 1760 V8EXPORT uint32_t Length() const; |
1791 | 1761 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1982 V8EXPORT Flags GetFlags() const; | 1952 V8EXPORT Flags GetFlags() const; |
1983 | 1953 |
1984 static inline RegExp* Cast(v8::Value* obj); | 1954 static inline RegExp* Cast(v8::Value* obj); |
1985 | 1955 |
1986 private: | 1956 private: |
1987 V8EXPORT static void CheckCast(v8::Value* obj); | 1957 V8EXPORT static void CheckCast(v8::Value* obj); |
1988 }; | 1958 }; |
1989 | 1959 |
1990 | 1960 |
1991 /** | 1961 /** |
1992 * A JavaScript value that wraps a C++ void*. This type of value is mainly used | 1962 * A JavaScript value that wraps a C++ void*. This type of value is |
1993 * to associate C++ data structures with JavaScript objects. | 1963 * mainly used to associate C++ data structures with JavaScript |
| 1964 * objects. |
| 1965 * |
| 1966 * The Wrap function V8 will return the most optimal Value object wrapping the |
| 1967 * C++ void*. The type of the value is not guaranteed to be an External object |
| 1968 * and no assumptions about its type should be made. To access the wrapped |
| 1969 * value Unwrap should be used, all other operations on that object will lead |
| 1970 * to unpredictable results. |
1994 */ | 1971 */ |
1995 class External : public Value { | 1972 class External : public Value { |
1996 public: | 1973 public: |
1997 /** Deprecated, use New instead. */ | 1974 V8EXPORT static Local<Value> Wrap(void* data); |
1998 V8_DEPRECATED(static inline Local<Value> Wrap(void* value)); | 1975 static inline void* Unwrap(Handle<Value> obj); |
1999 | |
2000 /** Deprecated, use a combination of Cast and Value instead. */ | |
2001 V8_DEPRECATED(static inline void* Unwrap(Handle<Value> obj)); | |
2002 | 1976 |
2003 V8EXPORT static Local<External> New(void* value); | 1977 V8EXPORT static Local<External> New(void* value); |
2004 static inline External* Cast(Value* obj); | 1978 static inline External* Cast(Value* obj); |
2005 V8EXPORT void* Value() const; | 1979 V8EXPORT void* Value() const; |
2006 private: | 1980 private: |
| 1981 V8EXPORT External(); |
2007 V8EXPORT static void CheckCast(v8::Value* obj); | 1982 V8EXPORT static void CheckCast(v8::Value* obj); |
| 1983 static inline void* QuickUnwrap(Handle<v8::Value> obj); |
| 1984 V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj); |
2008 }; | 1985 }; |
2009 | 1986 |
2010 | 1987 |
2011 // --- Templates --- | 1988 // --- Templates --- |
2012 | 1989 |
2013 | 1990 |
2014 /** | 1991 /** |
2015 * The superclass of object and function templates. | 1992 * The superclass of object and function templates. |
2016 */ | 1993 */ |
2017 class V8EXPORT Template : public Data { | 1994 class V8EXPORT Template : public Data { |
(...skipping 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3786 */ | 3763 */ |
3787 void Exit(); | 3764 void Exit(); |
3788 | 3765 |
3789 /** Returns true if the context has experienced an out of memory situation. */ | 3766 /** Returns true if the context has experienced an out of memory situation. */ |
3790 bool HasOutOfMemoryException(); | 3767 bool HasOutOfMemoryException(); |
3791 | 3768 |
3792 /** Returns true if V8 has a current context. */ | 3769 /** Returns true if V8 has a current context. */ |
3793 static bool InContext(); | 3770 static bool InContext(); |
3794 | 3771 |
3795 /** | 3772 /** |
3796 * Gets embedder data with index 0. Deprecated, use GetEmbedderData with index | 3773 * Associate an additional data object with the context. This is mainly used |
3797 * 0 instead. | 3774 * with the debugger to provide additional information on the context through |
| 3775 * the debugger API. |
3798 */ | 3776 */ |
3799 V8_DEPRECATED(inline Local<Value> GetData()); | 3777 void SetData(Handle<Value> data); |
3800 | 3778 Local<Value> GetData(); |
3801 /** | |
3802 * Sets embedder data with index 0. Deprecated, use SetEmbedderData with index | |
3803 * 0 instead. | |
3804 */ | |
3805 V8_DEPRECATED(inline void SetData(Handle<Value> value)); | |
3806 | |
3807 /** | |
3808 * Gets the embedder data with the given index, which must have been set by a | |
3809 * previous call to SetEmbedderData with the same index. Note that index 0 | |
3810 * currently has a special meaning for Chrome's debugger. | |
3811 */ | |
3812 inline Local<Value> GetEmbedderData(int index); | |
3813 | |
3814 /** | |
3815 * Sets the embedder data with the given index, growing the data as | |
3816 * needed. Note that index 0 currently has a special meaning for Chrome's | |
3817 * debugger. | |
3818 */ | |
3819 void SetEmbedderData(int index, Handle<Value> value); | |
3820 | |
3821 /** | |
3822 * Gets a 2-byte-aligned native pointer from the embedder data with the given | |
3823 * index, which must have bees set by a previous call to | |
3824 * SetAlignedPointerInEmbedderData with the same index. Note that index 0 | |
3825 * currently has a special meaning for Chrome's debugger. | |
3826 */ | |
3827 inline void* GetAlignedPointerFromEmbedderData(int index); | |
3828 | |
3829 /** | |
3830 * Sets a 2-byte-aligned native pointer in the embedder data with the given | |
3831 * index, growing the data as needed. Note that index 0 currently has a | |
3832 * special meaning for Chrome's debugger. | |
3833 */ | |
3834 void SetAlignedPointerInEmbedderData(int index, void* value); | |
3835 | 3779 |
3836 /** | 3780 /** |
3837 * Control whether code generation from strings is allowed. Calling | 3781 * Control whether code generation from strings is allowed. Calling |
3838 * this method with false will disable 'eval' and the 'Function' | 3782 * this method with false will disable 'eval' and the 'Function' |
3839 * constructor for code running in this context. If 'eval' or the | 3783 * constructor for code running in this context. If 'eval' or the |
3840 * 'Function' constructor are used an exception will be thrown. | 3784 * 'Function' constructor are used an exception will be thrown. |
3841 * | 3785 * |
3842 * If code generation from strings is not allowed the | 3786 * If code generation from strings is not allowed the |
3843 * V8::AllowCodeGenerationFromStrings callback will be invoked if | 3787 * V8::AllowCodeGenerationFromStrings callback will be invoked if |
3844 * set before blocking the call to 'eval' or the 'Function' | 3788 * set before blocking the call to 'eval' or the 'Function' |
(...skipping 28 matching lines...) Expand all Loading... |
3873 inline ~Scope() { context_->Exit(); } | 3817 inline ~Scope() { context_->Exit(); } |
3874 private: | 3818 private: |
3875 Handle<Context> context_; | 3819 Handle<Context> context_; |
3876 }; | 3820 }; |
3877 | 3821 |
3878 private: | 3822 private: |
3879 friend class Value; | 3823 friend class Value; |
3880 friend class Script; | 3824 friend class Script; |
3881 friend class Object; | 3825 friend class Object; |
3882 friend class Function; | 3826 friend class Function; |
3883 | |
3884 Local<Value> SlowGetEmbedderData(int index); | |
3885 void* SlowGetAlignedPointerFromEmbedderData(int index); | |
3886 }; | 3827 }; |
3887 | 3828 |
3888 | 3829 |
3889 /** | 3830 /** |
3890 * Multiple threads in V8 are allowed, but only one thread at a time | 3831 * Multiple threads in V8 are allowed, but only one thread at a time |
3891 * is allowed to use any given V8 isolate. See Isolate class | 3832 * is allowed to use any given V8 isolate. See Isolate class |
3892 * comments. The definition of 'using V8 isolate' includes | 3833 * comments. The definition of 'using V8 isolate' includes |
3893 * accessing handles or holding onto object pointers obtained | 3834 * accessing handles or holding onto object pointers obtained |
3894 * from V8 handles while in the particular V8 isolate. It is up | 3835 * from V8 handles while in the particular V8 isolate. It is up |
3895 * to the user of V8 to ensure (perhaps with locking) that this | 3836 * to the user of V8 to ensure (perhaps with locking) that this |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4109 | 4050 |
4110 // Smi constants for 32-bit systems. | 4051 // Smi constants for 32-bit systems. |
4111 template <> struct SmiTagging<4> { | 4052 template <> struct SmiTagging<4> { |
4112 static const int kSmiShiftSize = 0; | 4053 static const int kSmiShiftSize = 0; |
4113 static const int kSmiValueSize = 31; | 4054 static const int kSmiValueSize = 31; |
4114 static inline int SmiToInt(internal::Object* value) { | 4055 static inline int SmiToInt(internal::Object* value) { |
4115 int shift_bits = kSmiTagSize + kSmiShiftSize; | 4056 int shift_bits = kSmiTagSize + kSmiShiftSize; |
4116 // Throw away top 32 bits and shift down (requires >> to be sign extending). | 4057 // Throw away top 32 bits and shift down (requires >> to be sign extending). |
4117 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; | 4058 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
4118 } | 4059 } |
| 4060 |
| 4061 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi |
| 4062 // with a plain reinterpret_cast. |
| 4063 static const uintptr_t kEncodablePointerMask = 0x1; |
| 4064 static const int kPointerToSmiShift = 0; |
4119 }; | 4065 }; |
4120 | 4066 |
4121 // Smi constants for 64-bit systems. | 4067 // Smi constants for 64-bit systems. |
4122 template <> struct SmiTagging<8> { | 4068 template <> struct SmiTagging<8> { |
4123 static const int kSmiShiftSize = 31; | 4069 static const int kSmiShiftSize = 31; |
4124 static const int kSmiValueSize = 32; | 4070 static const int kSmiValueSize = 32; |
4125 static inline int SmiToInt(internal::Object* value) { | 4071 static inline int SmiToInt(internal::Object* value) { |
4126 int shift_bits = kSmiTagSize + kSmiShiftSize; | 4072 int shift_bits = kSmiTagSize + kSmiShiftSize; |
4127 // Shift down and throw away top 32 bits. | 4073 // Shift down and throw away top 32 bits. |
4128 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 4074 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
4129 } | 4075 } |
| 4076 |
| 4077 // To maximize the range of pointers that can be encoded |
| 4078 // in the available 32 bits, we require them to be 8 bytes aligned. |
| 4079 // This gives 2 ^ (32 + 3) = 32G address space covered. |
| 4080 // It might be not enough to cover stack allocated objects on some platforms. |
| 4081 static const int kPointerAlignment = 3; |
| 4082 |
| 4083 static const uintptr_t kEncodablePointerMask = |
| 4084 ~(uintptr_t(0xffffffff) << kPointerAlignment); |
| 4085 |
| 4086 static const int kPointerToSmiShift = |
| 4087 kSmiTagSize + kSmiShiftSize - kPointerAlignment; |
4130 }; | 4088 }; |
4131 | 4089 |
4132 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; | 4090 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
4133 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; | 4091 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
4134 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; | 4092 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
| 4093 const uintptr_t kEncodablePointerMask = |
| 4094 PlatformSmiTagging::kEncodablePointerMask; |
| 4095 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; |
4135 | 4096 |
4136 /** | 4097 /** |
4137 * This class exports constants and functionality from within v8 that | 4098 * This class exports constants and functionality from within v8 that |
4138 * is necessary to implement inline functions in the v8 api. Don't | 4099 * is necessary to implement inline functions in the v8 api. Don't |
4139 * depend on functions and constants defined here. | 4100 * depend on functions and constants defined here. |
4140 */ | 4101 */ |
4141 class Internals { | 4102 class Internals { |
4142 public: | 4103 public: |
4143 // These values match non-compiler-dependent values defined within | 4104 // These values match non-compiler-dependent values defined within |
4144 // the implementation of v8. | 4105 // the implementation of v8. |
4145 static const int kHeapObjectMapOffset = 0; | 4106 static const int kHeapObjectMapOffset = 0; |
4146 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; | 4107 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
4147 static const int kStringResourceOffset = 3 * kApiPointerSize; | 4108 static const int kStringResourceOffset = 3 * kApiPointerSize; |
4148 | 4109 |
4149 static const int kOddballKindOffset = 3 * kApiPointerSize; | 4110 static const int kOddballKindOffset = 3 * kApiPointerSize; |
4150 static const int kForeignAddressOffset = kApiPointerSize; | 4111 static const int kForeignAddressOffset = kApiPointerSize; |
4151 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 4112 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
4152 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; | |
4153 static const int kContextHeaderSize = 2 * kApiPointerSize; | |
4154 static const int kContextEmbedderDataIndex = 54; | |
4155 static const int kFullStringRepresentationMask = 0x07; | 4113 static const int kFullStringRepresentationMask = 0x07; |
4156 static const int kStringEncodingMask = 0x4; | 4114 static const int kStringEncodingMask = 0x4; |
4157 static const int kExternalTwoByteRepresentationTag = 0x02; | 4115 static const int kExternalTwoByteRepresentationTag = 0x02; |
4158 static const int kExternalAsciiRepresentationTag = 0x06; | 4116 static const int kExternalAsciiRepresentationTag = 0x06; |
4159 | 4117 |
4160 static const int kIsolateStateOffset = 0; | 4118 static const int kIsolateStateOffset = 0; |
4161 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | 4119 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
4162 static const int kIsolateRootsOffset = 3 * kApiPointerSize; | 4120 static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
4163 static const int kUndefinedValueRootIndex = 5; | 4121 static const int kUndefinedValueRootIndex = 5; |
4164 static const int kNullValueRootIndex = 7; | 4122 static const int kNullValueRootIndex = 7; |
4165 static const int kTrueValueRootIndex = 8; | 4123 static const int kTrueValueRootIndex = 8; |
4166 static const int kFalseValueRootIndex = 9; | 4124 static const int kFalseValueRootIndex = 9; |
4167 static const int kEmptySymbolRootIndex = 119; | 4125 static const int kEmptySymbolRootIndex = 118; |
4168 | 4126 |
4169 static const int kJSObjectType = 0xaa; | 4127 static const int kJSObjectType = 0xaa; |
4170 static const int kFirstNonstringType = 0x80; | 4128 static const int kFirstNonstringType = 0x80; |
4171 static const int kOddballType = 0x82; | 4129 static const int kOddballType = 0x82; |
4172 static const int kForeignType = 0x85; | 4130 static const int kForeignType = 0x85; |
4173 | 4131 |
4174 static const int kUndefinedOddballKind = 5; | 4132 static const int kUndefinedOddballKind = 5; |
4175 static const int kNullOddballKind = 3; | 4133 static const int kNullOddballKind = 3; |
4176 | 4134 |
4177 static inline bool HasHeapObjectTag(internal::Object* value) { | 4135 static inline bool HasHeapObjectTag(internal::Object* value) { |
4178 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 4136 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
4179 kHeapObjectTag); | 4137 kHeapObjectTag); |
4180 } | 4138 } |
4181 | 4139 |
| 4140 static inline bool HasSmiTag(internal::Object* value) { |
| 4141 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
| 4142 } |
| 4143 |
4182 static inline int SmiValue(internal::Object* value) { | 4144 static inline int SmiValue(internal::Object* value) { |
4183 return PlatformSmiTagging::SmiToInt(value); | 4145 return PlatformSmiTagging::SmiToInt(value); |
4184 } | 4146 } |
4185 | 4147 |
4186 static inline int GetInstanceType(internal::Object* obj) { | 4148 static inline int GetInstanceType(internal::Object* obj) { |
4187 typedef internal::Object O; | 4149 typedef internal::Object O; |
4188 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 4150 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
4189 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 4151 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
4190 } | 4152 } |
4191 | 4153 |
4192 static inline int GetOddballKind(internal::Object* obj) { | 4154 static inline int GetOddballKind(internal::Object* obj) { |
4193 typedef internal::Object O; | 4155 typedef internal::Object O; |
4194 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); | 4156 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
4195 } | 4157 } |
4196 | 4158 |
| 4159 static inline void* GetExternalPointerFromSmi(internal::Object* value) { |
| 4160 const uintptr_t address = reinterpret_cast<uintptr_t>(value); |
| 4161 return reinterpret_cast<void*>(address >> kPointerToSmiShift); |
| 4162 } |
| 4163 |
| 4164 static inline void* GetExternalPointer(internal::Object* obj) { |
| 4165 if (HasSmiTag(obj)) { |
| 4166 return GetExternalPointerFromSmi(obj); |
| 4167 } else if (GetInstanceType(obj) == kForeignType) { |
| 4168 return ReadField<void*>(obj, kForeignAddressOffset); |
| 4169 } else { |
| 4170 return NULL; |
| 4171 } |
| 4172 } |
| 4173 |
4197 static inline bool IsExternalTwoByteString(int instance_type) { | 4174 static inline bool IsExternalTwoByteString(int instance_type) { |
4198 int representation = (instance_type & kFullStringRepresentationMask); | 4175 int representation = (instance_type & kFullStringRepresentationMask); |
4199 return representation == kExternalTwoByteRepresentationTag; | 4176 return representation == kExternalTwoByteRepresentationTag; |
4200 } | 4177 } |
4201 | 4178 |
4202 static inline bool IsInitialized(v8::Isolate* isolate) { | 4179 static inline bool IsInitialized(v8::Isolate* isolate) { |
4203 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; | 4180 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
4204 return *reinterpret_cast<int*>(addr) == 1; | 4181 return *reinterpret_cast<int*>(addr) == 1; |
4205 } | 4182 } |
4206 | 4183 |
(...skipping 13 matching lines...) Expand all Loading... |
4220 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; | 4197 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
4221 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); | 4198 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
4222 } | 4199 } |
4223 | 4200 |
4224 template <typename T> | 4201 template <typename T> |
4225 static inline T ReadField(Object* ptr, int offset) { | 4202 static inline T ReadField(Object* ptr, int offset) { |
4226 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; | 4203 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
4227 return *reinterpret_cast<T*>(addr); | 4204 return *reinterpret_cast<T*>(addr); |
4228 } | 4205 } |
4229 | 4206 |
4230 template <typename T> | |
4231 static inline T ReadEmbedderData(Context* context, int index) { | |
4232 typedef internal::Object O; | |
4233 typedef internal::Internals I; | |
4234 O* ctx = *reinterpret_cast<O**>(context); | |
4235 int embedder_data_offset = I::kContextHeaderSize + | |
4236 (internal::kApiPointerSize * I::kContextEmbedderDataIndex); | |
4237 O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); | |
4238 int value_offset = | |
4239 I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); | |
4240 return I::ReadField<T>(embedder_data, value_offset); | |
4241 } | |
4242 | |
4243 static inline bool CanCastToHeapObject(void* o) { return false; } | 4207 static inline bool CanCastToHeapObject(void* o) { return false; } |
4244 static inline bool CanCastToHeapObject(Context* o) { return true; } | 4208 static inline bool CanCastToHeapObject(Context* o) { return true; } |
4245 static inline bool CanCastToHeapObject(String* o) { return true; } | 4209 static inline bool CanCastToHeapObject(String* o) { return true; } |
4246 static inline bool CanCastToHeapObject(Object* o) { return true; } | 4210 static inline bool CanCastToHeapObject(Object* o) { return true; } |
4247 static inline bool CanCastToHeapObject(Message* o) { return true; } | 4211 static inline bool CanCastToHeapObject(Message* o) { return true; } |
4248 static inline bool CanCastToHeapObject(StackTrace* o) { return true; } | 4212 static inline bool CanCastToHeapObject(StackTrace* o) { return true; } |
4249 static inline bool CanCastToHeapObject(StackFrame* o) { return true; } | 4213 static inline bool CanCastToHeapObject(StackFrame* o) { return true; } |
4250 }; | 4214 }; |
4251 | 4215 |
4252 } // namespace internal | 4216 } // namespace internal |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4447 } | 4411 } |
4448 | 4412 |
4449 | 4413 |
4450 void Template::Set(const char* name, v8::Handle<Data> value) { | 4414 void Template::Set(const char* name, v8::Handle<Data> value) { |
4451 Set(v8::String::New(name), value); | 4415 Set(v8::String::New(name), value); |
4452 } | 4416 } |
4453 | 4417 |
4454 | 4418 |
4455 Local<Value> Object::GetInternalField(int index) { | 4419 Local<Value> Object::GetInternalField(int index) { |
4456 #ifndef V8_ENABLE_CHECKS | 4420 #ifndef V8_ENABLE_CHECKS |
| 4421 Local<Value> quick_result = UncheckedGetInternalField(index); |
| 4422 if (!quick_result.IsEmpty()) return quick_result; |
| 4423 #endif |
| 4424 return CheckedGetInternalField(index); |
| 4425 } |
| 4426 |
| 4427 |
| 4428 Local<Value> Object::UncheckedGetInternalField(int index) { |
4457 typedef internal::Object O; | 4429 typedef internal::Object O; |
4458 typedef internal::Internals I; | 4430 typedef internal::Internals I; |
4459 O* obj = *reinterpret_cast<O**>(this); | 4431 O* obj = *reinterpret_cast<O**>(this); |
4460 // Fast path: If the object is a plain JSObject, which is the common case, we | |
4461 // know where to find the internal fields and can return the value directly. | |
4462 if (I::GetInstanceType(obj) == I::kJSObjectType) { | 4432 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
| 4433 // If the object is a plain JSObject, which is the common case, |
| 4434 // we know where to find the internal fields and can return the |
| 4435 // value directly. |
4463 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); | 4436 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
4464 O* value = I::ReadField<O*>(obj, offset); | 4437 O* value = I::ReadField<O*>(obj, offset); |
4465 O** result = HandleScope::CreateHandle(value); | 4438 O** result = HandleScope::CreateHandle(value); |
4466 return Local<Value>(reinterpret_cast<Value*>(result)); | 4439 return Local<Value>(reinterpret_cast<Value*>(result)); |
| 4440 } else { |
| 4441 return Local<Value>(); |
4467 } | 4442 } |
4468 #endif | |
4469 return SlowGetInternalField(index); | |
4470 } | 4443 } |
4471 | 4444 |
4472 | 4445 |
4473 void Object::SetPointerInInternalField(int index, void* value) { | 4446 void* External::Unwrap(Handle<v8::Value> obj) { |
4474 SetInternalField(index, External::New(value)); | 4447 #ifdef V8_ENABLE_CHECKS |
| 4448 return FullUnwrap(obj); |
| 4449 #else |
| 4450 return QuickUnwrap(obj); |
| 4451 #endif |
4475 } | 4452 } |
4476 | 4453 |
4477 | 4454 |
4478 void* Object::GetAlignedPointerFromInternalField(int index) { | 4455 void* External::QuickUnwrap(Handle<v8::Value> wrapper) { |
4479 #ifndef V8_ENABLE_CHECKS | |
4480 typedef internal::Object O; | 4456 typedef internal::Object O; |
4481 typedef internal::Internals I; | 4457 O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); |
4482 O* obj = *reinterpret_cast<O**>(this); | 4458 return internal::Internals::GetExternalPointer(obj); |
4483 // Fast path: If the object is a plain JSObject, which is the common case, we | |
4484 // know where to find the internal fields and can return the value directly. | |
4485 if (I::GetInstanceType(obj) == I::kJSObjectType) { | |
4486 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); | |
4487 return I::ReadField<void*>(obj, offset); | |
4488 } | |
4489 #endif | |
4490 return SlowGetAlignedPointerFromInternalField(index); | |
4491 } | 4459 } |
4492 | 4460 |
4493 | 4461 |
| 4462 void* Object::GetPointerFromInternalField(int index) { |
| 4463 typedef internal::Object O; |
| 4464 typedef internal::Internals I; |
| 4465 |
| 4466 O* obj = *reinterpret_cast<O**>(this); |
| 4467 |
| 4468 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
| 4469 // If the object is a plain JSObject, which is the common case, |
| 4470 // we know where to find the internal fields and can return the |
| 4471 // value directly. |
| 4472 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
| 4473 O* value = I::ReadField<O*>(obj, offset); |
| 4474 return I::GetExternalPointer(value); |
| 4475 } |
| 4476 |
| 4477 return SlowGetPointerFromInternalField(index); |
| 4478 } |
| 4479 |
| 4480 |
4494 String* String::Cast(v8::Value* value) { | 4481 String* String::Cast(v8::Value* value) { |
4495 #ifdef V8_ENABLE_CHECKS | 4482 #ifdef V8_ENABLE_CHECKS |
4496 CheckCast(value); | 4483 CheckCast(value); |
4497 #endif | 4484 #endif |
4498 return static_cast<String*>(value); | 4485 return static_cast<String*>(value); |
4499 } | 4486 } |
4500 | 4487 |
4501 | 4488 |
4502 Local<String> String::Empty(Isolate* isolate) { | 4489 Local<String> String::Empty(Isolate* isolate) { |
4503 typedef internal::Object* S; | 4490 typedef internal::Object* S; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4672 | 4659 |
4673 | 4660 |
4674 Function* Function::Cast(v8::Value* value) { | 4661 Function* Function::Cast(v8::Value* value) { |
4675 #ifdef V8_ENABLE_CHECKS | 4662 #ifdef V8_ENABLE_CHECKS |
4676 CheckCast(value); | 4663 CheckCast(value); |
4677 #endif | 4664 #endif |
4678 return static_cast<Function*>(value); | 4665 return static_cast<Function*>(value); |
4679 } | 4666 } |
4680 | 4667 |
4681 | 4668 |
4682 Local<Value> External::Wrap(void* value) { | |
4683 return External::New(value); | |
4684 } | |
4685 | |
4686 | |
4687 void* External::Unwrap(Handle<v8::Value> obj) { | |
4688 return External::Cast(*obj)->Value(); | |
4689 } | |
4690 | |
4691 | |
4692 External* External::Cast(v8::Value* value) { | 4669 External* External::Cast(v8::Value* value) { |
4693 #ifdef V8_ENABLE_CHECKS | 4670 #ifdef V8_ENABLE_CHECKS |
4694 CheckCast(value); | 4671 CheckCast(value); |
4695 #endif | 4672 #endif |
4696 return static_cast<External*>(value); | 4673 return static_cast<External*>(value); |
4697 } | 4674 } |
4698 | 4675 |
4699 | 4676 |
4700 Isolate* AccessorInfo::GetIsolate() const { | 4677 Isolate* AccessorInfo::GetIsolate() const { |
4701 return *reinterpret_cast<Isolate**>(&args_[-3]); | 4678 return *reinterpret_cast<Isolate**>(&args_[-3]); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4758 I::SetEmbedderData(this, data); | 4735 I::SetEmbedderData(this, data); |
4759 } | 4736 } |
4760 | 4737 |
4761 | 4738 |
4762 void* Isolate::GetData() { | 4739 void* Isolate::GetData() { |
4763 typedef internal::Internals I; | 4740 typedef internal::Internals I; |
4764 return I::GetEmbedderData(this); | 4741 return I::GetEmbedderData(this); |
4765 } | 4742 } |
4766 | 4743 |
4767 | 4744 |
4768 Local<Value> Context::GetData() { | |
4769 return GetEmbedderData(0); | |
4770 } | |
4771 | |
4772 void Context::SetData(Handle<Value> data) { | |
4773 SetEmbedderData(0, data); | |
4774 } | |
4775 | |
4776 | |
4777 Local<Value> Context::GetEmbedderData(int index) { | |
4778 #ifndef V8_ENABLE_CHECKS | |
4779 typedef internal::Object O; | |
4780 typedef internal::Internals I; | |
4781 O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); | |
4782 return Local<Value>(reinterpret_cast<Value*>(result)); | |
4783 #else | |
4784 return SlowGetEmbedderData(index); | |
4785 #endif | |
4786 } | |
4787 | |
4788 | |
4789 void* Context::GetAlignedPointerFromEmbedderData(int index) { | |
4790 #ifndef V8_ENABLE_CHECKS | |
4791 typedef internal::Internals I; | |
4792 return I::ReadEmbedderData<void*>(this, index); | |
4793 #else | |
4794 return SlowGetAlignedPointerFromEmbedderData(index); | |
4795 #endif | |
4796 } | |
4797 | |
4798 | |
4799 /** | 4745 /** |
4800 * \example shell.cc | 4746 * \example shell.cc |
4801 * A simple shell that takes a list of expressions on the | 4747 * A simple shell that takes a list of expressions on the |
4802 * command-line and executes them. | 4748 * command-line and executes them. |
4803 */ | 4749 */ |
4804 | 4750 |
4805 | 4751 |
4806 /** | 4752 /** |
4807 * \example process.cc | 4753 * \example process.cc |
4808 */ | 4754 */ |
4809 | 4755 |
4810 | 4756 |
4811 } // namespace v8 | 4757 } // namespace v8 |
4812 | 4758 |
4813 | 4759 |
4814 #undef V8EXPORT | 4760 #undef V8EXPORT |
4815 #undef TYPE_CHECK | 4761 #undef TYPE_CHECK |
4816 | 4762 |
4817 | 4763 |
4818 #endif // V8_H_ | 4764 #endif // V8_H_ |
OLD | NEW |