chromium/third_party/blink/renderer/platform/bindings/dom_data_store.h

/*
 * Copyright (C) 2009 Google Inc. 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.
 */

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_DOM_DATA_STORE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_DOM_DATA_STORE_H_

#include "base/containers/contains.h"
#include "third_party/blink/renderer/platform/bindings/dom_wrapper_world.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/bindings/trace_wrapper_v8_reference.h"
#include "third_party/blink/renderer/platform/bindings/wrapper_type_info.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_hash_map.h"
#include "third_party/blink/renderer/platform/heap/prefinalizer.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/stack_util.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
#include "v8/include/v8.h"

namespace blink {

// DOMDataStore is the entity responsible for managing wrapper references (C++
// to JS) in different worlds and settings (get/set wrapper, set return value).
// Such references are stored in two ways:
// - Inline in ScriptWrappable (or CustomWrappable); or
// - In an ephemeron map in the DOMDataStore instance that is tied to a context
//   in a V8 Isolate.
//
// The methods on DOMDataStore generally come in two forms:
// - static methods: Have fast paths for inline storage (e.g. main world on the
//   main rendering thread) and otherwise consider the current world, i.e., the
//   world that corresponds to the current context
//   (`v8::Isolate::GetCurrentContext()`).
// - instance methods: Have fast paths for inline storage and consider the
//   world the methods are invoked on. The calls are faster than the static
//   calls if the DOMDataStore is already around.
//
// Exceptions are methods that operate on all worlds instead of the current
// world. The methods mention this fact explicitly.
class DOMDataStore final : public GarbageCollected<DOMDataStore> {};

// static
bool DOMDataStore::SetReturnValue(v8::ReturnValue<v8::Value> return_value,
                                  ScriptWrappable* value) {}

// static
bool DOMDataStore::SetReturnValueFromInlineStorage(
    v8::ReturnValue<v8::Value> return_value,
    const ScriptWrappable* value) {}

// static
bool DOMDataStore::SetReturnValueFast(v8::ReturnValue<v8::Value> return_value,
                                      ScriptWrappable* object,
                                      v8::Local<v8::Object> v8_receiver,
                                      const ScriptWrappable* blink_receiver) {}

bool DOMDataStore::SetReturnValueFrom(v8::ReturnValue<v8::Value> return_value,
                                      const ScriptWrappable* value) {}

// static
v8::MaybeLocal<v8::Object> DOMDataStore::GetWrapper(
    v8::Isolate* isolate,
    const ScriptWrappable* object) {}

// static
v8::MaybeLocal<v8::Object> DOMDataStore::GetWrapper(
    ScriptState* script_state,
    const ScriptWrappable* object) {}

template <bool entered_context>
v8::MaybeLocal<v8::Object> DOMDataStore::Get(v8::Isolate* isolate,
                                             const ScriptWrappable* object) {}

// static
bool DOMDataStore::SetWrapper(v8::Isolate* isolate,
                              ScriptWrappable* object,
                              const WrapperTypeInfo* wrapper_type_info,
                              v8::Local<v8::Object>& wrapper) {}

// static
template <bool entered_context>
bool DOMDataStore::SetWrapperInInlineStorage(
    v8::Isolate* isolate,
    ScriptWrappable* object,
    const WrapperTypeInfo* wrapper_type_info,
    v8::Local<v8::Object>& wrapper) {}

template <bool entered_context>
bool DOMDataStore::Set(v8::Isolate* isolate,
                       ScriptWrappable* object,
                       const WrapperTypeInfo* wrapper_type_info,
                       v8::Local<v8::Object>& wrapper) {}

//  static
bool DOMDataStore::ContainsWrapper(v8::Isolate* isolate,
                                   const ScriptWrappable* object) {}

// Same as `ContainsWrapper()` but for a single world.
bool DOMDataStore::Contains(const ScriptWrappable* object) const {}

// static
template <typename HandleType>
bool DOMDataStore::ClearWrapperInAnyWorldIfEqualTo(ScriptWrappable* object,
                                                   const HandleType& handle) {}

// static
template <typename HandleType>
bool DOMDataStore::ClearInlineStorageWrapperIfEqualTo(
    ScriptWrappable* object,
    const HandleType& handle) {}

template <typename HandleType>
bool DOMDataStore::EqualTo(const ScriptWrappable* object,
                           const HandleType& handle) {}

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_DOM_DATA_STORE_H_