diff --git a/Tone/core/Offline.js b/Tone/core/Offline.js index 6d2727fb..340a9a2a 100644 --- a/Tone/core/Offline.js +++ b/Tone/core/Offline.js @@ -66,7 +66,7 @@ define(["Tone/core/Tone", "Tone/core/Transport", "Tone/core/Buffer", "Tone/core/ var context = renderRet.context; var ret; - if (response instanceof Promise){ + if (response && Tone.isFunction(response.then)){ //wait for the promise to resolve ret = response.then(function(){ //then render the audio diff --git a/Tone/shim/AudioContext.js b/Tone/shim/AudioContext.js index 4ef7d8ff..118a563e 100644 --- a/Tone/shim/AudioContext.js +++ b/Tone/shim/AudioContext.js @@ -40,7 +40,7 @@ define(["Tone/core/Tone", "Tone/shim/OfflineAudioContext"], function(Tone){ var audioData = new Uint32Array([1179011410, 48, 1163280727, 544501094, 16, 131073, 44100, 176400, 1048580, 1635017060, 8, 0, 0, 0, 0]).buffer; try { var ret = offlineContext.decodeAudioData(audioData); - if (ret instanceof Promise){ + if (ret && Tone.isFunction(ret.then)){ decodeAudioDataPromise = true; } } catch (e){ diff --git a/Tone/shim/OfflineAudioContext.js b/Tone/shim/OfflineAudioContext.js index 91b63816..161c7f02 100644 --- a/Tone/shim/OfflineAudioContext.js +++ b/Tone/shim/OfflineAudioContext.js @@ -8,7 +8,7 @@ define(["Tone/core/Tone"], function(Tone){ //returns promise? var context = new OfflineAudioContext(1, 1, 44100); var ret = context.startRendering(); - if (!(ret instanceof Promise)){ + if (!(ret && Tone.isFunction(ret.then))){ OfflineAudioContext.prototype._native_startRendering = OfflineAudioContext.prototype.startRendering; OfflineAudioContext.prototype.startRendering = function(){ return new Promise(function(done){ diff --git a/test/helper/Offline.js b/test/helper/Offline.js index 572ea21e..7542ad7c 100644 --- a/test/helper/Offline.js +++ b/test/helper/Offline.js @@ -1,24 +1,23 @@ -define(["Tone/core/Tone", "Tone/core/Offline", "helper/BufferTest", "Tone/core/Master"], - function(Tone, Offline, BufferTest, Master) { +define(["Tone/core/Tone", "Tone/core/Offline", "helper/BufferTest", "Tone/core/Master"], function(Tone, Offline, BufferTest, Master){ - return function(callback, duration, channels){ - duration = duration || 0.1; - channels = channels || 1; - return Offline(function(Transport){ - var testFn = callback(Transport); - if (testFn instanceof Promise){ - return testFn; - } else if (Tone.isFunction(testFn)){ - Transport.context.on("tick", function(){ - testFn(Transport.now()); - }); - } - }, duration).then(function(buffer){ - BufferTest(buffer); - if (channels === 1){ - buffer.toMono(); - } - return buffer; - }); - }; - }); + return function(callback, duration, channels){ + duration = duration || 0.1; + channels = channels || 1; + return Offline(function(Transport){ + var testFn = callback(Transport); + if (testFn && Tone.isFunction(testFn.then)){ + return testFn; + } else if (Tone.isFunction(testFn)){ + Transport.context.on("tick", function(){ + testFn(Transport.now()); + }); + } + }, duration).then(function(buffer){ + BufferTest(buffer); + if (channels === 1){ + buffer.toMono(); + } + return buffer; + }); + }; +});