Skip to content

Commit 51b8a89

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

14 files changed

+82
-48
lines changed

src/env.h

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

424424
std::unordered_map<nghttp2_rcbuf*, v8::Eternal<v8::String>> http2_static_strs;
425425
inline v8::Isolate* isolate() const;
426+
IsolateData(const IsolateData&) = delete;
427+
IsolateData& operator=(const IsolateData&) = delete;
426428

427429
private:
428430
#define VP(PropertyName, StringValue) V(v8::Private, PropertyName)
@@ -445,8 +447,6 @@ class IsolateData {
445447
const bool uses_node_allocator_;
446448
MultiIsolatePlatform* platform_;
447449
std::shared_ptr<PerIsolateOptions> options_;
448-
449-
DISALLOW_COPY_AND_ASSIGN(IsolateData);
450450
};
451451

452452
struct ContextInfo {
@@ -531,6 +531,9 @@ class AsyncRequest : public MemoryRetainer {
531531

532532
class Environment {
533533
public:
534+
Environment(const Environment&) = delete;
535+
Environment& operator=(const Environment&) = delete;
536+
534537
class AsyncHooks {
535538
public:
536539
// Reason for both UidFields and Fields are that one is stored as a double*
@@ -568,6 +571,9 @@ class Environment {
568571
inline bool pop_async_id(double async_id);
569572
inline void clear_async_id_stack(); // Used in fatal exceptions.
570573

574+
AsyncHooks(const AsyncHooks&) = delete;
575+
AsyncHooks& operator=(const AsyncHooks&) = delete;
576+
571577
// Used to set the kDefaultTriggerAsyncId in a scope. This is instead of
572578
// passing the trigger_async_id along with other constructor arguments.
573579
class DefaultTriggerAsyncIdScope {
@@ -578,11 +584,13 @@ class Environment {
578584
explicit DefaultTriggerAsyncIdScope(AsyncWrap* async_wrap);
579585
~DefaultTriggerAsyncIdScope();
580586

587+
DefaultTriggerAsyncIdScope(const DefaultTriggerAsyncIdScope&) = delete;
588+
DefaultTriggerAsyncIdScope& operator=(const DefaultTriggerAsyncIdScope&) =
589+
delete;
590+
581591
private:
582592
AsyncHooks* async_hooks_;
583593
double old_default_trigger_async_id_;
584-
585-
DISALLOW_COPY_AND_ASSIGN(DefaultTriggerAsyncIdScope);
586594
};
587595

588596

@@ -600,20 +608,18 @@ class Environment {
600608
AliasedBuffer<double, v8::Float64Array> async_id_fields_;
601609

602610
void grow_async_ids_stack();
603-
604-
DISALLOW_COPY_AND_ASSIGN(AsyncHooks);
605611
};
606612

607613
class AsyncCallbackScope {
608614
public:
609615
AsyncCallbackScope() = delete;
610616
explicit AsyncCallbackScope(Environment* env);
611617
~AsyncCallbackScope();
618+
AsyncCallbackScope(const AsyncCallbackScope&) = delete;
619+
AsyncCallbackScope& operator=(const AsyncCallbackScope&) = delete;
612620

613621
private:
614622
Environment* env_;
615-
616-
DISALLOW_COPY_AND_ASSIGN(AsyncCallbackScope);
617623
};
618624

619625
inline size_t makecallback_depth() const;
@@ -631,6 +637,9 @@ class Environment {
631637
inline void ref_count_inc(uint32_t increment);
632638
inline void ref_count_dec(uint32_t decrement);
633639

640+
ImmediateInfo(const ImmediateInfo&) = delete;
641+
ImmediateInfo& operator=(const ImmediateInfo&) = delete;
642+
634643
private:
635644
friend class Environment; // So we can call the constructor.
636645
inline explicit ImmediateInfo(v8::Isolate* isolate);
@@ -643,8 +652,6 @@ class Environment {
643652
};
644653

645654
AliasedBuffer<uint32_t, v8::Uint32Array> fields_;
646-
647-
DISALLOW_COPY_AND_ASSIGN(ImmediateInfo);
648655
};
649656

650657
class TickInfo {
@@ -653,6 +660,9 @@ class Environment {
653660
inline bool has_tick_scheduled() const;
654661
inline bool has_rejection_to_warn() const;
655662

663+
TickInfo(const TickInfo&) = delete;
664+
TickInfo& operator=(const TickInfo&) = delete;
665+
656666
private:
657667
friend class Environment; // So we can call the constructor.
658668
inline explicit TickInfo(v8::Isolate* isolate);
@@ -664,8 +674,6 @@ class Environment {
664674
};
665675

666676
AliasedBuffer<uint8_t, v8::Uint8Array> fields_;
667-
668-
DISALLOW_COPY_AND_ASSIGN(TickInfo);
669677
};
670678

671679
enum Flags {
@@ -1214,8 +1222,6 @@ class Environment {
12141222
#define V(PropertyName, TypeName) Persistent<TypeName> PropertyName ## _;
12151223
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V)
12161224
#undef V
1217-
1218-
DISALLOW_COPY_AND_ASSIGN(Environment);
12191225
};
12201226

12211227
} // 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)