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 7186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7197 i::Handle<i::String> wire_bytes = compiled_part->module_bytes(); | 7197 i::Handle<i::String> wire_bytes = compiled_part->module_bytes(); |
7198 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); | 7198 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); |
7199 } | 7199 } |
7200 | 7200 |
7201 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { | 7201 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { |
7202 i::Handle<i::JSObject> obj = | 7202 i::Handle<i::JSObject> obj = |
7203 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 7203 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |
7204 i::Handle<i::wasm::WasmCompiledModule> compiled_part = | 7204 i::Handle<i::wasm::WasmCompiledModule> compiled_part = |
7205 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0))); | 7205 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0))); |
7206 | 7206 |
7207 i::Handle<i::SeqOneByteString> wire_bytes = compiled_part->module_bytes(); | |
7208 compiled_part->reset_module_bytes(); | |
7209 std::unique_ptr<i::ScriptData> script_data = | 7207 std::unique_ptr<i::ScriptData> script_data = |
7210 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), | 7208 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), |
7211 compiled_part); | 7209 compiled_part); |
7212 compiled_part->set_module_bytes(wire_bytes); | |
7213 script_data->ReleaseDataOwnership(); | 7210 script_data->ReleaseDataOwnership(); |
7214 | 7211 |
7215 size_t size = static_cast<size_t>(script_data->length()); | 7212 size_t size = static_cast<size_t>(script_data->length()); |
7216 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; | 7213 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; |
7217 } | 7214 } |
7218 | 7215 |
7219 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( | 7216 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( |
7220 Isolate* isolate, | 7217 Isolate* isolate, |
7221 const WasmCompiledModule::SerializedModule& serialized_module) { | 7218 const WasmCompiledModule::SerializedModule& serialized_module) { |
7222 return Deserialize(isolate, | 7219 return Deserialize(isolate, |
7223 {serialized_module.first.get(), serialized_module.second}); | 7220 {serialized_module.first.get(), serialized_module.second}); |
7224 } | 7221 } |
7225 | 7222 |
7226 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( | 7223 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( |
7227 Isolate* isolate, | 7224 Isolate* isolate, |
7228 const WasmCompiledModule::CallerOwnedBuffer& serialized_module) { | 7225 const WasmCompiledModule::CallerOwnedBuffer& serialized_module) { |
7229 int size = static_cast<int>(serialized_module.second); | 7226 int size = static_cast<int>(serialized_module.second); |
7230 i::ScriptData sc(serialized_module.first, size); | 7227 i::ScriptData sc(serialized_module.first, size); |
7231 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7228 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7232 i::MaybeHandle<i::FixedArray> maybe_compiled_part = | 7229 i::MaybeHandle<i::FixedArray> maybe_compiled_part = |
7233 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); | 7230 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); |
7234 i::Handle<i::FixedArray> compiled_part; | 7231 i::Handle<i::FixedArray> compiled_part; |
7235 if (!maybe_compiled_part.ToHandle(&compiled_part)) { | 7232 if (!maybe_compiled_part.ToHandle(&compiled_part)) { |
7236 return MaybeLocal<WasmCompiledModule>(); | 7233 return MaybeLocal<WasmCompiledModule>(); |
7237 } | 7234 } |
7238 i::Handle<i::wasm::WasmCompiledModule> compiled_module = | 7235 i::Handle<i::wasm::WasmCompiledModule> compiled_module = |
7239 handle(i::wasm::WasmCompiledModule::cast(*compiled_part)); | 7236 handle(i::wasm::WasmCompiledModule::cast(*compiled_part)); |
7240 return Local<WasmCompiledModule>::Cast( | 7237 return Local<WasmCompiledModule>::Cast( |
7241 Utils::ToLocal(i::wasm::CreateCompiledModuleObject( | 7238 Utils::ToLocal(i::wasm::CreateWasmModuleObject( |
7242 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin))); | 7239 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin))); |
7243 } | 7240 } |
7244 | 7241 |
7245 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( | 7242 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( |
7246 Isolate* isolate, | 7243 Isolate* isolate, |
7247 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, | 7244 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, |
7248 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { | 7245 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { |
7249 MaybeLocal<WasmCompiledModule> ret = Deserialize(isolate, serialized_module); | 7246 MaybeLocal<WasmCompiledModule> ret = Deserialize(isolate, serialized_module); |
7250 if (!ret.IsEmpty()) { | 7247 if (!ret.IsEmpty()) { |
7251 // TODO(mtrofin): once we stop taking a dependency on Deserialize, | 7248 // TODO(mtrofin): once we stop taking a dependency on Deserialize, |
(...skipping 2243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9495 Address callback_address = | 9492 Address callback_address = |
9496 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9493 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9497 VMState<EXTERNAL> state(isolate); | 9494 VMState<EXTERNAL> state(isolate); |
9498 ExternalCallbackScope call_scope(isolate, callback_address); | 9495 ExternalCallbackScope call_scope(isolate, callback_address); |
9499 callback(info); | 9496 callback(info); |
9500 } | 9497 } |
9501 | 9498 |
9502 | 9499 |
9503 } // namespace internal | 9500 } // namespace internal |
9504 } // namespace v8 | 9501 } // namespace v8 |
OLD | NEW |