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 } 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 { |
| 200 v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| 201 v8::TryCatch tryCatch(isolate); |
| 202 v8::Isolate::DisallowJavascriptExecutionScope throwJs( |
| 203 isolate, |
| 204 v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); |
| 205 |
| 206 v8::Local<v8::Array> properties = v8::Array::New(isolate); |
| 207 if (tryCatch.HasCaught()) return; |
| 208 |
| 209 uint32_t outputIndex = 0; |
| 210 for (uint32_t i = 0; i < allProperties->Length(); i += 2) { |
| 211 v8::Local<v8::Value> key; |
| 212 if (!allProperties->Get(context, i).ToLocal(&key)) continue; |
| 213 if (tryCatch.HasCaught()) { |
| 214 tryCatch.Reset(); |
| 215 continue; |
| 216 } |
| 217 String16 keyString = toProtocolStringWithTypeCheck(key); |
| 218 if (keyString.isEmpty() || |
| 219 allowedProperties.find(keyString) == allowedProperties.end()) |
| 220 continue; |
| 221 v8::Local<v8::Value> value; |
| 222 if (!allProperties->Get(context, i + 1).ToLocal(&value)) continue; |
| 223 if (tryCatch.HasCaught()) { |
| 224 tryCatch.Reset(); |
| 225 continue; |
| 226 } |
| 227 createDataProperty(context, properties, outputIndex++, key); |
| 228 createDataProperty(context, properties, outputIndex++, value); |
| 229 } |
174 info.GetReturnValue().Set(properties); | 230 info.GetReturnValue().Set(properties); |
| 231 } |
175 } | 232 } |
176 | 233 |
177 void V8InjectedScriptHost::objectHasOwnPropertyCallback( | 234 void V8InjectedScriptHost::objectHasOwnPropertyCallback( |
178 const v8::FunctionCallbackInfo<v8::Value>& info) { | 235 const v8::FunctionCallbackInfo<v8::Value>& info) { |
179 if (info.Length() < 2 || !info[0]->IsObject() || !info[1]->IsString()) return; | 236 if (info.Length() < 2 || !info[0]->IsObject() || !info[1]->IsString()) return; |
180 bool result = info[0] | 237 bool result = info[0] |
181 .As<v8::Object>() | 238 .As<v8::Object>() |
182 ->HasOwnProperty(info.GetIsolate()->GetCurrentContext(), | 239 ->HasOwnProperty(info.GetIsolate()->GetCurrentContext(), |
183 v8::Local<v8::String>::Cast(info[1])) | 240 v8::Local<v8::String>::Cast(info[1])) |
184 .FromMaybe(false); | 241 .FromMaybe(false); |
(...skipping 22 matching lines...) Expand all Loading... |
207 UNREACHABLE(); | 264 UNREACHABLE(); |
208 return; | 265 return; |
209 } | 266 } |
210 v8::Local<v8::Object> target = info[0].As<v8::Proxy>(); | 267 v8::Local<v8::Object> target = info[0].As<v8::Proxy>(); |
211 while (target->IsProxy()) | 268 while (target->IsProxy()) |
212 target = v8::Local<v8::Proxy>::Cast(target)->GetTarget(); | 269 target = v8::Local<v8::Proxy>::Cast(target)->GetTarget(); |
213 info.GetReturnValue().Set(target); | 270 info.GetReturnValue().Set(target); |
214 } | 271 } |
215 | 272 |
216 } // namespace v8_inspector | 273 } // namespace v8_inspector |
OLD | NEW |