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

Side by Side Diff: third_party/WebKit/Source/core/inspector/InjectedScript.cpp

Issue 1638563002: DevTools: migrate ScriptFunctionCall off ScriptValue (to be inlined into the InjectedScript.cpp). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ready for review Created 4 years, 11 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 using blink::TypeBuilder::Debugger::CallFrame; 44 using blink::TypeBuilder::Debugger::CallFrame;
45 using blink::TypeBuilder::Debugger::CollectionEntry; 45 using blink::TypeBuilder::Debugger::CollectionEntry;
46 using blink::TypeBuilder::Debugger::FunctionDetails; 46 using blink::TypeBuilder::Debugger::FunctionDetails;
47 using blink::TypeBuilder::Debugger::GeneratorObjectDetails; 47 using blink::TypeBuilder::Debugger::GeneratorObjectDetails;
48 using blink::TypeBuilder::Runtime::PropertyDescriptor; 48 using blink::TypeBuilder::Runtime::PropertyDescriptor;
49 using blink::TypeBuilder::Runtime::InternalPropertyDescriptor; 49 using blink::TypeBuilder::Runtime::InternalPropertyDescriptor;
50 using blink::TypeBuilder::Runtime::RemoteObject; 50 using blink::TypeBuilder::Runtime::RemoteObject;
51 51
52 namespace blink { 52 namespace blink {
53 53
54 PassRefPtr<JSONValue> toJSONValue(const ScriptValue& value)
55 {
56 ScriptState* scriptState = value.scriptState();
57 ASSERT(scriptState->contextIsValid());
58 ScriptState::Scope scope(scriptState);
59 return toJSONValue(scriptState->isolate(), value.v8Value());
60 }
61
62 static PassRefPtr<TypeBuilder::Debugger::ExceptionDetails> toExceptionDetails(Pa ssRefPtr<JSONObject> object) 54 static PassRefPtr<TypeBuilder::Debugger::ExceptionDetails> toExceptionDetails(Pa ssRefPtr<JSONObject> object)
63 { 55 {
64 String text; 56 String text;
65 if (!object->getString("text", &text)) 57 if (!object->getString("text", &text))
66 return nullptr; 58 return nullptr;
67 59
68 RefPtr<TypeBuilder::Debugger::ExceptionDetails> exceptionDetails = TypeBuild er::Debugger::ExceptionDetails::create().setText(text); 60 RefPtr<TypeBuilder::Debugger::ExceptionDetails> exceptionDetails = TypeBuild er::Debugger::ExceptionDetails::create().setText(text);
69 String url; 61 String url;
70 if (object->getString("url", &url)) 62 if (object->getString("url", &url))
71 exceptionDetails->setUrl(url); 63 exceptionDetails->setUrl(url);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 98
107 frames->addItem(callFrame.release()); 99 frames->addItem(callFrame.release());
108 } 100 }
109 exceptionDetails->setStackTrace(frames.release()); 101 exceptionDetails->setStackTrace(frames.release());
110 } 102 }
111 if (originScriptId) 103 if (originScriptId)
112 exceptionDetails->setScriptId(String::number(originScriptId)); 104 exceptionDetails->setScriptId(String::number(originScriptId));
113 return exceptionDetails.release(); 105 return exceptionDetails.release();
114 } 106 }
115 107
116 InjectedScript::InjectedScript()
117 : m_inspectedStateAccessCheck(nullptr)
118 , m_contextId(0)
119 {
120 }
121
122 InjectedScript::InjectedScript(ScriptValue injectedScriptObject, InspectedStateA ccessCheck accessCheck, PassRefPtr<InjectedScriptNative> injectedScriptNative, i nt contextId) 108 InjectedScript::InjectedScript(ScriptValue injectedScriptObject, InspectedStateA ccessCheck accessCheck, PassRefPtr<InjectedScriptNative> injectedScriptNative, i nt contextId)
123 : m_injectedScriptObject(injectedScriptObject) 109 : m_isolate(injectedScriptObject.isolate())
110 , m_injectedScriptObject(injectedScriptObject)
124 , m_inspectedStateAccessCheck(accessCheck) 111 , m_inspectedStateAccessCheck(accessCheck)
125 , m_native(injectedScriptNative) 112 , m_native(injectedScriptNative)
126 , m_contextId(contextId) 113 , m_contextId(contextId)
127 { 114 {
128 } 115 }
129 116
130 InjectedScript::~InjectedScript() 117 InjectedScript::~InjectedScript()
131 { 118 {
132 } 119 }
133 120
134 void InjectedScript::evaluate(ErrorString* errorString, const String& expression , const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, boo l generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuild er::OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* exceptionDetails) 121 void InjectedScript::evaluate(ErrorString* errorString, const String& expression , const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, boo l generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuild er::OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* exceptionDetails)
135 { 122 {
136 ScriptFunctionCall function(injectedScriptObject(), "evaluate"); 123 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
dgozman 2016/01/26 02:45:14 Why do you need ScriptState::Scope at all?
pfeldman 2016/01/27 01:24:09 I need a handle scope and entered context.
124 ScriptFunctionCall function(v8Context(), v8Value(), "evaluate");
137 function.appendArgument(expression); 125 function.appendArgument(expression);
138 function.appendArgument(objectGroup); 126 function.appendArgument(objectGroup);
139 function.appendArgument(includeCommandLineAPI); 127 function.appendArgument(includeCommandLineAPI);
140 function.appendArgument(returnByValue); 128 function.appendArgument(returnByValue);
141 function.appendArgument(generatePreview); 129 function.appendArgument(generatePreview);
142 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); 130 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails);
143 } 131 }
144 132
145 void InjectedScript::callFunctionOn(ErrorString* errorString, const String& obje ctId, const String& expression, const String& arguments, bool returnByValue, boo l generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuild er::OptOutput<bool>* wasThrown) 133 void InjectedScript::callFunctionOn(ErrorString* errorString, const String& obje ctId, const String& expression, const String& arguments, bool returnByValue, boo l generatePreview, RefPtr<TypeBuilder::Runtime::RemoteObject>* result, TypeBuild er::OptOutput<bool>* wasThrown)
146 { 134 {
147 ScriptFunctionCall function(injectedScriptObject(), "callFunctionOn"); 135 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
136 ScriptFunctionCall function(v8Context(), v8Value(), "callFunctionOn");
148 function.appendArgument(objectId); 137 function.appendArgument(objectId);
149 function.appendArgument(expression); 138 function.appendArgument(expression);
150 function.appendArgument(arguments); 139 function.appendArgument(arguments);
151 function.appendArgument(returnByValue); 140 function.appendArgument(returnByValue);
152 function.appendArgument(generatePreview); 141 function.appendArgument(generatePreview);
153 makeEvalCall(errorString, function, result, wasThrown); 142 makeEvalCall(errorString, function, result, wasThrown);
154 } 143 }
155 144
156 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, TypeBuilder::Opt Output<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* except ionDetails) 145 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, TypeBuilder::Opt Output<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* except ionDetails)
157 { 146 {
158 ScriptFunctionCall function(injectedScriptObject(), "evaluateOnCallFrame"); 147 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
148 ScriptFunctionCall function(v8Context(), v8Value(), "evaluateOnCallFrame");
159 function.appendArgument(callFrames); 149 function.appendArgument(callFrames);
160 function.appendArgument(isAsyncCallStack); 150 function.appendArgument(isAsyncCallStack);
161 function.appendArgument(callFrameId); 151 function.appendArgument(callFrameId);
162 function.appendArgument(expression); 152 function.appendArgument(expression);
163 function.appendArgument(objectGroup); 153 function.appendArgument(objectGroup);
164 function.appendArgument(includeCommandLineAPI); 154 function.appendArgument(includeCommandLineAPI);
165 function.appendArgument(returnByValue); 155 function.appendArgument(returnByValue);
166 function.appendArgument(generatePreview); 156 function.appendArgument(generatePreview);
167 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); 157 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails);
168 } 158 }
169 159
170 void InjectedScript::restartFrame(ErrorString* errorString, v8::Local<v8::Object > callFrames, const String& callFrameId) 160 void InjectedScript::restartFrame(ErrorString* errorString, v8::Local<v8::Object > callFrames, const String& callFrameId)
171 { 161 {
172 ScriptFunctionCall function(injectedScriptObject(), "restartFrame"); 162 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
163 ScriptFunctionCall function(v8Context(), v8Value(), "restartFrame");
173 function.appendArgument(callFrames); 164 function.appendArgument(callFrames);
174 function.appendArgument(callFrameId); 165 function.appendArgument(callFrameId);
175 RefPtr<JSONValue> resultValue; 166 RefPtr<JSONValue> resultValue;
176 makeCall(function, &resultValue); 167 makeCall(function, &resultValue);
177 if (resultValue) { 168 if (resultValue) {
178 if (resultValue->type() == JSONValue::TypeString) { 169 if (resultValue->type() == JSONValue::TypeString) {
179 resultValue->asString(errorString); 170 resultValue->asString(errorString);
180 } else { 171 } else {
181 bool value; 172 bool value;
182 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value); 173 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value);
183 } 174 }
184 return; 175 return;
185 } 176 }
186 *errorString = "Internal error"; 177 *errorString = "Internal error";
187 } 178 }
188 179
189 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8:: Object> callFrames, const String& callFrameId, RefPtr<Array<TypeBuilder::Debugge r::Location>>& positions) 180 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8:: Object> callFrames, const String& callFrameId, RefPtr<Array<TypeBuilder::Debugge r::Location>>& positions)
190 { 181 {
191 ScriptFunctionCall function(injectedScriptObject(), "getStepInPositions"); 182 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
183 ScriptFunctionCall function(v8Context(), v8Value(), "getStepInPositions");
192 function.appendArgument(callFrames); 184 function.appendArgument(callFrames);
193 function.appendArgument(callFrameId); 185 function.appendArgument(callFrameId);
194 RefPtr<JSONValue> resultValue; 186 RefPtr<JSONValue> resultValue;
195 makeCall(function, &resultValue); 187 makeCall(function, &resultValue);
196 if (resultValue) { 188 if (resultValue) {
197 if (resultValue->type() == JSONValue::TypeString) { 189 if (resultValue->type() == JSONValue::TypeString) {
198 resultValue->asString(errorString); 190 resultValue->asString(errorString);
199 return; 191 return;
200 } 192 }
201 if (resultValue->type() == JSONValue::TypeArray) { 193 if (resultValue->type() == JSONValue::TypeArray) {
202 positions = Array<TypeBuilder::Debugger::Location>::runtimeCast(resu ltValue); 194 positions = Array<TypeBuilder::Debugger::Location>::runtimeCast(resu ltValue);
203 return; 195 return;
204 } 196 }
205 } 197 }
206 *errorString = "Internal error"; 198 *errorString = "Internal error";
207 } 199 }
208 200
209 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) 201 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)
210 { 202 {
211 ScriptFunctionCall function(injectedScriptObject(), "setVariableValue"); 203 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
204 ScriptFunctionCall function(v8Context(), v8Value(), "setVariableValue");
212 if (callFrameIdOpt) { 205 if (callFrameIdOpt) {
213 function.appendArgument(callFrames); 206 function.appendArgument(callFrames);
214 function.appendArgument(*callFrameIdOpt); 207 function.appendArgument(*callFrameIdOpt);
215 } else { 208 } else {
216 function.appendArgument(false); 209 function.appendArgument(false);
217 function.appendArgument(false); 210 function.appendArgument(false);
218 } 211 }
219 if (functionObjectIdOpt) 212 if (functionObjectIdOpt)
220 function.appendArgument(*functionObjectIdOpt); 213 function.appendArgument(*functionObjectIdOpt);
221 else 214 else
222 function.appendArgument(false); 215 function.appendArgument(false);
223 function.appendArgument(scopeNumber); 216 function.appendArgument(scopeNumber);
224 function.appendArgument(variableName); 217 function.appendArgument(variableName);
225 function.appendArgument(newValueStr); 218 function.appendArgument(newValueStr);
226 RefPtr<JSONValue> resultValue; 219 RefPtr<JSONValue> resultValue;
227 makeCall(function, &resultValue); 220 makeCall(function, &resultValue);
228 if (!resultValue) { 221 if (!resultValue) {
229 *errorString = "Internal error"; 222 *errorString = "Internal error";
230 return; 223 return;
231 } 224 }
232 if (resultValue->type() == JSONValue::TypeString) { 225 if (resultValue->type() == JSONValue::TypeString) {
233 resultValue->asString(errorString); 226 resultValue->asString(errorString);
234 return; 227 return;
235 } 228 }
236 // Normal return. 229 // Normal return.
237 } 230 }
238 231
239 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<FunctionDetails>* result) 232 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<FunctionDetails>* result)
240 { 233 {
241 ScriptFunctionCall function(injectedScriptObject(), "getFunctionDetails"); 234 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
235 ScriptFunctionCall function(v8Context(), v8Value(), "getFunctionDetails");
242 function.appendArgument(functionId); 236 function.appendArgument(functionId);
243 RefPtr<JSONValue> resultValue; 237 RefPtr<JSONValue> resultValue;
244 makeCall(function, &resultValue); 238 makeCall(function, &resultValue);
245 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { 239 if (!resultValue || resultValue->type() != JSONValue::TypeObject) {
246 if (!resultValue->asString(errorString)) 240 if (!resultValue->asString(errorString))
247 *errorString = "Internal error"; 241 *errorString = "Internal error";
248 return; 242 return;
249 } 243 }
250 *result = FunctionDetails::runtimeCast(resultValue); 244 *result = FunctionDetails::runtimeCast(resultValue);
251 } 245 }
252 246
253 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S tring& objectId, RefPtr<GeneratorObjectDetails>* result) 247 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S tring& objectId, RefPtr<GeneratorObjectDetails>* result)
254 { 248 {
255 ScriptFunctionCall function(injectedScriptObject(), "getGeneratorObjectDetai ls"); 249 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
250 ScriptFunctionCall function(v8Context(), v8Value(), "getGeneratorObjectDetai ls");
256 function.appendArgument(objectId); 251 function.appendArgument(objectId);
257 RefPtr<JSONValue> resultValue; 252 RefPtr<JSONValue> resultValue;
258 makeCall(function, &resultValue); 253 makeCall(function, &resultValue);
259 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { 254 if (!resultValue || resultValue->type() != JSONValue::TypeObject) {
260 if (!resultValue->asString(errorString)) 255 if (!resultValue->asString(errorString))
261 *errorString = "Internal error"; 256 *errorString = "Internal error";
262 return; 257 return;
263 } 258 }
264 *result = GeneratorObjectDetails::runtimeCast(resultValue); 259 *result = GeneratorObjectDetails::runtimeCast(resultValue);
265 } 260 }
266 261
267 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String & objectId, RefPtr<Array<CollectionEntry> >* result) 262 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String & objectId, RefPtr<Array<CollectionEntry> >* result)
268 { 263 {
269 ScriptFunctionCall function(injectedScriptObject(), "getCollectionEntries"); 264 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
265 ScriptFunctionCall function(v8Context(), v8Value(), "getCollectionEntries");
270 function.appendArgument(objectId); 266 function.appendArgument(objectId);
271 RefPtr<JSONValue> resultValue; 267 RefPtr<JSONValue> resultValue;
272 makeCall(function, &resultValue); 268 makeCall(function, &resultValue);
273 if (!resultValue || resultValue->type() != JSONValue::TypeArray) { 269 if (!resultValue || resultValue->type() != JSONValue::TypeArray) {
274 if (!resultValue->asString(errorString)) 270 if (!resultValue->asString(errorString))
275 *errorString = "Internal error"; 271 *errorString = "Internal error";
276 return; 272 return;
277 } 273 }
278 *result = Array<CollectionEntry>::runtimeCast(resultValue); 274 *result = Array<CollectionEntry>::runtimeCast(resultValue);
279 } 275 }
280 276
281 void InjectedScript::getProperties(ErrorString* errorString, const String& objec tId, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, RefP tr<Array<PropertyDescriptor>>* properties, RefPtr<TypeBuilder::Debugger::Excepti onDetails>* exceptionDetails) 277 void InjectedScript::getProperties(ErrorString* errorString, const String& objec tId, bool ownProperties, bool accessorPropertiesOnly, bool generatePreview, RefP tr<Array<PropertyDescriptor>>* properties, RefPtr<TypeBuilder::Debugger::Excepti onDetails>* exceptionDetails)
282 { 278 {
283 ScriptFunctionCall function(injectedScriptObject(), "getProperties"); 279 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
280 ScriptFunctionCall function(v8Context(), v8Value(), "getProperties");
284 function.appendArgument(objectId); 281 function.appendArgument(objectId);
285 function.appendArgument(ownProperties); 282 function.appendArgument(ownProperties);
286 function.appendArgument(accessorPropertiesOnly); 283 function.appendArgument(accessorPropertiesOnly);
287 function.appendArgument(generatePreview); 284 function.appendArgument(generatePreview);
288 285
289 RefPtr<JSONValue> result; 286 RefPtr<JSONValue> result;
290 makeCallWithExceptionDetails(function, &result, exceptionDetails); 287 makeCallWithExceptionDetails(function, &result, exceptionDetails);
291 if (*exceptionDetails) { 288 if (*exceptionDetails) {
292 // FIXME: make properties optional 289 // FIXME: make properties optional
293 *properties = Array<PropertyDescriptor>::create(); 290 *properties = Array<PropertyDescriptor>::create();
294 return; 291 return;
295 } 292 }
296 if (!result || result->type() != JSONValue::TypeArray) { 293 if (!result || result->type() != JSONValue::TypeArray) {
297 *errorString = "Internal error"; 294 *errorString = "Internal error";
298 return; 295 return;
299 } 296 }
300 *properties = Array<PropertyDescriptor>::runtimeCast(result); 297 *properties = Array<PropertyDescriptor>::runtimeCast(result);
301 } 298 }
302 299
303 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin g& objectId, RefPtr<Array<InternalPropertyDescriptor>>* properties, RefPtr<TypeB uilder::Debugger::ExceptionDetails>* exceptionDetails) 300 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin g& objectId, RefPtr<Array<InternalPropertyDescriptor>>* properties, RefPtr<TypeB uilder::Debugger::ExceptionDetails>* exceptionDetails)
304 { 301 {
305 ScriptFunctionCall function(injectedScriptObject(), "getInternalProperties") ; 302 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
303 ScriptFunctionCall function(v8Context(), v8Value(), "getInternalProperties") ;
306 function.appendArgument(objectId); 304 function.appendArgument(objectId);
307 305
308 RefPtr<JSONValue> result; 306 RefPtr<JSONValue> result;
309 makeCallWithExceptionDetails(function, &result, exceptionDetails); 307 makeCallWithExceptionDetails(function, &result, exceptionDetails);
310 if (*exceptionDetails) 308 if (*exceptionDetails)
311 return; 309 return;
312 if (!result || result->type() != JSONValue::TypeArray) { 310 if (!result || result->type() != JSONValue::TypeArray) {
313 *errorString = "Internal error"; 311 *errorString = "Internal error";
314 return; 312 return;
315 } 313 }
(...skipping 11 matching lines...) Expand all
327 if (!parsedObjectId->asObject(&object)) 325 if (!parsedObjectId->asObject(&object))
328 return; 326 return;
329 int boundId = 0; 327 int boundId = 0;
330 if (!object->getNumber("id", &boundId)) 328 if (!object->getNumber("id", &boundId))
331 return; 329 return;
332 m_native->unbind(boundId); 330 m_native->unbind(boundId);
333 } 331 }
334 332
335 PassRefPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames, int asyncOrdinal) 333 PassRefPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames, int asyncOrdinal)
336 { 334 {
337 ScriptFunctionCall function(injectedScriptObject(), "wrapCallFrames"); 335 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
336 v8::Local<v8::Context> context = v8Context();
337 ScriptFunctionCall function(context, v8Value(), "wrapCallFrames");
338 function.appendArgument(callFrames); 338 function.appendArgument(callFrames);
339 function.appendArgument(asyncOrdinal); 339 function.appendArgument(asyncOrdinal);
340 bool hadException = false; 340 bool hadException = false;
341 ScriptValue callFramesValue = callFunctionWithEvalEnabled(function, hadExcep tion); 341 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException);
342 ASSERT(!hadException); 342 ASSERT(!hadException);
343 RefPtr<JSONValue> result = toJSONValue(callFramesValue); 343 RefPtr<JSONValue> result = toJSONValue(context, callFramesValue);
344 if (result && result->type() == JSONValue::TypeArray) 344 if (result && result->type() == JSONValue::TypeArray)
345 return Array<CallFrame>::runtimeCast(result); 345 return Array<CallFrame>::runtimeCast(result);
346 return Array<CallFrame>::create(); 346 return Array<CallFrame>::create();
347 } 347 }
348 348
349 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(const ScriptValue& value, const String& groupName, bool generatePreview) const 349 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(const ScriptValue& value, const String& groupName, bool generatePreview) const
350 { 350 {
351 ScriptFunctionCall wrapFunction(injectedScriptObject(), "wrapObject"); 351 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
352 wrapFunction.appendArgument(value); 352 v8::Local<v8::Context> context = v8Context();
353 ScriptFunctionCall wrapFunction(context, v8Value(), "wrapObject");
354 wrapFunction.appendArgument(value.v8Value());
353 wrapFunction.appendArgument(groupName); 355 wrapFunction.appendArgument(groupName);
354 wrapFunction.appendArgument(canAccessInspectedWindow()); 356 wrapFunction.appendArgument(canAccessInspectedWindow());
355 wrapFunction.appendArgument(generatePreview); 357 wrapFunction.appendArgument(generatePreview);
356 bool hadException = false; 358 bool hadException = false;
357 ScriptValue r = callFunctionWithEvalEnabled(wrapFunction, hadException); 359 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(wrapFunction, hadExcept ion);
358 if (hadException) 360 if (hadException)
359 return nullptr; 361 return nullptr;
360 RefPtr<JSONObject> rawResult = toJSONValue(r)->asObject(); 362 RefPtr<JSONObject> rawResult = toJSONValue(context, r)->asObject();
361 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); 363 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult);
362 } 364 }
363 365
364 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapTable(const S criptValue& table, const ScriptValue& columns) const 366 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapTable(const S criptValue& table, const ScriptValue& columns) const
365 { 367 {
366 ScriptFunctionCall wrapFunction(injectedScriptObject(), "wrapTable"); 368 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
369 v8::Local<v8::Context> context = v8Context();
370 ScriptFunctionCall wrapFunction(context, v8Value(), "wrapTable");
367 wrapFunction.appendArgument(canAccessInspectedWindow()); 371 wrapFunction.appendArgument(canAccessInspectedWindow());
368 wrapFunction.appendArgument(table); 372 wrapFunction.appendArgument(table.v8Value());
369 if (columns.isEmpty()) 373 if (columns.isEmpty())
370 wrapFunction.appendArgument(false); 374 wrapFunction.appendArgument(false);
371 else 375 else
372 wrapFunction.appendArgument(columns); 376 wrapFunction.appendArgument(columns.v8Value());
373 bool hadException = false; 377 bool hadException = false;
374 ScriptValue r = callFunctionWithEvalEnabled(wrapFunction, hadException); 378 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(wrapFunction, hadExcep tion);
375 if (hadException) 379 if (hadException)
376 return nullptr; 380 return nullptr;
377 RefPtr<JSONObject> rawResult = toJSONValue(r)->asObject(); 381 RefPtr<JSONObject> rawResult = toJSONValue(context, r)->asObject();
378 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); 382 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult);
379 } 383 }
380 384
381 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const 385 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const
382 { 386 {
383 return m_native->objectForId(objectId.id()); 387 return m_native->objectForId(objectId.id());
384 } 388 }
385 389
386 String InjectedScript::objectIdToObjectGroupName(const String& objectId) const 390 String InjectedScript::objectIdToObjectGroupName(const String& objectId) const
387 { 391 {
388 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); 392 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId);
389 if (!parsedObjectId) 393 if (!parsedObjectId)
390 return String(); 394 return String();
391 RefPtr<JSONObject> object; 395 RefPtr<JSONObject> object;
392 if (!parsedObjectId->asObject(&object)) 396 if (!parsedObjectId->asObject(&object))
393 return String(); 397 return String();
394 int boundId = 0; 398 int boundId = 0;
395 if (!object->getNumber("id", &boundId)) 399 if (!object->getNumber("id", &boundId))
396 return String(); 400 return String();
397 return m_native->groupName(boundId); 401 return m_native->groupName(boundId);
398 } 402 }
399 403
400 void InjectedScript::releaseObjectGroup(const String& objectGroup) 404 void InjectedScript::releaseObjectGroup(const String& objectGroup)
401 { 405 {
406 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
402 m_native->releaseObjectGroup(objectGroup); 407 m_native->releaseObjectGroup(objectGroup);
403 if (objectGroup == "console") { 408 if (objectGroup == "console") {
404 ScriptFunctionCall releaseFunction(injectedScriptObject(), "clearLastEva luationResult"); 409 ScriptFunctionCall releaseFunction(v8Context(), v8Value(), "clearLastEva luationResult");
405 bool hadException = false; 410 bool hadException = false;
406 callFunctionWithEvalEnabled(releaseFunction, hadException); 411 callFunctionWithEvalEnabled(releaseFunction, hadException);
407 ASSERT(!hadException); 412 ASSERT(!hadException);
408 } 413 }
409 } 414 }
410 415
411 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) 416 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled)
412 { 417 {
413 ScriptFunctionCall function(injectedScriptObject(), "setCustomObjectFormatte rEnabled"); 418 ScriptState::Scope scope(m_injectedScriptObject.scriptState());
419 ScriptFunctionCall function(v8Context(), v8Value(), "setCustomObjectFormatte rEnabled");
414 function.appendArgument(enabled); 420 function.appendArgument(enabled);
415 RefPtr<JSONValue> result; 421 RefPtr<JSONValue> result;
416 makeCall(function, &result); 422 makeCall(function, &result);
417 } 423 }
418 424
419 void InjectedScript::initialize(ScriptValue injectedScriptObject, InspectedState AccessCheck accessCheck)
420 {
421 m_injectedScriptObject = injectedScriptObject;
422 m_inspectedStateAccessCheck = accessCheck;
423 }
424
425 bool InjectedScript::canAccessInspectedWindow() const 425 bool InjectedScript::canAccessInspectedWindow() const
426 { 426 {
427 return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState()); 427 return m_inspectedStateAccessCheck(m_injectedScriptObject.scriptState());
428 } 428 }
429 429
430 const ScriptValue& InjectedScript::injectedScriptObject() const 430 v8::Local<v8::Context> InjectedScript::v8Context() const
431 { 431 {
432 return m_injectedScriptObject; 432 return m_injectedScriptObject.context();
433 } 433 }
434 434
435 ScriptValue InjectedScript::callFunctionWithEvalEnabled(ScriptFunctionCall& func tion, bool& hadException) const 435 v8::Local<v8::Value> InjectedScript::v8Value() const
436 { 436 {
437 ScriptState* scriptState = m_injectedScriptObject.scriptState(); 437 return m_injectedScriptObject.v8Value();
438 ScriptState::Scope scope(scriptState); 438 }
439 bool evalIsDisabled = !scriptState->evalEnabled(); 439
440 v8::Local<v8::Value> InjectedScript::callFunctionWithEvalEnabled(ScriptFunctionC all& function, bool& hadException) const
dgozman 2016/01/26 02:45:15 Non-const references are prohibited.
pfeldman 2016/01/27 01:24:09 this comes from lhs. i'll fix it.
441 {
442 v8::Local<v8::Context> context = v8Context();
443 bool evalIsDisabled = !context->IsCodeGenerationFromStringsAllowed();
440 // Temporarily enable allow evals for inspector. 444 // Temporarily enable allow evals for inspector.
441 if (evalIsDisabled) 445 if (evalIsDisabled)
442 scriptState->setEvalEnabled(true); 446 context->AllowCodeGenerationFromStrings(true);
443 447 v8::Local<v8::Value> resultValue = function.call(hadException);
444 ScriptValue resultValue = function.call(hadException);
445
446 if (evalIsDisabled) 448 if (evalIsDisabled)
447 scriptState->setEvalEnabled(false); 449 context->AllowCodeGenerationFromStrings(false);
448
449 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( )); 450 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( ));
450 return resultValue; 451 return resultValue;
451 } 452 }
452 453
453 void InjectedScript::makeCall(ScriptFunctionCall& function, RefPtr<JSONValue>* r esult) 454 void InjectedScript::makeCall(ScriptFunctionCall& function, RefPtr<JSONValue>* r esult)
454 { 455 {
455 if (!canAccessInspectedWindow()) { 456 if (!canAccessInspectedWindow()) {
456 *result = JSONValue::null(); 457 *result = JSONValue::null();
457 return; 458 return;
458 } 459 }
459 460
460 bool hadException = false; 461 bool hadException = false;
461 ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException ); 462 v8::Local<v8::Value> resultValue = callFunctionWithEvalEnabled(function, had Exception);
462 463
463 ASSERT(!hadException); 464 ASSERT(!hadException);
464 if (!hadException) { 465 if (!hadException) {
465 *result = toJSONValue(resultValue); 466 *result = toJSONValue(function.context(), resultValue);
466 if (!*result) 467 if (!*result)
467 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 468 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
468 } else { 469 } else {
469 *result = JSONString::create("Exception while making a call."); 470 *result = JSONString::create("Exception while making a call.");
470 } 471 }
471 } 472 }
472 473
473 void InjectedScript::makeEvalCall(ErrorString* errorString, ScriptFunctionCall& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuilder: :OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* ex ceptionDetails) 474 void InjectedScript::makeEvalCall(ErrorString* errorString, ScriptFunctionCall& function, RefPtr<TypeBuilder::Runtime::RemoteObject>* objectResult, TypeBuilder: :OptOutput<bool>* wasThrown, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* ex ceptionDetails)
474 { 475 {
475 RefPtr<JSONValue> result; 476 RefPtr<JSONValue> result;
(...skipping 22 matching lines...) Expand all
498 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep tionDetails"); 499 RefPtr<JSONObject> objectExceptionDetails = resultPair->getObject("excep tionDetails");
499 if (objectExceptionDetails) 500 if (objectExceptionDetails)
500 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e()); 501 *exceptionDetails = toExceptionDetails(objectExceptionDetails.releas e());
501 } 502 }
502 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj); 503 *objectResult = TypeBuilder::Runtime::RemoteObject::runtimeCast(resultObj);
503 *wasThrown = wasThrownVal; 504 *wasThrown = wasThrownVal;
504 } 505 }
505 506
506 void InjectedScript::makeCallWithExceptionDetails(ScriptFunctionCall& function, RefPtr<JSONValue>* result, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* exce ptionDetails) 507 void InjectedScript::makeCallWithExceptionDetails(ScriptFunctionCall& function, RefPtr<JSONValue>* result, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* exce ptionDetails)
507 { 508 {
508 ScriptState::Scope scope(injectedScriptObject().scriptState()); 509 v8::TryCatch tryCatch(m_isolate);
509 v8::TryCatch tryCatch(injectedScriptObject().isolate()); 510 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling();
510 ScriptValue resultValue = function.callWithoutExceptionHandling();
511 if (tryCatch.HasCaught()) { 511 if (tryCatch.HasCaught()) {
512 v8::Local<v8::Message> message = tryCatch.Message(); 512 v8::Local<v8::Message> message = tryCatch.Message();
513 String text = !message.IsEmpty() ? toCoreStringWithUndefinedOrNullCheck( message->Get()) : "Internal error"; 513 String text = !message.IsEmpty() ? toCoreStringWithUndefinedOrNullCheck( message->Get()) : "Internal error";
514 *exceptionDetails = TypeBuilder::Debugger::ExceptionDetails::create().se tText(text); 514 *exceptionDetails = TypeBuilder::Debugger::ExceptionDetails::create().se tText(text);
515 } else { 515 } else {
516 *result = toJSONValue(resultValue); 516 *result = toJSONValue(function.context(), resultValue);
517 if (!*result) 517 if (!*result)
518 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); 518 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth));
519 } 519 }
520 } 520 }
521 521
522 } // namespace blink 522 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698