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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8Console.cpp

Issue 1991043002: [DevTools] Set toString for native CommandLineAPI methods in native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "platform/v8_inspector/V8Console.h" 5 #include "platform/v8_inspector/V8Console.h"
6 6
7 #include "platform/inspector_protocol/String16.h" 7 #include "platform/inspector_protocol/String16.h"
8 #include "platform/v8_inspector/InjectedScript.h" 8 #include "platform/v8_inspector/InjectedScript.h"
9 #include "platform/v8_inspector/InspectedContext.h" 9 #include "platform/v8_inspector/InspectedContext.h"
10 #include "platform/v8_inspector/V8DebuggerAgentImpl.h" 10 #include "platform/v8_inspector/V8DebuggerAgentImpl.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (flagValue->IsBoolean()) { 232 if (flagValue->IsBoolean()) {
233 ASSERT(flagValue.As<v8::Boolean>()->Value()); 233 ASSERT(flagValue.As<v8::Boolean>()->Value());
234 return true; 234 return true;
235 } 235 }
236 if (!console->SetPrivate(m_context, key, v8::True(m_isolate)).FromMaybe( false)) 236 if (!console->SetPrivate(m_context, key, v8::True(m_isolate)).FromMaybe( false))
237 return defaultValue; 237 return defaultValue;
238 return false; 238 return false;
239 } 239 }
240 }; 240 };
241 241
242 void createBoundFunctionProperty(v8::Local<v8::Context> context, v8::Local<v8::O bject> console, const char* name, v8::FunctionCallback callback) 242 void returnDataCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
243 {
244 info.GetReturnValue().Set(info.Data());
245 }
246
247 void createBoundFunctionProperty(v8::Local<v8::Context> context, v8::Local<v8::O bject> console, const char* name, v8::FunctionCallback callback, const char* des cription = nullptr)
243 { 248 {
244 v8::Local<v8::String> funcName = toV8StringInternalized(context->GetIsolate( ), name); 249 v8::Local<v8::String> funcName = toV8StringInternalized(context->GetIsolate( ), name);
245 v8::Local<v8::Function> func; 250 v8::Local<v8::Function> func;
246 if (!v8::Function::New(context, callback, console).ToLocal(&func)) 251 if (!v8::Function::New(context, callback, console).ToLocal(&func))
247 return; 252 return;
248 func->SetName(funcName); 253 func->SetName(funcName);
254 if (description) {
255 v8::Local<v8::String> returnValue = toV8String(context->GetIsolate(), de scription);
256 v8::Local<v8::Function> toStringFunction;
257 if (v8::Function::New(context, returnDataCallback, returnValue).ToLocal( &toStringFunction))
258 func->Set(toV8StringInternalized(context->GetIsolate(), "toString"), toStringFunction);
259 }
249 if (!console->Set(context, funcName, func).FromMaybe(false)) 260 if (!console->Set(context, funcName, func).FromMaybe(false))
250 return; 261 return;
251 } 262 }
252 263
253 } // namespace 264 } // namespace
254 265
255 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info) 266 void V8Console::debugCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
256 { 267 {
257 ConsoleHelper(info).addMessage(LogMessageType, DebugMessageLevel, false, 0); 268 ConsoleHelper(info).addMessage(LogMessageType, DebugMessageLevel, false, 0);
258 } 269 }
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 } 663 }
653 664
654 v8::Local<v8::Object> V8Console::createCommandLineAPI(InspectedContext* inspecte dContext) 665 v8::Local<v8::Object> V8Console::createCommandLineAPI(InspectedContext* inspecte dContext)
655 { 666 {
656 v8::Local<v8::Context> context = inspectedContext->context(); 667 v8::Local<v8::Context> context = inspectedContext->context();
657 v8::Isolate* isolate = context->GetIsolate(); 668 v8::Isolate* isolate = context->GetIsolate();
658 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks); 669 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM icrotasks);
659 670
660 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); 671 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate);
661 672
662 createBoundFunctionProperty(context, commandLineAPI, "dir", V8Console::dirCa llback); 673 createBoundFunctionProperty(context, commandLineAPI, "dir", V8Console::dirCa llback, "function dir(value) { [Command Line API] }");
663 createBoundFunctionProperty(context, commandLineAPI, "dirxml", V8Console::di rxmlCallback); 674 createBoundFunctionProperty(context, commandLineAPI, "dirxml", V8Console::di rxmlCallback, "function dirxml(value) { [Command Line API] }");
664 createBoundFunctionProperty(context, commandLineAPI, "profile", V8Console::p rofileCallback); 675 createBoundFunctionProperty(context, commandLineAPI, "profile", V8Console::p rofileCallback, "function profile(title) { [Command Line API] }");
665 createBoundFunctionProperty(context, commandLineAPI, "profileEnd", V8Console ::profileEndCallback); 676 createBoundFunctionProperty(context, commandLineAPI, "profileEnd", V8Console ::profileEndCallback, "function profileEnd(title) { [Command Line API] }");
666 createBoundFunctionProperty(context, commandLineAPI, "clear", V8Console::cle arCallback); 677 createBoundFunctionProperty(context, commandLineAPI, "clear", V8Console::cle arCallback, "function clear() { [Command Line API] }");
667 createBoundFunctionProperty(context, commandLineAPI, "table", V8Console::tab leCallback); 678 createBoundFunctionProperty(context, commandLineAPI, "table", V8Console::tab leCallback, "function table(data, [columns]) { [Command Line API] }");
668 679
669 createBoundFunctionProperty(context, commandLineAPI, "keys", V8Console::keys Callback); 680 createBoundFunctionProperty(context, commandLineAPI, "keys", V8Console::keys Callback, "function keys(object) { [Command Line API] }");
670 createBoundFunctionProperty(context, commandLineAPI, "values", V8Console::va luesCallback); 681 createBoundFunctionProperty(context, commandLineAPI, "values", V8Console::va luesCallback, "function values(object) { [Command Line API] }");
671 createBoundFunctionProperty(context, commandLineAPI, "debug", V8Console::deb ugFunctionCallback); 682 createBoundFunctionProperty(context, commandLineAPI, "debug", V8Console::deb ugFunctionCallback, "function debug(function) { [Command Line API] }");
672 createBoundFunctionProperty(context, commandLineAPI, "undebug", V8Console::u ndebugFunctionCallback); 683 createBoundFunctionProperty(context, commandLineAPI, "undebug", V8Console::u ndebugFunctionCallback, "function undebug(function) { [Command Line API] }");
673 createBoundFunctionProperty(context, commandLineAPI, "monitor", V8Console::m onitorFunctionCallback); 684 createBoundFunctionProperty(context, commandLineAPI, "monitor", V8Console::m onitorFunctionCallback, "function monitor(function) { [Command Line API] }");
674 createBoundFunctionProperty(context, commandLineAPI, "unmonitor", V8Console: :unmonitorFunctionCallback); 685 createBoundFunctionProperty(context, commandLineAPI, "unmonitor", V8Console: :unmonitorFunctionCallback, "function unmonitor(function) { [Command Line API] } ");
675 createBoundFunctionProperty(context, commandLineAPI, "inspect", V8Console::i nspectCallback); 686 createBoundFunctionProperty(context, commandLineAPI, "inspect", V8Console::i nspectCallback, "function inspect(object) { [Command Line API] }");
676 createBoundFunctionProperty(context, commandLineAPI, "copy", V8Console::copy Callback); 687 createBoundFunctionProperty(context, commandLineAPI, "copy", V8Console::copy Callback, "function copy(value) { [Command Line API] }");
677 createBoundFunctionProperty(context, commandLineAPI, "$_", V8Console::lastEv aluationResultCallback); 688 createBoundFunctionProperty(context, commandLineAPI, "$_", V8Console::lastEv aluationResultCallback);
678 createBoundFunctionProperty(context, commandLineAPI, "$0", V8Console::inspec tedObject0); 689 createBoundFunctionProperty(context, commandLineAPI, "$0", V8Console::inspec tedObject0);
679 createBoundFunctionProperty(context, commandLineAPI, "$1", V8Console::inspec tedObject1); 690 createBoundFunctionProperty(context, commandLineAPI, "$1", V8Console::inspec tedObject1);
680 createBoundFunctionProperty(context, commandLineAPI, "$2", V8Console::inspec tedObject2); 691 createBoundFunctionProperty(context, commandLineAPI, "$2", V8Console::inspec tedObject2);
681 createBoundFunctionProperty(context, commandLineAPI, "$3", V8Console::inspec tedObject3); 692 createBoundFunctionProperty(context, commandLineAPI, "$3", V8Console::inspec tedObject3);
682 createBoundFunctionProperty(context, commandLineAPI, "$4", V8Console::inspec tedObject4); 693 createBoundFunctionProperty(context, commandLineAPI, "$4", V8Console::inspec tedObject4);
683 694
684 commandLineAPI->SetPrivate(context, inspectedContextPrivateKey(isolate), v8: :External::New(isolate, inspectedContext)); 695 commandLineAPI->SetPrivate(context, inspectedContextPrivateKey(isolate), v8: :External::New(isolate, inspectedContext));
685 return commandLineAPI; 696 return commandLineAPI;
686 } 697 }
(...skipping 22 matching lines...) Expand all
709 DEFINE_STATIC_LOCAL(protocol::HashSet<String16>, getters, ()); 720 DEFINE_STATIC_LOCAL(protocol::HashSet<String16>, getters, ());
710 if (getters.size() == 0) { 721 if (getters.size() == 0) {
711 const char* members[] = { "$0", "$1", "$2", "$3", "$4", "$_" }; 722 const char* members[] = { "$0", "$1", "$2", "$3", "$4", "$_" };
712 for (size_t i = 0; i < WTF_ARRAY_LENGTH(members); ++i) 723 for (size_t i = 0; i < WTF_ARRAY_LENGTH(members); ++i)
713 getters.add(members[i]); 724 getters.add(members[i]);
714 } 725 }
715 return getters.find(name) != getters.end(); 726 return getters.find(name) != getters.end();
716 } 727 }
717 728
718 } // namespace blink 729 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/v8_inspector/InjectedScriptSource.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698