Commit a4124b3b authored by dslomov's avatar dslomov Committed by Commit bot

Map -0 to integer 0 for typed array constructors.

R=bmeurer@chromium.org
BUG=chromium:447756
LOG=Y

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

Cr-Commit-Position: refs/heads/master@{#26021}
parent 159b1417
...@@ -672,7 +672,7 @@ function DefaultString(x) { ...@@ -672,7 +672,7 @@ function DefaultString(x) {
} }
function ToPositiveInteger(x, rangeErrorName) { function ToPositiveInteger(x, rangeErrorName) {
var i = TO_INTEGER(x); var i = TO_INTEGER_MAP_MINUS_ZERO(x);
if (i < 0) throw MakeRangeError(rangeErrorName); if (i < 0) throw MakeRangeError(rangeErrorName);
return i; return i;
} }
......
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --allow-natives-syntax
function TestConstructor(c) {
var a = new c(-0);
assertSame(Infinity, 1 / a.length);
assertSame(Infinity, 1 / a.byteLength);
var ab = new ArrayBuffer(-0);
assertSame(Infinity, 1 / ab.byteLength);
var a1 = new c(ab, -0, -0);
assertSame(Infinity, 1 / a1.length);
assertSame(Infinity, 1 / a1.byteLength);
assertSame(Infinity, 1 / a1.byteOffset);
}
var constructors =
[ Uint8Array, Int8Array, Uint8ClampedArray,
Uint16Array, Int16Array,
Uint32Array, Int32Array,
Float32Array, Float64Array ];
for (var i = 0; i < constructors.length; i++) {
TestConstructor(constructors[i]);
}
function TestOptimizedCode() {
var a = new Uint8Array(-0);
assertSame(Infinity, 1 / a.length);
assertSame(Infinity, 1 / a.byteLength);
var ab = new ArrayBuffer(-0);
assertSame(Infinity, 1 / ab.byteLength);
var a1 = new Uint8Array(ab, -0, -0);
assertSame(Infinity, 1 / a1.length);
assertSame(Infinity, 1 / a1.byteLength);
assertSame(Infinity, 1 / a1.byteOffset);
}
%OptimizeFunctionOnNextCall(Uint8Array);
for (var i = 0; i < 1000; i++) {
TestOptimizedCode();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment