Reviewers: wingo (holiday until 11 sep), aperez, gemont_igalia.com,
vjazquez_igalia.com, caitp,
Message:
On 2014/09/09 10:59:36, aperez wrote:
https://codereview.chromium.org/553623004/diff/1/src/runtime.cc
File src/runtime.cc (right):
https://codereview.chromium.org/553623004/diff/1/src/runtime.cc#newcode6130
src/runtime.cc:6130: RUNTIME_FUNCTION(Runtime_ToLength) {
Is there any particular reason not to implement this in JS? The CL for
"Array.from" has one version that looks okay:
https://codereview.chromium.org/363833006/diff/290001/src/runtime.js
That being said, I think it is better to have separate, smaller CL like
this
to
introduce a ToLength() function. Once this is merged, then the CL for
"Array.from" can be made simpler, too.
No particular reason for implementing it as a runtime function. Since
ToLength()
is already coded, and reviewed, as part of the Array.from() CL, I think the
JavaScript implementation is the way to go. So, caitp could you create a
separate CL for implementing ToLength()? WDYT?
Description:
ES6: Array.prototype.slice and friends should use ToLength instead of
ToUint32
- Implement 'ToLength' according to ES-626 spec.
- Use 'ToLength' instead of 'ToUint32' where necessary.
BUG=v8:3087
LOG=
Please review this at https://codereview.chromium.org/553623004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+34, -21 lines):
M src/array.js
M src/runtime.h
M src/runtime.cc
A + test/mjsunit/runtime-gen/tolength.js
M tools/generate-runtime-tests.py
Index: src/array.js
diff --git a/src/array.js b/src/array.js
index
cf99aceb699de5c1de52f66510f7b07f6048ba7b..82ae4c743ce46fe68c0f14592658674f8467d067
100644
--- a/src/array.js
+++ b/src/array.js
@@ -357,8 +357,7 @@ function ArrayToString() {
function ArrayToLocaleString() {
var array = ToObject(this);
- var arrayLen = array.length;
- var len = TO_UINT32(arrayLen);
+ var len = %ToLength(array.length);
if (len === 0) return "";
return Join(array, len, ',', ConvertToLocaleString);
}
@@ -368,7 +367,7 @@ function ArrayJoin(separator) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.join");
var array = TO_OBJECT_INLINE(this);
- var length = TO_UINT32(array.length);
+ var length = %ToLength(array.length);
if (IS_UNDEFINED(separator)) {
separator = ',';
} else if (!IS_STRING(separator)) {
@@ -404,7 +403,7 @@ function ArrayPop() {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop");
var array = TO_OBJECT_INLINE(this);
- var n = TO_UINT32(array.length);
+ var n = %ToLength(array.length);
if (n == 0) {
array.length = n;
return;
@@ -449,7 +448,7 @@ function ArrayPush() {
return ObservedArrayPush.apply(this, arguments);
var array = TO_OBJECT_INLINE(this);
- var n = TO_UINT32(array.length);
+ var n = %ToLength(array.length);
var m = %_ArgumentsLength();
for (var i = 0; i < m; i++) {
@@ -528,7 +527,7 @@ function ArrayReverse() {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.reverse");
var array = TO_OBJECT_INLINE(this);
- var len = TO_UINT32(array.length);
+ var len = %ToLength(array.length);
if (UseSparseVariant(array, len, IS_ARRAY(array), len)) {
%NormalizeElements(array);
@@ -579,7 +578,7 @@ function ArrayShift() {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift");
var array = TO_OBJECT_INLINE(this);
- var len = TO_UINT32(array.length);
+ var len = %ToLength(array.length);
if (len === 0) {
array.length = 0;
@@ -634,7 +633,7 @@ function ArrayUnshift(arg1) { // length == 1
return ObservedArrayUnshift.apply(this, arguments);
var array = TO_OBJECT_INLINE(this);
- var len = TO_UINT32(array.length);
+ var len = %ToLength(array.length);
var num_arguments = %_ArgumentsLength();
var is_sealed = ObjectIsSealed(array);
@@ -653,12 +652,11 @@ function ArrayUnshift(arg1) { // length == 1
return new_length;
}
-
function ArraySlice(start, end) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.slice");
var array = TO_OBJECT_INLINE(this);
- var len = TO_UINT32(array.length);
+ var len = %ToLength(array.length);
var start_i = TO_INTEGER(start);
var end_i = len;
@@ -776,7 +774,7 @@ function ArraySplice(start, delete_count) {
var num_arguments = %_ArgumentsLength();
var array = TO_OBJECT_INLINE(this);
- var len = TO_UINT32(array.length);
+ var len = %ToLength(array.length);
var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments,
len,
start_i);
@@ -1119,7 +1117,7 @@ function ArrayFilter(f, receiver) {
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
var array = ToObject(this);
- var length = ToUint32(array.length);
+ var length = %ToLength(array.length);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
@@ -1155,7 +1153,7 @@ function ArrayForEach(f, receiver) {
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
var array = ToObject(this);
- var length = TO_UINT32(array.length);
+ var length = %ToLength(array.length);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
@@ -1186,7 +1184,7 @@ function ArraySome(f, receiver) {
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
var array = ToObject(this);
- var length = TO_UINT32(array.length);
+ var length = %ToLength(array.length);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
@@ -1216,7 +1214,7 @@ function ArrayEvery(f, receiver) {
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
var array = ToObject(this);
- var length = TO_UINT32(array.length);
+ var length = %ToLength(array.length);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
@@ -1245,7 +1243,7 @@ function ArrayMap(f, receiver) {
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
var array = ToObject(this);
- var length = TO_UINT32(array.length);
+ var length = %ToLength(array.length);
if (!IS_SPEC_FUNCTION(f)) {
throw MakeTypeError('called_non_callable', [ f ]);
@@ -1388,7 +1386,7 @@ function ArrayReduce(callback, current) {
// Pull out the length so that modifications to the length in the
// loop will not affect the looping and side effects are visible.
var array = ToObject(this);
- var length = ToUint32(array.length);
+ var length = %ToLength(array.length);
if (!IS_SPEC_FUNCTION(callback)) {
throw MakeTypeError('called_non_callable', [callback]);
@@ -1425,7 +1423,7 @@ function ArrayReduceRight(callback, current) {
// Pull out the length so that side effects are visible before the
// callback function is checked.
var array = ToObject(this);
- var length = ToUint32(array.length);
+ var length = %ToLength(array.length);
if (!IS_SPEC_FUNCTION(callback)) {
throw MakeTypeError('called_non_callable', [callback]);
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
501f2fd4435d9a3661388e850fbc9067dccfbda4..503c0e3a55095316517b3bcf3258bd4403b88b72
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -6126,6 +6126,20 @@ RUNTIME_FUNCTION(Runtime_Typeof) {
}
+// ECMA-262 section 7.1.15
+RUNTIME_FUNCTION(Runtime_ToLength) {
+ HandleScope scope(isolate);
+ DCHECK(args.length() == 1);
+
+ CONVERT_DOUBLE_ARG_CHECKED(number, 0);
+ double length = DoubleToInteger(number);
+ if (length <= 0) *isolate->factory()->NewNumber(0);
+ double MAX_SAFE_INTEGER = power_helper(2, 53) - 1;
+ double result = std::min<double>(length, MAX_SAFE_INTEGER);
+ return *isolate->factory()->NewNumber(result);
+}
+
+
RUNTIME_FUNCTION(Runtime_Booleanize) {
SealHandleScope shs(isolate);
DCHECK(args.length() == 2);
Index: src/runtime.h
diff --git a/src/runtime.h b/src/runtime.h
index
ef42b523562c6d2d4ab66babe0dec97565311b67..84f60521b7bcb7442809b1f14de1fe6ab06abdce
100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -93,6 +93,7 @@ namespace internal {
/* Conversions */ \
F(ToBool, 1, 1) \
F(Typeof, 1, 1) \
+ F(ToLength, 1, 1) \
\
F(Booleanize, 2, 1) /* TODO(turbofan): Only temporary */ \
\
Index: test/mjsunit/runtime-gen/tolength.js
diff --git a/test/mjsunit/runtime-gen/numbertointeger.js
b/test/mjsunit/runtime-gen/tolength.js
similarity index 88%
copy from test/mjsunit/runtime-gen/numbertointeger.js
copy to test/mjsunit/runtime-gen/tolength.js
index
eada58f45abaeb5d88d826be86416d3cde242c26..fcc8a32342fe5a52a439fcff483d311dc0b059e9
100644
--- a/test/mjsunit/runtime-gen/numbertointeger.js
+++ b/test/mjsunit/runtime-gen/tolength.js
@@ -2,4 +2,4 @@
// AUTO-GENERATED BY tools/generate-runtime-tests.py, DO NOT MODIFY
// Flags: --allow-natives-syntax --harmony --harmony-proxies
var _number = 1.5;
-%NumberToInteger(_number);
+%ToLength(_number);
Index: tools/generate-runtime-tests.py
diff --git a/tools/generate-runtime-tests.py
b/tools/generate-runtime-tests.py
index
6cda22277b8924391f2d2e94c4b98e4290244236..08aaf66d5a76739e71e10a3e74e113543b80674a
100755
--- a/tools/generate-runtime-tests.py
+++ b/tools/generate-runtime-tests.py
@@ -47,8 +47,8 @@ EXPAND_MACROS = [
# that the parser doesn't bit-rot. Change the values as needed when you
add,
# remove or change runtime functions, but make sure we don't lose our
ability
# to parse them!
-EXPECTED_FUNCTION_COUNT = 431
-EXPECTED_FUZZABLE_COUNT = 330
+EXPECTED_FUNCTION_COUNT = 432
+EXPECTED_FUZZABLE_COUNT = 331
EXPECTED_CCTEST_COUNT = 7
EXPECTED_UNKNOWN_COUNT = 17
EXPECTED_BUILTINS_COUNT = 806
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.