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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 return Just(true); | 776 return Just(true); |
777 } | 777 } |
778 | 778 |
779 Maybe<bool> ValueSerializer::WriteWasmModule(Handle<JSObject> object) { | 779 Maybe<bool> ValueSerializer::WriteWasmModule(Handle<JSObject> object) { |
780 Handle<WasmCompiledModule> compiled_part( | 780 Handle<WasmCompiledModule> compiled_part( |
781 WasmCompiledModule::cast(object->GetInternalField(0)), isolate_); | 781 WasmCompiledModule::cast(object->GetInternalField(0)), isolate_); |
782 WasmEncodingTag encoding_tag = WasmEncodingTag::kRawBytes; | 782 WasmEncodingTag encoding_tag = WasmEncodingTag::kRawBytes; |
783 WriteTag(SerializationTag::kWasmModule); | 783 WriteTag(SerializationTag::kWasmModule); |
784 WriteRawBytes(&encoding_tag, sizeof(encoding_tag)); | 784 WriteRawBytes(&encoding_tag, sizeof(encoding_tag)); |
785 | 785 |
786 Handle<String> wire_bytes = compiled_part->module_bytes(); | 786 Handle<String> wire_bytes(compiled_part->module_bytes(), isolate_); |
787 int wire_bytes_length = wire_bytes->length(); | 787 int wire_bytes_length = wire_bytes->length(); |
788 WriteVarint<uint32_t>(wire_bytes_length); | 788 WriteVarint<uint32_t>(wire_bytes_length); |
789 uint8_t* destination = ReserveRawBytes(wire_bytes_length); | 789 uint8_t* destination = ReserveRawBytes(wire_bytes_length); |
790 String::WriteToFlat(*wire_bytes, destination, 0, wire_bytes_length); | 790 String::WriteToFlat(*wire_bytes, destination, 0, wire_bytes_length); |
791 | 791 |
792 std::unique_ptr<ScriptData> script_data = | 792 std::unique_ptr<ScriptData> script_data = |
793 WasmCompiledModuleSerializer::SerializeWasmModule(isolate_, | 793 WasmCompiledModuleSerializer::SerializeWasmModule(isolate_, |
794 compiled_part); | 794 compiled_part); |
795 int script_data_length = script_data->length(); | 795 int script_data_length = script_data->length(); |
796 WriteVarint<uint32_t>(script_data_length); | 796 WriteVarint<uint32_t>(script_data_length); |
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 isolate_, &script_data, wire_bytes) | 1547 isolate_, &script_data, wire_bytes) |
1548 .ToHandle(&compiled_part)) { | 1548 .ToHandle(&compiled_part)) { |
1549 return WasmModuleObject::New( | 1549 return WasmModuleObject::New( |
1550 isolate_, Handle<WasmCompiledModule>::cast(compiled_part)); | 1550 isolate_, Handle<WasmCompiledModule>::cast(compiled_part)); |
1551 } | 1551 } |
1552 | 1552 |
1553 // If that fails, recompile. | 1553 // If that fails, recompile. |
1554 wasm::ErrorThrower thrower(isolate_, "ValueDeserializer::ReadWasmModule"); | 1554 wasm::ErrorThrower thrower(isolate_, "ValueDeserializer::ReadWasmModule"); |
1555 return wasm::CreateModuleObjectFromBytes( | 1555 return wasm::CreateModuleObjectFromBytes( |
1556 isolate_, wire_bytes.begin(), wire_bytes.end(), &thrower, | 1556 isolate_, wire_bytes.begin(), wire_bytes.end(), &thrower, |
1557 wasm::ModuleOrigin::kWasmOrigin, Handle<Script>::null(), nullptr, | 1557 wasm::ModuleOrigin::kWasmOrigin, Handle<Script>::null(), |
1558 nullptr); | 1558 Vector<const byte>::empty()); |
1559 } | 1559 } |
1560 | 1560 |
1561 MaybeHandle<JSObject> ValueDeserializer::ReadHostObject() { | 1561 MaybeHandle<JSObject> ValueDeserializer::ReadHostObject() { |
1562 if (!delegate_) return MaybeHandle<JSObject>(); | 1562 if (!delegate_) return MaybeHandle<JSObject>(); |
1563 STACK_CHECK(isolate_, MaybeHandle<JSObject>()); | 1563 STACK_CHECK(isolate_, MaybeHandle<JSObject>()); |
1564 uint32_t id = next_id_++; | 1564 uint32_t id = next_id_++; |
1565 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_); | 1565 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate_); |
1566 v8::Local<v8::Object> object; | 1566 v8::Local<v8::Object> object; |
1567 if (!delegate_->ReadHostObject(v8_isolate).ToLocal(&object)) { | 1567 if (!delegate_->ReadHostObject(v8_isolate).ToLocal(&object)) { |
1568 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate_, JSObject); | 1568 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate_, JSObject); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 if (stack.size() != 1) { | 1860 if (stack.size() != 1) { |
1861 isolate_->Throw(*isolate_->factory()->NewError( | 1861 isolate_->Throw(*isolate_->factory()->NewError( |
1862 MessageTemplate::kDataCloneDeserializationError)); | 1862 MessageTemplate::kDataCloneDeserializationError)); |
1863 return MaybeHandle<Object>(); | 1863 return MaybeHandle<Object>(); |
1864 } | 1864 } |
1865 return scope.CloseAndEscape(stack[0]); | 1865 return scope.CloseAndEscape(stack[0]); |
1866 } | 1866 } |
1867 | 1867 |
1868 } // namespace internal | 1868 } // namespace internal |
1869 } // namespace v8 | 1869 } // namespace v8 |
OLD | NEW |