From 05f6aaf959af2cce413c285d635d7297f5391d8a Mon Sep 17 00:00:00 2001 From: Terrence Cole Date: Mon, 6 Jun 2016 15:01:09 -0700 Subject: [PATCH] Bug 1276882 - Handle NaN sleep values explicitly; r=jandem --HG-- extra : rebase_source : 08f79177e7d1a4a58952b6f95d952105105fdbaa --- js/src/jit-test/tests/basic/bug1276882.js | 5 +++++ js/src/shell/js.cpp | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 js/src/jit-test/tests/basic/bug1276882.js diff --git a/js/src/jit-test/tests/basic/bug1276882.js b/js/src/jit-test/tests/basic/bug1276882.js new file mode 100644 index 000000000000..4e88122be989 --- /dev/null +++ b/js/src/jit-test/tests/basic/bug1276882.js @@ -0,0 +1,5 @@ +// |jit-test| error: sleep interval is not a number +sleep(0.001); +1; +sleep(0.1); +sleep(this); diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index b38f13f2f9b3..2a0c11f6db3a 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -3054,9 +3054,12 @@ Sleep_fn(JSContext* cx, unsigned argc, Value* vp) double t_secs; if (!ToNumber(cx, args[0], &t_secs)) return false; - duration = TimeDuration::FromSeconds(Max(0.0, t_secs)); + if (mozilla::IsNaN(t_secs)) { + JS_ReportError(cx, "sleep interval is not a number"); + return false; + } - /* NB: The next condition also filter out NaNs. */ + duration = TimeDuration::FromSeconds(Max(0.0, t_secs)); if (duration > MAX_TIMEOUT_INTERVAL) { JS_ReportError(cx, "Excessive sleep interval"); return false; @@ -3207,7 +3210,10 @@ CancelExecution(JSRuntime* rt) static bool SetTimeoutValue(JSContext* cx, double t) { - /* NB: The next condition also filter out NaNs. */ + if (mozilla::IsNaN(t)) { + JS_ReportError(cx, "timeout is not a number"); + return false; + } if (TimeDuration::FromSeconds(t) > MAX_TIMEOUT_INTERVAL) { JS_ReportError(cx, "Excessive timeout value"); return false;