OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 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 "src/inspector/v8-injected-script-host.h" | 5 #include "src/inspector/v8-injected-script-host.h" |
6 | 6 |
7 #include "src/base/macros.h" | 7 #include "src/base/macros.h" |
8 #include "src/inspector/injected-script-native.h" | 8 #include "src/inspector/injected-script-native.h" |
9 #include "src/inspector/string-util.h" | 9 #include "src/inspector/string-util.h" |
10 #include "src/inspector/v8-debugger.h" | 10 #include "src/inspector/v8-debugger.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 unwrapInspector(info)->client()->valueSubtype(value); | 159 unwrapInspector(info)->client()->valueSubtype(value); |
160 if (subtype) { | 160 if (subtype) { |
161 info.GetReturnValue().Set(toV8String(isolate, subtype->string())); | 161 info.GetReturnValue().Set(toV8String(isolate, subtype->string())); |
162 return; | 162 return; |
163 } | 163 } |
164 } | 164 } |
165 | 165 |
166 void V8InjectedScriptHost::getInternalPropertiesCallback( | 166 void V8InjectedScriptHost::getInternalPropertiesCallback( |
167 const v8::FunctionCallbackInfo<v8::Value>& info) { | 167 const v8::FunctionCallbackInfo<v8::Value>& info) { |
168 if (info.Length() < 1) return; | 168 if (info.Length() < 1) return; |
169 v8::Local<v8::Array> properties; | 169 |
170 if (unwrapInspector(info) | 170 std::unordered_set<String16> allowedProperties; |
171 ->debugger() | 171 if (info[0]->IsBooleanObject() || info[0]->IsNumberObject() || |
172 ->internalProperties(info.GetIsolate()->GetCurrentContext(), info[0]) | 172 info[0]->IsStringObject() || info[0]->IsSymbolObject()) { |
173 .ToLocal(&properties)) | 173 allowedProperties.insert(String16("[[PrimitiveValue]]")); |
174 info.GetReturnValue().Set(properties); | 174 } else if (info[0]->IsPromise()) { |
175 allowedProperties.insert(String16("[[PromiseStatus]]")); | |
176 allowedProperties.insert(String16("[[PromiseValue]]")); | |
177 } else if (info[0]->IsGeneratorObject()) { | |
178 allowedProperties.insert(String16("[[GeneratorStatus]]")); | |
179 } else if (info[0]->IsMapIterator() || info[0]->IsSetIterator()) { | |
180 allowedProperties.insert(String16("[[IteratorHasMore]]")); | |
181 allowedProperties.insert(String16("[[IteratorIndex]]")); | |
182 allowedProperties.insert(String16("[[IteratorKind]]")); | |
183 allowedProperties.insert(String16("[[Entries]]")); | |
184 } else if (info[0]->IsMap() || info[0]->IsWeakMap() || info[0]->IsSet() || | |
185 info[0]->IsWeakSet()) { | |
186 allowedProperties.insert(String16("[[Entries]]")); | |
187 } | |
188 if (!allowedProperties.size()) return; | |
189 | |
190 v8::Isolate* isolate = info.GetIsolate(); | |
191 v8::Local<v8::Array> allProperties; | |
192 if (!unwrapInspector(info) | |
193 ->debugger() | |
194 ->internalProperties(isolate->GetCurrentContext(), info[0]) | |
195 .ToLocal(&allProperties) || | |
196 !allProperties->IsArray() || allProperties->Length() % 2 != 0) | |
197 return; | |
198 | |
199 v8::Local<v8::Array> properties = v8::Array::New(isolate); | |
dgozman
2016/10/07 00:00:18
Let's put this under throwJs.
kozy
2016/10/07 00:20:30
Done.
| |
200 { | |
201 v8::Local<v8::Context> context = isolate->GetCurrentContext(); | |
202 v8::TryCatch tryCatch(isolate); | |
203 v8::Isolate::DisallowJavascriptExecutionScope throwJs( | |
204 isolate, | |
205 v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); | |
206 | |
207 uint32_t outputIndex = 0; | |
208 for (uint32_t i = 0; i < allProperties->Length(); i += 2) { | |
209 v8::Local<v8::Value> key; | |
210 if (!allProperties->Get(context, i).ToLocal(&key)) continue; | |
211 if (tryCatch.HasCaught()) return; | |
dgozman
2016/10/07 00:00:18
continue
kozy
2016/10/07 00:20:30
Done.
| |
212 String16 keyString = toProtocolStringWithTypeCheck(key); | |
213 if (keyString.isEmpty() || | |
214 allowedProperties.find(keyString) == allowedProperties.end()) | |
215 continue; | |
216 v8::Local<v8::Value> value; | |
217 if (!allProperties->Get(context, i + 1).ToLocal(&value)) continue; | |
218 if (tryCatch.HasCaught()) return; | |
dgozman
2016/10/07 00:00:18
continue
kozy
2016/10/07 00:20:30
Done.
| |
219 createDataProperty(context, properties, outputIndex++, key); | |
220 createDataProperty(context, properties, outputIndex++, value); | |
221 } | |
222 } | |
223 info.GetReturnValue().Set(properties); | |
175 } | 224 } |
176 | 225 |
177 void V8InjectedScriptHost::objectHasOwnPropertyCallback( | 226 void V8InjectedScriptHost::objectHasOwnPropertyCallback( |
178 const v8::FunctionCallbackInfo<v8::Value>& info) { | 227 const v8::FunctionCallbackInfo<v8::Value>& info) { |
179 if (info.Length() < 2 || !info[0]->IsObject() || !info[1]->IsString()) return; | 228 if (info.Length() < 2 || !info[0]->IsObject() || !info[1]->IsString()) return; |
180 bool result = info[0] | 229 bool result = info[0] |
181 .As<v8::Object>() | 230 .As<v8::Object>() |
182 ->HasOwnProperty(info.GetIsolate()->GetCurrentContext(), | 231 ->HasOwnProperty(info.GetIsolate()->GetCurrentContext(), |
183 v8::Local<v8::String>::Cast(info[1])) | 232 v8::Local<v8::String>::Cast(info[1])) |
184 .FromMaybe(false); | 233 .FromMaybe(false); |
(...skipping 22 matching lines...) Expand all Loading... | |
207 UNREACHABLE(); | 256 UNREACHABLE(); |
208 return; | 257 return; |
209 } | 258 } |
210 v8::Local<v8::Object> target = info[0].As<v8::Proxy>(); | 259 v8::Local<v8::Object> target = info[0].As<v8::Proxy>(); |
211 while (target->IsProxy()) | 260 while (target->IsProxy()) |
212 target = v8::Local<v8::Proxy>::Cast(target)->GetTarget(); | 261 target = v8::Local<v8::Proxy>::Cast(target)->GetTarget(); |
213 info.GetReturnValue().Set(target); | 262 info.GetReturnValue().Set(target); |
214 } | 263 } |
215 | 264 |
216 } // namespace v8_inspector | 265 } // namespace v8_inspector |
OLD | NEW |