Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 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/InjectedScriptManager.h" | |
| 36 #include "core/inspector/InspectorTraceEvents.h" | 37 #include "core/inspector/InspectorTraceEvents.h" |
| 37 #include "core/inspector/JSONParser.h" | 38 #include "core/inspector/JSONParser.h" |
| 38 #include "core/inspector/RemoteObjectId.h" | 39 #include "core/inspector/RemoteObjectId.h" |
| 40 #include "core/inspector/v8/V8Debugger.h" | |
| 39 #include "core/inspector/v8/V8DebuggerClient.h" | 41 #include "core/inspector/v8/V8DebuggerClient.h" |
| 40 #include "platform/JSONValues.h" | 42 #include "platform/JSONValues.h" |
| 41 #include "platform/JSONValuesForV8.h" | 43 #include "platform/JSONValuesForV8.h" |
| 42 #include "wtf/text/WTFString.h" | 44 #include "wtf/text/WTFString.h" |
| 43 | 45 |
| 44 using blink::TypeBuilder::Array; | 46 using blink::TypeBuilder::Array; |
| 45 using blink::TypeBuilder::Debugger::CallFrame; | 47 using blink::TypeBuilder::Debugger::CallFrame; |
| 46 using blink::TypeBuilder::Debugger::CollectionEntry; | 48 using blink::TypeBuilder::Debugger::CollectionEntry; |
| 47 using blink::TypeBuilder::Debugger::FunctionDetails; | 49 using blink::TypeBuilder::Debugger::FunctionDetails; |
| 48 using blink::TypeBuilder::Debugger::GeneratorObjectDetails; | 50 using blink::TypeBuilder::Debugger::GeneratorObjectDetails; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 | 101 |
| 100 frames->addItem(callFrame.release()); | 102 frames->addItem(callFrame.release()); |
| 101 } | 103 } |
| 102 exceptionDetails->setStackTrace(frames.release()); | 104 exceptionDetails->setStackTrace(frames.release()); |
| 103 } | 105 } |
| 104 if (originScriptId) | 106 if (originScriptId) |
| 105 exceptionDetails->setScriptId(String::number(originScriptId)); | 107 exceptionDetails->setScriptId(String::number(originScriptId)); |
| 106 return exceptionDetails.release(); | 108 return exceptionDetails.release(); |
| 107 } | 109 } |
| 108 | 110 |
| 109 InjectedScript::InjectedScript(v8::Local<v8::Object> injectedScriptObject, V8Deb uggerClient* client, PassRefPtr<InjectedScriptNative> injectedScriptNative, int contextId) | 111 static void weakCallback(const v8::WeakCallbackInfo<InjectedScript>& data) |
| 110 : m_isolate(injectedScriptObject->CreationContext()->GetIsolate()) | 112 { |
| 111 , m_injectedScriptObject(ScriptValue(ScriptState::from(injectedScriptObject- >CreationContext()), injectedScriptObject)) | 113 data.GetParameter()->dispose(); |
| 114 } | |
| 115 | |
| 116 InjectedScript::InjectedScript(InjectedScriptManager* manager, v8::Local<v8::Con text> context, v8::Local<v8::Object> object, V8DebuggerClient* client, PassRefPt r<InjectedScriptNative> injectedScriptNative, int contextId) | |
| 117 : m_manager(manager) | |
| 118 , m_isolate(context->GetIsolate()) | |
| 119 , m_context(m_isolate, context) | |
| 120 , m_value(m_isolate, object) | |
| 112 , m_client(client) | 121 , m_client(client) |
| 113 , m_native(injectedScriptNative) | 122 , m_native(injectedScriptNative) |
| 114 , m_contextId(contextId) | 123 , m_contextId(contextId) |
| 115 { | 124 { |
| 125 m_context.SetWeak(this, &weakCallback, v8::WeakCallbackType::kParameter); | |
|
dgozman
2016/01/27 22:05:47
You can pass context here as v8::Global already, a
pfeldman
2016/01/27 22:15:45
Not a fan of passing a weak global - it is not cle
| |
| 116 } | 126 } |
| 117 | 127 |
| 118 InjectedScript::~InjectedScript() | 128 InjectedScript::~InjectedScript() |
| 119 { | 129 { |
| 120 } | 130 } |
| 121 | 131 |
| 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) | 132 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) |
| 123 { | 133 { |
| 124 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 134 v8::HandleScope handles(m_isolate); |
| 125 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "evaluate"); | 135 ScriptFunctionCall function(m_client, context(), v8Value(), "evaluate"); |
| 126 function.appendArgument(expression); | 136 function.appendArgument(expression); |
| 127 function.appendArgument(objectGroup); | 137 function.appendArgument(objectGroup); |
| 128 function.appendArgument(includeCommandLineAPI); | 138 function.appendArgument(includeCommandLineAPI); |
| 129 function.appendArgument(returnByValue); | 139 function.appendArgument(returnByValue); |
| 130 function.appendArgument(generatePreview); | 140 function.appendArgument(generatePreview); |
| 131 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); | 141 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); |
| 132 } | 142 } |
| 133 | 143 |
| 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) | 144 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) |
| 135 { | 145 { |
| 136 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 146 v8::HandleScope handles(m_isolate); |
| 137 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "callFunctionO n"); | 147 ScriptFunctionCall function(m_client, context(), v8Value(), "callFunctionOn" ); |
| 138 function.appendArgument(objectId); | 148 function.appendArgument(objectId); |
| 139 function.appendArgument(expression); | 149 function.appendArgument(expression); |
| 140 function.appendArgument(arguments); | 150 function.appendArgument(arguments); |
| 141 function.appendArgument(returnByValue); | 151 function.appendArgument(returnByValue); |
| 142 function.appendArgument(generatePreview); | 152 function.appendArgument(generatePreview); |
| 143 makeEvalCall(errorString, function, result, wasThrown); | 153 makeEvalCall(errorString, function, result, wasThrown); |
| 144 } | 154 } |
| 145 | 155 |
| 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) | 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) |
| 147 { | 157 { |
| 148 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 158 v8::HandleScope handles(m_isolate); |
| 149 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "evaluateOnCal lFrame"); | 159 ScriptFunctionCall function(m_client, context(), v8Value(), "evaluateOnCallF rame"); |
| 150 function.appendArgument(callFrames); | 160 function.appendArgument(callFrames); |
| 151 function.appendArgument(isAsyncCallStack); | 161 function.appendArgument(isAsyncCallStack); |
| 152 function.appendArgument(callFrameId); | 162 function.appendArgument(callFrameId); |
| 153 function.appendArgument(expression); | 163 function.appendArgument(expression); |
| 154 function.appendArgument(objectGroup); | 164 function.appendArgument(objectGroup); |
| 155 function.appendArgument(includeCommandLineAPI); | 165 function.appendArgument(includeCommandLineAPI); |
| 156 function.appendArgument(returnByValue); | 166 function.appendArgument(returnByValue); |
| 157 function.appendArgument(generatePreview); | 167 function.appendArgument(generatePreview); |
| 158 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); | 168 makeEvalCall(errorString, function, result, wasThrown, exceptionDetails); |
| 159 } | 169 } |
| 160 | 170 |
| 161 void InjectedScript::restartFrame(ErrorString* errorString, v8::Local<v8::Object > callFrames, const String& callFrameId) | 171 void InjectedScript::restartFrame(ErrorString* errorString, v8::Local<v8::Object > callFrames, const String& callFrameId) |
| 162 { | 172 { |
| 163 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 173 v8::HandleScope handles(m_isolate); |
| 164 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "restartFrame" ); | 174 ScriptFunctionCall function(m_client, context(), v8Value(), "restartFrame"); |
| 165 function.appendArgument(callFrames); | 175 function.appendArgument(callFrames); |
| 166 function.appendArgument(callFrameId); | 176 function.appendArgument(callFrameId); |
| 167 RefPtr<JSONValue> resultValue; | 177 RefPtr<JSONValue> resultValue; |
| 168 makeCall(function, &resultValue); | 178 makeCall(function, &resultValue); |
| 169 if (resultValue) { | 179 if (resultValue) { |
| 170 if (resultValue->type() == JSONValue::TypeString) { | 180 if (resultValue->type() == JSONValue::TypeString) { |
| 171 resultValue->asString(errorString); | 181 resultValue->asString(errorString); |
| 172 } else { | 182 } else { |
| 173 bool value; | 183 bool value; |
| 174 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value); | 184 ASSERT_UNUSED(value, resultValue->asBoolean(&value) && value); |
| 175 } | 185 } |
| 176 return; | 186 return; |
| 177 } | 187 } |
| 178 *errorString = "Internal error"; | 188 *errorString = "Internal error"; |
| 179 } | 189 } |
| 180 | 190 |
| 181 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8:: Object> callFrames, const String& callFrameId, RefPtr<Array<TypeBuilder::Debugge r::Location>>& positions) | 191 void InjectedScript::getStepInPositions(ErrorString* errorString, v8::Local<v8:: Object> callFrames, const String& callFrameId, RefPtr<Array<TypeBuilder::Debugge r::Location>>& positions) |
| 182 { | 192 { |
| 183 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 193 v8::HandleScope handles(m_isolate); |
| 184 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "getStepInPosi tions"); | 194 ScriptFunctionCall function(m_client, context(), v8Value(), "getStepInPositi ons"); |
| 185 function.appendArgument(callFrames); | 195 function.appendArgument(callFrames); |
| 186 function.appendArgument(callFrameId); | 196 function.appendArgument(callFrameId); |
| 187 RefPtr<JSONValue> resultValue; | 197 RefPtr<JSONValue> resultValue; |
| 188 makeCall(function, &resultValue); | 198 makeCall(function, &resultValue); |
| 189 if (resultValue) { | 199 if (resultValue) { |
| 190 if (resultValue->type() == JSONValue::TypeString) { | 200 if (resultValue->type() == JSONValue::TypeString) { |
| 191 resultValue->asString(errorString); | 201 resultValue->asString(errorString); |
| 192 return; | 202 return; |
| 193 } | 203 } |
| 194 if (resultValue->type() == JSONValue::TypeArray) { | 204 if (resultValue->type() == JSONValue::TypeArray) { |
| 195 positions = Array<TypeBuilder::Debugger::Location>::runtimeCast(resu ltValue); | 205 positions = Array<TypeBuilder::Debugger::Location>::runtimeCast(resu ltValue); |
| 196 return; | 206 return; |
| 197 } | 207 } |
| 198 } | 208 } |
| 199 *errorString = "Internal error"; | 209 *errorString = "Internal error"; |
| 200 } | 210 } |
| 201 | 211 |
| 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) | 212 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) |
| 203 { | 213 { |
| 204 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 214 v8::HandleScope handles(m_isolate); |
| 205 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "setVariableVa lue"); | 215 ScriptFunctionCall function(m_client, context(), v8Value(), "setVariableValu e"); |
| 206 if (callFrameIdOpt) { | 216 if (callFrameIdOpt) { |
| 207 function.appendArgument(callFrames); | 217 function.appendArgument(callFrames); |
| 208 function.appendArgument(*callFrameIdOpt); | 218 function.appendArgument(*callFrameIdOpt); |
| 209 } else { | 219 } else { |
| 210 function.appendArgument(false); | 220 function.appendArgument(false); |
| 211 function.appendArgument(false); | 221 function.appendArgument(false); |
| 212 } | 222 } |
| 213 if (functionObjectIdOpt) | 223 if (functionObjectIdOpt) |
| 214 function.appendArgument(*functionObjectIdOpt); | 224 function.appendArgument(*functionObjectIdOpt); |
| 215 else | 225 else |
| 216 function.appendArgument(false); | 226 function.appendArgument(false); |
| 217 function.appendArgument(scopeNumber); | 227 function.appendArgument(scopeNumber); |
| 218 function.appendArgument(variableName); | 228 function.appendArgument(variableName); |
| 219 function.appendArgument(newValueStr); | 229 function.appendArgument(newValueStr); |
| 220 RefPtr<JSONValue> resultValue; | 230 RefPtr<JSONValue> resultValue; |
| 221 makeCall(function, &resultValue); | 231 makeCall(function, &resultValue); |
| 222 if (!resultValue) { | 232 if (!resultValue) { |
| 223 *errorString = "Internal error"; | 233 *errorString = "Internal error"; |
| 224 return; | 234 return; |
| 225 } | 235 } |
| 226 if (resultValue->type() == JSONValue::TypeString) { | 236 if (resultValue->type() == JSONValue::TypeString) { |
| 227 resultValue->asString(errorString); | 237 resultValue->asString(errorString); |
| 228 return; | 238 return; |
| 229 } | 239 } |
| 230 // Normal return. | 240 // Normal return. |
| 231 } | 241 } |
| 232 | 242 |
| 233 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<FunctionDetails>* result) | 243 void InjectedScript::getFunctionDetails(ErrorString* errorString, const String& functionId, RefPtr<FunctionDetails>* result) |
| 234 { | 244 { |
| 235 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 245 v8::HandleScope handles(m_isolate); |
| 236 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "getFunctionDe tails"); | 246 ScriptFunctionCall function(m_client, context(), v8Value(), "getFunctionDeta ils"); |
| 237 function.appendArgument(functionId); | 247 function.appendArgument(functionId); |
| 238 RefPtr<JSONValue> resultValue; | 248 RefPtr<JSONValue> resultValue; |
| 239 makeCall(function, &resultValue); | 249 makeCall(function, &resultValue); |
| 240 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { | 250 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { |
| 241 if (!resultValue->asString(errorString)) | 251 if (!resultValue->asString(errorString)) |
| 242 *errorString = "Internal error"; | 252 *errorString = "Internal error"; |
| 243 return; | 253 return; |
| 244 } | 254 } |
| 245 *result = FunctionDetails::runtimeCast(resultValue); | 255 *result = FunctionDetails::runtimeCast(resultValue); |
| 246 } | 256 } |
| 247 | 257 |
| 248 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S tring& objectId, RefPtr<GeneratorObjectDetails>* result) | 258 void InjectedScript::getGeneratorObjectDetails(ErrorString* errorString, const S tring& objectId, RefPtr<GeneratorObjectDetails>* result) |
| 249 { | 259 { |
| 250 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 260 v8::HandleScope handles(m_isolate); |
| 251 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "getGeneratorO bjectDetails"); | 261 ScriptFunctionCall function(m_client, context(), v8Value(), "getGeneratorObj ectDetails"); |
| 252 function.appendArgument(objectId); | 262 function.appendArgument(objectId); |
| 253 RefPtr<JSONValue> resultValue; | 263 RefPtr<JSONValue> resultValue; |
| 254 makeCall(function, &resultValue); | 264 makeCall(function, &resultValue); |
| 255 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { | 265 if (!resultValue || resultValue->type() != JSONValue::TypeObject) { |
| 256 if (!resultValue->asString(errorString)) | 266 if (!resultValue->asString(errorString)) |
| 257 *errorString = "Internal error"; | 267 *errorString = "Internal error"; |
| 258 return; | 268 return; |
| 259 } | 269 } |
| 260 *result = GeneratorObjectDetails::runtimeCast(resultValue); | 270 *result = GeneratorObjectDetails::runtimeCast(resultValue); |
| 261 } | 271 } |
| 262 | 272 |
| 263 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String & objectId, RefPtr<Array<CollectionEntry> >* result) | 273 void InjectedScript::getCollectionEntries(ErrorString* errorString, const String & objectId, RefPtr<Array<CollectionEntry> >* result) |
| 264 { | 274 { |
| 265 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 275 v8::HandleScope handles(m_isolate); |
| 266 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "getCollection Entries"); | 276 ScriptFunctionCall function(m_client, context(), v8Value(), "getCollectionEn tries"); |
| 267 function.appendArgument(objectId); | 277 function.appendArgument(objectId); |
| 268 RefPtr<JSONValue> resultValue; | 278 RefPtr<JSONValue> resultValue; |
| 269 makeCall(function, &resultValue); | 279 makeCall(function, &resultValue); |
| 270 if (!resultValue || resultValue->type() != JSONValue::TypeArray) { | 280 if (!resultValue || resultValue->type() != JSONValue::TypeArray) { |
| 271 if (!resultValue->asString(errorString)) | 281 if (!resultValue->asString(errorString)) |
| 272 *errorString = "Internal error"; | 282 *errorString = "Internal error"; |
| 273 return; | 283 return; |
| 274 } | 284 } |
| 275 *result = Array<CollectionEntry>::runtimeCast(resultValue); | 285 *result = Array<CollectionEntry>::runtimeCast(resultValue); |
| 276 } | 286 } |
| 277 | 287 |
| 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) | 288 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) |
| 279 { | 289 { |
| 280 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 290 v8::HandleScope handles(m_isolate); |
| 281 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "getProperties "); | 291 ScriptFunctionCall function(m_client, context(), v8Value(), "getProperties") ; |
| 282 function.appendArgument(objectId); | 292 function.appendArgument(objectId); |
| 283 function.appendArgument(ownProperties); | 293 function.appendArgument(ownProperties); |
| 284 function.appendArgument(accessorPropertiesOnly); | 294 function.appendArgument(accessorPropertiesOnly); |
| 285 function.appendArgument(generatePreview); | 295 function.appendArgument(generatePreview); |
| 286 | 296 |
| 287 RefPtr<JSONValue> result; | 297 RefPtr<JSONValue> result; |
| 288 makeCallWithExceptionDetails(function, &result, exceptionDetails); | 298 makeCallWithExceptionDetails(function, &result, exceptionDetails); |
| 289 if (*exceptionDetails) { | 299 if (*exceptionDetails) { |
| 290 // FIXME: make properties optional | 300 // FIXME: make properties optional |
| 291 *properties = Array<PropertyDescriptor>::create(); | 301 *properties = Array<PropertyDescriptor>::create(); |
| 292 return; | 302 return; |
| 293 } | 303 } |
| 294 if (!result || result->type() != JSONValue::TypeArray) { | 304 if (!result || result->type() != JSONValue::TypeArray) { |
| 295 *errorString = "Internal error"; | 305 *errorString = "Internal error"; |
| 296 return; | 306 return; |
| 297 } | 307 } |
| 298 *properties = Array<PropertyDescriptor>::runtimeCast(result); | 308 *properties = Array<PropertyDescriptor>::runtimeCast(result); |
| 299 } | 309 } |
| 300 | 310 |
| 301 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin g& objectId, RefPtr<Array<InternalPropertyDescriptor>>* properties, RefPtr<TypeB uilder::Debugger::ExceptionDetails>* exceptionDetails) | 311 void InjectedScript::getInternalProperties(ErrorString* errorString, const Strin g& objectId, RefPtr<Array<InternalPropertyDescriptor>>* properties, RefPtr<TypeB uilder::Debugger::ExceptionDetails>* exceptionDetails) |
| 302 { | 312 { |
| 303 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 313 v8::HandleScope handles(m_isolate); |
| 304 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "getInternalPr operties"); | 314 ScriptFunctionCall function(m_client, context(), v8Value(), "getInternalProp erties"); |
| 305 function.appendArgument(objectId); | 315 function.appendArgument(objectId); |
| 306 | 316 |
| 307 RefPtr<JSONValue> result; | 317 RefPtr<JSONValue> result; |
| 308 makeCallWithExceptionDetails(function, &result, exceptionDetails); | 318 makeCallWithExceptionDetails(function, &result, exceptionDetails); |
| 309 if (*exceptionDetails) | 319 if (*exceptionDetails) |
| 310 return; | 320 return; |
| 311 if (!result || result->type() != JSONValue::TypeArray) { | 321 if (!result || result->type() != JSONValue::TypeArray) { |
| 312 *errorString = "Internal error"; | 322 *errorString = "Internal error"; |
| 313 return; | 323 return; |
| 314 } | 324 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 326 if (!parsedObjectId->asObject(&object)) | 336 if (!parsedObjectId->asObject(&object)) |
| 327 return; | 337 return; |
| 328 int boundId = 0; | 338 int boundId = 0; |
| 329 if (!object->getNumber("id", &boundId)) | 339 if (!object->getNumber("id", &boundId)) |
| 330 return; | 340 return; |
| 331 m_native->unbind(boundId); | 341 m_native->unbind(boundId); |
| 332 } | 342 } |
| 333 | 343 |
| 334 PassRefPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames, int asyncOrdinal) | 344 PassRefPtr<Array<CallFrame>> InjectedScript::wrapCallFrames(v8::Local<v8::Object > callFrames, int asyncOrdinal) |
| 335 { | 345 { |
| 336 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 346 v8::HandleScope handles(m_isolate); |
| 337 v8::Local<v8::Context> context = v8Context(); | 347 ScriptFunctionCall function(m_client, context(), v8Value(), "wrapCallFrames" ); |
| 338 ScriptFunctionCall function(m_client, context, v8Value(), "wrapCallFrames"); | |
| 339 function.appendArgument(callFrames); | 348 function.appendArgument(callFrames); |
| 340 function.appendArgument(asyncOrdinal); | 349 function.appendArgument(asyncOrdinal); |
| 341 bool hadException = false; | 350 bool hadException = false; |
| 342 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException); | 351 v8::Local<v8::Value> callFramesValue = callFunctionWithEvalEnabled(function, hadException); |
| 343 ASSERT(!hadException); | 352 ASSERT(!hadException); |
| 344 RefPtr<JSONValue> result = toJSONValue(context, callFramesValue); | 353 RefPtr<JSONValue> result = toJSONValue(context(), callFramesValue); |
| 345 if (result && result->type() == JSONValue::TypeArray) | 354 if (result && result->type() == JSONValue::TypeArray) |
| 346 return Array<CallFrame>::runtimeCast(result); | 355 return Array<CallFrame>::runtimeCast(result); |
| 347 return Array<CallFrame>::create(); | 356 return Array<CallFrame>::create(); |
| 348 } | 357 } |
| 349 | 358 |
| 350 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Lo cal<v8::Value> value, const String& groupName, bool generatePreview) const | 359 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapObject(v8::Lo cal<v8::Value> value, const String& groupName, bool generatePreview) const |
| 351 { | 360 { |
| 352 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 361 v8::HandleScope handles(m_isolate); |
| 353 v8::Local<v8::Context> context = v8Context(); | 362 ScriptFunctionCall function(m_client, context(), v8Value(), "wrapObject"); |
| 354 ScriptFunctionCall function(m_client, context, v8Value(), "wrapObject"); | |
| 355 function.appendArgument(value); | 363 function.appendArgument(value); |
| 356 function.appendArgument(groupName); | 364 function.appendArgument(groupName); |
| 357 function.appendArgument(canAccessInspectedWindow()); | 365 function.appendArgument(canAccessInspectedWindow()); |
| 358 function.appendArgument(generatePreview); | 366 function.appendArgument(generatePreview); |
| 359 bool hadException = false; | 367 bool hadException = false; |
| 360 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ; | 368 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException) ; |
| 361 if (hadException) | 369 if (hadException) |
| 362 return nullptr; | 370 return nullptr; |
| 363 RefPtr<JSONObject> rawResult = toJSONValue(context, r)->asObject(); | 371 RefPtr<JSONObject> rawResult = toJSONValue(context(), r)->asObject(); |
| 364 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); | 372 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); |
| 365 } | 373 } |
| 366 | 374 |
| 367 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Loc al<v8::Value> table, v8::Local<v8::Value> columns) const | 375 PassRefPtr<TypeBuilder::Runtime::RemoteObject> InjectedScript::wrapTable(v8::Loc al<v8::Value> table, v8::Local<v8::Value> columns) const |
| 368 { | 376 { |
| 369 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 377 v8::HandleScope handles(m_isolate); |
| 370 v8::Local<v8::Context> context = v8Context(); | 378 ScriptFunctionCall function(m_client, context(), v8Value(), "wrapTable"); |
| 371 ScriptFunctionCall function(m_client, context, v8Value(), "wrapTable"); | |
| 372 function.appendArgument(canAccessInspectedWindow()); | 379 function.appendArgument(canAccessInspectedWindow()); |
| 373 function.appendArgument(table); | 380 function.appendArgument(table); |
| 374 if (columns.IsEmpty()) | 381 if (columns.IsEmpty()) |
| 375 function.appendArgument(false); | 382 function.appendArgument(false); |
| 376 else | 383 else |
| 377 function.appendArgument(columns); | 384 function.appendArgument(columns); |
| 378 bool hadException = false; | 385 bool hadException = false; |
| 379 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException ); | 386 v8::Local<v8::Value> r = callFunctionWithEvalEnabled(function, hadException ); |
| 380 if (hadException) | 387 if (hadException) |
| 381 return nullptr; | 388 return nullptr; |
| 382 RefPtr<JSONObject> rawResult = toJSONValue(context, r)->asObject(); | 389 RefPtr<JSONObject> rawResult = toJSONValue(context(), r)->asObject(); |
| 383 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); | 390 return TypeBuilder::Runtime::RemoteObject::runtimeCast(rawResult); |
| 384 } | 391 } |
| 385 | 392 |
| 386 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const | 393 v8::Local<v8::Value> InjectedScript::findObject(const RemoteObjectId& objectId) const |
| 387 { | 394 { |
| 388 return m_native->objectForId(objectId.id()); | 395 return m_native->objectForId(objectId.id()); |
| 389 } | 396 } |
| 390 | 397 |
| 391 String InjectedScript::objectIdToObjectGroupName(const String& objectId) const | 398 String InjectedScript::objectIdToObjectGroupName(const String& objectId) const |
| 392 { | 399 { |
| 393 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); | 400 RefPtr<JSONValue> parsedObjectId = parseJSON(objectId); |
| 394 if (!parsedObjectId) | 401 if (!parsedObjectId) |
| 395 return String(); | 402 return String(); |
| 396 RefPtr<JSONObject> object; | 403 RefPtr<JSONObject> object; |
| 397 if (!parsedObjectId->asObject(&object)) | 404 if (!parsedObjectId->asObject(&object)) |
| 398 return String(); | 405 return String(); |
| 399 int boundId = 0; | 406 int boundId = 0; |
| 400 if (!object->getNumber("id", &boundId)) | 407 if (!object->getNumber("id", &boundId)) |
| 401 return String(); | 408 return String(); |
| 402 return m_native->groupName(boundId); | 409 return m_native->groupName(boundId); |
| 403 } | 410 } |
| 404 | 411 |
| 405 void InjectedScript::releaseObjectGroup(const String& objectGroup) | 412 void InjectedScript::releaseObjectGroup(const String& objectGroup) |
| 406 { | 413 { |
| 407 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 414 v8::HandleScope handles(m_isolate); |
| 408 m_native->releaseObjectGroup(objectGroup); | 415 m_native->releaseObjectGroup(objectGroup); |
| 409 if (objectGroup == "console") { | 416 if (objectGroup == "console") { |
| 410 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "clearLast EvaluationResult"); | 417 ScriptFunctionCall function(m_client, context(), v8Value(), "clearLastEv aluationResult"); |
| 411 bool hadException = false; | 418 bool hadException = false; |
| 412 callFunctionWithEvalEnabled(function, hadException); | 419 callFunctionWithEvalEnabled(function, hadException); |
| 413 ASSERT(!hadException); | 420 ASSERT(!hadException); |
| 414 } | 421 } |
| 415 } | 422 } |
| 416 | 423 |
| 417 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) | 424 void InjectedScript::setCustomObjectFormatterEnabled(bool enabled) |
| 418 { | 425 { |
| 419 ScriptState::Scope scope(m_injectedScriptObject.scriptState()); | 426 v8::HandleScope handles(m_isolate); |
| 420 ScriptFunctionCall function(m_client, v8Context(), v8Value(), "setCustomObje ctFormatterEnabled"); | 427 ScriptFunctionCall function(m_client, context(), v8Value(), "setCustomObject FormatterEnabled"); |
| 421 function.appendArgument(enabled); | 428 function.appendArgument(enabled); |
| 422 RefPtr<JSONValue> result; | 429 RefPtr<JSONValue> result; |
| 423 makeCall(function, &result); | 430 makeCall(function, &result); |
| 424 } | 431 } |
| 425 | 432 |
| 426 bool InjectedScript::canAccessInspectedWindow() const | 433 bool InjectedScript::canAccessInspectedWindow() const |
| 427 { | 434 { |
| 428 ScriptState* scriptState = m_injectedScriptObject.scriptState(); | 435 v8::Local<v8::Context> callingContext = m_isolate->GetCallingContext(); |
| 429 return scriptState && m_client->callingContextCanAccessContext(scriptState-> context()); | 436 if (callingContext.IsEmpty()) |
| 437 return true; | |
| 438 return m_client->callingContextCanAccessContext(callingContext, context()); | |
| 430 } | 439 } |
| 431 | 440 |
| 432 v8::Local<v8::Context> InjectedScript::v8Context() const | 441 v8::Local<v8::Context> InjectedScript::context() const |
| 433 { | 442 { |
| 434 return m_injectedScriptObject.context(); | 443 return m_context.Get(m_isolate); |
| 435 } | 444 } |
| 436 | 445 |
| 437 v8::Local<v8::Value> InjectedScript::v8Value() const | 446 v8::Local<v8::Value> InjectedScript::v8Value() const |
| 438 { | 447 { |
| 439 return m_injectedScriptObject.v8Value(); | 448 return m_value.Get(m_isolate); |
| 440 } | 449 } |
| 441 | 450 |
| 442 v8::Local<v8::Value> InjectedScript::callFunctionWithEvalEnabled(ScriptFunctionC all& function, bool& hadException) const | 451 v8::Local<v8::Value> InjectedScript::callFunctionWithEvalEnabled(ScriptFunctionC all& function, bool& hadException) const |
| 443 { | 452 { |
| 444 v8::Local<v8::Context> context = v8Context(); | 453 v8::Local<v8::Context> localContext = context(); |
| 445 bool evalIsDisabled = !context->IsCodeGenerationFromStringsAllowed(); | 454 v8::Context::Scope scope(localContext); |
| 455 bool evalIsDisabled = !localContext->IsCodeGenerationFromStringsAllowed(); | |
| 446 // Temporarily enable allow evals for inspector. | 456 // Temporarily enable allow evals for inspector. |
| 447 if (evalIsDisabled) | 457 if (evalIsDisabled) |
| 448 context->AllowCodeGenerationFromStrings(true); | 458 localContext->AllowCodeGenerationFromStrings(true); |
| 449 v8::Local<v8::Value> resultValue = function.call(hadException); | 459 v8::Local<v8::Value> resultValue = function.call(hadException); |
| 450 if (evalIsDisabled) | 460 if (evalIsDisabled) |
| 451 context->AllowCodeGenerationFromStrings(false); | 461 localContext->AllowCodeGenerationFromStrings(false); |
| 452 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( )); | 462 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Update Counters", TRACE_EVENT_SCOPE_THREAD, "data", InspectorUpdateCountersEvent::data( )); |
| 453 return resultValue; | 463 return resultValue; |
| 454 } | 464 } |
| 455 | 465 |
| 456 void InjectedScript::makeCall(ScriptFunctionCall& function, RefPtr<JSONValue>* r esult) | 466 void InjectedScript::makeCall(ScriptFunctionCall& function, RefPtr<JSONValue>* r esult) |
| 457 { | 467 { |
| 458 if (!canAccessInspectedWindow()) { | 468 if (!canAccessInspectedWindow()) { |
| 459 *result = JSONValue::null(); | 469 *result = JSONString::create("Can not access given context."); |
| 460 return; | 470 return; |
| 461 } | 471 } |
| 472 v8::TryCatch tryCatch(m_isolate); | |
|
dgozman
2016/01/27 22:05:47
Why this?
pfeldman
2016/01/27 22:15:45
I have no idea. I pasted it or multiple cursors of
| |
| 462 | 473 |
| 463 bool hadException = false; | 474 bool hadException = false; |
| 464 v8::Local<v8::Value> resultValue = callFunctionWithEvalEnabled(function, had Exception); | 475 v8::Local<v8::Value> resultValue = callFunctionWithEvalEnabled(function, had Exception); |
| 465 | 476 |
| 466 ASSERT(!hadException); | 477 ASSERT(!hadException); |
| 467 if (!hadException) { | 478 if (!hadException) { |
| 468 *result = toJSONValue(function.context(), resultValue); | 479 *result = toJSONValue(function.context(), resultValue); |
| 469 if (!*result) | 480 if (!*result) |
| 470 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); | 481 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); |
| 471 } else { | 482 } else { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 void InjectedScript::makeCallWithExceptionDetails(ScriptFunctionCall& function, RefPtr<JSONValue>* result, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* exce ptionDetails) | 520 void InjectedScript::makeCallWithExceptionDetails(ScriptFunctionCall& function, RefPtr<JSONValue>* result, RefPtr<TypeBuilder::Debugger::ExceptionDetails>* exce ptionDetails) |
| 510 { | 521 { |
| 511 v8::TryCatch tryCatch(m_isolate); | 522 v8::TryCatch tryCatch(m_isolate); |
| 512 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); | 523 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); |
| 513 if (tryCatch.HasCaught()) { | 524 if (tryCatch.HasCaught()) { |
| 514 v8::Local<v8::Message> message = tryCatch.Message(); | 525 v8::Local<v8::Message> message = tryCatch.Message(); |
| 515 String text = !message.IsEmpty() ? toCoreStringWithUndefinedOrNullCheck( message->Get()) : "Internal error"; | 526 String text = !message.IsEmpty() ? toCoreStringWithUndefinedOrNullCheck( message->Get()) : "Internal error"; |
| 516 *exceptionDetails = TypeBuilder::Debugger::ExceptionDetails::create().se tText(text); | 527 *exceptionDetails = TypeBuilder::Debugger::ExceptionDetails::create().se tText(text); |
| 517 } else { | 528 } else { |
| 518 *result = toJSONValue(function.context(), resultValue); | 529 *result = toJSONValue(function.context(), resultValue); |
| 519 if (!*result) | 530 if (!*result) { |
|
dgozman
2016/01/27 22:05:47
extra {}
pfeldman
2016/01/27 22:15:45
Done.
| |
| 520 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); | 531 *result = JSONString::create(String::format("Object has too long ref erence chain(must not be longer than %d)", JSONValue::maxDepth)); |
| 532 } | |
| 521 } | 533 } |
| 522 } | 534 } |
| 523 | 535 |
| 536 void InjectedScript::dispose() | |
| 537 { | |
| 538 m_manager->discardInjectedScript(m_contextId); | |
| 539 } | |
| 540 | |
| 524 } // namespace blink | 541 } // namespace blink |
| OLD | NEW |