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 7228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7239 if (!ret.IsEmpty()) return ret; | 7239 if (!ret.IsEmpty()) return ret; |
7240 return Compile(isolate, uncompiled_bytes); | 7240 return Compile(isolate, uncompiled_bytes); |
7241 } | 7241 } |
7242 | 7242 |
7243 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile( | 7243 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile( |
7244 Isolate* isolate, Local<String> bytes) { | 7244 Isolate* isolate, Local<String> bytes) { |
7245 i::Handle<i::String> module_bytes = Utils::OpenHandle(*bytes); | 7245 i::Handle<i::String> module_bytes = Utils::OpenHandle(*bytes); |
7246 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7246 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7247 i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()"); | 7247 i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()"); |
7248 i::SeqOneByteString* data = i::SeqOneByteString::cast(*module_bytes); | 7248 i::SeqOneByteString* data = i::SeqOneByteString::cast(*module_bytes); |
| 7249 // Copy bytes such that GC can not move it during construction of the module. |
| 7250 // TODO(wasm): Avoid this additional copy. |
| 7251 i::ScopedVector<unsigned char> bytes_copy(data->length()); |
| 7252 memcpy(bytes_copy.start(), data->GetChars(), data->length()); |
7249 i::MaybeHandle<i::JSObject> maybe_compiled = | 7253 i::MaybeHandle<i::JSObject> maybe_compiled = |
7250 i::wasm::CreateModuleObjectFromBytes( | 7254 i::wasm::CreateModuleObjectFromBytes( |
7251 i_isolate, data->GetChars(), data->GetChars() + data->length(), | 7255 i_isolate, bytes_copy.start(), |
7252 &thrower, i::wasm::ModuleOrigin::kWasmOrigin); | 7256 bytes_copy.start() + bytes_copy.length(), &thrower, |
| 7257 i::wasm::ModuleOrigin::kWasmOrigin); |
7253 if (maybe_compiled.is_null()) return MaybeLocal<WasmCompiledModule>(); | 7258 if (maybe_compiled.is_null()) return MaybeLocal<WasmCompiledModule>(); |
7254 return Local<WasmCompiledModule>::Cast( | 7259 return Local<WasmCompiledModule>::Cast( |
7255 Utils::ToLocal(maybe_compiled.ToHandleChecked())); | 7260 Utils::ToLocal(maybe_compiled.ToHandleChecked())); |
7256 } | 7261 } |
7257 | 7262 |
7258 // static | 7263 // static |
7259 v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() { | 7264 v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() { |
7260 return new ArrayBufferAllocator(); | 7265 return new ArrayBufferAllocator(); |
7261 } | 7266 } |
7262 | 7267 |
(...skipping 2154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9417 Address callback_address = | 9422 Address callback_address = |
9418 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9423 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9419 VMState<EXTERNAL> state(isolate); | 9424 VMState<EXTERNAL> state(isolate); |
9420 ExternalCallbackScope call_scope(isolate, callback_address); | 9425 ExternalCallbackScope call_scope(isolate, callback_address); |
9421 callback(info); | 9426 callback(info); |
9422 } | 9427 } |
9423 | 9428 |
9424 | 9429 |
9425 } // namespace internal | 9430 } // namespace internal |
9426 } // namespace v8 | 9431 } // namespace v8 |
OLD | NEW |