| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 { | 65 { |
| 66 } | 66 } |
| 67 | 67 |
| 68 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() | 68 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() |
| 69 { | 69 { |
| 70 } | 70 } |
| 71 | 71 |
| 72 void V8RuntimeAgentImpl::evaluate( | 72 void V8RuntimeAgentImpl::evaluate( |
| 73 ErrorString* errorString, | 73 ErrorString* errorString, |
| 74 const String& expression, | 74 const String& expression, |
| 75 const OptionalValue<String>& objectGroup, | 75 const Maybe<String>& objectGroup, |
| 76 const OptionalValue<bool>& includeCommandLineAPI, | 76 const Maybe<bool>& includeCommandLineAPI, |
| 77 const OptionalValue<bool>& doNotPauseOnExceptionsAndMuteConsole, | 77 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 78 const OptionalValue<int>& executionContextId, | 78 const Maybe<int>& executionContextId, |
| 79 const OptionalValue<bool>& returnByValue, | 79 const Maybe<bool>& returnByValue, |
| 80 const OptionalValue<bool>& generatePreview, | 80 const Maybe<bool>& generatePreview, |
| 81 OwnPtr<RemoteObject>* result, | 81 OwnPtr<RemoteObject>* result, |
| 82 OptionalValue<bool>* wasThrown, | 82 Maybe<bool>* wasThrown, |
| 83 OwnPtr<ExceptionDetails>* exceptionDetails) | 83 Maybe<ExceptionDetails>* exceptionDetails) |
| 84 { | 84 { |
| 85 if (!executionContextId.hasValue()) { | 85 if (!executionContextId.isJust()) { |
| 86 *errorString = "Cannot find default execution context"; | 86 *errorString = "Cannot find default execution context"; |
| 87 return; | 87 return; |
| 88 } | 88 } |
| 89 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(executionContextId.get()); | 89 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(executionContextId.fromJust()); |
| 90 if (!injectedScript) { | 90 if (!injectedScript) { |
| 91 *errorString = "Cannot find execution context with given id"; | 91 *errorString = "Cannot find execution context with given id"; |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 Optional<IgnoreExceptionsScope> ignoreExceptionsScope; | 94 Optional<IgnoreExceptionsScope> ignoreExceptionsScope; |
| 95 if (doNotPauseOnExceptionsAndMuteConsole.get(false)) | 95 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 96 ignoreExceptionsScope.emplace(m_debugger); | 96 ignoreExceptionsScope.emplace(m_debugger); |
| 97 injectedScript->evaluate(errorString, expression, objectGroup.get(""), inclu
deCommandLineAPI.get(false), returnByValue.get(false), generatePreview.get(false
), result, wasThrown, exceptionDetails); | 97 injectedScript->evaluate(errorString, expression, objectGroup.fromMaybe(""),
includeCommandLineAPI.fromMaybe(false), returnByValue.fromMaybe(false), generat
ePreview.fromMaybe(false), result, wasThrown, exceptionDetails); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, | 100 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, |
| 101 const String& objectId, | 101 const String& objectId, |
| 102 const String& expression, | 102 const String& expression, |
| 103 PassOwnPtr<protocol::Array<protocol::Runtime::CallArgument>> optionalArgumen
ts, | 103 const Maybe<protocol::Array<protocol::Runtime::CallArgument>>& optionalArgum
ents, |
| 104 const OptionalValue<bool>& doNotPauseOnExceptionsAndMuteConsole, | 104 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 105 const OptionalValue<bool>& returnByValue, | 105 const Maybe<bool>& returnByValue, |
| 106 const OptionalValue<bool>& generatePreview, | 106 const Maybe<bool>& generatePreview, |
| 107 OwnPtr<RemoteObject>* result, | 107 OwnPtr<RemoteObject>* result, |
| 108 OptionalValue<bool>* wasThrown) | 108 Maybe<bool>* wasThrown) |
| 109 { | 109 { |
| 110 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(objectId); | 110 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(objectId); |
| 111 if (!remoteId) { | 111 if (!remoteId) { |
| 112 *errorString = "Invalid object id"; | 112 *errorString = "Invalid object id"; |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(remoteId.get()); | 115 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(remoteId.get()); |
| 116 if (!injectedScript) { | 116 if (!injectedScript) { |
| 117 *errorString = "Inspected frame has gone"; | 117 *errorString = "Inspected frame has gone"; |
| 118 return; | 118 return; |
| 119 } | 119 } |
| 120 String arguments; | 120 String arguments; |
| 121 if (optionalArguments) | 121 if (optionalArguments.isJust()) |
| 122 arguments = protocol::toValue(optionalArguments)->toJSONString(); | 122 arguments = protocol::toValue(optionalArguments.fromJust())->toJSONStrin
g(); |
| 123 | 123 |
| 124 Optional<IgnoreExceptionsScope> ignoreExceptionsScope; | 124 Optional<IgnoreExceptionsScope> ignoreExceptionsScope; |
| 125 if (doNotPauseOnExceptionsAndMuteConsole.get(false)) | 125 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 126 ignoreExceptionsScope.emplace(m_debugger); | 126 ignoreExceptionsScope.emplace(m_debugger); |
| 127 injectedScript->callFunctionOn(errorString, objectId, expression, arguments,
returnByValue.get(false), generatePreview.get(false), result, wasThrown); | 127 injectedScript->callFunctionOn(errorString, objectId, expression, arguments,
returnByValue.fromMaybe(false), generatePreview.fromMaybe(false), result, wasTh
rown); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void V8RuntimeAgentImpl::getProperties( | 130 void V8RuntimeAgentImpl::getProperties( |
| 131 ErrorString* errorString, | 131 ErrorString* errorString, |
| 132 const String& objectId, | 132 const String& objectId, |
| 133 const OptionalValue<bool>& ownProperties, | 133 const Maybe<bool>& ownProperties, |
| 134 const OptionalValue<bool>& accessorPropertiesOnly, | 134 const Maybe<bool>& accessorPropertiesOnly, |
| 135 const OptionalValue<bool>& generatePreview, | 135 const Maybe<bool>& generatePreview, |
| 136 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, | 136 OwnPtr<protocol::Array<protocol::Runtime::PropertyDescriptor>>* result, |
| 137 OwnPtr<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inte
rnalProperties, | 137 Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>* inter
nalProperties, |
| 138 OwnPtr<ExceptionDetails>* exceptionDetails) | 138 Maybe<ExceptionDetails>* exceptionDetails) |
| 139 { | 139 { |
| 140 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(objectId); | 140 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(objectId); |
| 141 if (!remoteId) { | 141 if (!remoteId) { |
| 142 *errorString = "Invalid object id"; | 142 *errorString = "Invalid object id"; |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(remoteId.get()); | 145 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(remoteId.get()); |
| 146 if (!injectedScript) { | 146 if (!injectedScript) { |
| 147 *errorString = "Inspected frame has gone"; | 147 *errorString = "Inspected frame has gone"; |
| 148 return; | 148 return; |
| 149 } | 149 } |
| 150 | 150 |
| 151 IgnoreExceptionsScope ignoreExceptionsScope(m_debugger); | 151 IgnoreExceptionsScope ignoreExceptionsScope(m_debugger); |
| 152 | 152 |
| 153 injectedScript->getProperties(errorString, objectId, ownProperties.get(false
), accessorPropertiesOnly.get(false), generatePreview.get(false), result, except
ionDetails); | 153 injectedScript->getProperties(errorString, objectId, ownProperties.fromMaybe
(false), accessorPropertiesOnly.fromMaybe(false), generatePreview.fromMaybe(fals
e), result, exceptionDetails); |
| 154 | 154 |
| 155 if (!exceptionDetails->get() && !accessorPropertiesOnly.get(false)) | 155 if (!exceptionDetails->isJust() && !accessorPropertiesOnly.fromMaybe(false)) |
| 156 injectedScript->getInternalProperties(errorString, objectId, internalPro
perties, exceptionDetails); | 156 injectedScript->getInternalProperties(errorString, objectId, internalPro
perties, exceptionDetails); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void V8RuntimeAgentImpl::releaseObject(ErrorString* errorString, const String& o
bjectId) | 159 void V8RuntimeAgentImpl::releaseObject(ErrorString* errorString, const String& o
bjectId) |
| 160 { | 160 { |
| 161 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(objectId); | 161 OwnPtr<RemoteObjectId> remoteId = RemoteObjectId::parse(objectId); |
| 162 if (!remoteId) { | 162 if (!remoteId) { |
| 163 *errorString = "Invalid object id"; | 163 *errorString = "Invalid object id"; |
| 164 return; | 164 return; |
| 165 } | 165 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 { | 198 { |
| 199 m_state->setBoolean(V8RuntimeAgentImplState::customObjectFormatterEnabled, e
nabled); | 199 m_state->setBoolean(V8RuntimeAgentImplState::customObjectFormatterEnabled, e
nabled); |
| 200 m_injectedScriptManager->setCustomObjectFormatterEnabled(enabled); | 200 m_injectedScriptManager->setCustomObjectFormatterEnabled(enabled); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void V8RuntimeAgentImpl::compileScript(ErrorString* errorString, | 203 void V8RuntimeAgentImpl::compileScript(ErrorString* errorString, |
| 204 const String& expression, | 204 const String& expression, |
| 205 const String& sourceURL, | 205 const String& sourceURL, |
| 206 bool persistScript, | 206 bool persistScript, |
| 207 int executionContextId, | 207 int executionContextId, |
| 208 OptionalValue<protocol::Runtime::ScriptId>* scriptId, | 208 Maybe<protocol::Runtime::ScriptId>* scriptId, |
| 209 OwnPtr<ExceptionDetails>* exceptionDetails) | 209 Maybe<ExceptionDetails>* exceptionDetails) |
| 210 { | 210 { |
| 211 if (!m_enabled) { | 211 if (!m_enabled) { |
| 212 *errorString = "Runtime agent is not enabled"; | 212 *errorString = "Runtime agent is not enabled"; |
| 213 return; | 213 return; |
| 214 } | 214 } |
| 215 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(executionContextId); | 215 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(executionContextId); |
| 216 if (!injectedScript) { | 216 if (!injectedScript) { |
| 217 *errorString = "Inspected frame has gone"; | 217 *errorString = "Inspected frame has gone"; |
| 218 return; | 218 return; |
| 219 } | 219 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 237 | 237 |
| 238 String scriptValueId = String::number(script->GetUnboundScript()->GetId()); | 238 String scriptValueId = String::number(script->GetUnboundScript()->GetId()); |
| 239 OwnPtr<v8::Global<v8::Script>> global = adoptPtr(new v8::Global<v8::Script>(
isolate, script)); | 239 OwnPtr<v8::Global<v8::Script>> global = adoptPtr(new v8::Global<v8::Script>(
isolate, script)); |
| 240 m_compiledScripts.set(scriptValueId, global.release()); | 240 m_compiledScripts.set(scriptValueId, global.release()); |
| 241 *scriptId = scriptValueId; | 241 *scriptId = scriptValueId; |
| 242 } | 242 } |
| 243 | 243 |
| 244 void V8RuntimeAgentImpl::runScript(ErrorString* errorString, | 244 void V8RuntimeAgentImpl::runScript(ErrorString* errorString, |
| 245 const protocol::Runtime::ScriptId& scriptId, | 245 const protocol::Runtime::ScriptId& scriptId, |
| 246 int executionContextId, | 246 int executionContextId, |
| 247 const OptionalValue<String>& objectGroup, | 247 const Maybe<String>& objectGroup, |
| 248 const OptionalValue<bool>& doNotPauseOnExceptionsAndMuteConsole, | 248 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 249 const OptionalValue<bool>& includeCommandLineAPI, | 249 const Maybe<bool>& includeCommandLineAPI, |
| 250 OwnPtr<RemoteObject>* result, | 250 OwnPtr<RemoteObject>* result, |
| 251 OwnPtr<ExceptionDetails>* exceptionDetails) | 251 Maybe<ExceptionDetails>* exceptionDetails) |
| 252 { | 252 { |
| 253 if (!m_enabled) { | 253 if (!m_enabled) { |
| 254 *errorString = "Runtime agent is not enabled"; | 254 *errorString = "Runtime agent is not enabled"; |
| 255 return; | 255 return; |
| 256 } | 256 } |
| 257 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(executionContextId); | 257 InjectedScript* injectedScript = m_injectedScriptManager->findInjectedScript
(executionContextId); |
| 258 if (!injectedScript) { | 258 if (!injectedScript) { |
| 259 *errorString = "Inspected frame has gone"; | 259 *errorString = "Inspected frame has gone"; |
| 260 return; | 260 return; |
| 261 } | 261 } |
| 262 | 262 |
| 263 Optional<IgnoreExceptionsScope> ignoreExceptionsScope; | 263 Optional<IgnoreExceptionsScope> ignoreExceptionsScope; |
| 264 if (doNotPauseOnExceptionsAndMuteConsole.get(false)) | 264 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 265 ignoreExceptionsScope.emplace(m_debugger); | 265 ignoreExceptionsScope.emplace(m_debugger); |
| 266 | 266 |
| 267 if (!m_compiledScripts.contains(scriptId)) { | 267 if (!m_compiledScripts.contains(scriptId)) { |
| 268 *errorString = "Script execution failed"; | 268 *errorString = "Script execution failed"; |
| 269 return; | 269 return; |
| 270 } | 270 } |
| 271 | 271 |
| 272 v8::Isolate* isolate = injectedScript->isolate(); | 272 v8::Isolate* isolate = injectedScript->isolate(); |
| 273 v8::HandleScope handles(isolate); | 273 v8::HandleScope handles(isolate); |
| 274 v8::Local<v8::Context> context = injectedScript->context(); | 274 v8::Local<v8::Context> context = injectedScript->context(); |
| 275 v8::Context::Scope scope(context); | 275 v8::Context::Scope scope(context); |
| 276 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script
Id); | 276 OwnPtr<v8::Global<v8::Script>> scriptWrapper = m_compiledScripts.take(script
Id); |
| 277 v8::Local<v8::Script> script = scriptWrapper->Get(isolate); | 277 v8::Local<v8::Script> script = scriptWrapper->Get(isolate); |
| 278 | 278 |
| 279 if (script.IsEmpty()) { | 279 if (script.IsEmpty()) { |
| 280 *errorString = "Script execution failed"; | 280 *errorString = "Script execution failed"; |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 v8::TryCatch tryCatch(isolate); | 283 v8::TryCatch tryCatch(isolate); |
| 284 | 284 |
| 285 v8::Local<v8::Value> value; | 285 v8::Local<v8::Value> value; |
| 286 v8::MaybeLocal<v8::Value> maybeValue = injectedScript->runCompiledScript(scr
ipt, includeCommandLineAPI.get(false)); | 286 v8::MaybeLocal<v8::Value> maybeValue = injectedScript->runCompiledScript(scr
ipt, includeCommandLineAPI.fromMaybe(false)); |
| 287 if (maybeValue.IsEmpty()) { | 287 if (maybeValue.IsEmpty()) { |
| 288 value = tryCatch.Exception(); | 288 value = tryCatch.Exception(); |
| 289 v8::Local<v8::Message> message = tryCatch.Message(); | 289 v8::Local<v8::Message> message = tryCatch.Message(); |
| 290 if (!message.IsEmpty()) | 290 if (!message.IsEmpty()) |
| 291 *exceptionDetails = createExceptionDetails(isolate, message); | 291 *exceptionDetails = createExceptionDetails(isolate, message); |
| 292 } else { | 292 } else { |
| 293 value = maybeValue.ToLocalChecked(); | 293 value = maybeValue.ToLocalChecked(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 if (value.IsEmpty()) { | 296 if (value.IsEmpty()) { |
| 297 *errorString = "Script execution failed"; | 297 *errorString = "Script execution failed"; |
| 298 return; | 298 return; |
| 299 } | 299 } |
| 300 | 300 |
| 301 *result = injectedScript->wrapObject(value, objectGroup.get("")); | 301 *result = injectedScript->wrapObject(value, objectGroup.fromMaybe("")); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void V8RuntimeAgentImpl::setInspectorState(PassRefPtr<JSONObject> state) | 304 void V8RuntimeAgentImpl::setInspectorState(PassRefPtr<JSONObject> state) |
| 305 { | 305 { |
| 306 m_state = state; | 306 m_state = state; |
| 307 } | 307 } |
| 308 | 308 |
| 309 void V8RuntimeAgentImpl::setFrontend(protocol::Frontend::Runtime* frontend) | 309 void V8RuntimeAgentImpl::setFrontend(protocol::Frontend::Runtime* frontend) |
| 310 { | 310 { |
| 311 m_frontend = frontend; | 311 m_frontend = frontend; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 OwnPtr<ExceptionDetails> exceptionDetails = ExceptionDetails::create().setTe
xt(toWTFStringWithTypeCheck(message->Get())).build(); | 435 OwnPtr<ExceptionDetails> exceptionDetails = ExceptionDetails::create().setTe
xt(toWTFStringWithTypeCheck(message->Get())).build(); |
| 436 exceptionDetails->setLine(message->GetLineNumber()); | 436 exceptionDetails->setLine(message->GetLineNumber()); |
| 437 exceptionDetails->setColumn(message->GetStartColumn()); | 437 exceptionDetails->setColumn(message->GetStartColumn()); |
| 438 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace(); | 438 v8::Local<v8::StackTrace> messageStackTrace = message->GetStackTrace(); |
| 439 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount() > 0) | 439 if (!messageStackTrace.IsEmpty() && messageStackTrace->GetFrameCount() > 0) |
| 440 exceptionDetails->setStack(m_debugger->createStackTrace(messageStackTrac
e, messageStackTrace->GetFrameCount())->buildInspectorObject()); | 440 exceptionDetails->setStack(m_debugger->createStackTrace(messageStackTrac
e, messageStackTrace->GetFrameCount())->buildInspectorObject()); |
| 441 return exceptionDetails.release(); | 441 return exceptionDetails.release(); |
| 442 } | 442 } |
| 443 | 443 |
| 444 } // namespace blink | 444 } // namespace blink |
| OLD | NEW |