OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 2829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2840 RETURN_ON_FAILED_EXECUTION(String); | 2840 RETURN_ON_FAILED_EXECUTION(String); |
2841 Local<String> result; | 2841 Local<String> result; |
2842 has_pending_exception = | 2842 has_pending_exception = |
2843 !ToLocal<String>(i::Object::ToString(isolate, maybe), &result); | 2843 !ToLocal<String>(i::Object::ToString(isolate, maybe), &result); |
2844 RETURN_ON_FAILED_EXECUTION(String); | 2844 RETURN_ON_FAILED_EXECUTION(String); |
2845 RETURN_ESCAPED(result); | 2845 RETURN_ESCAPED(result); |
2846 } | 2846 } |
2847 | 2847 |
2848 // --- V a l u e S e r i a l i z a t i o n --- | 2848 // --- V a l u e S e r i a l i z a t i o n --- |
2849 | 2849 |
2850 Maybe<bool> ValueSerializer::Delegate::WriteHostObject(Local<Object> object) { | |
2851 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(Isolate::GetCurrent()); | |
Jakob Kummerow
2016/09/14 01:09:20
AFAIK Isolate::GetCurrent() is deprecated and new
jbroman
2016/09/14 14:58:43
OK, done. In practice the delegate will already ha
| |
2852 isolate->Throw(*isolate->factory()->NewError( | |
2853 isolate->error_function(), i::MessageTemplate::kDataCloneError, | |
2854 Utils::OpenHandle(*object))); | |
2855 return Nothing<bool>(); | |
2856 } | |
2857 | |
2850 struct ValueSerializer::PrivateData { | 2858 struct ValueSerializer::PrivateData { |
2851 explicit PrivateData(i::Isolate* i, ValueSerializer::Delegate* delegate) | 2859 explicit PrivateData(i::Isolate* i, ValueSerializer::Delegate* delegate) |
2852 : isolate(i), serializer(i, delegate) {} | 2860 : isolate(i), serializer(i, delegate) {} |
2853 i::Isolate* isolate; | 2861 i::Isolate* isolate; |
2854 i::ValueSerializer serializer; | 2862 i::ValueSerializer serializer; |
2855 }; | 2863 }; |
2856 | 2864 |
2857 ValueSerializer::ValueSerializer(Isolate* isolate) | 2865 ValueSerializer::ValueSerializer(Isolate* isolate) |
2858 : ValueSerializer(isolate, nullptr) {} | 2866 : ValueSerializer(isolate, nullptr) {} |
2859 | 2867 |
(...skipping 24 matching lines...) Expand all Loading... | |
2884 private_->serializer.TransferArrayBuffer(transfer_id, | 2892 private_->serializer.TransferArrayBuffer(transfer_id, |
2885 Utils::OpenHandle(*array_buffer)); | 2893 Utils::OpenHandle(*array_buffer)); |
2886 } | 2894 } |
2887 | 2895 |
2888 void ValueSerializer::TransferSharedArrayBuffer( | 2896 void ValueSerializer::TransferSharedArrayBuffer( |
2889 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { | 2897 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { |
2890 private_->serializer.TransferArrayBuffer( | 2898 private_->serializer.TransferArrayBuffer( |
2891 transfer_id, Utils::OpenHandle(*shared_array_buffer)); | 2899 transfer_id, Utils::OpenHandle(*shared_array_buffer)); |
2892 } | 2900 } |
2893 | 2901 |
2902 void ValueSerializer::WriteUint32(uint32_t value) { | |
2903 private_->serializer.WriteUint32(value); | |
2904 } | |
2905 | |
2906 void ValueSerializer::WriteUint64(uint64_t value) { | |
2907 private_->serializer.WriteUint64(value); | |
2908 } | |
2909 | |
2910 void ValueSerializer::WriteRawBytes(const void* source, size_t length) { | |
2911 private_->serializer.WriteRawBytes(source, length); | |
2912 } | |
2913 | |
2914 MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject() { | |
2915 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(Isolate::GetCurrent()); | |
Jakob Kummerow
2016/09/14 01:09:20
same here.
jbroman
2016/09/14 14:58:43
Done.
| |
2916 isolate->Throw(*isolate->factory()->NewError( | |
2917 isolate->error_function(), | |
2918 i::MessageTemplate::kDataCloneDeserializationError)); | |
2919 return MaybeLocal<Object>(); | |
2920 } | |
2921 | |
2894 struct ValueDeserializer::PrivateData { | 2922 struct ValueDeserializer::PrivateData { |
2895 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data) | 2923 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate) |
2896 : isolate(i), deserializer(i, data) {} | 2924 : isolate(i), deserializer(i, data, delegate) {} |
2897 i::Isolate* isolate; | 2925 i::Isolate* isolate; |
2898 i::ValueDeserializer deserializer; | 2926 i::ValueDeserializer deserializer; |
2899 bool has_aborted = false; | 2927 bool has_aborted = false; |
2900 bool supports_legacy_wire_format = false; | 2928 bool supports_legacy_wire_format = false; |
2901 }; | 2929 }; |
2902 | 2930 |
2903 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, | 2931 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, |
2904 size_t size) { | 2932 size_t size) |
2933 : ValueDeserializer(isolate, data, size, nullptr) {} | |
2934 | |
2935 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, | |
2936 size_t size, Delegate* delegate) { | |
2905 if (base::IsValueInRangeForNumericType<int>(size)) { | 2937 if (base::IsValueInRangeForNumericType<int>(size)) { |
2906 private_ = | 2938 private_ = new PrivateData( |
2907 new PrivateData(reinterpret_cast<i::Isolate*>(isolate), | 2939 reinterpret_cast<i::Isolate*>(isolate), |
2908 i::Vector<const uint8_t>(data, static_cast<int>(size))); | 2940 i::Vector<const uint8_t>(data, static_cast<int>(size)), delegate); |
2909 } else { | 2941 } else { |
2910 private_ = new PrivateData(reinterpret_cast<i::Isolate*>(isolate), | 2942 private_ = new PrivateData(reinterpret_cast<i::Isolate*>(isolate), |
2911 i::Vector<const uint8_t>(nullptr, 0)); | 2943 i::Vector<const uint8_t>(nullptr, 0), nullptr); |
2912 private_->has_aborted = true; | 2944 private_->has_aborted = true; |
2913 } | 2945 } |
2914 } | 2946 } |
2915 | 2947 |
2916 ValueDeserializer::~ValueDeserializer() { delete private_; } | 2948 ValueDeserializer::~ValueDeserializer() { delete private_; } |
2917 | 2949 |
2918 Maybe<bool> ValueDeserializer::ReadHeader(Local<Context> context) { | 2950 Maybe<bool> ValueDeserializer::ReadHeader(Local<Context> context) { |
2919 PREPARE_FOR_EXECUTION_PRIMITIVE(context, ValueDeserializer, ReadHeader, bool); | 2951 PREPARE_FOR_EXECUTION_PRIMITIVE(context, ValueDeserializer, ReadHeader, bool); |
2920 | 2952 |
2921 // We could have aborted during the constructor. | 2953 // We could have aborted during the constructor. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2983 Utils::OpenHandle(*array_buffer)); | 3015 Utils::OpenHandle(*array_buffer)); |
2984 } | 3016 } |
2985 | 3017 |
2986 void ValueDeserializer::TransferSharedArrayBuffer( | 3018 void ValueDeserializer::TransferSharedArrayBuffer( |
2987 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { | 3019 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { |
2988 CHECK(!private_->has_aborted); | 3020 CHECK(!private_->has_aborted); |
2989 private_->deserializer.TransferArrayBuffer( | 3021 private_->deserializer.TransferArrayBuffer( |
2990 transfer_id, Utils::OpenHandle(*shared_array_buffer)); | 3022 transfer_id, Utils::OpenHandle(*shared_array_buffer)); |
2991 } | 3023 } |
2992 | 3024 |
3025 bool ValueDeserializer::ReadUint32(uint32_t* value) { | |
3026 return private_->deserializer.ReadUint32(value); | |
3027 } | |
3028 | |
3029 bool ValueDeserializer::ReadUint64(uint64_t* value) { | |
3030 return private_->deserializer.ReadUint64(value); | |
3031 } | |
3032 | |
3033 bool ValueDeserializer::ReadRawBytes(size_t length, const void** data) { | |
3034 return private_->deserializer.ReadRawBytes(length, data); | |
3035 } | |
3036 | |
2993 // --- D a t a --- | 3037 // --- D a t a --- |
2994 | 3038 |
2995 bool Value::FullIsUndefined() const { | 3039 bool Value::FullIsUndefined() const { |
2996 i::Handle<i::Object> object = Utils::OpenHandle(this); | 3040 i::Handle<i::Object> object = Utils::OpenHandle(this); |
2997 bool result = false; | 3041 bool result = false; |
2998 if (!object->IsSmi()) { | 3042 if (!object->IsSmi()) { |
2999 result = object->IsUndefined(i::HeapObject::cast(*object)->GetIsolate()); | 3043 result = object->IsUndefined(i::HeapObject::cast(*object)->GetIsolate()); |
3000 } | 3044 } |
3001 DCHECK_EQ(result, QuickIsUndefined()); | 3045 DCHECK_EQ(result, QuickIsUndefined()); |
3002 return result; | 3046 return result; |
(...skipping 6233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9236 Address callback_address = | 9280 Address callback_address = |
9237 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9281 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9238 VMState<EXTERNAL> state(isolate); | 9282 VMState<EXTERNAL> state(isolate); |
9239 ExternalCallbackScope call_scope(isolate, callback_address); | 9283 ExternalCallbackScope call_scope(isolate, callback_address); |
9240 callback(info); | 9284 callback(info); |
9241 } | 9285 } |
9242 | 9286 |
9243 | 9287 |
9244 } // namespace internal | 9288 } // namespace internal |
9245 } // namespace v8 | 9289 } // namespace v8 |
OLD | NEW |