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

Side by Side Diff: Source/bindings/v8/ScriptDebugServer.cpp

Issue 14362015: WIP enum / V8PerContextData solution (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 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
« no previous file with comments | « Source/bindings/v8/ScriptController.cpp ('k') | Source/bindings/v8/V8DOMWindowShell.cpp » ('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) 2010-2011 Google Inc. All rights reserved. 2 * Copyright (c) 2010-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 21 matching lines...) Expand all
32 #include "ScriptDebugServer.h" 32 #include "ScriptDebugServer.h"
33 33
34 34
35 #include "DebuggerScriptSource.h" 35 #include "DebuggerScriptSource.h"
36 #include "JavaScriptCallFrame.h" 36 #include "JavaScriptCallFrame.h"
37 #include "ScopedPersistent.h" 37 #include "ScopedPersistent.h"
38 #include "ScriptDebugListener.h" 38 #include "ScriptDebugListener.h"
39 #include "ScriptObject.h" 39 #include "ScriptObject.h"
40 #include "V8Binding.h" 40 #include "V8Binding.h"
41 #include "V8JavaScriptCallFrame.h" 41 #include "V8JavaScriptCallFrame.h"
42 #include "V8PerContextDebugData.h"
42 #include "V8RecursionScope.h" 43 #include "V8RecursionScope.h"
43 #include <wtf/StdLibExtras.h> 44 #include <wtf/StdLibExtras.h>
45 #include <wtf/StringExtras.h>
44 #include <wtf/Vector.h> 46 #include <wtf/Vector.h>
45 47
46 namespace WebCore { 48 namespace WebCore {
47 49
48 namespace { 50 namespace {
49 51
50 class ClientDataImpl : public v8::Debug::ClientData { 52 class ClientDataImpl : public v8::Debug::ClientData {
51 public: 53 public:
52 ClientDataImpl(PassOwnPtr<ScriptDebugServer::Task> task) : m_task(task) { } 54 ClientDataImpl(PassOwnPtr<ScriptDebugServer::Task> task) : m_task(task) { }
53 virtual ~ClientDataImpl() { } 55 virtual ~ClientDataImpl() { }
(...skipping 24 matching lines...) Expand all
78 v8::Local<v8::Value> ScriptDebugServer::callDebuggerMethod(const char* functionN ame, int argc, v8::Handle<v8::Value> argv[]) 80 v8::Local<v8::Value> ScriptDebugServer::callDebuggerMethod(const char* functionN ame, int argc, v8::Handle<v8::Value> argv[])
79 { 81 {
80 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast(m_debugger Script.get()->Get(v8::String::NewSymbol(functionName))); 82 v8::Handle<v8::Function> function = v8::Local<v8::Function>::Cast(m_debugger Script.get()->Get(v8::String::NewSymbol(functionName)));
81 V8RecursionScope::MicrotaskSuppression scope; 83 V8RecursionScope::MicrotaskSuppression scope;
82 return function->Call(m_debuggerScript.get(), argc, argv); 84 return function->Call(m_debuggerScript.get(), argc, argv);
83 } 85 }
84 86
85 class ScriptDebugServer::ScriptPreprocessor { 87 class ScriptDebugServer::ScriptPreprocessor {
86 WTF_MAKE_NONCOPYABLE(ScriptPreprocessor); 88 WTF_MAKE_NONCOPYABLE(ScriptPreprocessor);
87 public: 89 public:
90
88 explicit ScriptPreprocessor(const String& preprocessorScript) 91 explicit ScriptPreprocessor(const String& preprocessorScript)
89 { 92 {
90 v8::HandleScope scope; 93 v8::HandleScope scope;
91 94
92 m_utilityContext.set(v8::Context::New()); 95 m_utilityContext.set(v8::Context::New());
93 if (m_utilityContext.isEmpty()) 96 if (m_utilityContext.isEmpty())
94 return; 97 return;
95 98
99 V8PerContextDebugData::setDebugDataForSystemUtility(m_utilityContext.get ());
100
96 v8::Context::Scope contextScope(m_utilityContext.get()); 101 v8::Context::Scope contextScope(m_utilityContext.get());
97 102
98 v8::TryCatch tryCatch; 103 v8::TryCatch tryCatch;
99 104
100 String wrappedScript = makeString("(", preprocessorScript, ")"); 105 String wrappedScript = makeString("(", preprocessorScript, ")");
101 v8::Handle<v8::String> preprocessor = v8::String::New(wrappedScript.utf8 ().data(), wrappedScript.utf8().length()); 106 v8::Handle<v8::String> preprocessor = v8::String::New(wrappedScript.utf8 ().data(), wrappedScript.utf8().length());
102 107
103 v8::Handle<v8::Script> script = v8::Script::Compile(preprocessor); 108 v8::Handle<v8::Script> script = v8::Script::Compile(preprocessor);
104 109
105 if (tryCatch.HasCaught()) 110 if (tryCatch.HasCaught())
(...skipping 24 matching lines...) Expand all
130 135
131 v8::TryCatch tryCatch; 136 v8::TryCatch tryCatch;
132 RecursionScopeSuppression suppressionScope; 137 RecursionScopeSuppression suppressionScope;
133 v8::Handle<v8::Value> resultValue = m_preprocessorFunction->Call(context ->Global(), 2, argv); 138 v8::Handle<v8::Value> resultValue = m_preprocessorFunction->Call(context ->Global(), 2, argv);
134 139
135 if (tryCatch.HasCaught()) 140 if (tryCatch.HasCaught())
136 return sourceCode; 141 return sourceCode;
137 142
138 if (resultValue->IsString()) { 143 if (resultValue->IsString()) {
139 v8::String::Utf8Value utf8Value(resultValue); 144 v8::String::Utf8Value utf8Value(resultValue);
140 return String::fromUTF8(*utf8Value, utf8Value.length()); 145
146 String preprocessed = String::fromUTF8(*utf8Value, utf8Value.length( ));
147 // Zero bytes crash the page if we are preprocessing injectedScripts
148 if (preprocessed.length() == 0)
149 return sourceCode;
150
151 return preprocessed;
141 } 152 }
142 153
143 return sourceCode; 154 return sourceCode;
144 } 155 }
145 156
146 ~ScriptPreprocessor() 157 ~ScriptPreprocessor()
147 { 158 {
148 } 159 }
149 160
150 private: 161 private:
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 ASSERT(!eventContext.IsEmpty()); 462 ASSERT(!eventContext.IsEmpty());
452 463
453 ScriptDebugListener* listener = getDebugListenerForContext(eventContext); 464 ScriptDebugListener* listener = getDebugListenerForContext(eventContext);
454 if (listener) { 465 if (listener) {
455 v8::HandleScope scope; 466 v8::HandleScope scope;
456 if (event == v8::BeforeCompile) { 467 if (event == v8::BeforeCompile) {
457 468
458 if (!m_scriptPreprocessor) 469 if (!m_scriptPreprocessor)
459 return; 470 return;
460 471
472 // Only preprocess web scripts
473 if (V8PerContextDebugData::compilationOriginCategory(eventContext) ! = CompilationOriginWeb)
474 return;
475
461 OwnPtr<ScriptPreprocessor> preprocessor(m_scriptPreprocessor.release ()); 476 OwnPtr<ScriptPreprocessor> preprocessor(m_scriptPreprocessor.release ());
477
462 v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext(); 478 v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext();
463 v8::Context::Scope contextScope(debugContext); 479 v8::Context::Scope contextScope(debugContext);
480
464 v8::Handle<v8::Function> getScriptSourceFunction = v8::Local<v8::Fun ction>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptSource"))); 481 v8::Handle<v8::Function> getScriptSourceFunction = v8::Local<v8::Fun ction>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptSource")));
465 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; 482 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
466 v8::Handle<v8::Value> script = getScriptSourceFunction->Call(m_debug gerScript.get(), 1, argv); 483 v8::Handle<v8::Value> script = getScriptSourceFunction->Call(m_debug gerScript.get(), 1, argv);
467 484
468 v8::Handle<v8::Function> getScriptNameFunction = v8::Local<v8::Funct ion>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptName"))); 485 v8::Handle<v8::Function> getScriptNameFunction = v8::Local<v8::Funct ion>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptName")));
469 v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() }; 486 v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() };
470 v8::Handle<v8::Value> scriptName = getScriptNameFunction->Call(m_deb uggerScript.get(), 1, argv1); 487 v8::Handle<v8::Value> scriptName = getScriptNameFunction->Call(m_deb uggerScript.get(), 1, argv1);
471 488
489 v8::String::Utf8Value scriptNameUtf8Value(scriptName);
490 String scriptNameString = String::fromUTF8(*scriptNameUtf8Value, scr iptNameUtf8Value.length());
491 if (scriptNameString.contains("data:text/html,chromewebdata"))
492 return;
493
472 v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Fun ction>::Cast(m_debuggerScript.get()->Get(v8::String::New("setScriptSource"))); 494 v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Fun ction>::Cast(m_debuggerScript.get()->Get(v8::String::New("setScriptSource")));
473 String patchedScript = preprocessor->preprocessSourceCode(toWebCoreS tringWithUndefinedOrNullCheck(script), toWebCoreStringWithUndefinedOrNullCheck(s criptName)); 495 String patchedScript = preprocessor->preprocessSourceCode(toWebCoreS tringWithUndefinedOrNullCheck(script), scriptNameString);
474 496
475 v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8Str ing(patchedScript, debugContext->GetIsolate()) }; 497 v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8Str ing(patchedScript, debugContext->GetIsolate()) };
476 setScriptSourceFunction->Call(m_debuggerScript.get(), 2, argv2); 498 setScriptSourceFunction->Call(m_debuggerScript.get(), 2, argv2);
477 m_scriptPreprocessor = preprocessor.release(); 499 m_scriptPreprocessor = preprocessor.release();
478 } else if (event == v8::AfterCompile) { 500 } else if (event == v8::AfterCompile) {
479 v8::Context::Scope contextScope(v8::Debug::GetDebugContext()); 501 v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
480 v8::Handle<v8::Function> onAfterCompileFunction = v8::Local<v8::Func tion>::Cast(m_debuggerScript.get()->Get(v8::String::NewSymbol("getAfterCompileSc ript"))); 502 v8::Handle<v8::Function> onAfterCompileFunction = v8::Local<v8::Func tion>::Cast(m_debuggerScript.get()->Get(v8::String::NewSymbol("getAfterCompileSc ript")));
481 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() }; 503 v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
482 v8::Handle<v8::Value> value = onAfterCompileFunction->Call(m_debugge rScript.get(), 1, argv); 504 v8::Handle<v8::Value> value = onAfterCompileFunction->Call(m_debugge rScript.get(), 1, argv);
483 ASSERT(value->IsObject()); 505 ASSERT(value->IsObject());
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 *result = ScriptValue(tryCatch.Exception()); 655 *result = ScriptValue(tryCatch.Exception());
634 v8::Local<v8::Message> message = tryCatch.Message(); 656 v8::Local<v8::Message> message = tryCatch.Message();
635 if (!message.IsEmpty()) 657 if (!message.IsEmpty())
636 *exceptionMessage = toWebCoreStringWithUndefinedOrNullCheck(message- >Get()); 658 *exceptionMessage = toWebCoreStringWithUndefinedOrNullCheck(message- >Get());
637 } else 659 } else
638 *result = ScriptValue(value); 660 *result = ScriptValue(value);
639 } 661 }
640 662
641 } // namespace WebCore 663 } // namespace WebCore
642 664
OLDNEW
« no previous file with comments | « Source/bindings/v8/ScriptController.cpp ('k') | Source/bindings/v8/V8DOMWindowShell.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698