chromium/third_party/blink/renderer/platform/bindings/to_blink_string.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/bindings/to_blink_string.h"

#include <type_traits>

#include "third_party/blink/renderer/platform/bindings/string_resource.h"
#include "third_party/blink/renderer/platform/bindings/v8_binding.h"

namespace blink {

namespace {

template <class StringClass>
struct StringTraits {};

template <>
struct StringTraits<String> {};

template <>
struct StringTraits<AtomicString> {};

struct V8StringTwoBytesTrait {};

struct V8StringOneByteTrait {};

template <typename V8StringTrait>
String StringTraits<String>::FromV8String(v8::Isolate* isolate,
                                          v8::Local<v8::String> v8_string,
                                          int length) {}

template <typename V8StringTrait>
AtomicString StringTraits<AtomicString>::FromV8String(
    v8::Isolate* isolate,
    v8::Local<v8::String> v8_string,
    int length) {}

ALWAYS_INLINE bool CanExternalize(v8::Local<v8::String> v8_string,
                                  ExternalMode mode,
                                  bool is_one_byte) {}

// Retrieves the StringResourceBase from `v8_string`.
//
// Returns a nullptr if there was no previous externalization.
ALWAYS_INLINE StringResourceBase* GetExternalizedString(
    v8::Isolate* isolate,
    v8::Local<v8::String> v8_string) {}

// Converts a `v8_string` to a StringType optionally externalizing if
// `can_externalize` is true; sets `was_externalized` if on successful
// externalization.
//
// If the string was not successfully externalized, then the calling code
// may have the only reference to the StringType and must handle retaining
// it to keep it alive.
template <typename StringType>
ALWAYS_INLINE StringType
ConvertAndExternalizeString(v8::Isolate* isolate,
                            v8::Local<v8::String> v8_string,
                            bool can_externalize,
                            bool is_one_byte,
                            bool* was_externalized) {}

}  // namespace

template <typename StringType>
StringType ToBlinkString(v8::Isolate* isolate,
                         v8::Local<v8::String> v8_string,
                         ExternalMode mode) {}

// Explicitly instantiate the above template with the expected
// parameterizations, to ensure the compiler generates the code; otherwise link
// errors can result in GCC 4.4.
template String ToBlinkString<String>(v8::Isolate* isolate,
                                      v8::Local<v8::String>,
                                      ExternalMode);
template AtomicString ToBlinkString<AtomicString>(v8::Isolate* isolate,
                                                  v8::Local<v8::String>,
                                                  ExternalMode);

StringView ToBlinkStringView(v8::Isolate* isolate,
                             v8::Local<v8::String> v8_string,
                             StringView::StackBackingStore& backing_store,
                             ExternalMode mode) {}

// Fast but non thread-safe version.
static String ToBlinkStringFast(int value) {}

String ToBlinkString(int value) {}

}  // namespace blink