| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 54dd3df commit a80c989
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -525,7 +525,7 @@ function asyncResetHandle(socket) { | |||
| 525 | 525 | const handle = socket._handle; | |
| 526 | 526 | if (handle && typeof handle.asyncReset === 'function') { | |
| 527 | 527 | // Assign the handle a new asyncId and run any destroy()/init() hooks. | |
| 528 | - handle.asyncReset(new ReusedHandle(handle.getProviderType(), handle)); | ||
| 528 | + handle.asyncReset(new ReusedHandle(handle.getProviderType(), socket)); | ||
| 529 | 529 | socket[async_id_symbol] = handle.getAsyncId(); | |
| 530 | 530 | } | |
| 531 | 531 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,7 +81,7 @@ const active_hooks = { | |||
| 81 | 81 | ||
| 82 | 82 | const { registerDestroyHook } = async_wrap; | |
| 83 | 83 | const { enqueueMicrotask } = internalBinding('task_queue'); | |
| 84 | - const { resource_symbol, owner_symbol } = internalBinding('symbols'); | ||
| 84 | + const { owner_symbol } = internalBinding('symbols'); | ||
| 85 | 85 | ||
| 86 | 86 | // Each constant tracks how many callbacks there are for any given step of | |
| 87 | 87 | // async execution. These are tracked so if the user didn't include callbacks | |
@@ -178,11 +178,13 @@ function fatalError(e) { | |||
| 178 | 178 | ||
| 179 | 179 | function lookupPublicResource(resource) { | |
| 180 | 180 | if (typeof resource !== 'object' || resource === null) return resource; | |
| 181 | - // TODO(addaleax): Merge this with owner_symbol and use it across all | ||
| 182 | - // AsyncWrap instances. | ||
| 183 | - const publicResource = resource[resource_symbol]; | ||
| 184 | - if (publicResource !== undefined) | ||
| 181 | + | ||
| 182 | + const publicResource = resource[owner_symbol]; | ||
| 183 | + | ||
| 184 | + if (publicResource != null) { | ||
| 185 | 185 | return publicResource; | |
| 186 | + } | ||
| 187 | + | ||
| 186 | 188 | return resource; | |
| 187 | 189 | } | |
| 188 | 190 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,15 +22,55 @@ const kCurrentWriteRequest = Symbol('kCurrentWriteRequest'); | |||
| 22 | 22 | const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest'); | |
| 23 | 23 | const kPendingShutdownRequest = Symbol('kPendingShutdownRequest'); | |
| 24 | 24 | ||
| 25 | - function isClosing() { return this[owner_symbol].isClosing(); } | ||
| 25 | + function isClosing() { | ||
| 26 | + let socket = this[owner_symbol]; | ||
| 26 | 27 | ||
| 27 | - function onreadstart() { return this[owner_symbol].readStart(); } | ||
| 28 | + if (socket.constructor.name === 'ReusedHandle') { | ||
| 29 | + socket = socket.handle; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + return socket.isClosing(); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + function onreadstart() { | ||
| 36 | + let socket = this[owner_symbol]; | ||
| 37 | + | ||
| 38 | + if (socket.constructor.name === 'ReusedHandle') { | ||
| 39 | + socket = socket.handle; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + return socket.readStart(); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + function onreadstop() { | ||
| 46 | + let socket = this[owner_symbol]; | ||
| 47 | + | ||
| 48 | + if (socket.constructor.name === 'ReusedHandle') { | ||
| 49 | + socket = socket.handle; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + return socket.readStop(); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + function onshutdown(req) { | ||
| 56 | + let socket = this[owner_symbol]; | ||
| 57 | + | ||
| 58 | + if (socket.constructor.name === 'ReusedHandle') { | ||
| 59 | + socket = socket.handle; | ||
| 60 | + } | ||
| 28 | 61 | ||
| 29 | - function onreadstop() { return this[owner_symbol].readStop(); } | ||
| 62 | + return socket.doShutdown(req); | ||
| 63 | + } | ||
| 30 | 64 | ||
| 31 | - function onshutdown(req) { return this[owner_symbol].doShutdown(req); } | ||
| 65 | + function onwrite(req, bufs) { | ||
| 66 | + let socket = this[owner_symbol]; | ||
| 32 | 67 | ||
| 33 | - function onwrite(req, bufs) { return this[owner_symbol].doWrite(req, bufs); } | ||
| 68 | + if (socket.constructor.name === 'ReusedHandle') { | ||
| 69 | + socket = socket.handle; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + return socket.doWrite(req, bufs); | ||
| 73 | + } | ||
| 34 | 74 | ||
| 35 | 75 | /* This class serves as a wrapper for when the C++ side of Node wants access | |
| 36 | 76 | * to a standard JS stream. For example, TLS or HTTP do not operate on network | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,7 +80,11 @@ function handleWriteReq(req, data, encoding) { | |||
| 80 | 80 | function onWriteComplete(status) { | |
| 81 | 81 | debug('onWriteComplete', status, this.error); | |
| 82 | 82 | ||
| 83 | - const stream = this.handle[owner_symbol]; | ||
| 83 | + let stream = this.handle[owner_symbol]; | ||
| 84 | + | ||
| 85 | + if (stream.constructor.name === 'ReusedHandle') { | ||
| 86 | + stream = stream.handle; | ||
| 87 | + } | ||
| 84 | 88 | ||
| 85 | 89 | if (stream.destroyed) { | |
| 86 | 90 | if (typeof this.callback === 'function') | |
@@ -168,7 +172,12 @@ function onStreamRead(arrayBuffer) { | |||
| 168 | 172 | const nread = streamBaseState[kReadBytesOrError]; | |
| 169 | 173 | ||
| 170 | 174 | const handle = this; | |
| 171 | - const stream = this[owner_symbol]; | ||
| 175 | + | ||
| 176 | + let stream = this[owner_symbol]; | ||
| 177 | + | ||
| 178 | + if (stream.constructor.name === 'ReusedHandle') { | ||
| 179 | + stream = stream.handle; | ||
| 180 | + } | ||
| 172 | 181 | ||
| 173 | 182 | stream[kUpdateTimer](); | |
| 174 | 183 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1102,7 +1102,11 @@ Socket.prototype.unref = function() { | |||
| 1102 | 1102 | ||
| 1103 | 1103 | ||
| 1104 | 1104 | function afterConnect(status, handle, req, readable, writable) { | |
| 1105 | - const self = handle[owner_symbol]; | ||
| 1105 | + let self = handle[owner_symbol]; | ||
| 1106 | + | ||
| 1107 | + if (self.constructor.name === 'ReusedHandle') { | ||
| 1108 | + self = self.handle; | ||
| 1109 | + } | ||
| 1106 | 1110 | ||
| 1107 | 1111 | // Callback may come after call to destroy | |
| 1108 | 1112 | if (self.destroyed) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -313,7 +313,7 @@ void AsyncWrap::EmitDestroy(bool from_gc) { | |||
| 313 | 313 | ||
| 314 | 314 | if (!persistent().IsEmpty() && !from_gc) { | |
| 315 | 315 | HandleScope handle_scope(env()->isolate()); | |
| 316 | - USE(object()->Set(env()->context(), env()->resource_symbol(), object())); | ||
| 316 | + USE(object()->Set(env()->context(), env()->owner_symbol(), object())); | ||
| 317 | 317 | } | |
| 318 | 318 | } | |
| 319 | 319 | ||
@@ -586,7 +586,7 @@ void AsyncWrap::AsyncReset(Local<Object> resource, double execution_async_id, | |||
| 586 | 586 | Local<Object> obj = object(); | |
| 587 | 587 | CHECK(!obj.IsEmpty()); | |
| 588 | 588 | if (resource != obj) { | |
| 589 | - USE(obj->Set(env()->context(), env()->resource_symbol(), resource)); | ||
| 589 | + USE(obj->Set(env()->context(), env()->owner_symbol(), resource)); | ||
| 590 | 590 | } | |
| 591 | 591 | } | |
| 592 | 592 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -170,7 +170,6 @@ constexpr size_t kFsStatsBufferLength = | |||
| 170 | 170 | V(oninit_symbol, "oninit") \ | |
| 171 | 171 | V(owner_symbol, "owner_symbol") \ | |
| 172 | 172 | V(onpskexchange_symbol, "onpskexchange") \ | |
| 173 | - V(resource_symbol, "resource_symbol") \ | ||
| 174 | 173 | V(trigger_async_id_symbol, "trigger_async_id_symbol") \ | |
| 175 | 174 | ||
| 176 | 175 | // Strings are per-isolate primitives but Environment proxies them | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,6 +87,4 @@ function onExit() { | |||
| 87 | 87 | // Verify reuse handle has been wrapped | |
| 88 | 88 | assert.strictEqual(first.type, second.type); | |
| 89 | 89 | assert.ok(first.handle !== second.handle, 'Resource reused'); | |
| 90 | - assert.ok(first.handle === second.handle.handle, | ||
| 91 | - 'Resource not wrapped correctly'); | ||
| 92 | 90 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,6 +105,4 @@ function onExit() { | |||
| 105 | 105 | // Verify reuse handle has been wrapped | |
| 106 | 106 | assert.strictEqual(first.type, second.type); | |
| 107 | 107 | assert.ok(first.handle !== second.handle, 'Resource reused'); | |
| 108 | - assert.ok(first.handle === second.handle.handle, | ||
| 109 | - 'Resource not wrapped correctly'); | ||
| 110 | 108 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments