v8/test/unittests/compiler/js-native-context-specialization-unittest.cc
Nico Hartmann 2d26a2688a [TurboFan] Fix max double string length in JSNativeContextSpecialization
Some string constant optimizations in JSNativeContextSpecialization
assumed an incorrect maximal string length of double values.

Bug: chromium:1189077, chromium:1178718
Change-Id: Iae531f0e323679a4490e666a971b66655c25c757
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2843361
Commit-Queue: Nico Hartmann <nicohartmann@chromium.org>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74101}
2021-04-21 13:29:50 +00:00

50 lines
1.5 KiB
C++

// Copyright 2014 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.
#include "test/unittests/compiler/graph-unittest.h"
#include "src/compiler/js-native-context-specialization.h"
#include "src/compiler/js-operator.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/simplified-operator.h"
namespace v8 {
namespace internal {
namespace compiler {
namespace js_native_context_specialization_unittest {
class JSNativeContextSpecializationTest : public GraphTest {
public:
explicit JSNativeContextSpecializationTest(int num_parameters = 1)
: GraphTest(num_parameters), javascript_(zone()) {}
~JSNativeContextSpecializationTest() override {}
protected:
JSOperatorBuilder* javascript() { return &javascript_; }
private:
JSOperatorBuilder javascript_;
};
TEST_F(JSNativeContextSpecializationTest, GetMaxStringLengthOfString) {
const size_t str_len = 3;
const size_t num_len = kMaxDoubleStringLength;
Node* const str_node = graph()->NewNode(
common()->HeapConstant(factory()->InternalizeUtf8String("str")));
EXPECT_EQ(
JSNativeContextSpecialization::GetMaxStringLength(broker(), str_node),
str_len);
Node* const num_node = graph()->NewNode(common()->NumberConstant(10.0 / 3));
EXPECT_EQ(
JSNativeContextSpecialization::GetMaxStringLength(broker(), num_node),
num_len);
}
} // namespace js_native_context_specialization_unittest
} // namespace compiler
} // namespace internal
} // namespace v8