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 1876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1887 SealHandleScope shs(isolate); | 1887 SealHandleScope shs(isolate); |
1888 return Smi::FromInt(isolate->debug()->is_active()); | 1888 return Smi::FromInt(isolate->debug()->is_active()); |
1889 } | 1889 } |
1890 | 1890 |
1891 | 1891 |
1892 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 1892 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
1893 UNIMPLEMENTED(); | 1893 UNIMPLEMENTED(); |
1894 return NULL; | 1894 return NULL; |
1895 } | 1895 } |
1896 | 1896 |
| 1897 namespace { |
| 1898 Handle<JSObject> CreateRangeObject(Isolate* isolate, |
| 1899 const Coverage::Range* range, |
| 1900 Handle<String> inner_string, |
| 1901 Handle<String> start_string, |
| 1902 Handle<String> end_string, |
| 1903 Handle<String> count_string) { |
| 1904 HandleScope scope(isolate); |
| 1905 Factory* factory = isolate->factory(); |
| 1906 Handle<JSObject> range_obj = factory->NewJSObjectWithNullProto(); |
| 1907 JSObject::AddProperty(range_obj, start_string, |
| 1908 factory->NewNumberFromInt(range->start), NONE); |
| 1909 JSObject::AddProperty(range_obj, end_string, |
| 1910 factory->NewNumberFromInt(range->end), NONE); |
| 1911 JSObject::AddProperty(range_obj, count_string, |
| 1912 factory->NewNumberFromUint(range->count), NONE); |
| 1913 Handle<String> name = factory->anonymous_string(); |
| 1914 if (!range->name.empty()) { |
| 1915 Vector<const uc16> name_vector(range->name.data(), |
| 1916 static_cast<int>(range->name.size())); |
| 1917 name = factory->NewStringFromTwoByte(name_vector).ToHandleChecked(); |
| 1918 } |
| 1919 JSObject::AddProperty(range_obj, factory->name_string(), 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 |
1897 RUNTIME_FUNCTION(Runtime_DebugCollectCoverage) { | 1937 RUNTIME_FUNCTION(Runtime_DebugCollectCoverage) { |
1898 HandleScope scope(isolate); | 1938 HandleScope scope(isolate); |
1899 // Collect coverage data. | 1939 // Collect coverage data. |
1900 std::vector<Coverage::ScriptData> scripts = Coverage::Collect(isolate); | 1940 std::vector<Coverage::ScriptData> script_data = Coverage::Collect(isolate); |
1901 Factory* factory = isolate->factory(); | 1941 Factory* factory = isolate->factory(); |
1902 // Turn the returned data structure into JavaScript. | 1942 // Turn the returned data structure into JavaScript. |
1903 // Create an array of scripts. | 1943 // Create an array of scripts. |
1904 int num_scripts = static_cast<int>(scripts.size()); | 1944 int num_scripts = static_cast<int>(script_data.size()); |
1905 // Prepare property keys. | 1945 // Prepare property keys. |
1906 Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts); | 1946 Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts); |
1907 Handle<String> id_string = factory->NewStringFromStaticChars("script_id"); | 1947 Handle<String> script_string = factory->NewStringFromStaticChars("script"); |
1908 Handle<String> entries_string = factory->NewStringFromStaticChars("entries"); | 1948 Handle<String> toplevel_string = |
1909 Handle<String> end_string = factory->NewStringFromStaticChars("end_position"); | 1949 factory->NewStringFromStaticChars("toplevel"); |
| 1950 Handle<String> inner_string = factory->NewStringFromStaticChars("inner"); |
| 1951 Handle<String> start_string = factory->NewStringFromStaticChars("start"); |
| 1952 Handle<String> end_string = factory->NewStringFromStaticChars("end"); |
1910 Handle<String> count_string = factory->NewStringFromStaticChars("count"); | 1953 Handle<String> count_string = factory->NewStringFromStaticChars("count"); |
1911 for (int i = 0; i < num_scripts; i++) { | 1954 for (int i = 0; i < num_scripts; i++) { |
1912 // Create an object for each script, containing the script id and entries. | 1955 const auto& data = script_data[i]; |
1913 const auto& script = scripts[i]; | |
1914 HandleScope inner_scope(isolate); | 1956 HandleScope inner_scope(isolate); |
1915 int num_entries = static_cast<int>(script.entries.size()); | |
1916 Handle<FixedArray> entries_array = factory->NewFixedArray(num_entries); | |
1917 for (int j = 0; j < num_entries; j++) { | |
1918 // Create an object for each entry, containing the end position and count. | |
1919 const auto& entry = script.entries[j]; | |
1920 Handle<JSObject> entry_obj = factory->NewJSObjectWithNullProto(); | |
1921 JSObject::AddProperty(entry_obj, end_string, | |
1922 factory->NewNumberFromInt(entry.end_position), | |
1923 NONE); | |
1924 JSObject::AddProperty(entry_obj, count_string, | |
1925 factory->NewNumberFromUint(entry.count), NONE); | |
1926 entries_array->set(j, *entry_obj); | |
1927 } | |
1928 Handle<JSObject> script_obj = factory->NewJSObjectWithNullProto(); | 1957 Handle<JSObject> script_obj = factory->NewJSObjectWithNullProto(); |
1929 JSObject::AddProperty(script_obj, id_string, | 1958 Handle<JSObject> wrapper = Script::GetWrapper(data.script); |
1930 factory->NewNumberFromInt(script.script_id), NONE); | 1959 JSObject::AddProperty(script_obj, script_string, wrapper, NONE); |
1931 JSObject::AddProperty( | 1960 Handle<JSObject> toplevel = |
1932 script_obj, entries_string, | 1961 CreateRangeObject(isolate, &data.toplevel, inner_string, start_string, |
1933 factory->NewJSArrayWithElements(entries_array, FAST_ELEMENTS), NONE); | 1962 end_string, count_string); |
| 1963 JSObject::AddProperty(script_obj, toplevel_string, toplevel, NONE); |
1934 scripts_array->set(i, *script_obj); | 1964 scripts_array->set(i, *script_obj); |
1935 } | 1965 } |
1936 return *factory->NewJSArrayWithElements(scripts_array, FAST_ELEMENTS); | 1966 return *factory->NewJSArrayWithElements(scripts_array, FAST_ELEMENTS); |
1937 } | 1967 } |
1938 | 1968 |
1939 RUNTIME_FUNCTION(Runtime_DebugTogglePreciseCoverage) { | 1969 RUNTIME_FUNCTION(Runtime_DebugTogglePreciseCoverage) { |
1940 SealHandleScope shs(isolate); | 1970 SealHandleScope shs(isolate); |
1941 CONVERT_BOOLEAN_ARG_CHECKED(enable, 0); | 1971 CONVERT_BOOLEAN_ARG_CHECKED(enable, 0); |
1942 if (enable) { | 1972 if (enable) { |
1943 Coverage::EnablePrecise(isolate); | 1973 Coverage::EnablePrecise(isolate); |
1944 } else { | 1974 } else { |
1945 Coverage::DisablePrecise(isolate); | 1975 Coverage::DisablePrecise(isolate); |
1946 } | 1976 } |
1947 return isolate->heap()->undefined_value(); | 1977 return isolate->heap()->undefined_value(); |
1948 } | 1978 } |
1949 | 1979 |
1950 } // namespace internal | 1980 } // namespace internal |
1951 } // namespace v8 | 1981 } // namespace v8 |
OLD | NEW |