Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 | 87 |
| 87 void ScriptController::clearForClose() { | 88 void ScriptController::clearForClose() { |
| 88 m_windowProxyManager->clearForClose(); | 89 m_windowProxyManager->clearForClose(); |
| 89 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); | 90 MainThreadDebugger::instance()->didClearContextsForFrame(frame()); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) { | 93 void ScriptController::updateSecurityOrigin(SecurityOrigin* securityOrigin) { |
| 93 m_windowProxyManager->updateSecurityOrigin(securityOrigin); | 94 m_windowProxyManager->updateSecurityOrigin(securityOrigin); |
| 94 } | 95 } |
| 95 | 96 |
| 97 namespace { | |
| 98 | |
| 99 V8CacheOptions cacheOptions(const ScriptResource* resource, | |
| 100 const Settings* settings) { | |
| 101 V8CacheOptions v8CacheOptions(V8CacheOptionsDefault); | |
| 102 if (settings) | |
| 103 v8CacheOptions = settings->v8CacheOptions(); | |
| 104 if (resource && !resource->response().cacheStorageCacheName().isNull()) { | |
| 105 switch (settings->v8CacheStrategiesForCacheStorage()) { | |
| 106 case V8CacheStrategiesForCacheStorage::None: | |
| 107 v8CacheOptions = V8CacheOptionsNone; | |
| 108 break; | |
| 109 case V8CacheStrategiesForCacheStorage::Normal: | |
| 110 v8CacheOptions = V8CacheOptionsCode; | |
| 111 break; | |
| 112 case V8CacheStrategiesForCacheStorage::Default: | |
| 113 case V8CacheStrategiesForCacheStorage::Aggressive: | |
| 114 v8CacheOptions = V8CacheOptionsAlways; | |
| 115 break; | |
| 116 } | |
| 117 } | |
| 118 return v8CacheOptions; | |
| 119 } | |
| 120 | |
| 121 } // namespace | |
| 122 | |
| 96 v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue( | 123 v8::Local<v8::Value> ScriptController::executeScriptAndReturnValue( |
| 97 v8::Local<v8::Context> context, | 124 v8::Local<v8::Context> context, |
| 98 const ScriptSourceCode& source, | 125 const ScriptSourceCode& source, |
| 99 AccessControlStatus accessControlStatus) { | 126 AccessControlStatus accessControlStatus) { |
| 100 TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data", | 127 TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data", |
| 101 InspectorEvaluateScriptEvent::data( | 128 InspectorEvaluateScriptEvent::data( |
| 102 frame(), source.url().getString(), source.startPosition())); | 129 frame(), source.url().getString(), source.startPosition())); |
| 103 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( | 130 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( |
| 104 frame()->document(), "scriptFirstStatement", false); | 131 frame()->document(), "scriptFirstStatement", false); |
| 105 | 132 |
| 106 v8::Local<v8::Value> result; | 133 v8::Local<v8::Value> result; |
| 107 { | 134 { |
| 108 V8CacheOptions v8CacheOptions(V8CacheOptionsDefault); | 135 V8CacheOptions v8CacheOptions = |
| 109 if (frame()->settings()) | 136 cacheOptions(source.resource(), frame()->settings()); |
| 110 v8CacheOptions = frame()->settings()->v8CacheOptions(); | |
| 111 if (source.resource() && | |
| 112 !source.resource()->response().cacheStorageCacheName().isNull()) { | |
| 113 switch (frame()->settings()->v8CacheStrategiesForCacheStorage()) { | |
| 114 case V8CacheStrategiesForCacheStorage::None: | |
| 115 v8CacheOptions = V8CacheOptionsNone; | |
| 116 break; | |
| 117 case V8CacheStrategiesForCacheStorage::Normal: | |
| 118 v8CacheOptions = V8CacheOptionsCode; | |
| 119 break; | |
| 120 case V8CacheStrategiesForCacheStorage::Default: | |
| 121 case V8CacheStrategiesForCacheStorage::Aggressive: | |
| 122 v8CacheOptions = V8CacheOptionsAlways; | |
| 123 break; | |
| 124 } | |
| 125 } | |
| 126 | 137 |
| 127 // Isolate exceptions that occur when compiling and executing | 138 // Isolate exceptions that occur when compiling and executing |
| 128 // the code. These exceptions should not interfere with | 139 // the code. These exceptions should not interfere with |
| 129 // javascript code we might evaluate from C++ when returning | 140 // javascript code we might evaluate from C++ when returning |
| 130 // from here. | 141 // from here. |
| 131 v8::TryCatch tryCatch(isolate()); | 142 v8::TryCatch tryCatch(isolate()); |
| 132 tryCatch.SetVerbose(true); | 143 tryCatch.SetVerbose(true); |
| 133 | 144 |
| 134 v8::Local<v8::Script> script; | 145 v8::Local<v8::Script> script; |
| 135 if (!v8Call(V8ScriptRunner::compileScript( | 146 if (!v8Call(V8ScriptRunner::compileScript( |
| 136 source, isolate(), accessControlStatus, v8CacheOptions), | 147 source, isolate(), accessControlStatus, v8CacheOptions), |
| 137 script, tryCatch)) | 148 script, tryCatch)) |
| 138 return result; | 149 return result; |
| 139 | 150 |
| 140 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, | 151 if (!v8Call(V8ScriptRunner::runCompiledScript(isolate(), script, |
| 141 frame()->document()), | 152 frame()->document()), |
| 142 result, tryCatch)) | 153 result, tryCatch)) |
| 143 return result; | 154 return result; |
| 144 } | 155 } |
| 145 | 156 |
| 146 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), | 157 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 147 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", | 158 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", |
| 148 InspectorUpdateCountersEvent::data()); | 159 InspectorUpdateCountersEvent::data()); |
| 149 | 160 |
| 150 return result; | 161 return result; |
| 151 } | 162 } |
| 152 | 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 return new CompiledScript(isolate(), script, source); | |
| 185 } | |
| 186 | |
| 187 void ScriptController::executeScriptInMainWorld( | |
| 188 const CompiledScript& compiledScript) { | |
| 189 TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data", | |
| 190 InspectorEvaluateScriptEvent::data( | |
| 191 frame(), compiledScript.url().getString(), | |
| 192 compiledScript.startPosition())); | |
|
haraken
2016/12/12 00:53:57
Shall we introduce two trace events: "CompileScrip
jbroman
2016/12/13 15:53:21
I'm not opposed in principle, but these string con
| |
| 193 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( | |
| 194 frame()->document(), "scriptFirstStatement", false); | |
| 195 | |
| 196 v8::HandleScope handleScope(isolate()); | |
| 197 v8::TryCatch tryCatch(isolate()); | |
| 198 tryCatch.SetVerbose(true); | |
| 199 | |
| 200 v8::Local<v8::Value> result; | |
| 201 if (!v8Call( | |
| 202 V8ScriptRunner::runCompiledScript( | |
| 203 isolate(), compiledScript.script(isolate()), frame()->document()), | |
| 204 result, tryCatch)) | |
| 205 return; | |
| 206 | |
| 207 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), | |
| 208 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", | |
| 209 InspectorUpdateCountersEvent::data()); | |
|
haraken
2016/12/12 00:53:57
I don't fully understand this trace event. Is it e
jbroman
2016/12/13 15:53:21
From what I can tell, it makes a note of the heap
| |
| 210 } | |
| 211 | |
| 153 bool ScriptController::initializeMainWorld() { | 212 bool ScriptController::initializeMainWorld() { |
| 154 if (m_windowProxyManager->mainWorldProxy()->isContextInitialized()) | 213 if (m_windowProxyManager->mainWorldProxy()->isContextInitialized()) |
| 155 return false; | 214 return false; |
| 156 return windowProxy(DOMWrapperWorld::mainWorld())->isContextInitialized(); | 215 return windowProxy(DOMWrapperWorld::mainWorld())->isContextInitialized(); |
| 157 } | 216 } |
| 158 | 217 |
| 159 WindowProxy* ScriptController::existingWindowProxy(DOMWrapperWorld& world) { | 218 WindowProxy* ScriptController::existingWindowProxy(DOMWrapperWorld& world) { |
| 160 return m_windowProxyManager->existingWindowProxy(world); | 219 return m_windowProxyManager->existingWindowProxy(world); |
| 161 } | 220 } |
| 162 | 221 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 for (size_t i = 0; i < resultArray->Length(); ++i) { | 505 for (size_t i = 0; i < resultArray->Length(); ++i) { |
| 447 v8::Local<v8::Value> value; | 506 v8::Local<v8::Value> value; |
| 448 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) | 507 if (!resultArray->Get(scriptState->context(), i).ToLocal(&value)) |
| 449 return; | 508 return; |
| 450 results->push_back(value); | 509 results->push_back(value); |
| 451 } | 510 } |
| 452 } | 511 } |
| 453 } | 512 } |
| 454 | 513 |
| 455 } // namespace blink | 514 } // namespace blink |
| OLD | NEW |