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 12669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12680 counter++; | 12680 counter++; |
12681 } | 12681 } |
12682 return counter; | 12682 return counter; |
12683 } | 12683 } |
12684 | 12684 |
12685 // For a script finds all SharedFunctionInfo's in the heap that points | 12685 // For a script finds all SharedFunctionInfo's in the heap that points |
12686 // to this script. Returns JSArray of SharedFunctionInfo wrapped | 12686 // to this script. Returns JSArray of SharedFunctionInfo wrapped |
12687 // in OpaqueReferences. | 12687 // in OpaqueReferences. |
12688 RUNTIME_FUNCTION(MaybeObject*, | 12688 RUNTIME_FUNCTION(MaybeObject*, |
12689 Runtime_LiveEditFindSharedFunctionInfosForScript) { | 12689 Runtime_LiveEditFindSharedFunctionInfosForScript) { |
| 12690 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12690 ASSERT(args.length() == 1); | 12691 ASSERT(args.length() == 1); |
12691 HandleScope scope(isolate); | 12692 HandleScope scope(isolate); |
12692 CONVERT_ARG_CHECKED(JSValue, script_value, 0); | 12693 CONVERT_ARG_CHECKED(JSValue, script_value, 0); |
12693 | 12694 |
12694 | 12695 |
12695 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); | 12696 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); |
12696 | 12697 |
12697 const int kBufferSize = 32; | 12698 const int kBufferSize = 32; |
12698 | 12699 |
12699 Handle<FixedArray> array; | 12700 Handle<FixedArray> array; |
(...skipping 26 matching lines...) Expand all Loading... |
12726 } | 12727 } |
12727 | 12728 |
12728 // For a script calculates compilation information about all its functions. | 12729 // For a script calculates compilation information about all its functions. |
12729 // The script source is explicitly specified by the second argument. | 12730 // The script source is explicitly specified by the second argument. |
12730 // The source of the actual script is not used, however it is important that | 12731 // The source of the actual script is not used, however it is important that |
12731 // all generated code keeps references to this particular instance of script. | 12732 // all generated code keeps references to this particular instance of script. |
12732 // Returns a JSArray of compilation infos. The array is ordered so that | 12733 // Returns a JSArray of compilation infos. The array is ordered so that |
12733 // each function with all its descendant is always stored in a continues range | 12734 // each function with all its descendant is always stored in a continues range |
12734 // with the function itself going first. The root function is a script function. | 12735 // with the function itself going first. The root function is a script function. |
12735 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditGatherCompileInfo) { | 12736 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditGatherCompileInfo) { |
| 12737 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12736 ASSERT(args.length() == 2); | 12738 ASSERT(args.length() == 2); |
12737 HandleScope scope(isolate); | 12739 HandleScope scope(isolate); |
12738 CONVERT_ARG_CHECKED(JSValue, script, 0); | 12740 CONVERT_ARG_CHECKED(JSValue, script, 0); |
12739 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); | 12741 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); |
12740 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); | 12742 Handle<Script> script_handle = Handle<Script>(Script::cast(script->value())); |
12741 | 12743 |
12742 JSArray* result = LiveEdit::GatherCompileInfo(script_handle, source); | 12744 JSArray* result = LiveEdit::GatherCompileInfo(script_handle, source); |
12743 | 12745 |
12744 if (isolate->has_pending_exception()) { | 12746 if (isolate->has_pending_exception()) { |
12745 return Failure::Exception(); | 12747 return Failure::Exception(); |
12746 } | 12748 } |
12747 | 12749 |
12748 return result; | 12750 return result; |
12749 } | 12751 } |
12750 | 12752 |
12751 // Changes the source of the script to a new_source. | 12753 // Changes the source of the script to a new_source. |
12752 // If old_script_name is provided (i.e. is a String), also creates a copy of | 12754 // If old_script_name is provided (i.e. is a String), also creates a copy of |
12753 // the script with its original source and sends notification to debugger. | 12755 // the script with its original source and sends notification to debugger. |
12754 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceScript) { | 12756 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceScript) { |
| 12757 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12755 ASSERT(args.length() == 3); | 12758 ASSERT(args.length() == 3); |
12756 HandleScope scope(isolate); | 12759 HandleScope scope(isolate); |
12757 CONVERT_ARG_CHECKED(JSValue, original_script_value, 0); | 12760 CONVERT_ARG_CHECKED(JSValue, original_script_value, 0); |
12758 CONVERT_ARG_HANDLE_CHECKED(String, new_source, 1); | 12761 CONVERT_ARG_HANDLE_CHECKED(String, new_source, 1); |
12759 Handle<Object> old_script_name(args[2], isolate); | 12762 Handle<Object> old_script_name(args[2], isolate); |
12760 | 12763 |
12761 RUNTIME_ASSERT(original_script_value->value()->IsScript()); | 12764 RUNTIME_ASSERT(original_script_value->value()->IsScript()); |
12762 Handle<Script> original_script(Script::cast(original_script_value->value())); | 12765 Handle<Script> original_script(Script::cast(original_script_value->value())); |
12763 | 12766 |
12764 Object* old_script = LiveEdit::ChangeScriptSource(original_script, | 12767 Object* old_script = LiveEdit::ChangeScriptSource(original_script, |
12765 new_source, | 12768 new_source, |
12766 old_script_name); | 12769 old_script_name); |
12767 | 12770 |
12768 if (old_script->IsScript()) { | 12771 if (old_script->IsScript()) { |
12769 Handle<Script> script_handle(Script::cast(old_script)); | 12772 Handle<Script> script_handle(Script::cast(old_script)); |
12770 return *(GetScriptWrapper(script_handle)); | 12773 return *(GetScriptWrapper(script_handle)); |
12771 } else { | 12774 } else { |
12772 return isolate->heap()->null_value(); | 12775 return isolate->heap()->null_value(); |
12773 } | 12776 } |
12774 } | 12777 } |
12775 | 12778 |
12776 | 12779 |
12777 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSourceUpdated) { | 12780 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSourceUpdated) { |
| 12781 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12778 ASSERT(args.length() == 1); | 12782 ASSERT(args.length() == 1); |
12779 HandleScope scope(isolate); | 12783 HandleScope scope(isolate); |
12780 CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_info, 0); | 12784 CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_info, 0); |
12781 return LiveEdit::FunctionSourceUpdated(shared_info); | 12785 return LiveEdit::FunctionSourceUpdated(shared_info); |
12782 } | 12786 } |
12783 | 12787 |
12784 | 12788 |
12785 // Replaces code of SharedFunctionInfo with a new one. | 12789 // Replaces code of SharedFunctionInfo with a new one. |
12786 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceFunctionCode) { | 12790 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceFunctionCode) { |
| 12791 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12787 ASSERT(args.length() == 2); | 12792 ASSERT(args.length() == 2); |
12788 HandleScope scope(isolate); | 12793 HandleScope scope(isolate); |
12789 CONVERT_ARG_HANDLE_CHECKED(JSArray, new_compile_info, 0); | 12794 CONVERT_ARG_HANDLE_CHECKED(JSArray, new_compile_info, 0); |
12790 CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_info, 1); | 12795 CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_info, 1); |
12791 | 12796 |
12792 return LiveEdit::ReplaceFunctionCode(new_compile_info, shared_info); | 12797 return LiveEdit::ReplaceFunctionCode(new_compile_info, shared_info); |
12793 } | 12798 } |
12794 | 12799 |
12795 // Connects SharedFunctionInfo to another script. | 12800 // Connects SharedFunctionInfo to another script. |
12796 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSetScript) { | 12801 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditFunctionSetScript) { |
| 12802 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12797 ASSERT(args.length() == 2); | 12803 ASSERT(args.length() == 2); |
12798 HandleScope scope(isolate); | 12804 HandleScope scope(isolate); |
12799 Handle<Object> function_object(args[0], isolate); | 12805 Handle<Object> function_object(args[0], isolate); |
12800 Handle<Object> script_object(args[1], isolate); | 12806 Handle<Object> script_object(args[1], isolate); |
12801 | 12807 |
12802 if (function_object->IsJSValue()) { | 12808 if (function_object->IsJSValue()) { |
12803 Handle<JSValue> function_wrapper = Handle<JSValue>::cast(function_object); | 12809 Handle<JSValue> function_wrapper = Handle<JSValue>::cast(function_object); |
12804 if (script_object->IsJSValue()) { | 12810 if (script_object->IsJSValue()) { |
12805 RUNTIME_ASSERT(JSValue::cast(*script_object)->value()->IsScript()); | 12811 RUNTIME_ASSERT(JSValue::cast(*script_object)->value()->IsScript()); |
12806 Script* script = Script::cast(JSValue::cast(*script_object)->value()); | 12812 Script* script = Script::cast(JSValue::cast(*script_object)->value()); |
12807 script_object = Handle<Object>(script, isolate); | 12813 script_object = Handle<Object>(script, isolate); |
12808 } | 12814 } |
12809 | 12815 |
12810 LiveEdit::SetFunctionScript(function_wrapper, script_object); | 12816 LiveEdit::SetFunctionScript(function_wrapper, script_object); |
12811 } else { | 12817 } else { |
12812 // Just ignore this. We may not have a SharedFunctionInfo for some functions | 12818 // Just ignore this. We may not have a SharedFunctionInfo for some functions |
12813 // and we check it in this function. | 12819 // and we check it in this function. |
12814 } | 12820 } |
12815 | 12821 |
12816 return isolate->heap()->undefined_value(); | 12822 return isolate->heap()->undefined_value(); |
12817 } | 12823 } |
12818 | 12824 |
12819 | 12825 |
12820 // In a code of a parent function replaces original function as embedded object | 12826 // In a code of a parent function replaces original function as embedded object |
12821 // with a substitution one. | 12827 // with a substitution one. |
12822 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceRefToNestedFunction) { | 12828 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditReplaceRefToNestedFunction) { |
| 12829 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12823 ASSERT(args.length() == 3); | 12830 ASSERT(args.length() == 3); |
12824 HandleScope scope(isolate); | 12831 HandleScope scope(isolate); |
12825 | 12832 |
12826 CONVERT_ARG_HANDLE_CHECKED(JSValue, parent_wrapper, 0); | 12833 CONVERT_ARG_HANDLE_CHECKED(JSValue, parent_wrapper, 0); |
12827 CONVERT_ARG_HANDLE_CHECKED(JSValue, orig_wrapper, 1); | 12834 CONVERT_ARG_HANDLE_CHECKED(JSValue, orig_wrapper, 1); |
12828 CONVERT_ARG_HANDLE_CHECKED(JSValue, subst_wrapper, 2); | 12835 CONVERT_ARG_HANDLE_CHECKED(JSValue, subst_wrapper, 2); |
12829 | 12836 |
12830 LiveEdit::ReplaceRefToNestedFunction(parent_wrapper, orig_wrapper, | 12837 LiveEdit::ReplaceRefToNestedFunction(parent_wrapper, orig_wrapper, |
12831 subst_wrapper); | 12838 subst_wrapper); |
12832 | 12839 |
12833 return isolate->heap()->undefined_value(); | 12840 return isolate->heap()->undefined_value(); |
12834 } | 12841 } |
12835 | 12842 |
12836 | 12843 |
12837 // Updates positions of a shared function info (first parameter) according | 12844 // Updates positions of a shared function info (first parameter) according |
12838 // to script source change. Text change is described in second parameter as | 12845 // to script source change. Text change is described in second parameter as |
12839 // array of groups of 3 numbers: | 12846 // array of groups of 3 numbers: |
12840 // (change_begin, change_end, change_end_new_position). | 12847 // (change_begin, change_end, change_end_new_position). |
12841 // Each group describes a change in text; groups are sorted by change_begin. | 12848 // Each group describes a change in text; groups are sorted by change_begin. |
12842 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditPatchFunctionPositions) { | 12849 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditPatchFunctionPositions) { |
| 12850 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12843 ASSERT(args.length() == 2); | 12851 ASSERT(args.length() == 2); |
12844 HandleScope scope(isolate); | 12852 HandleScope scope(isolate); |
12845 CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0); | 12853 CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0); |
12846 CONVERT_ARG_HANDLE_CHECKED(JSArray, position_change_array, 1); | 12854 CONVERT_ARG_HANDLE_CHECKED(JSArray, position_change_array, 1); |
12847 | 12855 |
12848 return LiveEdit::PatchFunctionPositions(shared_array, position_change_array); | 12856 return LiveEdit::PatchFunctionPositions(shared_array, position_change_array); |
12849 } | 12857 } |
12850 | 12858 |
12851 | 12859 |
12852 // For array of SharedFunctionInfo's (each wrapped in JSValue) | 12860 // For array of SharedFunctionInfo's (each wrapped in JSValue) |
12853 // checks that none of them have activations on stacks (of any thread). | 12861 // checks that none of them have activations on stacks (of any thread). |
12854 // Returns array of the same length with corresponding results of | 12862 // Returns array of the same length with corresponding results of |
12855 // LiveEdit::FunctionPatchabilityStatus type. | 12863 // LiveEdit::FunctionPatchabilityStatus type. |
12856 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) { | 12864 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCheckAndDropActivations) { |
| 12865 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12857 ASSERT(args.length() == 2); | 12866 ASSERT(args.length() == 2); |
12858 HandleScope scope(isolate); | 12867 HandleScope scope(isolate); |
12859 CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0); | 12868 CONVERT_ARG_HANDLE_CHECKED(JSArray, shared_array, 0); |
12860 CONVERT_BOOLEAN_ARG_CHECKED(do_drop, 1); | 12869 CONVERT_BOOLEAN_ARG_CHECKED(do_drop, 1); |
12861 | 12870 |
12862 return *LiveEdit::CheckAndDropActivations(shared_array, do_drop, | 12871 return *LiveEdit::CheckAndDropActivations(shared_array, do_drop, |
12863 isolate->runtime_zone()); | 12872 isolate->runtime_zone()); |
12864 } | 12873 } |
12865 | 12874 |
12866 // Compares 2 strings line-by-line, then token-wise and returns diff in form | 12875 // Compares 2 strings line-by-line, then token-wise and returns diff in form |
12867 // of JSArray of triplets (pos1, pos1_end, pos2_end) describing list | 12876 // of JSArray of triplets (pos1, pos1_end, pos2_end) describing list |
12868 // of diff chunks. | 12877 // of diff chunks. |
12869 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCompareStrings) { | 12878 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCompareStrings) { |
| 12879 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12870 ASSERT(args.length() == 2); | 12880 ASSERT(args.length() == 2); |
12871 HandleScope scope(isolate); | 12881 HandleScope scope(isolate); |
12872 CONVERT_ARG_HANDLE_CHECKED(String, s1, 0); | 12882 CONVERT_ARG_HANDLE_CHECKED(String, s1, 0); |
12873 CONVERT_ARG_HANDLE_CHECKED(String, s2, 1); | 12883 CONVERT_ARG_HANDLE_CHECKED(String, s2, 1); |
12874 | 12884 |
12875 return *LiveEdit::CompareStrings(s1, s2); | 12885 return *LiveEdit::CompareStrings(s1, s2); |
12876 } | 12886 } |
12877 | 12887 |
12878 | 12888 |
12879 // Restarts a call frame and completely drops all frames above. | 12889 // Restarts a call frame and completely drops all frames above. |
12880 // Returns true if successful. Otherwise returns undefined or an error message. | 12890 // Returns true if successful. Otherwise returns undefined or an error message. |
12881 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditRestartFrame) { | 12891 RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditRestartFrame) { |
| 12892 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12882 HandleScope scope(isolate); | 12893 HandleScope scope(isolate); |
12883 ASSERT(args.length() == 2); | 12894 ASSERT(args.length() == 2); |
12884 | 12895 |
12885 // Check arguments. | 12896 // Check arguments. |
12886 Object* check; | 12897 Object* check; |
12887 { MaybeObject* maybe_check = Runtime_CheckExecutionState( | 12898 { MaybeObject* maybe_check = Runtime_CheckExecutionState( |
12888 RUNTIME_ARGUMENTS(isolate, args)); | 12899 RUNTIME_ARGUMENTS(isolate, args)); |
12889 if (!maybe_check->ToObject(&check)) return maybe_check; | 12900 if (!maybe_check->ToObject(&check)) return maybe_check; |
12890 } | 12901 } |
12891 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]); | 12902 CONVERT_NUMBER_CHECKED(int, index, Int32, args[1]); |
(...skipping 19 matching lines...) Expand all Loading... |
12911 if (error_message) { | 12922 if (error_message) { |
12912 return *(isolate->factory()->LookupAsciiSymbol(error_message)); | 12923 return *(isolate->factory()->LookupAsciiSymbol(error_message)); |
12913 } | 12924 } |
12914 return heap->true_value(); | 12925 return heap->true_value(); |
12915 } | 12926 } |
12916 | 12927 |
12917 | 12928 |
12918 // A testing entry. Returns statement position which is the closest to | 12929 // A testing entry. Returns statement position which is the closest to |
12919 // source_position. | 12930 // source_position. |
12920 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionCodePositionFromSource) { | 12931 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFunctionCodePositionFromSource) { |
| 12932 CHECK(isolate->debugger()->is_live_edit_enabled()); |
12921 ASSERT(args.length() == 2); | 12933 ASSERT(args.length() == 2); |
12922 HandleScope scope(isolate); | 12934 HandleScope scope(isolate); |
12923 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 12935 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
12924 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); | 12936 CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); |
12925 | 12937 |
12926 Handle<Code> code(function->code(), isolate); | 12938 Handle<Code> code(function->code(), isolate); |
12927 | 12939 |
12928 if (code->kind() != Code::FUNCTION && | 12940 if (code->kind() != Code::FUNCTION && |
12929 code->kind() != Code::OPTIMIZED_FUNCTION) { | 12941 code->kind() != Code::OPTIMIZED_FUNCTION) { |
12930 return isolate->heap()->undefined_value(); | 12942 return isolate->heap()->undefined_value(); |
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13718 // Handle last resort GC and make sure to allow future allocations | 13730 // Handle last resort GC and make sure to allow future allocations |
13719 // to grow the heap without causing GCs (if possible). | 13731 // to grow the heap without causing GCs (if possible). |
13720 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13732 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13721 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13733 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13722 "Runtime::PerformGC"); | 13734 "Runtime::PerformGC"); |
13723 } | 13735 } |
13724 } | 13736 } |
13725 | 13737 |
13726 | 13738 |
13727 } } // namespace v8::internal | 13739 } } // namespace v8::internal |
OLD | NEW |