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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 { | 101 { |
102 } | 102 } |
103 | 103 |
104 InjectedScript::~InjectedScript() | 104 InjectedScript::~InjectedScript() |
105 { | 105 { |
106 } | 106 } |
107 | 107 |
108 void InjectedScript::getProperties(ErrorString* errorString, v8::Local<v8::Objec
t> object, const String16& groupName, bool ownProperties, bool accessorPropertie
sOnly, bool generatePreview, std::unique_ptr<Array<PropertyDescriptor>>* propert
ies, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) | 108 void InjectedScript::getProperties(ErrorString* errorString, v8::Local<v8::Objec
t> object, const String16& groupName, bool ownProperties, bool accessorPropertie
sOnly, bool generatePreview, std::unique_ptr<Array<PropertyDescriptor>>* propert
ies, Maybe<protocol::Runtime::ExceptionDetails>* exceptionDetails) |
109 { | 109 { |
110 v8::HandleScope handles(m_context->isolate()); | 110 v8::HandleScope handles(m_context->isolate()); |
| 111 v8::Local<v8::Context> context = m_context->context(); |
111 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "getProperties"); | 112 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "getProperties"); |
112 function.appendArgument(object); | 113 function.appendArgument(object); |
113 function.appendArgument(groupName); | 114 function.appendArgument(groupName); |
114 function.appendArgument(ownProperties); | 115 function.appendArgument(ownProperties); |
115 function.appendArgument(accessorPropertiesOnly); | 116 function.appendArgument(accessorPropertiesOnly); |
116 function.appendArgument(generatePreview); | 117 function.appendArgument(generatePreview); |
117 | 118 |
118 v8::TryCatch tryCatch(m_context->isolate()); | 119 v8::TryCatch tryCatch(m_context->isolate()); |
119 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); | 120 v8::Local<v8::Value> resultValue = function.callWithoutExceptionHandling(); |
120 if (tryCatch.HasCaught()) { | 121 if (tryCatch.HasCaught()) { |
121 *exceptionDetails = createExceptionDetails(errorString, tryCatch, groupN
ame, generatePreview); | 122 *exceptionDetails = createExceptionDetails(errorString, tryCatch, groupN
ame, generatePreview); |
122 // FIXME: make properties optional | 123 // FIXME: make properties optional |
123 *properties = Array<PropertyDescriptor>::create(); | 124 *properties = Array<PropertyDescriptor>::create(); |
124 return; | 125 return; |
125 } | 126 } |
126 | 127 |
127 std::unique_ptr<protocol::Value> protocolValue = toProtocolValue(m_context->
context(), resultValue); | 128 std::unique_ptr<protocol::Value> protocolValue = toProtocolValue(context, re
sultValue); |
128 if (hasInternalError(errorString, !protocolValue)) | 129 if (hasInternalError(errorString, !protocolValue)) |
129 return; | 130 return; |
130 protocol::ErrorSupport errors(errorString); | 131 protocol::ErrorSupport errors(errorString); |
131 std::unique_ptr<Array<PropertyDescriptor>> result = Array<PropertyDescriptor
>::parse(protocolValue.get(), &errors); | 132 std::unique_ptr<Array<PropertyDescriptor>> result = Array<PropertyDescriptor
>::parse(protocolValue.get(), &errors); |
132 if (!hasInternalError(errorString, errors.hasErrors())) | 133 if (!hasInternalError(errorString, errors.hasErrors())) |
133 *properties = std::move(result); | 134 *properties = std::move(result); |
134 } | 135 } |
135 | 136 |
136 void InjectedScript::releaseObject(const String16& objectId) | 137 void InjectedScript::releaseObject(const String16& objectId) |
137 { | 138 { |
138 std::unique_ptr<protocol::Value> parsedObjectId = protocol::parseJSON(object
Id); | 139 std::unique_ptr<protocol::Value> parsedObjectId = protocol::parseJSON(object
Id); |
139 if (!parsedObjectId) | 140 if (!parsedObjectId) |
140 return; | 141 return; |
141 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb
jectId.get()); | 142 protocol::DictionaryValue* object = protocol::DictionaryValue::cast(parsedOb
jectId.get()); |
142 if (!object) | 143 if (!object) |
143 return; | 144 return; |
144 int boundId = 0; | 145 int boundId = 0; |
145 if (!object->getInteger("id", &boundId)) | 146 if (!object->getInteger("id", &boundId)) |
146 return; | 147 return; |
147 m_native->unbind(boundId); | 148 m_native->unbind(boundId); |
148 } | 149 } |
149 | 150 |
150 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(Erro
rString* errorString, v8::Local<v8::Value> value, const String16& groupName, boo
l forceValueType, bool generatePreview) const | 151 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapObject(Erro
rString* errorString, v8::Local<v8::Value> value, const String16& groupName, boo
l forceValueType, bool generatePreview) const |
151 { | 152 { |
152 v8::HandleScope handles(m_context->isolate()); | 153 v8::HandleScope handles(m_context->isolate()); |
153 v8::Local<v8::Value> wrappedObject; | 154 v8::Local<v8::Value> wrappedObject; |
| 155 v8::Local<v8::Context> context = m_context->context(); |
154 if (!wrapValue(errorString, value, groupName, forceValueType, generatePrevie
w).ToLocal(&wrappedObject)) | 156 if (!wrapValue(errorString, value, groupName, forceValueType, generatePrevie
w).ToLocal(&wrappedObject)) |
155 return nullptr; | 157 return nullptr; |
156 protocol::ErrorSupport errors; | 158 protocol::ErrorSupport errors; |
157 std::unique_ptr<protocol::Runtime::RemoteObject> remoteObject = protocol::Ru
ntime::RemoteObject::parse(toProtocolValue(m_context->context(), wrappedObject).
get(), &errors); | 159 std::unique_ptr<protocol::Runtime::RemoteObject> remoteObject = protocol::Ru
ntime::RemoteObject::parse(toProtocolValue(context, wrappedObject).get(), &error
s); |
158 if (!remoteObject) | 160 if (!remoteObject) |
159 *errorString = "Object has too long reference chain"; | 161 *errorString = "Object has too long reference chain"; |
160 return remoteObject; | 162 return remoteObject; |
161 } | 163 } |
162 | 164 |
163 bool InjectedScript::wrapObjectProperty(ErrorString* errorString, v8::Local<v8::
Object> object, v8::Local<v8::Name> key, const String16& groupName, bool forceVa
lueType, bool generatePreview) const | 165 bool InjectedScript::wrapObjectProperty(ErrorString* errorString, v8::Local<v8::
Object> object, v8::Local<v8::Name> key, const String16& groupName, bool forceVa
lueType, bool generatePreview) const |
164 { | 166 { |
165 v8::Local<v8::Value> property; | 167 v8::Local<v8::Value> property; |
166 if (hasInternalError(errorString, !object->Get(m_context->context(), key).To
Local(&property))) | 168 v8::Local<v8::Context> context = m_context->context(); |
| 169 if (hasInternalError(errorString, !object->Get(context, key).ToLocal(&proper
ty))) |
167 return false; | 170 return false; |
168 v8::Local<v8::Value> wrappedProperty; | 171 v8::Local<v8::Value> wrappedProperty; |
169 if (!wrapValue(errorString, property, groupName, forceValueType, generatePre
view).ToLocal(&wrappedProperty)) | 172 if (!wrapValue(errorString, property, groupName, forceValueType, generatePre
view).ToLocal(&wrappedProperty)) |
170 return false; | 173 return false; |
171 v8::Maybe<bool> success = createDataProperty(m_context->context(), object, k
ey, wrappedProperty); | 174 v8::Maybe<bool> success = createDataProperty(context, object, key, wrappedPr
operty); |
172 if (hasInternalError(errorString, success.IsNothing() || !success.FromJust()
)) | 175 if (hasInternalError(errorString, success.IsNothing() || !success.FromJust()
)) |
173 return false; | 176 return false; |
174 return true; | 177 return true; |
175 } | 178 } |
176 | 179 |
177 bool InjectedScript::wrapPropertyInArray(ErrorString* errorString, v8::Local<v8:
:Array> array, v8::Local<v8::String> property, const String16& groupName, bool f
orceValueType, bool generatePreview) const | 180 bool InjectedScript::wrapPropertyInArray(ErrorString* errorString, v8::Local<v8:
:Array> array, v8::Local<v8::String> property, const String16& groupName, bool f
orceValueType, bool generatePreview) const |
178 { | 181 { |
179 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "wrapPropertyInArray"); | 182 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "wrapPropertyInArray"); |
180 function.appendArgument(array); | 183 function.appendArgument(array); |
181 function.appendArgument(property); | 184 function.appendArgument(property); |
(...skipping 27 matching lines...) Expand all Loading... |
209 bool hadException = false; | 212 bool hadException = false; |
210 v8::Local<v8::Value> r = function.call(hadException); | 213 v8::Local<v8::Value> r = function.call(hadException); |
211 if (hasInternalError(errorString, hadException || r.IsEmpty())) | 214 if (hasInternalError(errorString, hadException || r.IsEmpty())) |
212 return v8::MaybeLocal<v8::Value>(); | 215 return v8::MaybeLocal<v8::Value>(); |
213 return r; | 216 return r; |
214 } | 217 } |
215 | 218 |
216 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::L
ocal<v8::Value> table, v8::Local<v8::Value> columns) const | 219 std::unique_ptr<protocol::Runtime::RemoteObject> InjectedScript::wrapTable(v8::L
ocal<v8::Value> table, v8::Local<v8::Value> columns) const |
217 { | 220 { |
218 v8::HandleScope handles(m_context->isolate()); | 221 v8::HandleScope handles(m_context->isolate()); |
219 V8FunctionCall function(m_context->inspector(), m_context->context(), v8Valu
e(), "wrapTable"); | 222 v8::Local<v8::Context> context = m_context->context(); |
| 223 V8FunctionCall function(m_context->inspector(), context, v8Value(), "wrapTab
le"); |
220 function.appendArgument(table); | 224 function.appendArgument(table); |
221 if (columns.IsEmpty()) | 225 if (columns.IsEmpty()) |
222 function.appendArgument(false); | 226 function.appendArgument(false); |
223 else | 227 else |
224 function.appendArgument(columns); | 228 function.appendArgument(columns); |
225 bool hadException = false; | 229 bool hadException = false; |
226 v8::Local<v8::Value> r = function.call(hadException); | 230 v8::Local<v8::Value> r = function.call(hadException); |
227 if (hadException) | 231 if (hadException) |
228 return nullptr; | 232 return nullptr; |
229 protocol::ErrorSupport errors; | 233 protocol::ErrorSupport errors; |
230 return protocol::Runtime::RemoteObject::parse(toProtocolValue(m_context->con
text(), r).get(), &errors); | 234 return protocol::Runtime::RemoteObject::parse(toProtocolValue(context, r).ge
t(), &errors); |
231 } | 235 } |
232 | 236 |
233 bool InjectedScript::findObject(ErrorString* errorString, const RemoteObjectId&
objectId, v8::Local<v8::Value>* outObject) const | 237 bool InjectedScript::findObject(ErrorString* errorString, const RemoteObjectId&
objectId, v8::Local<v8::Value>* outObject) const |
234 { | 238 { |
235 *outObject = m_native->objectForId(objectId.id()); | 239 *outObject = m_native->objectForId(objectId.id()); |
236 if (outObject->IsEmpty()) | 240 if (outObject->IsEmpty()) |
237 *errorString = "Could not find object with given id"; | 241 *errorString = "Could not find object with given id"; |
238 return !outObject->IsEmpty(); | 242 return !outObject->IsEmpty(); |
239 } | 243 } |
240 | 244 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl*
session) | 499 void InjectedScript::CallFrameScope::findInjectedScript(V8InspectorSessionImpl*
session) |
496 { | 500 { |
497 std::unique_ptr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_err
orString, m_remoteCallFrameId); | 501 std::unique_ptr<RemoteCallFrameId> remoteId = RemoteCallFrameId::parse(m_err
orString, m_remoteCallFrameId); |
498 if (!remoteId) | 502 if (!remoteId) |
499 return; | 503 return; |
500 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); | 504 m_frameOrdinal = static_cast<size_t>(remoteId->frameOrdinal()); |
501 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()
); | 505 m_injectedScript = session->findInjectedScript(m_errorString, remoteId.get()
); |
502 } | 506 } |
503 | 507 |
504 } // namespace v8_inspector | 508 } // namespace v8_inspector |
OLD | NEW |