| 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 3113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3124 | 3124 |
| 3125 Maybe<uint32_t> ValueSerializer::Delegate::GetSharedArrayBufferId( | 3125 Maybe<uint32_t> ValueSerializer::Delegate::GetSharedArrayBufferId( |
| 3126 Isolate* v8_isolate, Local<SharedArrayBuffer> shared_array_buffer) { | 3126 Isolate* v8_isolate, Local<SharedArrayBuffer> shared_array_buffer) { |
| 3127 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 3127 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 3128 isolate->ScheduleThrow(*isolate->factory()->NewError( | 3128 isolate->ScheduleThrow(*isolate->factory()->NewError( |
| 3129 isolate->error_function(), i::MessageTemplate::kDataCloneError, | 3129 isolate->error_function(), i::MessageTemplate::kDataCloneError, |
| 3130 Utils::OpenHandle(*shared_array_buffer))); | 3130 Utils::OpenHandle(*shared_array_buffer))); |
| 3131 return Nothing<uint32_t>(); | 3131 return Nothing<uint32_t>(); |
| 3132 } | 3132 } |
| 3133 | 3133 |
| 3134 Maybe<uint32_t> ValueSerializer::Delegate::GetWasmModuleTransferId( |
| 3135 Isolate* v8_isolate, Local<WasmCompiledModule> module) { |
| 3136 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 3137 isolate->ScheduleThrow(*isolate->factory()->NewError( |
| 3138 isolate->error_function(), i::MessageTemplate::kDataCloneError, |
| 3139 Utils::OpenHandle(*module))); |
| 3140 return Nothing<uint32_t>(); |
| 3141 } |
| 3142 |
| 3134 void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer, | 3143 void* ValueSerializer::Delegate::ReallocateBufferMemory(void* old_buffer, |
| 3135 size_t size, | 3144 size_t size, |
| 3136 size_t* actual_size) { | 3145 size_t* actual_size) { |
| 3137 *actual_size = size; | 3146 *actual_size = size; |
| 3138 return realloc(old_buffer, size); | 3147 return realloc(old_buffer, size); |
| 3139 } | 3148 } |
| 3140 | 3149 |
| 3141 void ValueSerializer::Delegate::FreeBufferMemory(void* buffer) { | 3150 void ValueSerializer::Delegate::FreeBufferMemory(void* buffer) { |
| 3142 return free(buffer); | 3151 return free(buffer); |
| 3143 } | 3152 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3274 } | 3283 } |
| 3275 | 3284 |
| 3276 return Just(true); | 3285 return Just(true); |
| 3277 } | 3286 } |
| 3278 | 3287 |
| 3279 void ValueDeserializer::SetSupportsLegacyWireFormat( | 3288 void ValueDeserializer::SetSupportsLegacyWireFormat( |
| 3280 bool supports_legacy_wire_format) { | 3289 bool supports_legacy_wire_format) { |
| 3281 private_->supports_legacy_wire_format = supports_legacy_wire_format; | 3290 private_->supports_legacy_wire_format = supports_legacy_wire_format; |
| 3282 } | 3291 } |
| 3283 | 3292 |
| 3293 void ValueDeserializer::SetAllowInlineWasm(bool allow_inline_wasm) { |
| 3294 private_->deserializer.set_allow_inline_wasm(allow_inline_wasm); |
| 3295 } |
| 3296 |
| 3284 uint32_t ValueDeserializer::GetWireFormatVersion() const { | 3297 uint32_t ValueDeserializer::GetWireFormatVersion() const { |
| 3285 CHECK(!private_->has_aborted); | 3298 CHECK(!private_->has_aborted); |
| 3286 return private_->deserializer.GetWireFormatVersion(); | 3299 return private_->deserializer.GetWireFormatVersion(); |
| 3287 } | 3300 } |
| 3288 | 3301 |
| 3289 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) { | 3302 MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) { |
| 3290 CHECK(!private_->has_aborted); | 3303 CHECK(!private_->has_aborted); |
| 3291 PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value); | 3304 PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value); |
| 3292 i::MaybeHandle<i::Object> result; | 3305 i::MaybeHandle<i::Object> result; |
| 3293 if (GetWireFormatVersion() > 0) { | 3306 if (GetWireFormatVersion() > 0) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3309 Utils::OpenHandle(*array_buffer)); | 3322 Utils::OpenHandle(*array_buffer)); |
| 3310 } | 3323 } |
| 3311 | 3324 |
| 3312 void ValueDeserializer::TransferSharedArrayBuffer( | 3325 void ValueDeserializer::TransferSharedArrayBuffer( |
| 3313 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { | 3326 uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) { |
| 3314 CHECK(!private_->has_aborted); | 3327 CHECK(!private_->has_aborted); |
| 3315 private_->deserializer.TransferArrayBuffer( | 3328 private_->deserializer.TransferArrayBuffer( |
| 3316 transfer_id, Utils::OpenHandle(*shared_array_buffer)); | 3329 transfer_id, Utils::OpenHandle(*shared_array_buffer)); |
| 3317 } | 3330 } |
| 3318 | 3331 |
| 3332 void ValueDeserializer::TransferWasmCompiledModule( |
| 3333 uint32_t transfer_id, Local<WasmCompiledModule> module) { |
| 3334 CHECK(!private_->has_aborted); |
| 3335 private_->deserializer.TransferWasmModule( |
| 3336 transfer_id, |
| 3337 i::Handle<i::WasmModuleObject>::cast(Utils::OpenHandle(*module))); |
| 3338 } |
| 3339 |
| 3319 bool ValueDeserializer::ReadUint32(uint32_t* value) { | 3340 bool ValueDeserializer::ReadUint32(uint32_t* value) { |
| 3320 return private_->deserializer.ReadUint32(value); | 3341 return private_->deserializer.ReadUint32(value); |
| 3321 } | 3342 } |
| 3322 | 3343 |
| 3323 bool ValueDeserializer::ReadUint64(uint64_t* value) { | 3344 bool ValueDeserializer::ReadUint64(uint64_t* value) { |
| 3324 return private_->deserializer.ReadUint64(value); | 3345 return private_->deserializer.ReadUint64(value); |
| 3325 } | 3346 } |
| 3326 | 3347 |
| 3327 bool ValueDeserializer::ReadDouble(double* value) { | 3348 bool ValueDeserializer::ReadDouble(double* value) { |
| 3328 return private_->deserializer.ReadDouble(value); | 3349 return private_->deserializer.ReadDouble(value); |
| (...skipping 4181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7510 | 7531 |
| 7511 Local<String> WasmCompiledModule::GetWasmWireBytes() { | 7532 Local<String> WasmCompiledModule::GetWasmWireBytes() { |
| 7512 i::Handle<i::JSObject> obj = | 7533 i::Handle<i::JSObject> obj = |
| 7513 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 7534 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |
| 7514 i::Handle<i::WasmCompiledModule> compiled_part = | 7535 i::Handle<i::WasmCompiledModule> compiled_part = |
| 7515 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); | 7536 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); |
| 7516 i::Handle<i::String> wire_bytes(compiled_part->module_bytes()); | 7537 i::Handle<i::String> wire_bytes(compiled_part->module_bytes()); |
| 7517 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); | 7538 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); |
| 7518 } | 7539 } |
| 7519 | 7540 |
| 7541 // Currently, wasm modules are bound, both to Isolate and to |
| 7542 // the Context they were created in. The currently-supported means to |
| 7543 // decontextualize and then re-contextualize a module is via |
| 7544 // serialization/deserialization. |
| 7545 WasmCompiledModule::TransferrableModule |
| 7546 WasmCompiledModule::GetTransferrableModule() { |
| 7547 i::DisallowHeapAllocation no_gc; |
| 7548 WasmCompiledModule::SerializedModule compiled_part = Serialize(); |
| 7549 |
| 7550 Local<String> wire_bytes = GetWasmWireBytes(); |
| 7551 size_t wire_size = static_cast<size_t>(wire_bytes->Length()); |
| 7552 uint8_t* bytes = new uint8_t[wire_size]; |
| 7553 wire_bytes->WriteOneByte(bytes, 0, wire_bytes->Length()); |
| 7554 |
| 7555 return TransferrableModule( |
| 7556 std::move(compiled_part), |
| 7557 std::make_pair( |
| 7558 std::unique_ptr<const uint8_t[]>(const_cast<const uint8_t*>(bytes)), |
| 7559 wire_size)); |
| 7560 } |
| 7561 |
| 7562 MaybeLocal<WasmCompiledModule> WasmCompiledModule::FromTransferrableModule( |
| 7563 Isolate* isolate, |
| 7564 const WasmCompiledModule::TransferrableModule& transferrable_module) { |
| 7565 MaybeLocal<WasmCompiledModule> ret = |
| 7566 Deserialize(isolate, AsCallerOwned(transferrable_module.compiled_code), |
| 7567 AsCallerOwned(transferrable_module.wire_bytes)); |
| 7568 return ret; |
| 7569 } |
| 7570 |
| 7520 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { | 7571 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { |
| 7521 i::Handle<i::JSObject> obj = | 7572 i::Handle<i::JSObject> obj = |
| 7522 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 7573 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |
| 7523 i::Handle<i::WasmCompiledModule> compiled_part = | 7574 i::Handle<i::WasmCompiledModule> compiled_part = |
| 7524 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); | 7575 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); |
| 7525 | 7576 |
| 7526 std::unique_ptr<i::ScriptData> script_data = | 7577 std::unique_ptr<i::ScriptData> script_data = |
| 7527 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), | 7578 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), |
| 7528 compiled_part); | 7579 compiled_part); |
| 7529 script_data->ReleaseDataOwnership(); | 7580 script_data->ReleaseDataOwnership(); |
| (...skipping 2723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10253 Address callback_address = | 10304 Address callback_address = |
| 10254 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10305 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 10255 VMState<EXTERNAL> state(isolate); | 10306 VMState<EXTERNAL> state(isolate); |
| 10256 ExternalCallbackScope call_scope(isolate, callback_address); | 10307 ExternalCallbackScope call_scope(isolate, callback_address); |
| 10257 callback(info); | 10308 callback(info); |
| 10258 } | 10309 } |
| 10259 | 10310 |
| 10260 | 10311 |
| 10261 } // namespace internal | 10312 } // namespace internal |
| 10262 } // namespace v8 | 10313 } // namespace v8 |
| OLD | NEW |