1
1
/* eslint-disable no-multi-spaces */
2
2
/* eslint-disable no-underscore-dangle */
3
3
/* eslint-disable prefer-rest-params */
4
+ /* eslint-disable prefer-spread */
4
5
5
6
/* global EXECPATH_FD */
6
7
/* global PAYLOAD_POSITION */
@@ -162,9 +163,33 @@ function findNativeAddon (path) {
162
163
}
163
164
164
165
// /////////////////////////////////////////////////////////////////
165
- // PAYLOAD /// //////////////////////////////////////////////////////
166
+ // FLOW UTILS //////////////////////////////////////////////////////
166
167
// /////////////////////////////////////////////////////////////////
167
168
169
+ function asap ( cb ) {
170
+ process . nextTick ( cb ) ;
171
+ }
172
+
173
+ function dezalgo ( cb ) {
174
+ if ( ! cb ) return cb ;
175
+
176
+ var sync = true ;
177
+ asap ( function ( ) {
178
+ sync = false ;
179
+ } ) ;
180
+
181
+ return function zalgoSafe ( ) {
182
+ var args = arguments ;
183
+ if ( sync ) {
184
+ asap ( function ( ) {
185
+ cb . apply ( undefined , args ) ;
186
+ } ) ;
187
+ } else {
188
+ cb . apply ( undefined , args ) ;
189
+ }
190
+ } ;
191
+ }
192
+
168
193
function rethrow ( error ) {
169
194
if ( error ) throw error ;
170
195
}
@@ -174,6 +199,10 @@ function rethrowBytesRead (error, bytesRead) {
174
199
return bytesRead ;
175
200
}
176
201
202
+ // /////////////////////////////////////////////////////////////////
203
+ // PAYLOAD /////////////////////////////////////////////////////////
204
+ // /////////////////////////////////////////////////////////////////
205
+
177
206
function payloadCopy ( source , target , targetStart , sourceStart , sourceEnd , cb ) {
178
207
var cb2 = cb || rethrowBytesRead ;
179
208
if ( sourceStart >= source [ 1 ] ) return cb2 ( null , 0 ) ;
@@ -636,7 +665,7 @@ var modifyNativeAddonWin32 = (function () {
636
665
return ancestor . read . apply ( fs , arguments ) ;
637
666
}
638
667
639
- var callback = maybeCallback ( arguments ) ;
668
+ var callback = dezalgo ( maybeCallback ( arguments ) ) ;
640
669
readFromSnapshot ( fd , buffer , offset , length , position , callback ) ;
641
670
} ;
642
671
0 commit comments