| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b614b17 commit 48157c4
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(), socket)); | ||
| 528 | + handle.asyncReset(new ReusedHandle(handle.getProviderType(), handle)); | ||
| 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 { owner_symbol } = internalBinding('symbols'); | ||
| 84 | + const { resource_symbol, 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 | |
@@ -176,13 +176,11 @@ function fatalError(e) { | |||
| 176 | 176 | ||
| 177 | 177 | function lookupPublicResource(resource) { | |
| 178 | 178 | if (typeof resource !== 'object' || resource === null) return resource; | |
| 179 | - | ||
| 180 | - const publicResource = resource[owner_symbol]; | ||
| 181 | - | ||
| 182 | - if (publicResource != null) { | ||
| 179 | + // TODO(addaleax): Merge this with owner_symbol and use it across all | ||
| 180 | + // AsyncWrap instances. | ||
| 181 | + const publicResource = resource[resource_symbol]; | ||
| 182 | + if (publicResource !== undefined) | ||
| 183 | 183 | return publicResource; | |
| 184 | - } | ||
| 185 | - | ||
| 186 | 184 | return resource; | |
| 187 | 185 | } | |
| 188 | 186 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,55 +22,15 @@ const kCurrentWriteRequest = Symbol('kCurrentWriteRequest'); | |||
| 22 | 22 | const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest'); | |
| 23 | 23 | const kPendingShutdownRequest = Symbol('kPendingShutdownRequest'); | |
| 24 | 24 | ||
| 25 | - function isClosing() { | ||
| 26 | - let socket = this[owner_symbol]; | ||
| 25 | + function isClosing() { return this[owner_symbol].isClosing(); } | ||
| 27 | 26 | ||
| 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 | - } | ||
| 27 | + function onreadstart() { return this[owner_symbol].readStart(); } | ||
| 61 | 28 | ||
| 62 | - return socket.doShutdown(req); | ||
| 63 | - } | ||
| 29 | + function onreadstop() { return this[owner_symbol].readStop(); } | ||
| 64 | 30 | ||
| 65 | - function onwrite(req, bufs) { | ||
| 66 | - let socket = this[owner_symbol]; | ||
| 31 | + function onshutdown(req) { return this[owner_symbol].doShutdown(req); } | ||
| 67 | 32 | ||
| 68 | - if (socket.constructor.name === 'ReusedHandle') { | ||
| 69 | - socket = socket.handle; | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - return socket.doWrite(req, bufs); | ||
| 73 | - } | ||
| 33 | + function onwrite(req, bufs) { return this[owner_symbol].doWrite(req, bufs); } | ||
| 74 | 34 | ||
| 75 | 35 | /* This class serves as a wrapper for when the C++ side of Node wants access | |
| 76 | 36 | * 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,11 +80,7 @@ function handleWriteReq(req, data, encoding) { | |||
| 80 | 80 | function onWriteComplete(status) { | |
| 81 | 81 | debug('onWriteComplete', status, this.error); | |
| 82 | 82 | ||
| 83 | - let stream = this.handle[owner_symbol]; | ||
| 84 | - | ||
| 85 | - if (stream.constructor.name === 'ReusedHandle') { | ||
| 86 | - stream = stream.handle; | ||
| 87 | - } | ||
| 83 | + const stream = this.handle[owner_symbol]; | ||
| 88 | 84 | ||
| 89 | 85 | if (stream.destroyed) { | |
| 90 | 86 | if (typeof this.callback === 'function') | |
@@ -172,12 +168,7 @@ function onStreamRead(arrayBuffer) { | |||
| 172 | 168 | const nread = streamBaseState[kReadBytesOrError]; | |
| 173 | 169 | ||
| 174 | 170 | const handle = this; | |
| 175 | - | ||
| 176 | - let stream = this[owner_symbol]; | ||
| 177 | - | ||
| 178 | - if (stream.constructor.name === 'ReusedHandle') { | ||
| 179 | - stream = stream.handle; | ||
| 180 | - } | ||
| 171 | + const stream = this[owner_symbol]; | ||
| 181 | 172 | ||
| 182 | 173 | stream[kUpdateTimer](); | |
| 183 | 174 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1117,11 +1117,7 @@ Socket.prototype.unref = function() { | |||
| 1117 | 1117 | ||
| 1118 | 1118 | ||
| 1119 | 1119 | function afterConnect(status, handle, req, readable, writable) { | |
| 1120 | - let self = handle[owner_symbol]; | ||
| 1121 | - | ||
| 1122 | - if (self.constructor.name === 'ReusedHandle') { | ||
| 1123 | - self = self.handle; | ||
| 1124 | - } | ||
| 1120 | + const self = handle[owner_symbol]; | ||
| 1125 | 1121 | ||
| 1126 | 1122 | // Callback may come after call to destroy | |
| 1127 | 1123 | 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()->owner_symbol(), object())); | ||
| 316 | + USE(object()->Set(env()->context(), env()->resource_symbol(), object())); | ||
| 317 | 317 | } | |
| 318 | 318 | } | |
| 319 | 319 | ||
@@ -589,7 +589,7 @@ void AsyncWrap::AsyncReset(Local<Object> resource, double execution_async_id, | |||
| 589 | 589 | Local<Object> obj = object(); | |
| 590 | 590 | CHECK(!obj.IsEmpty()); | |
| 591 | 591 | if (resource != obj) { | |
| 592 | - USE(obj->Set(env()->context(), env()->owner_symbol(), resource)); | ||
| 592 | + USE(obj->Set(env()->context(), env()->resource_symbol(), resource)); | ||
| 593 | 593 | } | |
| 594 | 594 | } | |
| 595 | 595 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -171,6 +171,7 @@ constexpr size_t kFsStatsBufferLength = | |||
| 171 | 171 | V(oninit_symbol, "oninit") \ | |
| 172 | 172 | V(owner_symbol, "owner_symbol") \ | |
| 173 | 173 | V(onpskexchange_symbol, "onpskexchange") \ | |
| 174 | + V(resource_symbol, "resource_symbol") \ | ||
| 174 | 175 | V(trigger_async_id_symbol, "trigger_async_id_symbol") \ | |
| 175 | 176 | ||
| 176 | 177 | // Strings are per-isolate primitives but Environment proxies them | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,4 +87,6 @@ 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'); | ||
| 90 | 92 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,4 +105,6 @@ 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'); | ||
| 108 | 110 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments