OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/value-serializer.h" | 5 #include "src/value-serializer.h" |
6 | 6 |
7 #include <type_traits> | 7 #include <type_traits> |
8 | 8 |
9 #include "src/base/logging.h" | 9 #include "src/base/logging.h" |
10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 WriteVarint(id - 1); | 342 WriteVarint(id - 1); |
343 return Just(true); | 343 return Just(true); |
344 } | 344 } |
345 | 345 |
346 // Otherwise, allocate an ID for it. | 346 // Otherwise, allocate an ID for it. |
347 uint32_t id = next_id_++; | 347 uint32_t id = next_id_++; |
348 *id_map_entry = id + 1; | 348 *id_map_entry = id + 1; |
349 | 349 |
350 // Eliminate callable and exotic objects, which should not be serialized. | 350 // Eliminate callable and exotic objects, which should not be serialized. |
351 InstanceType instance_type = receiver->map()->instance_type(); | 351 InstanceType instance_type = receiver->map()->instance_type(); |
352 if (receiver->IsCallable() || instance_type <= LAST_SPECIAL_RECEIVER_TYPE) { | 352 if (receiver->IsCallable() || (instance_type <= LAST_SPECIAL_RECEIVER_TYPE && |
| 353 instance_type != JS_SPECIAL_API_OBJECT_TYPE)) { |
353 ThrowDataCloneError(MessageTemplate::kDataCloneError, receiver); | 354 ThrowDataCloneError(MessageTemplate::kDataCloneError, receiver); |
354 return Nothing<bool>(); | 355 return Nothing<bool>(); |
355 } | 356 } |
356 | 357 |
357 // If we are at the end of the stack, abort. This function may recurse. | 358 // If we are at the end of the stack, abort. This function may recurse. |
358 STACK_CHECK(isolate_, Nothing<bool>()); | 359 STACK_CHECK(isolate_, Nothing<bool>()); |
359 | 360 |
360 HandleScope scope(isolate_); | 361 HandleScope scope(isolate_); |
361 switch (instance_type) { | 362 switch (instance_type) { |
362 case JS_ARRAY_TYPE: | 363 case JS_ARRAY_TYPE: |
363 return WriteJSArray(Handle<JSArray>::cast(receiver)); | 364 return WriteJSArray(Handle<JSArray>::cast(receiver)); |
364 case JS_OBJECT_TYPE: | 365 case JS_OBJECT_TYPE: |
365 case JS_API_OBJECT_TYPE: { | 366 case JS_API_OBJECT_TYPE: { |
366 Handle<JSObject> js_object = Handle<JSObject>::cast(receiver); | 367 Handle<JSObject> js_object = Handle<JSObject>::cast(receiver); |
367 return js_object->GetInternalFieldCount() ? WriteHostObject(js_object) | 368 return js_object->GetInternalFieldCount() ? WriteHostObject(js_object) |
368 : WriteJSObject(js_object); | 369 : WriteJSObject(js_object); |
369 } | 370 } |
| 371 case JS_SPECIAL_API_OBJECT_TYPE: |
| 372 return WriteHostObject(Handle<JSObject>::cast(receiver)); |
370 case JS_DATE_TYPE: | 373 case JS_DATE_TYPE: |
371 WriteJSDate(JSDate::cast(*receiver)); | 374 WriteJSDate(JSDate::cast(*receiver)); |
372 return Just(true); | 375 return Just(true); |
373 case JS_VALUE_TYPE: | 376 case JS_VALUE_TYPE: |
374 return WriteJSValue(Handle<JSValue>::cast(receiver)); | 377 return WriteJSValue(Handle<JSValue>::cast(receiver)); |
375 case JS_REGEXP_TYPE: | 378 case JS_REGEXP_TYPE: |
376 WriteJSRegExp(JSRegExp::cast(*receiver)); | 379 WriteJSRegExp(JSRegExp::cast(*receiver)); |
377 return Just(true); | 380 return Just(true); |
378 case JS_MAP_TYPE: | 381 case JS_MAP_TYPE: |
379 return WriteJSMap(Handle<JSMap>::cast(receiver)); | 382 return WriteJSMap(Handle<JSMap>::cast(receiver)); |
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1709 if (stack.size() != 1) { | 1712 if (stack.size() != 1) { |
1710 isolate_->Throw(*isolate_->factory()->NewError( | 1713 isolate_->Throw(*isolate_->factory()->NewError( |
1711 MessageTemplate::kDataCloneDeserializationError)); | 1714 MessageTemplate::kDataCloneDeserializationError)); |
1712 return MaybeHandle<Object>(); | 1715 return MaybeHandle<Object>(); |
1713 } | 1716 } |
1714 return scope.CloseAndEscape(stack[0]); | 1717 return scope.CloseAndEscape(stack[0]); |
1715 } | 1718 } |
1716 | 1719 |
1717 } // namespace internal | 1720 } // namespace internal |
1718 } // namespace v8 | 1721 } // namespace v8 |
OLD | NEW |