| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 , m_inspector(session->inspector()) | 179 , m_inspector(session->inspector()) |
| 180 , m_enabled(false) | 180 , m_enabled(false) |
| 181 { | 181 { |
| 182 } | 182 } |
| 183 | 183 |
| 184 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() | 184 V8RuntimeAgentImpl::~V8RuntimeAgentImpl() |
| 185 { | 185 { |
| 186 } | 186 } |
| 187 | 187 |
| 188 void V8RuntimeAgentImpl::evaluate( | 188 void V8RuntimeAgentImpl::evaluate( |
| 189 ErrorString* errorString, | |
| 190 const String16& expression, | 189 const String16& expression, |
| 191 const Maybe<String16>& objectGroup, | 190 const Maybe<String16>& objectGroup, |
| 192 const Maybe<bool>& includeCommandLineAPI, | 191 const Maybe<bool>& includeCommandLineAPI, |
| 193 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, | 192 const Maybe<bool>& doNotPauseOnExceptionsAndMuteConsole, |
| 194 const Maybe<int>& executionContextId, | 193 const Maybe<int>& executionContextId, |
| 195 const Maybe<bool>& returnByValue, | 194 const Maybe<bool>& returnByValue, |
| 196 const Maybe<bool>& generatePreview, | 195 const Maybe<bool>& generatePreview, |
| 197 const Maybe<bool>& userGesture, | 196 const Maybe<bool>& userGesture, |
| 198 const Maybe<bool>& awaitPromise, | 197 const Maybe<bool>& awaitPromise, |
| 199 std::unique_ptr<EvaluateCallback> callback) | 198 std::unique_ptr<EvaluateCallback> callback) |
| 200 { | 199 { |
| 201 int contextId; | 200 int contextId; |
| 202 if (executionContextId.isJust()) { | 201 if (executionContextId.isJust()) { |
| 203 contextId = executionContextId.fromJust(); | 202 contextId = executionContextId.fromJust(); |
| 204 } else { | 203 } else { |
| 205 v8::HandleScope handles(m_inspector->isolate()); | 204 v8::HandleScope handles(m_inspector->isolate()); |
| 206 v8::Local<v8::Context> defaultContext = m_inspector->client()->ensureDef
aultContextInGroup(m_session->contextGroupId()); | 205 v8::Local<v8::Context> defaultContext = m_inspector->client()->ensureDef
aultContextInGroup(m_session->contextGroupId()); |
| 207 if (defaultContext.IsEmpty()) { | 206 if (defaultContext.IsEmpty()) { |
| 208 callback->sendFailure("Cannot find default execution context"); | 207 callback->sendFailure("Cannot find default execution context"); |
| 209 return; | 208 return; |
| 210 } | 209 } |
| 211 contextId = V8InspectorImpl::contextId(defaultContext); | 210 contextId = V8InspectorImpl::contextId(defaultContext); |
| 212 } | 211 } |
| 213 | 212 |
| 214 InjectedScript::ContextScope scope(errorString, m_inspector, m_session->cont
extGroupId(), contextId); | 213 ErrorString errorString; |
| 214 InjectedScript::ContextScope scope(&errorString, m_inspector, m_session->con
textGroupId(), contextId); |
| 215 if (!scope.initialize()) { | 215 if (!scope.initialize()) { |
| 216 callback->sendFailure(*errorString); | 216 callback->sendFailure(errorString); |
| 217 return; | 217 return; |
| 218 } | 218 } |
| 219 | 219 |
| 220 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) | 220 if (doNotPauseOnExceptionsAndMuteConsole.fromMaybe(false)) |
| 221 scope.ignoreExceptionsAndMuteConsole(); | 221 scope.ignoreExceptionsAndMuteConsole(); |
| 222 if (userGesture.fromMaybe(false)) | 222 if (userGesture.fromMaybe(false)) |
| 223 scope.pretendUserGesture(); | 223 scope.pretendUserGesture(); |
| 224 | 224 |
| 225 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) { | 225 if (includeCommandLineAPI.fromMaybe(false) && !scope.installCommandLineAPI()
) { |
| 226 callback->sendFailure(*errorString); | 226 callback->sendFailure(errorString); |
| 227 return; | 227 return; |
| 228 } | 228 } |
| 229 | 229 |
| 230 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed()
; | 230 bool evalIsDisabled = !scope.context()->IsCodeGenerationFromStringsAllowed()
; |
| 231 // Temporarily enable allow evals for inspector. | 231 // Temporarily enable allow evals for inspector. |
| 232 if (evalIsDisabled) | 232 if (evalIsDisabled) |
| 233 scope.context()->AllowCodeGenerationFromStrings(true); | 233 scope.context()->AllowCodeGenerationFromStrings(true); |
| 234 | 234 |
| 235 v8::MaybeLocal<v8::Value> maybeResultValue; | 235 v8::MaybeLocal<v8::Value> maybeResultValue; |
| 236 v8::Local<v8::Script> script = m_inspector->compileScript(scope.context(), t
oV8String(m_inspector->isolate(), expression), String16(), false); | 236 v8::Local<v8::Script> script = m_inspector->compileScript(scope.context(), t
oV8String(m_inspector->isolate(), expression), String16(), false); |
| 237 if (!script.IsEmpty()) | 237 if (!script.IsEmpty()) |
| 238 maybeResultValue = m_inspector->runCompiledScript(scope.context(), scrip
t); | 238 maybeResultValue = m_inspector->runCompiledScript(scope.context(), scrip
t); |
| 239 | 239 |
| 240 if (evalIsDisabled) | 240 if (evalIsDisabled) |
| 241 scope.context()->AllowCodeGenerationFromStrings(false); | 241 scope.context()->AllowCodeGenerationFromStrings(false); |
| 242 | 242 |
| 243 // Re-initialize after running client's code, as it could have destroyed con
text or session. | 243 // Re-initialize after running client's code, as it could have destroyed con
text or session. |
| 244 if (!scope.initialize()) { | 244 if (!scope.initialize()) { |
| 245 callback->sendFailure(*errorString); | 245 callback->sendFailure(errorString); |
| 246 return; | 246 return; |
| 247 } | 247 } |
| 248 | 248 |
| 249 std::unique_ptr<RemoteObject> result; | 249 std::unique_ptr<RemoteObject> result; |
| 250 Maybe<bool> wasThrown; | 250 Maybe<bool> wasThrown; |
| 251 Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails; | 251 Maybe<protocol::Runtime::ExceptionDetails> exceptionDetails; |
| 252 | 252 |
| 253 scope.injectedScript()->wrapEvaluateResult(errorString, | 253 scope.injectedScript()->wrapEvaluateResult(&errorString, |
| 254 maybeResultValue, | 254 maybeResultValue, |
| 255 scope.tryCatch(), | 255 scope.tryCatch(), |
| 256 objectGroup.fromMaybe(""), | 256 objectGroup.fromMaybe(""), |
| 257 returnByValue.fromMaybe(false) && !awaitPromise.fromMaybe(false), | 257 returnByValue.fromMaybe(false) && !awaitPromise.fromMaybe(false), |
| 258 generatePreview.fromMaybe(false) && !awaitPromise.fromMaybe(false), | 258 generatePreview.fromMaybe(false) && !awaitPromise.fromMaybe(false), |
| 259 &result, | 259 &result, |
| 260 &wasThrown, | 260 &wasThrown, |
| 261 &exceptionDetails); | 261 &exceptionDetails); |
| 262 if (!errorString->isEmpty()) { | 262 if (!errorString.isEmpty()) { |
| 263 callback->sendFailure(*errorString); | 263 callback->sendFailure(errorString); |
| 264 return; | 264 return; |
| 265 } | 265 } |
| 266 | 266 |
| 267 if (!awaitPromise.fromMaybe(false) || wasThrown.fromMaybe(false)) { | 267 if (!awaitPromise.fromMaybe(false) || wasThrown.fromMaybe(false)) { |
| 268 callback->sendSuccess(std::move(result), wasThrown, exceptionDetails); | 268 callback->sendSuccess(std::move(result), wasThrown, exceptionDetails); |
| 269 return; | 269 return; |
| 270 } | 270 } |
| 271 | 271 |
| 272 if (maybeResultValue.IsEmpty()) { | 272 if (maybeResultValue.IsEmpty()) { |
| 273 callback->sendFailure("Internal error"); | 273 callback->sendFailure("Internal error"); |
| 274 return; | 274 return; |
| 275 } | 275 } |
| 276 | 276 |
| 277 if (!maybeResultValue.ToLocalChecked()->IsPromise()) { | 277 if (!maybeResultValue.ToLocalChecked()->IsPromise()) { |
| 278 callback->sendFailure("Result of expression is not a promise."); | 278 callback->sendFailure("Result of expression is not a promise."); |
| 279 return; | 279 return; |
| 280 } | 280 } |
| 281 | 281 |
| 282 ProtocolPromiseHandler<EvaluateCallback>::add(m_inspector, m_session->contex
tGroupId(), result->getObjectId(String16()), std::move(callback), returnByValue.
fromMaybe(false), generatePreview.fromMaybe(false)); | 282 ProtocolPromiseHandler<EvaluateCallback>::add(m_inspector, m_session->contex
tGroupId(), result->getObjectId(String16()), std::move(callback), returnByValue.
fromMaybe(false), generatePreview.fromMaybe(false)); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void V8RuntimeAgentImpl::awaitPromise(ErrorString* errorString, | 285 void V8RuntimeAgentImpl::awaitPromise( |
| 286 const String16& promiseObjectId, | 286 const String16& promiseObjectId, |
| 287 const Maybe<bool>& returnByValue, | 287 const Maybe<bool>& returnByValue, |
| 288 const Maybe<bool>& generatePreview, | 288 const Maybe<bool>& generatePreview, |
| 289 std::unique_ptr<AwaitPromiseCallback> callback) | 289 std::unique_ptr<AwaitPromiseCallback> callback) |
| 290 { | 290 { |
| 291 ProtocolPromiseHandler<AwaitPromiseCallback>::add(m_inspector, m_session->co
ntextGroupId(), promiseObjectId, std::move(callback), returnByValue.fromMaybe(fa
lse), generatePreview.fromMaybe(false)); | 291 ProtocolPromiseHandler<AwaitPromiseCallback>::add(m_inspector, m_session->co
ntextGroupId(), promiseObjectId, std::move(callback), returnByValue.fromMaybe(fa
lse), generatePreview.fromMaybe(false)); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, | 294 void V8RuntimeAgentImpl::callFunctionOn(ErrorString* errorString, |
| 295 const String16& objectId, | 295 const String16& objectId, |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 reportMessage(message, true); | 592 reportMessage(message, true); |
| 593 } | 593 } |
| 594 | 594 |
| 595 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP
review) | 595 void V8RuntimeAgentImpl::reportMessage(V8ConsoleMessage* message, bool generateP
review) |
| 596 { | 596 { |
| 597 message->reportToFrontend(&m_frontend, m_session, generatePreview); | 597 message->reportToFrontend(&m_frontend, m_session, generatePreview); |
| 598 m_frontend.flush(); | 598 m_frontend.flush(); |
| 599 } | 599 } |
| 600 | 600 |
| 601 } // namespace blink | 601 } // namespace blink |
| OLD | NEW |