net: make net.BlockList cloneable · nodejs/node@a4169ce

@@ -2,6 +2,7 @@

2233

const {

44

Boolean,

5+

ObjectSetPrototypeOf,

56

Symbol

67

} = primordials;

78

@@ -14,26 +15,28 @@ const {

1415

const {

1516

customInspectSymbol: kInspect,

1617

} = require('internal/util');

18+19+

const {

20+

JSTransferable,

21+

kClone,

22+

kDeserialize,

23+

} = require('internal/worker/js_transferable');

24+1725

const { inspect } = require('internal/util/inspect');

18261927

const kHandle = Symbol('kHandle');

2028

const { owner_symbol } = internalBinding('symbols');

21292230

const {

23-

ERR_INVALID_ARG_TYPE,

2431

ERR_INVALID_ARG_VALUE,

2532

} = require('internal/errors').codes;

26332734

const { validateInt32, validateString } = require('internal/validators');

283529-

class BlockList {

30-

constructor(handle = new BlockListHandle()) {

31-

// The handle argument is an intentionally undocumented

32-

// internal API. User code will not be able to create

33-

// a BlockListHandle object directly.

34-

if (!(handle instanceof BlockListHandle))

35-

throw new ERR_INVALID_ARG_TYPE('handle', 'BlockListHandle', handle);

36-

this[kHandle] = handle;

36+

class BlockList extends JSTransferable {

37+

constructor() {

38+

super();

39+

this[kHandle] = new BlockListHandle();

3740

this[kHandle][owner_symbol] = this;

3841

}

3942

@@ -107,6 +110,34 @@ class BlockList {

107110

get rules() {

108111

return this[kHandle].getRules();

109112

}

113+114+

[kClone]() {

115+

const handle = this[kHandle];

116+

return {

117+

data: { handle },

118+

deserializeInfo: 'internal/blocklist:InternalBlockList',

119+

};

120+

}

121+122+

[kDeserialize]({ handle }) {

123+

this[kHandle] = handle;

124+

this[kHandle][owner_symbol] = this;

125+

}

126+

}

127+128+

class InternalBlockList extends JSTransferable {

129+

constructor(handle) {

130+

super();

131+

this[kHandle] = handle;

132+

if (handle !== undefined)

133+

handle[owner_symbol] = this;

134+

}

110135

}

111136112-

module.exports = BlockList;

137+

InternalBlockList.prototype.constructor = BlockList.prototype.constructor;

138+

ObjectSetPrototypeOf(InternalBlockList.prototype, BlockList.prototype);

139+140+

module.exports = {

141+

BlockList,

142+

InternalBlockList,

143+

};