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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 InjectedScript::~InjectedScript() {} | 120 InjectedScript::~InjectedScript() {} |
121 | 121 |
122 void InjectedScript::getProperties( | 122 void InjectedScript::getProperties( |
123 ErrorString* errorString, v8::Local<v8::Object> object, | 123 ErrorString* errorString, v8::Local<v8::Object> object, |
124 const String16& groupName, bool ownProperties, bool accessorPropertiesOnly, | 124 const String16& groupName, bool ownProperties, bool accessorPropertiesOnly, |
125 bool generatePreview, | 125 bool generatePreview, |
126 std::unique_ptr<Array<PropertyDescriptor>>* properties, | 126 std::unique_ptr<Array<PropertyDescriptor>>* properties, |
127 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { | 127 Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) { |
128 v8::HandleScope handles(m_context->isolate()); | 128 v8::HandleScope handles(m_context->isolate()); |
| 129 v8::Local<v8::Context> context = m_context->context(); |
129 V8FunctionCall function(m_context->inspector(), m_context->context(), | 130 V8FunctionCall function(m_context->inspector(), m_context->context(), |
130 v8Value(), "getProperties"); | 131 v8Value(), "getProperties"); |
131 function.appendArgument(object); | 132 function.appendArgument(object); |
132 function.appendArgument(groupName); | 133 function.appendArgument(groupName); |
133 function.appendArgument(ownProperties); | 134 function.appendArgument(ownProperties); |
134 function.appendArgument(accessorPropertiesOnly); | 135 function.appendArgument(accessorPropertiesOnly); |
135 function.appendArgument(generatePreview); | 136 function.appendArgument(generatePreview); |
136 | 137 |
137 v8::TryCatch tryCatch(m_context->isolate()); | 138 v8::TryCatch tryCatch(m_context->isolate()); |
138 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); | 139 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); |
139 if (tryCatch.HasCaught()) { | 140 if (tryCatch.HasCaught()) { |
140 *exceptionDetails = createExceptionDetails(errorString, tryCatch, groupName, | 141 *exceptionDetails = createExceptionDetails(errorString, tryCatch, groupName, |
141 generatePreview); | 142 generatePreview); |
142 // FIXME: make properties optional | 143 // FIXME: make properties optional |
143 *properties = Array<PropertyDescriptor>::create(); | 144 *properties = Array<PropertyDescriptor>::create(); |
144 return; | 145 return; |
145 } | 146 } |
146 | 147 |
147 std::unique_ptr<protocol::Value> protocolValue = | 148 std::unique_ptr<protocol::Value> protocolValue = |
148 toProtocolValue(m_context->context(), resultValue); | 149 toProtocolValue(context, resultValue); |
149 if (hasInternalError(errorString, !protocolValue)) return; | 150 if (hasInternalError(errorString, !protocolValue)) return; |
150 protocol::ErrorSupport errors(errorString); | 151 protocol::ErrorSupport errors(errorString); |
151 std::unique_ptr<Array<PropertyDescriptor>> result = | 152 std::unique_ptr<Array<PropertyDescriptor>> result = |
152 Array<PropertyDescriptor>::parse(protocolValue.get(), &errors); | 153 Array<PropertyDescriptor>::parse(protocolValue.get(), &errors); |
153 if (!hasInternalError(errorString, errors.hasErrors())) | 154 if (!hasInternalError(errorString, errors.hasErrors())) |
154 *properties = std::move(result); | 155 *properties = std::move(result); |
155 } | 156 } |
156 | 157 |
157 void InjectedScript::releaseObject(const String16& objectId) { | 158 void InjectedScript::releaseObject(const String16& objectId) { |
158 std::unique_ptr<protocol::Value> parsedObjectId = | 159 std::unique_ptr<protocol::Value> parsedObjectId = |
159 protocol::parseJSON(objectId); | 160 protocol::parseJSON(objectId); |
160 if (!parsedObjectId) return; | 161 if (!parsedObjectId) return; |
161 protocol::DictionaryValue* object = | 162 protocol::DictionaryValue* object = |
162 protocol::DictionaryValue::cast(parsedObjectId.get()); | 163 protocol::DictionaryValue::cast(parsedObjectId.get()); |
163 if (!object) return; | 164 if (!object) return; |
164 int boundId = 0; | 165 int boundId = 0; |
165 if (!object->getInteger("id", &boundId)) return; | 166 if (!object->getInteger("id", &boundId)) return; |
166 m_native->unbind(boundId); | 167 m_native->unbind(boundId); |
167 } | 168 } |
168 | 169 |
169 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject( | 170 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject( |
170 ErrorString* errorString, v8::Local<v8::Value> value, | 171 ErrorString* errorString, v8::Local<v8::Value> value, |
171 const String16& groupName, bool forceValueType, | 172 const String16& groupName, bool forceValueType, |
172 bool generatePreview) const { | 173 bool generatePreview) const { |
173 v8::HandleScope handles(m_context->isolate()); | 174 v8::HandleScope handles(m_context->isolate()); |
174 v8::Local<v8::Value> wrappedObject; | 175 v8::Local<v8::Value> wrappedObject; |
| 176 v8::Local<v8::Context> context = m_context->context(); |
175 if (!wrapValue(errorString, value, groupName, forceValueType, generatePreview) | 177 if (!wrapValue(errorString, value, groupName, forceValueType, generatePreview) |
176 .ToLocal(&wrappedObject)) | 178 .ToLocal(&wrappedObject)) |
177 return nullptr; | 179 return nullptr; |
178 protocol::ErrorSupport errors; | 180 protocol::ErrorSupport errors; |
179 std::unique_ptr<protocol::Runtime::RemoteObject> remoteObject = | 181 std::unique_ptr<protocol::Runtime::RemoteObject> remoteObject = |
180 protocol::Runtime::RemoteObject::parse( | 182 protocol::Runtime::RemoteObject::parse( |
181 toProtocolValue(m_context->context(), wrappedObject).get(), &errors); | 183 toProtocolValue(context, wrappedObject).get(), &errors); |
182 if (!remoteObject) *errorString = "Object has too long reference chain"; | 184 if (!remoteObject) *errorString = "Object has too long reference chain"; |
183 return remoteObject; | 185 return remoteObject; |
184 } | 186 } |
185 | 187 |
186 bool InjectedScript::wrapObjectProperty(ErrorString* errorString, | 188 bool InjectedScript::wrapObjectProperty(ErrorString* errorString, |
187 v8::Local<v8::Object> object, | 189 v8::Local<v8::Object> object, |
188 v8::Local<v8::Name> key, | 190 v8::Local<v8::Name> key, |
189 const String16& groupName, | 191 const String16& groupName, |
190 bool forceValueType, | 192 bool forceValueType, |
191 bool generatePreview) const { | 193 bool generatePreview) const { |
192 v8::Local<v8::Value> property; | 194 v8::Local<v8::Value> property; |
193 if (hasInternalError( | 195 v8::Local<v8::Context> context = m_context->context(); |
194 errorString, | 196 if (hasInternalError(errorString, |
195 !object->Get(m_context->context(), key).ToLocal(&property))) | 197 !object->Get(context, key).ToLocal(&property))) |
196 return false; | 198 return false; |
197 v8::Local<v8::Value> wrappedProperty; | 199 v8::Local<v8::Value> wrappedProperty; |
198 if (!wrapValue(errorString, property, groupName, forceValueType, | 200 if (!wrapValue(errorString, property, groupName, forceValueType, |
199 generatePreview) | 201 generatePreview) |
200 .ToLocal(&wrappedProperty)) | 202 .ToLocal(&wrappedProperty)) |
201 return false; | 203 return false; |
202 v8::Maybe<bool> success = | 204 v8::Maybe<bool> success = |
203 createDataProperty(m_context->context(), object, key, wrappedProperty); | 205 createDataProperty(context, object, key, wrappedProperty); |
204 if (hasInternalError(errorString, success.IsNothing() || !success.FromJust())) | 206 if (hasInternalError(errorString, success.IsNothing() || !success.FromJust())) |
205 return false; | 207 return false; |
206 return true; | 208 return true; |
207 } | 209 } |
208 | 210 |
209 bool InjectedScript::wrapPropertyInArray(ErrorString* errorString, | 211 bool InjectedScript::wrapPropertyInArray(ErrorString* errorString, |
210 v8::Local<v8::Array> array, | 212 v8::Local<v8::Array> array, |
211 v8::Local<v8::String> property, | 213 v8::Local<v8::String> property, |
212 const String16& groupName, | 214 const String16& groupName, |
213 bool forceValueType, | 215 bool forceValueType, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 bool hadException = false; | 255 bool hadException = false; |
254 v8::Local<v8::Value> r = function.call(hadException); | 256 v8::Local<v8::Value> r = function.call(hadException); |
255 if (hasInternalError(errorString, hadException || r.IsEmpty())) | 257 if (hasInternalError(errorString, hadException || r.IsEmpty())) |
256 return v8::MaybeLocal<v8::Value>(); | 258 return v8::MaybeLocal<v8::Value>(); |
257 return r; | 259 return r; |
258 } | 260 } |
259 | 261 |
260 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable( | 262 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable( |
261 v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const { | 263 v8::Local<v8::Value> table, v8::Local<v8::Value> columns) const { |
262 v8::HandleScope handles(m_context->isolate()); | 264 v8::HandleScope handles(m_context->isolate()); |
263 V8FunctionCall function(m_context->inspector(), m_context->context(), | 265 v8::Local<v8::Context> context = m_context->context(); |
264 v8Value(), "wrapTable"); | 266 V8FunctionCall function(m_context->inspector(), context, v8Value(), |
| 267 "wrapTable"); |
265 function.appendArgument(table); | 268 function.appendArgument(table); |
266 if (columns.IsEmpty()) | 269 if (columns.IsEmpty()) |
267 function.appendArgument(false); | 270 function.appendArgument(false); |
268 else | 271 else |
269 function.appendArgument(columns); | 272 function.appendArgument(columns); |
270 bool hadException = false; | 273 bool hadException = false; |
271 v8::Local<v8::Value> r = function.call(hadException); | 274 v8::Local<v8::Value> r = function.call(hadException); |
272 if (hadException) return nullptr; | 275 if (hadException) return nullptr; |
273 protocol::ErrorSupport errors; | 276 protocol::ErrorSupport errors; |
274 return protocol::Runtime::RemoteObject::parse( | 277 return protocol::Runtime::RemoteObject::parse( |
275 toProtocolValue(m_context->context(), r).get(), &errors); | 278 toProtocolValue(context, r).get(), &errors); |
276 } | 279 } |
277 | 280 |
278 bool InjectedScript::findObject(ErrorString* errorString, | 281 bool InjectedScript::findObject(ErrorString* errorString, |
279 const RemoteObjectId& objectId, | 282 const RemoteObjectId& objectId, |
280 v8::Local<v8::Value>* outObject) const { | 283 v8::Local<v8::Value>* outObject) const { |
281 *outObject = m_native->objectForId(objectId.id()); | 284 *outObject = m_native->objectForId(objectId.id()); |
282 if (outObject->IsEmpty()) | 285 if (outObject->IsEmpty()) |
283 *errorString = "Could not find object with given id"; | 286 *errorString = "Could not find object with given id"; |
284 return !outObject->IsEmpty(); | 287 return !outObject->IsEmpty(); |
285 } | 288 } |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 void InjectedScript::CallFrameScope::findInjectedScript( | 562 void InjectedScript::CallFrameScope::findInjectedScript( |
560 V8InspectorSessionImpl* session) { | 563 V8InspectorSessionImpl* session) { |
561 std::unique_ptr<RemoteCallFrameId> remoteId = | 564 std::unique_ptr<RemoteCallFrameId> remoteId = |
562 RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId); | 565 RemoteCallFrameId::parse(m_errorString, m_remoteCallFrameId); |
563 if (!remoteId) return; | 566 if (!remoteId) return; |
564 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); | 567 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); |
565 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()); | 568 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()); |
566 } | 569 } |
567 | 570 |
568 } // namespace v8_inspector | 571 } // namespace v8_inspector |
OLD | NEW |