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/debug.h" | 9 #include "src/debug.h" |
10 #include "src/deoptimizer.h" | 10 #include "src/deoptimizer.h" |
(...skipping 2596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2607 return Smi::FromInt(usage); | 2607 return Smi::FromInt(usage); |
2608 } | 2608 } |
2609 | 2609 |
2610 | 2610 |
2611 // Finds the script object from the script data. NOTE: This operation uses | 2611 // Finds the script object from the script data. NOTE: This operation uses |
2612 // heap traversal to find the function generated for the source position | 2612 // heap traversal to find the function generated for the source position |
2613 // for the requested break point. For lazily compiled functions several heap | 2613 // for the requested break point. For lazily compiled functions several heap |
2614 // traversals might be required rendering this operation as a rather slow | 2614 // traversals might be required rendering this operation as a rather slow |
2615 // operation. However for setting break points which is normally done through | 2615 // operation. However for setting break points which is normally done through |
2616 // some kind of user interaction the performance is not crucial. | 2616 // some kind of user interaction the performance is not crucial. |
2617 static Handle<Object> Runtime_GetScriptFromScriptName( | 2617 RUNTIME_FUNCTION(Runtime_GetScript) { |
2618 Handle<String> script_name) { | 2618 HandleScope scope(isolate); |
2619 // Scan the heap for Script objects to find the script with the requested | 2619 DCHECK(args.length() == 1); |
2620 // script data. | 2620 CONVERT_ARG_HANDLE_CHECKED(String, script_name, 0); |
2621 Handle<Script> script; | 2621 |
2622 Factory* factory = script_name->GetIsolate()->factory(); | 2622 Handle<Script> found; |
2623 Heap* heap = script_name->GetHeap(); | 2623 Heap* heap = isolate->heap(); |
2624 HeapIterator iterator(heap); | 2624 { |
2625 HeapObject* obj = NULL; | 2625 HeapIterator iterator(heap); |
2626 while (script.is_null() && ((obj = iterator.next()) != NULL)) { | 2626 HeapObject* obj = NULL; |
2627 // If a script is found check if it has the script data requested. | 2627 while ((obj = iterator.next()) != NULL) { |
2628 if (obj->IsScript()) { | 2628 if (!obj->IsScript()) continue; |
2629 if (Script::cast(obj)->name()->IsString()) { | 2629 Script* script = Script::cast(obj); |
2630 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { | 2630 if (!script->name()->IsString()) continue; |
2631 script = Handle<Script>(Script::cast(obj)); | 2631 String* name = String::cast(script->name()); |
2632 } | 2632 if (name->Equals(*script_name)) { |
| 2633 found = Handle<Script>(script, isolate); |
| 2634 break; |
2633 } | 2635 } |
2634 } | 2636 } |
2635 } | 2637 } |
2636 | 2638 |
2637 // If no script with the requested script data is found return undefined. | 2639 if (found.is_null()) return heap->undefined_value(); |
2638 if (script.is_null()) return factory->undefined_value(); | 2640 return *Script::GetWrapper(found); |
2639 | |
2640 // Return the script found. | |
2641 return Script::GetWrapper(script); | |
2642 } | 2641 } |
2643 | 2642 |
2644 | 2643 |
2645 // Get the script object from script data. NOTE: Regarding performance | |
2646 // see the NOTE for GetScriptFromScriptData. | |
2647 // args[0]: script data for the script to find the source for | |
2648 RUNTIME_FUNCTION(Runtime_GetScript) { | |
2649 HandleScope scope(isolate); | |
2650 | |
2651 DCHECK(args.length() == 1); | |
2652 | |
2653 CONVERT_ARG_CHECKED(String, script_name, 0); | |
2654 | |
2655 // Find the requested script. | |
2656 Handle<Object> result = | |
2657 Runtime_GetScriptFromScriptName(Handle<String>(script_name)); | |
2658 return *result; | |
2659 } | |
2660 | |
2661 | |
2662 // Check whether debugger and is about to step into the callback that is passed | 2644 // Check whether debugger and is about to step into the callback that is passed |
2663 // to a built-in function such as Array.forEach. | 2645 // to a built-in function such as Array.forEach. |
2664 RUNTIME_FUNCTION(Runtime_DebugCallbackSupportsStepping) { | 2646 RUNTIME_FUNCTION(Runtime_DebugCallbackSupportsStepping) { |
2665 DCHECK(args.length() == 1); | 2647 DCHECK(args.length() == 1); |
2666 if (!isolate->debug()->is_active() || !isolate->debug()->StepInActive()) { | 2648 if (!isolate->debug()->is_active() || !isolate->debug()->StepInActive()) { |
2667 return isolate->heap()->false_value(); | 2649 return isolate->heap()->false_value(); |
2668 } | 2650 } |
2669 CONVERT_ARG_CHECKED(Object, callback, 0); | 2651 CONVERT_ARG_CHECKED(Object, callback, 0); |
2670 // We do not step into the callback if it's a builtin or not even a function. | 2652 // We do not step into the callback if it's a builtin or not even a function. |
2671 return isolate->heap()->ToBoolean(callback->IsJSFunction() && | 2653 return isolate->heap()->ToBoolean(callback->IsJSFunction() && |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2739 return Smi::FromInt(isolate->debug()->is_active()); | 2721 return Smi::FromInt(isolate->debug()->is_active()); |
2740 } | 2722 } |
2741 | 2723 |
2742 | 2724 |
2743 RUNTIME_FUNCTION(RuntimeReference_DebugBreakInOptimizedCode) { | 2725 RUNTIME_FUNCTION(RuntimeReference_DebugBreakInOptimizedCode) { |
2744 UNIMPLEMENTED(); | 2726 UNIMPLEMENTED(); |
2745 return NULL; | 2727 return NULL; |
2746 } | 2728 } |
2747 } | 2729 } |
2748 } // namespace v8::internal | 2730 } // namespace v8::internal |
OLD | NEW |