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