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

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

Issue 1826623002: [DevTools] Move wrapCallFrames from InjectedScriptSource.js to native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove-no-scopes
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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 using blink::protocol::Runtime::RemoteObject; 54 using blink::protocol::Runtime::RemoteObject;
55 using blink::protocol::Maybe; 55 using blink::protocol::Maybe;
56 56
57 namespace blink { 57 namespace blink {
58 58
59 static void weakCallback(const v8::WeakCallbackInfo<InjectedScript>& data) 59 static void weakCallback(const v8::WeakCallbackInfo<InjectedScript>& data)
60 { 60 {
61 data.GetParameter()->dispose(); 61 data.GetParameter()->dispose();
62 } 62 }
63 63
64 static bool hasInternalError(ErrorString* errorString, bool hasError)
65 {
66 if (hasError)
67 *errorString = "Internal error";
68 return hasError;
69 }
70
64 InjectedScript::InjectedScript(InjectedScriptManager* manager, v8::Local<v8::Con text> context, v8::Local<v8::Object> object, PassOwnPtr<InjectedScriptNative> in jectedScriptNative, int contextId) 71 InjectedScript::InjectedScript(InjectedScriptManager* manager, v8::Local<v8::Con text> context, v8::Local<v8::Object> object, PassOwnPtr<InjectedScriptNative> in jectedScriptNative, int contextId)
65 : m_manager(manager) 72 : m_manager(manager)
66 , m_isolate(context->GetIsolate()) 73 , m_isolate(context->GetIsolate())
67 , m_context(m_isolate, context) 74 , m_context(m_isolate, context)
68 , m_value(m_isolate, object) 75 , m_value(m_isolate, object)
69 , m_native(injectedScriptNative) 76 , m_native(injectedScriptNative)
70 , m_contextId(contextId) 77 , m_contextId(contextId)
71 { 78 {
72 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter); 79 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter);
73 } 80 }
(...skipping 29 matching lines...) Expand all
103 return; 110 return;
104 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb jectId.get()); 111 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb jectId.get());
105 if (!object) 112 if (!object)
106 return; 113 return;
107 int boundId = 0; 114 int boundId = 0;
108 if (!object->getNumber("id", &boundId)) 115 if (!object->getNumber("id", &boundId))
109 return; 116 return;
110 m_native->unbind(boundId); 117 m_native->unbind(boundId);
111 } 118 }
112 119
113 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames)
114 {
115 v8::HandleScope handles(m_isolate);
116 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapCa llFrames");
117 function.appendArgument(callFrames);
118 bool hadException = false;
119 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException);
120 ASSERT(!hadException);
121 OwnPtr<protocol::Value> result = toProtocolValue(context(), callFramesValue) ;
122 protocol::ErrorSupport errors;
123 if (result && result->type() == protocol::Value::TypeArray)
124 return Array<CallFrame>::parse(result.get(), &errors);
125 return Array<CallFrame>::create();
126 }
127
128 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(ErrorStri ng* errorString, v8::Local<v8::Value> value, const String16& groupName, bool for ceValueType, bool generatePreview) const 120 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(ErrorStri ng* errorString, v8::Local<v8::Value> value, const String16& groupName, bool for ceValueType, bool generatePreview) const
129 { 121 {
130 v8::HandleScope handles(m_isolate); 122 v8::HandleScope handles(m_isolate);
131 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb ject"); 123 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb ject");
132 v8::Local<v8::Value> wrappedObject; 124 v8::Local<v8::Value> wrappedObject;
133 if (!wrapValue(errorString, value, groupName, forceValueType, generatePrevie w).ToLocal(&wrappedObject)) 125 if (!wrapValue(errorString, value, groupName, forceValueType, generatePrevie w).ToLocal(&wrappedObject))
134 return nullptr; 126 return nullptr;
135 protocol::ErrorSupport errors; 127 protocol::ErrorSupport errors;
136 OwnPtr<protocol::Runtime::RemoteObject> remoteObject = protocol::Runtime::Re moteObject::parse(toProtocolValue(context(), wrappedObject).get(), &errors); 128 OwnPtr<protocol::Runtime::RemoteObject> remoteObject = protocol::Runtime::Re moteObject::parse(toProtocolValue(context(), wrappedObject).get(), &errors);
137 if (!remoteObject) 129 if (!remoteObject)
138 *errorString = "Object has too long reference chain"; 130 *errorString = "Object has too long reference chain";
139 return remoteObject.release(); 131 return remoteObject.release();
140 } 132 }
141 133
142 bool InjectedScript::wrapObjectProperty(ErrorString* error, v8::Local<v8::Object > object, v8::Local<v8::Value> key, const String16& groupName, bool forceValueTy pe, bool generatePreview) const 134 bool InjectedScript::wrapObjectProperty(ErrorString* errorString, v8::Local<v8:: Object> object, v8::Local<v8::Value> key, const String16& groupName, bool forceV alueType, bool generatePreview) const
143 { 135 {
144 v8::Local<v8::Value> property; 136 v8::Local<v8::Value> property;
145 if (!object->Get(context(), key).ToLocal(&property)) { 137 if (hasInternalError(errorString, !object->Get(context(), key).ToLocal(&prop erty)))
146 *error = "Internal error.";
147 return false; 138 return false;
148 }
149 v8::Local<v8::Value> wrappedProperty; 139 v8::Local<v8::Value> wrappedProperty;
150 if (!wrapValue(error, property, groupName, forceValueType, generatePreview). ToLocal(&wrappedProperty)) 140 if (!wrapValue(errorString, property, groupName, forceValueType, generatePre view).ToLocal(&wrappedProperty))
151 return false; 141 return false;
152 v8::Maybe<bool> success = object->Set(context(), key, wrappedProperty); 142 v8::Maybe<bool> success = object->Set(context(), key, wrappedProperty);
153 if (success.IsNothing() || !success.FromJust()) { 143 if (hasInternalError(errorString, success.IsNothing() || !success.FromJust() ))
154 *error = "Internal error.";
155 return false; 144 return false;
156 }
157 return true; 145 return true;
158 } 146 }
159 147
160 bool InjectedScript::wrapPropertyInArray(ErrorString* errorString, v8::Local<v8: :Array> array, v8::Local<v8::String> property, const String16& groupName, bool f orceValueType, bool generatePreview) const 148 bool InjectedScript::wrapPropertyInArray(ErrorString* errorString, v8::Local<v8: :Array> array, v8::Local<v8::String> property, const String16& groupName, bool f orceValueType, bool generatePreview) const
161 { 149 {
162 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapPr opertyInArray"); 150 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapPr opertyInArray");
163 function.appendArgument(array); 151 function.appendArgument(array);
164 function.appendArgument(property); 152 function.appendArgument(property);
165 function.appendArgument(groupName); 153 function.appendArgument(groupName);
166 function.appendArgument(canAccessInspectedWindow()); 154 function.appendArgument(canAccessInspectedWindow());
167 function.appendArgument(forceValueType); 155 function.appendArgument(forceValueType);
168 function.appendArgument(generatePreview); 156 function.appendArgument(generatePreview);
169 bool hadException = false; 157 bool hadException = false;
170 callFunctionWithEvalEnabled(function, hadException); 158 callFunctionWithEvalEnabled(function, hadException);
171 if (hadException) 159 return !hasInternalError(errorString, hadException);
172 *errorString = "Internal error.";
173 return !hadException;
174 } 160 }
175 161
176 v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(ErrorString* error, v8::Loca l<v8::Value> value, const String16& groupName, bool forceValueType, bool generat ePreview) const 162 bool InjectedScript::wrapObjectsInArray(ErrorString* errorString, v8::Local<v8:: Array> array, const String16& groupName, bool forceValueType, bool generatePrevi ew) const
163 {
164 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb jectsInArray");
165 function.appendArgument(array);
166 function.appendArgument(groupName);
167 function.appendArgument(canAccessInspectedWindow());
168 function.appendArgument(forceValueType);
169 function.appendArgument(generatePreview);
170 bool hadException = false;
171 callFunctionWithEvalEnabled(function, hadException);
172 return !hasInternalError(errorString, hadException);
173 }
174
175 v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(ErrorString* errorString, v8 ::Local<v8::Value> value, const String16& groupName, bool forceValueType, bool g eneratePreview) const
177 { 176 {
178 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb ject"); 177 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb ject");
179 function.appendArgument(value); 178 function.appendArgument(value);
180 function.appendArgument(groupName); 179 function.appendArgument(groupName);
181 function.appendArgument(canAccessInspectedWindow()); 180 function.appendArgument(canAccessInspectedWindow());
182 function.appendArgument(forceValueType); 181 function.appendArgument(forceValueType);
183 function.appendArgument(generatePreview); 182 function.appendArgument(generatePreview);
184 bool hadException = false; 183 bool hadException = false;
185 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ; 184 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ;
186 if (hadException) { 185 if (hasInternalError(errorString, hadException))
187 *error = "Internal error.";
188 return v8::MaybeLocal<v8::Value>(); 186 return v8::MaybeLocal<v8::Value>();
189 }
190 return r; 187 return r;
191 } 188 }
192 189
193 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local< v8::Value> table, v8::Local<v8::Value> columns) const 190 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local< v8::Value> table, v8::Local<v8::Value> columns) const
194 { 191 {
195 v8::HandleScope handles(m_isolate); 192 v8::HandleScope handles(m_isolate);
196 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapTa ble"); 193 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapTa ble");
197 function.appendArgument(canAccessInspectedWindow()); 194 function.appendArgument(canAccessInspectedWindow());
198 function.appendArgument(table); 195 function.appendArgument(table);
199 if (columns.IsEmpty()) 196 if (columns.IsEmpty())
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 { 315 {
319 m_manager->discardInjectedScript(m_contextId); 316 m_manager->discardInjectedScript(m_contextId);
320 } 317 }
321 318
322 bool InjectedScript::setLastEvaluationResult(ErrorString* errorString, v8::Local <v8::Value> value) 319 bool InjectedScript::setLastEvaluationResult(ErrorString* errorString, v8::Local <v8::Value> value)
323 { 320 {
324 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "setLas tEvaluationResult"); 321 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "setLas tEvaluationResult");
325 function.appendArgument(value); 322 function.appendArgument(value);
326 bool hadException = false; 323 bool hadException = false;
327 function.call(hadException, false); 324 function.call(hadException, false);
328 if (hadException) 325 return !hasInternalError(errorString, hadException);
329 *errorString = "Internal error";
330 return !hadException;
331 } 326 }
332 327
333 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error String, protocol::Runtime::CallArgument* callArgument) 328 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error String, protocol::Runtime::CallArgument* callArgument)
334 { 329 {
335 if (callArgument->hasObjectId()) { 330 if (callArgument->hasObjectId()) {
336 OwnPtr<RemoteObjectId> remoteObjectId = RemoteObjectId::parse(errorStrin g, callArgument->getObjectId("")); 331 OwnPtr<RemoteObjectId> remoteObjectId = RemoteObjectId::parse(errorStrin g, callArgument->getObjectId(""));
337 if (!remoteObjectId) 332 if (!remoteObjectId)
338 return v8::MaybeLocal<v8::Value>(); 333 return v8::MaybeLocal<v8::Value>();
339 if (remoteObjectId->contextId() != m_contextId) { 334 if (remoteObjectId->contextId() != m_contextId) {
340 *errorString = "Argument should belong to the same JavaScript world as target object"; 335 *errorString = "Argument should belong to the same JavaScript world as target object";
(...skipping 29 matching lines...) Expand all
370 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "remote ObjectAPI"); 365 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "remote ObjectAPI");
371 function.appendArgument(groupName); 366 function.appendArgument(groupName);
372 return callFunctionReturnObject(errorString, function); 367 return callFunctionReturnObject(errorString, function);
373 } 368 }
374 369
375 v8::MaybeLocal<v8::Object> InjectedScript::callFunctionReturnObject(ErrorString* errorString, V8FunctionCall& function) const 370 v8::MaybeLocal<v8::Object> InjectedScript::callFunctionReturnObject(ErrorString* errorString, V8FunctionCall& function) const
376 { 371 {
377 bool hadException = false; 372 bool hadException = false;
378 v8::Local<v8::Value> result = function.call(hadException, false); 373 v8::Local<v8::Value> result = function.call(hadException, false);
379 v8::Local<v8::Object> resultObject; 374 v8::Local<v8::Object> resultObject;
380 if (hadException || result.IsEmpty() || !result->ToObject(context()).ToLocal (&resultObject)) { 375 if (hasInternalError(errorString, hadException || result.IsEmpty() || !resul t->ToObject(context()).ToLocal(&resultObject)))
381 *errorString = "Internal error";
382 return v8::MaybeLocal<v8::Object>(); 376 return v8::MaybeLocal<v8::Object>();
383 }
384 return resultObject; 377 return resultObject;
385 } 378 }
386 379
387 PassOwnPtr<protocol::Runtime::ExceptionDetails> InjectedScript::createExceptionD etails(v8::Local<v8::Message> message) 380 PassOwnPtr<protocol::Runtime::ExceptionDetails> InjectedScript::createExceptionD etails(v8::Local<v8::Message> message)
388 { 381 {
389 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetailsObject = protoco l::Runtime::ExceptionDetails::create().setText(toProtocolString(message->Get())) .build(); 382 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetailsObject = protoco l::Runtime::ExceptionDetails::create().setText(toProtocolString(message->Get())) .build();
390 exceptionDetailsObject->setUrl(toProtocolStringWithTypeCheck(message->GetScr iptResourceName())); 383 exceptionDetailsObject->setUrl(toProtocolStringWithTypeCheck(message->GetScr iptResourceName()));
391 exceptionDetailsObject->setScriptId(String16::number(message->GetScriptOrigi n().ScriptID()->Value())); 384 exceptionDetailsObject->setScriptId(String16::number(message->GetScriptOrigi n().ScriptID()->Value()));
392 385
393 v8::Maybe<int> lineNumber = message->GetLineNumber(context()); 386 v8::Maybe<int> lineNumber = message->GetLineNumber(context());
394 if (lineNumber.IsJust()) 387 if (lineNumber.IsJust())
395 exceptionDetailsObject->setLine(lineNumber.FromJust()); 388 exceptionDetailsObject->setLine(lineNumber.FromJust());
396 v8::Maybe<int> columnNumber = message->GetStartColumn(context()); 389 v8::Maybe<int> columnNumber = message->GetStartColumn(context());
397 if (columnNumber.IsJust()) 390 if (columnNumber.IsJust())
398 exceptionDetailsObject->setColumn(columnNumber.FromJust()); 391 exceptionDetailsObject->setColumn(columnNumber.FromJust());
399 392
400 v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace(); 393 v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace();
401 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) 394 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0)
402 exceptionDetailsObject->setStack(m_manager->debugger()->createStackTrace (stackTrace, stackTrace->GetFrameCount())->buildInspectorObject()); 395 exceptionDetailsObject->setStack(m_manager->debugger()->createStackTrace (stackTrace, stackTrace->GetFrameCount())->buildInspectorObject());
403 return exceptionDetailsObject.release(); 396 return exceptionDetailsObject.release();
404 } 397 }
405 398
406 void InjectedScript::wrapEvaluateResult(ErrorString* errorString, v8::MaybeLocal <v8::Value> maybeResultValue, const v8::TryCatch& tryCatch, const String16& obje ctGroup, bool returnByValue, bool generatePreview, OwnPtr<protocol::Runtime::Rem oteObject>* result, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::ExceptionDe tails>* exceptionDetails) 399 void InjectedScript::wrapEvaluateResult(ErrorString* errorString, v8::MaybeLocal <v8::Value> maybeResultValue, const v8::TryCatch& tryCatch, const String16& obje ctGroup, bool returnByValue, bool generatePreview, OwnPtr<protocol::Runtime::Rem oteObject>* result, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::ExceptionDe tails>* exceptionDetails)
407 { 400 {
408 v8::Local<v8::Value> resultValue; 401 v8::Local<v8::Value> resultValue;
409 if (!tryCatch.HasCaught()) { 402 if (!tryCatch.HasCaught()) {
410 if (!maybeResultValue.ToLocal(&resultValue)) { 403 if (hasInternalError(errorString, !maybeResultValue.ToLocal(&resultValue )))
411 *errorString = "Internal error";
412 return; 404 return;
413 }
414 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, resultValue, objectGroup, returnByValue, generatePreview); 405 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, resultValue, objectGroup, returnByValue, generatePreview);
415 if (!remoteObject) 406 if (!remoteObject)
416 return; 407 return;
417 if (objectGroup == "console" && !setLastEvaluationResult(errorString, re sultValue)) 408 if (objectGroup == "console" && !setLastEvaluationResult(errorString, re sultValue))
418 return; 409 return;
419 *result = remoteObject.release(); 410 *result = remoteObject.release();
420 if (wasThrown) 411 if (wasThrown)
421 *wasThrown = false; 412 *wasThrown = false;
422 } else { 413 } else {
423 v8::Local<v8::Value> exception = tryCatch.Exception(); 414 v8::Local<v8::Value> exception = tryCatch.Exception();
424 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o bjectGroup, false, generatePreview && !exception->IsNativeError()); 415 OwnPtr<RemoteObject> remoteObject = wrapObject(errorString, exception, o bjectGroup, false, generatePreview && !exception->IsNativeError());
425 if (!remoteObject) 416 if (!remoteObject)
426 return; 417 return;
427 *result = remoteObject.release(); 418 *result = remoteObject.release();
428 if (exceptionDetails) 419 if (exceptionDetails)
429 *exceptionDetails = createExceptionDetails(tryCatch.Message()); 420 *exceptionDetails = createExceptionDetails(tryCatch.Message());
430 if (wasThrown) 421 if (wasThrown)
431 *wasThrown = true; 422 *wasThrown = true;
432 } 423 }
433 } 424 }
434 425
435 } // namespace blink 426 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698