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 7166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7177 PREPARE_FOR_EXECUTION(context, Proxy, New, Proxy); | 7177 PREPARE_FOR_EXECUTION(context, Proxy, New, Proxy); |
| 7178 i::Handle<i::JSReceiver> target = Utils::OpenHandle(*local_target); | 7178 i::Handle<i::JSReceiver> target = Utils::OpenHandle(*local_target); |
| 7179 i::Handle<i::JSReceiver> handler = Utils::OpenHandle(*local_handler); | 7179 i::Handle<i::JSReceiver> handler = Utils::OpenHandle(*local_handler); |
| 7180 Local<Proxy> result; | 7180 Local<Proxy> result; |
| 7181 has_pending_exception = | 7181 has_pending_exception = |
| 7182 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result); | 7182 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result); |
| 7183 RETURN_ON_FAILED_EXECUTION(Proxy); | 7183 RETURN_ON_FAILED_EXECUTION(Proxy); |
| 7184 RETURN_ESCAPED(result); | 7184 RETURN_ESCAPED(result); |
| 7185 } | 7185 } |
| 7186 | 7186 |
| 7187 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { | 7187 Local<String> WasmCompiledModule::GetUncompiledBytes() { |
| 7188 i::Handle<i::JSObject> obj = | 7188 i::Handle<i::JSObject> obj = |
| 7189 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 7189 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |
| 7190 i::Handle<i::FixedArray> compiled_part = | 7190 i::Handle<i::wasm::WasmCompiledModule> compiled_part = |
| 7191 i::handle(i::FixedArray::cast(obj->GetInternalField(0))); | 7191 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0))); |
| 7192 return Local<String>::Cast(Utils::ToLocal(compiled_part->module_bytes())); | |
| 7193 } | |
| 7194 | |
| 7195 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { | |
| 7196 class WasmCompiledModuleRawBytesManager { | |
| 7197 public: | |
| 7198 WasmCompiledModuleRawBytesManager( | |
| 7199 i::Handle<i::wasm::WasmCompiledModule> wasm_module) | |
| 7200 : module_(wasm_module), bytes_(wasm_module->module_bytes()) { | |
| 7201 module_->reset_module_bytes(); | |
| 7202 } | |
| 7203 | |
| 7204 ~WasmCompiledModuleRawBytesManager() { module_->set_module_bytes(bytes_); } | |
| 7205 | |
| 7206 private: | |
| 7207 i::Handle<i::wasm::WasmCompiledModule> module_; | |
| 7208 i::Handle<i::String> bytes_; | |
| 7209 }; | |
| 7210 | |
| 7211 i::Handle<i::JSObject> obj = | |
| 7212 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | |
| 7213 i::Handle<i::wasm::WasmCompiledModule> compiled_part = | |
| 7214 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0))); | |
| 7215 | |
| 7216 WasmCompiledModuleRawBytesManager ensure_clean_serialization(compiled_part); | |
|
Yang
2016/10/06 07:35:34
what's the advantage of this over of simply take c
vogelheim
2016/10/06 10:00:50
Agree w/ Yang.
Also, in case we do want to keep t
Mircea Trofin
2016/10/06 16:17:47
Initially I thought there may be error cases to de
| |
| 7192 std::unique_ptr<i::ScriptData> script_data = | 7217 std::unique_ptr<i::ScriptData> script_data = |
| 7193 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), | 7218 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), |
| 7194 compiled_part); | 7219 compiled_part); |
| 7195 script_data->ReleaseDataOwnership(); | 7220 script_data->ReleaseDataOwnership(); |
| 7221 | |
| 7196 size_t size = static_cast<size_t>(script_data->length()); | 7222 size_t size = static_cast<size_t>(script_data->length()); |
| 7197 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; | 7223 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; |
| 7198 } | 7224 } |
| 7199 | 7225 |
| 7200 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( | 7226 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( |
| 7201 Isolate* isolate, | 7227 Isolate* isolate, |
| 7202 const WasmCompiledModule::SerializedModule& serialized_data) { | 7228 const WasmCompiledModule::SerializedModule& serialized_data, |
| 7229 Local<String> uncompiled_bytes) { | |
| 7203 int size = static_cast<int>(serialized_data.second); | 7230 int size = static_cast<int>(serialized_data.second); |
| 7204 i::ScriptData sc(serialized_data.first.get(), size); | 7231 i::ScriptData sc(serialized_data.first.get(), size); |
| 7205 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7232 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 7206 i::MaybeHandle<i::FixedArray> maybe_compiled_part = | 7233 i::MaybeHandle<i::FixedArray> maybe_compiled_part = |
| 7207 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); | 7234 i::WasmCompiledModuleSerializer::DeserializeWasmModule(i_isolate, &sc); |
| 7208 i::Handle<i::FixedArray> compiled_part; | 7235 i::Handle<i::FixedArray> compiled_part; |
| 7209 if (!maybe_compiled_part.ToHandle(&compiled_part)) { | 7236 if (!maybe_compiled_part.ToHandle(&compiled_part)) { |
| 7210 return MaybeLocal<WasmCompiledModule>(); | 7237 return Compile(isolate, uncompiled_bytes); |
| 7211 } | 7238 } |
| 7239 i::Handle<i::wasm::WasmCompiledModule> compiled_module = | |
| 7240 handle(i::wasm::WasmCompiledModule::cast(*compiled_part)); | |
| 7241 i::Handle<i::String> module_bytes = Utils::OpenHandle(*uncompiled_bytes); | |
| 7242 compiled_module->set_module_bytes(module_bytes); | |
| 7212 return Local<WasmCompiledModule>::Cast( | 7243 return Local<WasmCompiledModule>::Cast( |
| 7213 Utils::ToLocal(i::wasm::CreateCompiledModuleObject( | 7244 Utils::ToLocal(i::wasm::CreateCompiledModuleObject( |
| 7214 i_isolate, compiled_part, i::wasm::ModuleOrigin::kWasmOrigin))); | 7245 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin))); |
| 7246 } | |
| 7247 | |
| 7248 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile( | |
| 7249 Isolate* isolate, Local<String> bytes) { | |
| 7250 i::Handle<i::String> module_bytes = Utils::OpenHandle(*bytes); | |
| 7251 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | |
| 7252 // if we cannot deserialize, we recompile | |
|
vogelheim
2016/10/06 10:00:50
Doesn't that comment belongs into DeserializeOrCom
Mircea Trofin
2016/10/06 16:17:47
yes.
| |
| 7253 i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()"); | |
| 7254 i::SeqOneByteString* data = i::SeqOneByteString::cast(*module_bytes); | |
| 7255 i::MaybeHandle<i::JSObject> maybe_compiled = | |
| 7256 i::wasm::CreateModuleObjectFromBytes( | |
| 7257 i_isolate, data->GetChars(), data->GetChars() + data->length(), | |
| 7258 &thrower, i::wasm::ModuleOrigin::kWasmOrigin); | |
| 7259 if (maybe_compiled.is_null()) return MaybeLocal<WasmCompiledModule>(); | |
| 7260 return Local<WasmCompiledModule>::Cast( | |
| 7261 Utils::ToLocal(maybe_compiled.ToHandleChecked())); | |
| 7215 } | 7262 } |
| 7216 | 7263 |
| 7217 // static | 7264 // static |
| 7218 v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() { | 7265 v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator() { |
| 7219 return new ArrayBufferAllocator(); | 7266 return new ArrayBufferAllocator(); |
| 7220 } | 7267 } |
| 7221 | 7268 |
| 7222 bool v8::ArrayBuffer::IsExternal() const { | 7269 bool v8::ArrayBuffer::IsExternal() const { |
| 7223 return Utils::OpenHandle(this)->is_external(); | 7270 return Utils::OpenHandle(this)->is_external(); |
| 7224 } | 7271 } |
| (...skipping 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9375 Address callback_address = | 9422 Address callback_address = |
| 9376 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9423 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 9377 VMState<EXTERNAL> state(isolate); | 9424 VMState<EXTERNAL> state(isolate); |
| 9378 ExternalCallbackScope call_scope(isolate, callback_address); | 9425 ExternalCallbackScope call_scope(isolate, callback_address); |
| 9379 callback(info); | 9426 callback(info); |
| 9380 } | 9427 } |
| 9381 | 9428 |
| 9382 | 9429 |
| 9383 } // namespace internal | 9430 } // namespace internal |
| 9384 } // namespace v8 | 9431 } // namespace v8 |
| OLD | NEW |