Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: src/api.cc

Issue 2327653002: Support delegating serialization of host objects. (Closed)
Patch Set: Isolate* argument to delegate Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(Isolate* v8_isolate,
2851 Local<Object> object) {
2852 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2853 isolate->ScheduleThrow(*isolate->factory()->NewError(
2854 isolate->error_function(), i::MessageTemplate::kDataCloneError,
2855 Utils::OpenHandle(*object)));
2856 return Nothing<bool>();
2857 }
2858
2850 struct ValueSerializer::PrivateData { 2859 struct ValueSerializer::PrivateData {
2851 explicit PrivateData(i::Isolate* i, ValueSerializer::Delegate* delegate) 2860 explicit PrivateData(i::Isolate* i, ValueSerializer::Delegate* delegate)
2852 : isolate(i), serializer(i, delegate) {} 2861 : isolate(i), serializer(i, delegate) {}
2853 i::Isolate* isolate; 2862 i::Isolate* isolate;
2854 i::ValueSerializer serializer; 2863 i::ValueSerializer serializer;
2855 }; 2864 };
2856 2865
2857 ValueSerializer::ValueSerializer(Isolate* isolate) 2866 ValueSerializer::ValueSerializer(Isolate* isolate)
2858 : ValueSerializer(isolate, nullptr) {} 2867 : ValueSerializer(isolate, nullptr) {}
2859 2868
(...skipping 24 matching lines...) Expand all
2884 private_->serializer.TransferArrayBuffer(transfer_id, 2893 private_->serializer.TransferArrayBuffer(transfer_id,
2885 Utils::OpenHandle(*array_buffer)); 2894 Utils::OpenHandle(*array_buffer));
2886 } 2895 }
2887 2896
2888 void ValueSerializer::TransferSharedArrayBuffer( 2897 void ValueSerializer::TransferSharedArrayBuffer(
2889 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { 2898 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) {
2890 private_->serializer.TransferArrayBuffer( 2899 private_->serializer.TransferArrayBuffer(
2891 transfer_id, Utils::OpenHandle(*shared_array_buffer)); 2900 transfer_id, Utils::OpenHandle(*shared_array_buffer));
2892 } 2901 }
2893 2902
2903 void ValueSerializer::WriteUint32(uint32_t value) {
2904 private_->serializer.WriteUint32(value);
2905 }
2906
2907 void ValueSerializer::WriteUint64(uint64_t value) {
2908 private_->serializer.WriteUint64(value);
2909 }
2910
2911 void ValueSerializer::WriteRawBytes(const void* source, size_t length) {
2912 private_->serializer.WriteRawBytes(source, length);
2913 }
2914
2915 MaybeLocal<Object> ValueDeserializer::Delegate::ReadHostObject(
2916 Isolate* v8_isolate) {
2917 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
2918 isolate->ScheduleThrow(*isolate->factory()->NewError(
2919 isolate->error_function(),
2920 i::MessageTemplate::kDataCloneDeserializationError));
2921 return MaybeLocal<Object>();
2922 }
2923
2894 struct ValueDeserializer::PrivateData { 2924 struct ValueDeserializer::PrivateData {
2895 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data) 2925 PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate)
2896 : isolate(i), deserializer(i, data) {} 2926 : isolate(i), deserializer(i, data, delegate) {}
2897 i::Isolate* isolate; 2927 i::Isolate* isolate;
2898 i::ValueDeserializer deserializer; 2928 i::ValueDeserializer deserializer;
2899 bool has_aborted = false; 2929 bool has_aborted = false;
2900 bool supports_legacy_wire_format = false; 2930 bool supports_legacy_wire_format = false;
2901 }; 2931 };
2902 2932
2903 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, 2933 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,
2904 size_t size) { 2934 size_t size)
2935 : ValueDeserializer(isolate, data, size, nullptr) {}
2936
2937 ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,
2938 size_t size, Delegate* delegate) {
2905 if (base::IsValueInRangeForNumericType<int>(size)) { 2939 if (base::IsValueInRangeForNumericType<int>(size)) {
2906 private_ = 2940 private_ = new PrivateData(
2907 new PrivateData(reinterpret_cast<i::Isolate*>(isolate), 2941 reinterpret_cast<i::Isolate*>(isolate),
2908 i::Vector<const uint8_t>(data, static_cast<int>(size))); 2942 i::Vector<const uint8_t>(data, static_cast<int>(size)), delegate);
2909 } else { 2943 } else {
2910 private_ = new PrivateData(reinterpret_cast<i::Isolate*>(isolate), 2944 private_ = new PrivateData(reinterpret_cast<i::Isolate*>(isolate),
2911 i::Vector<const uint8_t>(nullptr, 0)); 2945 i::Vector<const uint8_t>(nullptr, 0), nullptr);
2912 private_->has_aborted = true; 2946 private_->has_aborted = true;
2913 } 2947 }
2914 } 2948 }
2915 2949
2916 ValueDeserializer::~ValueDeserializer() { delete private_; } 2950 ValueDeserializer::~ValueDeserializer() { delete private_; }
2917 2951
2918 Maybe<bool> ValueDeserializer::ReadHeader(Local<Context> context) { 2952 Maybe<bool> ValueDeserializer::ReadHeader(Local<Context> context) {
2919 PREPARE_FOR_EXECUTION_PRIMITIVE(context, ValueDeserializer, ReadHeader, bool); 2953 PREPARE_FOR_EXECUTION_PRIMITIVE(context, ValueDeserializer, ReadHeader, bool);
2920 2954
2921 // We could have aborted during the constructor. 2955 // We could have aborted during the constructor.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2983 Utils::OpenHandle(*array_buffer)); 3017 Utils::OpenHandle(*array_buffer));
2984 } 3018 }
2985 3019
2986 void ValueDeserializer::TransferSharedArrayBuffer( 3020 void ValueDeserializer::TransferSharedArrayBuffer(
2987 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { 3021 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) {
2988 CHECK(!private_->has_aborted); 3022 CHECK(!private_->has_aborted);
2989 private_->deserializer.TransferArrayBuffer( 3023 private_->deserializer.TransferArrayBuffer(
2990 transfer_id, Utils::OpenHandle(*shared_array_buffer)); 3024 transfer_id, Utils::OpenHandle(*shared_array_buffer));
2991 } 3025 }
2992 3026
3027 bool ValueDeserializer::ReadUint32(uint32_t* value) {
3028 return private_->deserializer.ReadUint32(value);
3029 }
3030
3031 bool ValueDeserializer::ReadUint64(uint64_t* value) {
3032 return private_->deserializer.ReadUint64(value);
3033 }
3034
3035 bool ValueDeserializer::ReadRawBytes(size_t length, const void** data) {
3036 return private_->deserializer.ReadRawBytes(length, data);
3037 }
3038
2993 // --- D a t a --- 3039 // --- D a t a ---
2994 3040
2995 bool Value::FullIsUndefined() const { 3041 bool Value::FullIsUndefined() const {
2996 i::Handle<i::Object> object = Utils::OpenHandle(this); 3042 i::Handle<i::Object> object = Utils::OpenHandle(this);
2997 bool result = false; 3043 bool result = false;
2998 if (!object->IsSmi()) { 3044 if (!object->IsSmi()) {
2999 result = object->IsUndefined(i::HeapObject::cast(*object)->GetIsolate()); 3045 result = object->IsUndefined(i::HeapObject::cast(*object)->GetIsolate());
3000 } 3046 }
3001 DCHECK_EQ(result, QuickIsUndefined()); 3047 DCHECK_EQ(result, QuickIsUndefined());
3002 return result; 3048 return result;
(...skipping 6233 matching lines...) Expand 10 before | Expand all | Expand 10 after
9236 Address callback_address = 9282 Address callback_address =
9237 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9283 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9238 VMState<EXTERNAL> state(isolate); 9284 VMState<EXTERNAL> state(isolate);
9239 ExternalCallbackScope call_scope(isolate, callback_address); 9285 ExternalCallbackScope call_scope(isolate, callback_address);
9240 callback(info); 9286 callback(info);
9241 } 9287 }
9242 9288
9243 9289
9244 } // namespace internal 9290 } // namespace internal
9245 } // namespace v8 9291 } // namespace v8
OLDNEW
« include/v8.h ('K') | « include/v8.h ('k') | src/value-serializer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698