| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -378,6 +378,9 @@ are part of the channel. | |||
| 378 | 378 | <!-- YAML | |
| 379 | 379 | added: v10.5.0 | |
| 380 | 380 | changes: | |
| 381 | + - version: REPLACEME | ||
| 382 | + pr-url: https://github.com/nodejs/node/pull/37917 | ||
| 383 | + description: Add 'BlockList' to the list of cloneable types. | ||
| 381 | 384 | - version: v14.5.0 | |
| 382 | 385 | pr-url: https://github.com/nodejs/node/pull/33360 | |
| 383 | 386 | description: Added `KeyObject` to the list of cloneable types. | |
@@ -401,8 +404,11 @@ In particular, the significant differences to `JSON` are: | |||
| 401 | 404 | * `value` may contain typed arrays, both using `ArrayBuffer`s | |
| 402 | 405 | and `SharedArrayBuffer`s. | |
| 403 | 406 | * `value` may contain [`WebAssembly.Module`][] instances. | |
| 404 | - * `value` may not contain native (C++-backed) objects other than `MessagePort`s, | ||
| 405 | - [`FileHandle`][]s, and [`KeyObject`][]s. | ||
| 407 | + * `value` may not contain native (C++-backed) objects other than: | ||
| 408 | + * {FileHandle}s, | ||
| 409 | + * {KeyObject}s, | ||
| 410 | + * {MessagePort}s, | ||
| 411 | + * {net.BlockList}s, | ||
| 406 | 412 | ||
| 407 | 413 | ```js | |
| 408 | 414 | const { MessageChannel } = require('worker_threads'); | |
@@ -1032,7 +1038,6 @@ thread spawned will spawn another until the application crashes. | |||
| 1032 | 1038 | [`ERR_WORKER_NOT_RUNNING`]: errors.md#ERR_WORKER_NOT_RUNNING | |
| 1033 | 1039 | [`EventTarget`]: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget | |
| 1034 | 1040 | [`FileHandle`]: fs.md#fs_class_filehandle | |
| 1035 | - [`KeyObject`]: crypto.md#crypto_class_keyobject | ||
| 1036 | 1041 | [`MessagePort`]: #worker_threads_class_messageport | |
| 1037 | 1042 | [`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer | |
| 1038 | 1043 | [`Uint8Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | 4 | Boolean, | |
| 5 | + ObjectSetPrototypeOf, | ||
| 5 | 6 | Symbol | |
| 6 | 7 | } = primordials; | |
| 7 | 8 | ||
@@ -14,6 +15,13 @@ const { | |||
| 14 | 15 | const { | |
| 15 | 16 | customInspectSymbol: kInspect, | |
| 16 | 17 | } = require('internal/util'); | |
| 18 | + | ||
| 19 | + const { | ||
| 20 | + JSTransferable, | ||
| 21 | + kClone, | ||
| 22 | + kDeserialize, | ||
| 23 | + } = require('internal/worker/js_transferable'); | ||
| 24 | + | ||
| 17 | 25 | const { inspect } = require('internal/util/inspect'); | |
| 18 | 26 | ||
| 19 | 27 | const kHandle = Symbol('kHandle'); | |
@@ -26,14 +34,10 @@ const { | |||
| 26 | 34 | ||
| 27 | 35 | const { validateInt32 } = require('internal/validators'); | |
| 28 | 36 | ||
| 29 | - 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; | ||
| 37 | + class BlockList extends JSTransferable { | ||
| 38 | + constructor() { | ||
| 39 | + super(); | ||
| 40 | + this[kHandle] = new BlockListHandle(); | ||
| 37 | 41 | this[kHandle][owner_symbol] = this; | |
| 38 | 42 | } | |
| 39 | 43 | ||
@@ -116,6 +120,34 @@ class BlockList { | |||
| 116 | 120 | get rules() { | |
| 117 | 121 | return this[kHandle].getRules(); | |
| 118 | 122 | } | |
| 123 | + | ||
| 124 | + [kClone]() { | ||
| 125 | + const handle = this[kHandle]; | ||
| 126 | + return { | ||
| 127 | + data: { handle }, | ||
| 128 | + deserializeInfo: 'internal/blocklist:InternalBlockList', | ||
| 129 | + }; | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + [kDeserialize]({ handle }) { | ||
| 133 | + this[kHandle] = handle; | ||
| 134 | + this[kHandle][owner_symbol] = this; | ||
| 135 | + } | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + class InternalBlockList extends JSTransferable { | ||
| 139 | + constructor(handle) { | ||
| 140 | + super(); | ||
| 141 | + this[kHandle] = handle; | ||
| 142 | + if (handle !== undefined) | ||
| 143 | + handle[owner_symbol] = this; | ||
| 144 | + } | ||
| 119 | 145 | } | |
| 120 | 146 | ||
| 121 | - module.exports = BlockList; | ||
| 147 | + InternalBlockList.prototype.constructor = BlockList.prototype.constructor; | ||
| 148 | + ObjectSetPrototypeOf(InternalBlockList.prototype, BlockList.prototype); | ||
| 149 | + | ||
| 150 | + module.exports = { | ||
| 151 | + BlockList, | ||
| 152 | + InternalBlockList, | ||
| 153 | + }; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1757,8 +1757,7 @@ module.exports = { | |||
| 1757 | 1757 | _normalizeArgs: normalizeArgs, | |
| 1758 | 1758 | _setSimultaneousAccepts, | |
| 1759 | 1759 | get BlockList() { | |
| 1760 | - if (BlockList === undefined) | ||
| 1761 | - BlockList = require('internal/blocklist'); | ||
| 1760 | + BlockList = BlockList ?? require('internal/blocklist').BlockList; | ||
| 1762 | 1761 | return BlockList; | |
| 1763 | 1762 | }, | |
| 1764 | 1763 | connect, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1110,15 +1110,18 @@ inline void Environment::SetInstanceMethod(v8::Local<v8::FunctionTemplate> that, | |||
| 1110 | 1110 | inline void Environment::SetConstructorFunction( | |
| 1111 | 1111 | v8::Local<v8::Object> that, | |
| 1112 | 1112 | const char* name, | |
| 1113 | - v8::Local<v8::FunctionTemplate> tmpl) { | ||
| 1114 | - SetConstructorFunction(that, OneByteString(isolate(), name), tmpl); | ||
| 1113 | + v8::Local<v8::FunctionTemplate> tmpl, | ||
| 1114 | + SetConstructorFunctionFlag flag) { | ||
| 1115 | + SetConstructorFunction(that, OneByteString(isolate(), name), tmpl, flag); | ||
| 1115 | 1116 | } | |
| 1116 | 1117 | ||
| 1117 | 1118 | inline void Environment::SetConstructorFunction( | |
| 1118 | 1119 | v8::Local<v8::Object> that, | |
| 1119 | 1120 | v8::Local<v8::String> name, | |
| 1120 | - v8::Local<v8::FunctionTemplate> tmpl) { | ||
| 1121 | - tmpl->SetClassName(name); | ||
| 1121 | + v8::Local<v8::FunctionTemplate> tmpl, | ||
| 1122 | + SetConstructorFunctionFlag flag) { | ||
| 1123 | + if (LIKELY(flag == SetConstructorFunctionFlag::SET_CLASS_NAME)) | ||
| 1124 | + tmpl->SetClassName(name); | ||
| 1122 | 1125 | that->Set( | |
| 1123 | 1126 | context(), | |
| 1124 | 1127 | name, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -411,7 +411,7 @@ constexpr size_t kFsStatsBufferLength = | |||
| 411 | 411 | V(async_wrap_object_ctor_template, v8::FunctionTemplate) \ | |
| 412 | 412 | V(base_object_ctor_template, v8::FunctionTemplate) \ | |
| 413 | 413 | V(binding_data_ctor_template, v8::FunctionTemplate) \ | |
| 414 | - V(blocklist_instance_template, v8::ObjectTemplate) \ | ||
| 414 | + V(blocklist_constructor_template, v8::FunctionTemplate) \ | ||
| 415 | 415 | V(compiled_fn_entry_template, v8::ObjectTemplate) \ | |
| 416 | 416 | V(dir_instance_template, v8::ObjectTemplate) \ | |
| 417 | 417 | V(fd_constructor_template, v8::ObjectTemplate) \ | |
@@ -1111,13 +1111,22 @@ class Environment : public MemoryRetainer { | |||
| 1111 | 1111 | const char* name, | |
| 1112 | 1112 | v8::FunctionCallback callback); | |
| 1113 | 1113 | ||
| 1114 | + enum class SetConstructorFunctionFlag { | ||
| 1115 | + NONE, | ||
| 1116 | + SET_CLASS_NAME, | ||
| 1117 | + }; | ||
| 1118 | + | ||
| 1114 | 1119 | inline void SetConstructorFunction(v8::Local<v8::Object> that, | |
| 1115 | 1120 | const char* name, | |
| 1116 | - v8::Local<v8::FunctionTemplate> tmpl); | ||
| 1121 | + v8::Local<v8::FunctionTemplate> tmpl, | ||
| 1122 | + SetConstructorFunctionFlag flag = | ||
| 1123 | + SetConstructorFunctionFlag::SET_CLASS_NAME); | ||
| 1117 | 1124 | ||
| 1118 | 1125 | inline void SetConstructorFunction(v8::Local<v8::Object> that, | |
| 1119 | 1126 | v8::Local<v8::String> name, | |
| 1120 | - v8::Local<v8::FunctionTemplate> tmpl); | ||
| 1127 | + v8::Local<v8::FunctionTemplate> tmpl, | ||
| 1128 | + SetConstructorFunctionFlag flag = | ||
| 1129 | + SetConstructorFunctionFlag::SET_CLASS_NAME); | ||
| 1121 | 1130 | ||
| 1122 | 1131 | void AtExit(void (*cb)(void* arg), void* arg); | |
| 1123 | 1132 | void RunAtExitCallbacks(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments