| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/v8_inspector/V8InjectedScriptHost.h" | 5 #include "platform/v8_inspector/V8InjectedScriptHost.h" |
| 6 | 6 |
| 7 #include "platform/inspector_protocol/String16.h" | 7 #include "platform/inspector_protocol/String16.h" |
| 8 #include "platform/v8_inspector/InjectedScriptNative.h" | 8 #include "platform/v8_inspector/InjectedScriptNative.h" |
| 9 #include "platform/v8_inspector/V8Compat.h" | 9 #include "platform/v8_inspector/V8Compat.h" |
| 10 #include "platform/v8_inspector/V8DebuggerImpl.h" | 10 #include "platform/v8_inspector/V8DebuggerImpl.h" |
| 11 #include "platform/v8_inspector/V8StringUtil.h" | 11 #include "platform/v8_inspector/V8StringUtil.h" |
| 12 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 12 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
| 13 #include "platform/v8_inspector/public/V8EventListenerInfo.h" | |
| 14 | 13 |
| 15 namespace blink { | 14 namespace blink { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 void setFunctionProperty(v8::Local<v8::Context> context, v8::Local<v8::Object> o
bj, const char* name, v8::FunctionCallback callback, v8::Local<v8::External> ext
ernal) | 18 void setFunctionProperty(v8::Local<v8::Context> context, v8::Local<v8::Object> o
bj, const char* name, v8::FunctionCallback callback, v8::Local<v8::External> ext
ernal) |
| 20 { | 19 { |
| 21 v8::Local<v8::String> funcName = toV8StringInternalized(context->GetIsolate(
), name); | 20 v8::Local<v8::String> funcName = toV8StringInternalized(context->GetIsolate(
), name); |
| 22 v8::Local<v8::Function> func; | 21 v8::Local<v8::Function> func; |
| 23 if (!v8::Function::New(context, callback, external).ToLocal(&func)) | 22 if (!v8::Function::New(context, callback, external).ToLocal(&func)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 42 { | 41 { |
| 43 v8::Isolate* isolate = debugger->isolate(); | 42 v8::Isolate* isolate = debugger->isolate(); |
| 44 v8::Local<v8::Object> injectedScriptHost = v8::Object::New(isolate); | 43 v8::Local<v8::Object> injectedScriptHost = v8::Object::New(isolate); |
| 45 v8::Local<v8::External> debuggerExternal = v8::External::New(isolate, debugg
er); | 44 v8::Local<v8::External> debuggerExternal = v8::External::New(isolate, debugg
er); |
| 46 setFunctionProperty(context, injectedScriptHost, "internalConstructorName",
V8InjectedScriptHost::internalConstructorNameCallback, debuggerExternal); | 45 setFunctionProperty(context, injectedScriptHost, "internalConstructorName",
V8InjectedScriptHost::internalConstructorNameCallback, debuggerExternal); |
| 47 setFunctionProperty(context, injectedScriptHost, "formatAccessorsAsPropertie
s", V8InjectedScriptHost::formatAccessorsAsProperties, debuggerExternal); | 46 setFunctionProperty(context, injectedScriptHost, "formatAccessorsAsPropertie
s", V8InjectedScriptHost::formatAccessorsAsProperties, debuggerExternal); |
| 48 setFunctionProperty(context, injectedScriptHost, "isTypedArray", V8InjectedS
criptHost::isTypedArrayCallback, debuggerExternal); | 47 setFunctionProperty(context, injectedScriptHost, "isTypedArray", V8InjectedS
criptHost::isTypedArrayCallback, debuggerExternal); |
| 49 setFunctionProperty(context, injectedScriptHost, "subtype", V8InjectedScript
Host::subtypeCallback, debuggerExternal); | 48 setFunctionProperty(context, injectedScriptHost, "subtype", V8InjectedScript
Host::subtypeCallback, debuggerExternal); |
| 50 setFunctionProperty(context, injectedScriptHost, "collectionEntries", V8Inje
ctedScriptHost::collectionEntriesCallback, debuggerExternal); | 49 setFunctionProperty(context, injectedScriptHost, "collectionEntries", V8Inje
ctedScriptHost::collectionEntriesCallback, debuggerExternal); |
| 51 setFunctionProperty(context, injectedScriptHost, "getInternalProperties", V8
InjectedScriptHost::getInternalPropertiesCallback, debuggerExternal); | 50 setFunctionProperty(context, injectedScriptHost, "getInternalProperties", V8
InjectedScriptHost::getInternalPropertiesCallback, debuggerExternal); |
| 52 setFunctionProperty(context, injectedScriptHost, "getEventListeners", V8Inje
ctedScriptHost::getEventListenersCallback, debuggerExternal); | |
| 53 setFunctionProperty(context, injectedScriptHost, "suppressWarningsAndCallFun
ction", V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback, debuggerE
xternal); | 51 setFunctionProperty(context, injectedScriptHost, "suppressWarningsAndCallFun
ction", V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback, debuggerE
xternal); |
| 54 setFunctionProperty(context, injectedScriptHost, "setNonEnumProperty", V8Inj
ectedScriptHost::setNonEnumPropertyCallback, debuggerExternal); | 52 setFunctionProperty(context, injectedScriptHost, "setNonEnumProperty", V8Inj
ectedScriptHost::setNonEnumPropertyCallback, debuggerExternal); |
| 55 setFunctionProperty(context, injectedScriptHost, "bind", V8InjectedScriptHos
t::bindCallback, debuggerExternal); | 53 setFunctionProperty(context, injectedScriptHost, "bind", V8InjectedScriptHos
t::bindCallback, debuggerExternal); |
| 56 setFunctionProperty(context, injectedScriptHost, "proxyTargetValue", V8Injec
tedScriptHost::proxyTargetValueCallback, debuggerExternal); | 54 setFunctionProperty(context, injectedScriptHost, "proxyTargetValue", V8Injec
tedScriptHost::proxyTargetValueCallback, debuggerExternal); |
| 57 setFunctionProperty(context, injectedScriptHost, "prototype", V8InjectedScri
ptHost::prototypeCallback, debuggerExternal); | 55 setFunctionProperty(context, injectedScriptHost, "prototype", V8InjectedScri
ptHost::prototypeCallback, debuggerExternal); |
| 58 return injectedScriptHost; | 56 return injectedScriptHost; |
| 59 } | 57 } |
| 60 | 58 |
| 61 void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal
lbackInfo<v8::Value>& info) | 59 void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal
lbackInfo<v8::Value>& info) |
| 62 { | 60 { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 { | 144 { |
| 147 if (info.Length() < 1 || !info[0]->IsObject()) | 145 if (info.Length() < 1 || !info[0]->IsObject()) |
| 148 return; | 146 return; |
| 149 | 147 |
| 150 v8::Local<v8::Object> object = info[0].As<v8::Object>(); | 148 v8::Local<v8::Object> object = info[0].As<v8::Object>(); |
| 151 v8::Local<v8::Array> properties; | 149 v8::Local<v8::Array> properties; |
| 152 if (v8::Debug::GetInternalProperties(info.GetIsolate(), object).ToLocal(&pro
perties)) | 150 if (v8::Debug::GetInternalProperties(info.GetIsolate(), object).ToLocal(&pro
perties)) |
| 153 info.GetReturnValue().Set(properties); | 151 info.GetReturnValue().Set(properties); |
| 154 } | 152 } |
| 155 | 153 |
| 156 static v8::Local<v8::Array> wrapListenerFunctions(v8::Isolate* isolate, const V8
EventListenerInfoList& listeners, const String16& type) | |
| 157 { | |
| 158 v8::Local<v8::Array> result = v8::Array::New(isolate); | |
| 159 size_t handlersCount = listeners.size(); | |
| 160 for (size_t i = 0, outputIndex = 0; i < handlersCount; ++i) { | |
| 161 if (listeners[i].eventType != type) | |
| 162 continue; | |
| 163 v8::Local<v8::Object> function = listeners[i].handler; | |
| 164 v8::Local<v8::Object> listenerEntry = v8::Object::New(isolate); | |
| 165 listenerEntry->Set(toV8StringInternalized(isolate, "listener"), function
); | |
| 166 listenerEntry->Set(toV8StringInternalized(isolate, "useCapture"), v8::Bo
olean::New(isolate, listeners[i].useCapture)); | |
| 167 listenerEntry->Set(toV8StringInternalized(isolate, "passive"), v8::Boole
an::New(isolate, listeners[i].passive)); | |
| 168 result->Set(v8::Number::New(isolate, outputIndex++), listenerEntry); | |
| 169 } | |
| 170 return result; | |
| 171 } | |
| 172 | |
| 173 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI
nfo<v8::Value>& info) | |
| 174 { | |
| 175 if (info.Length() < 1) | |
| 176 return; | |
| 177 | |
| 178 V8DebuggerClient* client = unwrapDebugger(info)->client(); | |
| 179 V8EventListenerInfoList listenerInfo; | |
| 180 // eventListeners call can produce message on ErrorEvent during lazy event l
istener compilation. | |
| 181 client->muteWarningsAndDeprecations(); | |
| 182 client->eventListeners(info[0], listenerInfo); | |
| 183 client->unmuteWarningsAndDeprecations(); | |
| 184 | |
| 185 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); | |
| 186 protocol::HashSet<String16> types; | |
| 187 for (auto& info : listenerInfo) | |
| 188 types.add(info.eventType); | |
| 189 for (const auto& it : types) { | |
| 190 v8::Local<v8::Array> listeners = wrapListenerFunctions(info.GetIsolate()
, listenerInfo, it.first); | |
| 191 if (!listeners->Length()) | |
| 192 continue; | |
| 193 result->Set(toV8String(info.GetIsolate(), it.first), listeners); | |
| 194 } | |
| 195 info.GetReturnValue().Set(result); | |
| 196 } | |
| 197 | |
| 198 void V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback(const v8::Fun
ctionCallbackInfo<v8::Value>& info) | 154 void V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback(const v8::Fun
ctionCallbackInfo<v8::Value>& info) |
| 199 { | 155 { |
| 200 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) { | 156 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) { |
| 201 ASSERT_NOT_REACHED(); | 157 ASSERT_NOT_REACHED(); |
| 202 return; | 158 return; |
| 203 } | 159 } |
| 204 if (info.Length() > 2 && (!info[2]->IsArray() && !info[2]->IsUndefined())) { | 160 if (info.Length() > 2 && (!info[2]->IsArray() && !info[2]->IsUndefined())) { |
| 205 ASSERT_NOT_REACHED(); | 161 ASSERT_NOT_REACHED(); |
| 206 return; | 162 return; |
| 207 } | 163 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 ASSERT(info.Length() > 0 && info[0]->IsObject()); | 232 ASSERT(info.Length() > 0 && info[0]->IsObject()); |
| 277 info.GetReturnValue().Set(info[0].As<v8::Object>()->GetPrototype()); | 233 info.GetReturnValue().Set(info[0].As<v8::Object>()->GetPrototype()); |
| 278 } | 234 } |
| 279 | 235 |
| 280 v8::Local<v8::Private> V8Debugger::scopeExtensionPrivate(v8::Isolate* isolate) | 236 v8::Local<v8::Private> V8Debugger::scopeExtensionPrivate(v8::Isolate* isolate) |
| 281 { | 237 { |
| 282 return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Debug
ger#scopeExtension")); | 238 return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Debug
ger#scopeExtension")); |
| 283 } | 239 } |
| 284 | 240 |
| 285 } // namespace blink | 241 } // namespace blink |
| OLD | NEW |