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

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

Issue 761143003: DevTools: remove ScriptPreprocessor (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 5 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 Google Inc. All rights reserved. 2 * Copyright (c) 2011 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "bindings/core/v8/PageScriptDebugServer.h" 32 #include "bindings/core/v8/PageScriptDebugServer.h"
33 33
34 #include "bindings/core/v8/DOMWrapperWorld.h" 34 #include "bindings/core/v8/DOMWrapperWorld.h"
35 #include "bindings/core/v8/ScriptController.h" 35 #include "bindings/core/v8/ScriptController.h"
36 #include "bindings/core/v8/ScriptPreprocessor.h"
37 #include "bindings/core/v8/ScriptSourceCode.h" 36 #include "bindings/core/v8/ScriptSourceCode.h"
38 #include "bindings/core/v8/V8Binding.h" 37 #include "bindings/core/v8/V8Binding.h"
39 #include "bindings/core/v8/V8ScriptRunner.h" 38 #include "bindings/core/v8/V8ScriptRunner.h"
40 #include "bindings/core/v8/V8Window.h" 39 #include "bindings/core/v8/V8Window.h"
41 #include "bindings/core/v8/WindowProxy.h" 40 #include "bindings/core/v8/WindowProxy.h"
42 #include "core/frame/FrameConsole.h" 41 #include "core/frame/FrameConsole.h"
43 #include "core/frame/FrameHost.h" 42 #include "core/frame/FrameHost.h"
44 #include "core/frame/LocalFrame.h" 43 #include "core/frame/LocalFrame.h"
45 #include "core/frame/UseCounter.h" 44 #include "core/frame/UseCounter.h"
46 #include "core/inspector/InspectorInstrumentation.h" 45 #include "core/inspector/InspectorInstrumentation.h"
(...skipping 21 matching lines...) Expand all
68 if (isMainThread() && DOMWrapperWorld::windowIsBeingInitialized()) 67 if (isMainThread() && DOMWrapperWorld::windowIsBeingInitialized())
69 return 0; 68 return 0;
70 69
71 v8::Handle<v8::Value> global = V8Window::findInstanceInPrototypeChain(contex t->Global(), context->GetIsolate()); 70 v8::Handle<v8::Value> global = V8Window::findInstanceInPrototypeChain(contex t->Global(), context->GetIsolate());
72 if (global.IsEmpty()) 71 if (global.IsEmpty())
73 return 0; 72 return 0;
74 73
75 return toLocalFrame(toFrameIfNotDetached(context)); 74 return toLocalFrame(toFrameIfNotDetached(context));
76 } 75 }
77 76
78 void PageScriptDebugServer::setPreprocessorSource(const String& preprocessorSour ce)
79 {
80 if (preprocessorSource.isEmpty())
81 m_preprocessorSourceCode = ScriptSourceCode();
82 else
83 m_preprocessorSourceCode = ScriptSourceCode(preprocessorSource);
84 m_scriptPreprocessor.clear();
85 }
86
87 PageScriptDebugServer& PageScriptDebugServer::shared() 77 PageScriptDebugServer& PageScriptDebugServer::shared()
88 { 78 {
89 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<PageScriptDebugServer>, server, ( adoptPtrWillBeNoop(new PageScriptDebugServer()))); 79 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<PageScriptDebugServer>, server, ( adoptPtrWillBeNoop(new PageScriptDebugServer())));
90 return *server; 80 return *server;
91 } 81 }
92 82
93 v8::Isolate* PageScriptDebugServer::s_mainThreadIsolate = 0; 83 v8::Isolate* PageScriptDebugServer::s_mainThreadIsolate = 0;
94 84
95 void PageScriptDebugServer::setMainThreadIsolate(v8::Isolate* isolate) 85 void PageScriptDebugServer::setMainThreadIsolate(v8::Isolate* isolate)
96 { 86 {
97 s_mainThreadIsolate = isolate; 87 s_mainThreadIsolate = isolate;
98 } 88 }
99 89
100 PageScriptDebugServer::PageScriptDebugServer() 90 PageScriptDebugServer::PageScriptDebugServer()
101 : ScriptDebugServer(s_mainThreadIsolate) 91 : ScriptDebugServer(s_mainThreadIsolate)
102 , m_pausedFrame(nullptr) 92 , m_pausedFrame(nullptr)
103 , m_preprocessorSourceCode()
104 { 93 {
105 } 94 }
106 95
107 PageScriptDebugServer::~PageScriptDebugServer() 96 PageScriptDebugServer::~PageScriptDebugServer()
108 { 97 {
109 } 98 }
110 99
111 void PageScriptDebugServer::trace(Visitor* visitor) 100 void PageScriptDebugServer::trace(Visitor* visitor)
112 { 101 {
113 #if ENABLE(OILPAN) 102 #if ENABLE(OILPAN)
114 visitor->trace(m_listenersMap); 103 visitor->trace(m_listenersMap);
115 visitor->trace(m_pausedFrame); 104 visitor->trace(m_pausedFrame);
116 visitor->trace(m_preprocessorSourceCode);
117 #endif 105 #endif
118 ScriptDebugServer::trace(visitor); 106 ScriptDebugServer::trace(visitor);
119 } 107 }
120 108
121 void PageScriptDebugServer::addListener(ScriptDebugListener* listener, LocalFram e* localFrameRoot) 109 void PageScriptDebugServer::addListener(ScriptDebugListener* listener, LocalFram e* localFrameRoot)
122 { 110 {
123 ASSERT(localFrameRoot == localFrameRoot->localFrameRoot()); 111 ASSERT(localFrameRoot == localFrameRoot->localFrameRoot());
124 112
125 ScriptController& scriptController = localFrameRoot->script(); 113 ScriptController& scriptController = localFrameRoot->script();
126 if (!scriptController.canExecuteScripts(NotAboutToExecuteScript)) 114 if (!scriptController.canExecuteScripts(NotAboutToExecuteScript))
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 listener->didContinue(); 227 listener->didContinue();
240 228
241 m_pausedFrame = 0; 229 m_pausedFrame = 0;
242 } 230 }
243 231
244 void PageScriptDebugServer::quitMessageLoopOnPause() 232 void PageScriptDebugServer::quitMessageLoopOnPause()
245 { 233 {
246 m_clientMessageLoop->quitNow(); 234 m_clientMessageLoop->quitNow();
247 } 235 }
248 236
249 void PageScriptDebugServer::preprocessBeforeCompile(const v8::Debug::EventDetail s& eventDetails)
250 {
251 v8::Handle<v8::Context> eventContext = eventDetails.GetEventContext();
252 LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(eventContext);
253 if (!frame)
254 return;
255
256 if (!canPreprocess(frame))
257 return;
258
259 v8::Handle<v8::Object> eventData = eventDetails.GetEventData();
260 v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext();
261 v8::Context::Scope contextScope(debugContext);
262 v8::TryCatch tryCatch;
263 // <script> tag source and attribute value source are preprocessed before we enter V8.
264 // Avoid preprocessing any internal scripts by processing only eval source i n this V8 event handler.
265 v8::Handle<v8::Value> argvEventData[] = { eventData };
266 v8::Handle<v8::Value> v8Value = callDebuggerMethod("isEvalCompilation", WTF_ ARRAY_LENGTH(argvEventData), argvEventData);
267 if (v8Value.IsEmpty() || !v8Value->ToBoolean(debugContext->GetIsolate())->Va lue())
268 return;
269
270 // The name and source are in the JS event data.
271 String scriptName = toCoreStringWithUndefinedOrNullCheck(callDebuggerMethod( "getScriptName", WTF_ARRAY_LENGTH(argvEventData), argvEventData));
272 String script = toCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("get ScriptSource", WTF_ARRAY_LENGTH(argvEventData), argvEventData));
273
274 String preprocessedSource = m_scriptPreprocessor->preprocessSourceCode(scri pt, scriptName);
275
276 v8::Handle<v8::Value> argvPreprocessedScript[] = { eventData, v8String(debug Context->GetIsolate(), preprocessedSource) };
277 callDebuggerMethod("setScriptSource", WTF_ARRAY_LENGTH(argvPreprocessedScrip t), argvPreprocessedScript);
278 }
279
280 static bool isCreatingPreprocessor = false;
281
282 bool PageScriptDebugServer::canPreprocess(LocalFrame* frame)
283 {
284 ASSERT(frame);
285
286 if (m_preprocessorSourceCode.isNull() || !frame->page() || isCreatingPreproc essor)
287 return false;
288
289 // We delay the creation of the preprocessor until just before the first JS from the
290 // Web page to ensure that the debugger's console initialization code has co mpleted.
291 if (!m_scriptPreprocessor) {
292 TemporaryChange<bool> isPreprocessing(isCreatingPreprocessor, true);
293 m_scriptPreprocessor = adoptPtr(new ScriptPreprocessor(m_isolate, m_prep rocessorSourceCode, frame));
294 }
295
296 if (m_scriptPreprocessor->isValid())
297 return true;
298
299 m_scriptPreprocessor.clear();
300 // Don't retry the compile if we fail one time.
301 m_preprocessorSourceCode = ScriptSourceCode();
302 return false;
303 }
304
305 // Source to Source processing iff debugger enabled and it has loaded a preproce ssor.
306 ScriptSourceCode PageScriptDebugServer::preprocess(LocalFrame* frame, const Scri ptSourceCode& sourceCode)
307 {
308 if (!canPreprocess(frame))
309 return ScriptSourceCode();
310
311 String preprocessedSource = m_scriptPreprocessor->preprocessSourceCode(sourc eCode.source(), sourceCode.url());
312 return ScriptSourceCode(preprocessedSource, sourceCode.url());
313 }
314
315 String PageScriptDebugServer::preprocessEventListener(LocalFrame* frame, const S tring& source, const String& url, const String& functionName)
316 {
317 if (!canPreprocess(frame))
318 return source;
319
320 return m_scriptPreprocessor->preprocessSourceCode(source, url, functionName) ;
321 }
322
323 void PageScriptDebugServer::clearPreprocessor()
324 {
325 m_scriptPreprocessor.clear();
326 }
327
328 void PageScriptDebugServer::muteWarningsAndDeprecations() 237 void PageScriptDebugServer::muteWarningsAndDeprecations()
329 { 238 {
330 FrameConsole::mute(); 239 FrameConsole::mute();
331 UseCounter::muteForInspector(); 240 UseCounter::muteForInspector();
332 } 241 }
333 242
334 void PageScriptDebugServer::unmuteWarningsAndDeprecations() 243 void PageScriptDebugServer::unmuteWarningsAndDeprecations()
335 { 244 {
336 FrameConsole::unmute(); 245 FrameConsole::unmute();
337 UseCounter::unmuteForInspector(); 246 UseCounter::unmuteForInspector();
338 } 247 }
339 248
340 } // namespace blink 249 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/PageScriptDebugServer.h ('k') | Source/bindings/core/v8/ScriptController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698