@@ -176,7 +176,7 @@ test('`errorFirst` option and `multiArgs`', async t => {
176
176
} ) ( '🦄' , '🌈' ) , [ '🦄' , '🌈' ] ) ;
177
177
} ) ;
178
178
179
- test ( 'class support - creates a copy' , async t => {
179
+ test ( 'class support - does not create a copy' , async t => {
180
180
const obj = {
181
181
x : 'foo' ,
182
182
y ( cb ) {
@@ -186,28 +186,17 @@ test('class support - creates a copy', async t => {
186
186
}
187
187
} ;
188
188
189
- const pified = m ( obj , { bind : false } ) ;
189
+ const pified = m ( obj ) ;
190
190
obj . x = 'bar' ;
191
191
192
- t . is ( await pified . y ( ) , 'foo ' ) ;
193
- t . is ( pified . x , 'foo ' ) ;
192
+ t . is ( await pified . y ( ) , 'bar ' ) ;
193
+ t . is ( pified . x , 'bar ' ) ;
194
194
} ) ;
195
195
196
196
test ( 'class support — transforms inherited methods' , t => {
197
197
const instance = new FixtureClass ( ) ;
198
198
const pInstance = m ( instance ) ;
199
199
200
- const flattened = { } ;
201
- for ( let prot = instance ; prot ; prot = Object . getPrototypeOf ( prot ) ) {
202
- Object . assign ( flattened , prot ) ;
203
- }
204
-
205
- const keys = Object . keys ( flattened ) ;
206
- keys . sort ( ) ;
207
- const pKeys = Object . keys ( pInstance ) ;
208
- pKeys . sort ( ) ;
209
- t . deepEqual ( keys , pKeys ) ;
210
-
211
200
t . is ( instance . value1 , pInstance . value1 ) ;
212
201
t . is ( typeof pInstance . instanceMethod1 ( ) . then , 'function' ) ;
213
202
t . is ( typeof pInstance . method1 ( ) . then , 'function' ) ;
@@ -236,17 +225,6 @@ test('class support - transforms only members in options.include, copies all', t
236
225
include : [ 'parentMethod1' ]
237
226
} ) ;
238
227
239
- const flattened = { } ;
240
- for ( let prot = instance ; prot ; prot = Object . getPrototypeOf ( prot ) ) {
241
- Object . assign ( flattened , prot ) ;
242
- }
243
-
244
- const keys = Object . keys ( flattened ) ;
245
- keys . sort ( ) ;
246
- const pKeys = Object . keys ( pInstance ) ;
247
- pKeys . sort ( ) ;
248
- t . deepEqual ( keys , pKeys ) ;
249
-
250
228
t . is ( typeof pInstance . parentMethod1 ( ) . then , 'function' ) ;
251
229
t . not ( typeof pInstance . method1 ( ( ) => { } ) . then , 'function' ) ;
252
230
t . not ( typeof pInstance . grandparentMethod1 ( ( ) => { } ) . then , 'function' ) ;
@@ -278,3 +256,90 @@ test('promisify prototype function', async t => {
278
256
const instance = new FixtureClass ( ) ;
279
257
t . is ( await instance . method2Async ( ) , 72 ) ;
280
258
} ) ;
259
+
260
+ test ( 'method mutation' , async t => {
261
+ const obj = {
262
+ foo ( cb ) {
263
+ setImmediate ( ( ) => cb ( null , 'original' ) ) ;
264
+ }
265
+ } ;
266
+ const pified = m ( obj ) ;
267
+
268
+ obj . foo = cb => setImmediate ( ( ) => cb ( null , 'new' ) ) ;
269
+
270
+ t . is ( await pified . foo ( ) , 'new' ) ;
271
+ } ) ;
272
+
273
+ test ( 'symbol keys' , async t => {
274
+ await t . notThrowsAsync ( async ( ) => {
275
+ const sym = Symbol ( 'sym' ) ;
276
+ const obj = { [ sym ] : cb => setImmediate ( cb ) } ;
277
+ const pified = m ( obj ) ;
278
+ await pified [ sym ] ( ) ;
279
+ } ) ;
280
+ } ) ;
281
+
282
+ // [[Get]] for proxy objects enforces the following invariants: The value
283
+ // reported for a property must be the same as the value of the corresponding
284
+ // target object property if the target object property is a non-writable,
285
+ // non-configurable own data property.
286
+ test ( 'non-writable non-configurable property' , t => {
287
+ const obj = { } ;
288
+ Object . defineProperty ( obj , 'prop' , {
289
+ value : cb => setImmediate ( cb ) ,
290
+ writable : false ,
291
+ configurable : false
292
+ } ) ;
293
+
294
+ const pified = m ( obj ) ;
295
+ t . notThrows ( ( ) => Reflect . get ( pified , 'prop' ) ) ;
296
+ } ) ;
297
+
298
+ test ( 'do not promisify Function.prototype.bind' , async t => {
299
+ function fn ( cb ) {
300
+ cb ( null , this ) ;
301
+ }
302
+ const target = { } ;
303
+ t . is ( await m ( fn ) . bind ( target ) ( ) , target ) ;
304
+ } ) ;
305
+
306
+ test ( 'do not break internal callback usage' , async t => {
307
+ const obj = {
308
+ foo ( cb ) {
309
+ this . bar ( 4 , cb ) ;
310
+ } ,
311
+ bar ( ...args ) {
312
+ const cb = args . pop ( ) ;
313
+ cb ( null , 42 ) ;
314
+ }
315
+ } ;
316
+ t . is ( await m ( obj ) . foo ( ) , 42 ) ;
317
+ } ) ;
318
+
319
+ test ( 'Function.prototype.call' , async t => {
320
+ function fn ( ...args ) {
321
+ const cb = args . pop ( ) ;
322
+ cb ( null , args . length ) ;
323
+ }
324
+ const pified = m ( fn ) ;
325
+ t . is ( await pified . call ( ) , 0 ) ;
326
+ } ) ;
327
+
328
+ test ( 'Function.prototype.apply' , async t => {
329
+ function fn ( ...args ) {
330
+ const cb = args . pop ( ) ;
331
+ cb ( null , args . length ) ;
332
+ }
333
+ const pified = m ( fn ) ;
334
+ t . is ( await pified . apply ( ) , 0 ) ;
335
+ } ) ;
336
+
337
+ test ( 'self as member' , async t => {
338
+ function fn ( ...args ) {
339
+ const cb = args . pop ( ) ;
340
+ cb ( null , args . length ) ;
341
+ }
342
+ fn . self = fn ;
343
+ const pified = m ( fn ) ;
344
+ t . is ( await pified . self ( ) , 0 ) ;
345
+ } ) ;
0 commit comments