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 |
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 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1594 */ | 1605 */ |
1595 V8EXPORT Local<Value> GetConstructor(); | 1606 V8EXPORT Local<Value> GetConstructor(); |
1596 | 1607 |
1597 /** | 1608 /** |
1598 * Returns the name of the function invoked as a constructor for this object. | 1609 * Returns the name of the function invoked as a constructor for this object. |
1599 */ | 1610 */ |
1600 V8EXPORT Local<String> GetConstructorName(); | 1611 V8EXPORT Local<String> GetConstructorName(); |
1601 | 1612 |
1602 /** Gets the number of internal fields for this Object. */ | 1613 /** Gets the number of internal fields for this Object. */ |
1603 V8EXPORT int InternalFieldCount(); | 1614 V8EXPORT int InternalFieldCount(); |
1604 /** Gets the value in an internal field. */ | 1615 |
| 1616 /** Gets the value from an internal field. */ |
1605 inline Local<Value> GetInternalField(int index); | 1617 inline Local<Value> GetInternalField(int index); |
| 1618 |
1606 /** Sets the value in an internal field. */ | 1619 /** Sets the value in an internal field. */ |
1607 V8EXPORT void SetInternalField(int index, Handle<Value> value); | 1620 V8EXPORT void SetInternalField(int index, Handle<Value> value); |
1608 | 1621 |
1609 /** Gets a native pointer from an internal field. */ | 1622 /** |
1610 inline void* GetPointerFromInternalField(int index); | 1623 * Gets a native pointer from an internal field. Deprecated. If the pointer is |
| 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)); |
1611 | 1629 |
1612 /** Sets a native pointer in an internal field. */ | 1630 /** |
1613 V8EXPORT void SetPointerInInternalField(int index, void* value); | 1631 * Sets a native pointer in an internal field. Deprecated. If the pointer is |
| 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); |
1614 | 1650 |
1615 // Testers for local properties. | 1651 // Testers for local properties. |
1616 V8EXPORT bool HasOwnProperty(Handle<String> key); | 1652 V8EXPORT bool HasOwnProperty(Handle<String> key); |
1617 V8EXPORT bool HasRealNamedProperty(Handle<String> key); | 1653 V8EXPORT bool HasRealNamedProperty(Handle<String> key); |
1618 V8EXPORT bool HasRealIndexedProperty(uint32_t index); | 1654 V8EXPORT bool HasRealIndexedProperty(uint32_t index); |
1619 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); | 1655 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); |
1620 | 1656 |
1621 /** | 1657 /** |
1622 * If result.IsEmpty() no real property was located in the prototype chain. | 1658 * If result.IsEmpty() no real property was located in the prototype chain. |
1623 * This means interceptors in the prototype chain are not called. | 1659 * This means interceptors in the prototype chain are not called. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1734 */ | 1770 */ |
1735 V8EXPORT Local<Value> CallAsConstructor(int argc, | 1771 V8EXPORT Local<Value> CallAsConstructor(int argc, |
1736 Handle<Value> argv[]); | 1772 Handle<Value> argv[]); |
1737 | 1773 |
1738 V8EXPORT static Local<Object> New(); | 1774 V8EXPORT static Local<Object> New(); |
1739 static inline Object* Cast(Value* obj); | 1775 static inline Object* Cast(Value* obj); |
1740 | 1776 |
1741 private: | 1777 private: |
1742 V8EXPORT Object(); | 1778 V8EXPORT Object(); |
1743 V8EXPORT static void CheckCast(Value* obj); | 1779 V8EXPORT static void CheckCast(Value* obj); |
1744 V8EXPORT Local<Value> CheckedGetInternalField(int index); | 1780 V8EXPORT Local<Value> SlowGetInternalField(int index); |
1745 V8EXPORT void* SlowGetPointerFromInternalField(int index); | 1781 V8EXPORT void* SlowGetAlignedPointerFromInternalField(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); | |
1752 }; | 1782 }; |
1753 | 1783 |
1754 | 1784 |
1755 /** | 1785 /** |
1756 * An instance of the built-in array constructor (ECMA-262, 15.4.2). | 1786 * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
1757 */ | 1787 */ |
1758 class Array : public Object { | 1788 class Array : public Object { |
1759 public: | 1789 public: |
1760 V8EXPORT uint32_t Length() const; | 1790 V8EXPORT uint32_t Length() const; |
1761 | 1791 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 V8EXPORT Flags GetFlags() const; | 1982 V8EXPORT Flags GetFlags() const; |
1953 | 1983 |
1954 static inline RegExp* Cast(v8::Value* obj); | 1984 static inline RegExp* Cast(v8::Value* obj); |
1955 | 1985 |
1956 private: | 1986 private: |
1957 V8EXPORT static void CheckCast(v8::Value* obj); | 1987 V8EXPORT static void CheckCast(v8::Value* obj); |
1958 }; | 1988 }; |
1959 | 1989 |
1960 | 1990 |
1961 /** | 1991 /** |
1962 * A JavaScript value that wraps a C++ void*. This type of value is | 1992 * A JavaScript value that wraps a C++ void*. This type of value is mainly used |
1963 * mainly used to associate C++ data structures with JavaScript | 1993 * to associate C++ data structures with JavaScript objects. |
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. | |
1971 */ | 1994 */ |
1972 class External : public Value { | 1995 class External : public Value { |
1973 public: | 1996 public: |
1974 V8EXPORT static Local<Value> Wrap(void* data); | 1997 /** Deprecated, use New instead. */ |
1975 static inline void* Unwrap(Handle<Value> obj); | 1998 V8_DEPRECATED(static inline Local<Value> Wrap(void* value)); |
| 1999 |
| 2000 /** Deprecated, use a combination of Cast and Value instead. */ |
| 2001 V8_DEPRECATED(static inline void* Unwrap(Handle<Value> obj)); |
1976 | 2002 |
1977 V8EXPORT static Local<External> New(void* value); | 2003 V8EXPORT static Local<External> New(void* value); |
1978 static inline External* Cast(Value* obj); | 2004 static inline External* Cast(Value* obj); |
1979 V8EXPORT void* Value() const; | 2005 V8EXPORT void* Value() const; |
1980 private: | 2006 private: |
1981 V8EXPORT External(); | |
1982 V8EXPORT static void CheckCast(v8::Value* obj); | 2007 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); | |
1985 }; | 2008 }; |
1986 | 2009 |
1987 | 2010 |
1988 // --- Templates --- | 2011 // --- Templates --- |
1989 | 2012 |
1990 | 2013 |
1991 /** | 2014 /** |
1992 * The superclass of object and function templates. | 2015 * The superclass of object and function templates. |
1993 */ | 2016 */ |
1994 class V8EXPORT Template : public Data { | 2017 class V8EXPORT Template : public Data { |
(...skipping 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3763 */ | 3786 */ |
3764 void Exit(); | 3787 void Exit(); |
3765 | 3788 |
3766 /** Returns true if the context has experienced an out of memory situation. */ | 3789 /** Returns true if the context has experienced an out of memory situation. */ |
3767 bool HasOutOfMemoryException(); | 3790 bool HasOutOfMemoryException(); |
3768 | 3791 |
3769 /** Returns true if V8 has a current context. */ | 3792 /** Returns true if V8 has a current context. */ |
3770 static bool InContext(); | 3793 static bool InContext(); |
3771 | 3794 |
3772 /** | 3795 /** |
3773 * Associate an additional data object with the context. This is mainly used | 3796 * Gets embedder data with index 0. Deprecated, use GetEmbedderData with index |
3774 * with the debugger to provide additional information on the context through | 3797 * 0 instead. |
3775 * the debugger API. | |
3776 */ | 3798 */ |
3777 void SetData(Handle<Value> data); | 3799 V8_DEPRECATED(inline Local<Value> GetData()); |
3778 Local<Value> GetData(); | 3800 |
| 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); |
3779 | 3835 |
3780 /** | 3836 /** |
3781 * Control whether code generation from strings is allowed. Calling | 3837 * Control whether code generation from strings is allowed. Calling |
3782 * this method with false will disable 'eval' and the 'Function' | 3838 * this method with false will disable 'eval' and the 'Function' |
3783 * constructor for code running in this context. If 'eval' or the | 3839 * constructor for code running in this context. If 'eval' or the |
3784 * 'Function' constructor are used an exception will be thrown. | 3840 * 'Function' constructor are used an exception will be thrown. |
3785 * | 3841 * |
3786 * If code generation from strings is not allowed the | 3842 * If code generation from strings is not allowed the |
3787 * V8::AllowCodeGenerationFromStrings callback will be invoked if | 3843 * V8::AllowCodeGenerationFromStrings callback will be invoked if |
3788 * set before blocking the call to 'eval' or the 'Function' | 3844 * set before blocking the call to 'eval' or the 'Function' |
(...skipping 28 matching lines...) Expand all Loading... |
3817 inline ~Scope() { context_->Exit(); } | 3873 inline ~Scope() { context_->Exit(); } |
3818 private: | 3874 private: |
3819 Handle<Context> context_; | 3875 Handle<Context> context_; |
3820 }; | 3876 }; |
3821 | 3877 |
3822 private: | 3878 private: |
3823 friend class Value; | 3879 friend class Value; |
3824 friend class Script; | 3880 friend class Script; |
3825 friend class Object; | 3881 friend class Object; |
3826 friend class Function; | 3882 friend class Function; |
| 3883 |
| 3884 Local<Value> SlowGetEmbedderData(int index); |
| 3885 void* SlowGetAlignedPointerFromEmbedderData(int index); |
3827 }; | 3886 }; |
3828 | 3887 |
3829 | 3888 |
3830 /** | 3889 /** |
3831 * Multiple threads in V8 are allowed, but only one thread at a time | 3890 * Multiple threads in V8 are allowed, but only one thread at a time |
3832 * is allowed to use any given V8 isolate. See Isolate class | 3891 * is allowed to use any given V8 isolate. See Isolate class |
3833 * comments. The definition of 'using V8 isolate' includes | 3892 * comments. The definition of 'using V8 isolate' includes |
3834 * accessing handles or holding onto object pointers obtained | 3893 * accessing handles or holding onto object pointers obtained |
3835 * from V8 handles while in the particular V8 isolate. It is up | 3894 * from V8 handles while in the particular V8 isolate. It is up |
3836 * to the user of V8 to ensure (perhaps with locking) that this | 3895 * 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... |
4050 | 4109 |
4051 // Smi constants for 32-bit systems. | 4110 // Smi constants for 32-bit systems. |
4052 template <> struct SmiTagging<4> { | 4111 template <> struct SmiTagging<4> { |
4053 static const int kSmiShiftSize = 0; | 4112 static const int kSmiShiftSize = 0; |
4054 static const int kSmiValueSize = 31; | 4113 static const int kSmiValueSize = 31; |
4055 static inline int SmiToInt(internal::Object* value) { | 4114 static inline int SmiToInt(internal::Object* value) { |
4056 int shift_bits = kSmiTagSize + kSmiShiftSize; | 4115 int shift_bits = kSmiTagSize + kSmiShiftSize; |
4057 // Throw away top 32 bits and shift down (requires >> to be sign extending). | 4116 // Throw away top 32 bits and shift down (requires >> to be sign extending). |
4058 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; | 4117 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
4059 } | 4118 } |
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; | |
4065 }; | 4119 }; |
4066 | 4120 |
4067 // Smi constants for 64-bit systems. | 4121 // Smi constants for 64-bit systems. |
4068 template <> struct SmiTagging<8> { | 4122 template <> struct SmiTagging<8> { |
4069 static const int kSmiShiftSize = 31; | 4123 static const int kSmiShiftSize = 31; |
4070 static const int kSmiValueSize = 32; | 4124 static const int kSmiValueSize = 32; |
4071 static inline int SmiToInt(internal::Object* value) { | 4125 static inline int SmiToInt(internal::Object* value) { |
4072 int shift_bits = kSmiTagSize + kSmiShiftSize; | 4126 int shift_bits = kSmiTagSize + kSmiShiftSize; |
4073 // Shift down and throw away top 32 bits. | 4127 // Shift down and throw away top 32 bits. |
4074 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 4128 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
4075 } | 4129 } |
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; | |
4088 }; | 4130 }; |
4089 | 4131 |
4090 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; | 4132 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
4091 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; | 4133 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
4092 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; | 4134 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
4093 const uintptr_t kEncodablePointerMask = | |
4094 PlatformSmiTagging::kEncodablePointerMask; | |
4095 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; | |
4096 | 4135 |
4097 /** | 4136 /** |
4098 * This class exports constants and functionality from within v8 that | 4137 * This class exports constants and functionality from within v8 that |
4099 * is necessary to implement inline functions in the v8 api. Don't | 4138 * is necessary to implement inline functions in the v8 api. Don't |
4100 * depend on functions and constants defined here. | 4139 * depend on functions and constants defined here. |
4101 */ | 4140 */ |
4102 class Internals { | 4141 class Internals { |
4103 public: | 4142 public: |
4104 // These values match non-compiler-dependent values defined within | 4143 // These values match non-compiler-dependent values defined within |
4105 // the implementation of v8. | 4144 // the implementation of v8. |
4106 static const int kHeapObjectMapOffset = 0; | 4145 static const int kHeapObjectMapOffset = 0; |
4107 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; | 4146 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
4108 static const int kStringResourceOffset = 3 * kApiPointerSize; | 4147 static const int kStringResourceOffset = 3 * kApiPointerSize; |
4109 | 4148 |
4110 static const int kOddballKindOffset = 3 * kApiPointerSize; | 4149 static const int kOddballKindOffset = 3 * kApiPointerSize; |
4111 static const int kForeignAddressOffset = kApiPointerSize; | 4150 static const int kForeignAddressOffset = kApiPointerSize; |
4112 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 4151 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; |
4113 static const int kFullStringRepresentationMask = 0x07; | 4155 static const int kFullStringRepresentationMask = 0x07; |
4114 static const int kStringEncodingMask = 0x4; | 4156 static const int kStringEncodingMask = 0x4; |
4115 static const int kExternalTwoByteRepresentationTag = 0x02; | 4157 static const int kExternalTwoByteRepresentationTag = 0x02; |
4116 static const int kExternalAsciiRepresentationTag = 0x06; | 4158 static const int kExternalAsciiRepresentationTag = 0x06; |
4117 | 4159 |
4118 static const int kIsolateStateOffset = 0; | 4160 static const int kIsolateStateOffset = 0; |
4119 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | 4161 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
4120 static const int kIsolateRootsOffset = 3 * kApiPointerSize; | 4162 static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
4121 static const int kUndefinedValueRootIndex = 5; | 4163 static const int kUndefinedValueRootIndex = 5; |
4122 static const int kNullValueRootIndex = 7; | 4164 static const int kNullValueRootIndex = 7; |
4123 static const int kTrueValueRootIndex = 8; | 4165 static const int kTrueValueRootIndex = 8; |
4124 static const int kFalseValueRootIndex = 9; | 4166 static const int kFalseValueRootIndex = 9; |
4125 static const int kEmptySymbolRootIndex = 118; | 4167 static const int kEmptySymbolRootIndex = 119; |
4126 | 4168 |
4127 static const int kJSObjectType = 0xaa; | 4169 static const int kJSObjectType = 0xaa; |
4128 static const int kFirstNonstringType = 0x80; | 4170 static const int kFirstNonstringType = 0x80; |
4129 static const int kOddballType = 0x82; | 4171 static const int kOddballType = 0x82; |
4130 static const int kForeignType = 0x85; | 4172 static const int kForeignType = 0x85; |
4131 | 4173 |
4132 static const int kUndefinedOddballKind = 5; | 4174 static const int kUndefinedOddballKind = 5; |
4133 static const int kNullOddballKind = 3; | 4175 static const int kNullOddballKind = 3; |
4134 | 4176 |
4135 static inline bool HasHeapObjectTag(internal::Object* value) { | 4177 static inline bool HasHeapObjectTag(internal::Object* value) { |
4136 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 4178 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
4137 kHeapObjectTag); | 4179 kHeapObjectTag); |
4138 } | 4180 } |
4139 | 4181 |
4140 static inline bool HasSmiTag(internal::Object* value) { | |
4141 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); | |
4142 } | |
4143 | |
4144 static inline int SmiValue(internal::Object* value) { | 4182 static inline int SmiValue(internal::Object* value) { |
4145 return PlatformSmiTagging::SmiToInt(value); | 4183 return PlatformSmiTagging::SmiToInt(value); |
4146 } | 4184 } |
4147 | 4185 |
4148 static inline int GetInstanceType(internal::Object* obj) { | 4186 static inline int GetInstanceType(internal::Object* obj) { |
4149 typedef internal::Object O; | 4187 typedef internal::Object O; |
4150 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 4188 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
4151 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 4189 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
4152 } | 4190 } |
4153 | 4191 |
4154 static inline int GetOddballKind(internal::Object* obj) { | 4192 static inline int GetOddballKind(internal::Object* obj) { |
4155 typedef internal::Object O; | 4193 typedef internal::Object O; |
4156 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); | 4194 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
4157 } | 4195 } |
4158 | 4196 |
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 | |
4174 static inline bool IsExternalTwoByteString(int instance_type) { | 4197 static inline bool IsExternalTwoByteString(int instance_type) { |
4175 int representation = (instance_type & kFullStringRepresentationMask); | 4198 int representation = (instance_type & kFullStringRepresentationMask); |
4176 return representation == kExternalTwoByteRepresentationTag; | 4199 return representation == kExternalTwoByteRepresentationTag; |
4177 } | 4200 } |
4178 | 4201 |
4179 static inline bool IsInitialized(v8::Isolate* isolate) { | 4202 static inline bool IsInitialized(v8::Isolate* isolate) { |
4180 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; | 4203 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
4181 return *reinterpret_cast<int*>(addr) == 1; | 4204 return *reinterpret_cast<int*>(addr) == 1; |
4182 } | 4205 } |
4183 | 4206 |
(...skipping 13 matching lines...) Expand all Loading... |
4197 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; | 4220 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
4198 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); | 4221 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
4199 } | 4222 } |
4200 | 4223 |
4201 template <typename T> | 4224 template <typename T> |
4202 static inline T ReadField(Object* ptr, int offset) { | 4225 static inline T ReadField(Object* ptr, int offset) { |
4203 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; | 4226 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
4204 return *reinterpret_cast<T*>(addr); | 4227 return *reinterpret_cast<T*>(addr); |
4205 } | 4228 } |
4206 | 4229 |
| 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 |
4207 static inline bool CanCastToHeapObject(void* o) { return false; } | 4243 static inline bool CanCastToHeapObject(void* o) { return false; } |
4208 static inline bool CanCastToHeapObject(Context* o) { return true; } | 4244 static inline bool CanCastToHeapObject(Context* o) { return true; } |
4209 static inline bool CanCastToHeapObject(String* o) { return true; } | 4245 static inline bool CanCastToHeapObject(String* o) { return true; } |
4210 static inline bool CanCastToHeapObject(Object* o) { return true; } | 4246 static inline bool CanCastToHeapObject(Object* o) { return true; } |
4211 static inline bool CanCastToHeapObject(Message* o) { return true; } | 4247 static inline bool CanCastToHeapObject(Message* o) { return true; } |
4212 static inline bool CanCastToHeapObject(StackTrace* o) { return true; } | 4248 static inline bool CanCastToHeapObject(StackTrace* o) { return true; } |
4213 static inline bool CanCastToHeapObject(StackFrame* o) { return true; } | 4249 static inline bool CanCastToHeapObject(StackFrame* o) { return true; } |
4214 }; | 4250 }; |
4215 | 4251 |
4216 } // namespace internal | 4252 } // namespace internal |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4411 } | 4447 } |
4412 | 4448 |
4413 | 4449 |
4414 void Template::Set(const char* name, v8::Handle<Data> value) { | 4450 void Template::Set(const char* name, v8::Handle<Data> value) { |
4415 Set(v8::String::New(name), value); | 4451 Set(v8::String::New(name), value); |
4416 } | 4452 } |
4417 | 4453 |
4418 | 4454 |
4419 Local<Value> Object::GetInternalField(int index) { | 4455 Local<Value> Object::GetInternalField(int index) { |
4420 #ifndef V8_ENABLE_CHECKS | 4456 #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) { | |
4429 typedef internal::Object O; | 4457 typedef internal::Object O; |
4430 typedef internal::Internals I; | 4458 typedef internal::Internals I; |
4431 O* obj = *reinterpret_cast<O**>(this); | 4459 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. |
4432 if (I::GetInstanceType(obj) == I::kJSObjectType) { | 4462 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. | |
4436 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); | 4463 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
4437 O* value = I::ReadField<O*>(obj, offset); | 4464 O* value = I::ReadField<O*>(obj, offset); |
4438 O** result = HandleScope::CreateHandle(value); | 4465 O** result = HandleScope::CreateHandle(value); |
4439 return Local<Value>(reinterpret_cast<Value*>(result)); | 4466 return Local<Value>(reinterpret_cast<Value*>(result)); |
4440 } else { | |
4441 return Local<Value>(); | |
4442 } | 4467 } |
| 4468 #endif |
| 4469 return SlowGetInternalField(index); |
4443 } | 4470 } |
4444 | 4471 |
4445 | 4472 |
4446 void* External::Unwrap(Handle<v8::Value> obj) { | 4473 void Object::SetPointerInInternalField(int index, void* value) { |
4447 #ifdef V8_ENABLE_CHECKS | 4474 SetInternalField(index, External::New(value)); |
4448 return FullUnwrap(obj); | |
4449 #else | |
4450 return QuickUnwrap(obj); | |
4451 #endif | |
4452 } | 4475 } |
4453 | 4476 |
4454 | 4477 |
4455 void* External::QuickUnwrap(Handle<v8::Value> wrapper) { | 4478 void* Object::GetAlignedPointerFromInternalField(int index) { |
| 4479 #ifndef V8_ENABLE_CHECKS |
4456 typedef internal::Object O; | 4480 typedef internal::Object O; |
4457 O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); | 4481 typedef internal::Internals I; |
4458 return internal::Internals::GetExternalPointer(obj); | 4482 O* obj = *reinterpret_cast<O**>(this); |
| 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); |
4459 } | 4491 } |
4460 | 4492 |
4461 | 4493 |
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 | |
4481 String* String::Cast(v8::Value* value) { | 4494 String* String::Cast(v8::Value* value) { |
4482 #ifdef V8_ENABLE_CHECKS | 4495 #ifdef V8_ENABLE_CHECKS |
4483 CheckCast(value); | 4496 CheckCast(value); |
4484 #endif | 4497 #endif |
4485 return static_cast<String*>(value); | 4498 return static_cast<String*>(value); |
4486 } | 4499 } |
4487 | 4500 |
4488 | 4501 |
4489 Local<String> String::Empty(Isolate* isolate) { | 4502 Local<String> String::Empty(Isolate* isolate) { |
4490 typedef internal::Object* S; | 4503 typedef internal::Object* S; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4659 | 4672 |
4660 | 4673 |
4661 Function* Function::Cast(v8::Value* value) { | 4674 Function* Function::Cast(v8::Value* value) { |
4662 #ifdef V8_ENABLE_CHECKS | 4675 #ifdef V8_ENABLE_CHECKS |
4663 CheckCast(value); | 4676 CheckCast(value); |
4664 #endif | 4677 #endif |
4665 return static_cast<Function*>(value); | 4678 return static_cast<Function*>(value); |
4666 } | 4679 } |
4667 | 4680 |
4668 | 4681 |
| 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 |
4669 External* External::Cast(v8::Value* value) { | 4692 External* External::Cast(v8::Value* value) { |
4670 #ifdef V8_ENABLE_CHECKS | 4693 #ifdef V8_ENABLE_CHECKS |
4671 CheckCast(value); | 4694 CheckCast(value); |
4672 #endif | 4695 #endif |
4673 return static_cast<External*>(value); | 4696 return static_cast<External*>(value); |
4674 } | 4697 } |
4675 | 4698 |
4676 | 4699 |
4677 Isolate* AccessorInfo::GetIsolate() const { | 4700 Isolate* AccessorInfo::GetIsolate() const { |
4678 return *reinterpret_cast<Isolate**>(&args_[-3]); | 4701 return *reinterpret_cast<Isolate**>(&args_[-3]); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4735 I::SetEmbedderData(this, data); | 4758 I::SetEmbedderData(this, data); |
4736 } | 4759 } |
4737 | 4760 |
4738 | 4761 |
4739 void* Isolate::GetData() { | 4762 void* Isolate::GetData() { |
4740 typedef internal::Internals I; | 4763 typedef internal::Internals I; |
4741 return I::GetEmbedderData(this); | 4764 return I::GetEmbedderData(this); |
4742 } | 4765 } |
4743 | 4766 |
4744 | 4767 |
| 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 |
4745 /** | 4799 /** |
4746 * \example shell.cc | 4800 * \example shell.cc |
4747 * A simple shell that takes a list of expressions on the | 4801 * A simple shell that takes a list of expressions on the |
4748 * command-line and executes them. | 4802 * command-line and executes them. |
4749 */ | 4803 */ |
4750 | 4804 |
4751 | 4805 |
4752 /** | 4806 /** |
4753 * \example process.cc | 4807 * \example process.cc |
4754 */ | 4808 */ |
4755 | 4809 |
4756 | 4810 |
4757 } // namespace v8 | 4811 } // namespace v8 |
4758 | 4812 |
4759 | 4813 |
4760 #undef V8EXPORT | 4814 #undef V8EXPORT |
4761 #undef TYPE_CHECK | 4815 #undef TYPE_CHECK |
4762 | 4816 |
4763 | 4817 |
4764 #endif // V8_H_ | 4818 #endif // V8_H_ |
OLD | NEW |