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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
| 9 #include "src/debug/debug-coverage.h" |
9 #include "src/debug/debug-evaluate.h" | 10 #include "src/debug/debug-evaluate.h" |
10 #include "src/debug/debug-frames.h" | 11 #include "src/debug/debug-frames.h" |
11 #include "src/debug/debug-scopes.h" | 12 #include "src/debug/debug-scopes.h" |
12 #include "src/debug/debug.h" | 13 #include "src/debug/debug.h" |
13 #include "src/debug/liveedit.h" | 14 #include "src/debug/liveedit.h" |
14 #include "src/frames-inl.h" | 15 #include "src/frames-inl.h" |
15 #include "src/globals.h" | 16 #include "src/globals.h" |
16 #include "src/interpreter/bytecodes.h" | 17 #include "src/interpreter/bytecodes.h" |
17 #include "src/interpreter/interpreter.h" | 18 #include "src/interpreter/interpreter.h" |
18 #include "src/isolate-inl.h" | 19 #include "src/isolate-inl.h" |
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); | 1238 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); |
1238 | 1239 |
1239 RETURN_RESULT_OR_FAILURE(isolate, DebugEvaluate::Global(isolate, source)); | 1240 RETURN_RESULT_OR_FAILURE(isolate, DebugEvaluate::Global(isolate, source)); |
1240 } | 1241 } |
1241 | 1242 |
1242 | 1243 |
1243 RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) { | 1244 RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) { |
1244 HandleScope scope(isolate); | 1245 HandleScope scope(isolate); |
1245 DCHECK_EQ(0, args.length()); | 1246 DCHECK_EQ(0, args.length()); |
1246 | 1247 |
1247 // This runtime function is used by the debugger to determine whether the | |
1248 // debugger is active or not. Hence we fail gracefully here and don't crash. | |
1249 if (!isolate->debug()->is_active()) return isolate->ThrowIllegalOperation(); | |
1250 | |
1251 Handle<FixedArray> instances; | 1248 Handle<FixedArray> instances; |
1252 { | 1249 { |
1253 DebugScope debug_scope(isolate->debug()); | 1250 DebugScope debug_scope(isolate->debug()); |
1254 if (debug_scope.failed()) { | 1251 if (debug_scope.failed()) { |
1255 DCHECK(isolate->has_pending_exception()); | 1252 DCHECK(isolate->has_pending_exception()); |
1256 return isolate->heap()->exception(); | 1253 return isolate->heap()->exception(); |
1257 } | 1254 } |
1258 // Fill the script objects. | 1255 // Fill the script objects. |
1259 instances = isolate->debug()->GetLoadedScripts(); | 1256 instances = isolate->debug()->GetLoadedScripts(); |
1260 } | 1257 } |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1889 SealHandleScope shs(isolate); | 1886 SealHandleScope shs(isolate); |
1890 return Smi::FromInt(isolate->debug()->is_active()); | 1887 return Smi::FromInt(isolate->debug()->is_active()); |
1891 } | 1888 } |
1892 | 1889 |
1893 | 1890 |
1894 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 1891 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
1895 UNIMPLEMENTED(); | 1892 UNIMPLEMENTED(); |
1896 return NULL; | 1893 return NULL; |
1897 } | 1894 } |
1898 | 1895 |
| 1896 RUNTIME_FUNCTION(Runtime_DebugCollectCoverage) { |
| 1897 HandleScope scope(isolate); |
| 1898 // Collect coverage data. |
| 1899 std::vector<Coverage::ScriptData> scripts = Coverage::Collect(isolate); |
| 1900 Factory* factory = isolate->factory(); |
| 1901 // Turn the returned data structure into JavaScript. |
| 1902 // Create an array of scripts. |
| 1903 int num_scripts = static_cast<int>(scripts.size()); |
| 1904 // Prepare property keys. |
| 1905 Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts); |
| 1906 Handle<String> id_string = factory->NewStringFromStaticChars("script_id"); |
| 1907 Handle<String> entries_string = factory->NewStringFromStaticChars("entries"); |
| 1908 Handle<String> end_string = factory->NewStringFromStaticChars("end_position"); |
| 1909 Handle<String> count_string = factory->NewStringFromStaticChars("count"); |
| 1910 for (int i = 0; i < num_scripts; i++) { |
| 1911 // Create an object for each script, containing the script id and entries. |
| 1912 const auto& script = scripts[i]; |
| 1913 HandleScope inner_scope(isolate); |
| 1914 int num_entries = static_cast<int>(script.entries.size()); |
| 1915 Handle<FixedArray> entries_array = factory->NewFixedArray(num_entries); |
| 1916 for (int j = 0; j < num_entries; j++) { |
| 1917 // Create an object for each entry, containing the end position and count. |
| 1918 const auto& entry = script.entries[j]; |
| 1919 Handle<JSObject> entry_obj = factory->NewJSObjectWithNullProto(); |
| 1920 JSObject::AddProperty(entry_obj, end_string, |
| 1921 factory->NewNumberFromInt(entry.end_position), |
| 1922 NONE); |
| 1923 JSObject::AddProperty(entry_obj, count_string, |
| 1924 factory->NewNumberFromUint(entry.count), NONE); |
| 1925 entries_array->set(j, *entry_obj); |
| 1926 } |
| 1927 Handle<JSObject> script_obj = factory->NewJSObjectWithNullProto(); |
| 1928 JSObject::AddProperty(script_obj, id_string, |
| 1929 factory->NewNumberFromInt(script.script_id), NONE); |
| 1930 JSObject::AddProperty( |
| 1931 script_obj, entries_string, |
| 1932 factory->NewJSArrayWithElements(entries_array, FAST_ELEMENTS), NONE); |
| 1933 scripts_array->set(i, *script_obj); |
| 1934 } |
| 1935 return *factory->NewJSArrayWithElements(scripts_array, FAST_ELEMENTS); |
| 1936 } |
| 1937 |
1899 } // namespace internal | 1938 } // namespace internal |
1900 } // namespace v8 | 1939 } // namespace v8 |
OLD | NEW |