v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8-serialization-duplicate-tracker.cc
Go to the documentation of this file.
1// Copyright 2023 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
6
9#include "src/base/logging.h"
10
11namespace v8_inspector {
12
13std::unique_ptr<protocol::DictionaryValue>
15 v8::Local<v8::Value> v8Value, bool* isKnown) {
16 std::unique_ptr<protocol::DictionaryValue> result =
17 protocol::DictionaryValue::create();
18
19 protocol::DictionaryValue* maybeKnownSerializedValue =
21
22 if (maybeKnownSerializedValue == nullptr) {
23 *isKnown = false;
24 // Keep reference to the serialized value, so that
25 // `weakLocalObjectReference` can be set later.
26 SetKnownSerializedValue(v8Value, result.get());
27 } else {
28 *isKnown = true;
29
31 maybeKnownSerializedValue->getString("type", &type);
32 result->setString("type", type);
33
34 int weakLocalObjectReference;
35 // If `maybeKnownSerializedValue` has no `weakLocalObjectReference` yet,
36 // it's need to be set.
37 if (!maybeKnownSerializedValue->getInteger("weakLocalObjectReference",
38 &weakLocalObjectReference)) {
39 weakLocalObjectReference = m_counter++;
40 maybeKnownSerializedValue->setInteger("weakLocalObjectReference",
41 weakLocalObjectReference);
42 }
43 result->setInteger("weakLocalObjectReference", weakLocalObjectReference);
44 }
45
46 return result;
47}
48
50 v8::Local<v8::Value> v8Value, protocol::DictionaryValue* serializedValue) {
53 ->Set(m_context, v8Value,
54 v8::External::New(m_context->GetIsolate(), serializedValue))
55 .ToLocalChecked();
56}
57
58protocol::DictionaryValue*
60 v8::Local<v8::Value> v8Value) {
61 v8::Local<v8::Value> knownValue;
63 .ToLocal(&knownValue) ||
64 knownValue->IsUndefined()) {
65 return nullptr;
66 }
67
68 return static_cast<protocol::DictionaryValue*>(
69 knownValue.As<v8::External>()->Value());
70}
71
74 : m_context(context),
75 m_counter(1),
76 m_v8ObjectToSerializedDictionary(v8::Map::New(context->GetIsolate())) {}
77} // namespace v8_inspector
Isolate * GetIsolate()
Definition api.cc:7176
void * Value() const
Definition api.cc:7498
static Local< External > New(Isolate *isolate, void *value)
Definition api.cc:7483
V8_INLINE Local< S > As() const
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Get(Local< Context > context, Local< Value > key)
Definition api.cc:8427
V8_WARN_UNUSED_RESULT MaybeLocal< Map > Set(Local< Context > context, Local< Value > key, Local< Value > value)
Definition api.cc:8440
V8_WARN_UNUSED_RESULT V8_INLINE bool ToLocal(Local< S > *out) const
V8_EXPORT V8SerializationDuplicateTracker(v8::Local< v8::Context > context)
V8_EXPORT void SetKnownSerializedValue(v8::Local< v8::Value > v8Value, protocol::DictionaryValue *serializedValue)
V8_EXPORT protocol::DictionaryValue * FindKnownSerializedValue(v8::Local< v8::Value > v8Value)
V8_EXPORT std::unique_ptr< protocol::DictionaryValue > LinkExistingOrCreate(v8::Local< v8::Value > v8Value, bool *isKnown)
ZoneVector< RpoNumber > & result
v8::Local< v8::Context > m_context
wasm::ValueType type