Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: Source/bindings/core/v8/ScriptController.cpp

Issue 551333002: Fix WebCore.Scripts.ParserBlocking.TimeBetweenLoadedAndCompiled (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/core/v8/ScriptController.h ('k') | Source/core/dom/ScriptLoader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2008, 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2009 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2014 Opera Software ASA. All rights reserved. 4 * Copyright (C) 2014 Opera Software ASA. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 GetDevToolsFunctionInfo(function, isolate, scriptId, resourceName, lineN umber); 159 GetDevToolsFunctionInfo(function, isolate, scriptId, resourceName, lineN umber);
160 cookie = InspectorInstrumentation::willCallFunction(context, scriptId, r esourceName, lineNumber); 160 cookie = InspectorInstrumentation::willCallFunction(context, scriptId, r esourceName, lineNumber);
161 } 161 }
162 162
163 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, context , receiver, argc, info, isolate); 163 v8::Local<v8::Value> result = V8ScriptRunner::callFunction(function, context , receiver, argc, info, isolate);
164 164
165 InspectorInstrumentation::didCallFunction(cookie); 165 InspectorInstrumentation::didCallFunction(cookie);
166 return result; 166 return result;
167 } 167 }
168 168
169 v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Handle<v8 ::Context> context, const ScriptSourceCode& source, AccessControlStatus corsStat us) 169 v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue(v8::Handle<v8 ::Context> context, const ScriptSourceCode& source, AccessControlStatus corsStat us, double* compilationFinishTime)
170 { 170 {
171 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "EvaluateScript ", "data", InspectorEvaluateScriptEvent::data(m_frame, source.url().string(), so urce.startLine())); 171 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "EvaluateScript ", "data", InspectorEvaluateScriptEvent::data(m_frame, source.url().string(), so urce.startLine()));
172 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), " CallStack", "stack", InspectorCallStackEvent::currentCallStack()); 172 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), " CallStack", "stack", InspectorCallStackEvent::currentCallStack());
173 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli ne migrates to tracing. 173 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli ne migrates to tracing.
174 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvalua teScript(m_frame, source.url().string(), source.startLine()); 174 InspectorInstrumentationCookie cookie = InspectorInstrumentation::willEvalua teScript(m_frame, source.url().string(), source.startLine());
175 175
176 v8::Local<v8::Value> result; 176 v8::Local<v8::Value> result;
177 { 177 {
178 V8CacheOptions v8CacheOptions(V8CacheOptionsOff); 178 V8CacheOptions v8CacheOptions(V8CacheOptionsOff);
179 if (m_frame->settings()) 179 if (m_frame->settings())
180 v8CacheOptions = m_frame->settings()->v8CacheOptions(); 180 v8CacheOptions = m_frame->settings()->v8CacheOptions();
181 181
182 // Isolate exceptions that occur when compiling and executing 182 // Isolate exceptions that occur when compiling and executing
183 // the code. These exceptions should not interfere with 183 // the code. These exceptions should not interfere with
184 // javascript code we might evaluate from C++ when returning 184 // javascript code we might evaluate from C++ when returning
185 // from here. 185 // from here.
186 v8::TryCatch tryCatch; 186 v8::TryCatch tryCatch;
187 tryCatch.SetVerbose(true); 187 tryCatch.SetVerbose(true);
188 188
189 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, m_ isolate, corsStatus, v8CacheOptions); 189 v8::Handle<v8::Script> script = V8ScriptRunner::compileScript(source, m_ isolate, corsStatus, v8CacheOptions);
190 190
191 if (compilationFinishTime) {
192 *compilationFinishTime = WTF::monotonicallyIncreasingTime();
193 }
191 // Keep LocalFrame (and therefore ScriptController) alive. 194 // Keep LocalFrame (and therefore ScriptController) alive.
192 RefPtr<LocalFrame> protect(m_frame); 195 RefPtr<LocalFrame> protect(m_frame);
193 result = V8ScriptRunner::runCompiledScript(script, m_frame->document(), m_isolate); 196 result = V8ScriptRunner::runCompiledScript(script, m_frame->document(), m_isolate);
194 ASSERT(!tryCatch.HasCaught() || result.IsEmpty()); 197 ASSERT(!tryCatch.HasCaught() || result.IsEmpty());
195 } 198 }
196 199
197 InspectorInstrumentation::didEvaluateScript(cookie); 200 InspectorInstrumentation::didEvaluateScript(cookie);
198 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", "data", InspectorUpdateCountersEvent::data()); 201 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", "data", InspectorUpdateCountersEvent::data());
199 202
200 return result; 203 return result;
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 m_frame->loader().replaceDocumentWhileExecutingJavaScriptURL(scriptResult, o wnerDocument.get()); 564 m_frame->loader().replaceDocumentWhileExecutingJavaScriptURL(scriptResult, o wnerDocument.get());
562 return true; 565 return true;
563 } 566 }
564 567
565 void ScriptController::executeScriptInMainWorld(const String& script, ExecuteScr iptPolicy policy) 568 void ScriptController::executeScriptInMainWorld(const String& script, ExecuteScr iptPolicy policy)
566 { 569 {
567 v8::HandleScope handleScope(m_isolate); 570 v8::HandleScope handleScope(m_isolate);
568 evaluateScriptInMainWorld(ScriptSourceCode(script), NotSharableCrossOrigin, policy); 571 evaluateScriptInMainWorld(ScriptSourceCode(script), NotSharableCrossOrigin, policy);
569 } 572 }
570 573
571 void ScriptController::executeScriptInMainWorld(const ScriptSourceCode& sourceCo de, AccessControlStatus corsStatus) 574 void ScriptController::executeScriptInMainWorld(const ScriptSourceCode& sourceCo de, AccessControlStatus corsStatus, double* compilationFinishTime)
572 { 575 {
573 v8::HandleScope handleScope(m_isolate); 576 v8::HandleScope handleScope(m_isolate);
574 evaluateScriptInMainWorld(sourceCode, corsStatus, DoNotExecuteScriptWhenScri ptsDisabled); 577 evaluateScriptInMainWorld(sourceCode, corsStatus, DoNotExecuteScriptWhenScri ptsDisabled, compilationFinishTime);
575 } 578 }
576 579
577 v8::Local<v8::Value> ScriptController::executeScriptInMainWorldAndReturnValue(co nst ScriptSourceCode& sourceCode) 580 v8::Local<v8::Value> ScriptController::executeScriptInMainWorldAndReturnValue(co nst ScriptSourceCode& sourceCode)
578 { 581 {
579 return evaluateScriptInMainWorld(sourceCode, NotSharableCrossOrigin, DoNotEx ecuteScriptWhenScriptsDisabled); 582 return evaluateScriptInMainWorld(sourceCode, NotSharableCrossOrigin, DoNotEx ecuteScriptWhenScriptsDisabled);
580 } 583 }
581 584
582 v8::Local<v8::Value> ScriptController::evaluateScriptInMainWorld(const ScriptSou rceCode& sourceCode, AccessControlStatus corsStatus, ExecuteScriptPolicy policy) 585 v8::Local<v8::Value> ScriptController::evaluateScriptInMainWorld(const ScriptSou rceCode& sourceCode, AccessControlStatus corsStatus, ExecuteScriptPolicy policy, double* compilationFinishTime)
583 { 586 {
584 if (policy == DoNotExecuteScriptWhenScriptsDisabled && !canExecuteScripts(Ab outToExecuteScript)) 587 if (policy == DoNotExecuteScriptWhenScriptsDisabled && !canExecuteScripts(Ab outToExecuteScript))
585 return v8::Local<v8::Value>(); 588 return v8::Local<v8::Value>();
586 589
587 String sourceURL = sourceCode.url(); 590 String sourceURL = sourceCode.url();
588 const String* savedSourceURL = m_sourceURL; 591 const String* savedSourceURL = m_sourceURL;
589 m_sourceURL = &sourceURL; 592 m_sourceURL = &sourceURL;
590 593
591 v8::EscapableHandleScope handleScope(m_isolate); 594 v8::EscapableHandleScope handleScope(m_isolate);
592 v8::Handle<v8::Context> context = toV8Context(m_frame, DOMWrapperWorld::main World()); 595 v8::Handle<v8::Context> context = toV8Context(m_frame, DOMWrapperWorld::main World());
593 if (context.IsEmpty()) 596 if (context.IsEmpty())
594 return v8::Local<v8::Value>(); 597 return v8::Local<v8::Value>();
595 598
596 ScriptState* scriptState = ScriptState::from(context); 599 ScriptState* scriptState = ScriptState::from(context);
597 ScriptState::Scope scope(scriptState); 600 ScriptState::Scope scope(scriptState);
598 601
599 RefPtr<LocalFrame> protect(m_frame); 602 RefPtr<LocalFrame> protect(m_frame);
600 if (m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument()) 603 if (m_frame->loader().stateMachine()->isDisplayingInitialEmptyDocument())
601 m_frame->loader().didAccessInitialDocument(); 604 m_frame->loader().didAccessInitialDocument();
602 605
603 OwnPtr<ScriptSourceCode> maybeProcessedSourceCode = InspectorInstrumentatio n::preprocess(m_frame, sourceCode); 606 OwnPtr<ScriptSourceCode> maybeProcessedSourceCode = InspectorInstrumentatio n::preprocess(m_frame, sourceCode);
604 const ScriptSourceCode& sourceCodeToCompile = maybeProcessedSourceCode ? *ma ybeProcessedSourceCode : sourceCode; 607 const ScriptSourceCode& sourceCodeToCompile = maybeProcessedSourceCode ? *ma ybeProcessedSourceCode : sourceCode;
605 608
606 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte xt(), sourceCodeToCompile, corsStatus); 609 v8::Local<v8::Value> object = executeScriptAndReturnValue(scriptState->conte xt(), sourceCodeToCompile, corsStatus, compilationFinishTime);
607 m_sourceURL = savedSourceURL; 610 m_sourceURL = savedSourceURL;
608 611
609 if (object.IsEmpty()) 612 if (object.IsEmpty())
610 return v8::Local<v8::Value>(); 613 return v8::Local<v8::Value>();
611 614
612 return handleScope.Escape(object); 615 return handleScope.Escape(object);
613 } 616 }
614 617
615 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc riptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value> >* res ults) 618 void ScriptController::executeScriptInIsolatedWorld(int worldID, const Vector<Sc riptSourceCode>& sources, int extensionGroup, Vector<v8::Local<v8::Value> >* res ults)
616 { 619 {
(...skipping 16 matching lines...) Expand all
633 resultArray->Set(i, evaluationResult); 636 resultArray->Set(i, evaluationResult);
634 } 637 }
635 638
636 if (results) { 639 if (results) {
637 for (size_t i = 0; i < resultArray->Length(); ++i) 640 for (size_t i = 0; i < resultArray->Length(); ++i)
638 results->append(handleScope.Escape(resultArray->Get(i))); 641 results->append(handleScope.Escape(resultArray->Get(i)));
639 } 642 }
640 } 643 }
641 644
642 } // namespace blink 645 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ScriptController.h ('k') | Source/core/dom/ScriptLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698