Chromium Code Reviews| 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 7173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7184 i::Handle<i::String> wire_bytes = compiled_part->module_bytes(); | 7184 i::Handle<i::String> wire_bytes = compiled_part->module_bytes(); |
| 7185 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); | 7185 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); |
| 7186 } | 7186 } |
| 7187 | 7187 |
| 7188 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { | 7188 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { |
| 7189 i::Handle<i::JSObject> obj = | 7189 i::Handle<i::JSObject> obj = |
| 7190 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 7190 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |
| 7191 i::Handle<i::wasm::WasmCompiledModule> compiled_part = | 7191 i::Handle<i::wasm::WasmCompiledModule> compiled_part = |
| 7192 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0))); | 7192 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0))); |
| 7193 | 7193 |
| 7194 i::Handle<i::SeqOneByteString> wire_bytes = compiled_part->module_bytes(); | |
| 7195 compiled_part->reset_module_bytes(); | |
|
Mircea Trofin
2016/10/15 17:38:39
Consider the scenario when we try to deserialize f
| |
| 7196 std::unique_ptr<i::ScriptData> script_data = | 7194 std::unique_ptr<i::ScriptData> script_data = |
| 7197 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), | 7195 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), |
| 7198 compiled_part); | 7196 compiled_part); |
| 7199 compiled_part->set_module_bytes(wire_bytes); | |
| 7200 script_data->ReleaseDataOwnership(); | 7197 script_data->ReleaseDataOwnership(); |
| 7201 | 7198 |
| 7202 size_t size = static_cast<size_t>(script_data->length()); | 7199 size_t size = static_cast<size_t>(script_data->length()); |
| 7203 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; | 7200 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; |
| 7204 } | 7201 } |
| 7205 | 7202 |
| 7206 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( | 7203 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( |
| 7207 Isolate* isolate, | 7204 Isolate* isolate, |
| 7208 const WasmCompiledModule::SerializedModule& serialized_module) { | 7205 const WasmCompiledModule::SerializedModule& serialized_module) { |
| 7209 return Deserialize(isolate, | 7206 return Deserialize(isolate, |
| 7210 {serialized_module.first.get(), serialized_module.second}); | 7207 {serialized_module.first.get(), serialized_module.second}); |
| 7211 } | 7208 } |
| 7212 | 7209 |
| 7213 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( | 7210 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( |
| 7214 Isolate* isolate, | 7211 Isolate* isolate, |
| 7215 const WasmCompiledModule::CallerOwnedBuffer& serialized_module) { | 7212 const WasmCompiledModule::CallerOwnedBuffer& serialized_module) { |
| 7216 int size = static_cast<int>(serialized_module.second); | 7213 int size = static_cast<int>(serialized_module.second); |
| 7217 i::ScriptData sc(serialized_module.first, size); | 7214 i::ScriptData sc(serialized_module.first, size); |
| 7218 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7215 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 7219 i::MaybeHandle<i::FixedArray> maybe_compiled_part = | 7216 i::MaybeHandle<i::FixedArray> maybe_compiled_part = |
| 7220 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); | 7217 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); |
| 7221 i::Handle<i::FixedArray> compiled_part; | 7218 i::Handle<i::FixedArray> compiled_part; |
| 7222 if (!maybe_compiled_part.ToHandle(&compiled_part)) { | 7219 if (!maybe_compiled_part.ToHandle(&compiled_part)) { |
| 7223 return MaybeLocal<WasmCompiledModule>(); | 7220 return MaybeLocal<WasmCompiledModule>(); |
| 7224 } | 7221 } |
| 7225 i::Handle<i::wasm::WasmCompiledModule> compiled_module = | 7222 i::Handle<i::wasm::WasmCompiledModule> compiled_module = |
| 7226 handle(i::wasm::WasmCompiledModule::cast(*compiled_part)); | 7223 handle(i::wasm::WasmCompiledModule::cast(*compiled_part)); |
| 7227 return Local<WasmCompiledModule>::Cast( | 7224 return Local<WasmCompiledModule>::Cast( |
| 7228 Utils::ToLocal(i::wasm::CreateCompiledModuleObject( | 7225 Utils::ToLocal(i::wasm::CreateWasmModuleObject( |
| 7229 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin))); | 7226 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin))); |
| 7230 } | 7227 } |
| 7231 | 7228 |
| 7232 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( | 7229 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( |
| 7233 Isolate* isolate, | 7230 Isolate* isolate, |
| 7234 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, | 7231 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, |
| 7235 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { | 7232 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { |
| 7236 MaybeLocal<WasmCompiledModule> ret = Deserialize(isolate, serialized_module); | 7233 MaybeLocal<WasmCompiledModule> ret = Deserialize(isolate, serialized_module); |
| 7237 if (!ret.IsEmpty()) return ret; | 7234 if (!ret.IsEmpty()) return ret; |
| 7238 return Compile(isolate, wire_bytes.first, wire_bytes.second); | 7235 return Compile(isolate, wire_bytes.first, wire_bytes.second); |
| (...skipping 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9415 Address callback_address = | 9412 Address callback_address = |
| 9416 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9413 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 9417 VMState<EXTERNAL> state(isolate); | 9414 VMState<EXTERNAL> state(isolate); |
| 9418 ExternalCallbackScope call_scope(isolate, callback_address); | 9415 ExternalCallbackScope call_scope(isolate, callback_address); |
| 9419 callback(info); | 9416 callback(info); |
| 9420 } | 9417 } |
| 9421 | 9418 |
| 9422 | 9419 |
| 9423 } // namespace internal | 9420 } // namespace internal |
| 9424 } // namespace v8 | 9421 } // namespace v8 |
| OLD | NEW |