Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(810)

Side by Side Diff: src/inspector/V8InjectedScriptHost.cpp

Issue 2300823002: Revert of [inspector] Initial import of v8_inspector. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/inspector/V8InjectedScriptHost.h ('k') | src/inspector/V8InspectorImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/inspector/V8InjectedScriptHost.h"
6
7 #include "src/inspector/InjectedScriptNative.h"
8 #include "src/inspector/StringUtil.h"
9 #include "src/inspector/V8Compat.h"
10 #include "src/inspector/V8Debugger.h"
11 #include "src/inspector/V8InspectorImpl.h"
12 #include "src/inspector/V8InternalValueType.h"
13 #include "src/inspector/V8ValueCopier.h"
14 #include "src/inspector/public/V8InspectorClient.h"
15
16 namespace v8_inspector {
17
18 namespace {
19
20 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)
21 {
22 v8::Local<v8::String> funcName = toV8StringInternalized(context->GetIsolate( ), name);
23 v8::Local<v8::Function> func;
24 if (!V8_FUNCTION_NEW_REMOVE_PROTOTYPE(context, callback, external, 0).ToLoca l(&func))
25 return;
26 func->SetName(funcName);
27 createDataProperty(context, obj, funcName, func);
28 }
29
30 V8InspectorImpl* unwrapInspector(const v8::FunctionCallbackInfo<v8::Value>& info )
31 {
32 DCHECK(!info.Data().IsEmpty());
33 DCHECK(info.Data()->IsExternal());
34 V8InspectorImpl* inspector = static_cast<V8InspectorImpl*>(info.Data().As<v8 ::External>()->Value());
35 DCHECK(inspector);
36 return inspector;
37 }
38
39 } // namespace
40
41 v8::Local<v8::Object> V8InjectedScriptHost::create(v8::Local<v8::Context> contex t, V8InspectorImpl* inspector)
42 {
43 v8::Isolate* isolate = inspector->isolate();
44 v8::Local<v8::Object> injectedScriptHost = v8::Object::New(isolate);
45 bool success = injectedScriptHost->SetPrototype(context, v8::Null(isolate)). FromMaybe(false);
46 DCHECK(success);
47 v8::Local<v8::External> debuggerExternal = v8::External::New(isolate, inspec tor);
48 setFunctionProperty(context, injectedScriptHost, "internalConstructorName", V8InjectedScriptHost::internalConstructorNameCallback, debuggerExternal);
49 setFunctionProperty(context, injectedScriptHost, "formatAccessorsAsPropertie s", V8InjectedScriptHost::formatAccessorsAsProperties, debuggerExternal);
50 setFunctionProperty(context, injectedScriptHost, "subtype", V8InjectedScript Host::subtypeCallback, debuggerExternal);
51 setFunctionProperty(context, injectedScriptHost, "getInternalProperties", V8 InjectedScriptHost::getInternalPropertiesCallback, debuggerExternal);
52 setFunctionProperty(context, injectedScriptHost, "objectHasOwnProperty", V8I njectedScriptHost::objectHasOwnPropertyCallback, debuggerExternal);
53 setFunctionProperty(context, injectedScriptHost, "bind", V8InjectedScriptHos t::bindCallback, debuggerExternal);
54 setFunctionProperty(context, injectedScriptHost, "proxyTargetValue", V8Injec tedScriptHost::proxyTargetValueCallback, debuggerExternal);
55 return injectedScriptHost;
56 }
57
58 void V8InjectedScriptHost::internalConstructorNameCallback(const v8::FunctionCal lbackInfo<v8::Value>& info)
59 {
60 if (info.Length() < 1 || !info[0]->IsObject())
61 return;
62
63 v8::Local<v8::Object> object = info[0].As<v8::Object>();
64 info.GetReturnValue().Set(object->GetConstructorName());
65 }
66
67 void V8InjectedScriptHost::formatAccessorsAsProperties(const v8::FunctionCallbac kInfo<v8::Value>& info)
68 {
69 DCHECK_EQ(info.Length(), 2);
70 info.GetReturnValue().Set(false);
71 if (!info[1]->IsFunction())
72 return;
73 // Check that function is user-defined.
74 if (info[1].As<v8::Function>()->ScriptId() != v8::UnboundScript::kNoScriptId )
75 return;
76 info.GetReturnValue().Set(unwrapInspector(info)->client()->formatAccessorsAs Properties(info[0]));
77 }
78
79 void V8InjectedScriptHost::subtypeCallback(const v8::FunctionCallbackInfo<v8::Va lue>& info)
80 {
81 if (info.Length() < 1)
82 return;
83
84 v8::Isolate* isolate = info.GetIsolate();
85 v8::Local<v8::Value> value = info[0];
86 if (value->IsObject()) {
87 v8::Local<v8::Value> internalType = v8InternalValueTypeFrom(isolate->Get CurrentContext(), v8::Local<v8::Object>::Cast(value));
88 if (internalType->IsString()) {
89 info.GetReturnValue().Set(internalType);
90 return;
91 }
92 }
93 if (value->IsArray() || value->IsArgumentsObject()) {
94 info.GetReturnValue().Set(toV8StringInternalized(isolate, "array"));
95 return;
96 }
97 if (value->IsTypedArray()) {
98 info.GetReturnValue().Set(toV8StringInternalized(isolate, "typedarray")) ;
99 return;
100 }
101 if (value->IsDate()) {
102 info.GetReturnValue().Set(toV8StringInternalized(isolate, "date"));
103 return;
104 }
105 if (value->IsRegExp()) {
106 info.GetReturnValue().Set(toV8StringInternalized(isolate, "regexp"));
107 return;
108 }
109 if (value->IsMap() || value->IsWeakMap()) {
110 info.GetReturnValue().Set(toV8StringInternalized(isolate, "map"));
111 return;
112 }
113 if (value->IsSet() || value->IsWeakSet()) {
114 info.GetReturnValue().Set(toV8StringInternalized(isolate, "set"));
115 return;
116 }
117 if (value->IsMapIterator() || value->IsSetIterator()) {
118 info.GetReturnValue().Set(toV8StringInternalized(isolate, "iterator"));
119 return;
120 }
121 if (value->IsGeneratorObject()) {
122 info.GetReturnValue().Set(toV8StringInternalized(isolate, "generator"));
123 return;
124 }
125 if (value->IsNativeError()) {
126 info.GetReturnValue().Set(toV8StringInternalized(isolate, "error"));
127 return;
128 }
129 if (value->IsProxy()) {
130 info.GetReturnValue().Set(toV8StringInternalized(isolate, "proxy"));
131 return;
132 }
133 if (value->IsPromise()) {
134 info.GetReturnValue().Set(toV8StringInternalized(isolate, "promise"));
135 return;
136 }
137 std::unique_ptr<StringBuffer> subtype = unwrapInspector(info)->client()->val ueSubtype(value);
138 if (subtype) {
139 info.GetReturnValue().Set(toV8String(isolate, subtype->string()));
140 return;
141 }
142 }
143
144 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb ackInfo<v8::Value>& info)
145 {
146 if (info.Length() < 1)
147 return;
148 v8::Local<v8::Array> properties;
149 if (unwrapInspector(info)->debugger()->internalProperties(info.GetIsolate()- >GetCurrentContext(), info[0]).ToLocal(&properties))
150 info.GetReturnValue().Set(properties);
151 }
152
153 void V8InjectedScriptHost::objectHasOwnPropertyCallback(const v8::FunctionCallba ckInfo<v8::Value>& info)
154 {
155 if (info.Length() < 2 || !info[0]->IsObject() || !info[1]->IsString())
156 return;
157 bool result = info[0].As<v8::Object>()->HasOwnProperty(info.GetIsolate()->Ge tCurrentContext(), v8::Local<v8::String>::Cast(info[1])).FromMaybe(false);
158 info.GetReturnValue().Set(v8::Boolean::New(info.GetIsolate(), result));
159 }
160
161 void V8InjectedScriptHost::bindCallback(const v8::FunctionCallbackInfo<v8::Value >& info)
162 {
163 if (info.Length() < 2 || !info[1]->IsString())
164 return;
165 InjectedScriptNative* injectedScriptNative = InjectedScriptNative::fromInjec tedScriptHost(info.Holder());
166 if (!injectedScriptNative)
167 return;
168
169 v8::Local<v8::String> v8groupName = info[1]->ToString(info.GetIsolate());
170 String16 groupName = toProtocolStringWithTypeCheck(v8groupName);
171 int id = injectedScriptNative->bind(info[0], groupName);
172 info.GetReturnValue().Set(id);
173 }
174
175 void V8InjectedScriptHost::proxyTargetValueCallback(const v8::FunctionCallbackIn fo<v8::Value>& info)
176 {
177 if (info.Length() != 1 || !info[0]->IsProxy()) {
178 NOTREACHED();
179 return;
180 }
181 v8::Local<v8::Object> target = info[0].As<v8::Proxy>();
182 while (target->IsProxy())
183 target = v8::Local<v8::Proxy>::Cast(target)->GetTarget();
184 info.GetReturnValue().Set(target);
185 }
186
187 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/V8InjectedScriptHost.h ('k') | src/inspector/V8InspectorImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698