Index: include/v8.h |
diff --git a/include/v8.h b/include/v8.h |
index 430f410a6eaf61c4a71e80d3227278ee5c594490..e4fffadc81b6c29e44d7801eaefc14535bdce35f 100644 |
--- a/include/v8.h |
+++ b/include/v8.h |
@@ -2561,6 +2561,11 @@ Handle<Primitive> V8EXPORT Null(); |
Handle<Boolean> V8EXPORT True(); |
Handle<Boolean> V8EXPORT False(); |
+inline Handle<Primitive> Undefined(Isolate* isolate); |
+inline Handle<Primitive> Null(Isolate* isolate); |
+inline Handle<Boolean> True(Isolate* isolate); |
+inline Handle<Boolean> False(Isolate* isolate); |
+ |
/** |
* A set of constraints that specifies the limits of the runtime's memory use. |
@@ -3872,18 +3877,6 @@ const uintptr_t kEncodablePointerMask = |
PlatformSmiTagging::kEncodablePointerMask; |
const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; |
-template <size_t ptr_size> struct InternalConstants; |
- |
-// Internal constants for 32-bit systems. |
-template <> struct InternalConstants<4> { |
- static const int kStringResourceOffset = 3 * kApiPointerSize; |
-}; |
- |
-// Internal constants for 64-bit systems. |
-template <> struct InternalConstants<8> { |
- static const int kStringResourceOffset = 3 * kApiPointerSize; |
-}; |
- |
/** |
* This class exports constants and functionality from within v8 that |
* is necessary to implement inline functions in the v8 api. Don't |
@@ -3895,8 +3888,7 @@ class Internals { |
// the implementation of v8. |
static const int kHeapObjectMapOffset = 0; |
static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; |
- static const int kStringResourceOffset = |
- InternalConstants<kApiPointerSize>::kStringResourceOffset; |
+ static const int kStringResourceOffset = 3 * kApiPointerSize; |
static const int kOddballKindOffset = 3 * kApiPointerSize; |
static const int kForeignAddressOffset = kApiPointerSize; |
@@ -3904,6 +3896,14 @@ class Internals { |
static const int kFullStringRepresentationMask = 0x07; |
static const int kExternalTwoByteRepresentationTag = 0x02; |
+ static const int kIsolateStateOffset = 0; |
+ static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
+ static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
+ static const int kUndefinedValueRootIndex = 5; |
+ static const int kNullValueRootIndex = 7; |
+ static const int kTrueValueRootIndex = 8; |
+ static const int kFalseValueRootIndex = 9; |
+ |
static const int kJSObjectType = 0xaa; |
static const int kFirstNonstringType = 0x80; |
static const int kOddballType = 0x82; |
@@ -3956,6 +3956,16 @@ class Internals { |
return representation == kExternalTwoByteRepresentationTag; |
} |
+ static inline bool IsInitialized(v8::Isolate* isolate) { |
+ uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateStateOffset; |
+ return *reinterpret_cast<int*>(addr) == 1; |
+ } |
+ |
+ static inline internal::Object** GetRoot(v8::Isolate* isolate, int index) { |
+ uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
+ return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
+ } |
+ |
template <typename T> |
static inline T ReadField(Object* ptr, int offset) { |
uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
@@ -4378,6 +4388,42 @@ Local<Object> AccessorInfo::Holder() const { |
} |
+Handle<Primitive> Undefined(Isolate* isolate) { |
+ typedef internal::Object* S; |
+ typedef internal::Internals I; |
+ if (!I::IsInitialized(isolate)) return Undefined(); |
+ S* slot = I::GetRoot(isolate, I::kUndefinedValueRootIndex); |
+ return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
+} |
+ |
+ |
+Handle<Primitive> Null(Isolate* isolate) { |
+ typedef internal::Object* S; |
+ typedef internal::Internals I; |
+ if (!I::IsInitialized(isolate)) return Null(); |
+ S* slot = I::GetRoot(isolate, I::kNullValueRootIndex); |
+ return Handle<Primitive>(reinterpret_cast<Primitive*>(slot)); |
+} |
+ |
+ |
+Handle<Boolean> True(Isolate* isolate) { |
+ typedef internal::Object* S; |
+ typedef internal::Internals I; |
+ if (!I::IsInitialized(isolate)) return True(); |
+ S* slot = I::GetRoot(isolate, I::kTrueValueRootIndex); |
+ return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
+} |
+ |
+ |
+Handle<Boolean> False(Isolate* isolate) { |
+ typedef internal::Object* S; |
+ typedef internal::Internals I; |
+ if (!I::IsInitialized(isolate)) return False(); |
+ S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); |
+ return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
+} |
+ |
+ |
/** |
* \example shell.cc |
* A simple shell that takes a list of expressions on the |