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

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 compile to fail, disallow restreaming (hack) 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 return result; 151 return result;
151 } 152 }
152 153
153 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), 154 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
154 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", 155 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data",
155 InspectorUpdateCountersEvent::data()); 156 InspectorUpdateCountersEvent::data());
156 157
157 return result; 158 return result;
158 } 159 }
159 160
161 CompiledScript* ScriptController::compileScriptInMainWorld(
162 const ScriptSourceCode& source,
163 AccessControlStatus accessControlStatus) {
164 V8CacheOptions v8CacheOptions =
165 cacheOptions(source.resource(), frame()->settings());
166
167 v8::HandleScope handleScope(isolate());
168 v8::TryCatch tryCatch(isolate());
169 tryCatch.SetVerbose(true);
170
171 v8::Local<v8::Script> script;
172 if (!v8Call(V8ScriptRunner::compileScript(
173 source, isolate(), accessControlStatus, v8CacheOptions),
174 script, tryCatch)) {
175 return nullptr;
176 }
177
178 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
179 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data",
180 InspectorUpdateCountersEvent::data());
181 DCHECK_EQ(currentExecutionContext(isolate()), frame()->document());
182 return new CompiledScript(frame()->document(), script, source);
183 }
184
185 void ScriptController::executeScriptInMainWorld(
186 const CompiledScript& compiledScript) {
187 Document* document = frame()->document();
188
189 TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data",
190 InspectorEvaluateScriptEvent::data(
191 frame(), compiledScript.url().getString(),
192 compiledScript.startPosition()));
193
194 v8::HandleScope handleScope(isolate());
195 ScriptState::Scope scope(ScriptState::forMainWorld(frame()));
196 v8::TryCatch tryCatch(isolate());
197 tryCatch.SetVerbose(true);
198
199 v8::Local<v8::Script> script = compiledScript.getScript(document);
200 if (script.IsEmpty()) {
201 CHECK(false) << "Don't do this for now";
202 // TODO(jbroman): accessControlStatus
203 AccessControlStatus accessControlStatus = NotSharableCrossOrigin;
204 CompiledScript* recompiledScript = compileScriptInMainWorld(
205 compiledScript.sourceCode(), accessControlStatus);
206 // TODO(jbroman): is this so?
207 DCHECK(recompiledScript);
208 script = recompiledScript->getScript(document);
209 }
210
211 DCHECK(!script.IsEmpty());
212 v8::Local<v8::Value> result;
213 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, document),
214 result, tryCatch))
215 return;
216
217 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"),
218 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data",
219 InspectorUpdateCountersEvent::data());
220 }
221
160 LocalWindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) { 222 LocalWindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world) {
161 LocalWindowProxy* windowProxy = m_windowProxyManager->windowProxy(world); 223 LocalWindowProxy* windowProxy = m_windowProxyManager->windowProxy(world);
162 windowProxy->initializeIfNeeded(); 224 windowProxy->initializeIfNeeded();
163 return windowProxy; 225 return windowProxy;
164 } 226 }
165 227
166 bool ScriptController::shouldBypassMainWorldCSP() { 228 bool ScriptController::shouldBypassMainWorldCSP() {
167 v8::HandleScope handleScope(isolate()); 229 v8::HandleScope handleScope(isolate());
168 v8::Local<v8::Context> context = isolate()->GetCurrentContext(); 230 v8::Local<v8::Context> context = isolate()->GetCurrentContext();
169 if (context.IsEmpty() || !toDOMWindow(context)) 231 if (context.IsEmpty() || !toDOMWindow(context))
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 for (size_t i = 0; i < resultArray->Length(); ++i) { 441 for (size_t i = 0; i < resultArray->Length(); ++i) {
380 v8::Local<v8::Value> value; 442 v8::Local<v8::Value> value;
381 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) 443 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value))
382 return; 444 return;
383 results->push_back(value); 445 results->push_back(value);
384 } 446 }
385 } 447 }
386 } 448 }
387 449
388 } // namespace blink 450 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698