| 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 V8InternalValueType internalType = internalValueType(isolate->GetCurrent
Context(), v8::Local<v8::Object>::Cast(value)); |
| 96 switch (internalType) { |
| 97 case V8InternalValueType::kEntry: |
| 98 info.GetReturnValue().Set(toV8StringInternalized(isolate, "internal#
entry")); |
| 99 return; |
| 100 case V8InternalValueType::kLocation: |
| 101 info.GetReturnValue().Set(toV8StringInternalized(isolate, "internal#
location")); |
| 102 return; |
| 103 case V8InternalValueType::kScope: |
| 104 info.GetReturnValue().Set(toV8StringInternalized(isolate, "internal#
scope")); |
| 105 return; |
| 106 case V8InternalValueType::kScopeList: |
| 107 info.GetReturnValue().Set(toV8StringInternalized(isolate, "internal#
scopeList")); |
| 108 return; |
| 109 case V8InternalValueType::kNotInternal: |
| 110 break; |
| 111 } |
| 112 } |
| 103 if (value->IsArray() || value->IsTypedArray() || value->IsArgumentsObject())
{ | 113 if (value->IsArray() || value->IsTypedArray() || value->IsArgumentsObject())
{ |
| 104 info.GetReturnValue().Set(toV8StringInternalized(isolate, "array")); | 114 info.GetReturnValue().Set(toV8StringInternalized(isolate, "array")); |
| 105 return; | 115 return; |
| 106 } | 116 } |
| 107 if (value->IsDate()) { | 117 if (value->IsDate()) { |
| 108 info.GetReturnValue().Set(toV8StringInternalized(isolate, "date")); | 118 info.GetReturnValue().Set(toV8StringInternalized(isolate, "date")); |
| 109 return; | 119 return; |
| 110 } | 120 } |
| 111 if (value->IsRegExp()) { | 121 if (value->IsRegExp()) { |
| 112 info.GetReturnValue().Set(toV8StringInternalized(isolate, "regexp")); | 122 info.GetReturnValue().Set(toV8StringInternalized(isolate, "regexp")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 129 return; | 139 return; |
| 130 } | 140 } |
| 131 if (value->IsNativeError()) { | 141 if (value->IsNativeError()) { |
| 132 info.GetReturnValue().Set(toV8StringInternalized(isolate, "error")); | 142 info.GetReturnValue().Set(toV8StringInternalized(isolate, "error")); |
| 133 return; | 143 return; |
| 134 } | 144 } |
| 135 if (value->IsProxy()) { | 145 if (value->IsProxy()) { |
| 136 info.GetReturnValue().Set(toV8StringInternalized(isolate, "proxy")); | 146 info.GetReturnValue().Set(toV8StringInternalized(isolate, "proxy")); |
| 137 return; | 147 return; |
| 138 } | 148 } |
| 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); | 149 String16 subtype = unwrapDebugger(info)->client()->valueSubtype(value); |
| 151 if (!subtype.isEmpty()) { | 150 if (!subtype.isEmpty()) { |
| 152 info.GetReturnValue().Set(toV8String(isolate, subtype)); | 151 info.GetReturnValue().Set(toV8String(isolate, subtype)); |
| 153 return; | 152 return; |
| 154 } | 153 } |
| 155 } | 154 } |
| 156 | 155 |
| 157 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb
ackInfo<v8::Value>& info) | 156 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb
ackInfo<v8::Value>& info) |
| 158 { | 157 { |
| 159 if (info.Length() < 1) | 158 if (info.Length() < 1) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 info.GetReturnValue().Set(target); | 230 info.GetReturnValue().Set(target); |
| 232 } | 231 } |
| 233 | 232 |
| 234 void V8InjectedScriptHost::prototypeCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) | 233 void V8InjectedScriptHost::prototypeCallback(const v8::FunctionCallbackInfo<v8::
Value>& info) |
| 235 { | 234 { |
| 236 DCHECK(info.Length() > 0 && info[0]->IsObject()); | 235 DCHECK(info.Length() > 0 && info[0]->IsObject()); |
| 237 info.GetReturnValue().Set(info[0].As<v8::Object>()->GetPrototype()); | 236 info.GetReturnValue().Set(info[0].As<v8::Object>()->GetPrototype()); |
| 238 } | 237 } |
| 239 | 238 |
| 240 } // namespace blink | 239 } // namespace blink |
| OLD | NEW |