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

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

Issue 1702673002: DevTools: migrate remote debugging protocol generators to jinja2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 24 matching lines...) Expand all
35 #include "platform/JSONValuesForV8.h" 35 #include "platform/JSONValuesForV8.h"
36 #include "platform/v8_inspector/InjectedScriptHost.h" 36 #include "platform/v8_inspector/InjectedScriptHost.h"
37 #include "platform/v8_inspector/InjectedScriptManager.h" 37 #include "platform/v8_inspector/InjectedScriptManager.h"
38 #include "platform/v8_inspector/RemoteObjectId.h" 38 #include "platform/v8_inspector/RemoteObjectId.h"
39 #include "platform/v8_inspector/V8FunctionCall.h" 39 #include "platform/v8_inspector/V8FunctionCall.h"
40 #include "platform/v8_inspector/V8StringUtil.h" 40 #include "platform/v8_inspector/V8StringUtil.h"
41 #include "platform/v8_inspector/public/V8Debugger.h" 41 #include "platform/v8_inspector/public/V8Debugger.h"
42 #include "platform/v8_inspector/public/V8DebuggerClient.h" 42 #include "platform/v8_inspector/public/V8DebuggerClient.h"
43 #include "wtf/text/WTFString.h" 43 #include "wtf/text/WTFString.h"
44 44
45 using blink::protocol::TypeBuilder::Array; 45 using blink::protocol::Array;
46 using blink::protocol::TypeBuilder::Debugger::CallFrame; 46 using blink::protocol::Debugger::CallFrame;
47 using blink::protocol::TypeBuilder::Debugger::CollectionEntry; 47 using blink::protocol::Debugger::CollectionEntry;
48 using blink::protocol::TypeBuilder::Debugger::FunctionDetails; 48 using blink::protocol::Debugger::FunctionDetails;
49 using blink::protocol::TypeBuilder::Debugger::GeneratorObjectDetails; 49 using blink::protocol::Debugger::GeneratorObjectDetails;
50 using blink::protocol::TypeBuilder::Runtime::PropertyDescriptor; 50 using blink::protocol::Runtime::PropertyDescriptor;
51 using blink::protocol::TypeBuilder::Runtime::InternalPropertyDescriptor; 51 using blink::protocol::Runtime::InternalPropertyDescriptor;
52 using blink::protocol::TypeBuilder::Runtime::RemoteObject; 52 using blink::protocol::Runtime::RemoteObject;
53 using blink::protocol::OptionalValue;
53 54
54 namespace blink { 55 namespace blink {
55 56
56 static PassRefPtr<protocol::TypeBuilder::Runtime::ExceptionDetails> toExceptionD etails(PassRefPtr<JSONObject> object) 57 static PassOwnPtr<protocol::Runtime::ExceptionDetails> toExceptionDetails(PassRe fPtr<JSONObject> object)
57 { 58 {
58 String text; 59 String text;
59 if (!object->getString("text", &text)) 60 if (!object->getString("text", &text))
60 return nullptr; 61 return nullptr;
61 62
62 RefPtr<protocol::TypeBuilder::Runtime::ExceptionDetails> exceptionDetails = protocol::TypeBuilder::Runtime::ExceptionDetails::create().setText(text); 63 OwnPtr<protocol::Runtime::ExceptionDetails> exceptionDetails = protocol::Run time::ExceptionDetails::create().setText(text).build();
63 String url; 64 String url;
64 if (object->getString("url", &url)) 65 if (object->getString("url", &url))
65 exceptionDetails->setUrl(url); 66 exceptionDetails->setUrl(url);
66 int line = 0; 67 int line = 0;
67 if (object->getNumber("line", &line)) 68 if (object->getNumber("line", &line))
68 exceptionDetails->setLine(line); 69 exceptionDetails->setLine(line);
69 int column = 0; 70 int column = 0;
70 if (object->getNumber("column", &column)) 71 if (object->getNumber("column", &column))
71 exceptionDetails->setColumn(column); 72 exceptionDetails->setColumn(column);
72 int originScriptId = 0; 73 int originScriptId = 0;
73 object->getNumber("scriptId", &originScriptId); 74 object->getNumber("scriptId", &originScriptId);
74 75
75 RefPtr<JSONArray> stackTrace = object->getArray("stackTrace"); 76 RefPtr<JSONArray> stackTrace = object->getArray("stackTrace");
76 if (stackTrace && stackTrace->length() > 0) { 77 if (stackTrace && stackTrace->length() > 0) {
77 RefPtr<protocol::TypeBuilder::Array<protocol::TypeBuilder::Runtime::Call Frame>> frames = protocol::TypeBuilder::Array<protocol::TypeBuilder::Runtime::Ca llFrame>::create(); 78 OwnPtr<protocol::Array<protocol::Runtime::CallFrame>> frames = protocol: :Array<protocol::Runtime::CallFrame>::create();
78 for (unsigned i = 0; i < stackTrace->length(); ++i) { 79 for (unsigned i = 0; i < stackTrace->length(); ++i) {
79 RefPtr<JSONObject> stackFrame = stackTrace->get(i)->asObject(); 80 RefPtr<JSONObject> stackFrame = stackTrace->get(i)->asObject();
80 int lineNumber = 0; 81 int lineNumber = 0;
81 stackFrame->getNumber("lineNumber", &lineNumber); 82 stackFrame->getNumber("lineNumber", &lineNumber);
82 int column = 0; 83 int column = 0;
83 stackFrame->getNumber("column", &column); 84 stackFrame->getNumber("column", &column);
84 int scriptId = 0; 85 int scriptId = 0;
85 stackFrame->getNumber("scriptId", &scriptId); 86 stackFrame->getNumber("scriptId", &scriptId);
86 if (i == 0 && scriptId == originScriptId) 87 if (i == 0 && scriptId == originScriptId)
87 originScriptId = 0; 88 originScriptId = 0;
88 89
89 String sourceURL; 90 String sourceURL;
90 stackFrame->getString("scriptNameOrSourceURL", &sourceURL); 91 stackFrame->getString("scriptNameOrSourceURL", &sourceURL);
91 String functionName; 92 String functionName;
92 stackFrame->getString("functionName", &functionName); 93 stackFrame->getString("functionName", &functionName);
93 94
94 RefPtr<protocol::TypeBuilder::Runtime::CallFrame> callFrame = protoc ol::TypeBuilder::Runtime::CallFrame::create() 95 OwnPtr<protocol::Runtime::CallFrame> callFrame = protocol::Runtime:: CallFrame::create()
95 .setFunctionName(functionName) 96 .setFunctionName(functionName)
96 .setScriptId(String::number(scriptId)) 97 .setScriptId(String::number(scriptId))
97 .setUrl(sourceURL) 98 .setUrl(sourceURL)
98 .setLineNumber(lineNumber) 99 .setLineNumber(lineNumber)
99 .setColumnNumber(column); 100 .setColumnNumber(column).build();
100 101
101 frames->addItem(callFrame.release()); 102 frames->addItem(callFrame.release());
102 } 103 }
103 RefPtr<protocol::TypeBuilder::Runtime::StackTrace> stack = protocol::Typ eBuilder::Runtime::StackTrace::create() 104 OwnPtr<protocol::Runtime::StackTrace> stack = protocol::Runtime::StackTr ace::create()
104 .setCallFrames(frames.release()); 105 .setCallFrames(frames.release()).build();
105 exceptionDetails->setStack(stack.release()); 106 exceptionDetails->setStack(stack.release());
106 } 107 }
107 if (originScriptId) 108 if (originScriptId)
108 exceptionDetails->setScriptId(String::number(originScriptId)); 109 exceptionDetails->setScriptId(String::number(originScriptId));
109 return exceptionDetails.release(); 110 return exceptionDetails.release();
110 } 111 }
111 112
112 static void weakCallback(const v8::WeakCallbackInfo<InjectedScript>& data) 113 static void weakCallback(const v8::WeakCallbackInfo<InjectedScript>& data)
113 { 114 {
114 data.GetParameter()->dispose(); 115 data.GetParameter()->dispose();
115 } 116 }
116 117
117 InjectedScript::InjectedScript(InjectedScriptManager* manager, v8::Local<v8::Con text> context, v8::Local<v8::Object> object, V8DebuggerClient* client, PassRefPt r<InjectedScriptNative> injectedScriptNative, int contextId) 118 InjectedScript::InjectedScript(InjectedScriptManager* manager, v8::Local<v8::Con text> context, v8::Local<v8::Object> object, V8DebuggerClient* client, PassRefPt r<InjectedScriptNative> injectedScriptNative, int contextId)
118 : m_manager(manager) 119 : m_manager(manager)
119 , m_isolate(context->GetIsolate()) 120 , m_isolate(context->GetIsolate())
120 , m_context(m_isolate, context) 121 , m_context(m_isolate, context)
121 , m_value(m_isolate, object) 122 , m_value(m_isolate, object)
122 , m_client(client) 123 , m_client(client)
123 , m_native(injectedScriptNative) 124 , m_native(injectedScriptNative)
124 , m_contextId(contextId) 125 , m_contextId(contextId)
125 { 126 {
126 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter); 127 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter);
127 } 128 }
128 129
129 InjectedScript::~InjectedScript() 130 InjectedScript::~InjectedScript()
130 { 131 {
131 } 132 }
132 133
133 void InjectedScript::evaluate(ErrorString* errorString, const String& expression , const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, boo l generatePreview, RefPtr<protocol::TypeBuilder::Runtime::RemoteObject>* result, protocol::TypeBuilder::OptOutput<bool>* wasThrown, RefPtr<protocol::TypeBuilder ::Runtime::ExceptionDetails>* exceptionDetails) 134 void InjectedScript::evaluate(ErrorString* errorString, const String& expression , const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, boo l generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, OptionalValu e<bool>* wasThrown, OwnPtr<protocol::Runtime::ExceptionDetails>* exceptionDetail s)
134 { 135 {
135 v8::HandleScope handles(m_isolate); 136 v8::HandleScope handles(m_isolate);
136 V8FunctionCall function(m_client, context(), v8Value(), "evaluate"); 137 V8FunctionCall function(m_client, context(), v8Value(), "evaluate");
137 function.appendArgument(expression); 138 function.appendArgument(expression);
138 function.appendArgument(objectGroup); 139 function.appendArgument(objectGroup);
139 function.appendArgument(includeCommandLineAPI); 140 function.appendArgument(includeCommandLineAPI);
140 function.appendArgument(returnByValue); 141 function.appendArgument(returnByValue);
141 function.appendArgument(generatePreview); 142 function.appendArgument(generatePreview);
142 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); 143 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails);
143 } 144 }
144 145
145 void InjectedScript::callFunctionOn(ErrorString* errorString, const String& obje ctId, const String& expression, const String& arguments, bool returnByValue, boo l generatePreview, RefPtr<protocol::TypeBuilder::Runtime::RemoteObject>* result, protocol::TypeBuilder::OptOutput<bool>* wasThrown) 146 void InjectedScript::callFunctionOn(ErrorString* errorString, const String& obje ctId, const String& expression, const String& arguments, bool returnByValue, boo l generatePreview, OwnPtr<protocol::Runtime::RemoteObject>* result, OptionalValu e<bool>* wasThrown)
146 { 147 {
147 v8::HandleScope handles(m_isolate); 148 v8::HandleScope handles(m_isolate);
148 V8FunctionCall function(m_client, context(), v8Value(), "callFunctionOn"); 149 V8FunctionCall function(m_client, context(), v8Value(), "callFunctionOn");
149 function.appendArgument(objectId); 150 function.appendArgument(objectId);
150 function.appendArgument(expression); 151 function.appendArgument(expression);
151 function.appendArgument(arguments); 152 function.appendArgument(arguments);
152 function.appendArgument(returnByValue); 153 function.appendArgument(returnByValue);
153 function.appendArgument(generatePreview); 154 function.appendArgument(generatePreview);
154 makeEvalCall(errorString, function, result, wasThrown); 155 makeEvalCall(errorString, function, result, wasThrown);
155 } 156 }
156 157
157 void InjectedScript::evaluateOnCallFrame(ErrorString* errorString, v8::Local<v8: :Object> callFrames, bool isAsyncCallStack, const String& callFrameId, const Str ing& expression, const String& objectGroup, bool includeCommandLineAPI, bool ret urnByValue, bool generatePreview, RefPtr<RemoteObject>* result, protocol::TypeBu ilder::OptOutput<bool>* wasThrown, RefPtr<protocol::TypeBuilder::Runtime::Except ionDetails>* exceptionDetails) 158 void InjectedScript::evaluateOnCallFrame(ErrorString* errorString, v8::Local<v8: :Object> callFrames, bool isAsyncCallStack, const String& callFrameId, const Str ing& expression, const String& objectGroup, bool includeCommandLineAPI, bool ret urnByValue, bool generatePreview, OwnPtr<RemoteObject>* result, OptionalValue<bo ol>* wasThrown, OwnPtr<protocol::Runtime::ExceptionDetails>* exceptionDetails)
158 { 159 {
159 v8::HandleScope handles(m_isolate); 160 v8::HandleScope handles(m_isolate);
160 V8FunctionCall function(m_client, context(), v8Value(), "evaluateOnCallFrame "); 161 V8FunctionCall function(m_client, context(), v8Value(), "evaluateOnCallFrame ");
161 function.appendArgument(callFrames); 162 function.appendArgument(callFrames);
162 function.appendArgument(isAsyncCallStack); 163 function.appendArgument(isAsyncCallStack);
163 function.appendArgument(callFrameId); 164 function.appendArgument(callFrameId);
164 function.appendArgument(expression); 165 function.appendArgument(expression);
165 function.appendArgument(objectGroup); 166 function.appendArgument(objectGroup);
166 function.appendArgument(includeCommandLineAPI); 167 function.appendArgument(includeCommandLineAPI);
167 function.appendArgument(returnByValue); 168 function.appendArgument(returnByValue);
(...skipping 14 matching lines...) Expand all
182 resultValue->asString(errorString); 183 resultValue->asString(errorString);
183 } else { 184 } else {
184 bool value; 185 bool value;
185 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value); 186 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value);
186 } 187 }
187 return; 188 return;
188 } 189 }
189 *errorString = "Internal error"; 190 *errorString = "Internal error";
190 } 191 }
191 192
192 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8:: Object> callFrames, const String& callFrameId, RefPtr<Array<protocol::TypeBuilde r::Debugger::Location>>& positions) 193 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8:: Object> callFrames, const String& callFrameId, OwnPtr<Array<protocol::Debugger:: Location>>* positions)
193 { 194 {
194 v8::HandleScope handles(m_isolate); 195 v8::HandleScope handles(m_isolate);
195 V8FunctionCall function(m_client, context(), v8Value(), "getStepInPositions" ); 196 V8FunctionCall function(m_client, context(), v8Value(), "getStepInPositions" );
196 function.appendArgument(callFrames); 197 function.appendArgument(callFrames);
197 function.appendArgument(callFrameId); 198 function.appendArgument(callFrameId);
198 RefPtr<JSONValue> resultValue; 199 RefPtr<JSONValue> resultValue;
199 makeCall(function, &resultValue); 200 makeCall(function, &resultValue);
200 if (resultValue) { 201 if (resultValue) {
201 if (resultValue->type() == JSONValue::TypeString) { 202 if (resultValue->type() == JSONValue::TypeString) {
202 resultValue->asString(errorString); 203 resultValue->asString(errorString);
203 return; 204 return;
204 } 205 }
205 if (resultValue->type() == JSONValue::TypeArray) { 206 if (resultValue->type() == JSONValue::TypeArray) {
206 positions = Array<protocol::TypeBuilder::Debugger::Location>::runtim eCast(resultValue); 207 *positions = Array<protocol::Debugger::Location>::runtimeCast(result Value->asArray());
207 return; 208 return;
208 } 209 }
209 } 210 }
210 *errorString = "Internal error"; 211 *errorString = "Internal error";
211 } 212 }
212 213
213 void InjectedScript::setVariableValue(ErrorString* errorString, v8::Local<v8::Ob ject> callFrames, const String* callFrameIdOpt, const String* functionObjectIdOp t, int scopeNumber, const String& variableName, const String& newValueStr) 214 void InjectedScript::setVariableValue(ErrorString* errorString,
215 v8::Local<v8::Object> callFrames,
216 const protocol::OptionalValue<String>& callFrameIdOpt,
217 const protocol::OptionalValue<String>& functionObjectIdOpt,
218 int scopeNumber,
219 const String& variableName,
220 const String& newValueStr)
214 { 221 {
215 v8::HandleScope handles(m_isolate); 222 v8::HandleScope handles(m_isolate);
216 V8FunctionCall function(m_client, context(), v8Value(), "setVariableValue"); 223 V8FunctionCall function(m_client, context(), v8Value(), "setVariableValue");
217 if (callFrameIdOpt) { 224 if (callFrameIdOpt.hasValue()) {
218 function.appendArgument(callFrames); 225 function.appendArgument(callFrames);
219 function.appendArgument(*callFrameIdOpt); 226 function.appendArgument(callFrameIdOpt.get());
220 } else { 227 } else {
221 function.appendArgument(false); 228 function.appendArgument(false);
222 function.appendArgument(false); 229 function.appendArgument(false);
223 } 230 }
224 if (functionObjectIdOpt) 231 if (functionObjectIdOpt.hasValue())
225 function.appendArgument(*functionObjectIdOpt); 232 function.appendArgument(functionObjectIdOpt.get());
226 else 233 else
227 function.appendArgument(false); 234 function.appendArgument(false);
228 function.appendArgument(scopeNumber); 235 function.appendArgument(scopeNumber);
229 function.appendArgument(variableName); 236 function.appendArgument(variableName);
230 function.appendArgument(newValueStr); 237 function.appendArgument(newValueStr);
231 RefPtr<JSONValue> resultValue; 238 RefPtr<JSONValue> resultValue;
232 makeCall(function, &resultValue); 239 makeCall(function, &resultValue);
233 if (!resultValue) { 240 if (!resultValue) {
234 *errorString = "Internal error"; 241 *errorString = "Internal error";
235 return; 242 return;
236 } 243 }
237 if (resultValue->type() == JSONValue::TypeString) { 244 if (resultValue->type() == JSONValue::TypeString) {
238 resultValue->asString(errorString); 245 resultValue->asString(errorString);
239 return; 246 return;
240 } 247 }
241 // Normal return. 248 // Normal return.
242 } 249 }
243 250
244 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<FunctionDetails>* result) 251 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, OwnPtr<FunctionDetails>* result)
245 { 252 {
246 v8::HandleScope handles(m_isolate); 253 v8::HandleScope handles(m_isolate);
247 V8FunctionCall function(m_client, context(), v8Value(), "getFunctionDetails" ); 254 V8FunctionCall function(m_client, context(), v8Value(), "getFunctionDetails" );
248 function.appendArgument(functionId); 255 function.appendArgument(functionId);
249 RefPtr<JSONValue> resultValue; 256 RefPtr<JSONValue> resultValue;
250 makeCall(function, &resultValue); 257 makeCall(function, &resultValue);
251 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { 258 if (!resultValue || resultValue->type() != JSONValue::TypeObject) {
252 if (!resultValue->asString(errorString)) 259 if (!resultValue->asString(errorString))
253 *errorString = "Internal error"; 260 *errorString = "Internal error";
254 return; 261 return;
255 } 262 }
256 *result = FunctionDetails::runtimeCast(resultValue); 263 *result = FunctionDetails::runtimeCast(resultValue->asObject());
257 } 264 }
258 265
259 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S tring& objectId, RefPtr<GeneratorObjectDetails>* result) 266 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S tring& objectId, OwnPtr<GeneratorObjectDetails>* result)
260 { 267 {
261 v8::HandleScope handles(m_isolate); 268 v8::HandleScope handles(m_isolate);
262 V8FunctionCall function(m_client, context(), v8Value(), "getGeneratorObjectD etails"); 269 V8FunctionCall function(m_client, context(), v8Value(), "getGeneratorObjectD etails");
263 function.appendArgument(objectId); 270 function.appendArgument(objectId);
264 RefPtr<JSONValue> resultValue; 271 RefPtr<JSONValue> resultValue;
265 makeCall(function, &resultValue); 272 makeCall(function, &resultValue);
266 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { 273 if (!resultValue || resultValue->type() != JSONValue::TypeObject) {
267 if (!resultValue->asString(errorString)) 274 if (!resultValue->asString(errorString))
268 *errorString = "Internal error"; 275 *errorString = "Internal error";
269 return; 276 return;
270 } 277 }
271 *result = GeneratorObjectDetails::runtimeCast(resultValue); 278 *result = GeneratorObjectDetails::runtimeCast(resultValue->asObject());
272 } 279 }
273 280
274 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String & objectId, RefPtr<Array<CollectionEntry>>* result) 281 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String & objectId, OwnPtr<Array<CollectionEntry>>* result)
275 { 282 {
276 v8::HandleScope handles(m_isolate); 283 v8::HandleScope handles(m_isolate);
277 V8FunctionCall function(m_client, context(), v8Value(), "getCollectionEntrie s"); 284 V8FunctionCall function(m_client, context(), v8Value(), "getCollectionEntrie s");
278 function.appendArgument(objectId); 285 function.appendArgument(objectId);
279 RefPtr<JSONValue> resultValue; 286 RefPtr<JSONValue> resultValue;
280 makeCall(function, &resultValue); 287 makeCall(function, &resultValue);
281 if (!resultValue || resultValue->type() != JSONValue::TypeArray) { 288 if (!resultValue || resultValue->type() != JSONValue::TypeArray) {
282 if (!resultValue->asString(errorString)) 289 if (!resultValue->asString(errorString))
283 *errorString = "Internal error"; 290 *errorString = "Internal error";
284 return; 291 return;
285 } 292 }
286 *result = Array<CollectionEntry>::runtimeCast(resultValue); 293 *result = Array<CollectionEntry>::runtimeCast(resultValue->asArray());
287 } 294 }
288 295
289 void InjectedScript::getProperties(ErrorString* errorString, const String& objec tId, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, RefP tr<Array<PropertyDescriptor>>* properties, RefPtr<protocol::TypeBuilder::Runtime ::ExceptionDetails>* exceptionDetails) 296 void InjectedScript::getProperties(ErrorString* errorString, const String& objec tId, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, OwnP tr<Array<PropertyDescriptor>>* properties, OwnPtr<protocol::Runtime::ExceptionDe tails>* exceptionDetails)
290 { 297 {
291 v8::HandleScope handles(m_isolate); 298 v8::HandleScope handles(m_isolate);
292 V8FunctionCall function(m_client, context(), v8Value(), "getProperties"); 299 V8FunctionCall function(m_client, context(), v8Value(), "getProperties");
293 function.appendArgument(objectId); 300 function.appendArgument(objectId);
294 function.appendArgument(ownProperties); 301 function.appendArgument(ownProperties);
295 function.appendArgument(accessorPropertiesOnly); 302 function.appendArgument(accessorPropertiesOnly);
296 function.appendArgument(generatePreview); 303 function.appendArgument(generatePreview);
297 304
298 RefPtr<JSONValue> result; 305 RefPtr<JSONValue> result;
299 makeCallWithExceptionDetails(function, &result, exceptionDetails); 306 makeCallWithExceptionDetails(function, &result, exceptionDetails);
300 if (*exceptionDetails) { 307 if (*exceptionDetails) {
301 // FIXME: make properties optional 308 // FIXME: make properties optional
302 *properties = Array<PropertyDescriptor>::create(); 309 *properties = Array<PropertyDescriptor>::create();
303 return; 310 return;
304 } 311 }
305 if (!result || result->type() != JSONValue::TypeArray) { 312 if (!result || result->type() != JSONValue::TypeArray) {
306 *errorString = "Internal error"; 313 *errorString = "Internal error";
307 return; 314 return;
308 } 315 }
309 *properties = Array<PropertyDescriptor>::runtimeCast(result); 316 *properties = Array<PropertyDescriptor>::runtimeCast(result->asArray());
310 } 317 }
311 318
312 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin g& objectId, RefPtr<Array<InternalPropertyDescriptor>>* properties, RefPtr<proto col::TypeBuilder::Runtime::ExceptionDetails>* exceptionDetails) 319 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin g& objectId, OwnPtr<Array<InternalPropertyDescriptor>>* properties, OwnPtr<proto col::Runtime::ExceptionDetails>* exceptionDetails)
313 { 320 {
314 v8::HandleScope handles(m_isolate); 321 v8::HandleScope handles(m_isolate);
315 V8FunctionCall function(m_client, context(), v8Value(), "getInternalProperti es"); 322 V8FunctionCall function(m_client, context(), v8Value(), "getInternalProperti es");
316 function.appendArgument(objectId); 323 function.appendArgument(objectId);
317 324
318 RefPtr<JSONValue> result; 325 RefPtr<JSONValue> result;
319 makeCallWithExceptionDetails(function, &result, exceptionDetails); 326 makeCallWithExceptionDetails(function, &result, exceptionDetails);
320 if (*exceptionDetails) 327 if (*exceptionDetails)
321 return; 328 return;
322 if (!result || result->type() != JSONValue::TypeArray) { 329 if (!result || result->type() != JSONValue::TypeArray) {
323 *errorString = "Internal error"; 330 *errorString = "Internal error";
324 return; 331 return;
325 } 332 }
326 RefPtr<Array<InternalPropertyDescriptor>> array = Array<InternalPropertyDesc riptor>::runtimeCast(result); 333 OwnPtr<Array<InternalPropertyDescriptor>> array = Array<InternalPropertyDesc riptor>::runtimeCast(result->asArray());
327 if (array->length() > 0) 334 if (array->length() > 0)
328 *properties = array; 335 *properties = array.release();
329 } 336 }
330 337
331 void InjectedScript::releaseObject(const String& objectId) 338 void InjectedScript::releaseObject(const String& objectId)
332 { 339 {
333 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); 340 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId);
334 if (!parsedObjectId) 341 if (!parsedObjectId)
335 return; 342 return;
336 RefPtr<JSONObject> object; 343 RefPtr<JSONObject> object;
337 if (!parsedObjectId->asObject(&object)) 344 if (!parsedObjectId->asObject(&object))
338 return; 345 return;
(...skipping 15 matching lines...) Expand all
354 global->Set(commandLineAPISymbolValue, commandLineAPI); 361 global->Set(commandLineAPISymbolValue, commandLineAPI);
355 } 362 }
356 363
357 v8::MaybeLocal<v8::Value> maybeValue = m_client->runCompiledScript(context() , script); 364 v8::MaybeLocal<v8::Value> maybeValue = m_client->runCompiledScript(context() , script);
358 if (includeCommandLineAPI) 365 if (includeCommandLineAPI)
359 global->Delete(context(), commandLineAPISymbolValue); 366 global->Delete(context(), commandLineAPISymbolValue);
360 367
361 return maybeValue; 368 return maybeValue;
362 } 369 }
363 370
364 PassRefPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames, int asyncOrdinal) 371 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames, int asyncOrdinal)
365 { 372 {
366 v8::HandleScope handles(m_isolate); 373 v8::HandleScope handles(m_isolate);
367 V8FunctionCall function(m_client, context(), v8Value(), "wrapCallFrames"); 374 V8FunctionCall function(m_client, context(), v8Value(), "wrapCallFrames");
368 function.appendArgument(callFrames); 375 function.appendArgument(callFrames);
369 function.appendArgument(asyncOrdinal); 376 function.appendArgument(asyncOrdinal);
370 bool hadException = false; 377 bool hadException = false;
371 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException); 378 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException);
372 ASSERT(!hadException); 379 ASSERT(!hadException);
373 RefPtr<JSONValue> result = toJSONValue(context(), callFramesValue); 380 RefPtr<JSONValue> result = toJSONValue(context(), callFramesValue);
374 if (result && result->type() == JSONValue::TypeArray) 381 if (result && result->type() == JSONValue::TypeArray)
375 return Array<CallFrame>::runtimeCast(result); 382 return Array<CallFrame>::runtimeCast(result->asArray());
376 return Array<CallFrame>::create(); 383 return Array<CallFrame>::create();
377 } 384 }
378 385
379 PassRefPtr<protocol::TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObj ect(v8::Local<v8::Value> value, const String& groupName, bool generatePreview) c onst 386 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local <v8::Value> value, const String& groupName, bool generatePreview) const
380 { 387 {
381 v8::HandleScope handles(m_isolate); 388 v8::HandleScope handles(m_isolate);
382 V8FunctionCall function(m_client, context(), v8Value(), "wrapObject"); 389 V8FunctionCall function(m_client, context(), v8Value(), "wrapObject");
383 function.appendArgument(value); 390 function.appendArgument(value);
384 function.appendArgument(groupName); 391 function.appendArgument(groupName);
385 function.appendArgument(canAccessInspectedWindow()); 392 function.appendArgument(canAccessInspectedWindow());
386 function.appendArgument(generatePreview); 393 function.appendArgument(generatePreview);
387 bool hadException = false; 394 bool hadException = false;
388 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ; 395 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ;
389 if (hadException) 396 if (hadException)
390 return nullptr; 397 return nullptr;
391 RefPtr<JSONObject> rawResult = toJSONValue(context(), r)->asObject(); 398 RefPtr<JSONObject> rawResult = toJSONValue(context(), r)->asObject();
392 return protocol::TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); 399 return protocol::Runtime::RemoteObject::runtimeCast(rawResult);
393 } 400 }
394 401
395 PassRefPtr<protocol::TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapTab le(v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const 402 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Local< v8::Value> table, v8::Local<v8::Value> columns) const
396 { 403 {
397 v8::HandleScope handles(m_isolate); 404 v8::HandleScope handles(m_isolate);
398 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable"); 405 V8FunctionCall function(m_client, context(), v8Value(), "wrapTable");
399 function.appendArgument(canAccessInspectedWindow()); 406 function.appendArgument(canAccessInspectedWindow());
400 function.appendArgument(table); 407 function.appendArgument(table);
401 if (columns.IsEmpty()) 408 if (columns.IsEmpty())
402 function.appendArgument(false); 409 function.appendArgument(false);
403 else 410 else
404 function.appendArgument(columns); 411 function.appendArgument(columns);
405 bool hadException = false; 412 bool hadException = false;
406 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException ); 413 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException );
407 if (hadException) 414 if (hadException)
408 return nullptr; 415 return nullptr;
409 RefPtr<JSONObject> rawResult = toJSONValue(context(), r)->asObject(); 416 RefPtr<JSONObject> rawResult = toJSONValue(context(), r)->asObject();
410 return protocol::TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); 417 return protocol::Runtime::RemoteObject::runtimeCast(rawResult);
411 } 418 }
412 419
413 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const 420 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const
414 { 421 {
415 return m_native->objectForId(objectId.id()); 422 return m_native->objectForId(objectId.id());
416 } 423 }
417 424
418 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const 425 String InjectedScript::objectGroupName(const RemoteObjectId& objectId) const
419 { 426 {
420 return m_native->groupName(objectId.id()); 427 return m_native->groupName(objectId.id());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 ASSERT(!hadException); 493 ASSERT(!hadException);
487 if (!hadException) { 494 if (!hadException) {
488 *result = toJSONValue(function.context(), resultValue); 495 *result = toJSONValue(function.context(), resultValue);
489 if (!*result) 496 if (!*result)
490 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 497 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
491 } else { 498 } else {
492 *result = JSONString::create("Exception while making a call."); 499 *result = JSONString::create("Exception while making a call.");
493 } 500 }
494 } 501 }
495 502
496 void InjectedScript::makeEvalCall(ErrorString* errorString, V8FunctionCall& func tion, RefPtr<protocol::TypeBuilder::Runtime::RemoteObject>* objectResult, protoc ol::TypeBuilder::OptOutput<bool>* wasThrown, RefPtr<protocol::TypeBuilder::Runti me::ExceptionDetails>* exceptionDetails) 503 void InjectedScript::makeEvalCall(ErrorString* errorString, V8FunctionCall& func tion, OwnPtr<protocol::Runtime::RemoteObject>* objectResult, OptionalValue<bool> * wasThrown, OwnPtr<protocol::Runtime::ExceptionDetails>* exceptionDetails)
497 { 504 {
498 RefPtr<JSONValue> result; 505 RefPtr<JSONValue> result;
499 makeCall(function, &result); 506 makeCall(function, &result);
500 if (!result) { 507 if (!result) {
501 *errorString = "Internal error: result value is empty"; 508 *errorString = "Internal error: result value is empty";
502 return; 509 return;
503 } 510 }
504 if (result->type() == JSONValue::TypeString) { 511 if (result->type() == JSONValue::TypeString) {
505 result->asString(errorString); 512 result->asString(errorString);
506 ASSERT(errorString->length()); 513 ASSERT(errorString->length());
507 return; 514 return;
508 } 515 }
509 RefPtr<JSONObject> resultPair = result->asObject(); 516 RefPtr<JSONObject> resultPair = result->asObject();
510 if (!resultPair) { 517 if (!resultPair) {
511 *errorString = "Internal error: result is not an Object"; 518 *errorString = "Internal error: result is not an Object";
512 return; 519 return;
513 } 520 }
514 RefPtr<JSONObject> resultObj = resultPair->getObject("result"); 521 RefPtr<JSONObject> resultObj = resultPair->getObject("result");
515 bool wasThrownVal = false; 522 bool wasThrownVal = false;
516 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) { 523 if (!resultObj || !resultPair->getBoolean("wasThrown", &wasThrownVal)) {
517 *errorString = "Internal error: result is not a pair of value and wasThr own flag"; 524 *errorString = "Internal error: result is not a pair of value and wasThr own flag";
518 return; 525 return;
519 } 526 }
520 if (wasThrownVal) { 527 if (wasThrownVal) {
521 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep tionDetails"); 528 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep tionDetails");
522 if (objectExceptionDetails) 529 if (objectExceptionDetails)
523 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e()); 530 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e());
524 } 531 }
525 *objectResult = protocol::TypeBuilder::Runtime::RemoteObject::runtimeCast(re sultObj); 532 *objectResult = protocol::Runtime::RemoteObject::runtimeCast(resultObj);
526 *wasThrown = wasThrownVal; 533 *wasThrown = wasThrownVal;
527 } 534 }
528 535
529 void InjectedScript::makeCallWithExceptionDetails(V8FunctionCall& function, RefP tr<JSONValue>* result, RefPtr<protocol::TypeBuilder::Runtime::ExceptionDetails>* exceptionDetails) 536 void InjectedScript::makeCallWithExceptionDetails(V8FunctionCall& function, RefP tr<JSONValue>* result, OwnPtr<protocol::Runtime::ExceptionDetails>* exceptionDet ails)
530 { 537 {
531 v8::HandleScope handles(m_isolate); 538 v8::HandleScope handles(m_isolate);
532 v8::Context::Scope scope(context()); 539 v8::Context::Scope scope(context());
533 v8::TryCatch tryCatch(m_isolate); 540 v8::TryCatch tryCatch(m_isolate);
534 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); 541 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling();
535 if (tryCatch.HasCaught()) { 542 if (tryCatch.HasCaught()) {
536 v8::Local<v8::Message> message = tryCatch.Message(); 543 v8::Local<v8::Message> message = tryCatch.Message();
537 String text = !message.IsEmpty() ? toWTFStringWithTypeCheck(message->Get ()) : "Internal error"; 544 String text = !message.IsEmpty() ? toWTFStringWithTypeCheck(message->Get ()) : "Internal error";
538 *exceptionDetails = protocol::TypeBuilder::Runtime::ExceptionDetails::cr eate().setText(text); 545 *exceptionDetails = protocol::Runtime::ExceptionDetails::create().setTex t(text).build();
539 } else { 546 } else {
540 *result = toJSONValue(function.context(), resultValue); 547 *result = toJSONValue(function.context(), resultValue);
541 if (!*result) 548 if (!*result)
542 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 549 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
543 } 550 }
544 } 551 }
545 552
546 void InjectedScript::dispose() 553 void InjectedScript::dispose()
547 { 554 {
548 m_manager->discardInjectedScript(m_contextId); 555 m_manager->discardInjectedScript(m_contextId);
549 } 556 }
550 557
551 } // namespace blink 558 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698