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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 #include "platform/inspector_protocol/Parser.h" | 33 #include "platform/inspector_protocol/Parser.h" |
34 #include "platform/inspector_protocol/String16.h" | 34 #include "platform/inspector_protocol/String16.h" |
35 #include "platform/inspector_protocol/Values.h" | 35 #include "platform/inspector_protocol/Values.h" |
36 #include "platform/v8_inspector/InjectedScriptNative.h" | 36 #include "platform/v8_inspector/InjectedScriptNative.h" |
37 #include "platform/v8_inspector/InjectedScriptSource.h" | 37 #include "platform/v8_inspector/InjectedScriptSource.h" |
38 #include "platform/v8_inspector/InspectedContext.h" | 38 #include "platform/v8_inspector/InspectedContext.h" |
39 #include "platform/v8_inspector/RemoteObjectId.h" | 39 #include "platform/v8_inspector/RemoteObjectId.h" |
40 #include "platform/v8_inspector/V8Compat.h" | 40 #include "platform/v8_inspector/V8Compat.h" |
41 #include "platform/v8_inspector/V8Console.h" | 41 #include "platform/v8_inspector/V8Console.h" |
42 #include "platform/v8_inspector/V8DebuggerImpl.h" | |
43 #include "platform/v8_inspector/V8FunctionCall.h" | 42 #include "platform/v8_inspector/V8FunctionCall.h" |
44 #include "platform/v8_inspector/V8InjectedScriptHost.h" | 43 #include "platform/v8_inspector/V8InjectedScriptHost.h" |
| 44 #include "platform/v8_inspector/V8InspectorImpl.h" |
45 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 45 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
46 #include "platform/v8_inspector/V8StackTraceImpl.h" | 46 #include "platform/v8_inspector/V8StackTraceImpl.h" |
47 #include "platform/v8_inspector/V8StringUtil.h" | 47 #include "platform/v8_inspector/V8StringUtil.h" |
48 #include "platform/v8_inspector/public/V8Debugger.h" | 48 #include "platform/v8_inspector/public/V8InspectorClient.h" |
49 #include "platform/v8_inspector/public/V8DebuggerClient.h" | |
50 | 49 |
51 using blink::protocol::Array; | 50 using blink::protocol::Array; |
52 using blink::protocol::Debugger::CallFrame; | 51 using blink::protocol::Debugger::CallFrame; |
53 using blink::protocol::Runtime::PropertyDescriptor; | 52 using blink::protocol::Runtime::PropertyDescriptor; |
54 using blink::protocol::Runtime::InternalPropertyDescriptor; | 53 using blink::protocol::Runtime::InternalPropertyDescriptor; |
55 using blink::protocol::Runtime::RemoteObject; | 54 using blink::protocol::Runtime::RemoteObject; |
56 using blink::protocol::Maybe; | 55 using blink::protocol::Maybe; |
57 | 56 |
58 namespace blink { | 57 namespace blink { |
59 | 58 |
60 static bool hasInternalError(ErrorString* errorString, bool hasError) | 59 static bool hasInternalError(ErrorString* errorString, bool hasError) |
61 { | 60 { |
62 if (hasError) | 61 if (hasError) |
63 *errorString = "Internal error"; | 62 *errorString = "Internal error"; |
64 return hasError; | 63 return hasError; |
65 } | 64 } |
66 | 65 |
67 std::unique_ptr<InjectedScript> InjectedScript::create(InspectedContext* inspect
edContext) | 66 std::unique_ptr<InjectedScript> InjectedScript::create(InspectedContext* inspect
edContext) |
68 { | 67 { |
69 v8::Isolate* isolate = inspectedContext->isolate(); | 68 v8::Isolate* isolate = inspectedContext->isolate(); |
70 v8::HandleScope handles(isolate); | 69 v8::HandleScope handles(isolate); |
71 v8::Local<v8::Context> context = inspectedContext->context(); | 70 v8::Local<v8::Context> context = inspectedContext->context(); |
72 v8::Context::Scope scope(context); | 71 v8::Context::Scope scope(context); |
73 | 72 |
74 std::unique_ptr<InjectedScriptNative> injectedScriptNative(new InjectedScrip
tNative(isolate)); | 73 std::unique_ptr<InjectedScriptNative> injectedScriptNative(new InjectedScrip
tNative(isolate)); |
75 v8::Local<v8::Object> scriptHostWrapper = V8InjectedScriptHost::create(conte
xt, inspectedContext->debugger()); | 74 v8::Local<v8::Object> scriptHostWrapper = V8InjectedScriptHost::create(conte
xt, inspectedContext->inspector()); |
76 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); | 75 injectedScriptNative->setOnInjectedScriptHost(scriptHostWrapper); |
77 | 76 |
78 // Inject javascript into the context. The compiled script is supposed to ev
aluate into | 77 // Inject javascript into the context. The compiled script is supposed to ev
aluate into |
79 // a single anonymous function(it's anonymous to avoid cluttering the global
object with | 78 // a single anonymous function(it's anonymous to avoid cluttering the global
object with |
80 // inspector's stuff) the function is called a few lines below with Injected
ScriptHost wrapper, | 79 // inspector's stuff) the function is called a few lines below with Injected
ScriptHost wrapper, |
81 // injected script id and explicit reference to the inspected global object.
The function is expected | 80 // injected script id and explicit reference to the inspected global object.
The function is expected |
82 // to create and configure InjectedScript instance that is going to be used
by the inspector. | 81 // to create and configure InjectedScript instance that is going to be used
by the inspector. |
83 String16 injectedScriptSource(reinterpret_cast<const char*>(InjectedScriptSo
urce_js), sizeof(InjectedScriptSource_js)); | 82 String16 injectedScriptSource(reinterpret_cast<const char*>(InjectedScriptSo
urce_js), sizeof(InjectedScriptSource_js)); |
84 v8::Local<v8::Value> value; | 83 v8::Local<v8::Value> value; |
85 if (!inspectedContext->debugger()->compileAndRunInternalScript(context, toV8
String(isolate, injectedScriptSource)).ToLocal(&value)) | 84 if (!inspectedContext->inspector()->compileAndRunInternalScript(context, toV
8String(isolate, injectedScriptSource)).ToLocal(&value)) |
86 return nullptr; | 85 return nullptr; |
87 DCHECK(value->IsFunction()); | 86 DCHECK(value->IsFunction()); |
88 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | 87 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); |
89 v8::Local<v8::Object> windowGlobal = context->Global(); | 88 v8::Local<v8::Object> windowGlobal = context->Global(); |
90 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number:
:New(isolate, inspectedContext->contextId()) }; | 89 v8::Local<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number:
:New(isolate, inspectedContext->contextId()) }; |
91 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM
icrotasks); | 90 v8::MicrotasksScope microtasksScope(isolate, v8::MicrotasksScope::kDoNotRunM
icrotasks); |
92 v8::Local<v8::Value> injectedScriptValue; | 91 v8::Local<v8::Value> injectedScriptValue; |
93 if (!function->Call(context, windowGlobal, PROTOCOL_ARRAY_LENGTH(info), info
).ToLocal(&injectedScriptValue)) | 92 if (!function->Call(context, windowGlobal, PROTOCOL_ARRAY_LENGTH(info), info
).ToLocal(&injectedScriptValue)) |
94 return nullptr; | 93 return nullptr; |
95 if (!injectedScriptValue->IsObject()) | 94 if (!injectedScriptValue->IsObject()) |
96 return nullptr; | 95 return nullptr; |
97 return wrapUnique(new InjectedScript(inspectedContext, injectedScriptValue.A
s<v8::Object>(), std::move(injectedScriptNative))); | 96 return wrapUnique(new InjectedScript(inspectedContext, injectedScriptValue.A
s<v8::Object>(), std::move(injectedScriptNative))); |
98 } | 97 } |
99 | 98 |
100 InjectedScript::InjectedScript(InspectedContext* context, v8::Local<v8::Object>
object, std::unique_ptr<InjectedScriptNative> injectedScriptNative) | 99 InjectedScript::InjectedScript(InspectedContext* context, v8::Local<v8::Object>
object, std::unique_ptr<InjectedScriptNative> injectedScriptNative) |
101 : m_context(context) | 100 : m_context(context) |
102 , m_value(context->isolate(), object) | 101 , m_value(context->isolate(), object) |
103 , m_native(std::move(injectedScriptNative)) | 102 , m_native(std::move(injectedScriptNative)) |
104 { | 103 { |
105 } | 104 } |
106 | 105 |
107 InjectedScript::~InjectedScript() | 106 InjectedScript::~InjectedScript() |
108 { | 107 { |
109 } | 108 } |
110 | 109 |
111 void InjectedScript::getProperties(ErrorString* errorString, v8::Local<v8::Objec
t> object, const String16& groupName, bool ownProperties, bool accessorPropertie
sOnly, bool generatePreview, std::unique_ptr<Array<PropertyDescriptor>>* propert
ies, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) | 110 void InjectedScript::getProperties(ErrorString* errorString, v8::Local<v8::Objec
t> object, const String16& groupName, bool ownProperties, bool accessorPropertie
sOnly, bool generatePreview, std::unique_ptr<Array<PropertyDescriptor>>* propert
ies, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) |
112 { | 111 { |
113 v8::HandleScope handles(m_context->isolate()); | 112 v8::HandleScope handles(m_context->isolate()); |
114 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value
(), "getProperties"); | 113 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "getProperties"); |
115 function.appendArgument(object); | 114 function.appendArgument(object); |
116 function.appendArgument(groupName); | 115 function.appendArgument(groupName); |
117 function.appendArgument(ownProperties); | 116 function.appendArgument(ownProperties); |
118 function.appendArgument(accessorPropertiesOnly); | 117 function.appendArgument(accessorPropertiesOnly); |
119 function.appendArgument(generatePreview); | 118 function.appendArgument(generatePreview); |
120 | 119 |
121 v8::TryCatch tryCatch(m_context->isolate()); | 120 v8::TryCatch tryCatch(m_context->isolate()); |
122 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); | 121 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); |
123 if (tryCatch.HasCaught()) { | 122 if (tryCatch.HasCaught()) { |
124 *exceptionDetails = createExceptionDetails(tryCatch.Message()); | 123 *exceptionDetails = createExceptionDetails(tryCatch.Message()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 if (!wrapValue(errorString, property, groupName, forceValueType, generatePre
view).ToLocal(&wrappedProperty)) | 171 if (!wrapValue(errorString, property, groupName, forceValueType, generatePre
view).ToLocal(&wrappedProperty)) |
173 return false; | 172 return false; |
174 v8::Maybe<bool> success = object->Set(m_context->context(), key, wrappedProp
erty); | 173 v8::Maybe<bool> success = object->Set(m_context->context(), key, wrappedProp
erty); |
175 if (hasInternalError(errorString, success.IsNothing() || !success.FromJust()
)) | 174 if (hasInternalError(errorString, success.IsNothing() || !success.FromJust()
)) |
176 return false; | 175 return false; |
177 return true; | 176 return true; |
178 } | 177 } |
179 | 178 |
180 bool InjectedScript::wrapPropertyInArray(ErrorString* errorString, v8::Local<v8:
:Array> array, v8::Local<v8::String> property, const String16& groupName, bool f
orceValueType, bool generatePreview) const | 179 bool InjectedScript::wrapPropertyInArray(ErrorString* errorString, v8::Local<v8:
:Array> array, v8::Local<v8::String> property, const String16& groupName, bool f
orceValueType, bool generatePreview) const |
181 { | 180 { |
182 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value
(), "wrapPropertyInArray"); | 181 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "wrapPropertyInArray"); |
183 function.appendArgument(array); | 182 function.appendArgument(array); |
184 function.appendArgument(property); | 183 function.appendArgument(property); |
185 function.appendArgument(groupName); | 184 function.appendArgument(groupName); |
186 function.appendArgument(forceValueType); | 185 function.appendArgument(forceValueType); |
187 function.appendArgument(generatePreview); | 186 function.appendArgument(generatePreview); |
188 bool hadException = false; | 187 bool hadException = false; |
189 function.call(hadException); | 188 function.call(hadException); |
190 return !hasInternalError(errorString, hadException); | 189 return !hasInternalError(errorString, hadException); |
191 } | 190 } |
192 | 191 |
193 bool InjectedScript::wrapObjectsInArray(ErrorString* errorString, v8::Local<v8::
Array> array, const String16& groupName, bool forceValueType, bool generatePrevi
ew) const | 192 bool InjectedScript::wrapObjectsInArray(ErrorString* errorString, v8::Local<v8::
Array> array, const String16& groupName, bool forceValueType, bool generatePrevi
ew) const |
194 { | 193 { |
195 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value
(), "wrapObjectsInArray"); | 194 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "wrapObjectsInArray"); |
196 function.appendArgument(array); | 195 function.appendArgument(array); |
197 function.appendArgument(groupName); | 196 function.appendArgument(groupName); |
198 function.appendArgument(forceValueType); | 197 function.appendArgument(forceValueType); |
199 function.appendArgument(generatePreview); | 198 function.appendArgument(generatePreview); |
200 bool hadException = false; | 199 bool hadException = false; |
201 function.call(hadException); | 200 function.call(hadException); |
202 return !hasInternalError(errorString, hadException); | 201 return !hasInternalError(errorString, hadException); |
203 } | 202 } |
204 | 203 |
205 v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(ErrorString* errorString, v8
::Local<v8::Value> value, const String16& groupName, bool forceValueType, bool g
eneratePreview) const | 204 v8::MaybeLocal<v8::Value> InjectedScript::wrapValue(ErrorString* errorString, v8
::Local<v8::Value> value, const String16& groupName, bool forceValueType, bool g
eneratePreview) const |
206 { | 205 { |
207 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value
(), "wrapObject"); | 206 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "wrapObject"); |
208 function.appendArgument(value); | 207 function.appendArgument(value); |
209 function.appendArgument(groupName); | 208 function.appendArgument(groupName); |
210 function.appendArgument(forceValueType); | 209 function.appendArgument(forceValueType); |
211 function.appendArgument(generatePreview); | 210 function.appendArgument(generatePreview); |
212 bool hadException = false; | 211 bool hadException = false; |
213 v8::Local<v8::Value> r = function.call(hadException); | 212 v8::Local<v8::Value> r = function.call(hadException); |
214 if (hasInternalError(errorString, hadException || r.IsEmpty())) | 213 if (hasInternalError(errorString, hadException || r.IsEmpty())) |
215 return v8::MaybeLocal<v8::Value>(); | 214 return v8::MaybeLocal<v8::Value>(); |
216 return r; | 215 return r; |
217 } | 216 } |
218 | 217 |
219 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::L
ocal<v8::Value> table, v8::Local<v8::Value> columns) const | 218 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::L
ocal<v8::Value> table, v8::Local<v8::Value> columns) const |
220 { | 219 { |
221 v8::HandleScope handles(m_context->isolate()); | 220 v8::HandleScope handles(m_context->isolate()); |
222 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value
(), "wrapTable"); | 221 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "wrapTable"); |
223 function.appendArgument(table); | 222 function.appendArgument(table); |
224 if (columns.IsEmpty()) | 223 if (columns.IsEmpty()) |
225 function.appendArgument(false); | 224 function.appendArgument(false); |
226 else | 225 else |
227 function.appendArgument(columns); | 226 function.appendArgument(columns); |
228 bool hadException = false; | 227 bool hadException = false; |
229 v8::Local<v8::Value> r = function.call(hadException); | 228 v8::Local<v8::Value> r = function.call(hadException); |
230 if (hadException) | 229 if (hadException) |
231 return nullptr; | 230 return nullptr; |
232 protocol::ErrorSupport errors; | 231 protocol::ErrorSupport errors; |
(...skipping 16 matching lines...) Expand all Loading... |
249 void InjectedScript::releaseObjectGroup(const String16& objectGroup) | 248 void InjectedScript::releaseObjectGroup(const String16& objectGroup) |
250 { | 249 { |
251 m_native->releaseObjectGroup(objectGroup); | 250 m_native->releaseObjectGroup(objectGroup); |
252 if (objectGroup == "console") | 251 if (objectGroup == "console") |
253 m_lastEvaluationResult.Reset(); | 252 m_lastEvaluationResult.Reset(); |
254 } | 253 } |
255 | 254 |
256 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) | 255 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) |
257 { | 256 { |
258 v8::HandleScope handles(m_context->isolate()); | 257 v8::HandleScope handles(m_context->isolate()); |
259 V8FunctionCall function(m_context->debugger(), m_context->context(), v8Value
(), "setCustomObjectFormatterEnabled"); | 258 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "setCustomObjectFormatterEnabled"); |
260 function.appendArgument(enabled); | 259 function.appendArgument(enabled); |
261 bool hadException = false; | 260 bool hadException = false; |
262 function.call(hadException); | 261 function.call(hadException); |
263 DCHECK(!hadException); | 262 DCHECK(!hadException); |
264 } | 263 } |
265 | 264 |
266 v8::Local<v8::Value> InjectedScript::v8Value() const | 265 v8::Local<v8::Value> InjectedScript::v8Value() const |
267 { | 266 { |
268 return m_value.Get(m_context->isolate()); | 267 return m_value.Get(m_context->isolate()); |
269 } | 268 } |
(...skipping 18 matching lines...) Expand all Loading... |
288 v8::Local<v8::Value> object; | 287 v8::Local<v8::Value> object; |
289 if (!findObject(errorString, *remoteObjectId, &object)) | 288 if (!findObject(errorString, *remoteObjectId, &object)) |
290 return v8::MaybeLocal<v8::Value>(); | 289 return v8::MaybeLocal<v8::Value>(); |
291 return object; | 290 return object; |
292 } | 291 } |
293 if (callArgument->hasValue()) { | 292 if (callArgument->hasValue()) { |
294 String16 value = callArgument->getValue(nullptr)->toJSONString(); | 293 String16 value = callArgument->getValue(nullptr)->toJSONString(); |
295 if (callArgument->getType(String16()) == "number") | 294 if (callArgument->getType(String16()) == "number") |
296 value = "Number(" + value + ")"; | 295 value = "Number(" + value + ")"; |
297 v8::Local<v8::Value> object; | 296 v8::Local<v8::Value> object; |
298 if (!m_context->debugger()->compileAndRunInternalScript(m_context->conte
xt(), toV8String(m_context->isolate(), value)).ToLocal(&object)) { | 297 if (!m_context->inspector()->compileAndRunInternalScript(m_context->cont
ext(), toV8String(m_context->isolate(), value)).ToLocal(&object)) { |
299 *errorString = "Couldn't parse value object in call argument"; | 298 *errorString = "Couldn't parse value object in call argument"; |
300 return v8::MaybeLocal<v8::Value>(); | 299 return v8::MaybeLocal<v8::Value>(); |
301 } | 300 } |
302 return object; | 301 return object; |
303 } | 302 } |
304 return v8::Undefined(m_context->isolate()); | 303 return v8::Undefined(m_context->isolate()); |
305 } | 304 } |
306 | 305 |
307 std::unique_ptr<protocol::Runtime::ExceptionDetails> InjectedScript::createExcep
tionDetails(v8::Local<v8::Message> message) | 306 std::unique_ptr<protocol::Runtime::ExceptionDetails> InjectedScript::createExcep
tionDetails(v8::Local<v8::Message> message) |
308 { | 307 { |
309 std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetailsObject
= protocol::Runtime::ExceptionDetails::create() | 308 std::unique_ptr<protocol::Runtime::ExceptionDetails> exceptionDetailsObject
= protocol::Runtime::ExceptionDetails::create() |
310 .setText(toProtocolString(message->Get())) | 309 .setText(toProtocolString(message->Get())) |
311 .setScriptId(String16::fromInteger(message->GetScriptOrigin().ScriptID()
->Value())) | 310 .setScriptId(String16::fromInteger(message->GetScriptOrigin().ScriptID()
->Value())) |
312 .setLineNumber(message->GetLineNumber(m_context->context()).FromMaybe(1)
- 1) | 311 .setLineNumber(message->GetLineNumber(m_context->context()).FromMaybe(1)
- 1) |
313 .setColumnNumber(message->GetStartColumn(m_context->context()).FromMaybe
(0)) | 312 .setColumnNumber(message->GetStartColumn(m_context->context()).FromMaybe
(0)) |
314 .build(); | 313 .build(); |
315 | 314 |
316 v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace(); | 315 v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace(); |
317 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) | 316 if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) |
318 exceptionDetailsObject->setStackTrace(m_context->debugger()->createStack
TraceImpl(stackTrace)->buildInspectorObjectImpl()); | 317 exceptionDetailsObject->setStackTrace(m_context->inspector()->createStac
kTraceImpl(stackTrace)->buildInspectorObjectImpl()); |
319 return exceptionDetailsObject; | 318 return exceptionDetailsObject; |
320 } | 319 } |
321 | 320 |
322 void InjectedScript::wrapEvaluateResult(ErrorString* errorString, v8::MaybeLocal
<v8::Value> maybeResultValue, const v8::TryCatch& tryCatch, const String16& obje
ctGroup, bool returnByValue, bool generatePreview, std::unique_ptr<protocol::Run
time::RemoteObject>* result, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::Ex
ceptionDetails>* exceptionDetails) | 321 void InjectedScript::wrapEvaluateResult(ErrorString* errorString, v8::MaybeLocal
<v8::Value> maybeResultValue, const v8::TryCatch& tryCatch, const String16& obje
ctGroup, bool returnByValue, bool generatePreview, std::unique_ptr<protocol::Run
time::RemoteObject>* result, Maybe<bool>* wasThrown, Maybe<protocol::Runtime::Ex
ceptionDetails>* exceptionDetails) |
323 { | 322 { |
324 v8::Local<v8::Value> resultValue; | 323 v8::Local<v8::Value> resultValue; |
325 if (!tryCatch.HasCaught()) { | 324 if (!tryCatch.HasCaught()) { |
326 if (hasInternalError(errorString, !maybeResultValue.ToLocal(&resultValue
))) | 325 if (hasInternalError(errorString, !maybeResultValue.ToLocal(&resultValue
))) |
327 return; | 326 return; |
328 std::unique_ptr<RemoteObject> remoteObject = wrapObject(errorString, res
ultValue, objectGroup, returnByValue, generatePreview); | 327 std::unique_ptr<RemoteObject> remoteObject = wrapObject(errorString, res
ultValue, objectGroup, returnByValue, generatePreview); |
(...skipping 17 matching lines...) Expand all Loading... |
346 } | 345 } |
347 } | 346 } |
348 | 347 |
349 v8::Local<v8::Object> InjectedScript::commandLineAPI() | 348 v8::Local<v8::Object> InjectedScript::commandLineAPI() |
350 { | 349 { |
351 if (m_commandLineAPI.IsEmpty()) | 350 if (m_commandLineAPI.IsEmpty()) |
352 m_commandLineAPI.Reset(m_context->isolate(), V8Console::createCommandLin
eAPI(m_context)); | 351 m_commandLineAPI.Reset(m_context->isolate(), V8Console::createCommandLin
eAPI(m_context)); |
353 return m_commandLineAPI.Get(m_context->isolate()); | 352 return m_commandLineAPI.Get(m_context->isolate()); |
354 } | 353 } |
355 | 354 |
356 InjectedScript::Scope::Scope(ErrorString* errorString, V8DebuggerImpl* debugger,
int contextGroupId) | 355 InjectedScript::Scope::Scope(ErrorString* errorString, V8InspectorImpl* inspecto
r, int contextGroupId) |
357 : m_errorString(errorString) | 356 : m_errorString(errorString) |
358 , m_debugger(debugger) | 357 , m_inspector(inspector) |
359 , m_contextGroupId(contextGroupId) | 358 , m_contextGroupId(contextGroupId) |
360 , m_injectedScript(nullptr) | 359 , m_injectedScript(nullptr) |
361 , m_handleScope(debugger->isolate()) | 360 , m_handleScope(inspector->isolate()) |
362 , m_tryCatch(debugger->isolate()) | 361 , m_tryCatch(inspector->isolate()) |
363 , m_ignoreExceptionsAndMuteConsole(false) | 362 , m_ignoreExceptionsAndMuteConsole(false) |
364 , m_previousPauseOnExceptionsState(V8DebuggerImpl::DontPauseOnExceptions) | 363 , m_previousPauseOnExceptionsState(V8InspectorImpl::DontPauseOnExceptions) |
365 , m_userGesture(false) | 364 , m_userGesture(false) |
366 { | 365 { |
367 } | 366 } |
368 | 367 |
369 bool InjectedScript::Scope::initialize() | 368 bool InjectedScript::Scope::initialize() |
370 { | 369 { |
371 cleanup(); | 370 cleanup(); |
372 // TODO(dgozman): what if we reattach to the same context group during evalu
ate? Introduce a session id? | 371 // TODO(dgozman): what if we reattach to the same context group during evalu
ate? Introduce a session id? |
373 V8InspectorSessionImpl* session = m_debugger->sessionForContextGroup(m_conte
xtGroupId); | 372 V8InspectorSessionImpl* session = m_inspector->sessionForContextGroup(m_cont
extGroupId); |
374 if (!session) { | 373 if (!session) { |
375 *m_errorString = "Internal error"; | 374 *m_errorString = "Internal error"; |
376 return false; | 375 return false; |
377 } | 376 } |
378 findInjectedScript(session); | 377 findInjectedScript(session); |
379 if (!m_injectedScript) | 378 if (!m_injectedScript) |
380 return false; | 379 return false; |
381 m_context = m_injectedScript->context()->context(); | 380 m_context = m_injectedScript->context()->context(); |
382 m_context->Enter(); | 381 m_context->Enter(); |
383 return true; | 382 return true; |
384 } | 383 } |
385 | 384 |
386 bool InjectedScript::Scope::installCommandLineAPI() | 385 bool InjectedScript::Scope::installCommandLineAPI() |
387 { | 386 { |
388 DCHECK(m_injectedScript && !m_context.IsEmpty() && !m_commandLineAPIScope.ge
t()); | 387 DCHECK(m_injectedScript && !m_context.IsEmpty() && !m_commandLineAPIScope.ge
t()); |
389 m_commandLineAPIScope.reset(new V8Console::CommandLineAPIScope(m_context, m_
injectedScript->commandLineAPI(), m_context->Global())); | 388 m_commandLineAPIScope.reset(new V8Console::CommandLineAPIScope(m_context, m_
injectedScript->commandLineAPI(), m_context->Global())); |
390 return true; | 389 return true; |
391 } | 390 } |
392 | 391 |
393 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() | 392 void InjectedScript::Scope::ignoreExceptionsAndMuteConsole() |
394 { | 393 { |
395 DCHECK(!m_ignoreExceptionsAndMuteConsole); | 394 DCHECK(!m_ignoreExceptionsAndMuteConsole); |
396 m_ignoreExceptionsAndMuteConsole = true; | 395 m_ignoreExceptionsAndMuteConsole = true; |
397 m_debugger->client()->muteWarningsAndDeprecations(m_contextGroupId); | 396 m_inspector->client()->muteWarningsAndDeprecations(m_contextGroupId); |
398 m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8DebuggerImpl:
:DontPauseOnExceptions); | 397 m_previousPauseOnExceptionsState = setPauseOnExceptionsState(V8InspectorImpl
::DontPauseOnExceptions); |
399 } | 398 } |
400 | 399 |
401 V8DebuggerImpl::PauseOnExceptionsState InjectedScript::Scope::setPauseOnExceptio
nsState(V8DebuggerImpl::PauseOnExceptionsState newState) | 400 V8InspectorImpl::PauseOnExceptionsState InjectedScript::Scope::setPauseOnExcepti
onsState(V8InspectorImpl::PauseOnExceptionsState newState) |
402 { | 401 { |
403 if (!m_debugger->enabled()) | 402 if (!m_inspector->enabled()) |
404 return newState; | 403 return newState; |
405 V8DebuggerImpl::PauseOnExceptionsState presentState = m_debugger->getPauseOn
ExceptionsState(); | 404 V8InspectorImpl::PauseOnExceptionsState presentState = m_inspector->getPause
OnExceptionsState(); |
406 if (presentState != newState) | 405 if (presentState != newState) |
407 m_debugger->setPauseOnExceptionsState(newState); | 406 m_inspector->setPauseOnExceptionsState(newState); |
408 return presentState; | 407 return presentState; |
409 } | 408 } |
410 | 409 |
411 void InjectedScript::Scope::pretendUserGesture() | 410 void InjectedScript::Scope::pretendUserGesture() |
412 { | 411 { |
413 DCHECK(!m_userGesture); | 412 DCHECK(!m_userGesture); |
414 m_userGesture = true; | 413 m_userGesture = true; |
415 m_debugger->client()->beginUserGesture(); | 414 m_inspector->client()->beginUserGesture(); |
416 } | 415 } |
417 | 416 |
418 void InjectedScript::Scope::cleanup() | 417 void InjectedScript::Scope::cleanup() |
419 { | 418 { |
420 m_commandLineAPIScope.reset(); | 419 m_commandLineAPIScope.reset(); |
421 if (!m_context.IsEmpty()) { | 420 if (!m_context.IsEmpty()) { |
422 m_context->Exit(); | 421 m_context->Exit(); |
423 m_context.Clear(); | 422 m_context.Clear(); |
424 } | 423 } |
425 } | 424 } |
426 | 425 |
427 InjectedScript::Scope::~Scope() | 426 InjectedScript::Scope::~Scope() |
428 { | 427 { |
429 if (m_ignoreExceptionsAndMuteConsole) { | 428 if (m_ignoreExceptionsAndMuteConsole) { |
430 setPauseOnExceptionsState(m_previousPauseOnExceptionsState); | 429 setPauseOnExceptionsState(m_previousPauseOnExceptionsState); |
431 m_debugger->client()->unmuteWarningsAndDeprecations(m_contextGroupId); | 430 m_inspector->client()->unmuteWarningsAndDeprecations(m_contextGroupId); |
432 } | 431 } |
433 if (m_userGesture) | 432 if (m_userGesture) |
434 m_debugger->client()->endUserGesture(); | 433 m_inspector->client()->endUserGesture(); |
435 cleanup(); | 434 cleanup(); |
436 } | 435 } |
437 | 436 |
438 InjectedScript::ContextScope::ContextScope(ErrorString* errorString, V8DebuggerI
mpl* debugger, int contextGroupId, int executionContextId) | 437 InjectedScript::ContextScope::ContextScope(ErrorString* errorString, V8Inspector
Impl* inspector, int contextGroupId, int executionContextId) |
439 : InjectedScript::Scope(errorString, debugger, contextGroupId) | 438 : InjectedScript::Scope(errorString, inspector, contextGroupId) |
440 , m_executionContextId(executionContextId) | 439 , m_executionContextId(executionContextId) |
441 { | 440 { |
442 } | 441 } |
443 | 442 |
444 InjectedScript::ContextScope::~ContextScope() | 443 InjectedScript::ContextScope::~ContextScope() |
445 { | 444 { |
446 } | 445 } |
447 | 446 |
448 void InjectedScript::ContextScope::findInjectedScript(V8InspectorSessionImpl* se
ssion) | 447 void InjectedScript::ContextScope::findInjectedScript(V8InspectorSessionImpl* se
ssion) |
449 { | 448 { |
450 m_injectedScript = session->findInjectedScript(m_errorString, m_executionCon
textId); | 449 m_injectedScript = session->findInjectedScript(m_errorString, m_executionCon
textId); |
451 } | 450 } |
452 | 451 |
453 InjectedScript::ObjectScope::ObjectScope(ErrorString* errorString, V8DebuggerImp
l* debugger, int contextGroupId, const String16& remoteObjectId) | 452 InjectedScript::ObjectScope::ObjectScope(ErrorString* errorString, V8InspectorIm
pl* inspector, int contextGroupId, const String16& remoteObjectId) |
454 : InjectedScript::Scope(errorString, debugger, contextGroupId) | 453 : InjectedScript::Scope(errorString, inspector, contextGroupId) |
455 , m_remoteObjectId(remoteObjectId) | 454 , m_remoteObjectId(remoteObjectId) |
456 { | 455 { |
457 } | 456 } |
458 | 457 |
459 InjectedScript::ObjectScope::~ObjectScope() | 458 InjectedScript::ObjectScope::~ObjectScope() |
460 { | 459 { |
461 } | 460 } |
462 | 461 |
463 void InjectedScript::ObjectScope::findInjectedScript(V8InspectorSessionImpl* ses
sion) | 462 void InjectedScript::ObjectScope::findInjectedScript(V8InspectorSessionImpl* ses
sion) |
464 { | 463 { |
465 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(m_errorStri
ng, m_remoteObjectId); | 464 std::unique_ptr<RemoteObjectId> remoteId = RemoteObjectId::parse(m_errorStri
ng, m_remoteObjectId); |
466 if (!remoteId) | 465 if (!remoteId) |
467 return; | 466 return; |
468 InjectedScript* injectedScript = session->findInjectedScript(m_errorString,
remoteId.get()); | 467 InjectedScript* injectedScript = session->findInjectedScript(m_errorString,
remoteId.get()); |
469 if (!injectedScript) | 468 if (!injectedScript) |
470 return; | 469 return; |
471 m_objectGroupName = injectedScript->objectGroupName(*remoteId); | 470 m_objectGroupName = injectedScript->objectGroupName(*remoteId); |
472 if (!injectedScript->findObject(m_errorString, *remoteId, &m_object)) | 471 if (!injectedScript->findObject(m_errorString, *remoteId, &m_object)) |
473 return; | 472 return; |
474 m_injectedScript = injectedScript; | 473 m_injectedScript = injectedScript; |
475 } | 474 } |
476 | 475 |
477 InjectedScript::CallFrameScope::CallFrameScope(ErrorString* errorString, V8Debug
gerImpl* debugger, int contextGroupId, const String16& remoteObjectId) | 476 InjectedScript::CallFrameScope::CallFrameScope(ErrorString* errorString, V8Inspe
ctorImpl* inspector, int contextGroupId, const String16& remoteObjectId) |
478 : InjectedScript::Scope(errorString, debugger, contextGroupId) | 477 : InjectedScript::Scope(errorString, inspector, contextGroupId) |
479 , m_remoteCallFrameId(remoteObjectId) | 478 , m_remoteCallFrameId(remoteObjectId) |
480 { | 479 { |
481 } | 480 } |
482 | 481 |
483 InjectedScript::CallFrameScope::~CallFrameScope() | 482 InjectedScript::CallFrameScope::~CallFrameScope() |
484 { | 483 { |
485 } | 484 } |
486 | 485 |
487 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl*
session) | 486 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl*
session) |
488 { | 487 { |
489 std::unique_ptr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_err
orString, m_remoteCallFrameId); | 488 std::unique_ptr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_err
orString, m_remoteCallFrameId); |
490 if (!remoteId) | 489 if (!remoteId) |
491 return; | 490 return; |
492 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); | 491 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); |
493 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()
); | 492 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()
); |
494 } | 493 } |
495 | 494 |
496 } // namespace blink | 495 } // namespace blink |
OLD | NEW |