Commit 67b5a501 authored by mlippautz's avatar mlippautz Committed by Commit bot

Remove SealHandleScope from TryNumberToSize conversion

This function should also be callable from a concurrent thread, so we cannot use
the scope here. Instead, provide a test that checks that no handles are created.

R=ulan@chromium.org
TEST=cctest/test-conversions/NoHandlesForTryNumberToSize
BUG=

Review-Url: https://codereview.chromium.org/2106083002
Cr-Commit-Position: refs/heads/master@{#37381}
parent bf5641f9
...@@ -133,7 +133,8 @@ int64_t NumberToInt64(Object* number) { ...@@ -133,7 +133,8 @@ int64_t NumberToInt64(Object* number) {
} }
bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result) { bool TryNumberToSize(Isolate* isolate, Object* number, size_t* result) {
SealHandleScope shs(isolate); // Do not create handles in this function! Don't use SealHandleScope because
// the function can be used concurrently.
if (number->IsSmi()) { if (number->IsSmi()) {
int value = Smi::cast(number)->value(); int value = Smi::cast(number)->value();
DCHECK(static_cast<unsigned>(Smi::kMaxValue) <= DCHECK(static_cast<unsigned>(Smi::kMaxValue) <=
......
...@@ -406,3 +406,30 @@ TEST(SpecialIndexParsing) { ...@@ -406,3 +406,30 @@ TEST(SpecialIndexParsing) {
CheckNonArrayIndex(false, "-9999999999999999"); CheckNonArrayIndex(false, "-9999999999999999");
CheckNonArrayIndex(false, "42949672964294967296429496729694966"); CheckNonArrayIndex(false, "42949672964294967296429496729694966");
} }
TEST(NoHandlesForTryNumberToSize) {
i::Isolate* isolate = CcTest::i_isolate();
size_t result = 0;
{
SealHandleScope no_handles(isolate);
Smi* smi = Smi::FromInt(1);
CHECK(TryNumberToSize(isolate, smi, &result));
CHECK_EQ(result, 1);
}
result = 0;
{
HandleScope scope(isolate);
Handle<HeapNumber> heap_number1 = isolate->factory()->NewHeapNumber(2.0);
{
SealHandleScope no_handles(isolate);
CHECK(TryNumberToSize(isolate, *heap_number1, &result));
CHECK_EQ(result, 2);
}
Handle<HeapNumber> heap_number2 = isolate->factory()->NewHeapNumber(
static_cast<double>(std::numeric_limits<size_t>::max()) + 10000.0);
{
SealHandleScope no_handles(isolate);
CHECK(!TryNumberToSize(isolate, *heap_number2, &result));
}
}
}
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