| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/debug.h" | 10 #include "src/debug.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 case LookupIterator::DATA: | 95 case LookupIterator::DATA: |
| 96 return it->GetDataValue(); | 96 return it->GetDataValue(); |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 return it->isolate()->factory()->undefined_value(); | 100 return it->isolate()->factory()->undefined_value(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 | 103 |
| 104 static Handle<Object> DebugGetProperty(Handle<Object> object, | |
| 105 Handle<Name> name) { | |
| 106 LookupIterator it(object, name); | |
| 107 return DebugGetProperty(&it); | |
| 108 } | |
| 109 | |
| 110 | |
| 111 template <class IteratorType> | |
| 112 static MaybeHandle<JSArray> GetIteratorInternalProperties( | |
| 113 Isolate* isolate, Handle<IteratorType> object) { | |
| 114 Factory* factory = isolate->factory(); | |
| 115 Handle<IteratorType> iterator = Handle<IteratorType>::cast(object); | |
| 116 RUNTIME_ASSERT_HANDLIFIED(iterator->kind()->IsSmi(), JSArray); | |
| 117 const char* kind = NULL; | |
| 118 switch (Smi::cast(iterator->kind())->value()) { | |
| 119 case IteratorType::kKindKeys: | |
| 120 kind = "keys"; | |
| 121 break; | |
| 122 case IteratorType::kKindValues: | |
| 123 kind = "values"; | |
| 124 break; | |
| 125 case IteratorType::kKindEntries: | |
| 126 kind = "entries"; | |
| 127 break; | |
| 128 default: | |
| 129 RUNTIME_ASSERT_HANDLIFIED(false, JSArray); | |
| 130 } | |
| 131 | |
| 132 Handle<FixedArray> result = factory->NewFixedArray(2 * 3); | |
| 133 result->set(0, *factory->NewStringFromAsciiChecked("[[IteratorHasMore]]")); | |
| 134 result->set(1, isolate->heap()->ToBoolean(iterator->HasMore())); | |
| 135 | |
| 136 result->set(2, *factory->NewStringFromAsciiChecked("[[IteratorIndex]]")); | |
| 137 result->set(3, iterator->index()); | |
| 138 | |
| 139 result->set(4, *factory->NewStringFromAsciiChecked("[[IteratorKind]]")); | |
| 140 result->set(5, *factory->NewStringFromAsciiChecked(kind)); | |
| 141 return factory->NewJSArrayWithElements(result); | |
| 142 } | |
| 143 | |
| 144 | |
| 145 MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate, | |
| 146 Handle<Object> object) { | |
| 147 Factory* factory = isolate->factory(); | |
| 148 if (object->IsJSFunction()) { | |
| 149 Handle<JSFunction> function = Handle<JSFunction>::cast(object); | |
| 150 if (function->shared()->bound()) { | |
| 151 RUNTIME_ASSERT_HANDLIFIED(function->function_bindings()->IsFixedArray(), | |
| 152 JSArray); | |
| 153 | |
| 154 Handle<FixedArray> bindings(function->function_bindings()); | |
| 155 | |
| 156 Handle<FixedArray> result = factory->NewFixedArray(2 * 3); | |
| 157 result->set(0, *factory->NewStringFromAsciiChecked("[[TargetFunction]]")); | |
| 158 result->set(1, bindings->get(JSFunction::kBoundFunctionIndex)); | |
| 159 | |
| 160 result->set(2, *factory->NewStringFromAsciiChecked("[[BoundThis]]")); | |
| 161 result->set(3, bindings->get(JSFunction::kBoundThisIndex)); | |
| 162 | |
| 163 Handle<FixedArray> arguments = factory->NewFixedArray( | |
| 164 bindings->length() - JSFunction::kBoundArgumentsStartIndex); | |
| 165 bindings->CopyTo( | |
| 166 JSFunction::kBoundArgumentsStartIndex, *arguments, 0, | |
| 167 bindings->length() - JSFunction::kBoundArgumentsStartIndex); | |
| 168 result->set(4, *factory->NewStringFromAsciiChecked("[[BoundArgs]]")); | |
| 169 result->set(5, *factory->NewJSArrayWithElements(arguments)); | |
| 170 return factory->NewJSArrayWithElements(result); | |
| 171 } | |
| 172 } else if (object->IsJSMapIterator()) { | |
| 173 Handle<JSMapIterator> iterator = Handle<JSMapIterator>::cast(object); | |
| 174 return GetIteratorInternalProperties(isolate, iterator); | |
| 175 } else if (object->IsJSSetIterator()) { | |
| 176 Handle<JSSetIterator> iterator = Handle<JSSetIterator>::cast(object); | |
| 177 return GetIteratorInternalProperties(isolate, iterator); | |
| 178 } else if (object->IsJSGeneratorObject()) { | |
| 179 Handle<JSGeneratorObject> generator = | |
| 180 Handle<JSGeneratorObject>::cast(object); | |
| 181 | |
| 182 const char* status = "suspended"; | |
| 183 if (generator->is_closed()) { | |
| 184 status = "closed"; | |
| 185 } else if (generator->is_executing()) { | |
| 186 status = "running"; | |
| 187 } else { | |
| 188 DCHECK(generator->is_suspended()); | |
| 189 } | |
| 190 | |
| 191 Handle<FixedArray> result = factory->NewFixedArray(2 * 3); | |
| 192 result->set(0, *factory->NewStringFromAsciiChecked("[[GeneratorStatus]]")); | |
| 193 result->set(1, *factory->NewStringFromAsciiChecked(status)); | |
| 194 | |
| 195 result->set(2, | |
| 196 *factory->NewStringFromAsciiChecked("[[GeneratorFunction]]")); | |
| 197 result->set(3, generator->function()); | |
| 198 | |
| 199 result->set(4, | |
| 200 *factory->NewStringFromAsciiChecked("[[GeneratorReceiver]]")); | |
| 201 result->set(5, generator->receiver()); | |
| 202 return factory->NewJSArrayWithElements(result); | |
| 203 } else if (Object::IsPromise(object)) { | |
| 204 Handle<JSObject> promise = Handle<JSObject>::cast(object); | |
| 205 | |
| 206 Handle<Object> status_obj = | |
| 207 DebugGetProperty(promise, isolate->promise_status()); | |
| 208 RUNTIME_ASSERT_HANDLIFIED(status_obj->IsSmi(), JSArray); | |
| 209 const char* status = "rejected"; | |
| 210 int status_val = Handle<Smi>::cast(status_obj)->value(); | |
| 211 switch (status_val) { | |
| 212 case +1: | |
| 213 status = "resolved"; | |
| 214 break; | |
| 215 case 0: | |
| 216 status = "pending"; | |
| 217 break; | |
| 218 default: | |
| 219 DCHECK_EQ(-1, status_val); | |
| 220 } | |
| 221 | |
| 222 Handle<FixedArray> result = factory->NewFixedArray(2 * 2); | |
| 223 result->set(0, *factory->NewStringFromAsciiChecked("[[PromiseStatus]]")); | |
| 224 result->set(1, *factory->NewStringFromAsciiChecked(status)); | |
| 225 | |
| 226 Handle<Object> value_obj = | |
| 227 DebugGetProperty(promise, isolate->promise_value()); | |
| 228 result->set(2, *factory->NewStringFromAsciiChecked("[[PromiseValue]]")); | |
| 229 result->set(3, *value_obj); | |
| 230 return factory->NewJSArrayWithElements(result); | |
| 231 } else if (object->IsJSValue()) { | |
| 232 Handle<JSValue> js_value = Handle<JSValue>::cast(object); | |
| 233 | |
| 234 Handle<FixedArray> result = factory->NewFixedArray(2); | |
| 235 result->set(0, *factory->NewStringFromAsciiChecked("[[PrimitiveValue]]")); | |
| 236 result->set(1, js_value->value()); | |
| 237 return factory->NewJSArrayWithElements(result); | |
| 238 } | |
| 239 return factory->NewJSArray(0); | |
| 240 } | |
| 241 | |
| 242 | |
| 243 RUNTIME_FUNCTION(Runtime_DebugGetInternalProperties) { | |
| 244 HandleScope scope(isolate); | |
| 245 DCHECK(args.length() == 1); | |
| 246 CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0); | |
| 247 Handle<JSArray> result; | |
| 248 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
| 249 isolate, result, Runtime::GetInternalProperties(isolate, obj)); | |
| 250 return *result; | |
| 251 } | |
| 252 | |
| 253 | |
| 254 // Get debugger related details for an object property, in the following format: | 104 // Get debugger related details for an object property, in the following format: |
| 255 // 0: Property value | 105 // 0: Property value |
| 256 // 1: Property details | 106 // 1: Property details |
| 257 // 2: Property value is exception | 107 // 2: Property value is exception |
| 258 // 3: Getter function if defined | 108 // 3: Getter function if defined |
| 259 // 4: Setter function if defined | 109 // 4: Setter function if defined |
| 260 // Items 2-4 are only filled if the property has either a getter or a setter. | 110 // Items 2-4 are only filled if the property has either a getter or a setter. |
| 261 RUNTIME_FUNCTION(Runtime_DebugGetPropertyDetails) { | 111 RUNTIME_FUNCTION(Runtime_DebugGetPropertyDetails) { |
| 262 HandleScope scope(isolate); | 112 HandleScope scope(isolate); |
| 263 | 113 |
| (...skipping 2862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3126 return Smi::FromInt(isolate->debug()->is_active()); | 2976 return Smi::FromInt(isolate->debug()->is_active()); |
| 3127 } | 2977 } |
| 3128 | 2978 |
| 3129 | 2979 |
| 3130 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 2980 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
| 3131 UNIMPLEMENTED(); | 2981 UNIMPLEMENTED(); |
| 3132 return NULL; | 2982 return NULL; |
| 3133 } | 2983 } |
| 3134 } | 2984 } |
| 3135 } // namespace v8::internal | 2985 } // namespace v8::internal |
| OLD | NEW |