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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) | 75 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) |
76 | 76 |
77 | 77 |
78 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \ | 78 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \ |
79 bailout_value, HandleScopeClass, \ | 79 bailout_value, HandleScopeClass, \ |
80 do_callback) \ | 80 do_callback) \ |
81 if (IsExecutionTerminatingCheck(isolate)) { \ | 81 if (IsExecutionTerminatingCheck(isolate)) { \ |
82 return bailout_value; \ | 82 return bailout_value; \ |
83 } \ | 83 } \ |
84 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); \ | |
85 HandleScopeClass handle_scope(isolate); \ | 84 HandleScopeClass handle_scope(isolate); \ |
86 CallDepthScope call_depth_scope(isolate, context, do_callback); \ | 85 CallDepthScope call_depth_scope(isolate, context, do_callback); \ |
87 LOG_API(isolate, function_name); \ | 86 LOG_API(isolate, function_name); \ |
88 ENTER_V8(isolate); \ | 87 ENTER_V8(isolate); \ |
89 bool has_pending_exception = false | 88 bool has_pending_exception = false |
90 | 89 |
91 | 90 |
92 #define PREPARE_FOR_EXECUTION_WITH_CONTEXT( \ | 91 #define PREPARE_FOR_EXECUTION_WITH_CONTEXT( \ |
93 context, function_name, bailout_value, HandleScopeClass, do_callback) \ | 92 context, function_name, bailout_value, HandleScopeClass, do_callback) \ |
94 auto isolate = context.IsEmpty() \ | 93 auto isolate = context.IsEmpty() \ |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 Local<Context> context_; | 206 Local<Context> context_; |
208 bool escaped_; | 207 bool escaped_; |
209 bool do_callback_; | 208 bool do_callback_; |
210 }; | 209 }; |
211 | 210 |
212 } // namespace | 211 } // namespace |
213 | 212 |
214 | 213 |
215 static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate, | 214 static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate, |
216 i::Handle<i::Script> script) { | 215 i::Handle<i::Script> script) { |
217 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); | |
218 i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script)); | 216 i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script)); |
219 i::Handle<i::Object> source_map_url(script->source_mapping_url(), isolate); | 217 i::Handle<i::Object> source_map_url(script->source_mapping_url(), isolate); |
220 v8::Isolate* v8_isolate = | 218 v8::Isolate* v8_isolate = |
221 reinterpret_cast<v8::Isolate*>(script->GetIsolate()); | 219 reinterpret_cast<v8::Isolate*>(script->GetIsolate()); |
222 ScriptOriginOptions options(script->origin_options()); | 220 ScriptOriginOptions options(script->origin_options()); |
223 v8::ScriptOrigin origin( | 221 v8::ScriptOrigin origin( |
224 Utils::ToLocal(scriptName), | 222 Utils::ToLocal(scriptName), |
225 v8::Integer::New(v8_isolate, script->line_offset()), | 223 v8::Integer::New(v8_isolate, script->line_offset()), |
226 v8::Integer::New(v8_isolate, script->column_offset()), | 224 v8::Integer::New(v8_isolate, script->column_offset()), |
227 v8::Boolean::New(v8_isolate, options.IsSharedCrossOrigin()), | 225 v8::Boolean::New(v8_isolate, options.IsSharedCrossOrigin()), |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 }; | 384 }; |
387 | 385 |
388 } // namespace | 386 } // namespace |
389 | 387 |
390 | 388 |
391 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { | 389 StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { |
392 i::Isolate* internal_isolate = new i::Isolate(true); | 390 i::Isolate* internal_isolate = new i::Isolate(true); |
393 ArrayBufferAllocator allocator; | 391 ArrayBufferAllocator allocator; |
394 internal_isolate->set_array_buffer_allocator(&allocator); | 392 internal_isolate->set_array_buffer_allocator(&allocator); |
395 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); | 393 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); |
396 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); | |
397 StartupData result = {NULL, 0}; | 394 StartupData result = {NULL, 0}; |
398 { | 395 { |
399 base::ElapsedTimer timer; | 396 base::ElapsedTimer timer; |
400 timer.Start(); | 397 timer.Start(); |
401 Isolate::Scope isolate_scope(isolate); | 398 Isolate::Scope isolate_scope(isolate); |
402 internal_isolate->Init(NULL); | 399 internal_isolate->Init(NULL); |
403 Persistent<Context> context; | 400 Persistent<Context> context; |
404 i::Snapshot::Metadata metadata; | 401 i::Snapshot::Metadata metadata; |
405 { | 402 { |
406 HandleScope handle_scope(isolate); | 403 HandleScope handle_scope(isolate); |
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 CompileOptions options) { | 1844 CompileOptions options) { |
1848 auto context = v8_isolate->GetCurrentContext(); | 1845 auto context = v8_isolate->GetCurrentContext(); |
1849 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script); | 1846 RETURN_TO_LOCAL_UNCHECKED(Compile(context, source, options), Script); |
1850 } | 1847 } |
1851 | 1848 |
1852 | 1849 |
1853 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, | 1850 MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, |
1854 Source* source, | 1851 Source* source, |
1855 CompileOptions options) { | 1852 CompileOptions options) { |
1856 auto isolate = context->GetIsolate(); | 1853 auto isolate = context->GetIsolate(); |
1857 TRACE_EVENT_SCOPED_CONTEXT("V8", "Isolate", isolate); | |
1858 auto maybe = CompileUnboundInternal(isolate, source, options, true); | 1854 auto maybe = CompileUnboundInternal(isolate, source, options, true); |
1859 Local<UnboundScript> generic; | 1855 Local<UnboundScript> generic; |
1860 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); | 1856 if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); |
1861 v8::Context::Scope scope(context); | 1857 v8::Context::Scope scope(context); |
1862 return generic->BindToCurrentContext(); | 1858 return generic->BindToCurrentContext(); |
1863 } | 1859 } |
1864 | 1860 |
1865 | 1861 |
1866 class IsIdentifierHelper { | 1862 class IsIdentifierHelper { |
1867 public: | 1863 public: |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2274 void v8::TryCatch::SetCaptureMessage(bool value) { | 2270 void v8::TryCatch::SetCaptureMessage(bool value) { |
2275 capture_message_ = value; | 2271 capture_message_ = value; |
2276 } | 2272 } |
2277 | 2273 |
2278 | 2274 |
2279 // --- M e s s a g e --- | 2275 // --- M e s s a g e --- |
2280 | 2276 |
2281 | 2277 |
2282 Local<String> Message::Get() const { | 2278 Local<String> Message::Get() const { |
2283 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2279 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2284 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); | |
2285 ENTER_V8(isolate); | 2280 ENTER_V8(isolate); |
2286 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2281 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
2287 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 2282 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
2288 i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj); | 2283 i::Handle<i::String> raw_result = i::MessageHandler::GetMessage(isolate, obj); |
2289 Local<String> result = Utils::ToLocal(raw_result); | 2284 Local<String> result = Utils::ToLocal(raw_result); |
2290 return scope.Escape(result); | 2285 return scope.Escape(result); |
2291 } | 2286 } |
2292 | 2287 |
2293 | 2288 |
2294 ScriptOrigin Message::GetScriptOrigin() const { | 2289 ScriptOrigin Message::GetScriptOrigin() const { |
2295 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2290 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2296 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); | 2291 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
2297 auto script_wraper = i::Handle<i::Object>(message->script(), isolate); | 2292 auto script_wraper = i::Handle<i::Object>(message->script(), isolate); |
2298 auto script_value = i::Handle<i::JSValue>::cast(script_wraper); | 2293 auto script_value = i::Handle<i::JSValue>::cast(script_wraper); |
2299 i::Handle<i::Script> script(i::Script::cast(script_value->value())); | 2294 i::Handle<i::Script> script(i::Script::cast(script_value->value())); |
2300 return GetScriptOriginForScript(isolate, script); | 2295 return GetScriptOriginForScript(isolate, script); |
2301 } | 2296 } |
2302 | 2297 |
2303 | 2298 |
2304 v8::Local<Value> Message::GetScriptResourceName() const { | 2299 v8::Local<Value> Message::GetScriptResourceName() const { |
2305 return GetScriptOrigin().ResourceName(); | 2300 return GetScriptOrigin().ResourceName(); |
2306 } | 2301 } |
2307 | 2302 |
2308 | 2303 |
2309 v8::Local<v8::StackTrace> Message::GetStackTrace() const { | 2304 v8::Local<v8::StackTrace> Message::GetStackTrace() const { |
2310 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2305 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2311 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); | |
2312 ENTER_V8(isolate); | 2306 ENTER_V8(isolate); |
2313 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2307 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
2314 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); | 2308 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
2315 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); | 2309 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); |
2316 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>(); | 2310 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>(); |
2317 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj); | 2311 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj); |
2318 return scope.Escape(Utils::StackTraceToLocal(stackTrace)); | 2312 return scope.Escape(Utils::StackTraceToLocal(stackTrace)); |
2319 } | 2313 } |
2320 | 2314 |
2321 | 2315 |
(...skipping 3209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5531 // Leave V8. | 5525 // Leave V8. |
5532 | 5526 |
5533 return env; | 5527 return env; |
5534 } | 5528 } |
5535 | 5529 |
5536 Local<Context> v8::Context::New(v8::Isolate* external_isolate, | 5530 Local<Context> v8::Context::New(v8::Isolate* external_isolate, |
5537 v8::ExtensionConfiguration* extensions, | 5531 v8::ExtensionConfiguration* extensions, |
5538 v8::Local<ObjectTemplate> global_template, | 5532 v8::Local<ObjectTemplate> global_template, |
5539 v8::Local<Value> global_object) { | 5533 v8::Local<Value> global_object) { |
5540 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); | 5534 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); |
5541 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); | |
5542 LOG_API(isolate, "Context::New"); | 5535 LOG_API(isolate, "Context::New"); |
5543 i::HandleScope scope(isolate); | 5536 i::HandleScope scope(isolate); |
5544 ExtensionConfiguration no_extensions; | 5537 ExtensionConfiguration no_extensions; |
5545 if (extensions == NULL) extensions = &no_extensions; | 5538 if (extensions == NULL) extensions = &no_extensions; |
5546 i::Handle<i::Context> env = | 5539 i::Handle<i::Context> env = |
5547 CreateEnvironment(isolate, extensions, global_template, global_object); | 5540 CreateEnvironment(isolate, extensions, global_template, global_object); |
5548 if (env.is_null()) { | 5541 if (env.is_null()) { |
5549 if (isolate->has_pending_exception()) { | 5542 if (isolate->has_pending_exception()) { |
5550 isolate->OptionalRescheduleException(true); | 5543 isolate->OptionalRescheduleException(true); |
5551 } | 5544 } |
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7170 | 7163 |
7171 Isolate* Isolate::GetCurrent() { | 7164 Isolate* Isolate::GetCurrent() { |
7172 i::Isolate* isolate = i::Isolate::Current(); | 7165 i::Isolate* isolate = i::Isolate::Current(); |
7173 return reinterpret_cast<Isolate*>(isolate); | 7166 return reinterpret_cast<Isolate*>(isolate); |
7174 } | 7167 } |
7175 | 7168 |
7176 | 7169 |
7177 Isolate* Isolate::New(const Isolate::CreateParams& params) { | 7170 Isolate* Isolate::New(const Isolate::CreateParams& params) { |
7178 i::Isolate* isolate = new i::Isolate(false); | 7171 i::Isolate* isolate = new i::Isolate(false); |
7179 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); | 7172 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); |
7180 TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); | |
7181 CHECK(params.array_buffer_allocator != NULL); | 7173 CHECK(params.array_buffer_allocator != NULL); |
7182 isolate->set_array_buffer_allocator(params.array_buffer_allocator); | 7174 isolate->set_array_buffer_allocator(params.array_buffer_allocator); |
7183 if (params.snapshot_blob != NULL) { | 7175 if (params.snapshot_blob != NULL) { |
7184 isolate->set_snapshot_blob(params.snapshot_blob); | 7176 isolate->set_snapshot_blob(params.snapshot_blob); |
7185 } else { | 7177 } else { |
7186 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob()); | 7178 isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob()); |
7187 } | 7179 } |
7188 if (params.entry_hook) { | 7180 if (params.entry_hook) { |
7189 isolate->set_function_entry_hook(params.entry_hook); | 7181 isolate->set_function_entry_hook(params.entry_hook); |
7190 } | 7182 } |
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8693 Address callback_address = | 8685 Address callback_address = |
8694 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8686 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8695 VMState<EXTERNAL> state(isolate); | 8687 VMState<EXTERNAL> state(isolate); |
8696 ExternalCallbackScope call_scope(isolate, callback_address); | 8688 ExternalCallbackScope call_scope(isolate, callback_address); |
8697 callback(info); | 8689 callback(info); |
8698 } | 8690 } |
8699 | 8691 |
8700 | 8692 |
8701 } // namespace internal | 8693 } // namespace internal |
8702 } // namespace v8 | 8694 } // namespace v8 |
OLD | NEW |