OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 12223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12234 } | 12234 } |
12235 return *array; | 12235 return *array; |
12236 } | 12236 } |
12237 | 12237 |
12238 | 12238 |
12239 static const int kScopeDetailsTypeIndex = 0; | 12239 static const int kScopeDetailsTypeIndex = 0; |
12240 static const int kScopeDetailsObjectIndex = 1; | 12240 static const int kScopeDetailsObjectIndex = 1; |
12241 static const int kScopeDetailsSize = 2; | 12241 static const int kScopeDetailsSize = 2; |
12242 | 12242 |
12243 | 12243 |
12244 static MaybeObject* MaterializeScopeDetails(Isolate* isolate, | 12244 static Handle<JSObject> MaterializeScopeDetails(Isolate* isolate, |
12245 ScopeIterator* it) { | 12245 ScopeIterator* it) { |
12246 // Calculate the size of the result. | 12246 // Calculate the size of the result. |
12247 int details_size = kScopeDetailsSize; | 12247 int details_size = kScopeDetailsSize; |
12248 Handle<FixedArray> details = isolate->factory()->NewFixedArray(details_size); | 12248 Handle<FixedArray> details = isolate->factory()->NewFixedArray(details_size); |
12249 | 12249 |
12250 // Fill in scope details. | 12250 // Fill in scope details. |
12251 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it->Type())); | 12251 details->set(kScopeDetailsTypeIndex, Smi::FromInt(it->Type())); |
12252 Handle<JSObject> scope_object = it->ScopeObject(); | 12252 Handle<JSObject> scope_object = it->ScopeObject(); |
12253 RETURN_IF_EMPTY_HANDLE(isolate, scope_object); | 12253 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, scope_object, Handle<JSObject>()); |
12254 details->set(kScopeDetailsObjectIndex, *scope_object); | 12254 details->set(kScopeDetailsObjectIndex, *scope_object); |
12255 | 12255 |
12256 return *isolate->factory()->NewJSArrayWithElements(details); | 12256 return isolate->factory()->NewJSArrayWithElements(details); |
12257 } | 12257 } |
12258 | 12258 |
12259 | 12259 |
12260 // Return an array with scope details | 12260 // Return an array with scope details |
12261 // args[0]: number: break id | 12261 // args[0]: number: break id |
12262 // args[1]: number: frame index | 12262 // args[1]: number: frame index |
12263 // args[2]: number: inlined frame index | 12263 // args[2]: number: inlined frame index |
12264 // args[3]: number: scope index | 12264 // args[3]: number: scope index |
12265 // | 12265 // |
12266 // The array returned contains the following information: | 12266 // The array returned contains the following information: |
(...skipping 20 matching lines...) Expand all Loading... |
12287 | 12287 |
12288 // Find the requested scope. | 12288 // Find the requested scope. |
12289 int n = 0; | 12289 int n = 0; |
12290 ScopeIterator it(isolate, frame, inlined_jsframe_index); | 12290 ScopeIterator it(isolate, frame, inlined_jsframe_index); |
12291 for (; !it.Done() && n < index; it.Next()) { | 12291 for (; !it.Done() && n < index; it.Next()) { |
12292 n++; | 12292 n++; |
12293 } | 12293 } |
12294 if (it.Done()) { | 12294 if (it.Done()) { |
12295 return isolate->heap()->undefined_value(); | 12295 return isolate->heap()->undefined_value(); |
12296 } | 12296 } |
12297 return MaterializeScopeDetails(isolate, &it); | 12297 Handle<JSObject> details = MaterializeScopeDetails(isolate, &it); |
| 12298 RETURN_IF_EMPTY_HANDLE(isolate, details); |
| 12299 return *details; |
12298 } | 12300 } |
12299 | 12301 |
12300 | 12302 |
| 12303 // Return an array of scope details |
| 12304 // args[0]: number: break id |
| 12305 // args[1]: number: frame index |
| 12306 // args[2]: number: inlined frame index |
| 12307 // |
| 12308 // The array returned contains arrays with the following information: |
| 12309 // 0: Scope type |
| 12310 // 1: Scope object |
| 12311 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetAllScopesDetails) { |
| 12312 HandleScope scope(isolate); |
| 12313 ASSERT(args.length() == 3); |
| 12314 |
| 12315 // Check arguments. |
| 12316 Object* check; |
| 12317 { MaybeObject* maybe_check = Runtime_CheckExecutionState( |
| 12318 RUNTIME_ARGUMENTS(isolate, args)); |
| 12319 if (!maybe_check->ToObject(&check)) return maybe_check; |
| 12320 } |
| 12321 CONVERT_SMI_ARG_CHECKED(wrapped_id, 1); |
| 12322 CONVERT_NUMBER_CHECKED(int, inlined_jsframe_index, Int32, args[2]); |
| 12323 |
| 12324 // Get the frame where the debugging is performed. |
| 12325 StackFrame::Id id = UnwrapFrameId(wrapped_id); |
| 12326 JavaScriptFrameIterator frame_it(isolate, id); |
| 12327 JavaScriptFrame* frame = frame_it.frame(); |
| 12328 |
| 12329 List<Handle<JSObject> > result(4); |
| 12330 ScopeIterator it(isolate, frame, inlined_jsframe_index); |
| 12331 for (; !it.Done(); it.Next()) { |
| 12332 Handle<JSObject> details = MaterializeScopeDetails(isolate, &it); |
| 12333 RETURN_IF_EMPTY_HANDLE(isolate, details); |
| 12334 result.Add(details); |
| 12335 } |
| 12336 |
| 12337 Handle<FixedArray> array = isolate->factory()->NewFixedArray(result.length()); |
| 12338 for (int i = 0; i < result.length(); ++i) { |
| 12339 array->set(i, *result[i]); |
| 12340 } |
| 12341 return *isolate->factory()->NewJSArrayWithElements(array); |
| 12342 } |
| 12343 |
| 12344 |
12301 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionScopeCount) { | 12345 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionScopeCount) { |
12302 HandleScope scope(isolate); | 12346 HandleScope scope(isolate); |
12303 ASSERT(args.length() == 1); | 12347 ASSERT(args.length() == 1); |
12304 | 12348 |
12305 // Check arguments. | 12349 // Check arguments. |
12306 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); | 12350 CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); |
12307 | 12351 |
12308 // Count the visible scopes. | 12352 // Count the visible scopes. |
12309 int n = 0; | 12353 int n = 0; |
12310 for (ScopeIterator it(isolate, fun); !it.Done(); it.Next()) { | 12354 for (ScopeIterator it(isolate, fun); !it.Done(); it.Next()) { |
(...skipping 15 matching lines...) Expand all Loading... |
12326 // Find the requested scope. | 12370 // Find the requested scope. |
12327 int n = 0; | 12371 int n = 0; |
12328 ScopeIterator it(isolate, fun); | 12372 ScopeIterator it(isolate, fun); |
12329 for (; !it.Done() && n < index; it.Next()) { | 12373 for (; !it.Done() && n < index; it.Next()) { |
12330 n++; | 12374 n++; |
12331 } | 12375 } |
12332 if (it.Done()) { | 12376 if (it.Done()) { |
12333 return isolate->heap()->undefined_value(); | 12377 return isolate->heap()->undefined_value(); |
12334 } | 12378 } |
12335 | 12379 |
12336 return MaterializeScopeDetails(isolate, &it); | 12380 Handle<JSObject> details = MaterializeScopeDetails(isolate, &it); |
| 12381 RETURN_IF_EMPTY_HANDLE(isolate, details); |
| 12382 return *details; |
12337 } | 12383 } |
12338 | 12384 |
12339 | 12385 |
12340 static bool SetScopeVariableValue(ScopeIterator* it, int index, | 12386 static bool SetScopeVariableValue(ScopeIterator* it, int index, |
12341 Handle<String> variable_name, | 12387 Handle<String> variable_name, |
12342 Handle<Object> new_value) { | 12388 Handle<Object> new_value) { |
12343 for (int n = 0; !it->Done() && n < index; it->Next()) { | 12389 for (int n = 0; !it->Done() && n < index; it->Next()) { |
12344 n++; | 12390 n++; |
12345 } | 12391 } |
12346 if (it->Done()) { | 12392 if (it->Done()) { |
(...skipping 2618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14965 // Handle last resort GC and make sure to allow future allocations | 15011 // Handle last resort GC and make sure to allow future allocations |
14966 // to grow the heap without causing GCs (if possible). | 15012 // to grow the heap without causing GCs (if possible). |
14967 isolate->counters()->gc_last_resort_from_js()->Increment(); | 15013 isolate->counters()->gc_last_resort_from_js()->Increment(); |
14968 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 15014 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
14969 "Runtime::PerformGC"); | 15015 "Runtime::PerformGC"); |
14970 } | 15016 } |
14971 } | 15017 } |
14972 | 15018 |
14973 | 15019 |
14974 } } // namespace v8::internal | 15020 } } // namespace v8::internal |
OLD | NEW |