aurelia-task-queue
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "aurelia-task-queue", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A simple task queue for the browser that enables the queuing of both standard tasks and micro tasks.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
var path = require('path'); | ||
var fs = require('fs'); | ||
var appRoot = 'src/'; | ||
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8')); | ||
module.exports = { | ||
root: appRoot, | ||
source: appRoot + '**/*.js', | ||
html: appRoot + '**/*.html', | ||
style: 'styles/**/*.css', | ||
output: 'dist/', | ||
doc:'./doc', | ||
e2eSpecsSrc: 'test/e2e/src/*.js', | ||
e2eSpecsDist: 'test/e2e/dist/', | ||
packageName: pkg.name | ||
};var path = require('path'); | ||
var fs = require('fs'); | ||
// hide warning // | ||
@@ -21,0 +5,0 @@ var emitter = require('events'); |
@@ -11,3 +11,11 @@ define(['exports', 'aurelia-pal'], function (exports, _aureliaPal) { | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
var hasSetImmediate = typeof setImmediate === 'function'; | ||
var stackSeparator = '\nEnqueued in TaskQueue by:\n'; | ||
var microStackSeparator = '\nEnqueued in MicroTaskQueue by:\n'; | ||
@@ -38,3 +46,7 @@ function makeRequestFlushFromMutationObserver(flush) { | ||
function onError(error, task) { | ||
function onError(error, task, longStacks) { | ||
if (longStacks && task.stack && (typeof error === 'undefined' ? 'undefined' : _typeof(error)) === 'object' && error !== null) { | ||
error.stack = filterFlushStack(error.stack) + task.stack; | ||
} | ||
if ('onError' in task) { | ||
@@ -60,2 +72,3 @@ task.onError(error); | ||
this.flushing = false; | ||
this.longStacks = false; | ||
@@ -86,2 +99,5 @@ this.microTaskQueue = []; | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(microStackSeparator); | ||
} | ||
this.microTaskQueue.push(task); | ||
@@ -95,2 +111,5 @@ }; | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(stackSeparator); | ||
} | ||
this.taskQueue.push(task); | ||
@@ -110,2 +129,5 @@ }; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -115,3 +137,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -132,2 +154,5 @@ this.flushing = false; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -146,3 +171,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -155,4 +180,42 @@ this.flushing = false; | ||
TaskQueue.prototype.prepareQueueStack = function prepareQueueStack(separator) { | ||
var stack = separator + filterQueueStack(captureStack()); | ||
if (typeof this.stack === 'string') { | ||
stack = filterFlushStack(stack) + this.stack; | ||
} | ||
return stack; | ||
}; | ||
return TaskQueue; | ||
}(); | ||
function captureStack() { | ||
var error = new Error(); | ||
if (error.stack) { | ||
return error.stack; | ||
} | ||
try { | ||
throw error; | ||
} catch (e) { | ||
return e.stack; | ||
} | ||
} | ||
function filterQueueStack(stack) { | ||
return stack.replace(/^[\s\S]*?\bqueue(Micro)?Task\b[^\n]*\n/, ''); | ||
} | ||
function filterFlushStack(stack) { | ||
var index = stack.lastIndexOf('flushMicroTaskQueue'); | ||
if (index < 0) { | ||
index = stack.lastIndexOf('flushTaskQueue'); | ||
if (index < 0) { | ||
return stack; | ||
} | ||
} | ||
index = stack.lastIndexOf('\n', index); | ||
return index < 0 ? stack : stack.substr(0, index); | ||
} | ||
}); |
@@ -31,2 +31,7 @@ import { | ||
/** | ||
* Enables long stack traces for queued tasks. | ||
*/ | ||
longStacks: any; | ||
/** | ||
* Creates an instance of TaskQueue. | ||
@@ -57,2 +62,3 @@ */ | ||
flushMicroTaskQueue(): void; | ||
prepareQueueStack(separator?: any): any; | ||
} |
import {DOM,FEATURE} from 'aurelia-pal'; | ||
let hasSetImmediate = typeof setImmediate === 'function'; | ||
const stackSeparator = '\nEnqueued in TaskQueue by:\n'; | ||
const microStackSeparator = '\nEnqueued in MicroTaskQueue by:\n'; | ||
@@ -37,3 +39,11 @@ function makeRequestFlushFromMutationObserver(flush) { | ||
function onError(error, task) { | ||
function onError(error, task, longStacks) { | ||
if (longStacks && | ||
task.stack && | ||
typeof error === 'object' && | ||
error !== null) { | ||
// Note: IE sets error.stack when throwing but does not override a defined .stack. | ||
error.stack = filterFlushStack(error.stack) + task.stack; | ||
} | ||
if ('onError' in task) { | ||
@@ -68,2 +78,7 @@ task.onError(error); | ||
/** | ||
* Enables long stack traces for queued tasks. | ||
*/ | ||
longStacks = false; | ||
/** | ||
* Creates an instance of TaskQueue. | ||
@@ -94,2 +109,5 @@ */ | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(microStackSeparator); | ||
} | ||
this.microTaskQueue.push(task); | ||
@@ -107,2 +125,5 @@ } | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(stackSeparator); | ||
} | ||
this.taskQueue.push(task); | ||
@@ -125,2 +146,5 @@ } | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -130,3 +154,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -150,2 +174,5 @@ this.flushing = false; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -171,3 +198,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -179,2 +206,45 @@ this.flushing = false; | ||
} | ||
prepareQueueStack(separator) { | ||
let stack = separator + filterQueueStack(captureStack()); | ||
if (typeof this.stack === 'string') { | ||
stack = filterFlushStack(stack) + this.stack; | ||
} | ||
return stack; | ||
} | ||
} | ||
function captureStack() { | ||
let error = new Error(); | ||
// Firefox, Chrome, Edge all have .stack defined by now, IE has not. | ||
if (error.stack) { | ||
return error.stack; | ||
} | ||
try { | ||
throw error; | ||
} catch (e) { | ||
return e.stack; | ||
} | ||
} | ||
function filterQueueStack(stack) { | ||
// Remove everything (error message + top stack frames) up to the topmost queueTask or queueMicroTask call | ||
return stack.replace(/^[\s\S]*?\bqueue(Micro)?Task\b[^\n]*\n/, ''); | ||
} | ||
function filterFlushStack(stack) { | ||
// Remove bottom frames starting with the last flushTaskQueue or flushMicroTaskQueue | ||
let index = stack.lastIndexOf('flushMicroTaskQueue'); | ||
if (index < 0) { | ||
index = stack.lastIndexOf('flushTaskQueue'); | ||
if (index < 0) { | ||
return stack; | ||
} | ||
} | ||
index = stack.lastIndexOf('\n', index); | ||
return index < 0 ? stack : stack.substr(0, index); | ||
// The following would work but without regex support to match from end of string, | ||
// it's hard to ensure we have the last occurence of "flushTaskQueue". | ||
// return stack.replace(/\n[^\n]*?\bflush(Micro)?TaskQueue\b[\s\S]*$/, ""); | ||
} |
@@ -8,2 +8,4 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _aureliaPal = require('aurelia-pal'); | ||
@@ -14,2 +16,4 @@ | ||
var hasSetImmediate = typeof setImmediate === 'function'; | ||
var stackSeparator = '\nEnqueued in TaskQueue by:\n'; | ||
var microStackSeparator = '\nEnqueued in MicroTaskQueue by:\n'; | ||
@@ -40,3 +44,7 @@ function makeRequestFlushFromMutationObserver(flush) { | ||
function onError(error, task) { | ||
function onError(error, task, longStacks) { | ||
if (longStacks && task.stack && (typeof error === 'undefined' ? 'undefined' : _typeof(error)) === 'object' && error !== null) { | ||
error.stack = filterFlushStack(error.stack) + task.stack; | ||
} | ||
if ('onError' in task) { | ||
@@ -62,2 +70,3 @@ task.onError(error); | ||
this.flushing = false; | ||
this.longStacks = false; | ||
@@ -88,2 +97,5 @@ this.microTaskQueue = []; | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(microStackSeparator); | ||
} | ||
this.microTaskQueue.push(task); | ||
@@ -97,2 +109,5 @@ }; | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(stackSeparator); | ||
} | ||
this.taskQueue.push(task); | ||
@@ -112,2 +127,5 @@ }; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -117,3 +135,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -134,2 +152,5 @@ this.flushing = false; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -148,3 +169,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -157,3 +178,41 @@ this.flushing = false; | ||
TaskQueue.prototype.prepareQueueStack = function prepareQueueStack(separator) { | ||
var stack = separator + filterQueueStack(captureStack()); | ||
if (typeof this.stack === 'string') { | ||
stack = filterFlushStack(stack) + this.stack; | ||
} | ||
return stack; | ||
}; | ||
return TaskQueue; | ||
}(); | ||
}(); | ||
function captureStack() { | ||
var error = new Error(); | ||
if (error.stack) { | ||
return error.stack; | ||
} | ||
try { | ||
throw error; | ||
} catch (e) { | ||
return e.stack; | ||
} | ||
} | ||
function filterQueueStack(stack) { | ||
return stack.replace(/^[\s\S]*?\bqueue(Micro)?Task\b[^\n]*\n/, ''); | ||
} | ||
function filterFlushStack(stack) { | ||
var index = stack.lastIndexOf('flushMicroTaskQueue'); | ||
if (index < 0) { | ||
index = stack.lastIndexOf('flushTaskQueue'); | ||
if (index < 0) { | ||
return stack; | ||
} | ||
} | ||
index = stack.lastIndexOf('\n', index); | ||
return index < 0 ? stack : stack.substr(0, index); | ||
} |
import { DOM, FEATURE } from 'aurelia-pal'; | ||
let hasSetImmediate = typeof setImmediate === 'function'; | ||
const stackSeparator = '\nEnqueued in TaskQueue by:\n'; | ||
const microStackSeparator = '\nEnqueued in MicroTaskQueue by:\n'; | ||
@@ -29,3 +31,7 @@ function makeRequestFlushFromMutationObserver(flush) { | ||
function onError(error, task) { | ||
function onError(error, task, longStacks) { | ||
if (longStacks && task.stack && typeof error === 'object' && error !== null) { | ||
error.stack = filterFlushStack(error.stack) + task.stack; | ||
} | ||
if ('onError' in task) { | ||
@@ -47,2 +53,3 @@ task.onError(error); | ||
this.flushing = false; | ||
this.longStacks = false; | ||
@@ -67,2 +74,5 @@ this.microTaskQueue = []; | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(microStackSeparator); | ||
} | ||
this.microTaskQueue.push(task); | ||
@@ -76,2 +86,5 @@ } | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(stackSeparator); | ||
} | ||
this.taskQueue.push(task); | ||
@@ -91,2 +104,5 @@ } | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -96,3 +112,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -113,2 +129,5 @@ this.flushing = false; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -127,3 +146,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -135,2 +154,40 @@ this.flushing = false; | ||
} | ||
}; | ||
prepareQueueStack(separator) { | ||
let stack = separator + filterQueueStack(captureStack()); | ||
if (typeof this.stack === 'string') { | ||
stack = filterFlushStack(stack) + this.stack; | ||
} | ||
return stack; | ||
} | ||
}; | ||
function captureStack() { | ||
let error = new Error(); | ||
if (error.stack) { | ||
return error.stack; | ||
} | ||
try { | ||
throw error; | ||
} catch (e) { | ||
return e.stack; | ||
} | ||
} | ||
function filterQueueStack(stack) { | ||
return stack.replace(/^[\s\S]*?\bqueue(Micro)?Task\b[^\n]*\n/, ''); | ||
} | ||
function filterFlushStack(stack) { | ||
let index = stack.lastIndexOf('flushMicroTaskQueue'); | ||
if (index < 0) { | ||
index = stack.lastIndexOf('flushTaskQueue'); | ||
if (index < 0) { | ||
return stack; | ||
} | ||
} | ||
index = stack.lastIndexOf('\n', index); | ||
return index < 0 ? stack : stack.substr(0, index); | ||
} |
@@ -0,6 +1,10 @@ | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
import { DOM, FEATURE } from 'aurelia-pal'; | ||
var hasSetImmediate = typeof setImmediate === 'function'; | ||
var stackSeparator = '\nEnqueued in TaskQueue by:\n'; | ||
var microStackSeparator = '\nEnqueued in MicroTaskQueue by:\n'; | ||
@@ -31,3 +35,7 @@ function makeRequestFlushFromMutationObserver(flush) { | ||
function onError(error, task) { | ||
function onError(error, task, longStacks) { | ||
if (longStacks && task.stack && (typeof error === 'undefined' ? 'undefined' : _typeof(error)) === 'object' && error !== null) { | ||
error.stack = filterFlushStack(error.stack) + task.stack; | ||
} | ||
if ('onError' in task) { | ||
@@ -53,2 +61,3 @@ task.onError(error); | ||
this.flushing = false; | ||
this.longStacks = false; | ||
@@ -79,2 +88,5 @@ this.microTaskQueue = []; | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(microStackSeparator); | ||
} | ||
this.microTaskQueue.push(task); | ||
@@ -88,2 +100,5 @@ }; | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(stackSeparator); | ||
} | ||
this.taskQueue.push(task); | ||
@@ -103,2 +118,5 @@ }; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -108,3 +126,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -125,2 +143,5 @@ this.flushing = false; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -139,3 +160,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -148,3 +169,41 @@ this.flushing = false; | ||
TaskQueue.prototype.prepareQueueStack = function prepareQueueStack(separator) { | ||
var stack = separator + filterQueueStack(captureStack()); | ||
if (typeof this.stack === 'string') { | ||
stack = filterFlushStack(stack) + this.stack; | ||
} | ||
return stack; | ||
}; | ||
return TaskQueue; | ||
}(); | ||
}(); | ||
function captureStack() { | ||
var error = new Error(); | ||
if (error.stack) { | ||
return error.stack; | ||
} | ||
try { | ||
throw error; | ||
} catch (e) { | ||
return e.stack; | ||
} | ||
} | ||
function filterQueueStack(stack) { | ||
return stack.replace(/^[\s\S]*?\bqueue(Micro)?Task\b[^\n]*\n/, ''); | ||
} | ||
function filterFlushStack(stack) { | ||
var index = stack.lastIndexOf('flushMicroTaskQueue'); | ||
if (index < 0) { | ||
index = stack.lastIndexOf('flushTaskQueue'); | ||
if (index < 0) { | ||
return stack; | ||
} | ||
} | ||
index = stack.lastIndexOf('\n', index); | ||
return index < 0 ? stack : stack.substr(0, index); | ||
} |
@@ -6,3 +6,3 @@ 'use strict'; | ||
var DOM, FEATURE, hasSetImmediate, TaskQueue; | ||
var DOM, FEATURE, _typeof, hasSetImmediate, stackSeparator, microStackSeparator, TaskQueue; | ||
@@ -35,3 +35,7 @@ | ||
function onError(error, task) { | ||
function onError(error, task, longStacks) { | ||
if (longStacks && task.stack && (typeof error === 'undefined' ? 'undefined' : _typeof(error)) === 'object' && error !== null) { | ||
error.stack = filterFlushStack(error.stack) + task.stack; | ||
} | ||
if ('onError' in task) { | ||
@@ -50,2 +54,31 @@ task.onError(error); | ||
function captureStack() { | ||
var error = new Error(); | ||
if (error.stack) { | ||
return error.stack; | ||
} | ||
try { | ||
throw error; | ||
} catch (e) { | ||
return e.stack; | ||
} | ||
} | ||
function filterQueueStack(stack) { | ||
return stack.replace(/^[\s\S]*?\bqueue(Micro)?Task\b[^\n]*\n/, ''); | ||
} | ||
function filterFlushStack(stack) { | ||
var index = stack.lastIndexOf('flushMicroTaskQueue'); | ||
if (index < 0) { | ||
index = stack.lastIndexOf('flushTaskQueue'); | ||
if (index < 0) { | ||
return stack; | ||
} | ||
} | ||
index = stack.lastIndexOf('\n', index); | ||
return index < 0 ? stack : stack.substr(0, index); | ||
} | ||
return { | ||
@@ -57,3 +90,10 @@ setters: [function (_aureliaPal) { | ||
execute: function () { | ||
_typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; | ||
}; | ||
hasSetImmediate = typeof setImmediate === 'function'; | ||
stackSeparator = '\nEnqueued in TaskQueue by:\n'; | ||
microStackSeparator = '\nEnqueued in MicroTaskQueue by:\n'; | ||
@@ -67,2 +107,3 @@ _export('TaskQueue', TaskQueue = function () { | ||
this.flushing = false; | ||
this.longStacks = false; | ||
@@ -93,2 +134,5 @@ this.microTaskQueue = []; | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(microStackSeparator); | ||
} | ||
this.microTaskQueue.push(task); | ||
@@ -102,2 +146,5 @@ }; | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(stackSeparator); | ||
} | ||
this.taskQueue.push(task); | ||
@@ -117,2 +164,5 @@ }; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -122,3 +172,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -139,2 +189,5 @@ this.flushing = false; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -153,3 +206,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -162,2 +215,10 @@ this.flushing = false; | ||
TaskQueue.prototype.prepareQueueStack = function prepareQueueStack(separator) { | ||
var stack = separator + filterQueueStack(captureStack()); | ||
if (typeof this.stack === 'string') { | ||
stack = filterFlushStack(stack) + this.stack; | ||
} | ||
return stack; | ||
}; | ||
return TaskQueue; | ||
@@ -164,0 +225,0 @@ }()); |
@@ -1,1 +0,1 @@ | ||
{"name":"aurelia-task-queue","children":[{"id":5,"name":"TaskQueue","kind":128,"kindString":"Class","flags":{"isExported":true},"comment":{"shortText":"Implements an asynchronous task queue."},"children":[{"id":7,"name":"constructor","kind":512,"kindString":"Constructor","flags":{"isExported":true},"comment":{"shortText":"Creates an instance of TaskQueue."},"signatures":[{"id":8,"name":"new TaskQueue","kind":16384,"kindString":"Constructor signature","flags":{},"comment":{"shortText":"Creates an instance of TaskQueue."},"type":{"type":"reference","name":"TaskQueue","id":5}}]},{"id":6,"name":"flushing","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"Whether the queue is in the process of flushing."},"type":{"type":"instrinct","name":"any"}},{"id":17,"name":"flushMicroTaskQueue","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":18,"name":"flushMicroTaskQueue","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Immediately flushes the micro task queue."},"type":{"type":"instrinct","name":"void"}}]},{"id":15,"name":"flushTaskQueue","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":16,"name":"flushTaskQueue","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Immediately flushes the task queue."},"type":{"type":"instrinct","name":"void"}}]},{"id":9,"name":"queueMicroTask","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":10,"name":"queueMicroTask","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Queues a task on the micro task queue for ASAP execution."},"parameters":[{"id":11,"name":"task","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The task to queue up for ASAP execution.\n"},"type":{"type":"union","types":[{"type":"reference","name":"Task","id":2},{"type":"reference","name":"Function"}]}}],"type":{"type":"instrinct","name":"void"}}]},{"id":12,"name":"queueTask","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":13,"name":"queueTask","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Queues a task on the macro task queue for turn-based execution."},"parameters":[{"id":14,"name":"task","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The task to queue up for turn-based execution.\n"},"type":{"type":"union","types":[{"type":"reference","name":"Task","id":2},{"type":"reference","name":"Function"}]}}],"type":{"type":"instrinct","name":"void"}}]}],"groups":[{"title":"Constructors","kind":512,"children":[7]},{"title":"Properties","kind":1024,"children":[6]},{"title":"Methods","kind":2048,"children":[17,15,9,12]}]},{"id":2,"name":"Task","kind":256,"kindString":"Interface","flags":{"isExported":true},"comment":{"shortText":"Either a Function or a class with a call method that will do work when dequeued."},"children":[{"id":3,"name":"call","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":4,"name":"call","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Call it."},"type":{"type":"instrinct","name":"void"}}]}],"groups":[{"title":"Methods","kind":2048,"children":[3]}]}],"groups":[{"title":"Classes","kind":128,"children":[5]},{"title":"Interfaces","kind":256,"children":[2]}]} | ||
{"name":"aurelia-task-queue","children":[{"id":5,"name":"TaskQueue","kind":128,"kindString":"Class","flags":{"isExported":true},"comment":{"shortText":"Implements an asynchronous task queue."},"children":[{"id":8,"name":"constructor","kind":512,"kindString":"Constructor","flags":{"isExported":true},"comment":{"shortText":"Creates an instance of TaskQueue."},"signatures":[{"id":9,"name":"new TaskQueue","kind":16384,"kindString":"Constructor signature","flags":{},"comment":{"shortText":"Creates an instance of TaskQueue."},"type":{"type":"reference","name":"TaskQueue","id":5}}]},{"id":6,"name":"flushing","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"Whether the queue is in the process of flushing."},"type":{"type":"instrinct","name":"any"}},{"id":7,"name":"longStacks","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"Enables long stack traces for queued tasks."},"type":{"type":"instrinct","name":"any"}},{"id":18,"name":"flushMicroTaskQueue","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":19,"name":"flushMicroTaskQueue","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Immediately flushes the micro task queue."},"type":{"type":"instrinct","name":"void"}}]},{"id":16,"name":"flushTaskQueue","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":17,"name":"flushTaskQueue","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Immediately flushes the task queue."},"type":{"type":"instrinct","name":"void"}}]},{"id":20,"name":"prepareQueueStack","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":21,"name":"prepareQueueStack","kind":4096,"kindString":"Call signature","flags":{},"parameters":[{"id":22,"name":"separator","kind":32768,"kindString":"Parameter","flags":{"isOptional":true},"type":{"type":"instrinct","name":"any"}}],"type":{"type":"instrinct","name":"any"}}]},{"id":10,"name":"queueMicroTask","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":11,"name":"queueMicroTask","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Queues a task on the micro task queue for ASAP execution."},"parameters":[{"id":12,"name":"task","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The task to queue up for ASAP execution.\n"},"type":{"type":"union","types":[{"type":"reference","name":"Task","id":2},{"type":"reference","name":"Function"}]}}],"type":{"type":"instrinct","name":"void"}}]},{"id":13,"name":"queueTask","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":14,"name":"queueTask","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Queues a task on the macro task queue for turn-based execution."},"parameters":[{"id":15,"name":"task","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The task to queue up for turn-based execution.\n"},"type":{"type":"union","types":[{"type":"reference","name":"Task","id":2},{"type":"reference","name":"Function"}]}}],"type":{"type":"instrinct","name":"void"}}]}],"groups":[{"title":"Constructors","kind":512,"children":[8]},{"title":"Properties","kind":1024,"children":[6,7]},{"title":"Methods","kind":2048,"children":[18,16,20,10,13]}]},{"id":2,"name":"Task","kind":256,"kindString":"Interface","flags":{"isExported":true},"comment":{"shortText":"Either a Function or a class with a call method that will do work when dequeued."},"children":[{"id":3,"name":"call","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":4,"name":"call","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Call it."},"type":{"type":"instrinct","name":"void"}}]}],"groups":[{"title":"Methods","kind":2048,"children":[3]}]}],"groups":[{"title":"Classes","kind":128,"children":[5]},{"title":"Interfaces","kind":256,"children":[2]}]} |
@@ -0,1 +1,11 @@ | ||
<a name="1.2.0"></a> | ||
# [1.2.0](https://github.com/aurelia/task-queue/compare/1.1.0...v1.2.0) (2017-02-21) | ||
### Features | ||
* **index:** provide public api for enabling long stack traces ([352f50b](https://github.com/aurelia/task-queue/commit/352f50b)) | ||
<a name="1.1.0"></a> | ||
@@ -2,0 +12,0 @@ # [1.1.0](https://github.com/aurelia/task-queue/compare/1.0.0...v1.1.0) (2016-09-29) |
{ | ||
"name": "aurelia-task-queue", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A simple task queue for the browser that enables the queuing of both standard tasks and micro tasks.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import {DOM, FEATURE} from 'aurelia-pal'; | ||
let hasSetImmediate = typeof setImmediate === 'function'; | ||
const stackSeparator = '\nEnqueued in TaskQueue by:\n'; | ||
const microStackSeparator = '\nEnqueued in MicroTaskQueue by:\n'; | ||
@@ -37,3 +39,11 @@ function makeRequestFlushFromMutationObserver(flush) { | ||
function onError(error, task) { | ||
function onError(error, task, longStacks) { | ||
if (longStacks && | ||
task.stack && | ||
typeof error === 'object' && | ||
error !== null) { | ||
// Note: IE sets error.stack when throwing but does not override a defined .stack. | ||
error.stack = filterFlushStack(error.stack) + task.stack; | ||
} | ||
if ('onError' in task) { | ||
@@ -68,2 +78,7 @@ task.onError(error); | ||
/** | ||
* Enables long stack traces for queued tasks. | ||
*/ | ||
longStacks = false; | ||
/** | ||
* Creates an instance of TaskQueue. | ||
@@ -94,2 +109,5 @@ */ | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(microStackSeparator); | ||
} | ||
this.microTaskQueue.push(task); | ||
@@ -107,2 +125,5 @@ } | ||
if (this.longStacks) { | ||
task.stack = this.prepareQueueStack(stackSeparator); | ||
} | ||
this.taskQueue.push(task); | ||
@@ -125,2 +146,5 @@ } | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -130,3 +154,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -150,2 +174,5 @@ this.flushing = false; | ||
task = queue[index]; | ||
if (this.longStacks) { | ||
this.stack = typeof task.stack === 'string' ? task.stack : undefined; | ||
} | ||
task.call(); | ||
@@ -171,3 +198,3 @@ index++; | ||
} catch (error) { | ||
onError(error, task); | ||
onError(error, task, this.longStacks); | ||
} finally { | ||
@@ -179,2 +206,45 @@ this.flushing = false; | ||
} | ||
prepareQueueStack(separator) { | ||
let stack = separator + filterQueueStack(captureStack()); | ||
if (typeof this.stack === 'string') { | ||
stack = filterFlushStack(stack) + this.stack; | ||
} | ||
return stack; | ||
} | ||
} | ||
function captureStack() { | ||
let error = new Error(); | ||
// Firefox, Chrome, Edge all have .stack defined by now, IE has not. | ||
if (error.stack) { | ||
return error.stack; | ||
} | ||
try { | ||
throw error; | ||
} catch (e) { | ||
return e.stack; | ||
} | ||
} | ||
function filterQueueStack(stack) { | ||
// Remove everything (error message + top stack frames) up to the topmost queueTask or queueMicroTask call | ||
return stack.replace(/^[\s\S]*?\bqueue(Micro)?Task\b[^\n]*\n/, ''); | ||
} | ||
function filterFlushStack(stack) { | ||
// Remove bottom frames starting with the last flushTaskQueue or flushMicroTaskQueue | ||
let index = stack.lastIndexOf('flushMicroTaskQueue'); | ||
if (index < 0) { | ||
index = stack.lastIndexOf('flushTaskQueue'); | ||
if (index < 0) { | ||
return stack; | ||
} | ||
} | ||
index = stack.lastIndexOf('\n', index); | ||
return index < 0 ? stack : stack.substr(0, index); | ||
// The following would work but without regex support to match from end of string, | ||
// it's hard to ensure we have the last occurence of "flushTaskQueue". | ||
// return stack.replace(/\n[^\n]*?\bflush(Micro)?TaskQueue\b[\s\S]*$/, ""); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
143830
2334
2