@@ -296,9 +296,13 @@ Worker.prototype.save = function save(filename) {
296
296
/* ----- SET / GET ----- */
297
297
298
298
Worker . prototype . set = function set ( opt ) {
299
- // TODO: Test null/undefined input to this function.
300
299
// TODO: Implement ordered pairs?
301
300
301
+ // Silently ignore invalid or empty input.
302
+ if ( objType ( opt ) !== 'object' ) {
303
+ return this ;
304
+ }
305
+
302
306
// Build an array of setter functions to queue.
303
307
var fns = Object . keys ( opt || { } ) . map ( function ( key ) {
304
308
if ( key in Worker . template . prop ) {
@@ -412,9 +416,13 @@ Worker.prototype.then = function then(onFulfilled, onRejected) {
412
416
if ( onFulfilled ) { onFulfilled = onFulfilled . bind ( self ) ; }
413
417
if ( onRejected ) { onRejected = onRejected . bind ( self ) ; }
414
418
419
+ // Cast self into a Promise to avoid es6-promise recursively defining `then`.
420
+ var selfPromise = ( '_state' in self ) ?
421
+ Worker . convert ( Object . assign ( { } , self ) , Promise . prototype ) : self ;
422
+
415
423
// Update progress while queuing, calling, and resolving `then`.
416
424
self . updateProgress ( null , null , 1 , [ onFulfilled ] ) ;
417
- var returnVal = Promise . prototype . then . call ( self , function then_pre ( val ) {
425
+ var returnVal = Promise . prototype . then . call ( selfPromise , function then_pre ( val ) {
418
426
self . updateProgress ( null , onFulfilled ) ;
419
427
return val ;
420
428
} ) . then ( onFulfilled , onRejected ) . then ( function then_post ( val ) {
@@ -434,8 +442,12 @@ Worker.prototype.thenCore = function thenCore(onFulfilled, onRejected) {
434
442
if ( onFulfilled ) { onFulfilled = onFulfilled . bind ( self ) ; }
435
443
if ( onRejected ) { onRejected = onRejected . bind ( self ) ; }
436
444
445
+ // Cast self into a Promise to avoid es6-promise recursively defining `then`.
446
+ var selfPromise = ( '_state' in self ) ?
447
+ Worker . convert ( Object . assign ( { } , self ) , Promise . prototype ) : self ;
448
+
437
449
// Return the promise, after casting it into a Worker and preserving props.
438
- var returnVal = Promise . prototype . then . call ( self , onFulfilled , onRejected ) ;
450
+ var returnVal = Promise . prototype . then . call ( selfPromise , onFulfilled , onRejected ) ;
439
451
return Worker . convert ( returnVal , self . __proto__ ) ;
440
452
} ;
441
453
0 commit comments