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 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 { | 1897 namespace { |
1898 Handle<JSObject> CreateRangeObject(Isolate* isolate, | 1898 Handle<JSObject> CreateRangeObject(Isolate* isolate, const CoverageRange* range, |
1899 const Coverage::Range* range, | |
1900 Handle<String> inner_string, | 1899 Handle<String> inner_string, |
1901 Handle<String> start_string, | 1900 Handle<String> start_string, |
1902 Handle<String> end_string, | 1901 Handle<String> end_string, |
1903 Handle<String> count_string) { | 1902 Handle<String> count_string) { |
1904 HandleScope scope(isolate); | 1903 HandleScope scope(isolate); |
1905 Factory* factory = isolate->factory(); | 1904 Factory* factory = isolate->factory(); |
1906 Handle<JSObject> range_obj = factory->NewJSObjectWithNullProto(); | 1905 Handle<JSObject> range_obj = factory->NewJSObjectWithNullProto(); |
1907 JSObject::AddProperty(range_obj, start_string, | 1906 JSObject::AddProperty(range_obj, start_string, |
1908 factory->NewNumberFromInt(range->start), NONE); | 1907 factory->NewNumberFromInt(range->start), NONE); |
1909 JSObject::AddProperty(range_obj, end_string, | 1908 JSObject::AddProperty(range_obj, end_string, |
1910 factory->NewNumberFromInt(range->end), NONE); | 1909 factory->NewNumberFromInt(range->end), NONE); |
1911 JSObject::AddProperty(range_obj, count_string, | 1910 JSObject::AddProperty(range_obj, count_string, |
1912 factory->NewNumberFromUint(range->count), NONE); | 1911 factory->NewNumberFromUint(range->count), NONE); |
1913 Handle<String> name = factory->anonymous_string(); | 1912 JSObject::AddProperty(range_obj, factory->name_string(), range->name, NONE); |
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()) { | 1913 if (!range->inner.empty()) { |
1921 int size = static_cast<int>(range->inner.size()); | 1914 int size = static_cast<int>(range->inner.size()); |
1922 Handle<FixedArray> inner_array = factory->NewFixedArray(size); | 1915 Handle<FixedArray> inner_array = factory->NewFixedArray(size); |
1923 for (int i = 0; i < size; i++) { | 1916 for (int i = 0; i < size; i++) { |
1924 Handle<JSObject> element = | 1917 Handle<JSObject> element = |
1925 CreateRangeObject(isolate, &range->inner[i], inner_string, | 1918 CreateRangeObject(isolate, &range->inner[i], inner_string, |
1926 start_string, end_string, count_string); | 1919 start_string, end_string, count_string); |
1927 inner_array->set(i, *element); | 1920 inner_array->set(i, *element); |
1928 } | 1921 } |
1929 Handle<JSArray> inner = | 1922 Handle<JSArray> inner = |
1930 factory->NewJSArrayWithElements(inner_array, FAST_ELEMENTS); | 1923 factory->NewJSArrayWithElements(inner_array, FAST_ELEMENTS); |
1931 JSObject::AddProperty(range_obj, inner_string, inner, NONE); | 1924 JSObject::AddProperty(range_obj, inner_string, inner, NONE); |
1932 } | 1925 } |
1933 return scope.CloseAndEscape(range_obj); | 1926 return scope.CloseAndEscape(range_obj); |
1934 } | 1927 } |
1935 } // anonymous namespace | 1928 } // anonymous namespace |
1936 | 1929 |
1937 RUNTIME_FUNCTION(Runtime_DebugCollectCoverage) { | 1930 RUNTIME_FUNCTION(Runtime_DebugCollectCoverage) { |
1938 HandleScope scope(isolate); | 1931 HandleScope scope(isolate); |
1939 // Collect coverage data. | 1932 // Collect coverage data. |
1940 std::vector<Coverage::ScriptData> script_data = Coverage::Collect(isolate); | 1933 std::unique_ptr<Coverage> coverage(Coverage::Collect(isolate)); |
1941 Factory* factory = isolate->factory(); | 1934 Factory* factory = isolate->factory(); |
1942 // Turn the returned data structure into JavaScript. | 1935 // Turn the returned data structure into JavaScript. |
1943 // Create an array of scripts. | 1936 // Create an array of scripts. |
1944 int num_scripts = static_cast<int>(script_data.size()); | 1937 int num_scripts = static_cast<int>(coverage->size()); |
1945 // Prepare property keys. | 1938 // Prepare property keys. |
1946 Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts); | 1939 Handle<FixedArray> scripts_array = factory->NewFixedArray(num_scripts); |
1947 Handle<String> script_string = factory->NewStringFromStaticChars("script"); | 1940 Handle<String> script_string = factory->NewStringFromStaticChars("script"); |
1948 Handle<String> toplevel_string = | 1941 Handle<String> toplevel_string = |
1949 factory->NewStringFromStaticChars("toplevel"); | 1942 factory->NewStringFromStaticChars("toplevel"); |
1950 Handle<String> inner_string = factory->NewStringFromStaticChars("inner"); | 1943 Handle<String> inner_string = factory->NewStringFromStaticChars("inner"); |
1951 Handle<String> start_string = factory->NewStringFromStaticChars("start"); | 1944 Handle<String> start_string = factory->NewStringFromStaticChars("start"); |
1952 Handle<String> end_string = factory->NewStringFromStaticChars("end"); | 1945 Handle<String> end_string = factory->NewStringFromStaticChars("end"); |
1953 Handle<String> count_string = factory->NewStringFromStaticChars("count"); | 1946 Handle<String> count_string = factory->NewStringFromStaticChars("count"); |
1954 for (int i = 0; i < num_scripts; i++) { | 1947 for (int i = 0; i < num_scripts; i++) { |
1955 const auto& data = script_data[i]; | 1948 const auto& data = coverage->at(i); |
1956 HandleScope inner_scope(isolate); | 1949 HandleScope inner_scope(isolate); |
1957 Handle<JSObject> script_obj = factory->NewJSObjectWithNullProto(); | 1950 Handle<JSObject> script_obj = factory->NewJSObjectWithNullProto(); |
1958 Handle<JSObject> wrapper = Script::GetWrapper(data.script); | 1951 Handle<JSObject> wrapper = Script::GetWrapper(data.script); |
1959 JSObject::AddProperty(script_obj, script_string, wrapper, NONE); | 1952 JSObject::AddProperty(script_obj, script_string, wrapper, NONE); |
1960 Handle<JSObject> toplevel = | 1953 Handle<JSObject> toplevel = |
1961 CreateRangeObject(isolate, &data.toplevel, inner_string, start_string, | 1954 CreateRangeObject(isolate, &data.toplevel, inner_string, start_string, |
1962 end_string, count_string); | 1955 end_string, count_string); |
1963 JSObject::AddProperty(script_obj, toplevel_string, toplevel, NONE); | 1956 JSObject::AddProperty(script_obj, toplevel_string, toplevel, NONE); |
1964 scripts_array->set(i, *script_obj); | 1957 scripts_array->set(i, *script_obj); |
1965 } | 1958 } |
1966 return *factory->NewJSArrayWithElements(scripts_array, FAST_ELEMENTS); | 1959 return *factory->NewJSArrayWithElements(scripts_array, FAST_ELEMENTS); |
1967 } | 1960 } |
1968 | 1961 |
1969 RUNTIME_FUNCTION(Runtime_DebugTogglePreciseCoverage) { | 1962 RUNTIME_FUNCTION(Runtime_DebugTogglePreciseCoverage) { |
1970 SealHandleScope shs(isolate); | 1963 SealHandleScope shs(isolate); |
1971 CONVERT_BOOLEAN_ARG_CHECKED(enable, 0); | 1964 CONVERT_BOOLEAN_ARG_CHECKED(enable, 0); |
1972 if (enable) { | 1965 Coverage::TogglePrecise(isolate, enable); |
1973 Coverage::EnablePrecise(isolate); | |
1974 } else { | |
1975 Coverage::DisablePrecise(isolate); | |
1976 } | |
1977 return isolate->heap()->undefined_value(); | 1966 return isolate->heap()->undefined_value(); |
1978 } | 1967 } |
1979 | 1968 |
1980 } // namespace internal | 1969 } // namespace internal |
1981 } // namespace v8 | 1970 } // namespace v8 |
OLD | NEW |