Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 DCHECK(!resource->ErrorOccurred()); | 409 DCHECK(!resource->ErrorOccurred()); |
| 410 DCHECK(streamer->IsFinished()); | 410 DCHECK(streamer->IsFinished()); |
| 411 DCHECK(!streamer->StreamingSuppressed()); | 411 DCHECK(!streamer->StreamingSuppressed()); |
| 412 return WTF::Bind(PostStreamCompile, cache_options, | 412 return WTF::Bind(PostStreamCompile, cache_options, |
| 413 WrapPersistent(resource->CacheHandler()), | 413 WrapPersistent(resource->CacheHandler()), |
| 414 WrapPersistent(streamer)); | 414 WrapPersistent(streamer)); |
| 415 } | 415 } |
| 416 } // namespace | 416 } // namespace |
| 417 | 417 |
| 418 v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript( | 418 v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript( |
| 419 ExecutionContext* context, | |
| 419 const ScriptSourceCode& source, | 420 const ScriptSourceCode& source, |
| 420 v8::Isolate* isolate, | 421 v8::Isolate* isolate, |
| 421 AccessControlStatus access_control_status, | 422 AccessControlStatus access_control_status, |
| 422 V8CacheOptions cache_options) { | 423 V8CacheOptions cache_options) { |
| 423 if (source.Source().length() >= v8::String::kMaxLength) { | 424 if (source.Source().length() >= v8::String::kMaxLength) { |
| 424 V8ThrowException::ThrowError(isolate, "Source file too large."); | 425 V8ThrowException::ThrowError(isolate, "Source file too large."); |
| 425 return v8::Local<v8::Script>(); | 426 return v8::Local<v8::Script>(); |
| 426 } | 427 } |
| 427 return CompileScript( | 428 return CompileScript( |
| 428 V8String(isolate, source.Source()), source.Url(), source.SourceMapUrl(), | 429 context, V8String(isolate, source.Source()), source.Url(), |
| 429 source.StartPosition(), isolate, source.GetResource(), source.Streamer(), | 430 source.SourceMapUrl(), source.StartPosition(), isolate, |
| 431 source.GetResource(), source.Streamer(), | |
| 430 source.GetResource() ? source.GetResource()->CacheHandler() : nullptr, | 432 source.GetResource() ? source.GetResource()->CacheHandler() : nullptr, |
| 431 access_control_status, cache_options); | 433 access_control_status, cache_options); |
| 432 } | 434 } |
| 433 | 435 |
| 434 v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript( | 436 v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript( |
| 437 ExecutionContext* context, | |
| 435 const String& code, | 438 const String& code, |
| 436 const String& file_name, | 439 const String& file_name, |
| 437 const String& source_map_url, | 440 const String& source_map_url, |
| 438 const TextPosition& text_position, | 441 const TextPosition& text_position, |
| 439 v8::Isolate* isolate, | 442 v8::Isolate* isolate, |
| 440 CachedMetadataHandler* cache_metadata_handler, | 443 CachedMetadataHandler* cache_metadata_handler, |
| 441 AccessControlStatus access_control_status, | 444 AccessControlStatus access_control_status, |
| 442 V8CacheOptions v8_cache_options) { | 445 V8CacheOptions v8_cache_options) { |
| 443 if (code.length() >= v8::String::kMaxLength) { | 446 if (code.length() >= v8::String::kMaxLength) { |
| 444 V8ThrowException::ThrowError(isolate, "Source file too large."); | 447 V8ThrowException::ThrowError(isolate, "Source file too large."); |
| 445 return v8::Local<v8::Script>(); | 448 return v8::Local<v8::Script>(); |
| 446 } | 449 } |
| 447 return CompileScript(V8String(isolate, code), file_name, source_map_url, | 450 return CompileScript(context, V8String(isolate, code), file_name, |
| 448 text_position, isolate, nullptr, nullptr, | 451 source_map_url, text_position, isolate, nullptr, nullptr, |
| 449 cache_metadata_handler, access_control_status, | 452 cache_metadata_handler, access_control_status, |
| 450 v8_cache_options); | 453 v8_cache_options); |
| 451 } | 454 } |
| 452 | 455 |
| 453 v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript( | 456 v8::MaybeLocal<v8::Script> V8ScriptRunner::CompileScript( |
| 457 ExecutionContext* context, | |
| 454 v8::Local<v8::String> code, | 458 v8::Local<v8::String> code, |
| 455 const String& file_name, | 459 const String& file_name, |
| 456 const String& source_map_url, | 460 const String& source_map_url, |
| 457 const TextPosition& script_start_position, | 461 const TextPosition& script_start_position, |
| 458 v8::Isolate* isolate, | 462 v8::Isolate* isolate, |
| 459 ScriptResource* resource, | 463 ScriptResource* resource, |
| 460 ScriptStreamer* streamer, | 464 ScriptStreamer* streamer, |
| 461 CachedMetadataHandler* cache_handler, | 465 CachedMetadataHandler* cache_handler, |
| 462 AccessControlStatus access_control_status, | 466 AccessControlStatus access_control_status, |
| 463 V8CacheOptions cache_options) { | 467 V8CacheOptions cache_options) { |
| 464 TRACE_EVENT2( | 468 TRACE_EVENT2( |
| 465 "v8,devtools.timeline", "v8.compile", "fileName", file_name.Utf8(), | 469 "v8,devtools.timeline", "v8.compile", "fileName", file_name.Utf8(), |
| 466 "data", | 470 "data", |
| 467 InspectorCompileScriptEvent::Data(file_name, script_start_position)); | 471 InspectorCompileScriptEvent::Data(file_name, script_start_position)); |
| 472 probe::V8Compile probe(context, file_name, | |
| 473 script_start_position.line_.ZeroBasedInt(), | |
| 474 script_start_position.column_.ZeroBasedInt()); | |
| 468 | 475 |
| 469 DCHECK(!streamer || resource); | 476 DCHECK(!streamer || resource); |
| 470 DCHECK(!resource || resource->CacheHandler() == cache_handler); | 477 DCHECK(!resource || resource->CacheHandler() == cache_handler); |
| 471 | 478 |
| 472 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at | 479 // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at |
| 473 // 1, whereas v8 starts at 0. | 480 // 1, whereas v8 starts at 0. |
| 474 v8::ScriptOrigin origin( | 481 v8::ScriptOrigin origin( |
| 475 V8String(isolate, file_name), | 482 V8String(isolate, file_name), |
| 476 v8::Integer::New(isolate, script_start_position.line_.ZeroBasedInt()), | 483 v8::Integer::New(isolate, script_start_position.line_.ZeroBasedInt()), |
| 477 v8::Integer::New(isolate, script_start_position.column_.ZeroBasedInt()), | 484 v8::Integer::New(isolate, script_start_position.column_.ZeroBasedInt()), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 return result; | 587 return result; |
| 581 } | 588 } |
| 582 | 589 |
| 583 v8::MaybeLocal<v8::Value> V8ScriptRunner::CompileAndRunInternalScript( | 590 v8::MaybeLocal<v8::Value> V8ScriptRunner::CompileAndRunInternalScript( |
| 584 v8::Local<v8::String> source, | 591 v8::Local<v8::String> source, |
| 585 v8::Isolate* isolate, | 592 v8::Isolate* isolate, |
| 586 const String& file_name, | 593 const String& file_name, |
| 587 const TextPosition& script_start_position) { | 594 const TextPosition& script_start_position) { |
| 588 v8::Local<v8::Script> script; | 595 v8::Local<v8::Script> script; |
| 589 if (!V8ScriptRunner::CompileScript( | 596 if (!V8ScriptRunner::CompileScript( |
| 590 source, file_name, String(), script_start_position, isolate, nullptr, | 597 ExecutionContext::From(ScriptState::Current(isolate)), source, |
|
haraken
2017/07/17 16:16:24
Alternately can you pass in ExecutionContext* to V
Liquan (Max) Gu
2017/07/17 20:39:52
Done.
| |
| 598 file_name, String(), script_start_position, isolate, nullptr, | |
| 591 nullptr, nullptr, kSharableCrossOrigin, kV8CacheOptionsDefault) | 599 nullptr, nullptr, kSharableCrossOrigin, kV8CacheOptionsDefault) |
| 592 .ToLocal(&script)) | 600 .ToLocal(&script)) |
| 593 return v8::MaybeLocal<v8::Value>(); | 601 return v8::MaybeLocal<v8::Value>(); |
| 594 | 602 |
| 595 TRACE_EVENT0("v8", "v8.run"); | 603 TRACE_EVENT0("v8", "v8.run"); |
| 596 RuntimeCallStatsScopedTracer rcs_scoped_tracer(isolate); | 604 RuntimeCallStatsScopedTracer rcs_scoped_tracer(isolate); |
| 597 RUNTIME_CALL_TIMER_SCOPE(isolate, RuntimeCallStats::CounterId::kV8); | 605 RUNTIME_CALL_TIMER_SCOPE(isolate, RuntimeCallStats::CounterId::kV8); |
| 598 v8::MicrotasksScope microtasks_scope( | 606 v8::MicrotasksScope microtasks_scope( |
| 599 isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); | 607 isolate, v8::MicrotasksScope::kDoNotRunMicrotasks); |
| 600 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()); | 608 v8::MaybeLocal<v8::Value> result = script->Run(isolate->GetCurrentContext()); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 782 if (!context->GetExtrasBindingObject() | 790 if (!context->GetExtrasBindingObject() |
| 783 ->Get(context, V8AtomicString(isolate, name)) | 791 ->Get(context, V8AtomicString(isolate, name)) |
| 784 .ToLocal(&function_value)) | 792 .ToLocal(&function_value)) |
| 785 return v8::MaybeLocal<v8::Value>(); | 793 return v8::MaybeLocal<v8::Value>(); |
| 786 v8::Local<v8::Function> function = function_value.As<v8::Function>(); | 794 v8::Local<v8::Function> function = function_value.As<v8::Function>(); |
| 787 return V8ScriptRunner::CallInternalFunction(function, v8::Undefined(isolate), | 795 return V8ScriptRunner::CallInternalFunction(function, v8::Undefined(isolate), |
| 788 num_args, args, isolate); | 796 num_args, args, isolate); |
| 789 } | 797 } |
| 790 | 798 |
| 791 } // namespace blink | 799 } // namespace blink |
| OLD | NEW |