chromium/v8/test/cctest/test-strings.cc

// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above
//       copyright notice, this list of conditions and the following
//       disclaimer in the documentation and/or other materials provided
//       with the distribution.
//     * Neither the name of Google Inc. nor the names of its
//       contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Check that we can traverse very deep stacks of ConsStrings using
// StringCharacterStram.  Check that Get(int) works on very deep stacks
// of ConsStrings.  These operations may not be very fast, but they
// should be possible without getting errors due to too deep recursion.

#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"

// Adapted from http://en.wikipedia.org/wiki/Multiply-with-carry
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
namespace {

int* global_use_counts =;

void MockUseCounterCallback(v8::Isolate* isolate,
                            v8::Isolate::UseCounterFeature feature) {}
}  // namespace

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) {
    // This are equivalent characters in unicode.
    case 0x39c:
    case 0x3bc:
      return 0xb5;
    // This is an uppercase of a Latin-1 character
    // outside of Latin-1.
    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);
    // Filter out all character whose upper is not their lower or vice versa.
    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) {}

}  // namespace

TEST(HashArrayIndexStrings) {}

TEST(StringEquals) {}

class OneByteStringResource : public v8::String::ExternalOneByteStringResource {};

// Show that it is possible to internalize an external string without a copy, as
// long as it is not uncached.
TEST(InternalizeExternalString) {}

// Show that it is possible to internalize an external string without a copy, as
// long as it is not uncached. Two byte version.
TEST(InternalizeExternalStringTwoByte) {}

class UncachedExternalOneByteResource
    : public v8::String::ExternalOneByteStringResource {};

// Show that we can internalize an external uncached string, by creating a copy.
TEST(InternalizeExternalStringUncachedWithCopy) {}

class UncachedExternalResource : public v8::String::ExternalStringResource {};

// Show that we can internalize an external uncached string, by creating a copy.
// Two byte version.
TEST(InternalizeExternalStringUncachedWithCopyTwoByte) {}

// Show that we cache the data pointer for internal, external and uncached
// strings with cacheable resources through MakeExternal. One byte version.
TEST(CheckCachedDataInternalExternalUncachedString) {}

// Show that we cache the data pointer for internal, external and uncached
// strings with cacheable resources through MakeExternal. Two byte version.
TEST(CheckCachedDataInternalExternalUncachedStringTwoByte) {}

TEST(CheckIntlSegmentIteratorTerminateExecutionInterrupt) {}

}  // namespace test_strings
}  // namespace internal
}  // namespace v8