OLD | NEW |
---|---|
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 3264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3275 virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; | 3275 virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; |
3276 }; | 3276 }; |
3277 | 3277 |
3278 | 3278 |
3279 | 3279 |
3280 // --- I m p l e m e n t a t i o n --- | 3280 // --- I m p l e m e n t a t i o n --- |
3281 | 3281 |
3282 | 3282 |
3283 namespace internal { | 3283 namespace internal { |
3284 | 3284 |
3285 const int kPointerSize = sizeof(void*); // NOLINT | 3285 static const int kApiPointerSize = sizeof(void*); // NOLINT |
3286 const int kIntSize = sizeof(int); // NOLINT | 3286 static const int kApiIntSize = sizeof(int); // NOLINT |
Lasse Reichstein
2010/11/15 12:32:55
Renamed to avoid collision with kPointerSize and k
| |
3287 | 3287 |
3288 // Tag information for HeapObject. | 3288 // Tag information for HeapObject. |
3289 const int kHeapObjectTag = 1; | 3289 const int kHeapObjectTag = 1; |
3290 const int kHeapObjectTagSize = 2; | 3290 const int kHeapObjectTagSize = 2; |
3291 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; | 3291 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
3292 | 3292 |
3293 // Tag information for Smi. | 3293 // Tag information for Smi. |
3294 const int kSmiTag = 0; | 3294 const int kSmiTag = 0; |
3295 const int kSmiTagSize = 1; | 3295 const int kSmiTagSize = 1; |
3296 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; | 3296 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
(...skipping 15 matching lines...) Expand all Loading... | |
3312 template <> struct SmiConstants<8> { | 3312 template <> struct SmiConstants<8> { |
3313 static const int kSmiShiftSize = 31; | 3313 static const int kSmiShiftSize = 31; |
3314 static const int kSmiValueSize = 32; | 3314 static const int kSmiValueSize = 32; |
3315 static inline int SmiToInt(internal::Object* value) { | 3315 static inline int SmiToInt(internal::Object* value) { |
3316 int shift_bits = kSmiTagSize + kSmiShiftSize; | 3316 int shift_bits = kSmiTagSize + kSmiShiftSize; |
3317 // Shift down and throw away top 32 bits. | 3317 // Shift down and throw away top 32 bits. |
3318 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 3318 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
3319 } | 3319 } |
3320 }; | 3320 }; |
3321 | 3321 |
3322 const int kSmiShiftSize = SmiConstants<kPointerSize>::kSmiShiftSize; | 3322 const int kSmiShiftSize = SmiConstants<kApiPointerSize>::kSmiShiftSize; |
3323 const int kSmiValueSize = SmiConstants<kPointerSize>::kSmiValueSize; | 3323 const int kSmiValueSize = SmiConstants<kApiPointerSize>::kSmiValueSize; |
3324 | 3324 |
3325 template <size_t ptr_size> struct InternalConstants; | 3325 template <size_t ptr_size> struct InternalConstants; |
3326 | 3326 |
3327 // Internal constants for 32-bit systems. | 3327 // Internal constants for 32-bit systems. |
3328 template <> struct InternalConstants<4> { | 3328 template <> struct InternalConstants<4> { |
3329 static const int kStringResourceOffset = 3 * kPointerSize; | 3329 static const int kStringResourceOffset = 3 * kApiPointerSize; |
3330 }; | 3330 }; |
3331 | 3331 |
3332 // Internal constants for 64-bit systems. | 3332 // Internal constants for 64-bit systems. |
3333 template <> struct InternalConstants<8> { | 3333 template <> struct InternalConstants<8> { |
3334 static const int kStringResourceOffset = 3 * kPointerSize; | 3334 static const int kStringResourceOffset = 3 * kApiPointerSize; |
3335 }; | 3335 }; |
3336 | 3336 |
3337 /** | 3337 /** |
3338 * This class exports constants and functionality from within v8 that | 3338 * This class exports constants and functionality from within v8 that |
3339 * is necessary to implement inline functions in the v8 api. Don't | 3339 * is necessary to implement inline functions in the v8 api. Don't |
3340 * depend on functions and constants defined here. | 3340 * depend on functions and constants defined here. |
3341 */ | 3341 */ |
3342 class Internals { | 3342 class Internals { |
3343 public: | 3343 public: |
3344 | 3344 |
3345 // These values match non-compiler-dependent values defined within | 3345 // These values match non-compiler-dependent values defined within |
3346 // the implementation of v8. | 3346 // the implementation of v8. |
3347 static const int kHeapObjectMapOffset = 0; | 3347 static const int kHeapObjectMapOffset = 0; |
3348 static const int kMapInstanceTypeOffset = kPointerSize + kIntSize; | 3348 static const int kMapInstanceTypeOffset = kApiPointerSize + kApiIntSize; |
3349 static const int kStringResourceOffset = | 3349 static const int kStringResourceOffset = |
3350 InternalConstants<kPointerSize>::kStringResourceOffset; | 3350 InternalConstants<kApiPointerSize>::kStringResourceOffset; |
3351 | 3351 |
3352 static const int kProxyProxyOffset = kPointerSize; | 3352 static const int kProxyProxyOffset = kApiPointerSize; |
3353 static const int kJSObjectHeaderSize = 3 * kPointerSize; | 3353 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
3354 static const int kFullStringRepresentationMask = 0x07; | 3354 static const int kFullStringRepresentationMask = 0x07; |
3355 static const int kExternalTwoByteRepresentationTag = 0x02; | 3355 static const int kExternalTwoByteRepresentationTag = 0x02; |
3356 | 3356 |
3357 static const int kJSObjectType = 0x9f; | 3357 static const int kJSObjectType = 0x9f; |
3358 static const int kFirstNonstringType = 0x80; | 3358 static const int kFirstNonstringType = 0x80; |
3359 static const int kProxyType = 0x85; | 3359 static const int kProxyType = 0x85; |
3360 | 3360 |
3361 static inline bool HasHeapObjectTag(internal::Object* value) { | 3361 static inline bool HasHeapObjectTag(internal::Object* value) { |
3362 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 3362 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
3363 kHeapObjectTag); | 3363 kHeapObjectTag); |
3364 } | 3364 } |
3365 | 3365 |
3366 static inline bool HasSmiTag(internal::Object* value) { | 3366 static inline bool HasSmiTag(internal::Object* value) { |
3367 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); | 3367 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
3368 } | 3368 } |
3369 | 3369 |
3370 static inline int SmiValue(internal::Object* value) { | 3370 static inline int SmiValue(internal::Object* value) { |
3371 return SmiConstants<kPointerSize>::SmiToInt(value); | 3371 return SmiConstants<kApiPointerSize>::SmiToInt(value); |
3372 } | 3372 } |
3373 | 3373 |
3374 static inline int GetInstanceType(internal::Object* obj) { | 3374 static inline int GetInstanceType(internal::Object* obj) { |
3375 typedef internal::Object O; | 3375 typedef internal::Object O; |
3376 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 3376 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
3377 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 3377 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
3378 } | 3378 } |
3379 | 3379 |
3380 static inline void* GetExternalPointer(internal::Object* obj) { | 3380 static inline void* GetExternalPointer(internal::Object* obj) { |
3381 if (HasSmiTag(obj)) { | 3381 if (HasSmiTag(obj)) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3552 | 3552 |
3553 | 3553 |
3554 Local<Value> Object::UncheckedGetInternalField(int index) { | 3554 Local<Value> Object::UncheckedGetInternalField(int index) { |
3555 typedef internal::Object O; | 3555 typedef internal::Object O; |
3556 typedef internal::Internals I; | 3556 typedef internal::Internals I; |
3557 O* obj = *reinterpret_cast<O**>(this); | 3557 O* obj = *reinterpret_cast<O**>(this); |
3558 if (I::GetInstanceType(obj) == I::kJSObjectType) { | 3558 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
3559 // If the object is a plain JSObject, which is the common case, | 3559 // If the object is a plain JSObject, which is the common case, |
3560 // we know where to find the internal fields and can return the | 3560 // we know where to find the internal fields and can return the |
3561 // value directly. | 3561 // value directly. |
3562 int offset = I::kJSObjectHeaderSize + (internal::kPointerSize * index); | 3562 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
3563 O* value = I::ReadField<O*>(obj, offset); | 3563 O* value = I::ReadField<O*>(obj, offset); |
3564 O** result = HandleScope::CreateHandle(value); | 3564 O** result = HandleScope::CreateHandle(value); |
3565 return Local<Value>(reinterpret_cast<Value*>(result)); | 3565 return Local<Value>(reinterpret_cast<Value*>(result)); |
3566 } else { | 3566 } else { |
3567 return Local<Value>(); | 3567 return Local<Value>(); |
3568 } | 3568 } |
3569 } | 3569 } |
3570 | 3570 |
3571 | 3571 |
3572 void* External::Unwrap(Handle<v8::Value> obj) { | 3572 void* External::Unwrap(Handle<v8::Value> obj) { |
(...skipping 15 matching lines...) Expand all Loading... | |
3588 void* Object::GetPointerFromInternalField(int index) { | 3588 void* Object::GetPointerFromInternalField(int index) { |
3589 typedef internal::Object O; | 3589 typedef internal::Object O; |
3590 typedef internal::Internals I; | 3590 typedef internal::Internals I; |
3591 | 3591 |
3592 O* obj = *reinterpret_cast<O**>(this); | 3592 O* obj = *reinterpret_cast<O**>(this); |
3593 | 3593 |
3594 if (I::GetInstanceType(obj) == I::kJSObjectType) { | 3594 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
3595 // If the object is a plain JSObject, which is the common case, | 3595 // If the object is a plain JSObject, which is the common case, |
3596 // we know where to find the internal fields and can return the | 3596 // we know where to find the internal fields and can return the |
3597 // value directly. | 3597 // value directly. |
3598 int offset = I::kJSObjectHeaderSize + (internal::kPointerSize * index); | 3598 int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); |
3599 O* value = I::ReadField<O*>(obj, offset); | 3599 O* value = I::ReadField<O*>(obj, offset); |
3600 return I::GetExternalPointer(value); | 3600 return I::GetExternalPointer(value); |
3601 } | 3601 } |
3602 | 3602 |
3603 return SlowGetPointerFromInternalField(index); | 3603 return SlowGetPointerFromInternalField(index); |
3604 } | 3604 } |
3605 | 3605 |
3606 | 3606 |
3607 String* String::Cast(v8::Value* value) { | 3607 String* String::Cast(v8::Value* value) { |
3608 #ifdef V8_ENABLE_CHECKS | 3608 #ifdef V8_ENABLE_CHECKS |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3739 | 3739 |
3740 | 3740 |
3741 } // namespace v8 | 3741 } // namespace v8 |
3742 | 3742 |
3743 | 3743 |
3744 #undef V8EXPORT | 3744 #undef V8EXPORT |
3745 #undef TYPE_CHECK | 3745 #undef TYPE_CHECK |
3746 | 3746 |
3747 | 3747 |
3748 #endif // V8_H_ | 3748 #endif // V8_H_ |
OLD | NEW |