Commit 9d511664 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[bigint] Make kMaxLength platform-independent.

Taking kSystemPointerSize into account when determining the maximum
allowed BigInt size accidentally made the limit platform-specific.
This patch chooses a platform-independent constant (1<<30) instead.

Bug: chromium:909614
Change-Id: I4717969bc56e6dd5f1eed70b7e60e621989d0719
Reviewed-on: https://chromium-review.googlesource.com/c/1355625
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57983}
parent e7ea6545
...@@ -38,9 +38,12 @@ class BigIntBase : public HeapObjectPtr { ...@@ -38,9 +38,12 @@ class BigIntBase : public HeapObjectPtr {
static inline BigIntBase unchecked_cast(ObjectPtr o) { static inline BigIntBase unchecked_cast(ObjectPtr o) {
return bit_cast<BigIntBase>(o); return bit_cast<BigIntBase>(o);
} }
// Increasing kMaxLength will require code changes.
static const int kMaxLengthBits = // The maximum kMaxLengthBits that the current implementation supports
kMaxInt - kSystemPointerSize * kBitsPerByte - 1; // would be kMaxInt - kSystemPointerSize * kBitsPerByte - 1.
// Since we want a platform independent limit, choose a nice round number
// somewhere below that maximum.
static const int kMaxLengthBits = 1 << 30; // ~1 billion.
static const int kMaxLength = static const int kMaxLength =
kMaxLengthBits / (kSystemPointerSize * kBitsPerByte); kMaxLengthBits / (kSystemPointerSize * kBitsPerByte);
......
...@@ -19,8 +19,8 @@ assertTrue(0n === 0n); ...@@ -19,8 +19,8 @@ assertTrue(0n === 0n);
// crbug.com/818277: Must throw without DCHECK failures. // crbug.com/818277: Must throw without DCHECK failures.
// In order to run acceptably fast in Debug mode, this test assumes that // In order to run acceptably fast in Debug mode, this test assumes that
// we allow at least 2 billion bits in a BigInt. // we allow at least 1 billion bits in a BigInt.
var close_to_limit = 2n ** 2000000000n; var close_to_limit = 2n ** 1000000000n;
assertThrows(() => close_to_limit ** 100n, RangeError); assertThrows(() => close_to_limit ** 100n, RangeError);
// Check boundary conditions of the power-of-two fast path. // Check boundary conditions of the power-of-two fast path.
......
// Copyright 2018 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.
let just_under = 2n ** 30n - 1n;
let just_above = 2n ** 30n;
assertDoesNotThrow(() => { var dummy = 2n ** just_under; });
assertThrows(() => { var dummy = 2n ** just_above; });
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