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 7206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7217 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), | 7217 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), |
7218 compiled_part); | 7218 compiled_part); |
7219 script_data->ReleaseDataOwnership(); | 7219 script_data->ReleaseDataOwnership(); |
7220 | 7220 |
7221 size_t size = static_cast<size_t>(script_data->length()); | 7221 size_t size = static_cast<size_t>(script_data->length()); |
7222 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; | 7222 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; |
7223 } | 7223 } |
7224 | 7224 |
7225 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( | 7225 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( |
7226 Isolate* isolate, | 7226 Isolate* isolate, |
7227 const WasmCompiledModule::CallerOwnedBuffer& serialized_module) { | 7227 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, |
| 7228 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { |
7228 int size = static_cast<int>(serialized_module.second); | 7229 int size = static_cast<int>(serialized_module.second); |
7229 i::ScriptData sc(serialized_module.first, size); | 7230 i::ScriptData sc(serialized_module.first, size); |
7230 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7231 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7231 i::MaybeHandle<i::FixedArray> maybe_compiled_part = | 7232 i::MaybeHandle<i::FixedArray> maybe_compiled_part = |
7232 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); | 7233 i::WasmCompiledModuleSerializer::DeserializeWasmModule( |
| 7234 i_isolate, &sc, |
| 7235 {wire_bytes.first, static_cast<int>(wire_bytes.second)}); |
7233 i::Handle<i::FixedArray> compiled_part; | 7236 i::Handle<i::FixedArray> compiled_part; |
7234 if (!maybe_compiled_part.ToHandle(&compiled_part)) { | 7237 if (!maybe_compiled_part.ToHandle(&compiled_part)) { |
7235 return MaybeLocal<WasmCompiledModule>(); | 7238 return MaybeLocal<WasmCompiledModule>(); |
7236 } | 7239 } |
7237 i::Handle<i::wasm::WasmCompiledModule> compiled_module = | 7240 i::Handle<i::wasm::WasmCompiledModule> compiled_module = |
7238 handle(i::wasm::WasmCompiledModule::cast(*compiled_part)); | 7241 handle(i::wasm::WasmCompiledModule::cast(*compiled_part)); |
7239 return Local<WasmCompiledModule>::Cast( | 7242 return Local<WasmCompiledModule>::Cast( |
7240 Utils::ToLocal(i::wasm::CreateWasmModuleObject( | 7243 Utils::ToLocal(i::wasm::CreateWasmModuleObject( |
7241 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin))); | 7244 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin))); |
7242 } | 7245 } |
7243 | 7246 |
7244 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( | 7247 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( |
7245 Isolate* isolate, | 7248 Isolate* isolate, |
7246 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, | 7249 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, |
7247 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { | 7250 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { |
7248 MaybeLocal<WasmCompiledModule> ret = Deserialize(isolate, serialized_module); | 7251 MaybeLocal<WasmCompiledModule> ret = |
| 7252 Deserialize(isolate, serialized_module, wire_bytes); |
7249 if (!ret.IsEmpty()) { | 7253 if (!ret.IsEmpty()) { |
7250 // TODO(mtrofin): once we stop taking a dependency on Deserialize, | |
7251 // clean this up to avoid the back and forth between internal | |
7252 // and external representations. | |
7253 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | |
7254 i::Vector<const uint8_t> str(wire_bytes.first, | |
7255 static_cast<int>(wire_bytes.second)); | |
7256 i::Handle<i::SeqOneByteString> wire_bytes_as_string( | |
7257 i::SeqOneByteString::cast( | |
7258 *i_isolate->factory()->NewStringFromOneByte(str).ToHandleChecked()), | |
7259 i_isolate); | |
7260 | |
7261 i::Handle<i::JSObject> obj = | |
7262 i::Handle<i::JSObject>::cast(Utils::OpenHandle(*ret.ToLocalChecked())); | |
7263 i::Handle<i::wasm::WasmCompiledModule> compiled_part = | |
7264 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0))); | |
7265 compiled_part->set_module_bytes(wire_bytes_as_string); | |
7266 return ret; | 7254 return ret; |
7267 } | 7255 } |
7268 return Compile(isolate, wire_bytes.first, wire_bytes.second); | 7256 return Compile(isolate, wire_bytes.first, wire_bytes.second); |
7269 } | 7257 } |
7270 | 7258 |
7271 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate, | 7259 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(Isolate* isolate, |
7272 const uint8_t* start, | 7260 const uint8_t* start, |
7273 size_t length) { | 7261 size_t length) { |
7274 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7262 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7275 i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()"); | 7263 i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()"); |
(...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9511 Address callback_address = | 9499 Address callback_address = |
9512 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9500 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9513 VMState<EXTERNAL> state(isolate); | 9501 VMState<EXTERNAL> state(isolate); |
9514 ExternalCallbackScope call_scope(isolate, callback_address); | 9502 ExternalCallbackScope call_scope(isolate, callback_address); |
9515 callback(info); | 9503 callback(info); |
9516 } | 9504 } |
9517 | 9505 |
9518 | 9506 |
9519 } // namespace internal | 9507 } // namespace internal |
9520 } // namespace v8 | 9508 } // namespace v8 |
OLD | NEW |