提交 e1cacfed 编写于 作者: H hannesw

8010804: Review long and integer usage conventions

Reviewed-by: jlaskey, sundar
上级 3bf9a5d4
......@@ -279,9 +279,9 @@ final class FoldConstants extends NodeVisitor {
isLong &= value != 0.0 && JSType.isRepresentableAsLong(value);
if (isInteger) {
return LiteralNode.newInstance(token, finish, JSType.toInt32(value));
return LiteralNode.newInstance(token, finish, (int)value);
} else if (isLong) {
return LiteralNode.newInstance(token, finish, JSType.toLong(value));
return LiteralNode.newInstance(token, finish, (long)value);
}
return LiteralNode.newInstance(token, finish, value);
......
......@@ -754,25 +754,11 @@ public final class NativeArray extends ScriptObject {
final Object obj = Global.toObject(self);
final ScriptObject sobj = (ScriptObject)obj;
final long len = JSType.toUint32(sobj.getLength());
final double startNum = JSType.toNumber(start);
final long relativeStartUint32 = JSType.toUint32(startNum);
final long relativeStart = JSType.toInteger(startNum);
long k = relativeStart < 0 ?
Math.max(len + relativeStart, 0) :
Math.min(
Math.max(relativeStartUint32, relativeStart),
len);
final double endNum = (end == ScriptRuntime.UNDEFINED)? Double.NaN : JSType.toNumber(end);
final long relativeEndUint32 = (end == ScriptRuntime.UNDEFINED)? len : JSType.toUint32(endNum);
final long relativeEnd = (end == ScriptRuntime.UNDEFINED)? len : JSType.toInteger(endNum);
final long finale = relativeEnd < 0 ?
Math.max(len + relativeEnd, 0) :
Math.min(
Math.max(relativeEndUint32, relativeEnd),
len);
final long relativeStart = JSType.toLong(start);
final long relativeEnd = (end == ScriptRuntime.UNDEFINED) ? len : JSType.toLong(end);
long k = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
final long finale = relativeEnd < 0 ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len);
if (k >= finale) {
return new NativeArray(0);
......@@ -909,21 +895,10 @@ public final class NativeArray extends ScriptObject {
final ScriptObject sobj = (ScriptObject)obj;
final boolean strict = Global.isStrict();
final long len = JSType.toUint32(sobj.getLength());
final double startNum = JSType.toNumber(start);
final long relativeStartUint32 = JSType.toUint32(startNum);
final long relativeStart = JSType.toInteger(startNum);
//TODO: workaround overflow of relativeStart for start > Integer.MAX_VALUE
final long actualStart = relativeStart < 0 ?
Math.max(len + relativeStart, 0) :
Math.min(
Math.max(relativeStartUint32, relativeStart),
len);
final long actualDeleteCount =
Math.min(
Math.max(JSType.toInteger(deleteCount), 0),
len - actualStart);
final long relativeStart = JSType.toLong(start);
final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
final long actualDeleteCount = Math.min(Math.max(JSType.toLong(deleteCount), 0), len - actualStart);
final NativeArray array = new NativeArray(actualDeleteCount);
......
......@@ -770,7 +770,7 @@ public final class NativeDate extends ScriptObject {
nd.setTime(NaN);
return nd.getTime();
}
int yearInt = JSType.toInteger(yearNum);
int yearInt = (int)yearNum;
if (0 <= yearInt && yearInt <= 99) {
yearInt += 1900;
}
......
......@@ -565,8 +565,11 @@ public enum JSType {
}
/**
* JavaScript compliant Object to integer conversion
* See ECMA 9.4 ToInteger
* JavaScript compliant Object to integer conversion. See ECMA 9.4 ToInteger
*
* <p>Note that this returns {@link java.lang.Integer#MAX_VALUE} or {@link java.lang.Integer#MIN_VALUE}
* for double values that exceed the int range, including positive and negative Infinity. It is the
* caller's responsibility to handle such values correctly.</p>
*
* @param obj an object
* @return an integer
......@@ -576,8 +579,11 @@ public enum JSType {
}
/**
* JavaScript compliant Object to long conversion
* See ECMA 9.4 ToInteger
* JavaScript compliant Object to long conversion. See ECMA 9.4 ToInteger
*
* <p>Note that this returns {@link java.lang.Long#MAX_VALUE} or {@link java.lang.Long#MIN_VALUE}
* for double values that exceed the long range, including positive and negative Infinity. It is the
* caller's responsibility to handle such values correctly.</p>
*
* @param obj an object
* @return a long
......
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* JDK-8010804: Review long and integer usage conventions
*
* @test
* @run
*/
var x = [];
print(x.length);
x[4294967294] = 1;
print(x.length);
x[4294967295] = 1;
print(x.length);
print(x.slice(4294967293).length);
print(x.slice(4294967294).length);
print(x.slice(4294967295).length);
print(x.slice(4294967296).length);
print(x.slice(-4294967293).length);
print(x.slice(-4294967294).length);
print(x.slice(-4294967295).length);
print(x.slice(-4294967296).length);
print(x.slice(0, 4294967293).length);
print(x.slice(0, 4294967294).length);
print(x.slice(0, 4294967295).length);
print(x.slice(0, 4294967296).length);
print(x.slice(0, -4294967293).length);
print(x.slice(0, -4294967294).length);
print(x.slice(0, -4294967295).length);
print(x.slice(0, -4294967296).length);
print(x.slice(9223371036854775807).length);
print(x.slice(9223372036854775807).length);
print(x.slice(9223373036854775807).length);
print(x.slice(9223374036854775807).length);
print(x.slice(-9223371036854775807).length);
print(x.slice(-9223372036854775807).length);
print(x.slice(-9223373036854775807).length);
print(x.slice(-9223374036854775807).length);
print(x.slice(-9223371036854775807, 1).length);
print(x.slice(-9223372036854775807, 1).length);
print(x.slice(-9223373036854775807, 1).length);
print(x.slice(-9223374036854775807, 1).length);
print(x.slice(-9223371036854775807, -1).length);
print(x.slice(-9223372036854775807, -1).length);
print(x.slice(-9223373036854775807, -1).length);
print(x.slice(-9223374036854775807, -1).length);
print(x.slice(Infinity).length);
print(x.slice(Infinity, Infinity).length);
print(x.slice(Infinity, -Infinity).length);
print(x.slice(-Infinity).length);
print(x.slice(-Infinity, Infinity).length);
print(x.slice(-Infinity, -Infinity).length);
var d = new Date();
d.setYear(Infinity);
print(d);
\ No newline at end of file
0
4294967295
4294967295
2
1
0
0
4294967293
4294967294
4294967295
4294967295
4294967293
4294967294
4294967295
4294967295
2
1
0
0
0
0
0
0
4294967295
4294967295
4294967295
4294967295
1
1
1
1
4294967294
4294967294
4294967294
4294967294
0
0
0
4294967295
4294967295
0
Invalid Date
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册