Skip to content

Commit b215bf9

Browse files
gengjiawenrefack
authored andcommitted
src: inline macro DISALLOW_COPY_AND_ASSIGN
PR-URL: nodejs#26634 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent ed60e86 commit b215bf9

14 files changed

+82
-48
lines changed

src/env.h

+20-14
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ class IsolateData {
426426

427427
std::unordered_map<nghttp2_rcbuf*, v8::Eternal<v8::String>> http2_static_strs;
428428
inline v8::Isolate* isolate() const;
429+
IsolateData(const IsolateData&) = delete;
430+
IsolateData& operator=(const IsolateData&) = delete;
429431

430432
private:
431433
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
@@ -448,8 +450,6 @@ class IsolateData {
448450
const bool uses_node_allocator_;
449451
MultiIsolatePlatform* platform_;
450452
std::shared_ptr<PerIsolateOptions> options_;
451-
452-
DISALLOW_COPY_AND_ASSIGN(IsolateData);
453453
};
454454

455455
struct ContextInfo {
@@ -534,6 +534,9 @@ class AsyncRequest : public MemoryRetainer {
534534

535535
class Environment {
536536
public:
537+
Environment(const Environment&) = delete;
538+
Environment& operator=(const Environment&) = delete;
539+
537540
class AsyncHooks {
538541
public:
539542
// Reason for both UidFields and Fields are that one is stored as a double*
@@ -571,6 +574,9 @@ class Environment {
571574
inline bool pop_async_id(double async_id);
572575
inline void clear_async_id_stack(); // Used in fatal exceptions.
573576

577+
AsyncHooks(const AsyncHooks&) = delete;
578+
AsyncHooks& operator=(const AsyncHooks&) = delete;
579+
574580
// Used to set the kDefaultTriggerAsyncId in a scope. This is instead of
575581
// passing the trigger_async_id along with other constructor arguments.
576582
class DefaultTriggerAsyncIdScope {
@@ -581,11 +587,13 @@ class Environment {
581587
explicit DefaultTriggerAsyncIdScope(AsyncWrap* async_wrap);
582588
~DefaultTriggerAsyncIdScope();
583589

590+
DefaultTriggerAsyncIdScope(const DefaultTriggerAsyncIdScope&) = delete;
591+
DefaultTriggerAsyncIdScope& operator=(const DefaultTriggerAsyncIdScope&) =
592+
delete;
593+
584594
private:
585595
AsyncHooks* async_hooks_;
586596
double old_default_trigger_async_id_;
587-
588-
DISALLOW_COPY_AND_ASSIGN(DefaultTriggerAsyncIdScope);
589597
};
590598

591599

@@ -603,20 +611,18 @@ class Environment {
603611
AliasedBuffer<double, v8::Float64Array> async_id_fields_;
604612

605613
void grow_async_ids_stack();
606-
607-
DISALLOW_COPY_AND_ASSIGN(AsyncHooks);
608614
};
609615

610616
class AsyncCallbackScope {
611617
public:
612618
AsyncCallbackScope() = delete;
613619
explicit AsyncCallbackScope(Environment* env);
614620
~AsyncCallbackScope();
621+
AsyncCallbackScope(const AsyncCallbackScope&) = delete;
622+
AsyncCallbackScope& operator=(const AsyncCallbackScope&) = delete;
615623

616624
private:
617625
Environment* env_;
618-
619-
DISALLOW_COPY_AND_ASSIGN(AsyncCallbackScope);
620626
};
621627

622628
inline size_t makecallback_depth() const;
@@ -634,6 +640,9 @@ class Environment {
634640
inline void ref_count_inc(uint32_t increment);
635641
inline void ref_count_dec(uint32_t decrement);
636642

643+
ImmediateInfo(const ImmediateInfo&) = delete;
644+
ImmediateInfo& operator=(const ImmediateInfo&) = delete;
645+
637646
private:
638647
friend class Environment; // So we can call the constructor.
639648
inline explicit ImmediateInfo(v8::Isolate* isolate);
@@ -646,8 +655,6 @@ class Environment {
646655
};
647656

648657
AliasedBuffer<uint32_t, v8::Uint32Array> fields_;
649-
650-
DISALLOW_COPY_AND_ASSIGN(ImmediateInfo);
651658
};
652659

653660
class TickInfo {
@@ -656,6 +663,9 @@ class Environment {
656663
inline bool has_tick_scheduled() const;
657664
inline bool has_rejection_to_warn() const;
658665

666+
TickInfo(const TickInfo&) = delete;
667+
TickInfo& operator=(const TickInfo&) = delete;
668+
659669
private:
660670
friend class Environment; // So we can call the constructor.
661671
inline explicit TickInfo(v8::Isolate* isolate);
@@ -667,8 +677,6 @@ class Environment {
667677
};
668678

669679
AliasedBuffer<uint8_t, v8::Uint8Array> fields_;
670-
671-
DISALLOW_COPY_AND_ASSIGN(TickInfo);
672680
};
673681

674682
enum Flags {
@@ -1211,8 +1219,6 @@ class Environment {
12111219
#define V(PropertyName, TypeName) Persistent<TypeName> PropertyName ## _;
12121220
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
12131221
#undef V
1214-
1215-
DISALLOW_COPY_AND_ASSIGN(Environment);
12161222
};
12171223

12181224
} // namespace node

src/inspector_socket.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ class InspectorSocket {
4141
void SwitchProtocol(ProtocolHandler* handler);
4242
std::string GetHost();
4343

44+
InspectorSocket(const InspectorSocket&) = delete;
45+
InspectorSocket& operator=(const InspectorSocket&) = delete;
46+
4447
private:
4548
static void Shutdown(ProtocolHandler*);
4649
InspectorSocket() = default;
4750

4851
DeleteFnPtr<ProtocolHandler, Shutdown> protocol_handler_;
49-
50-
DISALLOW_COPY_AND_ASSIGN(InspectorSocket);
5152
};
5253

5354

src/node_binding.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class DLib {
8080
#endif
8181
bool has_entry_in_global_handle_map_ = false;
8282

83-
private:
84-
DISALLOW_COPY_AND_ASSIGN(DLib);
83+
DLib(const DLib&) = delete;
84+
DLib& operator=(const DLib&) = delete;
8585
};
8686

8787
// Call _register<module_name> functions for all of

src/node_buffer.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class CallbackInfo {
8787
FreeCallback callback,
8888
char* data,
8989
void* hint = nullptr);
90+
91+
CallbackInfo(const CallbackInfo&) = delete;
92+
CallbackInfo& operator=(const CallbackInfo&) = delete;
93+
9094
private:
9195
static void WeakCallback(const WeakCallbackInfo<CallbackInfo>&);
9296
inline void WeakCallback(Isolate* isolate);
@@ -99,7 +103,6 @@ class CallbackInfo {
99103
FreeCallback const callback_;
100104
char* const data_;
101105
void* const hint_;
102-
DISALLOW_COPY_AND_ASSIGN(CallbackInfo);
103106
};
104107

105108

src/node_crypto.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ class ByteSource {
367367

368368
static ByteSource FromSymmetricKeyObject(v8::Local<v8::Value> handle);
369369

370+
ByteSource(const ByteSource&) = delete;
371+
ByteSource& operator=(const ByteSource&) = delete;
372+
370373
private:
371374
const char* data_ = nullptr;
372375
char* allocated_data_ = nullptr;
@@ -376,8 +379,6 @@ class ByteSource {
376379

377380
static ByteSource Allocated(char* data, size_t size);
378381
static ByteSource Foreign(const char* data, size_t size);
379-
380-
DISALLOW_COPY_AND_ASSIGN(ByteSource);
381382
};
382383

383384
enum PKEncodingType {

src/node_file.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,8 @@ class FSReqWrapSync {
682682
~FSReqWrapSync() { uv_fs_req_cleanup(&req); }
683683
uv_fs_t req;
684684

685-
private:
686-
DISALLOW_COPY_AND_ASSIGN(FSReqWrapSync);
685+
FSReqWrapSync(const FSReqWrapSync&) = delete;
686+
FSReqWrapSync& operator=(const FSReqWrapSync&) = delete;
687687
};
688688

689689
// Returns nullptr if the operation fails from the start.

src/node_file.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class FSReqBase : public ReqWrap<uv_fs_t> {
114114
return static_cast<FSReqBase*>(ReqWrap::from_req(req));
115115
}
116116

117+
FSReqBase(const FSReqBase&) = delete;
118+
FSReqBase& operator=(const FSReqBase&) = delete;
119+
117120
private:
118121
enum encoding encoding_ = UTF8;
119122
bool has_data_ = false;
@@ -123,8 +126,6 @@ class FSReqBase : public ReqWrap<uv_fs_t> {
123126
// Typically, the content of buffer_ is something like a file name, so
124127
// something around 64 bytes should be enough.
125128
FSReqBuffer buffer_;
126-
127-
DISALLOW_COPY_AND_ASSIGN(FSReqBase);
128129
};
129130

130131
class FSReqCallback : public FSReqBase {
@@ -144,8 +145,8 @@ class FSReqCallback : public FSReqBase {
144145
SET_MEMORY_INFO_NAME(FSReqCallback)
145146
SET_SELF_SIZE(FSReqCallback)
146147

147-
private:
148-
DISALLOW_COPY_AND_ASSIGN(FSReqCallback);
148+
FSReqCallback(const FSReqCallback&) = delete;
149+
FSReqCallback& operator=(const FSReqCallback&) = delete;
149150
};
150151

151152
// Wordaround a GCC4.9 bug that C++14 N3652 was not implemented

src/node_mutex.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class MutexBase {
2323
inline void Lock();
2424
inline void Unlock();
2525

26+
MutexBase(const MutexBase&) = delete;
27+
MutexBase& operator=(const MutexBase&) = delete;
28+
2629
class ScopedLock;
2730
class ScopedUnlock;
2831

@@ -32,28 +35,31 @@ class MutexBase {
3235
inline explicit ScopedLock(const ScopedUnlock& scoped_unlock);
3336
inline ~ScopedLock();
3437

38+
ScopedLock(const ScopedLock&) = delete;
39+
ScopedLock& operator=(const ScopedLock&) = delete;
40+
3541
private:
3642
template <typename> friend class ConditionVariableBase;
3743
friend class ScopedUnlock;
3844
const MutexBase& mutex_;
39-
DISALLOW_COPY_AND_ASSIGN(ScopedLock);
4045
};
4146

4247
class ScopedUnlock {
4348
public:
4449
inline explicit ScopedUnlock(const ScopedLock& scoped_lock);
4550
inline ~ScopedUnlock();
4651

52+
ScopedUnlock(const ScopedUnlock&) = delete;
53+
ScopedUnlock& operator=(const ScopedUnlock&) = delete;
54+
4755
private:
4856
friend class ScopedLock;
4957
const MutexBase& mutex_;
50-
DISALLOW_COPY_AND_ASSIGN(ScopedUnlock);
5158
};
5259

5360
private:
5461
template <typename> friend class ConditionVariableBase;
5562
mutable typename Traits::MutexT mutex_;
56-
DISALLOW_COPY_AND_ASSIGN(MutexBase);
5763
};
5864

5965
template <typename Traits>
@@ -67,9 +73,11 @@ class ConditionVariableBase {
6773
inline void Signal(const ScopedLock&);
6874
inline void Wait(const ScopedLock& scoped_lock);
6975

76+
ConditionVariableBase(const ConditionVariableBase&) = delete;
77+
ConditionVariableBase& operator=(const ConditionVariableBase&) = delete;
78+
7079
private:
7180
typename Traits::CondT cond_;
72-
DISALLOW_COPY_AND_ASSIGN(ConditionVariableBase);
7381
};
7482

7583
struct LibuvMutexTraits {

src/node_union_bytes.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ class NonOwningExternalOneByteResource
2424
}
2525
size_t length() const override { return length_; }
2626

27+
NonOwningExternalOneByteResource(const NonOwningExternalOneByteResource&) =
28+
delete;
29+
NonOwningExternalOneByteResource& operator=(
30+
const NonOwningExternalOneByteResource&) = delete;
31+
2732
private:
2833
const uint8_t* data_;
2934
size_t length_;
30-
DISALLOW_COPY_AND_ASSIGN(NonOwningExternalOneByteResource);
3135
};
3236

3337
class NonOwningExternalTwoByteResource
@@ -40,10 +44,14 @@ class NonOwningExternalTwoByteResource
4044
const uint16_t* data() const override { return data_; }
4145
size_t length() const override { return length_; }
4246

47+
NonOwningExternalTwoByteResource(const NonOwningExternalTwoByteResource&) =
48+
delete;
49+
NonOwningExternalTwoByteResource& operator=(
50+
const NonOwningExternalTwoByteResource&) = delete;
51+
4352
private:
4453
const uint16_t* data_;
4554
size_t length_;
46-
DISALLOW_COPY_AND_ASSIGN(NonOwningExternalTwoByteResource);
4755
};
4856

4957
// Similar to a v8::String, but it's independent from Isolates

src/node_zlib.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ class ZlibContext : public MemoryRetainer {
145145
tracker->TrackField("dictionary", dictionary_);
146146
}
147147

148+
ZlibContext(const ZlibContext&) = delete;
149+
ZlibContext& operator=(const ZlibContext&) = delete;
150+
148151
private:
149152
CompressionError ErrorForMessage(const char* message) const;
150153
CompressionError SetDictionary();
@@ -160,8 +163,6 @@ class ZlibContext : public MemoryRetainer {
160163
std::vector<unsigned char> dictionary_;
161164

162165
z_stream strm_;
163-
164-
DISALLOW_COPY_AND_ASSIGN(ZlibContext);
165166
};
166167

167168
// Brotli has different data types for compression and decompression streams,
@@ -175,6 +176,9 @@ class BrotliContext : public MemoryRetainer {
175176
void GetAfterWriteOffsets(uint32_t* avail_in, uint32_t* avail_out) const;
176177
inline void SetMode(node_zlib_mode mode) { mode_ = mode; }
177178

179+
BrotliContext(const BrotliContext&) = delete;
180+
BrotliContext& operator=(const BrotliContext&) = delete;
181+
178182
protected:
179183
node_zlib_mode mode_ = NONE;
180184
uint8_t* next_in_ = nullptr;
@@ -188,9 +192,6 @@ class BrotliContext : public MemoryRetainer {
188192
brotli_alloc_func alloc_ = nullptr;
189193
brotli_free_func free_ = nullptr;
190194
void* alloc_opaque_ = nullptr;
191-
192-
private:
193-
DISALLOW_COPY_AND_ASSIGN(BrotliContext);
194195
};
195196

196197
class BrotliEncoderContext final : public BrotliContext {

src/tracing/trace_event_common.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@
150150
// void AppendAsTraceFormat(std::string* out) const override {
151151
// out->append("{\"foo\":1}");
152152
// }
153+
// MyData(const MyData&) = delete;
154+
// MyData& operator=(const MyData&) = delete;
155+
//
153156
// private:
154157
// ~MyData() override {}
155-
// DISALLOW_COPY_AND_ASSIGN(MyData);
156158
// };
157159
//
158160
// TRACE_EVENT1("foo", "bar", "data",

src/tracing/traced_value.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class TracedValue : public v8::ConvertableToTraceFormat {
5050
// ConvertableToTraceFormat implementation.
5151
void AppendAsTraceFormat(std::string* out) const override;
5252

53+
TracedValue(const TracedValue&) = delete;
54+
TracedValue& operator=(const TracedValue&) = delete;
55+
5356
private:
5457
explicit TracedValue(bool root_is_array = false);
5558

@@ -59,8 +62,6 @@ class TracedValue : public v8::ConvertableToTraceFormat {
5962
std::string data_;
6063
bool first_item_;
6164
bool root_is_array_;
62-
63-
DISALLOW_COPY_AND_ASSIGN(TracedValue);
6465
};
6566

6667
} // namespace tracing

0 commit comments

Comments
 (0)