chromium/third_party/blink/renderer/bindings/core/v8/idl_types.h

// 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.

#ifndef THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_IDL_TYPES_H_
#define THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_IDL_TYPES_H_

#include <optional>
#include <type_traits>

#include "base/time/time.h"
#include "third_party/blink/renderer/bindings/core/v8/idl_types_base.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits.h"
#include "third_party/blink/renderer/platform/heap/heap_traits.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

class BigInt;
class EventListener;
class ScriptPromiseUntyped;
class ScriptValue;
struct ToV8UndefinedGenerator;

// The type names below are named as "IDL" prefix + Web IDL type name.
// https://webidl.spec.whatwg.org/#dfn-type-name
// undefined
// TODO(japhet): Use IDLUndefined in place of ToV8UndefinedGenerator and delete
// ToV8UndefinedGenerator. Using IDLUndefined here makes calls to
// ScriptPromseResolver::Resolve/Reject ambiguous between the ToV8() variant
// and the ToV8Traits<>::ToV8() variant of those functions.
struct IDLUndefined final : public IDLBaseHelper<ToV8UndefinedGenerator> {};

// any
struct IDLAny final : public IDLBaseHelper<ScriptValue> {};

// boolean
struct IDLBoolean final : public IDLBaseHelper<bool> {};

// bigint
struct IDLBigint final : public IDLBaseHelper<BigInt> {};

// Integer types

namespace bindings {

enum class IDLIntegerConvMode {};

}  // namespace bindings

template <typename T,
          bindings::IDLIntegerConvMode mode =
              bindings::IDLIntegerConvMode::kDefault>
struct IDLIntegerTypeBase final : public IDLBaseHelper<T> {};

// Integers
IDLByte;
IDLOctet;
IDLShort;
IDLUnsignedShort;
IDLLong;
IDLUnsignedLong;
IDLLongLong;
IDLUnsignedLongLong;

// [Clamp] Integers
IDLByteClamp;
IDLOctetClamp;
IDLShortClamp;
IDLUnsignedShortClamp;
IDLLongClamp;
IDLUnsignedLongClamp;
IDLLongLongClamp;
IDLUnsignedLongLongClamp;

// [EnforceRange] Integers
IDLByteEnforceRange;
IDLOctetEnforceRange;
IDLShortEnforceRange;
IDLUnsignedShortEnforceRange;
IDLLongEnforceRange;
IDLUnsignedLongEnforceRange;
IDLLongLongEnforceRange;
IDLUnsignedLongLongEnforceRange;

// Floating point number types

namespace bindings {

enum class IDLFloatingPointNumberConvMode {};

}  // namespace bindings

template <typename T,
          bindings::IDLFloatingPointNumberConvMode mode =
              bindings::IDLFloatingPointNumberConvMode::kDefault>
struct IDLFloatingPointNumberTypeBase final : public IDLBaseHelper<T> {};

// float
IDLFloat;
IDLUnrestrictedFloat;

// double
IDLDouble;
IDLUnrestrictedDouble;

// DOMHighResTimeStamp
// https://w3c.github.io/hr-time/#sec-domhighrestimestamp
IDLDOMHighResTimeStamp;

// Strings

namespace bindings {

enum class IDLStringConvMode {};

}  // namespace bindings

// Base class for IDL string types (except for enumeration types)
struct IDLStringTypeBase : public IDLBaseHelper<String> {};

// ByteString
template <bindings::IDLStringConvMode mode>
struct IDLByteStringBase final : public IDLStringTypeBase {};
IDLByteString;

// DOMString
template <bindings::IDLStringConvMode mode>
struct IDLStringBase final : public IDLStringTypeBase {};
IDLString;
IDLStringLegacyNullToEmptyString;

// USVString
template <bindings::IDLStringConvMode mode>
struct IDLUSVStringBase final : public IDLStringTypeBase {};
IDLUSVString;

// [StringContext=TrustedHTML] DOMString
template <bindings::IDLStringConvMode mode>
struct IDLStringStringContextTrustedHTMLBase final : public IDLStringTypeBase {};
IDLStringStringContextTrustedHTML;
IDLStringLegacyNullToEmptyStringStringContextTrustedHTML;

// [StringContext=TrustedScript] DOMString
template <bindings::IDLStringConvMode mode>
struct IDLStringStringContextTrustedScriptBase final
    : public IDLStringTypeBase {};
IDLStringStringContextTrustedScript;
IDLStringLegacyNullToEmptyStringStringContextTrustedScript;

// [StringContext=TrustedScriptURL] USVString
template <bindings::IDLStringConvMode mode>
struct IDLUSVStringStringContextTrustedScriptURLBase final
    : public IDLStringTypeBase {};
IDLUSVStringStringContextTrustedScriptURL;

// object
struct IDLObject final : public IDLBaseHelper<ScriptValue> {};

// Promise types
struct IDLPromise final : public IDLBaseHelper<ScriptPromiseUntyped> {};

// Sequence types
template <typename T>
struct IDLSequence final : public IDLBase {};

// Frozen array types
template <typename T>
struct IDLArray final : public IDLBase {};

// Record types
template <typename Key, typename Value>
struct IDLRecord final : public IDLBase {};

// Nullable types
template <typename T>
struct IDLNullable final : public IDLBase {};

// Date
struct IDLDate final : public IDLBaseHelper<base::Time> {};

// EventHandler types
struct IDLEventHandler final : public IDLBaseHelper<EventListener*> {};
struct IDLOnBeforeUnloadEventHandler final
    : public IDLBaseHelper<EventListener*> {};
struct IDLOnErrorEventHandler final : public IDLBaseHelper<EventListener*> {};

// [BufferSourceTypeNoSizeLimit]
template <typename T>
struct IDLBufferSourceTypeNoSizeLimit {};

// [AllowResizable]
template <typename T>
struct IDLAllowResizable {};

// IDL optional types
//
// IDLOptional represents an optional argument and supports a conversion from
// ES undefined to "missing" special value.  The "missing" value might be
// represented in Blink as std::nullopt, nullptr, 0, etc. depending on a Blink
// type.
//
// Note that IDLOptional is not meant to represent an optional dictionary
// member.
template <typename T>
struct IDLOptional final : public IDLBase {};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_BINDINGS_CORE_V8_IDL_TYPES_H_