/src/mozilla-central/js/src/jsnum.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
2 | | * vim: set ts=8 sts=4 et sw=4 tw=99: |
3 | | * This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef jsnum_h |
8 | | #define jsnum_h |
9 | | |
10 | | #include "mozilla/Compiler.h" |
11 | | #include "mozilla/FloatingPoint.h" |
12 | | #include "mozilla/Range.h" |
13 | | #include "mozilla/Utf8.h" |
14 | | |
15 | | #include "NamespaceImports.h" |
16 | | |
17 | | #include "js/Conversions.h" |
18 | | |
19 | | #include "vm/StringType.h" |
20 | | |
21 | | |
22 | | // This macro is should be `one' if current compiler supports builtin functions |
23 | | // like __builtin_sadd_overflow. |
24 | | #if MOZ_IS_GCC |
25 | | // GCC supports these functions. |
26 | | #define BUILTIN_CHECKED_ARITHMETIC_SUPPORTED(x) 1 |
27 | | #else |
28 | | // For CLANG, we use its own function to check for this. |
29 | | #ifdef __has_builtin |
30 | | #define BUILTIN_CHECKED_ARITHMETIC_SUPPORTED(x) __has_builtin(x) |
31 | | #endif |
32 | | #endif |
33 | | #ifndef BUILTIN_CHECKED_ARITHMETIC_SUPPORTED |
34 | | #define BUILTIN_CHECKED_ARITHMETIC_SUPPORTED(x) 0 |
35 | | #endif |
36 | | |
37 | | namespace js { |
38 | | |
39 | | class GlobalObject; |
40 | | class StringBuffer; |
41 | | |
42 | | extern MOZ_MUST_USE bool |
43 | | InitRuntimeNumberState(JSRuntime* rt); |
44 | | |
45 | | #if !EXPOSE_INTL_API |
46 | | extern void |
47 | | FinishRuntimeNumberState(JSRuntime* rt); |
48 | | #endif |
49 | | |
50 | | /* Initialize the Number class, returning its prototype object. */ |
51 | | extern JSObject* |
52 | | InitNumberClass(JSContext* cx, Handle<GlobalObject*> global); |
53 | | |
54 | | /* |
55 | | * When base == 10, this function implements ToString() as specified by |
56 | | * ECMA-262-5 section 9.8.1; but note that it handles integers specially for |
57 | | * performance. See also js::NumberToCString(). |
58 | | */ |
59 | | template <AllowGC allowGC> |
60 | | extern JSString* |
61 | | NumberToString(JSContext* cx, double d); |
62 | | |
63 | | extern JSString* |
64 | | NumberToStringHelper(JSContext* cx, double d); |
65 | | |
66 | | extern JSAtom* |
67 | | NumberToAtom(JSContext* cx, double d); |
68 | | |
69 | | template <AllowGC allowGC> |
70 | | extern JSFlatString* |
71 | | Int32ToString(JSContext* cx, int32_t i); |
72 | | |
73 | | extern JSFlatString* |
74 | | Int32ToStringHelper(JSContext* cx, int32_t i); |
75 | | |
76 | | extern JSAtom* |
77 | | Int32ToAtom(JSContext* cx, int32_t si); |
78 | | |
79 | | // ES6 15.7.3.12 |
80 | | extern bool |
81 | | IsInteger(const Value& val); |
82 | | |
83 | | /* |
84 | | * Convert an integer or double (contained in the given value) to a string and |
85 | | * append to the given buffer. |
86 | | */ |
87 | | extern MOZ_MUST_USE bool JS_FASTCALL |
88 | | NumberValueToStringBuffer(JSContext* cx, const Value& v, StringBuffer& sb); |
89 | | |
90 | | extern JSFlatString* |
91 | | IndexToString(JSContext* cx, uint32_t index); |
92 | | |
93 | | /* |
94 | | * Usually a small amount of static storage is enough, but sometimes we need |
95 | | * to dynamically allocate much more. This struct encapsulates that. |
96 | | * Dynamically allocated memory will be freed when the object is destroyed. |
97 | | */ |
98 | | struct ToCStringBuf |
99 | | { |
100 | | /* |
101 | | * The longest possible result that would need to fit in sbuf is |
102 | | * (-0x80000000).toString(2), which has length 33. Longer cases are |
103 | | * possible, but they'll go in dbuf. |
104 | | */ |
105 | | static const size_t sbufSize = 34; |
106 | | char sbuf[sbufSize]; |
107 | | char* dbuf; |
108 | | |
109 | | ToCStringBuf(); |
110 | | ~ToCStringBuf(); |
111 | | }; |
112 | | |
113 | | /* |
114 | | * Convert a number to a C string. When base==10, this function implements |
115 | | * ToString() as specified by ECMA-262-5 section 9.8.1. It handles integral |
116 | | * values cheaply. Return nullptr if we ran out of memory. See also |
117 | | * NumberToCString(). |
118 | | */ |
119 | | extern char* |
120 | | NumberToCString(JSContext* cx, ToCStringBuf* cbuf, double d, int base = 10); |
121 | | |
122 | | /* |
123 | | * The largest positive integer such that all positive integers less than it |
124 | | * may be precisely represented using the IEEE-754 double-precision format. |
125 | | */ |
126 | | const double DOUBLE_INTEGRAL_PRECISION_LIMIT = uint64_t(1) << 53; |
127 | | |
128 | | /* |
129 | | * Parse a decimal number encoded in |chars|. The decimal number must be |
130 | | * sufficiently small that it will not overflow the integrally-precise range of |
131 | | * the double type -- that is, the number will be smaller than |
132 | | * DOUBLE_INTEGRAL_PRECISION_LIMIT |
133 | | */ |
134 | | template <typename CharT> |
135 | | extern double |
136 | | ParseDecimalNumber(const mozilla::Range<const CharT> chars); |
137 | | |
138 | | /* |
139 | | * Compute the positive integer of the given base described immediately at the |
140 | | * start of the range [start, end) -- no whitespace-skipping, no magical |
141 | | * leading-"0" octal or leading-"0x" hex behavior, no "+"/"-" parsing, just |
142 | | * reading the digits of the integer. Return the index one past the end of the |
143 | | * digits of the integer in *endp, and return the integer itself in *dp. If |
144 | | * base is 10 or a power of two the returned integer is the closest possible |
145 | | * double; otherwise extremely large integers may be slightly inaccurate. |
146 | | * |
147 | | * If [start, end) does not begin with a number with the specified base, |
148 | | * *dp == 0 and *endp == start upon return. |
149 | | */ |
150 | | template <typename CharT> |
151 | | extern MOZ_MUST_USE bool |
152 | | GetPrefixInteger(JSContext* cx, const CharT* start, const CharT* end, int base, |
153 | | const CharT** endp, double* dp); |
154 | | |
155 | | inline const char16_t* |
156 | | ToRawChars(const char16_t* units) |
157 | 878 | { |
158 | 878 | return units; |
159 | 878 | } |
160 | | |
161 | | inline const unsigned char* |
162 | | ToRawChars(const unsigned char* units) |
163 | 0 | { |
164 | 0 | return units; |
165 | 0 | } |
166 | | |
167 | | inline const unsigned char* |
168 | | ToRawChars(const mozilla::Utf8Unit* units) |
169 | 0 | { |
170 | 0 | return mozilla::Utf8AsUnsignedChars(units); |
171 | 0 | } |
172 | | |
173 | | /** |
174 | | * Like the prior function, but [start, end) must all be digits in the given |
175 | | * base (and so this function doesn't take a useless outparam). |
176 | | */ |
177 | | template <typename CharT> |
178 | | extern MOZ_MUST_USE bool |
179 | | GetFullInteger(JSContext* cx, const CharT* start, const CharT* end, int base, double* dp) |
180 | 439 | { |
181 | 439 | decltype(ToRawChars(start)) realEnd; |
182 | 439 | if (GetPrefixInteger(cx, ToRawChars(start), ToRawChars(end), base, &realEnd, dp)) { |
183 | 439 | MOZ_ASSERT(end == static_cast<const void*>(realEnd)); |
184 | 439 | return true; |
185 | 439 | } |
186 | 0 | return false; |
187 | 0 | } Unexecuted instantiation: bool js::GetFullInteger<unsigned char>(JSContext*, unsigned char const*, unsigned char const*, int, double*) bool js::GetFullInteger<char16_t>(JSContext*, char16_t const*, char16_t const*, int, double*) Line | Count | Source | 180 | 439 | { | 181 | 439 | decltype(ToRawChars(start)) realEnd; | 182 | 439 | if (GetPrefixInteger(cx, ToRawChars(start), ToRawChars(end), base, &realEnd, dp)) { | 183 | 439 | MOZ_ASSERT(end == static_cast<const void*>(realEnd)); | 184 | 439 | return true; | 185 | 439 | } | 186 | 0 | return false; | 187 | 0 | } |
Unexecuted instantiation: bool js::GetFullInteger<mozilla::Utf8Unit>(JSContext*, mozilla::Utf8Unit const*, mozilla::Utf8Unit const*, int, double*) |
188 | | |
189 | | /* |
190 | | * This is like GetPrefixInteger, but it only deals with base 10 and doesn't |
191 | | * have an |endp| outparam. It should only be used when the characters are |
192 | | * known to only contain digits. |
193 | | */ |
194 | | template <typename CharT> |
195 | | extern MOZ_MUST_USE bool |
196 | | GetDecimalInteger(JSContext* cx, const CharT* start, const CharT* end, double* dp); |
197 | | |
198 | | extern MOZ_MUST_USE bool |
199 | | StringToNumber(JSContext* cx, JSString* str, double* result); |
200 | | |
201 | | extern MOZ_MUST_USE bool |
202 | | StringToNumberDontReportOOM(JSContext* cx, JSString* str, double* result); |
203 | | |
204 | | /* ES5 9.3 ToNumber, overwriting *vp with the appropriate number value. */ |
205 | | MOZ_ALWAYS_INLINE MOZ_MUST_USE bool |
206 | | ToNumber(JSContext* cx, JS::MutableHandleValue vp) |
207 | 1 | { |
208 | 1 | if (vp.isNumber()) { |
209 | 1 | return true; |
210 | 1 | } |
211 | 0 | double d; |
212 | 0 | extern JS_PUBLIC_API(bool) ToNumberSlow(JSContext* cx, HandleValue v, double* dp); |
213 | 0 | if (!ToNumberSlow(cx, vp, &d)) { |
214 | 0 | return false; |
215 | 0 | } |
216 | 0 | |
217 | 0 | vp.setNumber(d); |
218 | 0 | return true; |
219 | 0 | } |
220 | | |
221 | | bool |
222 | | ToNumericSlow(JSContext* cx, JS::MutableHandleValue vp); |
223 | | |
224 | | // BigInt proposal section 3.1.6 |
225 | | MOZ_ALWAYS_INLINE MOZ_MUST_USE bool |
226 | | ToNumeric(JSContext* cx, JS::MutableHandleValue vp) |
227 | 0 | { |
228 | 0 | if (vp.isNumber()) { |
229 | 0 | return true; |
230 | 0 | } |
231 | | #ifdef ENABLE_BIGINT |
232 | | if (vp.isBigInt()) { |
233 | | return true; |
234 | | } |
235 | | #endif |
236 | 0 | return ToNumericSlow(cx, vp); |
237 | 0 | } |
238 | | |
239 | | bool |
240 | | ToInt32OrBigIntSlow(JSContext* cx, JS::MutableHandleValue vp); |
241 | | |
242 | | MOZ_ALWAYS_INLINE MOZ_MUST_USE bool |
243 | | ToInt32OrBigInt(JSContext* cx, JS::MutableHandleValue vp) |
244 | 110 | { |
245 | 110 | if (vp.isInt32()) { |
246 | 110 | return true; |
247 | 110 | } |
248 | 0 | return ToInt32OrBigIntSlow(cx, vp); |
249 | 0 | } |
250 | | |
251 | | MOZ_MUST_USE bool |
252 | | num_parseInt(JSContext* cx, unsigned argc, Value* vp); |
253 | | |
254 | | } /* namespace js */ |
255 | | |
256 | | /* |
257 | | * Similar to strtod except that it replaces overflows with infinities of the |
258 | | * correct sign, and underflows with zeros of the correct sign. Guaranteed to |
259 | | * return the closest double number to the given input in dp. |
260 | | * |
261 | | * Also allows inputs of the form [+|-]Infinity, which produce an infinity of |
262 | | * the appropriate sign. The case of the "Infinity" string must match exactly. |
263 | | * If the string does not contain a number, set *dEnd to begin and return 0.0 |
264 | | * in *d. |
265 | | * |
266 | | * Return false if out of memory. |
267 | | */ |
268 | | template <typename CharT> |
269 | | extern MOZ_MUST_USE bool |
270 | | js_strtod(JSContext* cx, const CharT* begin, const CharT* end, |
271 | | const CharT** dEnd, double* d); |
272 | | |
273 | | namespace js { |
274 | | |
275 | | /** |
276 | | * Like js_strtod, but for when you don't require a |dEnd| argument *and* it's |
277 | | * possible that the number in the string will not occupy the full [begin, end) |
278 | | * range. |
279 | | */ |
280 | | template <typename CharT> |
281 | | extern MOZ_MUST_USE bool |
282 | | StringToDouble(JSContext* cx, const CharT* begin, const CharT* end, double* d) |
283 | 0 | { |
284 | 0 | decltype(ToRawChars(begin)) dummy; |
285 | 0 | return js_strtod(cx, ToRawChars(begin), ToRawChars(end), &dummy, d); |
286 | 0 | } Unexecuted instantiation: bool js::StringToDouble<char16_t>(JSContext*, char16_t const*, char16_t const*, double*) Unexecuted instantiation: bool js::StringToDouble<mozilla::Utf8Unit>(JSContext*, mozilla::Utf8Unit const*, mozilla::Utf8Unit const*, double*) |
287 | | |
288 | | /** |
289 | | * Like js_strtod, but for when the number always constitutes the entire range |
290 | | * (and so |dEnd| would be a value already known). |
291 | | */ |
292 | | template <typename CharT> |
293 | | extern MOZ_MUST_USE bool |
294 | | FullStringToDouble(JSContext* cx, const CharT* begin, const CharT* end, double* d) |
295 | 0 | { |
296 | 0 | decltype(ToRawChars(begin)) realEnd; |
297 | 0 | if (js_strtod(cx, ToRawChars(begin), ToRawChars(end), &realEnd, d)) { |
298 | 0 | MOZ_ASSERT(end == static_cast<const void*>(realEnd)); |
299 | 0 | return true; |
300 | 0 | } |
301 | 0 | return false; |
302 | 0 | } Unexecuted instantiation: bool js::FullStringToDouble<unsigned char>(JSContext*, unsigned char const*, unsigned char const*, double*) Unexecuted instantiation: bool js::FullStringToDouble<char16_t>(JSContext*, char16_t const*, char16_t const*, double*) |
303 | | |
304 | | extern MOZ_MUST_USE bool |
305 | | num_toString(JSContext* cx, unsigned argc, Value* vp); |
306 | | |
307 | | extern MOZ_MUST_USE bool |
308 | | num_valueOf(JSContext* cx, unsigned argc, Value* vp); |
309 | | |
310 | | /* |
311 | | * Returns true if the given value is definitely an index: that is, the value |
312 | | * is a number that's an unsigned 32-bit integer. |
313 | | * |
314 | | * This method prioritizes common-case speed over accuracy in every case. It |
315 | | * can produce false negatives (but not false positives): some values which are |
316 | | * indexes will be reported not to be indexes by this method. Users must |
317 | | * consider this possibility when using this method. |
318 | | */ |
319 | | static MOZ_ALWAYS_INLINE bool |
320 | | IsDefinitelyIndex(const Value& v, uint32_t* indexp) |
321 | 45 | { |
322 | 45 | if (v.isInt32() && v.toInt32() >= 0) { |
323 | 33 | *indexp = v.toInt32(); |
324 | 33 | return true; |
325 | 33 | } |
326 | 12 | |
327 | 12 | int32_t i; |
328 | 12 | if (v.isDouble() && mozilla::NumberEqualsInt32(v.toDouble(), &i) && i >= 0) { |
329 | 0 | *indexp = uint32_t(i); |
330 | 0 | return true; |
331 | 0 | } |
332 | 12 | |
333 | 12 | if (v.isString() && v.toString()->hasIndexValue()) { |
334 | 0 | *indexp = v.toString()->getIndexValue(); |
335 | 0 | return true; |
336 | 0 | } |
337 | 12 | |
338 | 12 | return false; |
339 | 12 | } Unexecuted instantiation: CTypes.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: StructuredClone.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src0.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src1.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src10.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src11.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src12.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unified_cpp_js_src14.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Line | Count | Source | 321 | 5 | { | 322 | 5 | if (v.isInt32() && v.toInt32() >= 0) { | 323 | 4 | *indexp = v.toInt32(); | 324 | 4 | return true; | 325 | 4 | } | 326 | 1 | | 327 | 1 | int32_t i; | 328 | 1 | if (v.isDouble() && mozilla::NumberEqualsInt32(v.toDouble(), &i) && i >= 0) { | 329 | 0 | *indexp = uint32_t(i); | 330 | 0 | return true; | 331 | 0 | } | 332 | 1 | | 333 | 1 | if (v.isString() && v.toString()->hasIndexValue()) { | 334 | 0 | *indexp = v.toString()->getIndexValue(); | 335 | 0 | return true; | 336 | 0 | } | 337 | 1 | | 338 | 1 | return false; | 339 | 1 | } |
Unexecuted instantiation: Unified_cpp_js_src15.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src17.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src18.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src19.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src2.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src20.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src21.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src22.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src23.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src24.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src25.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src26.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src27.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src28.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src29.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src3.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src31.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src32.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src33.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src34.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src35.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src36.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src37.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src38.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src39.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src4.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src40.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src41.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src42.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src43.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src44.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src45.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src5.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src6.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src7.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src8.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src9.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: RegExp.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Parser.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Disassembler-x86-shared.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: jsmath.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Interpreter.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Line | Count | Source | 321 | 40 | { | 322 | 40 | if (v.isInt32() && v.toInt32() >= 0) { | 323 | 29 | *indexp = v.toInt32(); | 324 | 29 | return true; | 325 | 29 | } | 326 | 11 | | 327 | 11 | int32_t i; | 328 | 11 | if (v.isDouble() && mozilla::NumberEqualsInt32(v.toDouble(), &i) && i >= 0) { | 329 | 0 | *indexp = uint32_t(i); | 330 | 0 | return true; | 331 | 0 | } | 332 | 11 | | 333 | 11 | if (v.isString() && v.toString()->hasIndexValue()) { | 334 | 0 | *indexp = v.toString()->getIndexValue(); | 335 | 0 | return true; | 336 | 0 | } | 337 | 11 | | 338 | 11 | return false; | 339 | 11 | } |
Unexecuted instantiation: Unified_cpp_js_src13.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) Unexecuted instantiation: Unified_cpp_js_src16.cpp:js::IsDefinitelyIndex(JS::Value const&, unsigned int*) |
340 | | |
341 | | /* ES5 9.4 ToInteger. */ |
342 | | static MOZ_MUST_USE inline bool |
343 | | ToInteger(JSContext* cx, HandleValue v, double* dp) |
344 | 130 | { |
345 | 130 | if (v.isInt32()) { |
346 | 130 | *dp = v.toInt32(); |
347 | 130 | return true; |
348 | 130 | } |
349 | 0 | if (v.isDouble()) { |
350 | 0 | *dp = v.toDouble(); |
351 | 0 | } else if (v.isString() && v.toString()->hasIndexValue()) { |
352 | 0 | *dp = v.toString()->getIndexValue(); |
353 | 0 | return true; |
354 | 0 | } else { |
355 | 0 | extern JS_PUBLIC_API(bool) ToNumberSlow(JSContext* cx, HandleValue v, double* dp); |
356 | 0 | if (!ToNumberSlow(cx, v, dp)) { |
357 | 0 | return false; |
358 | 0 | } |
359 | 0 | } |
360 | 0 | *dp = JS::ToInteger(*dp); |
361 | 0 | return true; |
362 | 0 | } Unexecuted instantiation: CTypes.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: StructuredClone.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src0.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src1.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src10.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src11.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src12.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src14.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src15.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src17.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src18.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src19.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src2.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src20.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src21.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src22.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src23.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src24.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src25.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src26.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src27.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src28.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src29.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src3.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src31.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src32.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src33.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src34.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src35.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src36.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src37.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src38.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unified_cpp_js_src39.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Line | Count | Source | 344 | 130 | { | 345 | 130 | if (v.isInt32()) { | 346 | 130 | *dp = v.toInt32(); | 347 | 130 | return true; | 348 | 130 | } | 349 | 0 | if (v.isDouble()) { | 350 | 0 | *dp = v.toDouble(); | 351 | 0 | } else if (v.isString() && v.toString()->hasIndexValue()) { | 352 | 0 | *dp = v.toString()->getIndexValue(); | 353 | 0 | return true; | 354 | 0 | } else { | 355 | 0 | extern JS_PUBLIC_API(bool) ToNumberSlow(JSContext* cx, HandleValue v, double* dp); | 356 | 0 | if (!ToNumberSlow(cx, v, dp)) { | 357 | 0 | return false; | 358 | 0 | } | 359 | 0 | } | 360 | 0 | *dp = JS::ToInteger(*dp); | 361 | 0 | return true; | 362 | 0 | } |
Unexecuted instantiation: Unified_cpp_js_src4.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src40.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src41.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src42.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src43.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src44.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src45.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src5.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src6.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src7.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src8.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src9.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: RegExp.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Parser.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Disassembler-x86-shared.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: jsmath.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Interpreter.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src13.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) Unexecuted instantiation: Unified_cpp_js_src16.cpp:js::ToInteger(JSContext*, JS::Handle<JS::Value>, double*) |
363 | | |
364 | | /* ES2017 draft 7.1.17 ToIndex |
365 | | * |
366 | | * Return true and set |*index| to the integer value if |v| is a valid |
367 | | * integer index value. Otherwise report a RangeError and return false. |
368 | | * |
369 | | * The returned index will always be in the range 0 <= *index <= 2^53-1. |
370 | | */ |
371 | | extern MOZ_MUST_USE bool |
372 | | ToIndexSlow(JSContext* cx, JS::HandleValue v, const unsigned errorNumber, uint64_t* index); |
373 | | |
374 | | static MOZ_MUST_USE inline bool |
375 | | ToIndex(JSContext* cx, JS::HandleValue v, const unsigned errorNumber, uint64_t* index) |
376 | 0 | { |
377 | 0 | if (v.isInt32()) { |
378 | 0 | int32_t i = v.toInt32(); |
379 | 0 | if (i >= 0) { |
380 | 0 | *index = uint64_t(i); |
381 | 0 | return true; |
382 | 0 | } |
383 | 0 | } |
384 | 0 | return ToIndexSlow(cx, v, errorNumber, index); |
385 | 0 | } Unexecuted instantiation: CTypes.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: StructuredClone.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src0.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src1.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src10.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src11.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src12.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src14.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src15.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src17.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src18.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src19.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src2.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src20.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src21.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src22.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src23.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src24.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src25.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src26.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src27.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src28.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src29.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src3.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src31.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src32.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src33.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src34.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src35.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src36.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src37.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src38.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src39.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src4.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src40.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src41.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src42.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src43.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src44.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src45.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src5.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src6.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src7.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src8.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src9.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: RegExp.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Parser.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Disassembler-x86-shared.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: jsmath.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Interpreter.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src13.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src16.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned int, unsigned long*) |
386 | | |
387 | | static MOZ_MUST_USE inline bool |
388 | | ToIndex(JSContext* cx, JS::HandleValue v, uint64_t* index) |
389 | 0 | { |
390 | 0 | return ToIndex(cx, v, JSMSG_BAD_INDEX, index); |
391 | 0 | } Unexecuted instantiation: CTypes.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: StructuredClone.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src0.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src1.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src10.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src11.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src12.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src14.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src15.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src17.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src18.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src19.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src2.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src20.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src21.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src22.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src23.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src24.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src25.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src26.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src27.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src28.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src29.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src3.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src31.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src32.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src33.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src34.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src35.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src36.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src37.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src38.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src39.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src4.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src40.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src41.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src42.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src43.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src44.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src45.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src5.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src6.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src7.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src8.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src9.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: RegExp.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Parser.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Disassembler-x86-shared.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: jsmath.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Interpreter.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src13.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) Unexecuted instantiation: Unified_cpp_js_src16.cpp:js::ToIndex(JSContext*, JS::Handle<JS::Value>, unsigned long*) |
392 | | |
393 | | MOZ_MUST_USE inline bool |
394 | | SafeAdd(int32_t one, int32_t two, int32_t* res) |
395 | 12 | { |
396 | 12 | #if BUILTIN_CHECKED_ARITHMETIC_SUPPORTED(__builtin_sadd_overflow) |
397 | 12 | // Using compiler's builtin function. |
398 | 12 | return !__builtin_sadd_overflow(one, two, res); |
399 | | #else |
400 | | // Use unsigned for the 32-bit operation since signed overflow gets |
401 | | // undefined behavior. |
402 | | *res = uint32_t(one) + uint32_t(two); |
403 | | int64_t ores = (int64_t)one + (int64_t)two; |
404 | | return ores == (int64_t)*res; |
405 | | #endif |
406 | | } |
407 | | |
408 | | MOZ_MUST_USE inline bool |
409 | | SafeSub(int32_t one, int32_t two, int32_t* res) |
410 | 0 | { |
411 | 0 | #if BUILTIN_CHECKED_ARITHMETIC_SUPPORTED(__builtin_ssub_overflow) |
412 | 0 | return !__builtin_ssub_overflow(one, two, res); |
413 | | #else |
414 | | *res = uint32_t(one) - uint32_t(two); |
415 | | int64_t ores = (int64_t)one - (int64_t)two; |
416 | | return ores == (int64_t)*res; |
417 | | #endif |
418 | | } |
419 | | |
420 | | MOZ_MUST_USE inline bool |
421 | | SafeMul(int32_t one, int32_t two, int32_t* res) |
422 | 0 | { |
423 | 0 | #if BUILTIN_CHECKED_ARITHMETIC_SUPPORTED(__builtin_smul_overflow) |
424 | 0 | return !__builtin_smul_overflow(one, two, res); |
425 | | #else |
426 | | *res = uint32_t(one) * uint32_t(two); |
427 | | int64_t ores = (int64_t)one * (int64_t)two; |
428 | | return ores == (int64_t)*res; |
429 | | #endif |
430 | | } |
431 | | |
432 | | } /* namespace js */ |
433 | | |
434 | | #endif /* jsnum_h */ |