| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 class AccessorInfo; | 104 class AccessorInfo; |
| 105 class StackTrace; | 105 class StackTrace; |
| 106 class StackFrame; | 106 class StackFrame; |
| 107 | 107 |
| 108 namespace internal { | 108 namespace internal { |
| 109 | 109 |
| 110 class Arguments; | 110 class Arguments; |
| 111 class Object; | 111 class Object; |
| 112 class Heap; | 112 class Heap; |
| 113 class Top; | 113 class Top; |
| 114 | |
| 115 } | 114 } |
| 116 | 115 |
| 117 | 116 |
| 118 // --- W e a k H a n d l e s | 117 // --- W e a k H a n d l e s |
| 119 | 118 |
| 120 | 119 |
| 121 /** | 120 /** |
| 122 * A weak reference callback function. | 121 * A weak reference callback function. |
| 123 * | 122 * |
| 124 * This callback should either explicitly invoke Dispose on |object| if | 123 * This callback should either explicitly invoke Dispose on |object| if |
| (...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 /** | 1031 /** |
| 1033 * Returns true if the string is external | 1032 * Returns true if the string is external |
| 1034 */ | 1033 */ |
| 1035 V8EXPORT bool IsExternal() const; | 1034 V8EXPORT bool IsExternal() const; |
| 1036 | 1035 |
| 1037 /** | 1036 /** |
| 1038 * Returns true if the string is both external and ascii | 1037 * Returns true if the string is both external and ascii |
| 1039 */ | 1038 */ |
| 1040 V8EXPORT bool IsExternalAscii() const; | 1039 V8EXPORT bool IsExternalAscii() const; |
| 1041 | 1040 |
| 1042 class V8EXPORT ExternalStringResourceBase { | 1041 class V8EXPORT ExternalStringResourceBase { // NOLINT |
| 1043 public: | 1042 public: |
| 1044 virtual ~ExternalStringResourceBase() {} | 1043 virtual ~ExternalStringResourceBase() {} |
| 1045 | 1044 |
| 1046 protected: | 1045 protected: |
| 1047 ExternalStringResourceBase() {} | 1046 ExternalStringResourceBase() {} |
| 1048 | 1047 |
| 1049 /** | 1048 /** |
| 1050 * Internally V8 will call this Dispose method when the external string | 1049 * Internally V8 will call this Dispose method when the external string |
| 1051 * resource is no longer needed. The default implementation will use the | 1050 * resource is no longer needed. The default implementation will use the |
| 1052 * delete operator. This method can be overridden in subclasses to | 1051 * delete operator. This method can be overridden in subclasses to |
| (...skipping 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3237 | 3236 |
| 3238 // Disallow copying and assigning. | 3237 // Disallow copying and assigning. |
| 3239 Locker(const Locker&); | 3238 Locker(const Locker&); |
| 3240 void operator=(const Locker&); | 3239 void operator=(const Locker&); |
| 3241 }; | 3240 }; |
| 3242 | 3241 |
| 3243 | 3242 |
| 3244 /** | 3243 /** |
| 3245 * An interface for exporting data from V8, using "push" model. | 3244 * An interface for exporting data from V8, using "push" model. |
| 3246 */ | 3245 */ |
| 3247 class V8EXPORT OutputStream { | 3246 class V8EXPORT OutputStream { // NOLINT |
| 3248 public: | 3247 public: |
| 3249 enum OutputEncoding { | 3248 enum OutputEncoding { |
| 3250 kAscii = 0 // 7-bit ASCII. | 3249 kAscii = 0 // 7-bit ASCII. |
| 3251 }; | 3250 }; |
| 3252 enum WriteResult { | 3251 enum WriteResult { |
| 3253 kContinue = 0, | 3252 kContinue = 0, |
| 3254 kAbort = 1 | 3253 kAbort = 1 |
| 3255 }; | 3254 }; |
| 3256 virtual ~OutputStream() {} | 3255 virtual ~OutputStream() {} |
| 3257 /** Notify about the end of stream. */ | 3256 /** Notify about the end of stream. */ |
| 3258 virtual void EndOfStream() = 0; | 3257 virtual void EndOfStream() = 0; |
| 3259 /** Get preferred output chunk size. Called only once. */ | 3258 /** Get preferred output chunk size. Called only once. */ |
| 3260 virtual int GetChunkSize() { return 1024; } | 3259 virtual int GetChunkSize() { return 1024; } |
| 3261 /** Get preferred output encoding. Called only once. */ | 3260 /** Get preferred output encoding. Called only once. */ |
| 3262 virtual OutputEncoding GetOutputEncoding() { return kAscii; } | 3261 virtual OutputEncoding GetOutputEncoding() { return kAscii; } |
| 3263 /** | 3262 /** |
| 3264 * Writes the next chunk of snapshot data into the stream. Writing | 3263 * Writes the next chunk of snapshot data into the stream. Writing |
| 3265 * can be stopped by returning kAbort as function result. EndOfStream | 3264 * can be stopped by returning kAbort as function result. EndOfStream |
| 3266 * will not be called in case writing was aborted. | 3265 * will not be called in case writing was aborted. |
| 3267 */ | 3266 */ |
| 3268 virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; | 3267 virtual WriteResult WriteAsciiChunk(char* data, int size) = 0; |
| 3269 }; | 3268 }; |
| 3270 | 3269 |
| 3271 | 3270 |
| 3272 | 3271 |
| 3273 // --- I m p l e m e n t a t i o n --- | 3272 // --- I m p l e m e n t a t i o n --- |
| 3274 | 3273 |
| 3275 | 3274 |
| 3276 namespace internal { | 3275 namespace internal { |
| 3277 | 3276 |
| 3277 const int kPointerSize = sizeof(void*); // NOLINT |
| 3278 const int kIntSize = sizeof(int); // NOLINT |
| 3278 | 3279 |
| 3279 // Tag information for HeapObject. | 3280 // Tag information for HeapObject. |
| 3280 const int kHeapObjectTag = 1; | 3281 const int kHeapObjectTag = 1; |
| 3281 const int kHeapObjectTagSize = 2; | 3282 const int kHeapObjectTagSize = 2; |
| 3282 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; | 3283 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 3283 | 3284 |
| 3284 // Tag information for Smi. | 3285 // Tag information for Smi. |
| 3285 const int kSmiTag = 0; | 3286 const int kSmiTag = 0; |
| 3286 const int kSmiTagSize = 1; | 3287 const int kSmiTagSize = 1; |
| 3287 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; | 3288 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3303 template <> struct SmiConstants<8> { | 3304 template <> struct SmiConstants<8> { |
| 3304 static const int kSmiShiftSize = 31; | 3305 static const int kSmiShiftSize = 31; |
| 3305 static const int kSmiValueSize = 32; | 3306 static const int kSmiValueSize = 32; |
| 3306 static inline int SmiToInt(internal::Object* value) { | 3307 static inline int SmiToInt(internal::Object* value) { |
| 3307 int shift_bits = kSmiTagSize + kSmiShiftSize; | 3308 int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 3308 // Shift down and throw away top 32 bits. | 3309 // Shift down and throw away top 32 bits. |
| 3309 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 3310 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 3310 } | 3311 } |
| 3311 }; | 3312 }; |
| 3312 | 3313 |
| 3313 const int kSmiShiftSize = SmiConstants<sizeof(void*)>::kSmiShiftSize; | 3314 const int kSmiShiftSize = SmiConstants<kPointerSize>::kSmiShiftSize; |
| 3314 const int kSmiValueSize = SmiConstants<sizeof(void*)>::kSmiValueSize; | 3315 const int kSmiValueSize = SmiConstants<kPointerSize>::kSmiValueSize; |
| 3315 | 3316 |
| 3316 template <size_t ptr_size> struct InternalConstants; | 3317 template <size_t ptr_size> struct InternalConstants; |
| 3317 | 3318 |
| 3318 // Internal constants for 32-bit systems. | 3319 // Internal constants for 32-bit systems. |
| 3319 template <> struct InternalConstants<4> { | 3320 template <> struct InternalConstants<4> { |
| 3320 static const int kStringResourceOffset = 3 * sizeof(void*); | 3321 static const int kStringResourceOffset = 3 * kPointerSize; |
| 3321 }; | 3322 }; |
| 3322 | 3323 |
| 3323 // Internal constants for 64-bit systems. | 3324 // Internal constants for 64-bit systems. |
| 3324 template <> struct InternalConstants<8> { | 3325 template <> struct InternalConstants<8> { |
| 3325 static const int kStringResourceOffset = 3 * sizeof(void*); | 3326 static const int kStringResourceOffset = 3 * kPointerSize; |
| 3326 }; | 3327 }; |
| 3327 | 3328 |
| 3328 /** | 3329 /** |
| 3329 * This class exports constants and functionality from within v8 that | 3330 * This class exports constants and functionality from within v8 that |
| 3330 * is necessary to implement inline functions in the v8 api. Don't | 3331 * is necessary to implement inline functions in the v8 api. Don't |
| 3331 * depend on functions and constants defined here. | 3332 * depend on functions and constants defined here. |
| 3332 */ | 3333 */ |
| 3333 class Internals { | 3334 class Internals { |
| 3334 public: | 3335 public: |
| 3335 | 3336 |
| 3336 // These values match non-compiler-dependent values defined within | 3337 // These values match non-compiler-dependent values defined within |
| 3337 // the implementation of v8. | 3338 // the implementation of v8. |
| 3338 static const int kHeapObjectMapOffset = 0; | 3339 static const int kHeapObjectMapOffset = 0; |
| 3339 static const int kMapInstanceTypeOffset = sizeof(void*) + sizeof(int); | 3340 static const int kMapInstanceTypeOffset = kPointerSize + kIntSize; |
| 3340 static const int kStringResourceOffset = | 3341 static const int kStringResourceOffset = |
| 3341 InternalConstants<sizeof(void*)>::kStringResourceOffset; | 3342 InternalConstants<kPointerSize>::kStringResourceOffset; |
| 3342 | 3343 |
| 3343 static const int kProxyProxyOffset = sizeof(void*); | 3344 static const int kProxyProxyOffset = kPointerSize; |
| 3344 static const int kJSObjectHeaderSize = 3 * sizeof(void*); | 3345 static const int kJSObjectHeaderSize = 3 * kPointerSize; |
| 3345 static const int kFullStringRepresentationMask = 0x07; | 3346 static const int kFullStringRepresentationMask = 0x07; |
| 3346 static const int kExternalTwoByteRepresentationTag = 0x02; | 3347 static const int kExternalTwoByteRepresentationTag = 0x02; |
| 3347 | 3348 |
| 3348 static const int kJSObjectType = 0x9f; | 3349 static const int kJSObjectType = 0x9f; |
| 3349 static const int kFirstNonstringType = 0x80; | 3350 static const int kFirstNonstringType = 0x80; |
| 3350 static const int kProxyType = 0x85; | 3351 static const int kProxyType = 0x85; |
| 3351 | 3352 |
| 3352 static inline bool HasHeapObjectTag(internal::Object* value) { | 3353 static inline bool HasHeapObjectTag(internal::Object* value) { |
| 3353 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 3354 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 3354 kHeapObjectTag); | 3355 kHeapObjectTag); |
| 3355 } | 3356 } |
| 3356 | 3357 |
| 3357 static inline bool HasSmiTag(internal::Object* value) { | 3358 static inline bool HasSmiTag(internal::Object* value) { |
| 3358 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); | 3359 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
| 3359 } | 3360 } |
| 3360 | 3361 |
| 3361 static inline int SmiValue(internal::Object* value) { | 3362 static inline int SmiValue(internal::Object* value) { |
| 3362 return SmiConstants<sizeof(void*)>::SmiToInt(value); | 3363 return SmiConstants<kPointerSize>::SmiToInt(value); |
| 3363 } | 3364 } |
| 3364 | 3365 |
| 3365 static inline int GetInstanceType(internal::Object* obj) { | 3366 static inline int GetInstanceType(internal::Object* obj) { |
| 3366 typedef internal::Object O; | 3367 typedef internal::Object O; |
| 3367 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 3368 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 3368 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 3369 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 3369 } | 3370 } |
| 3370 | 3371 |
| 3371 static inline void* GetExternalPointer(internal::Object* obj) { | 3372 static inline void* GetExternalPointer(internal::Object* obj) { |
| 3372 if (HasSmiTag(obj)) { | 3373 if (HasSmiTag(obj)) { |
| 3373 return obj; | 3374 return obj; |
| 3374 } else if (GetInstanceType(obj) == kProxyType) { | 3375 } else if (GetInstanceType(obj) == kProxyType) { |
| 3375 return ReadField<void*>(obj, kProxyProxyOffset); | 3376 return ReadField<void*>(obj, kProxyProxyOffset); |
| 3376 } else { | 3377 } else { |
| 3377 return NULL; | 3378 return NULL; |
| 3378 } | 3379 } |
| 3379 } | 3380 } |
| 3380 | 3381 |
| 3381 static inline bool IsExternalTwoByteString(int instance_type) { | 3382 static inline bool IsExternalTwoByteString(int instance_type) { |
| 3382 int representation = (instance_type & kFullStringRepresentationMask); | 3383 int representation = (instance_type & kFullStringRepresentationMask); |
| 3383 return representation == kExternalTwoByteRepresentationTag; | 3384 return representation == kExternalTwoByteRepresentationTag; |
| 3384 } | 3385 } |
| 3385 | 3386 |
| 3386 template <typename T> | 3387 template <typename T> |
| 3387 static inline T ReadField(Object* ptr, int offset) { | 3388 static inline T ReadField(Object* ptr, int offset) { |
| 3388 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; | 3389 uint8_t* addr = reinterpret_cast<uint8_t*>(ptr) + offset - kHeapObjectTag; |
| 3389 return *reinterpret_cast<T*>(addr); | 3390 return *reinterpret_cast<T*>(addr); |
| 3390 } | 3391 } |
| 3391 | |
| 3392 }; | 3392 }; |
| 3393 | 3393 |
| 3394 } | 3394 } // namespace internal |
| 3395 | 3395 |
| 3396 | 3396 |
| 3397 template <class T> | 3397 template <class T> |
| 3398 Handle<T>::Handle() : val_(0) { } | 3398 Handle<T>::Handle() : val_(0) { } |
| 3399 | 3399 |
| 3400 | 3400 |
| 3401 template <class T> | 3401 template <class T> |
| 3402 Local<T>::Local() : Handle<T>() { } | 3402 Local<T>::Local() : Handle<T>() { } |
| 3403 | 3403 |
| 3404 | 3404 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3544 | 3544 |
| 3545 | 3545 |
| 3546 Local<Value> Object::UncheckedGetInternalField(int index) { | 3546 Local<Value> Object::UncheckedGetInternalField(int index) { |
| 3547 typedef internal::Object O; | 3547 typedef internal::Object O; |
| 3548 typedef internal::Internals I; | 3548 typedef internal::Internals I; |
| 3549 O* obj = *reinterpret_cast<O**>(this); | 3549 O* obj = *reinterpret_cast<O**>(this); |
| 3550 if (I::GetInstanceType(obj) == I::kJSObjectType) { | 3550 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
| 3551 // If the object is a plain JSObject, which is the common case, | 3551 // If the object is a plain JSObject, which is the common case, |
| 3552 // we know where to find the internal fields and can return the | 3552 // we know where to find the internal fields and can return the |
| 3553 // value directly. | 3553 // value directly. |
| 3554 int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index); | 3554 int offset = I::kJSObjectHeaderSize + (internal::kPointerSize * index); |
| 3555 O* value = I::ReadField<O*>(obj, offset); | 3555 O* value = I::ReadField<O*>(obj, offset); |
| 3556 O** result = HandleScope::CreateHandle(value); | 3556 O** result = HandleScope::CreateHandle(value); |
| 3557 return Local<Value>(reinterpret_cast<Value*>(result)); | 3557 return Local<Value>(reinterpret_cast<Value*>(result)); |
| 3558 } else { | 3558 } else { |
| 3559 return Local<Value>(); | 3559 return Local<Value>(); |
| 3560 } | 3560 } |
| 3561 } | 3561 } |
| 3562 | 3562 |
| 3563 | 3563 |
| 3564 void* External::Unwrap(Handle<v8::Value> obj) { | 3564 void* External::Unwrap(Handle<v8::Value> obj) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3580 void* Object::GetPointerFromInternalField(int index) { | 3580 void* Object::GetPointerFromInternalField(int index) { |
| 3581 typedef internal::Object O; | 3581 typedef internal::Object O; |
| 3582 typedef internal::Internals I; | 3582 typedef internal::Internals I; |
| 3583 | 3583 |
| 3584 O* obj = *reinterpret_cast<O**>(this); | 3584 O* obj = *reinterpret_cast<O**>(this); |
| 3585 | 3585 |
| 3586 if (I::GetInstanceType(obj) == I::kJSObjectType) { | 3586 if (I::GetInstanceType(obj) == I::kJSObjectType) { |
| 3587 // If the object is a plain JSObject, which is the common case, | 3587 // If the object is a plain JSObject, which is the common case, |
| 3588 // we know where to find the internal fields and can return the | 3588 // we know where to find the internal fields and can return the |
| 3589 // value directly. | 3589 // value directly. |
| 3590 int offset = I::kJSObjectHeaderSize + (sizeof(void*) * index); | 3590 int offset = I::kJSObjectHeaderSize + (internal::kPointerSize * index); |
| 3591 O* value = I::ReadField<O*>(obj, offset); | 3591 O* value = I::ReadField<O*>(obj, offset); |
| 3592 return I::GetExternalPointer(value); | 3592 return I::GetExternalPointer(value); |
| 3593 } | 3593 } |
| 3594 | 3594 |
| 3595 return SlowGetPointerFromInternalField(index); | 3595 return SlowGetPointerFromInternalField(index); |
| 3596 } | 3596 } |
| 3597 | 3597 |
| 3598 | 3598 |
| 3599 String* String::Cast(v8::Value* value) { | 3599 String* String::Cast(v8::Value* value) { |
| 3600 #ifdef V8_ENABLE_CHECKS | 3600 #ifdef V8_ENABLE_CHECKS |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3731 | 3731 |
| 3732 | 3732 |
| 3733 } // namespace v8 | 3733 } // namespace v8 |
| 3734 | 3734 |
| 3735 | 3735 |
| 3736 #undef V8EXPORT | 3736 #undef V8EXPORT |
| 3737 #undef TYPE_CHECK | 3737 #undef TYPE_CHECK |
| 3738 | 3738 |
| 3739 | 3739 |
| 3740 #endif // V8_H_ | 3740 #endif // V8_H_ |
| OLD | NEW |