| 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 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1593 */ | 1582 */ |
| 1594 V8EXPORT Local<Value> GetConstructor(); | 1583 V8EXPORT Local<Value> GetConstructor(); |
| 1595 | 1584 |
| 1596 /** | 1585 /** |
| 1597 * Returns the name of the function invoked as a constructor for this object. | 1586 * Returns the name of the function invoked as a constructor for this object. |
| 1598 */ | 1587 */ |
| 1599 V8EXPORT Local<String> GetConstructorName(); | 1588 V8EXPORT Local<String> GetConstructorName(); |
| 1600 | 1589 |
| 1601 /** Gets the number of internal fields for this Object. */ | 1590 /** Gets the number of internal fields for this Object. */ |
| 1602 V8EXPORT int InternalFieldCount(); | 1591 V8EXPORT int InternalFieldCount(); |
| 1603 | 1592 /** Gets the value in an internal field. */ |
| 1604 /** Gets the value from an internal field. */ | |
| 1605 inline Local<Value> GetInternalField(int index); | 1593 inline Local<Value> GetInternalField(int index); |
| 1606 | |
| 1607 /** Sets the value in an internal field. */ | 1594 /** Sets the value in an internal field. */ |
| 1608 V8EXPORT void SetInternalField(int index, Handle<Value> value); | 1595 V8EXPORT void SetInternalField(int index, Handle<Value> value); |
| 1609 | 1596 |
| 1610 /** | 1597 /** Gets a native pointer from an internal field. */ |
| 1611 * Gets a native pointer from an internal field. Deprecated. If the pointer is | 1598 inline void* GetPointerFromInternalField(int index); |
| 1612 * always 2-byte-aligned, use GetAlignedPointerFromInternalField instead, | |
| 1613 * otherwise use a combination of GetInternalField, External::Cast and | |
| 1614 * External::Value. | |
| 1615 */ | |
| 1616 V8EXPORT V8_DEPRECATED(void* GetPointerFromInternalField(int index)); | |
| 1617 | 1599 |
| 1618 /** | 1600 /** Sets a native pointer in an internal field. */ |
| 1619 * Sets a native pointer in an internal field. Deprecated. If the pointer is | 1601 V8EXPORT void SetPointerInInternalField(int index, void* value); |
| 1620 * always 2-byte aligned, use SetAlignedPointerInInternalField instead, | |
| 1621 * otherwise use a combination of External::New and SetInternalField. | |
| 1622 */ | |
| 1623 inline V8_DEPRECATED(void SetPointerInInternalField(int index, void* value)); | |
| 1624 | |
| 1625 /** | |
| 1626 * Gets a 2-byte-aligned native pointer from an internal field. This field | |
| 1627 * must have been set by SetAlignedPointerInInternalField, everything else | |
| 1628 * leads to undefined behavior. | |
| 1629 */ | |
| 1630 inline void* GetAlignedPointerFromInternalField(int index); | |
| 1631 | |
| 1632 /** | |
| 1633 * Sets a 2-byte-aligned native pointer in an internal field. To retrieve such | |
| 1634 * a field, GetAlignedPointerFromInternalField must be used, everything else | |
| 1635 * leads to undefined behavior. | |
| 1636 */ | |
| 1637 V8EXPORT void SetAlignedPointerInInternalField(int index, void* value); | |
| 1638 | 1602 |
| 1639 // Testers for local properties. | 1603 // Testers for local properties. |
| 1640 V8EXPORT bool HasOwnProperty(Handle<String> key); | 1604 V8EXPORT bool HasOwnProperty(Handle<String> key); |
| 1641 V8EXPORT bool HasRealNamedProperty(Handle<String> key); | 1605 V8EXPORT bool HasRealNamedProperty(Handle<String> key); |
| 1642 V8EXPORT bool HasRealIndexedProperty(uint32_t index); | 1606 V8EXPORT bool HasRealIndexedProperty(uint32_t index); |
| 1643 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); | 1607 V8EXPORT bool HasRealNamedCallbackProperty(Handle<String> key); |
| 1644 | 1608 |
| 1645 /** | 1609 /** |
| 1646 * If result.IsEmpty() no real property was located in the prototype chain. | 1610 * If result.IsEmpty() no real property was located in the prototype chain. |
| 1647 * This means interceptors in the prototype chain are not called. | 1611 * This means interceptors in the prototype chain are not called. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1758 */ | 1722 */ |
| 1759 V8EXPORT Local<Value> CallAsConstructor(int argc, | 1723 V8EXPORT Local<Value> CallAsConstructor(int argc, |
| 1760 Handle<Value> argv[]); | 1724 Handle<Value> argv[]); |
| 1761 | 1725 |
| 1762 V8EXPORT static Local<Object> New(); | 1726 V8EXPORT static Local<Object> New(); |
| 1763 static inline Object* Cast(Value* obj); | 1727 static inline Object* Cast(Value* obj); |
| 1764 | 1728 |
| 1765 private: | 1729 private: |
| 1766 V8EXPORT Object(); | 1730 V8EXPORT Object(); |
| 1767 V8EXPORT static void CheckCast(Value* obj); | 1731 V8EXPORT static void CheckCast(Value* obj); |
| 1768 V8EXPORT Local<Value> SlowGetInternalField(int index); | 1732 V8EXPORT Local<Value> CheckedGetInternalField(int index); |
| 1769 V8EXPORT void* SlowGetAlignedPointerFromInternalField(int index); | 1733 V8EXPORT void* SlowGetPointerFromInternalField(int index); |
| 1734 |
| 1735 /** |
| 1736 * If quick access to the internal field is possible this method |
| 1737 * returns the value. Otherwise an empty handle is returned. |
| 1738 */ |
| 1739 inline Local<Value> UncheckedGetInternalField(int index); |
| 1770 }; | 1740 }; |
| 1771 | 1741 |
| 1772 | 1742 |
| 1773 /** | 1743 /** |
| 1774 * An instance of the built-in array constructor (ECMA-262, 15.4.2). | 1744 * An instance of the built-in array constructor (ECMA-262, 15.4.2). |
| 1775 */ | 1745 */ |
| 1776 class Array : public Object { | 1746 class Array : public Object { |
| 1777 public: | 1747 public: |
| 1778 V8EXPORT uint32_t Length() const; | 1748 V8EXPORT uint32_t Length() const; |
| 1779 | 1749 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1970 V8EXPORT Flags GetFlags() const; | 1940 V8EXPORT Flags GetFlags() const; |
| 1971 | 1941 |
| 1972 static inline RegExp* Cast(v8::Value* obj); | 1942 static inline RegExp* Cast(v8::Value* obj); |
| 1973 | 1943 |
| 1974 private: | 1944 private: |
| 1975 V8EXPORT static void CheckCast(v8::Value* obj); | 1945 V8EXPORT static void CheckCast(v8::Value* obj); |
| 1976 }; | 1946 }; |
| 1977 | 1947 |
| 1978 | 1948 |
| 1979 /** | 1949 /** |
| 1980 * A JavaScript value that wraps a C++ void*. This type of value is mainly used | 1950 * A JavaScript value that wraps a C++ void*. This type of value is |
| 1981 * to associate C++ data structures with JavaScript objects. | 1951 * mainly used to associate C++ data structures with JavaScript |
| 1952 * objects. |
| 1953 * |
| 1954 * The Wrap function V8 will return the most optimal Value object wrapping the |
| 1955 * C++ void*. The type of the value is not guaranteed to be an External object |
| 1956 * and no assumptions about its type should be made. To access the wrapped |
| 1957 * value Unwrap should be used, all other operations on that object will lead |
| 1958 * to unpredictable results. |
| 1982 */ | 1959 */ |
| 1983 class External : public Value { | 1960 class External : public Value { |
| 1984 public: | 1961 public: |
| 1985 /** Deprecated, use New instead. */ | 1962 V8EXPORT static Local<Value> Wrap(void* data); |
| 1986 V8_DEPRECATED(static inline Local<Value> Wrap(void* value)); | 1963 static inline void* Unwrap(Handle<Value> obj); |
| 1987 | |
| 1988 /** Deprecated, use a combination of Cast and Value instead. */ | |
| 1989 V8_DEPRECATED(static inline void* Unwrap(Handle<Value> obj)); | |
| 1990 | 1964 |
| 1991 V8EXPORT static Local<External> New(void* value); | 1965 V8EXPORT static Local<External> New(void* value); |
| 1992 static inline External* Cast(Value* obj); | 1966 static inline External* Cast(Value* obj); |
| 1993 V8EXPORT void* Value() const; | 1967 V8EXPORT void* Value() const; |
| 1994 private: | 1968 private: |
| 1969 V8EXPORT External(); |
| 1995 V8EXPORT static void CheckCast(v8::Value* obj); | 1970 V8EXPORT static void CheckCast(v8::Value* obj); |
| 1971 static inline void* QuickUnwrap(Handle<v8::Value> obj); |
| 1972 V8EXPORT static void* FullUnwrap(Handle<v8::Value> obj); |
| 1996 }; | 1973 }; |
| 1997 | 1974 |
| 1998 | 1975 |
| 1999 // --- Templates --- | 1976 // --- Templates --- |
| 2000 | 1977 |
| 2001 | 1978 |
| 2002 /** | 1979 /** |
| 2003 * The superclass of object and function templates. | 1980 * The superclass of object and function templates. |
| 2004 */ | 1981 */ |
| 2005 class V8EXPORT Template : public Data { | 1982 class V8EXPORT Template : public Data { |
| (...skipping 1760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3766 */ | 3743 */ |
| 3767 void Exit(); | 3744 void Exit(); |
| 3768 | 3745 |
| 3769 /** Returns true if the context has experienced an out of memory situation. */ | 3746 /** Returns true if the context has experienced an out of memory situation. */ |
| 3770 bool HasOutOfMemoryException(); | 3747 bool HasOutOfMemoryException(); |
| 3771 | 3748 |
| 3772 /** Returns true if V8 has a current context. */ | 3749 /** Returns true if V8 has a current context. */ |
| 3773 static bool InContext(); | 3750 static bool InContext(); |
| 3774 | 3751 |
| 3775 /** | 3752 /** |
| 3776 * Gets embedder data with index 0. Deprecated, use GetEmbedderData with index | 3753 * Associate an additional data object with the context. This is mainly used |
| 3777 * 0 instead. | 3754 * with the debugger to provide additional information on the context through |
| 3755 * the debugger API. |
| 3778 */ | 3756 */ |
| 3779 V8_DEPRECATED(inline Local<Value> GetData()); | 3757 void SetData(Handle<Value> data); |
| 3780 | 3758 Local<Value> GetData(); |
| 3781 /** | |
| 3782 * Sets embedder data with index 0. Deprecated, use SetEmbedderData with index | |
| 3783 * 0 instead. | |
| 3784 */ | |
| 3785 V8_DEPRECATED(inline void SetData(Handle<Value> value)); | |
| 3786 | |
| 3787 /** | |
| 3788 * Gets the embedder data with the given index, which must have been set by a | |
| 3789 * previous call to SetEmbedderData with the same index. Note that index 0 | |
| 3790 * currently has a special meaning for Chrome's debugger. | |
| 3791 */ | |
| 3792 inline Local<Value> GetEmbedderData(int index); | |
| 3793 | |
| 3794 /** | |
| 3795 * Sets the embedder data with the given index, growing the data as | |
| 3796 * needed. Note that index 0 currently has a special meaning for Chrome's | |
| 3797 * debugger. | |
| 3798 */ | |
| 3799 void SetEmbedderData(int index, Handle<Value> value); | |
| 3800 | |
| 3801 /** | |
| 3802 * Gets a 2-byte-aligned native pointer from the embedder data with the given | |
| 3803 * index, which must have bees set by a previous call to | |
| 3804 * SetAlignedPointerInEmbedderData with the same index. Note that index 0 | |
| 3805 * currently has a special meaning for Chrome's debugger. | |
| 3806 */ | |
| 3807 inline void* GetAlignedPointerFromEmbedderData(int index); | |
| 3808 | |
| 3809 /** | |
| 3810 * Sets a 2-byte-aligned native pointer in the embedder data with the given | |
| 3811 * index, growing the data as needed. Note that index 0 currently has a | |
| 3812 * special meaning for Chrome's debugger. | |
| 3813 */ | |
| 3814 void SetAlignedPointerInEmbedderData(int index, void* value); | |
| 3815 | 3759 |
| 3816 /** | 3760 /** |
| 3817 * Control whether code generation from strings is allowed. Calling | 3761 * Control whether code generation from strings is allowed. Calling |
| 3818 * this method with false will disable 'eval' and the 'Function' | 3762 * this method with false will disable 'eval' and the 'Function' |
| 3819 * constructor for code running in this context. If 'eval' or the | 3763 * constructor for code running in this context. If 'eval' or the |
| 3820 * 'Function' constructor are used an exception will be thrown. | 3764 * 'Function' constructor are used an exception will be thrown. |
| 3821 * | 3765 * |
| 3822 * If code generation from strings is not allowed the | 3766 * If code generation from strings is not allowed the |
| 3823 * V8::AllowCodeGenerationFromStrings callback will be invoked if | 3767 * V8::AllowCodeGenerationFromStrings callback will be invoked if |
| 3824 * set before blocking the call to 'eval' or the 'Function' | 3768 * set before blocking the call to 'eval' or the 'Function' |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3853 inline ~Scope() { context_->Exit(); } | 3797 inline ~Scope() { context_->Exit(); } |
| 3854 private: | 3798 private: |
| 3855 Handle<Context> context_; | 3799 Handle<Context> context_; |
| 3856 }; | 3800 }; |
| 3857 | 3801 |
| 3858 private: | 3802 private: |
| 3859 friend class Value; | 3803 friend class Value; |
| 3860 friend class Script; | 3804 friend class Script; |
| 3861 friend class Object; | 3805 friend class Object; |
| 3862 friend class Function; | 3806 friend class Function; |
| 3863 | |
| 3864 Local<Value> SlowGetEmbedderData(int index); | |
| 3865 void* SlowGetAlignedPointerFromEmbedderData(int index); | |
| 3866 }; | 3807 }; |
| 3867 | 3808 |
| 3868 | 3809 |
| 3869 /** | 3810 /** |
| 3870 * Multiple threads in V8 are allowed, but only one thread at a time | 3811 * Multiple threads in V8 are allowed, but only one thread at a time |
| 3871 * is allowed to use any given V8 isolate. See Isolate class | 3812 * is allowed to use any given V8 isolate. See Isolate class |
| 3872 * comments. The definition of 'using V8 isolate' includes | 3813 * comments. The definition of 'using V8 isolate' includes |
| 3873 * accessing handles or holding onto object pointers obtained | 3814 * accessing handles or holding onto object pointers obtained |
| 3874 * from V8 handles while in the particular V8 isolate. It is up | 3815 * from V8 handles while in the particular V8 isolate. It is up |
| 3875 * to the user of V8 to ensure (perhaps with locking) that this | 3816 * 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... |
| 4089 | 4030 |
| 4090 // Smi constants for 32-bit systems. | 4031 // Smi constants for 32-bit systems. |
| 4091 template <> struct SmiTagging<4> { | 4032 template <> struct SmiTagging<4> { |
| 4092 static const int kSmiShiftSize = 0; | 4033 static const int kSmiShiftSize = 0; |
| 4093 static const int kSmiValueSize = 31; | 4034 static const int kSmiValueSize = 31; |
| 4094 static inline int SmiToInt(internal::Object* value) { | 4035 static inline int SmiToInt(internal::Object* value) { |
| 4095 int shift_bits = kSmiTagSize + kSmiShiftSize; | 4036 int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 4096 // Throw away top 32 bits and shift down (requires >> to be sign extending). | 4037 // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 4097 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; | 4038 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 4098 } | 4039 } |
| 4040 |
| 4041 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi |
| 4042 // with a plain reinterpret_cast. |
| 4043 static const uintptr_t kEncodablePointerMask = 0x1; |
| 4044 static const int kPointerToSmiShift = 0; |
| 4099 }; | 4045 }; |
| 4100 | 4046 |
| 4101 // Smi constants for 64-bit systems. | 4047 // Smi constants for 64-bit systems. |
| 4102 template <> struct SmiTagging<8> { | 4048 template <> struct SmiTagging<8> { |
| 4103 static const int kSmiShiftSize = 31; | 4049 static const int kSmiShiftSize = 31; |
| 4104 static const int kSmiValueSize = 32; | 4050 static const int kSmiValueSize = 32; |
| 4105 static inline int SmiToInt(internal::Object* value) { | 4051 static inline int SmiToInt(internal::Object* value) { |
| 4106 int shift_bits = kSmiTagSize + kSmiShiftSize; | 4052 int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 4107 // Shift down and throw away top 32 bits. | 4053 // Shift down and throw away top 32 bits. |
| 4108 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 4054 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 4109 } | 4055 } |
| 4056 |
| 4057 // To maximize the range of pointers that can be encoded |
| 4058 // in the available 32 bits, we require them to be 8 bytes aligned. |
| 4059 // This gives 2 ^ (32 + 3) = 32G address space covered. |
| 4060 // It might be not enough to cover stack allocated objects on some platforms. |
| 4061 static const int kPointerAlignment = 3; |
| 4062 |
| 4063 static const uintptr_t kEncodablePointerMask = |
| 4064 ~(uintptr_t(0xffffffff) << kPointerAlignment); |
| 4065 |
| 4066 static const int kPointerToSmiShift = |
| 4067 kSmiTagSize + kSmiShiftSize - kPointerAlignment; |
| 4110 }; | 4068 }; |
| 4111 | 4069 |
| 4112 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; | 4070 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 4113 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; | 4071 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 4114 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; | 4072 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
| 4073 const uintptr_t kEncodablePointerMask = |
| 4074 PlatformSmiTagging::kEncodablePointerMask; |
| 4075 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; |
| 4115 | 4076 |
| 4116 /** | 4077 /** |
| 4117 * This class exports constants and functionality from within v8 that | 4078 * This class exports constants and functionality from within v8 that |
| 4118 * is necessary to implement inline functions in the v8 api. Don't | 4079 * is necessary to implement inline functions in the v8 api. Don't |
| 4119 * depend on functions and constants defined here. | 4080 * depend on functions and constants defined here. |
| 4120 */ | 4081 */ |
| 4121 class Internals { | 4082 class Internals { |
| 4122 public: | 4083 public: |
| 4123 // These values match non-compiler-dependent values defined within | 4084 // These values match non-compiler-dependent values defined within |
| 4124 // the implementation of v8. | 4085 // the implementation of v8. |
| 4125 static const int kHeapObjectMapOffset = 0; | 4086 static const int kHeapObjectMapOffset = 0; |
| 4126 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; | 4087 static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
| 4127 static const int kStringResourceOffset = 3 * kApiPointerSize; | 4088 static const int kStringResourceOffset = 3 * kApiPointerSize; |
| 4128 | 4089 |
| 4129 static const int kOddballKindOffset = 3 * kApiPointerSize; | 4090 static const int kOddballKindOffset = 3 * kApiPointerSize; |
| 4130 static const int kForeignAddressOffset = kApiPointerSize; | 4091 static const int kForeignAddressOffset = kApiPointerSize; |
| 4131 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 4092 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
| 4132 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; | |
| 4133 static const int kContextHeaderSize = 2 * kApiPointerSize; | |
| 4134 static const int kContextEmbedderDataIndex = 54; | |
| 4135 static const int kFullStringRepresentationMask = 0x07; | 4093 static const int kFullStringRepresentationMask = 0x07; |
| 4136 static const int kStringEncodingMask = 0x4; | 4094 static const int kStringEncodingMask = 0x4; |
| 4137 static const int kExternalTwoByteRepresentationTag = 0x02; | 4095 static const int kExternalTwoByteRepresentationTag = 0x02; |
| 4138 static const int kExternalAsciiRepresentationTag = 0x06; | 4096 static const int kExternalAsciiRepresentationTag = 0x06; |
| 4139 | 4097 |
| 4140 static const int kIsolateStateOffset = 0; | 4098 static const int kIsolateStateOffset = 0; |
| 4141 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | 4099 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
| 4142 static const int kIsolateRootsOffset = 3 * kApiPointerSize; | 4100 static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
| 4143 static const int kUndefinedValueRootIndex = 5; | 4101 static const int kUndefinedValueRootIndex = 5; |
| 4144 static const int kNullValueRootIndex = 7; | 4102 static const int kNullValueRootIndex = 7; |
| 4145 static const int kTrueValueRootIndex = 8; | 4103 static const int kTrueValueRootIndex = 8; |
| 4146 static const int kFalseValueRootIndex = 9; | 4104 static const int kFalseValueRootIndex = 9; |
| 4147 static const int kEmptySymbolRootIndex = 118; | 4105 static const int kEmptySymbolRootIndex = 117; |
| 4148 | 4106 |
| 4149 static const int kJSObjectType = 0xaa; | 4107 static const int kJSObjectType = 0xaa; |
| 4150 static const int kFirstNonstringType = 0x80; | 4108 static const int kFirstNonstringType = 0x80; |
| 4151 static const int kOddballType = 0x82; | 4109 static const int kOddballType = 0x82; |
| 4152 static const int kForeignType = 0x85; | 4110 static const int kForeignType = 0x85; |
| 4153 | 4111 |
| 4154 static const int kUndefinedOddballKind = 5; | 4112 static const int kUndefinedOddballKind = 5; |
| 4155 static const int kNullOddballKind = 3; | 4113 static const int kNullOddballKind = 3; |
| 4156 | 4114 |
| 4157 static inline bool HasHeapObjectTag(internal::Object* value) { | 4115 static inline bool HasHeapObjectTag(internal::Object* value) { |
| 4158 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 4116 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 4159 kHeapObjectTag); | 4117 kHeapObjectTag); |
| 4160 } | 4118 } |
| 4161 | 4119 |
| 4120 static inline bool HasSmiTag(internal::Object* value) { |
| 4121 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
| 4122 } |
| 4123 |
| 4162 static inline int SmiValue(internal::Object* value) { | 4124 static inline int SmiValue(internal::Object* value) { |
| 4163 return PlatformSmiTagging::SmiToInt(value); | 4125 return PlatformSmiTagging::SmiToInt(value); |
| 4164 } | 4126 } |
| 4165 | 4127 |
| 4166 static inline int GetInstanceType(internal::Object* obj) { | 4128 static inline int GetInstanceType(internal::Object* obj) { |
| 4167 typedef internal::Object O; | 4129 typedef internal::Object O; |
| 4168 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 4130 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 4169 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 4131 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 4170 } | 4132 } |
| 4171 | 4133 |
| 4172 static inline int GetOddballKind(internal::Object* obj) { | 4134 static inline int GetOddballKind(internal::Object* obj) { |
| 4173 typedef internal::Object O; | 4135 typedef internal::Object O; |
| 4174 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); | 4136 return SmiValue(ReadField<O*>(obj, kOddballKindOffset)); |
| 4175 } | 4137 } |
| 4176 | 4138 |
| 4139 static inline void* GetExternalPointerFromSmi(internal::Object* value) { |
| 4140 const uintptr_t address = reinterpret_cast<uintptr_t>(value); |
| 4141 return reinterpret_cast<void*>(address >> kPointerToSmiShift); |
| 4142 } |
| 4143 |
| 4144 static inline void* GetExternalPointer(internal::Object* obj) { |
| 4145 if (HasSmiTag(obj)) { |
| 4146 return GetExternalPointerFromSmi(obj); |
| 4147 } else if (GetInstanceType(obj) == kForeignType) { |
| 4148 return ReadField<void*>(obj, kForeignAddressOffset); |
| 4149 } else { |
| 4150 return NULL; |
| 4151 } |
| 4152 } |
| 4153 |
| 4177 static inline bool IsExternalTwoByteString(int instance_type) { | 4154 static inline bool IsExternalTwoByteString(int instance_type) { |
| 4178 int representation = (instance_type & kFullStringRepresentationMask); | 4155 int representation = (instance_type & kFullStringRepresentationMask); |
| 4179 return representation == kExternalTwoByteRepresentationTag; | 4156 return representation == kExternalTwoByteRepresentationTag; |
| 4180 } | 4157 } |
| 4181 | 4158 |
| 4182 static inline bool IsInitialized(v8::Isolate* isolate) { | 4159 static inline bool IsInitialized(v8::Isolate* isolate) { |
| 4183 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; | 4160 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
| 4184 return *reinterpret_cast<int*>(addr) == 1; | 4161 return *reinterpret_cast<int*>(addr) == 1; |
| 4185 } | 4162 } |
| 4186 | 4163 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4200 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; | 4177 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
| 4201 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); | 4178 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
| 4202 } | 4179 } |
| 4203 | 4180 |
| 4204 template <typename T> | 4181 template <typename T> |
| 4205 static inline T ReadField(Object* ptr, int offset) { | 4182 static inline T ReadField(Object* ptr, int offset) { |
| 4206 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; | 4183 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 4207 return *reinterpret_cast<T*>(addr); | 4184 return *reinterpret_cast<T*>(addr); |
| 4208 } | 4185 } |
| 4209 | 4186 |
| 4210 template <typename T> | |
| 4211 static inline T ReadEmbedderData(Context* context, int index) { | |
| 4212 typedef internal::Object O; | |
| 4213 typedef internal::Internals I; | |
| 4214 O* ctx = *reinterpret_cast<O**>(context); | |
| 4215 int embedder_data_offset = I::kContextHeaderSize + | |
| 4216 (internal::kApiPointerSize * I::kContextEmbedderDataIndex); | |
| 4217 O* embedder_data = I::ReadField<O*>(ctx, embedder_data_offset); | |
| 4218 int value_offset = | |
| 4219 I::kFixedArrayHeaderSize + (internal::kApiPointerSize * index); | |
| 4220 return I::ReadField<T>(embedder_data, value_offset); | |
| 4221 } | |
| 4222 | |
| 4223 static inline bool CanCastToHeapObject(void* o) { return false; } | 4187 static inline bool CanCastToHeapObject(void* o) { return false; } |
| 4224 static inline bool CanCastToHeapObject(Context* o) { return true; } | 4188 static inline bool CanCastToHeapObject(Context* o) { return true; } |
| 4225 static inline bool CanCastToHeapObject(String* o) { return true; } | 4189 static inline bool CanCastToHeapObject(String* o) { return true; } |
| 4226 static inline bool CanCastToHeapObject(Object* o) { return true; } | 4190 static inline bool CanCastToHeapObject(Object* o) { return true; } |
| 4227 static inline bool CanCastToHeapObject(Message* o) { return true; } | 4191 static inline bool CanCastToHeapObject(Message* o) { return true; } |
| 4228 static inline bool CanCastToHeapObject(StackTrace* o) { return true; } | 4192 static inline bool CanCastToHeapObject(StackTrace* o) { return true; } |
| 4229 static inline bool CanCastToHeapObject(StackFrame* o) { return true; } | 4193 static inline bool CanCastToHeapObject(StackFrame* o) { return true; } |
| 4230 }; | 4194 }; |
| 4231 | 4195 |
| 4232 } // namespace internal | 4196 } // namespace internal |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4410 } | 4374 } |
| 4411 | 4375 |
| 4412 | 4376 |
| 4413 void Template::Set(const char* name, v8::Handle<Data> value) { | 4377 void Template::Set(const char* name, v8::Handle<Data> value) { |
| 4414 Set(v8::String::New(name), value); | 4378 Set(v8::String::New(name), value); |
| 4415 } | 4379 } |
| 4416 | 4380 |
| 4417 | 4381 |
| 4418 Local<Value> Object::GetInternalField(int index) { | 4382 Local<Value> Object::GetInternalField(int index) { |
| 4419 #ifndef V8_ENABLE_CHECKS | 4383 #ifndef V8_ENABLE_CHECKS |
| 4384 Local<Value> quick_result = UncheckedGetInternalField(index); |
| 4385 if (!quick_result.IsEmpty()) return quick_result; |
| 4386 #endif |
| 4387 return CheckedGetInternalField(index); |
| 4388 } |
| 4389 |
| 4390 |
| 4391 Local<Value> Object::UncheckedGetInternalField(int index) { |
| 4420 typedef internal::Object O; | 4392 typedef internal::Object O; |
| 4421 typedef internal::Internals I; | 4393 typedef internal::Internals I; |
| 4422 O* obj = *reinterpret_cast<O**>(this); | 4394 O* obj = *reinterpret_cast<O**>(this); |
| 4423 // Fast path: If the object is a plain JSObject, which is the common case, we | |
| 4424 // know where to find the internal fields and can return the value directly. | |
| 4425 if (I::GetInstanceType(obj) == I::kJSObjectType) { | 4395 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
| 4396 // If the object is a plain JSObject, which is the common case, |
| 4397 // we know where to find the internal fields and can return the |
| 4398 // value directly. |
| 4426 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); | 4399 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
| 4427 O* value = I::ReadField<O*>(obj, offset); | 4400 O* value = I::ReadField<O*>(obj, offset); |
| 4428 O** result = HandleScope::CreateHandle(value); | 4401 O** result = HandleScope::CreateHandle(value); |
| 4429 return Local<Value>(reinterpret_cast<Value*>(result)); | 4402 return Local<Value>(reinterpret_cast<Value*>(result)); |
| 4403 } else { |
| 4404 return Local<Value>(); |
| 4430 } | 4405 } |
| 4431 #endif | |
| 4432 return SlowGetInternalField(index); | |
| 4433 } | 4406 } |
| 4434 | 4407 |
| 4435 | 4408 |
| 4436 void Object::SetPointerInInternalField(int index, void* value) { | 4409 void* External::Unwrap(Handle<v8::Value> obj) { |
| 4437 SetInternalField(index, External::New(value)); | 4410 #ifdef V8_ENABLE_CHECKS |
| 4411 return FullUnwrap(obj); |
| 4412 #else |
| 4413 return QuickUnwrap(obj); |
| 4414 #endif |
| 4438 } | 4415 } |
| 4439 | 4416 |
| 4440 | 4417 |
| 4441 void* Object::GetAlignedPointerFromInternalField(int index) { | 4418 void* External::QuickUnwrap(Handle<v8::Value> wrapper) { |
| 4442 #ifndef V8_ENABLE_CHECKS | |
| 4443 typedef internal::Object O; | 4419 typedef internal::Object O; |
| 4444 typedef internal::Internals I; | 4420 O* obj = *reinterpret_cast<O**>(const_cast<v8::Value*>(*wrapper)); |
| 4445 O* obj = *reinterpret_cast<O**>(this); | 4421 return internal::Internals::GetExternalPointer(obj); |
| 4446 // Fast path: If the object is a plain JSObject, which is the common case, we | |
| 4447 // know where to find the internal fields and can return the value directly. | |
| 4448 if (I::GetInstanceType(obj) == I::kJSObjectType) { | |
| 4449 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); | |
| 4450 return I::ReadField<void*>(obj, offset); | |
| 4451 } | |
| 4452 #endif | |
| 4453 return SlowGetAlignedPointerFromInternalField(index); | |
| 4454 } | 4422 } |
| 4455 | 4423 |
| 4456 | 4424 |
| 4425 void* Object::GetPointerFromInternalField(int index) { |
| 4426 typedef internal::Object O; |
| 4427 typedef internal::Internals I; |
| 4428 |
| 4429 O* obj = *reinterpret_cast<O**>(this); |
| 4430 |
| 4431 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
| 4432 // If the object is a plain JSObject, which is the common case, |
| 4433 // we know where to find the internal fields and can return the |
| 4434 // value directly. |
| 4435 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
| 4436 O* value = I::ReadField<O*>(obj, offset); |
| 4437 return I::GetExternalPointer(value); |
| 4438 } |
| 4439 |
| 4440 return SlowGetPointerFromInternalField(index); |
| 4441 } |
| 4442 |
| 4443 |
| 4457 String* String::Cast(v8::Value* value) { | 4444 String* String::Cast(v8::Value* value) { |
| 4458 #ifdef V8_ENABLE_CHECKS | 4445 #ifdef V8_ENABLE_CHECKS |
| 4459 CheckCast(value); | 4446 CheckCast(value); |
| 4460 #endif | 4447 #endif |
| 4461 return static_cast<String*>(value); | 4448 return static_cast<String*>(value); |
| 4462 } | 4449 } |
| 4463 | 4450 |
| 4464 | 4451 |
| 4465 Local<String> String::Empty(Isolate* isolate) { | 4452 Local<String> String::Empty(Isolate* isolate) { |
| 4466 typedef internal::Object* S; | 4453 typedef internal::Object* S; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4635 | 4622 |
| 4636 | 4623 |
| 4637 Function* Function::Cast(v8::Value* value) { | 4624 Function* Function::Cast(v8::Value* value) { |
| 4638 #ifdef V8_ENABLE_CHECKS | 4625 #ifdef V8_ENABLE_CHECKS |
| 4639 CheckCast(value); | 4626 CheckCast(value); |
| 4640 #endif | 4627 #endif |
| 4641 return static_cast<Function*>(value); | 4628 return static_cast<Function*>(value); |
| 4642 } | 4629 } |
| 4643 | 4630 |
| 4644 | 4631 |
| 4645 Local<Value> External::Wrap(void* value) { | |
| 4646 return External::New(value); | |
| 4647 } | |
| 4648 | |
| 4649 | |
| 4650 void* External::Unwrap(Handle<v8::Value> obj) { | |
| 4651 return External::Cast(*obj)->Value(); | |
| 4652 } | |
| 4653 | |
| 4654 | |
| 4655 External* External::Cast(v8::Value* value) { | 4632 External* External::Cast(v8::Value* value) { |
| 4656 #ifdef V8_ENABLE_CHECKS | 4633 #ifdef V8_ENABLE_CHECKS |
| 4657 CheckCast(value); | 4634 CheckCast(value); |
| 4658 #endif | 4635 #endif |
| 4659 return static_cast<External*>(value); | 4636 return static_cast<External*>(value); |
| 4660 } | 4637 } |
| 4661 | 4638 |
| 4662 | 4639 |
| 4663 Isolate* AccessorInfo::GetIsolate() const { | 4640 Isolate* AccessorInfo::GetIsolate() const { |
| 4664 return *reinterpret_cast<Isolate**>(&args_[-3]); | 4641 return *reinterpret_cast<Isolate**>(&args_[-3]); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4721 I::SetEmbedderData(this, data); | 4698 I::SetEmbedderData(this, data); |
| 4722 } | 4699 } |
| 4723 | 4700 |
| 4724 | 4701 |
| 4725 void* Isolate::GetData() { | 4702 void* Isolate::GetData() { |
| 4726 typedef internal::Internals I; | 4703 typedef internal::Internals I; |
| 4727 return I::GetEmbedderData(this); | 4704 return I::GetEmbedderData(this); |
| 4728 } | 4705 } |
| 4729 | 4706 |
| 4730 | 4707 |
| 4731 Local<Value> Context::GetData() { | |
| 4732 return GetEmbedderData(0); | |
| 4733 } | |
| 4734 | |
| 4735 void Context::SetData(Handle<Value> data) { | |
| 4736 SetEmbedderData(0, data); | |
| 4737 } | |
| 4738 | |
| 4739 | |
| 4740 Local<Value> Context::GetEmbedderData(int index) { | |
| 4741 #ifndef V8_ENABLE_CHECKS | |
| 4742 typedef internal::Object O; | |
| 4743 typedef internal::Internals I; | |
| 4744 O** result = HandleScope::CreateHandle(I::ReadEmbedderData<O*>(this, index)); | |
| 4745 return Local<Value>(reinterpret_cast<Value*>(result)); | |
| 4746 #else | |
| 4747 return SlowGetEmbedderData(index); | |
| 4748 #endif | |
| 4749 } | |
| 4750 | |
| 4751 | |
| 4752 void* Context::GetAlignedPointerFromEmbedderData(int index) { | |
| 4753 #ifndef V8_ENABLE_CHECKS | |
| 4754 typedef internal::Internals I; | |
| 4755 return I::ReadEmbedderData<void*>(this, index); | |
| 4756 #else | |
| 4757 return SlowGetAlignedPointerFromEmbedderData(index); | |
| 4758 #endif | |
| 4759 } | |
| 4760 | |
| 4761 | |
| 4762 /** | 4708 /** |
| 4763 * \example shell.cc | 4709 * \example shell.cc |
| 4764 * A simple shell that takes a list of expressions on the | 4710 * A simple shell that takes a list of expressions on the |
| 4765 * command-line and executes them. | 4711 * command-line and executes them. |
| 4766 */ | 4712 */ |
| 4767 | 4713 |
| 4768 | 4714 |
| 4769 /** | 4715 /** |
| 4770 * \example process.cc | 4716 * \example process.cc |
| 4771 */ | 4717 */ |
| 4772 | 4718 |
| 4773 | 4719 |
| 4774 } // namespace v8 | 4720 } // namespace v8 |
| 4775 | 4721 |
| 4776 | 4722 |
| 4777 #undef V8EXPORT | 4723 #undef V8EXPORT |
| 4778 #undef TYPE_CHECK | 4724 #undef TYPE_CHECK |
| 4779 | 4725 |
| 4780 | 4726 |
| 4781 #endif // V8_H_ | 4727 #endif // V8_H_ |
| OLD | NEW |