OLD | NEW |
---|---|
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 v8::HandleScope handles(m_isolate); | 148 v8::HandleScope handles(m_isolate); |
149 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "callFu nctionOn"); | 149 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "callFu nctionOn"); |
150 function.appendArgument(objectId); | 150 function.appendArgument(objectId); |
151 function.appendArgument(expression); | 151 function.appendArgument(expression); |
152 function.appendArgument(arguments); | 152 function.appendArgument(arguments); |
153 function.appendArgument(returnByValue); | 153 function.appendArgument(returnByValue); |
154 function.appendArgument(generatePreview); | 154 function.appendArgument(generatePreview); |
155 *result = makeEvalCall(errorString, function, wasThrown); | 155 *result = makeEvalCall(errorString, function, wasThrown); |
156 } | 156 } |
157 | 157 |
158 void InjectedScript::evaluateOnCallFrame(ErrorString* errorString, v8::Local<v8: :Object> callFrames, const String16& callFrameId, const String16& expression, co nst String16& objectGroup, bool includeCommandLineAPI, bool returnByValue, bool generatePreview, OwnPtr<RemoteObject>* result, Maybe<bool>* wasThrown, Maybe<pro tocol::Runtime::ExceptionDetails>* exceptionDetails) | |
159 { | |
160 v8::HandleScope handles(m_isolate); | |
161 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "evalua teOnCallFrame"); | |
162 function.appendArgument(callFrames); | |
163 function.appendArgument(callFrameId); | |
164 function.appendArgument(expression); | |
165 function.appendArgument(objectGroup); | |
166 function.appendArgument(includeCommandLineAPI); | |
167 function.appendArgument(returnByValue); | |
168 function.appendArgument(generatePreview); | |
169 *result = makeEvalCall(errorString, function, wasThrown, exceptionDetails); | |
170 } | |
171 | |
172 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String16 & functionId, OwnPtr<FunctionDetails>* result) | 158 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String16 & functionId, OwnPtr<FunctionDetails>* result) |
173 { | 159 { |
174 v8::HandleScope handles(m_isolate); | 160 v8::HandleScope handles(m_isolate); |
175 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "getFun ctionDetails"); | 161 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "getFun ctionDetails"); |
176 function.appendArgument(functionId); | 162 function.appendArgument(functionId); |
177 OwnPtr<protocol::Value> resultValue = makeCall(function); | 163 OwnPtr<protocol::Value> resultValue = makeCall(function); |
178 protocol::ErrorSupport errors(errorString); | 164 protocol::ErrorSupport errors(errorString); |
179 *result = FunctionDetails::parse(resultValue.get(), &errors); | 165 *result = FunctionDetails::parse(resultValue.get(), &errors); |
180 } | 166 } |
181 | 167 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 return; | 216 return; |
231 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb jectId.get()); | 217 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb jectId.get()); |
232 if (!object) | 218 if (!object) |
233 return; | 219 return; |
234 int boundId = 0; | 220 int boundId = 0; |
235 if (!object->getNumber("id", &boundId)) | 221 if (!object->getNumber("id", &boundId)) |
236 return; | 222 return; |
237 m_native->unbind(boundId); | 223 m_native->unbind(boundId); |
238 } | 224 } |
239 | 225 |
240 v8::MaybeLocal<v8::Value> InjectedScript::runCompiledScript(v8::Local<v8::Script > script, bool includeCommandLineAPI) | |
241 { | |
242 v8::Local<v8::Symbol> commandLineAPISymbolValue = V8Debugger::commandLineAPI Symbol(m_isolate); | |
243 v8::Local<v8::Object> global = context()->Global(); | |
244 if (includeCommandLineAPI) { | |
245 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "co mmandLineAPI"); | |
246 bool hadException = false; | |
247 v8::Local<v8::Value> commandLineAPI = function.call(hadException, false) ; | |
248 if (!hadException) | |
249 global->Set(commandLineAPISymbolValue, commandLineAPI); | |
250 } | |
251 | |
252 v8::MaybeLocal<v8::Value> maybeValue = m_manager->debugger()->runCompiledScr ipt(context(), script); | |
253 if (includeCommandLineAPI) | |
254 global->Delete(context(), commandLineAPISymbolValue); | |
255 | |
256 return maybeValue; | |
257 } | |
258 | |
259 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames) | 226 PassOwnPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames) |
260 { | 227 { |
261 v8::HandleScope handles(m_isolate); | 228 v8::HandleScope handles(m_isolate); |
262 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapCa llFrames"); | 229 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapCa llFrames"); |
263 function.appendArgument(callFrames); | 230 function.appendArgument(callFrames); |
264 bool hadException = false; | 231 bool hadException = false; |
265 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException); | 232 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException); |
266 ASSERT(!hadException); | 233 ASSERT(!hadException); |
267 OwnPtr<protocol::Value> result = toProtocolValue(context(), callFramesValue) ; | 234 OwnPtr<protocol::Value> result = toProtocolValue(context(), callFramesValue) ; |
268 protocol::ErrorSupport errors; | 235 protocol::ErrorSupport errors; |
269 if (result && result->type() == protocol::Value::TypeArray) | 236 if (result && result->type() == protocol::Value::TypeArray) |
270 return Array<CallFrame>::parse(result.get(), &errors); | 237 return Array<CallFrame>::parse(result.get(), &errors); |
271 return Array<CallFrame>::create(); | 238 return Array<CallFrame>::create(); |
272 } | 239 } |
273 | 240 |
274 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Local <v8::Value> value, const String16& groupName, bool generatePreview) const | 241 PassOwnPtr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(ErrorStri ng* errorString, v8::Local<v8::Value> value, const String16& groupName, bool for ceValueType, bool generatePreview) const |
275 { | 242 { |
276 v8::HandleScope handles(m_isolate); | 243 v8::HandleScope handles(m_isolate); |
277 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb ject"); | 244 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb ject"); |
278 v8::Local<v8::Value> wrappedObject; | 245 v8::Local<v8::Value> wrappedObject; |
279 ErrorString errorString; | 246 if (!wrapValue(errorString, value, groupName, forceValueType, generatePrevie w).ToLocal(&wrappedObject)) { |
280 if (!wrapValue(&errorString, value, groupName, generatePreview).ToLocal(&wra ppedObject)) | 247 *errorString = "Internal error"; |
dgozman
2016/03/17 19:16:11
wrapValue takes care of errorString.
kozy
2016/03/17 20:48:55
Done.
| |
281 return nullptr; | 248 return nullptr; |
249 } | |
282 protocol::ErrorSupport errors; | 250 protocol::ErrorSupport errors; |
283 return protocol::Runtime::RemoteObject::parse(toProtocolValue(context(), wra ppedObject).get(), &errors); | 251 OwnPtr<protocol::Runtime::RemoteObject> remoteObject = protocol::Runtime::Re moteObject::parse(toProtocolValue(context(), wrappedObject).get(), &errors); |
252 if (!remoteObject) | |
253 *errorString = "Object has too long reference chain"; | |
254 return remoteObject.release(); | |
284 } | 255 } |
285 | 256 |
286 bool InjectedScript::wrapObjectProperty(ErrorString* error, v8::Local<v8::Object > object, v8::Local<v8::Value> key, const String16& groupName, bool generatePrev iew) const | 257 bool InjectedScript::wrapObjectProperty(ErrorString* error, v8::Local<v8::Object > object, v8::Local<v8::Value> key, const String16& groupName, bool forceValueTy pe, bool generatePreview) const |
287 { | 258 { |
288 v8::Local<v8::Value> property; | 259 v8::Local<v8::Value> property; |
289 if (!object->Get(context(), key).ToLocal(&property)) { | 260 if (!object->Get(context(), key).ToLocal(&property)) { |
290 *error = "Internal error."; | 261 *error = "Internal error."; |
291 return false; | 262 return false; |
292 } | 263 } |
293 v8::Local<v8::Value> wrappedProperty; | 264 v8::Local<v8::Value> wrappedProperty; |
294 if (!wrapValue(error, property, groupName, generatePreview).ToLocal(&wrapped Property)) | 265 if (!wrapValue(error, property, groupName, forceValueType, generatePreview). ToLocal(&wrappedProperty)) |
295 return false; | 266 return false; |
296 v8::Maybe<bool> success = object->Set(context(), key, wrappedProperty); | 267 v8::Maybe<bool> success = object->Set(context(), key, wrappedProperty); |
297 if (success.IsNothing() || !success.FromJust()) { | 268 if (success.IsNothing() || !success.FromJust()) { |
298 *error = "Internal error."; | 269 *error = "Internal error."; |
299 return false; | 270 return false; |
300 } | 271 } |
301 return true; | 272 return true; |
302 } | 273 } |
303 | 274 |
304 v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(ErrorString* error, v8::Loca l<v8::Value> value, const String16& groupName, bool generatePreview) const | 275 v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(ErrorString* error, v8::Loca l<v8::Value> value, const String16& groupName, bool forceValueType, bool generat ePreview) const |
305 { | 276 { |
306 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb ject"); | 277 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "wrapOb ject"); |
307 function.appendArgument(value); | 278 function.appendArgument(value); |
308 function.appendArgument(groupName); | 279 function.appendArgument(groupName); |
309 function.appendArgument(canAccessInspectedWindow()); | 280 function.appendArgument(canAccessInspectedWindow()); |
281 function.appendArgument(forceValueType); | |
310 function.appendArgument(generatePreview); | 282 function.appendArgument(generatePreview); |
311 bool hadException = false; | 283 bool hadException = false; |
312 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ; | 284 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ; |
313 if (hadException) { | 285 if (hadException) { |
314 *error = "Internal error."; | 286 *error = "Internal error."; |
315 return v8::MaybeLocal<v8::Value>(); | 287 return v8::MaybeLocal<v8::Value>(); |
316 } | 288 } |
317 return r; | 289 return r; |
318 } | 290 } |
319 | 291 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 result = protocol::StringValue::create("Object has too long referenc e chain"); | 441 result = protocol::StringValue::create("Object has too long referenc e chain"); |
470 } | 442 } |
471 return result.release(); | 443 return result.release(); |
472 } | 444 } |
473 | 445 |
474 void InjectedScript::dispose() | 446 void InjectedScript::dispose() |
475 { | 447 { |
476 m_manager->discardInjectedScript(m_contextId); | 448 m_manager->discardInjectedScript(m_contextId); |
477 } | 449 } |
478 | 450 |
451 bool InjectedScript::setLastEvaluationResult(ErrorString* errorString, v8::Local <v8::Value> value) | |
452 { | |
453 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), "setLas tEvaluationResult"); | |
454 function.appendArgument(value); | |
455 bool hadException = false; | |
456 function.call(hadException, false); | |
457 if (hadException) | |
458 *errorString = "Internal error"; | |
459 return !hadException; | |
460 } | |
461 | |
479 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error String, protocol::Runtime::CallArgument* callArgument) | 462 v8::MaybeLocal<v8::Value> InjectedScript::resolveCallArgument(ErrorString* error String, protocol::Runtime::CallArgument* callArgument) |
480 { | 463 { |
481 if (callArgument->hasObjectId()) { | 464 if (callArgument->hasObjectId()) { |
482 OwnPtr<RemoteObjectId> remoteObjectId = RemoteObjectId::parse(errorStrin g, callArgument->getObjectId("")); | 465 OwnPtr<RemoteObjectId> remoteObjectId = RemoteObjectId::parse(errorStrin g, callArgument->getObjectId("")); |
483 if (!remoteObjectId) | 466 if (!remoteObjectId) |
484 return v8::MaybeLocal<v8::Value>(); | 467 return v8::MaybeLocal<v8::Value>(); |
485 if (remoteObjectId->contextId() != m_contextId) { | 468 if (remoteObjectId->contextId() != m_contextId) { |
486 *errorString = "Argument should belong to the same JavaScript world as target object"; | 469 *errorString = "Argument should belong to the same JavaScript world as target object"; |
487 return v8::MaybeLocal<v8::Value>(); | 470 return v8::MaybeLocal<v8::Value>(); |
488 } | 471 } |
(...skipping 11 matching lines...) Expand all Loading... | |
500 v8::Local<v8::Value> object; | 483 v8::Local<v8::Value> object; |
501 if (!m_manager->debugger()->compileAndRunInternalScript(context(), toV8S tring(m_isolate, value)).ToLocal(&object)) { | 484 if (!m_manager->debugger()->compileAndRunInternalScript(context(), toV8S tring(m_isolate, value)).ToLocal(&object)) { |
502 *errorString = "Couldn't parse value object in call argument"; | 485 *errorString = "Couldn't parse value object in call argument"; |
503 return v8::MaybeLocal<v8::Value>(); | 486 return v8::MaybeLocal<v8::Value>(); |
504 } | 487 } |
505 return object; | 488 return object; |
506 } | 489 } |
507 return v8::Undefined(m_isolate); | 490 return v8::Undefined(m_isolate); |
508 } | 491 } |
509 | 492 |
493 v8::MaybeLocal<v8::Object> InjectedScript::scopeExtensionByName(ErrorString* err orString, const String16& name) | |
494 { | |
495 V8FunctionCall function(m_manager->debugger(), context(), v8Value(), name); | |
496 bool hadException = false; | |
497 v8::Local<v8::Value> scopeExtensionValue = function.call(hadException, false ); | |
498 v8::Local<v8::Object> scopeExtensionObject; | |
499 if (hadException || scopeExtensionValue.IsEmpty() || !scopeExtensionValue->T oObject(context()).ToLocal(&scopeExtensionObject)) { | |
500 *errorString = "Internal error"; | |
501 return v8::MaybeLocal<v8::Object>(); | |
502 } | |
503 return scopeExtensionObject; | |
504 } | |
505 | |
510 } // namespace blink | 506 } // namespace blink |
OLD | NEW |