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

Side by Side Diff: src/runtime/runtime-debug.cc

Issue 1134193002: Provide accessor for object internal properties that doesn't require debugger to be active (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed gcmole failures Created 5 years, 7 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/runtime/runtime.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 Handle<String> has_more =
134 factory->NewStringFromAsciiChecked("[[IteratorHasMore]]");
135 result->set(0, *has_more);
136 result->set(1, isolate->heap()->ToBoolean(iterator->HasMore()));
137
138 Handle<String> index =
139 factory->NewStringFromAsciiChecked("[[IteratorIndex]]");
140 result->set(2, *index);
141 result->set(3, iterator->index());
142
143 Handle<String> iterator_kind =
144 factory->NewStringFromAsciiChecked("[[IteratorKind]]");
145 result->set(4, *iterator_kind);
146 Handle<String> kind_str = factory->NewStringFromAsciiChecked(kind);
147 result->set(5, *kind_str);
148 return factory->NewJSArrayWithElements(result);
149 }
150
151
152 MaybeHandle<JSArray> Runtime::GetInternalProperties(Isolate* isolate,
153 Handle<Object> object) {
154 Factory* factory = isolate->factory();
155 if (object->IsJSFunction()) {
156 Handle<JSFunction> function = Handle<JSFunction>::cast(object);
157 if (function->shared()->bound()) {
158 RUNTIME_ASSERT_HANDLIFIED(function->function_bindings()->IsFixedArray(),
159 JSArray);
160
161 Handle<FixedArray> bindings(function->function_bindings());
162
163 Handle<FixedArray> result = factory->NewFixedArray(2 * 3);
164 Handle<String> target =
165 factory->NewStringFromAsciiChecked("[[TargetFunction]]");
166 result->set(0, *target);
167 result->set(1, bindings->get(JSFunction::kBoundFunctionIndex));
168
169 Handle<String> bound_this =
170 factory->NewStringFromAsciiChecked("[[BoundThis]]");
171 result->set(2, *bound_this);
172 result->set(3, bindings->get(JSFunction::kBoundThisIndex));
173
174 Handle<FixedArray> arguments = factory->NewFixedArray(
175 bindings->length() - JSFunction::kBoundArgumentsStartIndex);
176 bindings->CopyTo(
177 JSFunction::kBoundArgumentsStartIndex, *arguments, 0,
178 bindings->length() - JSFunction::kBoundArgumentsStartIndex);
179 Handle<String> bound_args =
180 factory->NewStringFromAsciiChecked("[[BoundArgs]]");
181 result->set(4, *bound_args);
182 Handle<JSArray> arguments_array =
183 factory->NewJSArrayWithElements(arguments);
184 result->set(5, *arguments_array);
185 return factory->NewJSArrayWithElements(result);
186 }
187 } else if (object->IsJSMapIterator()) {
188 Handle<JSMapIterator> iterator = Handle<JSMapIterator>::cast(object);
189 return GetIteratorInternalProperties(isolate, iterator);
190 } else if (object->IsJSSetIterator()) {
191 Handle<JSSetIterator> iterator = Handle<JSSetIterator>::cast(object);
192 return GetIteratorInternalProperties(isolate, iterator);
193 } else if (object->IsJSGeneratorObject()) {
194 Handle<JSGeneratorObject> generator =
195 Handle<JSGeneratorObject>::cast(object);
196
197 const char* status = "suspended";
198 if (generator->is_closed()) {
199 status = "closed";
200 } else if (generator->is_executing()) {
201 status = "running";
202 } else {
203 DCHECK(generator->is_suspended());
204 }
205
206 Handle<FixedArray> result = factory->NewFixedArray(2 * 3);
207 Handle<String> generator_status =
208 factory->NewStringFromAsciiChecked("[[GeneratorStatus]]");
209 result->set(0, *generator_status);
210 Handle<String> status_str = factory->NewStringFromAsciiChecked(status);
211 result->set(1, *status_str);
212
213 Handle<String> function =
214 factory->NewStringFromAsciiChecked("[[GeneratorFunction]]");
215 result->set(2, *function);
216 result->set(3, generator->function());
217
218 Handle<String> receiver =
219 factory->NewStringFromAsciiChecked("[[GeneratorReceiver]]");
220 result->set(4, *receiver);
221 result->set(5, generator->receiver());
222 return factory->NewJSArrayWithElements(result);
223 } else if (Object::IsPromise(object)) {
224 Handle<JSObject> promise = Handle<JSObject>::cast(object);
225
226 Handle<Object> status_obj =
227 DebugGetProperty(promise, isolate->promise_status());
228 RUNTIME_ASSERT_HANDLIFIED(status_obj->IsSmi(), JSArray);
229 const char* status = "rejected";
230 int status_val = Handle<Smi>::cast(status_obj)->value();
231 switch (status_val) {
232 case +1:
233 status = "resolved";
234 break;
235 case 0:
236 status = "pending";
237 break;
238 default:
239 DCHECK_EQ(-1, status_val);
240 }
241
242 Handle<FixedArray> result = factory->NewFixedArray(2 * 2);
243 Handle<String> promise_status =
244 factory->NewStringFromAsciiChecked("[[PromiseStatus]]");
245 result->set(0, *promise_status);
246 Handle<String> status_str = factory->NewStringFromAsciiChecked(status);
247 result->set(1, *status_str);
248
249 Handle<Object> value_obj =
250 DebugGetProperty(promise, isolate->promise_value());
251 Handle<String> promise_value =
252 factory->NewStringFromAsciiChecked("[[PromiseValue]]");
253 result->set(2, *promise_value);
254 result->set(3, *value_obj);
255 return factory->NewJSArrayWithElements(result);
256 } else if (object->IsJSValue()) {
257 Handle<JSValue> js_value = Handle<JSValue>::cast(object);
258
259 Handle<FixedArray> result = factory->NewFixedArray(2);
260 Handle<String> primitive_value =
261 factory->NewStringFromAsciiChecked("[[PrimitiveValue]]");
262 result->set(0, *primitive_value);
263 result->set(1, js_value->value());
264 return factory->NewJSArrayWithElements(result);
265 }
266 return factory->NewJSArray(0);
267 }
268
269
270 RUNTIME_FUNCTION(Runtime_DebugGetInternalProperties) {
271 HandleScope scope(isolate);
272 DCHECK(args.length() == 1);
273 CONVERT_ARG_HANDLE_CHECKED(Object, obj, 0);
274 Handle<JSArray> result;
275 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
276 isolate, result, Runtime::GetInternalProperties(isolate, obj));
277 return *result;
278 }
279
280
104 // Get debugger related details for an object property, in the following format: 281 // Get debugger related details for an object property, in the following format:
105 // 0: Property value 282 // 0: Property value
106 // 1: Property details 283 // 1: Property details
107 // 2: Property value is exception 284 // 2: Property value is exception
108 // 3: Getter function if defined 285 // 3: Getter function if defined
109 // 4: Setter function if defined 286 // 4: Setter function if defined
110 // Items 2-4 are only filled if the property has either a getter or a setter. 287 // Items 2-4 are only filled if the property has either a getter or a setter.
111 RUNTIME_FUNCTION(Runtime_DebugGetPropertyDetails) { 288 RUNTIME_FUNCTION(Runtime_DebugGetPropertyDetails) {
112 HandleScope scope(isolate); 289 HandleScope scope(isolate);
113 290
(...skipping 2871 matching lines...) Expand 10 before | Expand all | Expand 10 after
2985 return Smi::FromInt(isolate->debug()->is_active()); 3162 return Smi::FromInt(isolate->debug()->is_active());
2986 } 3163 }
2987 3164
2988 3165
2989 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { 3166 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) {
2990 UNIMPLEMENTED(); 3167 UNIMPLEMENTED();
2991 return NULL; 3168 return NULL;
2992 } 3169 }
2993 } 3170 }
2994 } // namespace v8::internal 3171 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698