@@ -7,6 +7,39 @@ var common = require('./common');
77var assert = require ( 'assert' ) ;
88var callbackify = require ( '../../' ) . callbackify ;
99var execFile = require ( 'child_process' ) . execFile ;
10+ var nodeJSVersion = require ( '../../support/nodeJSVersion' ) ;
11+ var isFunctionLengthConfigurable = require ( "../../support/isFunctionLengthConfigurable" ) ;
12+
13+ ( function callbackify_resulting_function_should_have_one_more_argument ( ) {
14+
15+ if ( ! isFunctionLengthConfigurable ( ) ) {
16+ console . log ( "skipping this test as function.length is not configurable in the current javascript engine" ) ;
17+ return ;
18+ }
19+ var nodeVersion = nodeJSVersion ( ) ;
20+
21+ console . log ( "Testing callbackify resulting function should have one more argument" )
22+ var original_callbackify = require ( 'util' ) . callbackify ;
23+ // Test that resulting function should have one more argument
24+ [
25+ function ( ) { } ,
26+ function ( a ) { } ,
27+ function ( a , b ) { }
28+ ] . forEach ( function ( fct ) {
29+
30+ var node_callbackified = original_callbackify ( fct ) ;
31+ var browser_callbackified = callbackify ( fct ) ;
32+
33+ if ( nodeVersion >= 12 && node_callbackified . length !== fct . length + 1 ) {
34+ // this behavior is only true with node 12 and above, where the bug was fixed
35+ throw new Error ( "callbackified function should have one more argument" ) ;
36+ }
37+ if ( browser_callbackified . length !== node_callbackified . length ) {
38+ console . log ( "browser_callbackified=" , browser_callbackified . length , "node_callbackified=" , node_callbackified . length )
39+ throw new Error ( "callbackified function should have one more argument, like in node" ) ;
40+ }
41+ } ) ;
42+ } ) ( ) ;
1043
1144if ( typeof Promise === 'undefined' ) {
1245 console . log ( 'no global Promise found, skipping callbackify tests' ) ;
@@ -193,29 +226,3 @@ if (false) {
193226if ( require ( 'is-async-supported' ) ( ) ) {
194227 require ( './callbackify-async' ) ;
195228}
196-
197- ( function callbackify_resulting_function_should_have_one_more_argument ( ) {
198-
199- var nodeJSVersion = parseInt ( process . version . substring ( 1 , 3 ) , 10 ) ;
200-
201- console . log ( "Testing callbackify resulting function should have one more argument" )
202- var original_callbackify = require ( 'util' ) . callbackify ;
203- // Test that resulting function should have one more argument
204- [
205- function ( ) { } ,
206- function ( a ) { } ,
207- function ( a , b ) { }
208- ] . forEach ( function ( fct ) {
209-
210- var node_callbackified = original_callbackify ( fct ) ;
211- var browser_callbackified = callbackify ( fct ) ;
212-
213- if ( nodeJSVersion >= 12 && node_callbackified . length !== fct . length + 1 ) {
214- // this behavior is only true with node 12 and above, where the bug was fixed
215- throw new Error ( "callbackified function should have one more argument" ) ;
216- }
217- if ( browser_callbackified . length !== node_callbackified . length ) {
218- throw new Error ( "callbackified function should have one more argument, like in node" ) ;
219- }
220- } ) ;
221- } ) ( ) ;
0 commit comments