Implement ToLength from ES6 section 7.1.15
authorrossberg@chromium.org <rossberg@chromium.org>
Thu, 18 Sep 2014 12:21:50 +0000 (12:21 +0000)
committerrossberg@chromium.org <rossberg@chromium.org>
Thu, 18 Sep 2014 12:21:50 +0000 (12:21 +0000)
BUG=
R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/552273002

Patch from Caitlin Potter <caitpotter88@gmail.com>.

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24036 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/runtime.js

index d9e1fe5..4d15d20 100644 (file)
@@ -563,6 +563,14 @@ function ToInteger(x) {
 }
 
 
+// ES6, draft 08-24-14, section 7.1.15
+function ToLength(arg) {
+  arg = ToInteger(arg);
+  if (arg < 0) return 0;
+  return arg < $Number.MAX_SAFE_INTEGER ? arg : $Number.MAX_SAFE_INTEGER;
+}
+
+
 // ECMA-262, section 9.6, page 34.
 function ToUint32(x) {
   if (%_IsSmi(x) && x >= 0) return x;