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

Side by Side Diff: src/inspector/V8Console.cpp

Issue 2292053003: [inspector] Build inspector under v8_enable_inspector build flag. (Closed)
Patch Set: owners Created 4 years, 3 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project 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 "src/inspector/V8Console.h" 5 #include "src/inspector/V8Console.h"
6 6
7 #include "src/base/macros.h"
7 #include "src/inspector/InjectedScript.h" 8 #include "src/inspector/InjectedScript.h"
8 #include "src/inspector/InspectedContext.h" 9 #include "src/inspector/InspectedContext.h"
9 #include "src/inspector/StringUtil.h" 10 #include "src/inspector/StringUtil.h"
10 #include "src/inspector/V8Compat.h"
11 #include "src/inspector/V8ConsoleMessage.h" 11 #include "src/inspector/V8ConsoleMessage.h"
12 #include "src/inspector/V8DebuggerAgentImpl.h" 12 #include "src/inspector/V8DebuggerAgentImpl.h"
13 #include "src/inspector/V8InspectorImpl.h" 13 #include "src/inspector/V8InspectorImpl.h"
14 #include "src/inspector/V8InspectorSessionImpl.h" 14 #include "src/inspector/V8InspectorSessionImpl.h"
15 #include "src/inspector/V8ProfilerAgentImpl.h" 15 #include "src/inspector/V8ProfilerAgentImpl.h"
16 #include "src/inspector/V8RuntimeAgentImpl.h" 16 #include "src/inspector/V8RuntimeAgentImpl.h"
17 #include "src/inspector/V8StackTraceImpl.h" 17 #include "src/inspector/V8StackTraceImpl.h"
18 #include "src/inspector/V8ValueCopier.h" 18 #include "src/inspector/V8ValueCopier.h"
19 #include "src/inspector/public/V8InspectorClient.h" 19
20 #include "include/v8-inspector.h"
20 21
21 namespace v8_inspector { 22 namespace v8_inspector {
22 23
23 namespace { 24 namespace {
24 25
25 v8::Local<v8::Private> inspectedContextPrivateKey(v8::Isolate* isolate) { 26 v8::Local<v8::Private> inspectedContextPrivateKey(v8::Isolate* isolate) {
26 return v8::Private::ForApi( 27 return v8::Private::ForApi(
27 isolate, toV8StringInternalized(isolate, "V8Console#InspectedContext")); 28 isolate, toV8StringInternalized(isolate, "V8Console#InspectedContext"));
28 } 29 }
29 30
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 248 }
248 249
249 void createBoundFunctionProperty(v8::Local<v8::Context> context, 250 void createBoundFunctionProperty(v8::Local<v8::Context> context,
250 v8::Local<v8::Object> console, 251 v8::Local<v8::Object> console,
251 const char* name, 252 const char* name,
252 v8::FunctionCallback callback, 253 v8::FunctionCallback callback,
253 const char* description = nullptr) { 254 const char* description = nullptr) {
254 v8::Local<v8::String> funcName = 255 v8::Local<v8::String> funcName =
255 toV8StringInternalized(context->GetIsolate(), name); 256 toV8StringInternalized(context->GetIsolate(), name);
256 v8::Local<v8::Function> func; 257 v8::Local<v8::Function> func;
257 if (!V8_FUNCTION_NEW_REMOVE_PROTOTYPE(context, callback, console, 0) 258 if (!v8::Function::New(context, callback, console, 0,
259 v8::ConstructorBehavior::kThrow)
258 .ToLocal(&func)) 260 .ToLocal(&func))
259 return; 261 return;
260 func->SetName(funcName); 262 func->SetName(funcName);
261 if (description) { 263 if (description) {
262 v8::Local<v8::String> returnValue = 264 v8::Local<v8::String> returnValue =
263 toV8String(context->GetIsolate(), description); 265 toV8String(context->GetIsolate(), description);
264 v8::Local<v8::Function> toStringFunction; 266 v8::Local<v8::Function> toStringFunction;
265 if (V8_FUNCTION_NEW_REMOVE_PROTOTYPE(context, returnDataCallback, 267 if (v8::Function::New(context, returnDataCallback, returnValue, 0,
266 returnValue, 0) 268 v8::ConstructorBehavior::kThrow)
267 .ToLocal(&toStringFunction)) 269 .ToLocal(&toStringFunction))
268 createDataProperty(context, func, toV8StringInternalized( 270 createDataProperty(context, func, toV8StringInternalized(
269 context->GetIsolate(), "toString"), 271 context->GetIsolate(), "toString"),
270 toStringFunction); 272 toStringFunction);
271 } 273 }
272 createDataProperty(context, console, funcName, func); 274 createDataProperty(context, console, funcName, func);
273 } 275 }
274 276
275 } // namespace 277 } // namespace
276 278
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 v8::Local<v8::Context> context = inspectedContext->context(); 656 v8::Local<v8::Context> context = inspectedContext->context();
655 v8::Context::Scope contextScope(context); 657 v8::Context::Scope contextScope(context);
656 v8::Isolate* isolate = context->GetIsolate(); 658 v8::Isolate* isolate = context->GetIsolate();
657 v8::MicrotasksScope microtasksScope(isolate, 659 v8::MicrotasksScope microtasksScope(isolate,
658 v8::MicrotasksScope::kDoNotRunMicrotasks); 660 v8::MicrotasksScope::kDoNotRunMicrotasks);
659 661
660 v8::Local<v8::Object> console = v8::Object::New(isolate); 662 v8::Local<v8::Object> console = v8::Object::New(isolate);
661 bool success = 663 bool success =
662 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false); 664 console->SetPrototype(context, v8::Object::New(isolate)).FromMaybe(false);
663 DCHECK(success); 665 DCHECK(success);
666 USE(success);
664 667
665 createBoundFunctionProperty(context, console, "debug", 668 createBoundFunctionProperty(context, console, "debug",
666 V8Console::debugCallback); 669 V8Console::debugCallback);
667 createBoundFunctionProperty(context, console, "error", 670 createBoundFunctionProperty(context, console, "error",
668 V8Console::errorCallback); 671 V8Console::errorCallback);
669 createBoundFunctionProperty(context, console, "info", 672 createBoundFunctionProperty(context, console, "info",
670 V8Console::infoCallback); 673 V8Console::infoCallback);
671 createBoundFunctionProperty(context, console, "log", V8Console::logCallback); 674 createBoundFunctionProperty(context, console, "log", V8Console::logCallback);
672 createBoundFunctionProperty(context, console, "warn", 675 createBoundFunctionProperty(context, console, "warn",
673 V8Console::warnCallback); 676 V8Console::warnCallback);
(...skipping 29 matching lines...) Expand all
703 createBoundFunctionProperty(context, console, "time", 706 createBoundFunctionProperty(context, console, "time",
704 V8Console::timeCallback); 707 V8Console::timeCallback);
705 createBoundFunctionProperty(context, console, "timeEnd", 708 createBoundFunctionProperty(context, console, "timeEnd",
706 V8Console::timeEndCallback); 709 V8Console::timeEndCallback);
707 createBoundFunctionProperty(context, console, "timeStamp", 710 createBoundFunctionProperty(context, console, "timeStamp",
708 V8Console::timeStampCallback); 711 V8Console::timeStampCallback);
709 712
710 if (hasMemoryAttribute) 713 if (hasMemoryAttribute)
711 console->SetAccessorProperty( 714 console->SetAccessorProperty(
712 toV8StringInternalized(isolate, "memory"), 715 toV8StringInternalized(isolate, "memory"),
713 V8_FUNCTION_NEW_REMOVE_PROTOTYPE( 716 v8::Function::New(context, V8Console::memoryGetterCallback, console, 0,
714 context, V8Console::memoryGetterCallback, console, 0) 717 v8::ConstructorBehavior::kThrow)
715 .ToLocalChecked(), 718 .ToLocalChecked(),
716 V8_FUNCTION_NEW_REMOVE_PROTOTYPE( 719 v8::Function::New(context, V8Console::memorySetterCallback,
717 context, V8Console::memorySetterCallback, v8::Local<v8::Value>(), 0) 720 v8::Local<v8::Value>(), 0,
721 v8::ConstructorBehavior::kThrow)
718 .ToLocalChecked(), 722 .ToLocalChecked(),
719 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT); 723 static_cast<v8::PropertyAttribute>(v8::None), v8::DEFAULT);
720 724
721 console->SetPrivate(context, inspectedContextPrivateKey(isolate), 725 console->SetPrivate(context, inspectedContextPrivateKey(isolate),
722 v8::External::New(isolate, inspectedContext)); 726 v8::External::New(isolate, inspectedContext));
723 return console; 727 return console;
724 } 728 }
725 729
726 void V8Console::clearInspectedContextIfNeeded(v8::Local<v8::Context> context, 730 void V8Console::clearInspectedContextIfNeeded(v8::Local<v8::Context> context,
727 v8::Local<v8::Object> console) { 731 v8::Local<v8::Object> console) {
728 v8::Isolate* isolate = context->GetIsolate(); 732 v8::Isolate* isolate = context->GetIsolate();
729 console->SetPrivate(context, inspectedContextPrivateKey(isolate), 733 console->SetPrivate(context, inspectedContextPrivateKey(isolate),
730 v8::External::New(isolate, nullptr)); 734 v8::External::New(isolate, nullptr));
731 } 735 }
732 736
733 v8::Local<v8::Object> V8Console::createCommandLineAPI( 737 v8::Local<v8::Object> V8Console::createCommandLineAPI(
734 InspectedContext* inspectedContext) { 738 InspectedContext* inspectedContext) {
735 v8::Local<v8::Context> context = inspectedContext->context(); 739 v8::Local<v8::Context> context = inspectedContext->context();
736 v8::Isolate* isolate = context->GetIsolate(); 740 v8::Isolate* isolate = context->GetIsolate();
737 v8::MicrotasksScope microtasksScope(isolate, 741 v8::MicrotasksScope microtasksScope(isolate,
738 v8::MicrotasksScope::kDoNotRunMicrotasks); 742 v8::MicrotasksScope::kDoNotRunMicrotasks);
739 743
740 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate); 744 v8::Local<v8::Object> commandLineAPI = v8::Object::New(isolate);
741 bool success = 745 bool success =
742 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false); 746 commandLineAPI->SetPrototype(context, v8::Null(isolate)).FromMaybe(false);
743 DCHECK(success); 747 DCHECK(success);
748 USE(success);
744 749
745 createBoundFunctionProperty(context, commandLineAPI, "dir", 750 createBoundFunctionProperty(context, commandLineAPI, "dir",
746 V8Console::dirCallback, 751 V8Console::dirCallback,
747 "function dir(value) { [Command Line API] }"); 752 "function dir(value) { [Command Line API] }");
748 createBoundFunctionProperty(context, commandLineAPI, "dirxml", 753 createBoundFunctionProperty(context, commandLineAPI, "dirxml",
749 V8Console::dirxmlCallback, 754 V8Console::dirxmlCallback,
750 "function dirxml(value) { [Command Line API] }"); 755 "function dirxml(value) { [Command Line API] }");
751 createBoundFunctionProperty(context, commandLineAPI, "profile", 756 createBoundFunctionProperty(context, commandLineAPI, "profile",
752 V8Console::profileCallback, 757 V8Console::profileCallback,
753 "function profile(title) { [Command Line API] }"); 758 "function profile(title) { [Command Line API] }");
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 void V8Console::CommandLineAPIScope::accessorGetterCallback( 822 void V8Console::CommandLineAPIScope::accessorGetterCallback(
818 v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) { 823 v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
819 CommandLineAPIScope* scope = static_cast<CommandLineAPIScope*>( 824 CommandLineAPIScope* scope = static_cast<CommandLineAPIScope*>(
820 info.Data().As<v8::External>()->Value()); 825 info.Data().As<v8::External>()->Value());
821 DCHECK(scope); 826 DCHECK(scope);
822 827
823 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); 828 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
824 if (scope->m_cleanup) { 829 if (scope->m_cleanup) {
825 bool removed = info.Holder()->Delete(context, name).FromMaybe(false); 830 bool removed = info.Holder()->Delete(context, name).FromMaybe(false);
826 DCHECK(removed); 831 DCHECK(removed);
832 USE(removed);
827 return; 833 return;
828 } 834 }
829 v8::Local<v8::Object> commandLineAPI = scope->m_commandLineAPI; 835 v8::Local<v8::Object> commandLineAPI = scope->m_commandLineAPI;
830 836
831 v8::Local<v8::Value> value; 837 v8::Local<v8::Value> value;
832 if (!commandLineAPI->Get(context, name).ToLocal(&value)) return; 838 if (!commandLineAPI->Get(context, name).ToLocal(&value)) return;
833 if (isCommandLineAPIGetter(toProtocolStringWithTypeCheck(name))) { 839 if (isCommandLineAPIGetter(toProtocolStringWithTypeCheck(name))) {
834 DCHECK(value->IsFunction()); 840 DCHECK(value->IsFunction());
835 v8::MicrotasksScope microtasks(info.GetIsolate(), 841 v8::MicrotasksScope microtasks(info.GetIsolate(),
836 v8::MicrotasksScope::kDoNotRunMicrotasks); 842 v8::MicrotasksScope::kDoNotRunMicrotasks);
(...skipping 11 matching lines...) Expand all
848 const v8::PropertyCallbackInfo<void>& info) { 854 const v8::PropertyCallbackInfo<void>& info) {
849 CommandLineAPIScope* scope = static_cast<CommandLineAPIScope*>( 855 CommandLineAPIScope* scope = static_cast<CommandLineAPIScope*>(
850 info.Data().As<v8::External>()->Value()); 856 info.Data().As<v8::External>()->Value());
851 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext(); 857 v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
852 if (!info.Holder()->Delete(context, name).FromMaybe(false)) return; 858 if (!info.Holder()->Delete(context, name).FromMaybe(false)) return;
853 if (!info.Holder()->CreateDataProperty(context, name, value).FromMaybe(false)) 859 if (!info.Holder()->CreateDataProperty(context, name, value).FromMaybe(false))
854 return; 860 return;
855 bool removed = 861 bool removed =
856 scope->m_installedMethods->Delete(context, name).FromMaybe(false); 862 scope->m_installedMethods->Delete(context, name).FromMaybe(false);
857 DCHECK(removed); 863 DCHECK(removed);
864 USE(removed);
858 } 865 }
859 866
860 V8Console::CommandLineAPIScope::CommandLineAPIScope( 867 V8Console::CommandLineAPIScope::CommandLineAPIScope(
861 v8::Local<v8::Context> context, v8::Local<v8::Object> commandLineAPI, 868 v8::Local<v8::Context> context, v8::Local<v8::Object> commandLineAPI,
862 v8::Local<v8::Object> global) 869 v8::Local<v8::Object> global)
863 : m_context(context), 870 : m_context(context),
864 m_commandLineAPI(commandLineAPI), 871 m_commandLineAPI(commandLineAPI),
865 m_global(global), 872 m_global(global),
866 m_installedMethods(v8::Set::New(context->GetIsolate())), 873 m_installedMethods(v8::Set::New(context->GetIsolate())),
867 m_cleanup(false) { 874 m_cleanup(false) {
868 v8::Local<v8::Array> names; 875 v8::Local<v8::Array> names;
869 if (!m_commandLineAPI->GetOwnPropertyNames(context).ToLocal(&names)) return; 876 if (!m_commandLineAPI->GetOwnPropertyNames(context).ToLocal(&names)) return;
870 v8::Local<v8::External> externalThis = 877 v8::Local<v8::External> externalThis =
871 v8::External::New(context->GetIsolate(), this); 878 v8::External::New(context->GetIsolate(), this);
872 for (size_t i = 0; i < names->Length(); ++i) { 879 for (size_t i = 0; i < names->Length(); ++i) {
873 v8::Local<v8::Value> name; 880 v8::Local<v8::Value> name;
874 if (!names->Get(context, i).ToLocal(&name) || !name->IsName()) continue; 881 if (!names->Get(context, i).ToLocal(&name) || !name->IsName()) continue;
875 if (m_global->Has(context, name).FromMaybe(true)) continue; 882 if (m_global->Has(context, name).FromMaybe(true)) continue;
876 if (!m_installedMethods->Add(context, name).ToLocal(&m_installedMethods)) 883 if (!m_installedMethods->Add(context, name).ToLocal(&m_installedMethods))
877 continue; 884 continue;
878 if (!m_global 885 if (!m_global
879 ->SetAccessor(context, v8::Local<v8::Name>::Cast(name), 886 ->SetAccessor(context, v8::Local<v8::Name>::Cast(name),
880 CommandLineAPIScope::accessorGetterCallback, 887 CommandLineAPIScope::accessorGetterCallback,
881 CommandLineAPIScope::accessorSetterCallback, 888 CommandLineAPIScope::accessorSetterCallback,
882 externalThis, v8::DEFAULT, v8::DontEnum) 889 externalThis, v8::DEFAULT, v8::DontEnum)
883 .FromMaybe(false)) { 890 .FromMaybe(false)) {
884 bool removed = m_installedMethods->Delete(context, name).FromMaybe(false); 891 bool removed = m_installedMethods->Delete(context, name).FromMaybe(false);
885 DCHECK(removed); 892 DCHECK(removed);
893 USE(removed);
886 continue; 894 continue;
887 } 895 }
888 } 896 }
889 } 897 }
890 898
891 V8Console::CommandLineAPIScope::~CommandLineAPIScope() { 899 V8Console::CommandLineAPIScope::~CommandLineAPIScope() {
892 m_cleanup = true; 900 m_cleanup = true;
893 v8::Local<v8::Array> names = m_installedMethods->AsArray(); 901 v8::Local<v8::Array> names = m_installedMethods->AsArray();
894 for (size_t i = 0; i < names->Length(); ++i) { 902 for (size_t i = 0; i < names->Length(); ++i) {
895 v8::Local<v8::Value> name; 903 v8::Local<v8::Value> name;
896 if (!names->Get(m_context, i).ToLocal(&name) || !name->IsName()) continue; 904 if (!names->Get(m_context, i).ToLocal(&name) || !name->IsName()) continue;
897 if (name->IsString()) { 905 if (name->IsString()) {
898 v8::Local<v8::Value> descriptor; 906 v8::Local<v8::Value> descriptor;
899 bool success = m_global 907 bool success = m_global
900 ->GetOwnPropertyDescriptor( 908 ->GetOwnPropertyDescriptor(
901 m_context, v8::Local<v8::String>::Cast(name)) 909 m_context, v8::Local<v8::String>::Cast(name))
902 .ToLocal(&descriptor); 910 .ToLocal(&descriptor);
903 DCHECK(success); 911 DCHECK(success);
912 USE(success);
904 } 913 }
905 } 914 }
906 } 915 }
907 916
908 } // namespace v8_inspector 917 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698