@@ -1714,144 +1714,6 @@ struct JSHistogramData {
1714
1714
HistogramID histogramId;
1715
1715
};
1716
1716
1717
- bool internal_JSHistogram_CoerceValue (JSContext* aCx,
1718
- JS::Handle<JS::Value> aElement,
1719
- HistogramID aId, uint32_t aHistogramType,
1720
- uint32_t & aValue) {
1721
- if (aElement.isString ()) {
1722
- // Strings only allowed for categorical histograms
1723
- if (aHistogramType != nsITelemetry::HISTOGRAM_CATEGORICAL) {
1724
- LogToBrowserConsole (
1725
- nsIScriptError::errorFlag,
1726
- nsLiteralString (
1727
- u" String argument only allowed for categorical histogram" ));
1728
- return false ;
1729
- }
1730
-
1731
- // Label is given by the string argument
1732
- nsAutoJSString label;
1733
- if (!label.init (aCx, aElement)) {
1734
- LogToBrowserConsole (nsIScriptError::errorFlag,
1735
- u" Invalid string parameter" _ns);
1736
- return false ;
1737
- }
1738
-
1739
- // Get the label id for accumulation
1740
- nsresult rv = gHistogramInfos [aId].label_id (
1741
- NS_ConvertUTF16toUTF8 (label).get(), &aValue);
1742
- if (NS_FAILED(rv)) {
1743
- nsPrintfCString msg (" '%s' is an invalid string label" ,
1744
- NS_ConvertUTF16toUTF8 (label).get());
1745
- LogToBrowserConsole (nsIScriptError::errorFlag,
1746
- NS_ConvertUTF8toUTF16 (msg));
1747
- return false ;
1748
- }
1749
- } else if (!(aElement.isNumber () || aElement.isBoolean ())) {
1750
- LogToBrowserConsole (nsIScriptError::errorFlag, u" Argument not a number" _ns);
1751
- return false ;
1752
- } else if (aElement.isNumber () && aElement.toNumber () > UINT32_MAX) {
1753
- // Clamp large numerical arguments to aValue's acceptable values.
1754
- // JS::ToUint32 will take aElement modulo 2^32 before returning it, which
1755
- // may result in a smaller final value.
1756
- aValue = UINT32_MAX;
1757
- #ifdef DEBUG
1758
- LogToBrowserConsole (nsIScriptError::errorFlag,
1759
- u" Clamped large numeric value" _ns);
1760
- #endif
1761
- } else if (!JS::ToUint32 (aCx, aElement, &aValue)) {
1762
- LogToBrowserConsole (nsIScriptError::errorFlag,
1763
- u" Failed to convert element to UInt32" _ns);
1764
- return false ;
1765
- }
1766
-
1767
- // If we're here then all type checks have passed and aValue contains the
1768
- // coerced integer
1769
- return true ;
1770
- }
1771
-
1772
- bool internal_JSHistogram_GetValueArray (JSContext* aCx, JS::CallArgs& args,
1773
- uint32_t aHistogramType,
1774
- HistogramID aId, bool isKeyed,
1775
- nsTArray<uint32_t >& aArray) {
1776
- // This function populates aArray with the values extracted from args. Handles
1777
- // keyed and non-keyed histograms, and single and array of values. Also
1778
- // performs sanity checks on the arguments. Returns true upon successful
1779
- // population, false otherwise.
1780
-
1781
- uint32_t firstArgIndex = 0 ;
1782
- if (isKeyed) {
1783
- firstArgIndex = 1 ;
1784
- }
1785
-
1786
- // Special case of no argument (or only key) and count histogram
1787
- if (args.length () == firstArgIndex) {
1788
- if (!(aHistogramType == nsITelemetry::HISTOGRAM_COUNT)) {
1789
- LogToBrowserConsole (
1790
- nsIScriptError::errorFlag,
1791
- nsLiteralString (
1792
- u" Need at least one argument for non count type histogram" ));
1793
- return false ;
1794
- }
1795
-
1796
- aArray.AppendElement (1 );
1797
- return true ;
1798
- }
1799
-
1800
- if (args[firstArgIndex].isObject () && !args[firstArgIndex].isString ()) {
1801
- JS::Rooted<JSObject*> arrayObj (aCx, &args[firstArgIndex].toObject ());
1802
-
1803
- bool isArray = false ;
1804
- JS::IsArrayObject (aCx, arrayObj, &isArray);
1805
-
1806
- if (!isArray) {
1807
- LogToBrowserConsole (
1808
- nsIScriptError::errorFlag,
1809
- nsLiteralString (
1810
- u" The argument to accumulate can't be a non-array object" ));
1811
- return false ;
1812
- }
1813
-
1814
- uint32_t arrayLength = 0 ;
1815
- if (!JS::GetArrayLength (aCx, arrayObj, &arrayLength)) {
1816
- LogToBrowserConsole (nsIScriptError::errorFlag,
1817
- u" Failed while trying to get array length" _ns);
1818
- return false ;
1819
- }
1820
-
1821
- for (uint32_t arrayIdx = 0 ; arrayIdx < arrayLength; arrayIdx++) {
1822
- JS::Rooted<JS::Value> element (aCx);
1823
-
1824
- if (!JS_GetElement (aCx, arrayObj, arrayIdx, &element)) {
1825
- nsPrintfCString msg (" Failed while trying to get element at index %d" ,
1826
- arrayIdx);
1827
- LogToBrowserConsole (nsIScriptError::errorFlag,
1828
- NS_ConvertUTF8toUTF16 (msg));
1829
- return false ;
1830
- }
1831
-
1832
- uint32_t value = 0 ;
1833
- if (!internal_JSHistogram_CoerceValue (aCx, element, aId, aHistogramType,
1834
- value)) {
1835
- nsPrintfCString msg (" Element at index %d failed type checks" , arrayIdx);
1836
- LogToBrowserConsole (nsIScriptError::errorFlag,
1837
- NS_ConvertUTF8toUTF16 (msg));
1838
- return false ;
1839
- }
1840
- aArray.AppendElement (value);
1841
- }
1842
-
1843
- return true ;
1844
- }
1845
-
1846
- uint32_t value = 0 ;
1847
- if (!internal_JSHistogram_CoerceValue (aCx, args[firstArgIndex], aId,
1848
- aHistogramType, value)) {
1849
- return false ;
1850
- }
1851
- aArray.AppendElement (value);
1852
- return true ;
1853
- }
1854
-
1855
1717
static JSHistogramData* GetJSHistogramData (JSObject* obj) {
1856
1718
MOZ_ASSERT (JS::GetClass (obj) == &sJSHistogramClass );
1857
1719
return JS::GetMaybePtrFromReservedSlot<JSHistogramData>(
@@ -2070,7 +1932,6 @@ void internal_JSHistogram_finalize(JS::GCContext* gcx, JSObject* obj) {
2070
1932
2071
1933
// NOTE: the functions in this section:
2072
1934
//
2073
- // internal_JSKeyedHistogram_Add
2074
1935
// internal_JSKeyedHistogram_Name
2075
1936
// internal_JSKeyedHistogram_Keys
2076
1937
// internal_JSKeyedHistogram_Snapshot
@@ -2172,66 +2033,6 @@ bool internal_JSKeyedHistogram_Snapshot(JSContext* cx, unsigned argc,
2172
2033
return true ;
2173
2034
}
2174
2035
2175
- bool internal_JSKeyedHistogram_Add (JSContext* cx, unsigned argc,
2176
- JS::Value* vp) {
2177
- JS::CallArgs args = JS::CallArgsFromVp (argc, vp);
2178
-
2179
- if (!args.thisv ().isObject () ||
2180
- JS::GetClass (&args.thisv ().toObject ()) != &sJSKeyedHistogramClass ) {
2181
- JS_ReportErrorASCII (cx, " Wrong JS class, expected JSKeyedHistogram class" );
2182
- return false ;
2183
- }
2184
-
2185
- JSObject* obj = &args.thisv ().toObject ();
2186
- JSHistogramData* data = GetJSKeyedHistogramData (obj);
2187
- MOZ_ASSERT (data);
2188
- HistogramID id = data->histogramId ;
2189
- MOZ_ASSERT (internal_IsHistogramEnumId (id));
2190
-
2191
- // This function should always return |undefined| and never fail but
2192
- // rather report failures using the console.
2193
- args.rval ().setUndefined ();
2194
- if (args.length () < 1 ) {
2195
- LogToBrowserConsole (nsIScriptError::errorFlag, u" Expected one argument" _ns);
2196
- return true ;
2197
- }
2198
-
2199
- nsAutoJSString key;
2200
- if (!args[0 ].isString () || !key.init (cx, args[0 ])) {
2201
- LogToBrowserConsole (nsIScriptError::errorFlag, u" Not a string" _ns);
2202
- return true ;
2203
- }
2204
-
2205
- // Check if we're allowed to record in the provided key, for this histogram.
2206
- if (!gHistogramInfos [id].allows_key (NS_ConvertUTF16toUTF8(key))) {
2207
- nsPrintfCString msg (" %s - key '%s' not allowed for this keyed histogram" ,
2208
- gHistogramInfos [id].name (),
2209
- NS_ConvertUTF16toUTF8 (key).get());
2210
- LogToBrowserConsole (nsIScriptError::errorFlag, NS_ConvertUTF8toUTF16(msg));
2211
- TelemetryScalar::Add (mozilla::Telemetry::ScalarID::
2212
- TELEMETRY_ACCUMULATE_UNKNOWN_HISTOGRAM_KEYS,
2213
- NS_ConvertASCIItoUTF16 (gHistogramInfos [id].name()), 1);
2214
- return true ;
2215
- }
2216
-
2217
- const uint32_t type = gHistogramInfos [id].histogramType ;
2218
-
2219
- nsTArray<uint32_t > values;
2220
- if (!internal_JSHistogram_GetValueArray (cx, args, type, id, true , values)) {
2221
- // Either GetValueArray or CoerceValue utility function will have printed a
2222
- // meaningful error message so we simple return true
2223
- return true ;
2224
- }
2225
-
2226
- {
2227
- StaticMutexAutoLock locker (gTelemetryHistogramMutex );
2228
- for (uint32_t aValue : values) {
2229
- internal_Accumulate (locker, id, NS_ConvertUTF16toUTF8(key), aValue);
2230
- }
2231
- }
2232
- return true ;
2233
- }
2234
-
2235
2036
bool internal_JSKeyedHistogram_Name (JSContext* cx, unsigned argc,
2236
2037
JS::Value* vp) {
2237
2038
JS::CallArgs args = CallArgsFromVp (argc, vp);
@@ -2379,11 +2180,9 @@ nsresult internal_WrapAndReturnKeyedHistogram(
2379
2180
HistogramID id, JSContext* cx, JS::MutableHandle<JS::Value> ret) {
2380
2181
JS::Rooted<JSObject*> obj (cx, JS_NewObject (cx, &sJSKeyedHistogramClass ));
2381
2182
if (!obj) return NS_ERROR_FAILURE;
2382
- // The 6 functions that are wrapped up here are eventually called
2183
+ // The functions that are wrapped up here are eventually called
2383
2184
// by the same thread that runs this function.
2384
- if (!(JS_DefineFunction (cx, obj, " add" , internal_JSKeyedHistogram_Add, 2 ,
2385
- 0 ) &&
2386
- JS_DefineFunction (cx, obj, " name" , internal_JSKeyedHistogram_Name, 1 ,
2185
+ if (!(JS_DefineFunction (cx, obj, " name" , internal_JSKeyedHistogram_Name, 1 ,
2387
2186
0 ) &&
2388
2187
JS_DefineFunction (cx, obj, " snapshot" ,
2389
2188
internal_JSKeyedHistogram_Snapshot, 1 , 0 ) &&
0 commit comments