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

Side by Side Diff: chrome/browser/debugger/debugger_shell.cc

Issue 39206: NO CODE CHANGE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/debugger/debugger_node.cc ('k') | chrome/browser/dom_ui/dom_ui_contents.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/debugger/debugger_shell.h" 5 #include "chrome/browser/debugger/debugger_shell.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 ChromeNode* chrome = new ChromeNode(this); 78 ChromeNode* chrome = new ChromeNode(this);
79 v8_context_->Global()->Set(v8::String::New("chrome"), 79 v8_context_->Global()->Set(v8::String::New("chrome"),
80 chrome->NewInstance()); 80 chrome->NewInstance());
81 81
82 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 82 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
83 const std::string& debugger_shell_js = 83 const std::string& debugger_shell_js =
84 rb.GetDataResource(IDR_DEBUGGER_SHELL_JS); 84 rb.GetDataResource(IDR_DEBUGGER_SHELL_JS);
85 CompileAndRun(debugger_shell_js, "chrome.dll/debugger_shell.js"); 85 CompileAndRun(debugger_shell_js, "chrome.dll/debugger_shell.js");
86 } 86 }
87 87
88 void DebuggerShell::HandleWeakReference(v8::Persistent<v8::Value> obj, void* dat a) { 88 void DebuggerShell::HandleWeakReference(v8::Persistent<v8::Value> obj,
89 void* data) {
89 DebuggerNodeWrapper* node = static_cast<DebuggerNodeWrapper*>(data); 90 DebuggerNodeWrapper* node = static_cast<DebuggerNodeWrapper*>(data);
90 node->Release(); 91 node->Release();
91 } 92 }
92 93
93 v8::Handle<v8::Value> DebuggerShell::SetDebuggerReady(const v8::Arguments& args, 94 v8::Handle<v8::Value> DebuggerShell::SetDebuggerReady(const v8::Arguments& args,
94 DebuggerShell* debugger) { 95 DebuggerShell* debugger) {
95 if (args[0]->IsBoolean()) { 96 if (args[0]->IsBoolean()) {
96 bool flag = args[0]->BooleanValue(); 97 bool flag = args[0]->BooleanValue();
97 debugger->debugger_ready_ = flag; 98 debugger->debugger_ready_ = flag;
98 debugger->GetIo()->SetDebuggerReady(flag); 99 debugger->GetIo()->SetDebuggerReady(flag);
99 } 100 }
100 return v8::Undefined(); 101 return v8::Undefined();
101 } 102 }
102 103
103 v8::Handle<v8::Value> DebuggerShell::SetDebuggerBreak(const v8::Arguments& args, 104 v8::Handle<v8::Value> DebuggerShell::SetDebuggerBreak(const v8::Arguments& args,
104 DebuggerShell* debugger) { 105 DebuggerShell* debugger) {
105 if (args[0]->IsBoolean()) { 106 if (args[0]->IsBoolean()) {
106 bool flag = args[0]->BooleanValue(); 107 bool flag = args[0]->BooleanValue();
107 debugger->GetIo()->SetDebuggerBreak(flag); 108 debugger->GetIo()->SetDebuggerBreak(flag);
108 } 109 }
109 return v8::Undefined(); 110 return v8::Undefined();
110 } 111 }
111 112
112 DebuggerInputOutput* DebuggerShell::GetIo() { 113 DebuggerInputOutput* DebuggerShell::GetIo() {
113 return io_.get(); 114 return io_.get();
114 } 115 }
115 116
116 v8::Handle<v8::Value> DebuggerShell::DelegateSubshell(const v8::Arguments& args) { 117 v8::Handle<v8::Value> DebuggerShell::DelegateSubshell(
118 const v8::Arguments& args) {
117 DebuggerShell* debugger = 119 DebuggerShell* debugger =
118 static_cast<DebuggerShell*>(v8::External::Cast(*args.Data())->Value()); 120 static_cast<DebuggerShell*>(v8::External::Cast(*args.Data())->Value());
119 return debugger->Subshell(args); 121 return debugger->Subshell(args);
120 } 122 }
121 123
122 v8::Handle<v8::Value> DebuggerShell::Subshell(const v8::Arguments& args) { 124 v8::Handle<v8::Value> DebuggerShell::Subshell(const v8::Arguments& args) {
123 if (args.Length() != 1) { 125 if (args.Length() != 1) {
124 return v8::Undefined(); 126 return v8::Undefined();
125 } 127 }
126 if (!shell_.IsEmpty()) { 128 if (!shell_.IsEmpty()) {
127 shell_.Dispose(); 129 shell_.Dispose();
128 shell_.Clear(); 130 shell_.Clear();
129 v8_context_->Global()->Delete(v8::String::New("shell_")); 131 v8_context_->Global()->Delete(v8::String::New("shell_"));
130 } 132 }
131 if (args[0]->IsFunction()) { 133 if (args[0]->IsFunction()) {
132 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(args[0]); 134 v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(args[0]);
133 v8::Local<v8::Object> obj = func->NewInstance(); 135 v8::Local<v8::Object> obj = func->NewInstance();
134 if (!obj->IsUndefined()) { 136 if (!obj->IsUndefined()) {
135 shell_ = v8::Persistent<v8::Object>::New(obj); 137 shell_ = v8::Persistent<v8::Object>::New(obj);
136 v8_context_->Global()->Set(v8::String::New("shell_"), shell_); 138 v8_context_->Global()->Set(v8::String::New("shell_"), shell_);
137 } 139 }
138 } else if (args[0]->IsObject()) { 140 } else if (args[0]->IsObject()) {
139 shell_ = v8::Persistent<v8::Object>::New(v8::Local<v8::Object>::Cast(args[0] )); 141 shell_ =
142 v8::Persistent<v8::Object>::New(v8::Local<v8::Object>::Cast(args[0]));
140 v8_context_->Global()->Set(v8::String::New("shell_"), shell_); 143 v8_context_->Global()->Set(v8::String::New("shell_"), shell_);
141 } 144 }
142 return v8::Undefined(); 145 return v8::Undefined();
143 } 146 }
144 147
145 v8::Handle<v8::Value> DebuggerShell::SubshellFunction(const char* func, 148 v8::Handle<v8::Value> DebuggerShell::SubshellFunction(const char* func,
146 int argc, 149 int argc,
147 v8::Handle<v8::Value>* argv) { 150 v8::Handle<v8::Value>* argv) {
148 if (!shell_.IsEmpty()) { 151 if (!shell_.IsEmpty()) {
149 v8::Context::Scope scope(v8_context_); 152 v8::Context::Scope scope(v8_context_);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 v8::Handle<v8::Value> argv[] = {node->NewInstance()}; 231 v8::Handle<v8::Value> argv[] = {node->NewInstance()};
229 PrintObject(v8::Function::Cast(*function)->Call(global, 1, argv)); 232 PrintObject(v8::Function::Cast(*function)->Call(global, 1, argv));
230 } 233 }
231 } 234 }
232 235
233 void DebuggerShell::DebugMessage(const std::wstring& msg) { 236 void DebuggerShell::DebugMessage(const std::wstring& msg) {
234 v8::Locker locked; 237 v8::Locker locked;
235 v8::HandleScope scope; 238 v8::HandleScope scope;
236 239
237 if (msg.length()) { 240 if (msg.length()) {
238 if ((msg[0] == L'{' || msg[0] == L'[' || msg[0] == L'(') && (!shell_.IsEmpty ())) { 241 if ((msg[0] == L'{' || msg[0] == L'[' || msg[0] == L'(') &&
242 (!shell_.IsEmpty())) {
239 // v8's wide String constructor requires uint16 rather than wchar 243 // v8's wide String constructor requires uint16 rather than wchar
240 const uint16* data = reinterpret_cast<const uint16* >(msg.c_str()); 244 const uint16* data = reinterpret_cast<const uint16* >(msg.c_str());
241 v8::Handle<v8::Value> argv[] = {v8::String::New(data)}; 245 v8::Handle<v8::Value> argv[] = {v8::String::New(data)};
242 PrintObject(SubshellFunction("response", 1, argv)); 246 PrintObject(SubshellFunction("response", 1, argv));
243 PrintPrompt(); 247 PrintPrompt();
244 } else { 248 } else {
245 if (msg[msg.length() - 1] == L'\n') 249 if (msg[msg.length() - 1] == L'\n')
246 PrintString(msg); 250 PrintString(msg);
247 else 251 else
248 PrintLine(msg); 252 PrintLine(msg);
249 } 253 }
250 } 254 }
251 } 255 }
252 256
253 void DebuggerShell::OnDebugAttach() { 257 void DebuggerShell::OnDebugAttach() {
254 v8::Locker locked; 258 v8::Locker locked;
255 v8::HandleScope scope; 259 v8::HandleScope scope;
256 SubshellFunction("on_attach", 0, NULL); 260 SubshellFunction("on_attach", 0, NULL);
257 } 261 }
258 262
259 void DebuggerShell::OnDebugDisconnect() { 263 void DebuggerShell::OnDebugDisconnect() {
260 v8::Locker locked; 264 v8::Locker locked;
261 v8::HandleScope scope; 265 v8::HandleScope scope;
262 SubshellFunction("on_disconnect", 0, NULL); 266 SubshellFunction("on_disconnect", 0, NULL);
263 } 267 }
264 268
265 void DebuggerShell::ObjectToString(v8::Handle<v8::Value> result, std::wstring* s tr) { 269 void DebuggerShell::ObjectToString(v8::Handle<v8::Value> result,
270 std::wstring* str) {
266 v8::HandleScope scope; 271 v8::HandleScope scope;
267 if (!result.IsEmpty() && !result->IsUndefined()) { 272 if (!result.IsEmpty() && !result->IsUndefined()) {
268 v8::Local<v8::String> str_obj = result->ToString(); 273 v8::Local<v8::String> str_obj = result->ToString();
269 if (!str_obj.IsEmpty()) { 274 if (!str_obj.IsEmpty()) {
270 int length = str_obj->Length(); 275 int length = str_obj->Length();
271 wchar_t* buf = new wchar_t[length + 1]; 276 wchar_t* buf = new wchar_t[length + 1];
272 int size = str_obj->Write(reinterpret_cast<uint16_t*>(buf)); 277 int size = str_obj->Write(reinterpret_cast<uint16_t*>(buf));
273 str->clear(); 278 str->clear();
274 str->append(buf, size); 279 str->append(buf, size);
275 delete[] buf; 280 delete[] buf;
276 } 281 }
277 } 282 }
278 } 283 }
279 284
280 void DebuggerShell::ObjectToString(v8::Handle<v8::Value> result, std::string* st r) { 285 void DebuggerShell::ObjectToString(v8::Handle<v8::Value> result,
286 std::string* str) {
281 v8::HandleScope scope; 287 v8::HandleScope scope;
282 if (!result.IsEmpty() && !result->IsUndefined()) { 288 if (!result.IsEmpty() && !result->IsUndefined()) {
283 v8::Local<v8::String> str_obj = result->ToString(); 289 v8::Local<v8::String> str_obj = result->ToString();
284 if (!str_obj.IsEmpty()) { 290 if (!str_obj.IsEmpty()) {
285 int length = str_obj->Length(); 291 int length = str_obj->Length();
286 char* buf = new char[length + 1]; 292 char* buf = new char[length + 1];
287 str_obj->WriteAscii(buf); 293 str_obj->WriteAscii(buf);
288 str->clear(); 294 str->clear();
289 str->append(buf); 295 str->append(buf);
290 delete[] buf; 296 delete[] buf;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 v8::Local<v8::Script> code = 427 v8::Local<v8::Script> code =
422 v8::Script::Compile(v8::String::New(utf16), &origin); 428 v8::Script::Compile(v8::String::New(utf16), &origin);
423 if (!code.IsEmpty()) { 429 if (!code.IsEmpty()) {
424 v8::Local<v8::Value> result = code->Run(); 430 v8::Local<v8::Value> result = code->Run();
425 if (!result.IsEmpty()) { 431 if (!result.IsEmpty()) {
426 return result; 432 return result;
427 } 433 }
428 } 434 }
429 return v8::Undefined(); 435 return v8::Undefined();
430 } 436 }
OLDNEW
« no previous file with comments | « chrome/browser/debugger/debugger_node.cc ('k') | chrome/browser/dom_ui/dom_ui_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698