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-coverage.h" |
10 #include "src/debug/debug-evaluate.h" | 10 #include "src/debug/debug-evaluate.h" |
(...skipping 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1888 isolate->debug()->NextAsyncTaskId(promise), 0); | 1888 isolate->debug()->NextAsyncTaskId(promise), 0); |
1889 } | 1889 } |
1890 return isolate->heap()->undefined_value(); | 1890 return isolate->heap()->undefined_value(); |
1891 } | 1891 } |
1892 | 1892 |
1893 RUNTIME_FUNCTION(Runtime_DebugIsActive) { | 1893 RUNTIME_FUNCTION(Runtime_DebugIsActive) { |
1894 SealHandleScope shs(isolate); | 1894 SealHandleScope shs(isolate); |
1895 return Smi::FromInt(isolate->debug()->is_active()); | 1895 return Smi::FromInt(isolate->debug()->is_active()); |
1896 } | 1896 } |
1897 | 1897 |
1898 | |
1899 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 1898 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
1900 UNIMPLEMENTED(); | 1899 UNIMPLEMENTED(); |
1901 return NULL; | 1900 return NULL; |
1902 } | 1901 } |
1903 | 1902 |
1904 namespace { | |
1905 Handle<JSObject> CreateRangeObject(Isolate* isolate, const CoverageRange* range, | |
1906 Handle<String> inner_string, | |
1907 Handle<String> start_string, | |
1908 Handle<String> end_string, | |
1909 Handle<String> count_string) { | |
1910 HandleScope scope(isolate); | |
1911 Factory* factory = isolate->factory(); | |
1912 Handle<JSObject> range_obj = factory->NewJSObjectWithNullProto(); | |
1913 JSObject::AddProperty(range_obj, start_string, | |
1914 factory->NewNumberFromInt(range->start), NONE); | |
1915 JSObject::AddProperty(range_obj, end_string, | |
1916 factory->NewNumberFromInt(range->end), NONE); | |
1917 JSObject::AddProperty(range_obj, count_string, | |
1918 factory->NewNumberFromUint(range->count), NONE); | |
1919 JSObject::AddProperty(range_obj, factory->name_string(), range->name, NONE); | |
1920 if (!range->inner.empty()) { | |
1921 int size = static_cast<int>(range->inner.size()); | |
1922 Handle<FixedArray> inner_array = factory->NewFixedArray(size); | |
1923 for (int i = 0; i < size; i++) { | |
1924 Handle<JSObject> element = | |
1925 CreateRangeObject(isolate, &range->inner[i], inner_string, | |
1926 start_string, end_string, count_string); | |
1927 inner_array->set(i, *element); | |
1928 } | |
1929 Handle<JSArray> inner = | |
1930 factory->NewJSArrayWithElements(inner_array, FAST_ELEMENTS); | |
1931 JSObject::AddProperty(range_obj, inner_string, inner, NONE); | |
1932 } | |
1933 return scope.CloseAndEscape(range_obj); | |
1934 } | |
1935 } // anonymous namespace | |
1936 | |
1937 RUNTIME_FUNCTION(Runtime_DebugCollectCoverage) { | 1903 RUNTIME_FUNCTION(Runtime_DebugCollectCoverage) { |
1938 HandleScope scope(isolate); | 1904 HandleScope scope(isolate); |
| 1905 DCHECK_EQ(0, args.length()); |
1939 // Collect coverage data. | 1906 // Collect coverage data. |
1940 std::unique_ptr<Coverage> coverage(Coverage::Collect(isolate)); | 1907 std::unique_ptr<Coverage> coverage(Coverage::Collect(isolate, false)); |
1941 Factory* factory = isolate->factory(); | 1908 Factory* factory = isolate->factory(); |
1942 // Turn the returned data structure into JavaScript. | 1909 // Turn the returned data structure into JavaScript. |
1943 // Create an array of scripts. | 1910 // Create an array of scripts. |
1944 int num_scripts = static_cast<int>(coverage->size()); | 1911 int num_scripts = static_cast<int>(coverage->size()); |
1945 // Prepare property keys. | 1912 // Prepare property keys. |
1946 Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts); | 1913 Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts); |
1947 Handle<String> script_string = factory->NewStringFromStaticChars("script"); | 1914 Handle<String> script_string = factory->NewStringFromStaticChars("script"); |
1948 Handle<String> toplevel_string = | |
1949 factory->NewStringFromStaticChars("toplevel"); | |
1950 Handle<String> inner_string = factory->NewStringFromStaticChars("inner"); | |
1951 Handle<String> start_string = factory->NewStringFromStaticChars("start"); | 1915 Handle<String> start_string = factory->NewStringFromStaticChars("start"); |
1952 Handle<String> end_string = factory->NewStringFromStaticChars("end"); | 1916 Handle<String> end_string = factory->NewStringFromStaticChars("end"); |
1953 Handle<String> count_string = factory->NewStringFromStaticChars("count"); | 1917 Handle<String> count_string = factory->NewStringFromStaticChars("count"); |
1954 for (int i = 0; i < num_scripts; i++) { | 1918 for (int i = 0; i < num_scripts; i++) { |
1955 const auto& data = coverage->at(i); | 1919 const auto& script_data = coverage->at(i); |
1956 HandleScope inner_scope(isolate); | 1920 HandleScope inner_scope(isolate); |
1957 Handle<JSObject> script_obj = factory->NewJSObjectWithNullProto(); | 1921 int num_functions = static_cast<int>(script_data.functions.size()); |
1958 Handle<JSObject> wrapper = Script::GetWrapper(data.script); | 1922 Handle<FixedArray> functions_array = factory->NewFixedArray(num_functions); |
| 1923 for (int j = 0; j < num_functions; j++) { |
| 1924 const auto& function_data = script_data.functions[j]; |
| 1925 Handle<JSObject> range_obj = factory->NewJSObjectWithNullProto(); |
| 1926 JSObject::AddProperty(range_obj, start_string, |
| 1927 factory->NewNumberFromInt(function_data.start), |
| 1928 NONE); |
| 1929 JSObject::AddProperty(range_obj, end_string, |
| 1930 factory->NewNumberFromInt(function_data.end), NONE); |
| 1931 JSObject::AddProperty(range_obj, count_string, |
| 1932 factory->NewNumberFromUint(function_data.count), |
| 1933 NONE); |
| 1934 functions_array->set(j, *range_obj); |
| 1935 } |
| 1936 Handle<JSArray> script_obj = |
| 1937 factory->NewJSArrayWithElements(functions_array, FAST_ELEMENTS); |
| 1938 Handle<JSObject> wrapper = Script::GetWrapper(script_data.script); |
1959 JSObject::AddProperty(script_obj, script_string, wrapper, NONE); | 1939 JSObject::AddProperty(script_obj, script_string, wrapper, NONE); |
1960 Handle<JSObject> toplevel = | |
1961 CreateRangeObject(isolate, &data.toplevel, inner_string, start_string, | |
1962 end_string, count_string); | |
1963 JSObject::AddProperty(script_obj, toplevel_string, toplevel, NONE); | |
1964 scripts_array->set(i, *script_obj); | 1940 scripts_array->set(i, *script_obj); |
1965 } | 1941 } |
1966 return *factory->NewJSArrayWithElements(scripts_array, FAST_ELEMENTS); | 1942 return *factory->NewJSArrayWithElements(scripts_array, FAST_ELEMENTS); |
1967 } | 1943 } |
1968 | 1944 |
1969 RUNTIME_FUNCTION(Runtime_DebugTogglePreciseCoverage) { | 1945 RUNTIME_FUNCTION(Runtime_DebugTogglePreciseCoverage) { |
1970 SealHandleScope shs(isolate); | 1946 SealHandleScope shs(isolate); |
1971 CONVERT_BOOLEAN_ARG_CHECKED(enable, 0); | 1947 CONVERT_BOOLEAN_ARG_CHECKED(enable, 0); |
1972 Coverage::TogglePrecise(isolate, enable); | 1948 Coverage::TogglePrecise(isolate, enable); |
1973 return isolate->heap()->undefined_value(); | 1949 return isolate->heap()->undefined_value(); |
1974 } | 1950 } |
1975 | 1951 |
1976 } // namespace internal | 1952 } // namespace internal |
1977 } // namespace v8 | 1953 } // namespace v8 |
OLD | NEW |