v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
shared-object-conveyor-handles.h
Go to the documentation of this file.
1// Copyright 2022 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_HANDLES_SHARED_OBJECT_CONVEYOR_HANDLES_H_
6#define V8_HANDLES_SHARED_OBJECT_CONVEYOR_HANDLES_H_
7
8#include <memory>
9#include <vector>
10
12
13namespace v8 {
14namespace internal {
15
16class PersistentHandles;
17
18// Wrapper around PersistentHandles that is used to convey shared objects
19// (i.e. keep them alive) from a ValueSerializer to a ValueDeserializer for APIs
20// like postMessage.
21//
22// The conveyor must be allocated in an isolate that remains alive until the
23// ValueDeserializer in the receiving isolate finishes processing the message.
24//
25// Each shared object gets an id that is stable across GCs.
26//
27// The embedder owns the lifetime of instances of this class. See
28// v8::SharedValueConveyor.
30 public:
31 explicit SharedObjectConveyorHandles(Isolate* isolate);
32
35 delete;
36
37 uint32_t Persist(Tagged<HeapObject> shared_object);
38
39 bool HasPersisted(uint32_t object_id) const {
40 return object_id < shared_objects_.size();
41 }
42
43 Tagged<HeapObject> GetPersisted(uint32_t object_id) const {
44 DCHECK(HasPersisted(object_id));
45 return *shared_objects_[object_id];
46 }
47
48 private:
49 std::unique_ptr<PersistentHandles> persistent_handles_;
50 std::vector<Handle<HeapObject>> shared_objects_;
51};
52
53} // namespace internal
54} // namespace v8
55
56#endif // V8_HANDLES_SHARED_OBJECT_CONVEYOR_HANDLES_H_
SharedObjectConveyorHandles(const SharedObjectConveyorHandles &)=delete
uint32_t Persist(Tagged< HeapObject > shared_object)
SharedObjectConveyorHandles & operator=(const SharedObjectConveyorHandles &)=delete
Tagged< HeapObject > GetPersisted(uint32_t object_id) const
std::vector< Handle< HeapObject > > shared_objects_
std::unique_ptr< PersistentHandles > persistent_handles_
#define DCHECK(condition)
Definition logging.h:482