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

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

Issue 1815753002: [DevTools] Move getFunctionDetails to native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-get-internal-properties
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/V8InjectedScriptHost.h" 5 #include "platform/v8_inspector/V8InjectedScriptHost.h"
6 6
7 #include "platform/inspector_protocol/String16.h" 7 #include "platform/inspector_protocol/String16.h"
8 #include "platform/inspector_protocol/Values.h" 8 #include "platform/inspector_protocol/Values.h"
9 #include "platform/v8_inspector/InjectedScript.h" 9 #include "platform/v8_inspector/InjectedScript.h"
10 #include "platform/v8_inspector/InjectedScriptHost.h" 10 #include "platform/v8_inspector/InjectedScriptHost.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 isolate->ThrowException(v8::Exception::TypeError(toV8String(isolate, "ar gument has to be an integer"))); 58 isolate->ThrowException(v8::Exception::TypeError(toV8String(isolate, "ar gument has to be an integer")));
59 return; 59 return;
60 } 60 }
61 61
62 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 62 v8::Local<v8::Context> context = isolate->GetCurrentContext();
63 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(context, info.Holder ()); 63 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(context, info.Holder ());
64 V8RuntimeAgent::Inspectable* object = host->inspectedObject(info[0].As<v8::I nt32>()->Value()); 64 V8RuntimeAgent::Inspectable* object = host->inspectedObject(info[0].As<v8::I nt32>()->Value());
65 v8SetReturnValue(info, object ? object->get(context) : v8::Local<v8::Value>( )); 65 v8SetReturnValue(info, object ? object->get(context) : v8::Local<v8::Value>( ));
66 } 66 }
67 67
68 static v8::Local<v8::String> functionDisplayName(v8::Local<v8::Function> functio n)
69 {
70 v8::Local<v8::Value> value = function->GetDebugName();
71 if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length())
72 return v8::Local<v8::String>::Cast(value);
73 return v8::Local<v8::String>();
74 }
75
76 void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal lbackInfo<v8::Value>& info) 68 void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal lbackInfo<v8::Value>& info)
77 { 69 {
78 if (info.Length() < 1 || !info[0]->IsObject()) 70 if (info.Length() < 1 || !info[0]->IsObject())
79 return; 71 return;
80 72
81 v8::Local<v8::Object> object = info[0].As<v8::Object>(); 73 v8::Local<v8::Object> object = info[0].As<v8::Object>();
82 v8::Local<v8::String> result = object->GetConstructorName(); 74 v8::Local<v8::String> result = object->GetConstructorName();
83 75
84 v8SetReturnValue(info, result); 76 v8SetReturnValue(info, result);
85 } 77 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G etCurrentContext(), info.Holder()); 138 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G etCurrentContext(), info.Holder());
147 if (!host->debugger()) 139 if (!host->debugger())
148 return; 140 return;
149 String16 subtype = host->debugger()->client()->valueSubtype(value); 141 String16 subtype = host->debugger()->client()->valueSubtype(value);
150 if (!subtype.isEmpty()) { 142 if (!subtype.isEmpty()) {
151 v8SetReturnValue(info, toV8String(isolate, subtype)); 143 v8SetReturnValue(info, toV8String(isolate, subtype));
152 return; 144 return;
153 } 145 }
154 } 146 }
155 147
156 void V8InjectedScriptHost::functionDetailsCallback(const v8::FunctionCallbackInf o<v8::Value>& info)
157 {
158 if (info.Length() < 1 || !info[0]->IsFunction())
159 return;
160
161 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]);
162 int lineNumber = function->GetScriptLineNumber();
163 int columnNumber = function->GetScriptColumnNumber();
164
165 v8::Isolate* isolate = info.GetIsolate();
166 v8::Local<v8::Object> location = v8::Object::New(isolate);
167 location->Set(toV8StringInternalized(isolate, "lineNumber"), v8::Integer::Ne w(isolate, lineNumber));
168 location->Set(toV8StringInternalized(isolate, "columnNumber"), v8::Integer:: New(isolate, columnNumber));
169 location->Set(toV8StringInternalized(isolate, "scriptId"), v8::Integer::New( isolate, function->ScriptId())->ToString(isolate));
170
171 v8::Local<v8::Object> result = v8::Object::New(isolate);
172 result->Set(toV8StringInternalized(isolate, "location"), location);
173
174 v8::Local<v8::String> name = functionDisplayName(function);
175 result->Set(toV8StringInternalized(isolate, "functionName"), name.IsEmpty() ? toV8StringInternalized(isolate, "") : name);
176 result->Set(toV8StringInternalized(isolate, "isGenerator"), v8::Boolean::New (isolate, function->IsGeneratorFunction()));
177
178 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G etCurrentContext(), info.Holder());
179 if (!host->debugger())
180 return;
181 v8::MaybeLocal<v8::Value> scopes = host->debugger()->functionScopes(function );
182 if (!scopes.IsEmpty() && scopes.ToLocalChecked()->IsArray())
183 result->Set(toV8StringInternalized(isolate, "rawScopes"), scopes.ToLocal Checked());
184
185 v8SetReturnValue(info, result);
186 }
187
188 void V8InjectedScriptHost::collectionEntriesCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) 148 void V8InjectedScriptHost::collectionEntriesCallback(const v8::FunctionCallbackI nfo<v8::Value>& info)
189 { 149 {
190 if (info.Length() < 1 || !info[0]->IsObject()) 150 if (info.Length() < 1 || !info[0]->IsObject())
191 return; 151 return;
192 152
193 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); 153 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]);
194 154
195 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G etCurrentContext(), info.Holder()); 155 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.GetIsolate()->G etCurrentContext(), info.Holder());
196 if (!host->debugger()) 156 if (!host->debugger())
197 return; 157 return;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 using InjectedScriptHostWrapper = InspectorWrapper<InjectedScriptHost, hiddenPro pertyName, className>; 446 using InjectedScriptHostWrapper = InspectorWrapper<InjectedScriptHost, hiddenPro pertyName, className>;
487 447
488 const InjectedScriptHostWrapper::V8MethodConfiguration V8InjectedScriptHostMetho ds[] = { 448 const InjectedScriptHostWrapper::V8MethodConfiguration V8InjectedScriptHostMetho ds[] = {
489 {"clearConsoleMessages", V8InjectedScriptHost::clearConsoleMessagesCallback} , 449 {"clearConsoleMessages", V8InjectedScriptHost::clearConsoleMessagesCallback} ,
490 {"inspect", V8InjectedScriptHost::inspectCallback}, 450 {"inspect", V8InjectedScriptHost::inspectCallback},
491 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback}, 451 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback},
492 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal lback}, 452 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal lback},
493 {"formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsPrope rties}, 453 {"formatAccessorsAsProperties", V8InjectedScriptHost::formatAccessorsAsPrope rties},
494 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback}, 454 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback},
495 {"subtype", V8InjectedScriptHost::subtypeCallback}, 455 {"subtype", V8InjectedScriptHost::subtypeCallback},
496 {"functionDetails", V8InjectedScriptHost::functionDetailsCallback},
497 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback}, 456 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback},
498 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac k}, 457 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac k},
499 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback}, 458 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback},
500 {"eval", V8InjectedScriptHost::evalCallback}, 459 {"eval", V8InjectedScriptHost::evalCallback},
501 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback}, 460 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback},
502 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback}, 461 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback},
503 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback}, 462 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback},
504 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback}, 463 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback},
505 {"callFunction", V8InjectedScriptHost::callFunctionCallback}, 464 {"callFunction", V8InjectedScriptHost::callFunctionCallback},
506 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn dCallFunctionCallback}, 465 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn dCallFunctionCallback},
(...skipping 17 matching lines...) Expand all
524 { 483 {
525 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); 484 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host);
526 } 485 }
527 486
528 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> object) 487 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Context> context, v8::Local<v8::Object> object)
529 { 488 {
530 return InjectedScriptHostWrapper::unwrap(context, object); 489 return InjectedScriptHostWrapper::unwrap(context, object);
531 } 490 }
532 491
533 } // namespace blink 492 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698