#include <stdlib.h>
#include "include/v8-json.h"
#include "include/v8-template.h"
#include "src/api/api-inl.h"
#include "src/base/platform/elapsed-timer.h"
#include "src/base/strings.h"
#include "src/execution/messages.h"
#include "src/heap/factory.h"
#include "src/heap/heap-inl.h"
#include "src/objects/objects-inl.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"
class MyRandomNumberGenerator { … };
namespace v8 {
namespace internal {
namespace test_strings {
static const int DEEP_DEPTH = …;
static const int SUPER_DEEP_DEPTH = …;
class Resource : public v8::String::ExternalStringResource { … };
class OneByteResource : public v8::String::ExternalOneByteStringResource { … };
static void InitializeBuildingBlocks(Handle<String>* building_blocks,
int bb_length, bool long_blocks,
MyRandomNumberGenerator* rng) { … }
class ConsStringStats { … };
void ConsStringStats::Reset() { … }
void ConsStringStats::VerifyEqual(const ConsStringStats& that) const { … }
class ConsStringGenerationData { … };
ConsStringGenerationData::ConsStringGenerationData(bool long_blocks) { … }
Handle<String> ConsStringGenerationData::block(uint32_t offset) { … }
Handle<String> ConsStringGenerationData::block(int offset) { … }
void ConsStringGenerationData::Reset() { … }
void AccumulateStats(Tagged<ConsString> cons_string, ConsStringStats* stats) { … }
void AccumulateStats(DirectHandle<String> cons_string, ConsStringStats* stats) { … }
void AccumulateStatsWithOperator(Tagged<ConsString> cons_string,
ConsStringStats* stats) { … }
void VerifyConsString(DirectHandle<String> root,
ConsStringGenerationData* data) { … }
static Handle<String> ConstructRandomString(ConsStringGenerationData* data,
unsigned max_recursion) { … }
static Handle<String> ConstructLeft(ConsStringGenerationData* data, int depth) { … }
static Handle<String> ConstructRight(ConsStringGenerationData* data,
int depth) { … }
static Handle<String> ConstructBalancedHelper(ConsStringGenerationData* data,
int from, int to) { … }
static Handle<String> ConstructBalanced(ConsStringGenerationData* data,
int depth = DEEP_DEPTH) { … }
static void Traverse(DirectHandle<String> s1, DirectHandle<String> s2) { … }
static void TraverseFirst(DirectHandle<String> s1, DirectHandle<String> s2,
int chars) { … }
TEST(Traverse) { … }
TEST(ConsStringWithEmptyFirstFlatten) { … }
static void VerifyCharacterStream(Tagged<String> flat_string,
Tagged<String> cons_string) { … }
static inline void PrintStats(const ConsStringGenerationData& data) { … }
template <typename BuildString>
void TestStringCharacterStream(BuildString build, int test_cases) { … }
static const int kCharacterStreamNonRandomCases = …;
static Handle<String> BuildEdgeCaseConsString(int test_case,
ConsStringGenerationData* data) { … }
TEST(StringCharacterStreamEdgeCases) { … }
static const int kBalances = …;
static const int kTreeLengths = …;
static const int kEmptyLeaves = …;
static const int kUniqueRandomParameters = …;
static void InitializeGenerationData(int test_case,
ConsStringGenerationData* data) { … }
static Handle<String> BuildRandomConsString(int test_case,
ConsStringGenerationData* data) { … }
TEST(StringCharacterStreamRandom) { … }
static const int kDeepOneByteDepth = …;
TEST(DeepOneByte) { … }
TEST(Utf8Conversion) { … }
TEST(Utf8ConversionPerf) { … }
TEST(ExternalShortStringAdd) { … }
TEST(ReplaceInvalidUtf8) { … }
TEST(JSONStringifyWellFormed) { … }
TEST(CachedHashOverflow) { … }
TEST(SliceFromCons) { … }
class OneByteVectorResource : public v8::String::ExternalOneByteStringResource { … };
TEST(InternalizeExternal) { … }
TEST(Regress1402187) { … }
TEST(SliceFromExternal) { … }
static void ExternalizeDuringJsonStringifyCallback(
const v8::FunctionCallbackInfo<v8::Value>& args) { … }
TEST(ExternalizeDuringJsonStringify) { … }
TEST(TrivialSlice) { … }
TEST(SliceFromSlice) { … }
UNINITIALIZED_TEST(OneByteArrayJoin) { … }
namespace {
int* global_use_counts = …;
void MockUseCounterCallback(v8::Isolate* isolate,
v8::Isolate::UseCounterFeature feature) { … }
}
TEST(CountBreakIterator) { … }
TEST(StringReplaceAtomTwoByteResult) { … }
TEST(IsAscii) { … }
template <typename Op, bool return_first>
static uint16_t ConvertLatin1(uint16_t c) { … }
#ifndef V8_INTL_SUPPORT
static void CheckCanonicalEquivalence(uint16_t c, uint16_t test) {
uint16_t expect = ConvertLatin1<unibrow::Ecma262UnCanonicalize, true>(c);
if (expect > unibrow::Latin1::kMaxChar || expect == 0) expect = c;
CHECK_EQ(expect, test);
}
static inline uint16_t TryConvertToLatin1(uint16_t c) {
switch (c) {
case 0x39c:
case 0x3bc:
return 0xb5;
case 0x178:
return 0xff;
}
return c;
}
TEST(Latin1IgnoreCase) {
for (uint16_t c = unibrow::Latin1::kMaxChar + 1; c != 0; c++) {
uint16_t lower = ConvertLatin1<unibrow::ToLowercase, false>(c);
uint16_t upper = ConvertLatin1<unibrow::ToUppercase, false>(c);
uint16_t test = TryConvertToLatin1(c);
if (lower == 0 && upper == 0) {
CheckCanonicalEquivalence(c, test);
continue;
}
if (lower > unibrow::Latin1::kMaxChar &&
upper > unibrow::Latin1::kMaxChar) {
CheckCanonicalEquivalence(c, test);
continue;
}
if (lower == 0 && upper != 0) {
lower = ConvertLatin1<unibrow::ToLowercase, false>(upper);
}
if (upper == 0 && lower != c) {
upper = ConvertLatin1<unibrow::ToUppercase, false>(lower);
}
if (lower > unibrow::Latin1::kMaxChar &&
upper > unibrow::Latin1::kMaxChar) {
CheckCanonicalEquivalence(c, test);
continue;
}
if (upper != c && lower != c) {
CheckCanonicalEquivalence(c, test);
continue;
}
CHECK_EQ(std::min(upper, lower), test);
}
}
#endif
class DummyResource : public v8::String::ExternalStringResource { … };
class DummyOneByteResource : public v8::String::ExternalOneByteStringResource { … };
TEST(InvalidExternalString) { … }
#define INVALID_STRING_TEST …
INVALID_STRING_TEST …
INVALID_STRING_TEST …
#undef INVALID_STRING_TEST
TEST(FormatMessage) { … }
TEST(Regress609831) { … }
TEST(ExternalStringIndexOf) { … }
namespace {
struct IndexData { … };
void TestString(i::Isolate* isolate, const IndexData& data) { … }
}
TEST(HashArrayIndexStrings) { … }
TEST(StringEquals) { … }
class OneByteStringResource : public v8::String::ExternalOneByteStringResource { … };
TEST(InternalizeExternalString) { … }
TEST(InternalizeExternalStringTwoByte) { … }
class UncachedExternalOneByteResource
: public v8::String::ExternalOneByteStringResource { … };
TEST(InternalizeExternalStringUncachedWithCopy) { … }
class UncachedExternalResource : public v8::String::ExternalStringResource { … };
TEST(InternalizeExternalStringUncachedWithCopyTwoByte) { … }
TEST(CheckCachedDataInternalExternalUncachedString) { … }
TEST(CheckCachedDataInternalExternalUncachedStringTwoByte) { … }
TEST(CheckIntlSegmentIteratorTerminateExecutionInterrupt) { … }
}
}
}