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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 #include "src/snapshot/snapshot.h" | 66 #include "src/snapshot/snapshot.h" |
67 #include "src/startup-data-util.h" | 67 #include "src/startup-data-util.h" |
68 #include "src/tracing/trace-event.h" | 68 #include "src/tracing/trace-event.h" |
69 #include "src/unicode-inl.h" | 69 #include "src/unicode-inl.h" |
70 #include "src/v8.h" | 70 #include "src/v8.h" |
71 #include "src/v8threads.h" | 71 #include "src/v8threads.h" |
72 #include "src/value-serializer.h" | 72 #include "src/value-serializer.h" |
73 #include "src/version.h" | 73 #include "src/version.h" |
74 #include "src/vm-state-inl.h" | 74 #include "src/vm-state-inl.h" |
75 #include "src/wasm/wasm-module.h" | 75 #include "src/wasm/wasm-module.h" |
| 76 #include "src/wasm/wasm-objects.h" |
76 #include "src/wasm/wasm-result.h" | 77 #include "src/wasm/wasm-result.h" |
77 | 78 |
78 namespace v8 { | 79 namespace v8 { |
79 | 80 |
80 #define LOG_API(isolate, class_name, function_name) \ | 81 #define LOG_API(isolate, class_name, function_name) \ |
81 i::RuntimeCallTimerScope _runtime_timer( \ | 82 i::RuntimeCallTimerScope _runtime_timer( \ |
82 isolate, &i::RuntimeCallStats::API_##class_name##_##function_name); \ | 83 isolate, &i::RuntimeCallStats::API_##class_name##_##function_name); \ |
83 LOG(isolate, ApiEntryCall("v8::" #class_name "::" #function_name)) | 84 LOG(isolate, ApiEntryCall("v8::" #class_name "::" #function_name)) |
84 | 85 |
85 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) | 86 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) |
(...skipping 7144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7230 Local<Proxy> result; | 7231 Local<Proxy> result; |
7231 has_pending_exception = | 7232 has_pending_exception = |
7232 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result); | 7233 !ToLocal<Proxy>(i::JSProxy::New(isolate, target, handler), &result); |
7233 RETURN_ON_FAILED_EXECUTION(Proxy); | 7234 RETURN_ON_FAILED_EXECUTION(Proxy); |
7234 RETURN_ESCAPED(result); | 7235 RETURN_ESCAPED(result); |
7235 } | 7236 } |
7236 | 7237 |
7237 Local<String> WasmCompiledModule::GetWasmWireBytes() { | 7238 Local<String> WasmCompiledModule::GetWasmWireBytes() { |
7238 i::Handle<i::JSObject> obj = | 7239 i::Handle<i::JSObject> obj = |
7239 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 7240 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |
7240 i::Handle<i::wasm::WasmCompiledModule> compiled_part = | 7241 i::Handle<i::WasmCompiledModule> compiled_part = |
7241 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0))); | 7242 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); |
7242 i::Handle<i::String> wire_bytes = compiled_part->module_bytes(); | 7243 i::Handle<i::String> wire_bytes = compiled_part->module_bytes(); |
7243 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); | 7244 return Local<String>::Cast(Utils::ToLocal(wire_bytes)); |
7244 } | 7245 } |
7245 | 7246 |
7246 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { | 7247 WasmCompiledModule::SerializedModule WasmCompiledModule::Serialize() { |
7247 i::Handle<i::JSObject> obj = | 7248 i::Handle<i::JSObject> obj = |
7248 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); | 7249 i::Handle<i::JSObject>::cast(Utils::OpenHandle(this)); |
7249 i::Handle<i::wasm::WasmCompiledModule> compiled_part = | 7250 i::Handle<i::WasmCompiledModule> compiled_part = |
7250 i::handle(i::wasm::WasmCompiledModule::cast(obj->GetInternalField(0))); | 7251 i::handle(i::WasmCompiledModule::cast(obj->GetInternalField(0))); |
7251 | 7252 |
7252 std::unique_ptr<i::ScriptData> script_data = | 7253 std::unique_ptr<i::ScriptData> script_data = |
7253 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), | 7254 i::WasmCompiledModuleSerializer::SerializeWasmModule(obj->GetIsolate(), |
7254 compiled_part); | 7255 compiled_part); |
7255 script_data->ReleaseDataOwnership(); | 7256 script_data->ReleaseDataOwnership(); |
7256 | 7257 |
7257 size_t size = static_cast<size_t>(script_data->length()); | 7258 size_t size = static_cast<size_t>(script_data->length()); |
7258 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; | 7259 return {std::unique_ptr<const uint8_t[]>(script_data->data()), size}; |
7259 } | 7260 } |
7260 | 7261 |
7261 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( | 7262 MaybeLocal<WasmCompiledModule> WasmCompiledModule::Deserialize( |
7262 Isolate* isolate, | 7263 Isolate* isolate, |
7263 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, | 7264 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, |
7264 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { | 7265 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { |
7265 int size = static_cast<int>(serialized_module.second); | 7266 int size = static_cast<int>(serialized_module.second); |
7266 i::ScriptData sc(serialized_module.first, size); | 7267 i::ScriptData sc(serialized_module.first, size); |
7267 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 7268 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
7268 i::MaybeHandle<i::FixedArray> maybe_compiled_part = | 7269 i::MaybeHandle<i::FixedArray> maybe_compiled_part = |
7269 i::WasmCompiledModuleSerializer::DeserializeWasmModule( | 7270 i::WasmCompiledModuleSerializer::DeserializeWasmModule( |
7270 i_isolate, &sc, | 7271 i_isolate, &sc, |
7271 {wire_bytes.first, static_cast<int>(wire_bytes.second)}); | 7272 {wire_bytes.first, static_cast<int>(wire_bytes.second)}); |
7272 i::Handle<i::FixedArray> compiled_part; | 7273 i::Handle<i::FixedArray> compiled_part; |
7273 if (!maybe_compiled_part.ToHandle(&compiled_part)) { | 7274 if (!maybe_compiled_part.ToHandle(&compiled_part)) { |
7274 return MaybeLocal<WasmCompiledModule>(); | 7275 return MaybeLocal<WasmCompiledModule>(); |
7275 } | 7276 } |
7276 i::Handle<i::wasm::WasmCompiledModule> compiled_module = | 7277 i::Handle<i::WasmCompiledModule> compiled_module = |
7277 handle(i::wasm::WasmCompiledModule::cast(*compiled_part)); | 7278 handle(i::WasmCompiledModule::cast(*compiled_part)); |
7278 return Local<WasmCompiledModule>::Cast( | 7279 return Local<WasmCompiledModule>::Cast( |
7279 Utils::ToLocal(i::wasm::CreateWasmModuleObject( | 7280 Utils::ToLocal(i::Handle<i::JSObject>::cast( |
7280 i_isolate, compiled_module, i::wasm::ModuleOrigin::kWasmOrigin))); | 7281 i::WasmModuleObject::New(i_isolate, compiled_module)))); |
7281 } | 7282 } |
7282 | 7283 |
7283 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( | 7284 MaybeLocal<WasmCompiledModule> WasmCompiledModule::DeserializeOrCompile( |
7284 Isolate* isolate, | 7285 Isolate* isolate, |
7285 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, | 7286 const WasmCompiledModule::CallerOwnedBuffer& serialized_module, |
7286 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { | 7287 const WasmCompiledModule::CallerOwnedBuffer& wire_bytes) { |
7287 MaybeLocal<WasmCompiledModule> ret = | 7288 MaybeLocal<WasmCompiledModule> ret = |
7288 Deserialize(isolate, serialized_module, wire_bytes); | 7289 Deserialize(isolate, serialized_module, wire_bytes); |
7289 if (!ret.IsEmpty()) { | 7290 if (!ret.IsEmpty()) { |
7290 return ret; | 7291 return ret; |
(...skipping 2473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9764 Address callback_address = | 9765 Address callback_address = |
9765 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9766 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9766 VMState<EXTERNAL> state(isolate); | 9767 VMState<EXTERNAL> state(isolate); |
9767 ExternalCallbackScope call_scope(isolate, callback_address); | 9768 ExternalCallbackScope call_scope(isolate, callback_address); |
9768 callback(info); | 9769 callback(info); |
9769 } | 9770 } |
9770 | 9771 |
9771 | 9772 |
9772 } // namespace internal | 9773 } // namespace internal |
9773 } // namespace v8 | 9774 } // namespace v8 |
OLD | NEW |