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

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

Issue 2695713015: WIP: Reland CompiledScript, prototype compiling in a separate task.
Patch Set: allow fetchFinished to finish when there is no frame Created 3 years, 9 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
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 14 matching lines...) Expand all
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33 #include "bindings/core/v8/ScriptController.h" 33 #include "bindings/core/v8/ScriptController.h"
34 34
35 #include "bindings/core/v8/CompiledScript.h"
35 #include "bindings/core/v8/ScriptSourceCode.h" 36 #include "bindings/core/v8/ScriptSourceCode.h"
36 #include "bindings/core/v8/ScriptValue.h" 37 #include "bindings/core/v8/ScriptValue.h"
37 #include "bindings/core/v8/V8Binding.h" 38 #include "bindings/core/v8/V8Binding.h"
38 #include "bindings/core/v8/V8Event.h" 39 #include "bindings/core/v8/V8Event.h"
39 #include "bindings/core/v8/V8GCController.h" 40 #include "bindings/core/v8/V8GCController.h"
40 #include "bindings/core/v8/V8HTMLElement.h" 41 #include "bindings/core/v8/V8HTMLElement.h"
41 #include "bindings/core/v8/V8PerContextData.h" 42 #include "bindings/core/v8/V8PerContextData.h"
42 #include "bindings/core/v8/V8ScriptRunner.h" 43 #include "bindings/core/v8/V8ScriptRunner.h"
43 #include "bindings/core/v8/V8Window.h" 44 #include "bindings/core/v8/V8Window.h"
44 #include "bindings/core/v8/WindowProxy.h" 45 #include "bindings/core/v8/WindowProxy.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return result; 154 return result;
154 } 155 }
155 156
156 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), 157 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
157 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", 158 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data",
158 InspectorUpdateCountersEvent::data()); 159 InspectorUpdateCountersEvent::data());
159 160
160 return result; 161 return result;
161 } 162 }
162 163
164 CompiledScript* ScriptController::compileScriptInMainWorld(
165 const ScriptSourceCode& source,
166 AccessControlStatus accessControlStatus) {
167 V8CacheOptions v8CacheOptions =
168 cacheOptions(source.resource(), frame()->settings());
169
170 v8::HandleScope handleScope(isolate());
171 v8::TryCatch tryCatch(isolate());
172 tryCatch.SetVerbose(true);
173
174 v8::Local<v8::Script> script;
175 if (!v8Call(V8ScriptRunner::compileScript(
176 source, isolate(), accessControlStatus, v8CacheOptions),
177 script, tryCatch)) {
178 return nullptr;
179 }
180
181 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
182 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data",
183 InspectorUpdateCountersEvent::data());
184 DCHECK_EQ(currentExecutionContext(isolate()), frame()->document());
185 return new CompiledScript(frame()->document(), script, source);
186 }
187
188 void ScriptController::executeScriptInMainWorld(
189 const CompiledScript& compiledScript) {
190 Document* document = frame()->document();
191
192 TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data",
193 InspectorEvaluateScriptEvent::data(
194 frame(), compiledScript.url().getString(),
195 compiledScript.startPosition()));
196 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint(
197 document, "scriptFirstStatement");
198
199 v8::HandleScope handleScope(isolate());
200 ScriptState::Scope scope(ScriptState::forMainWorld(frame()));
201 v8::TryCatch tryCatch(isolate());
202 tryCatch.SetVerbose(true);
203
204 v8::Local<v8::Script> script = compiledScript.getScript(document);
205 if (script.IsEmpty()) {
206 CHECK(false) << "Don't do this for now";
207 // TODO(jbroman): accessControlStatus
208 AccessControlStatus accessControlStatus = NotSharableCrossOrigin;
209 CompiledScript* recompiledScript = compileScriptInMainWorld(
210 compiledScript.sourceCode(), accessControlStatus);
211 // TODO(jbroman): is this so?
212 DCHECK(recompiledScript);
213 script = recompiledScript->getScript(document);
214 }
215
216 DCHECK(!script.IsEmpty());
217 v8::Local<v8::Value> result;
218 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, document),
219 result, tryCatch))
220 return;
221
222 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
223 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data",
224 InspectorUpdateCountersEvent::data());
225 }
226
163 LocalWindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) { 227 LocalWindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) {
164 LocalWindowProxy* windowProxy = m_windowProxyManager->windowProxy(world); 228 LocalWindowProxy* windowProxy = m_windowProxyManager->windowProxy(world);
165 windowProxy->initializeIfNeeded(); 229 windowProxy->initializeIfNeeded();
166 return windowProxy; 230 return windowProxy;
167 } 231 }
168 232
169 bool ScriptController::shouldBypassMainWorldCSP() { 233 bool ScriptController::shouldBypassMainWorldCSP() {
170 v8::HandleScope handleScope(isolate()); 234 v8::HandleScope handleScope(isolate());
171 v8::Local<v8::Context> context = isolate()->GetCurrentContext(); 235 v8::Local<v8::Context> context = isolate()->GetCurrentContext();
172 if (context.IsEmpty() || !toDOMWindow(context)) 236 if (context.IsEmpty() || !toDOMWindow(context))
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 for (size_t i = 0; i < resultArray->Length(); ++i) { 445 for (size_t i = 0; i < resultArray->Length(); ++i) {
382 v8::Local<v8::Value> value; 446 v8::Local<v8::Value> value;
383 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) 447 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value))
384 return; 448 return;
385 results->push_back(value); 449 results->push_back(value);
386 } 450 }
387 } 451 }
388 } 452 }
389 453
390 } // namespace blink 454 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698