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 5694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5705 TYPE_CHECK(T, S); | 5705 TYPE_CHECK(T, S); |
5706 if (V8_UNLIKELY(handle.IsEmpty())) { | 5706 if (V8_UNLIKELY(handle.IsEmpty())) { |
5707 *value_ = GetDefaultValue(); | 5707 *value_ = GetDefaultValue(); |
5708 } else { | 5708 } else { |
5709 *value_ = *reinterpret_cast<internal::Object**>(*handle); | 5709 *value_ = *reinterpret_cast<internal::Object**>(*handle); |
5710 } | 5710 } |
5711 } | 5711 } |
5712 | 5712 |
5713 template<typename T> | 5713 template<typename T> |
5714 void ReturnValue<T>::Set(double i) { | 5714 void ReturnValue<T>::Set(double i) { |
| 5715 TYPE_CHECK(T, Number); |
5715 Set(Number::New(GetIsolate(), i)); | 5716 Set(Number::New(GetIsolate(), i)); |
5716 } | 5717 } |
5717 | 5718 |
5718 template<typename T> | 5719 template<typename T> |
5719 void ReturnValue<T>::Set(int32_t i) { | 5720 void ReturnValue<T>::Set(int32_t i) { |
| 5721 TYPE_CHECK(T, Integer); |
5720 typedef internal::Internals I; | 5722 typedef internal::Internals I; |
5721 if (V8_LIKELY(I::IsValidSmi(i))) { | 5723 if (V8_LIKELY(I::IsValidSmi(i))) { |
5722 *value_ = I::IntToSmi(i); | 5724 *value_ = I::IntToSmi(i); |
5723 return; | 5725 return; |
5724 } | 5726 } |
5725 Set(Integer::New(i, GetIsolate())); | 5727 Set(Integer::New(i, GetIsolate())); |
5726 } | 5728 } |
5727 | 5729 |
5728 template<typename T> | 5730 template<typename T> |
5729 void ReturnValue<T>::Set(uint32_t i) { | 5731 void ReturnValue<T>::Set(uint32_t i) { |
| 5732 TYPE_CHECK(T, Integer); |
5730 typedef internal::Internals I; | 5733 typedef internal::Internals I; |
5731 // Can't simply use INT32_MAX here for whatever reason. | 5734 // Can't simply use INT32_MAX here for whatever reason. |
5732 bool fits_into_int32_t = (i & (1 << 31)) == 0; | 5735 bool fits_into_int32_t = (i & (1 << 31)) == 0; |
5733 if (V8_LIKELY(fits_into_int32_t)) { | 5736 if (V8_LIKELY(fits_into_int32_t)) { |
5734 Set(static_cast<int32_t>(i)); | 5737 Set(static_cast<int32_t>(i)); |
5735 return; | 5738 return; |
5736 } | 5739 } |
5737 Set(Integer::NewFromUnsigned(i, GetIsolate())); | 5740 Set(Integer::NewFromUnsigned(i, GetIsolate())); |
5738 } | 5741 } |
5739 | 5742 |
5740 template<typename T> | 5743 template<typename T> |
5741 void ReturnValue<T>::Set(bool value) { | 5744 void ReturnValue<T>::Set(bool value) { |
| 5745 TYPE_CHECK(T, Boolean); |
5742 typedef internal::Internals I; | 5746 typedef internal::Internals I; |
5743 int root_index; | 5747 int root_index; |
5744 if (value) { | 5748 if (value) { |
5745 root_index = I::kTrueValueRootIndex; | 5749 root_index = I::kTrueValueRootIndex; |
5746 } else { | 5750 } else { |
5747 root_index = I::kFalseValueRootIndex; | 5751 root_index = I::kFalseValueRootIndex; |
5748 } | 5752 } |
5749 *value_ = *I::GetRoot(GetIsolate(), root_index); | 5753 *value_ = *I::GetRoot(GetIsolate(), root_index); |
5750 } | 5754 } |
5751 | 5755 |
5752 template<typename T> | 5756 template<typename T> |
5753 void ReturnValue<T>::SetNull() { | 5757 void ReturnValue<T>::SetNull() { |
| 5758 TYPE_CHECK(T, Primitive); |
5754 typedef internal::Internals I; | 5759 typedef internal::Internals I; |
5755 *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex); | 5760 *value_ = *I::GetRoot(GetIsolate(), I::kNullValueRootIndex); |
5756 } | 5761 } |
5757 | 5762 |
5758 template<typename T> | 5763 template<typename T> |
5759 void ReturnValue<T>::SetUndefined() { | 5764 void ReturnValue<T>::SetUndefined() { |
| 5765 TYPE_CHECK(T, Primitive); |
5760 typedef internal::Internals I; | 5766 typedef internal::Internals I; |
5761 *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); | 5767 *value_ = *I::GetRoot(GetIsolate(), I::kUndefinedValueRootIndex); |
5762 } | 5768 } |
5763 | 5769 |
5764 template<typename T> | 5770 template<typename T> |
5765 void ReturnValue<T>::SetEmptyString() { | 5771 void ReturnValue<T>::SetEmptyString() { |
| 5772 TYPE_CHECK(T, String); |
5766 typedef internal::Internals I; | 5773 typedef internal::Internals I; |
5767 *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex); | 5774 *value_ = *I::GetRoot(GetIsolate(), I::kEmptyStringRootIndex); |
5768 } | 5775 } |
5769 | 5776 |
5770 template<typename T> | 5777 template<typename T> |
5771 Isolate* ReturnValue<T>::GetIsolate() { | 5778 Isolate* ReturnValue<T>::GetIsolate() { |
5772 // Isolate is always the pointer below the default value on the stack. | 5779 // Isolate is always the pointer below the default value on the stack. |
5773 return *reinterpret_cast<Isolate**>(&value_[-2]); | 5780 return *reinterpret_cast<Isolate**>(&value_[-2]); |
5774 } | 5781 } |
5775 | 5782 |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6365 | 6372 |
6366 | 6373 |
6367 } // namespace v8 | 6374 } // namespace v8 |
6368 | 6375 |
6369 | 6376 |
6370 #undef V8EXPORT | 6377 #undef V8EXPORT |
6371 #undef TYPE_CHECK | 6378 #undef TYPE_CHECK |
6372 | 6379 |
6373 | 6380 |
6374 #endif // V8_H_ | 6381 #endif // V8_H_ |
OLD | NEW |