| 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 2840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2851 | 2851 |
| 2852 ValueSerializer::~ValueSerializer() { delete private_; } | 2852 ValueSerializer::~ValueSerializer() { delete private_; } |
| 2853 | 2853 |
| 2854 void ValueSerializer::WriteHeader() { private_->serializer.WriteHeader(); } | 2854 void ValueSerializer::WriteHeader() { private_->serializer.WriteHeader(); } |
| 2855 | 2855 |
| 2856 Maybe<bool> ValueSerializer::WriteValue(Local<Context> context, | 2856 Maybe<bool> ValueSerializer::WriteValue(Local<Context> context, |
| 2857 Local<Value> value) { | 2857 Local<Value> value) { |
| 2858 PREPARE_FOR_EXECUTION_PRIMITIVE(context, ValueSerializer, WriteValue, bool); | 2858 PREPARE_FOR_EXECUTION_PRIMITIVE(context, ValueSerializer, WriteValue, bool); |
| 2859 i::Handle<i::Object> object = Utils::OpenHandle(*value); | 2859 i::Handle<i::Object> object = Utils::OpenHandle(*value); |
| 2860 Maybe<bool> result = private_->serializer.WriteObject(object); | 2860 Maybe<bool> result = private_->serializer.WriteObject(object); |
| 2861 if (result.IsNothing()) { | 2861 has_pending_exception = result.IsNothing(); |
| 2862 has_pending_exception = private_->isolate->has_pending_exception(); | 2862 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 2863 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | |
| 2864 } | |
| 2865 return result; | 2863 return result; |
| 2866 } | 2864 } |
| 2867 | 2865 |
| 2868 std::vector<uint8_t> ValueSerializer::ReleaseBuffer() { | 2866 std::vector<uint8_t> ValueSerializer::ReleaseBuffer() { |
| 2869 return private_->serializer.ReleaseBuffer(); | 2867 return private_->serializer.ReleaseBuffer(); |
| 2870 } | 2868 } |
| 2871 | 2869 |
| 2872 void ValueSerializer::TransferArrayBuffer(uint32_t transfer_id, | 2870 void ValueSerializer::TransferArrayBuffer(uint32_t transfer_id, |
| 2873 Local<ArrayBuffer> array_buffer) { | 2871 Local<ArrayBuffer> array_buffer) { |
| 2874 private_->serializer.TransferArrayBuffer(transfer_id, | 2872 private_->serializer.TransferArrayBuffer(transfer_id, |
| 2875 Utils::OpenHandle(*array_buffer)); | 2873 Utils::OpenHandle(*array_buffer)); |
| 2876 } | 2874 } |
| 2877 | 2875 |
| 2878 void ValueSerializer::TransferSharedArrayBuffer( | 2876 void ValueSerializer::TransferSharedArrayBuffer( |
| 2879 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { | 2877 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { |
| 2880 private_->serializer.TransferArrayBuffer( | 2878 private_->serializer.TransferArrayBuffer( |
| 2881 transfer_id, Utils::OpenHandle(*shared_array_buffer)); | 2879 transfer_id, Utils::OpenHandle(*shared_array_buffer)); |
| 2882 } | 2880 } |
| 2883 | 2881 |
| 2884 struct ValueDeserializer::PrivateData { | 2882 struct ValueDeserializer::PrivateData { |
| 2885 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data) | 2883 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data) |
| 2886 : isolate(i), deserializer(i, data) {} | 2884 : isolate(i), deserializer(i, data) {} |
| 2887 i::Isolate* isolate; | 2885 i::Isolate* isolate; |
| 2888 i::ValueDeserializer deserializer; | 2886 i::ValueDeserializer deserializer; |
| 2887 bool has_aborted = false; |
| 2889 bool supports_legacy_wire_format = false; | 2888 bool supports_legacy_wire_format = false; |
| 2890 }; | 2889 }; |
| 2891 | 2890 |
| 2892 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, | 2891 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, |
| 2893 size_t size) { | 2892 size_t size) { |
| 2894 if (base::IsValueInRangeForNumericType<int>(size)) { | 2893 if (base::IsValueInRangeForNumericType<int>(size)) { |
| 2895 private_ = | 2894 private_ = |
| 2896 new PrivateData(reinterpret_cast<i::Isolate*>(isolate), | 2895 new PrivateData(reinterpret_cast<i::Isolate*>(isolate), |
| 2897 i::Vector<const uint8_t>(data, static_cast<int>(size))); | 2896 i::Vector<const uint8_t>(data, static_cast<int>(size))); |
| 2898 } else { | 2897 } else { |
| 2899 private_ = nullptr; | 2898 private_ = new PrivateData(reinterpret_cast<i::Isolate*>(isolate), |
| 2899 i::Vector<const uint8_t>(nullptr, 0)); |
| 2900 private_->has_aborted = true; |
| 2900 } | 2901 } |
| 2901 } | 2902 } |
| 2902 | 2903 |
| 2903 ValueDeserializer::~ValueDeserializer() { delete private_; } | 2904 ValueDeserializer::~ValueDeserializer() { delete private_; } |
| 2904 | 2905 |
| 2905 Maybe<bool> ValueDeserializer::ReadHeader() { | 2906 Maybe<bool> ValueDeserializer::ReadHeader(Local<Context> context) { |
| 2907 PREPARE_FOR_EXECUTION_PRIMITIVE(context, ValueDeserializer, ReadHeader, bool); |
| 2908 |
| 2909 // We could have aborted during the constructor. |
| 2910 // If so, ReadHeader is where we report it. |
| 2911 if (private_->has_aborted) { |
| 2912 isolate->Throw(*isolate->factory()->NewError( |
| 2913 i::MessageTemplate::kDataCloneDeserializationError)); |
| 2914 has_pending_exception = true; |
| 2915 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 2916 } |
| 2917 |
| 2918 bool read_header = false; |
| 2919 has_pending_exception = !private_->deserializer.ReadHeader().To(&read_header); |
| 2920 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 2921 DCHECK(read_header); |
| 2922 |
| 2906 // TODO(jbroman): Today, all wire formats are "legacy". When a more supported | 2923 // TODO(jbroman): Today, all wire formats are "legacy". When a more supported |
| 2907 // format is added, compare the version of the internal serializer to the | 2924 // format is added, compare the version of the internal serializer to the |
| 2908 // minimum non-legacy version number. | 2925 // minimum non-legacy version number. |
| 2909 if (!private_ || !private_->deserializer.ReadHeader().FromMaybe(false) || | 2926 if (!private_->supports_legacy_wire_format) { |
| 2910 !private_->supports_legacy_wire_format) { | 2927 isolate->Throw(*isolate->factory()->NewError( |
| 2911 delete private_; | 2928 i::MessageTemplate::kDataCloneDeserializationVersionError)); |
| 2912 private_ = nullptr; | 2929 has_pending_exception = true; |
| 2913 return Nothing<bool>(); | 2930 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 2914 } | 2931 } |
| 2932 |
| 2915 return Just(true); | 2933 return Just(true); |
| 2916 } | 2934 } |
| 2917 | 2935 |
| 2936 Maybe<bool> ValueDeserializer::ReadHeader() { |
| 2937 Isolate* isolate = reinterpret_cast<Isolate*>(private_->isolate); |
| 2938 return ReadHeader(isolate->GetEnteredContext()); |
| 2939 } |
| 2940 |
| 2918 void ValueDeserializer::SetSupportsLegacyWireFormat( | 2941 void ValueDeserializer::SetSupportsLegacyWireFormat( |
| 2919 bool supports_legacy_wire_format) { | 2942 bool supports_legacy_wire_format) { |
| 2920 if (!private_) return; | |
| 2921 private_->supports_legacy_wire_format = supports_legacy_wire_format; | 2943 private_->supports_legacy_wire_format = supports_legacy_wire_format; |
| 2922 } | 2944 } |
| 2923 | 2945 |
| 2924 uint32_t ValueDeserializer::GetWireFormatVersion() const { | 2946 uint32_t ValueDeserializer::GetWireFormatVersion() const { |
| 2925 CHECK(private_); | 2947 CHECK(!private_->has_aborted); |
| 2926 return private_->deserializer.GetWireFormatVersion(); | 2948 return private_->deserializer.GetWireFormatVersion(); |
| 2927 } | 2949 } |
| 2928 | 2950 |
| 2929 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) { | 2951 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) { |
| 2930 CHECK(private_); | 2952 CHECK(!private_->has_aborted); |
| 2931 PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value); | 2953 PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value); |
| 2932 i::MaybeHandle<i::Object> result; | 2954 i::MaybeHandle<i::Object> result; |
| 2933 if (GetWireFormatVersion() > 0) { | 2955 if (GetWireFormatVersion() > 0) { |
| 2934 result = private_->deserializer.ReadObject(); | 2956 result = private_->deserializer.ReadObject(); |
| 2935 } else { | 2957 } else { |
| 2936 result = | 2958 result = |
| 2937 private_->deserializer.ReadObjectUsingEntireBufferForLegacyFormat(); | 2959 private_->deserializer.ReadObjectUsingEntireBufferForLegacyFormat(); |
| 2938 } | 2960 } |
| 2939 Local<Value> value; | 2961 Local<Value> value; |
| 2940 if (!ToLocal(result, &value)) { | 2962 has_pending_exception = !ToLocal(result, &value); |
| 2941 has_pending_exception = private_->isolate->has_pending_exception(); | 2963 RETURN_ON_FAILED_EXECUTION(Value); |
| 2942 RETURN_ON_FAILED_EXECUTION(Value); | |
| 2943 return MaybeLocal<Value>(); | |
| 2944 } | |
| 2945 RETURN_ESCAPED(value); | 2964 RETURN_ESCAPED(value); |
| 2946 } | 2965 } |
| 2947 | 2966 |
| 2948 void ValueDeserializer::TransferArrayBuffer(uint32_t transfer_id, | 2967 void ValueDeserializer::TransferArrayBuffer(uint32_t transfer_id, |
| 2949 Local<ArrayBuffer> array_buffer) { | 2968 Local<ArrayBuffer> array_buffer) { |
| 2969 CHECK(!private_->has_aborted); |
| 2950 private_->deserializer.TransferArrayBuffer(transfer_id, | 2970 private_->deserializer.TransferArrayBuffer(transfer_id, |
| 2951 Utils::OpenHandle(*array_buffer)); | 2971 Utils::OpenHandle(*array_buffer)); |
| 2952 } | 2972 } |
| 2953 | 2973 |
| 2954 void ValueDeserializer::TransferSharedArrayBuffer( | 2974 void ValueDeserializer::TransferSharedArrayBuffer( |
| 2955 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { | 2975 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { |
| 2976 CHECK(!private_->has_aborted); |
| 2956 private_->deserializer.TransferArrayBuffer( | 2977 private_->deserializer.TransferArrayBuffer( |
| 2957 transfer_id, Utils::OpenHandle(*shared_array_buffer)); | 2978 transfer_id, Utils::OpenHandle(*shared_array_buffer)); |
| 2958 } | 2979 } |
| 2959 | 2980 |
| 2960 // --- D a t a --- | 2981 // --- D a t a --- |
| 2961 | 2982 |
| 2962 bool Value::FullIsUndefined() const { | 2983 bool Value::FullIsUndefined() const { |
| 2963 i::Handle<i::Object> object = Utils::OpenHandle(this); | 2984 i::Handle<i::Object> object = Utils::OpenHandle(this); |
| 2964 bool result = false; | 2985 bool result = false; |
| 2965 if (!object->IsSmi()) { | 2986 if (!object->IsSmi()) { |
| (...skipping 6243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9209 Address callback_address = | 9230 Address callback_address = |
| 9210 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9231 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 9211 VMState<EXTERNAL> state(isolate); | 9232 VMState<EXTERNAL> state(isolate); |
| 9212 ExternalCallbackScope call_scope(isolate, callback_address); | 9233 ExternalCallbackScope call_scope(isolate, callback_address); |
| 9213 callback(info); | 9234 callback(info); |
| 9214 } | 9235 } |
| 9215 | 9236 |
| 9216 | 9237 |
| 9217 } // namespace internal | 9238 } // namespace internal |
| 9218 } // namespace v8 | 9239 } // namespace v8 |
| OLD | NEW |