chromium/content/services/auction_worklet/lazy_filler.h

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

#ifndef CONTENT_SERVICES_AUCTION_WORKLET_LAZY_FILLER_H_
#define CONTENT_SERVICES_AUCTION_WORKLET_LAZY_FILLER_H_

#include <string_view>

#include "base/memory/raw_ptr.h"
#include "v8/include/v8-external.h"
#include "v8/include/v8-forward.h"
#include "v8/include/v8-function-callback.h"
#include "v8/include/v8-object.h"

namespace auction_worklet {

class AuctionV8Helper;

// Helper class to populate fields of one or more v8::Objects on first access.
// The associated v8::Context must be destroyed immediately after the LazyFiller
// to avoid a UAF. Before would be better, but LazyFiller subclasses often have
// raw pointers to other context-scoped variables (e.g., an AuctionV8Logger)
// which must be destroyed after the LazyFiller.
//
// API for implementers is as follows:
//
// 1) Call DefineLazyAttribute() and/or DefineLazyAttributeWithMetadata()
//     for all relevant attributes. There's no requirement that all calls be
//     on the same object (e.g., can defined lazy attributes on objects
//     contained within the same top-level object).
//
// 2) In the static helpers registered with DefineLazyAttribute
//    (which take (v8::Local<v8::Name> name,
//                 const v8::PropertyCallbackInfo<v8::Value>& info)
//    Use GetSelf() / GetSelfWithMetadata() and SetResult() to provide value.
//
//    If you use the JSON parser, make sure to eat exceptions with v8::TryCatch.
class LazyFiller {};

}  // namespace auction_worklet

#endif  // CONTENT_SERVICES_AUCTION_WORKLET_LAZY_FILLER_H_