Coverage Report

Created: 2025-12-30 08:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/node/deps/v8/include/v8-external.h
Line
Count
Source
1
// Copyright 2021 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 INCLUDE_V8_EXTERNAL_H_
6
#define INCLUDE_V8_EXTERNAL_H_
7
8
#include "v8-value.h"  // NOLINT(build/include_directory)
9
#include "v8config.h"  // NOLINT(build/include_directory)
10
11
namespace v8 {
12
13
class Isolate;
14
15
/**
16
 * A tag for external pointers. Objects with different C++ types should use
17
 * different values of ExternalPointerTypeTag when using v8::External. The
18
 * allowed range is 0..V8_EXTERNAL_POINTER_TAG_COUNT - 1. If this is not
19
 * sufficient, V8_EXTERNAL_POINTER_TAG_COUNT can be increased.
20
 */
21
using ExternalPointerTypeTag = uint16_t;
22
23
constexpr ExternalPointerTypeTag kExternalPointerTypeTagDefault = 0;
24
25
/**
26
 * A JavaScript value that wraps a C++ void*. This type of value is mainly used
27
 * to associate C++ data structures with JavaScript objects.
28
 */
29
class V8_EXPORT External : public Value {
30
 public:
31
  V8_DEPRECATE_SOON("Use the version with the type tag.")
32
0
  static Local<External> New(Isolate* isolate, void* value) {
33
0
    return New(isolate, value, kExternalPointerTypeTagDefault);
34
0
  }
35
  static Local<External> New(Isolate* isolate, void* value,
36
                             ExternalPointerTypeTag tag);
37
0
  V8_INLINE static External* Cast(Value* value) {
38
0
#ifdef V8_ENABLE_CHECKS
39
0
    CheckCast(value);
40
0
#endif
41
0
    return static_cast<External*>(value);
42
0
  }
43
44
  V8_DEPRECATE_SOON("Use the version with the type tag.")
45
0
  void* Value() const { return Value(kExternalPointerTypeTagDefault); }
46
47
  void* Value(ExternalPointerTypeTag tag) const;
48
49
 private:
50
  static void CheckCast(v8::Value* obj);
51
};
52
53
}  // namespace v8
54
55
#endif  // INCLUDE_V8_EXTERNAL_H_