| 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/V8InternalValueType.h" |
| 11 #include "platform/v8_inspector/V8StringUtil.h" | 12 #include "platform/v8_inspector/V8StringUtil.h" |
| 12 #include "platform/v8_inspector/public/V8DebuggerClient.h" | 13 #include "platform/v8_inspector/public/V8DebuggerClient.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 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) | 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) |
| 19 { | 20 { |
| 20 v8::Local<v8::String> funcName = toV8StringInternalized(context->GetIsolate(
), name); | 21 v8::Local<v8::String> funcName = toV8StringInternalized(context->GetIsolate(
), name); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 setFunctionProperty(context, injectedScriptHost, "isTypedArray", V8InjectedS
criptHost::isTypedArrayCallback, debuggerExternal); | 48 setFunctionProperty(context, injectedScriptHost, "isTypedArray", V8InjectedS
criptHost::isTypedArrayCallback, debuggerExternal); |
| 48 setFunctionProperty(context, injectedScriptHost, "subtype", V8InjectedScript
Host::subtypeCallback, debuggerExternal); | 49 setFunctionProperty(context, injectedScriptHost, "subtype", V8InjectedScript
Host::subtypeCallback, debuggerExternal); |
| 49 setFunctionProperty(context, injectedScriptHost, "getInternalProperties", V8
InjectedScriptHost::getInternalPropertiesCallback, debuggerExternal); | 50 setFunctionProperty(context, injectedScriptHost, "getInternalProperties", V8
InjectedScriptHost::getInternalPropertiesCallback, debuggerExternal); |
| 50 setFunctionProperty(context, injectedScriptHost, "suppressWarningsAndCallFun
ction", V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback, debuggerE
xternal); | 51 setFunctionProperty(context, injectedScriptHost, "suppressWarningsAndCallFun
ction", V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback, debuggerE
xternal); |
| 51 setFunctionProperty(context, injectedScriptHost, "bind", V8InjectedScriptHos
t::bindCallback, debuggerExternal); | 52 setFunctionProperty(context, injectedScriptHost, "bind", V8InjectedScriptHos
t::bindCallback, debuggerExternal); |
| 52 setFunctionProperty(context, injectedScriptHost, "proxyTargetValue", V8Injec
tedScriptHost::proxyTargetValueCallback, debuggerExternal); | 53 setFunctionProperty(context, injectedScriptHost, "proxyTargetValue", V8Injec
tedScriptHost::proxyTargetValueCallback, debuggerExternal); |
| 53 setFunctionProperty(context, injectedScriptHost, "prototype", V8InjectedScri
ptHost::prototypeCallback, debuggerExternal); | 54 setFunctionProperty(context, injectedScriptHost, "prototype", V8InjectedScri
ptHost::prototypeCallback, debuggerExternal); |
| 54 return injectedScriptHost; | 55 return injectedScriptHost; |
| 55 } | 56 } |
| 56 | 57 |
| 57 v8::Local<v8::Private> V8InjectedScriptHost::internalEntryPrivate(v8::Isolate* i
solate) | |
| 58 { | |
| 59 return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Injec
tedScriptHost#internalEntry")); | |
| 60 } | |
| 61 | |
| 62 v8::Local<v8::Private> V8InjectedScriptHost::internalLocationPrivate(v8::Isolate
* isolate) | |
| 63 { | |
| 64 return v8::Private::ForApi(isolate, toV8StringInternalized(isolate, "V8Injec
tedScriptHost#internalLocation")); | |
| 65 } | |
| 66 | |
| 67 void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal
lbackInfo<v8::Value>& info) | 58 void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal
lbackInfo<v8::Value>& info) |
| 68 { | 59 { |
| 69 if (info.Length() < 1 || !info[0]->IsObject()) | 60 if (info.Length() < 1 || !info[0]->IsObject()) |
| 70 return; | 61 return; |
| 71 | 62 |
| 72 v8::Local<v8::Object> object = info[0].As<v8::Object>(); | 63 v8::Local<v8::Object> object = info[0].As<v8::Object>(); |
| 73 info.GetReturnValue().Set(object->GetConstructorName()); | 64 info.GetReturnValue().Set(object->GetConstructorName()); |
| 74 } | 65 } |
| 75 | 66 |
| 76 void V8InjectedScriptHost::formatAccessorsAsProperties(const v8::FunctionCallbac
kInfo<v8::Value>& info) | 67 void V8InjectedScriptHost::formatAccessorsAsProperties(const v8::FunctionCallbac
kInfo<v8::Value>& info) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 93 info.GetReturnValue().Set(info[0]->IsTypedArray()); | 84 info.GetReturnValue().Set(info[0]->IsTypedArray()); |
| 94 } | 85 } |
| 95 | 86 |
| 96 void V8InjectedScriptHost::subtypeCallback(const v8::FunctionCallbackInfo<v8::Va
lue>& info) | 87 void V8InjectedScriptHost::subtypeCallback(const v8::FunctionCallbackInfo<v8::Va
lue>& info) |
| 97 { | 88 { |
| 98 if (info.Length() < 1) | 89 if (info.Length() < 1) |
| 99 return; | 90 return; |
| 100 | 91 |
| 101 v8::Isolate* isolate = info.GetIsolate(); | 92 v8::Isolate* isolate = info.GetIsolate(); |
| 102 v8::Local<v8::Value> value = info[0]; | 93 v8::Local<v8::Value> value = info[0]; |
| 94 if (value->IsObject()) { |
| 95 v8::Local<v8::Value> internalType = v8InternalValueTypeFrom(isolate->Get
CurrentContext(), v8::Local<v8::Object>::Cast(value)); |
| 96 if (internalType->IsString()) { |
| 97 info.GetReturnValue().Set(internalType); |
| 98 return; |
| 99 } |
| 100 } |
| 103 if (value->IsArray() || value->IsTypedArray() || value->IsArgumentsObject())
{ | 101 if (value->IsArray() || value->IsTypedArray() || value->IsArgumentsObject())
{ |
| 104 info.GetReturnValue().Set(toV8StringInternalized(isolate, "array")); | 102 info.GetReturnValue().Set(toV8StringInternalized(isolate, "array")); |
| 105 return; | 103 return; |
| 106 } | 104 } |
| 107 if (value->IsDate()) { | 105 if (value->IsDate()) { |
| 108 info.GetReturnValue().Set(toV8StringInternalized(isolate, "date")); | 106 info.GetReturnValue().Set(toV8StringInternalized(isolate, "date")); |
| 109 return; | 107 return; |
| 110 } | 108 } |
| 111 if (value->IsRegExp()) { | 109 if (value->IsRegExp()) { |
| 112 info.GetReturnValue().Set(toV8StringInternalized(isolate, "regexp")); | 110 info.GetReturnValue().Set(toV8StringInternalized(isolate, "regexp")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 129 return; | 127 return; |
| 130 } | 128 } |
| 131 if (value->IsNativeError()) { | 129 if (value->IsNativeError()) { |
| 132 info.GetReturnValue().Set(toV8StringInternalized(isolate, "error")); | 130 info.GetReturnValue().Set(toV8StringInternalized(isolate, "error")); |
| 133 return; | 131 return; |
| 134 } | 132 } |
| 135 if (value->IsProxy()) { | 133 if (value->IsProxy()) { |
| 136 info.GetReturnValue().Set(toV8StringInternalized(isolate, "proxy")); | 134 info.GetReturnValue().Set(toV8StringInternalized(isolate, "proxy")); |
| 137 return; | 135 return; |
| 138 } | 136 } |
| 139 if (value->IsObject()) { | |
| 140 v8::Local<v8::Object> obj = value.As<v8::Object>(); | |
| 141 if (obj->HasPrivate(isolate->GetCurrentContext(), internalEntryPrivate(i
solate)).FromMaybe(false)) { | |
| 142 info.GetReturnValue().Set(toV8StringInternalized(isolate, "internal#
entry")); | |
| 143 return; | |
| 144 } | |
| 145 if (obj->HasPrivate(isolate->GetCurrentContext(), internalLocationPrivat
e(isolate)).FromMaybe(false)) { | |
| 146 info.GetReturnValue().Set(toV8StringInternalized(isolate, "internal#
location")); | |
| 147 return; | |
| 148 } | |
| 149 } | |
| 150 String16 subtype = unwrapDebugger(info)->client()->valueSubtype(value); | 137 String16 subtype = unwrapDebugger(info)->client()->valueSubtype(value); |
| 151 if (!subtype.isEmpty()) { | 138 if (!subtype.isEmpty()) { |
| 152 info.GetReturnValue().Set(toV8String(isolate, subtype)); | 139 info.GetReturnValue().Set(toV8String(isolate, subtype)); |
| 153 return; | 140 return; |
| 154 } | 141 } |
| 155 } | 142 } |
| 156 | 143 |
| 157 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb
ackInfo<v8::Value>& info) | 144 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb
ackInfo<v8::Value>& info) |
| 158 { | 145 { |
| 159 if (info.Length() < 1) | 146 if (info.Length() < 1) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 info.GetReturnValue().Set(target); | 218 info.GetReturnValue().Set(target); |
| 232 } | 219 } |
| 233 | 220 |
| 234 void V8InjectedScriptHost::prototypeCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) | 221 void V8InjectedScriptHost::prototypeCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) |
| 235 { | 222 { |
| 236 DCHECK(info.Length() > 0 && info[0]->IsObject()); | 223 DCHECK(info.Length() > 0 && info[0]->IsObject()); |
| 237 info.GetReturnValue().Set(info[0].As<v8::Object>()->GetPrototype()); | 224 info.GetReturnValue().Set(info[0].As<v8::Object>()->GetPrototype()); |
| 238 } | 225 } |
| 239 | 226 |
| 240 } // namespace blink | 227 } // namespace blink |
| OLD | NEW |