async-try-catch
Advanced tools
Comparing version 0.1.7 to 0.2.1
@@ -35,6 +35,44 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.AsyncTryCatch = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
module.exports = AsyncTryCatch ; | ||
global.AsyncTryCatch = AsyncTryCatch ; | ||
AsyncTryCatch.prototype.__prototypeUID__ = 'async-try-catch/AsyncTryCatch' ; | ||
AsyncTryCatch.prototype.__prototypeVersion__ = require( '../package.json' ).version ; | ||
if ( global.AsyncTryCatch ) | ||
{ | ||
if ( global.AsyncTryCatch.prototype.__prototypeUID__ === 'async-try-catch/AsyncTryCatch' ) | ||
{ | ||
//console.log( "Already installed:" , global.AsyncTryCatch.prototype.__prototypeVersion__ , "current:" , AsyncTryCatch.prototype.__prototypeVersion__ ) ; | ||
var currentVersions = AsyncTryCatch.prototype.__prototypeVersion__.split( '.' ) ; | ||
var installedVersions = global.AsyncTryCatch.prototype.__prototypeVersion__.split( '.' ) ; | ||
// Basic semver comparison | ||
if ( | ||
installedVersions[ 0 ] !== currentVersions[ 0 ] || | ||
( currentVersions[ 0 ] === "0" && installedVersions[ 1 ] !== currentVersions[ 1 ] ) | ||
) | ||
{ | ||
throw new Error( | ||
"Incompatible version of AsyncTryCatch already installed on global.AsyncTryCatch: " + | ||
global.AsyncTryCatch.prototype.__prototypeVersion__ + | ||
", current version: " + AsyncTryCatch.prototype.__prototypeVersion__ | ||
) ; | ||
} | ||
//global.AsyncTryCatch = AsyncTryCatch ; | ||
} | ||
else | ||
{ | ||
throw new Error( "Incompatible module already installed on global.AsyncTryCatch" ) ; | ||
} | ||
} | ||
else | ||
{ | ||
global.AsyncTryCatch = AsyncTryCatch ; | ||
global.AsyncTryCatch.stack = [] ; | ||
global.AsyncTryCatch.substituted = false ; | ||
} | ||
if ( process.browser && ! global.setImmediate ) | ||
@@ -48,17 +86,9 @@ { | ||
if ( ! global.Vanilla ) | ||
{ | ||
global.Vanilla = {} ; | ||
if ( ! global.Vanilla.setTimeout ) { global.Vanilla.setTimeout = setTimeout ; } | ||
if ( ! global.Vanilla.setImmediate ) { global.Vanilla.setImmediate = setImmediate ; } | ||
if ( ! global.Vanilla.nextTick ) { global.Vanilla.nextTick = process.nextTick ; } | ||
//if ( ! global.Vanilla.Error ) { global.Vanilla.Error = Error ; } | ||
} | ||
if ( ! global.Vanilla ) { global.Vanilla = {} ; } | ||
if ( ! global.Vanilla.setTimeout ) { global.Vanilla.setTimeout = setTimeout ; } | ||
if ( ! global.Vanilla.setImmediate ) { global.Vanilla.setImmediate = setImmediate ; } | ||
if ( ! global.Vanilla.nextTick ) { global.Vanilla.nextTick = process.nextTick ; } | ||
AsyncTryCatch.stack = [] ; | ||
AsyncTryCatch.substituted = false ; | ||
AsyncTryCatch.try = function try_( fn ) | ||
@@ -68,3 +98,3 @@ { | ||
fn: { value: fn , enumerable: true } , | ||
parent: { value: AsyncTryCatch.stack[ AsyncTryCatch.stack.length - 1 ] } | ||
parent: { value: global.AsyncTryCatch.stack[ global.AsyncTryCatch.stack.length - 1 ] } | ||
} ) ; | ||
@@ -83,11 +113,11 @@ | ||
if ( ! AsyncTryCatch.substituted ) { AsyncTryCatch.substitute() ; } | ||
if ( ! global.AsyncTryCatch.substituted ) { AsyncTryCatch.substitute() ; } | ||
try { | ||
AsyncTryCatch.stack.push( this ) ; | ||
global.AsyncTryCatch.stack.push( this ) ; | ||
this.fn() ; | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
} | ||
catch ( error ) { | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
this.callCatchFn( error ) ; | ||
@@ -110,8 +140,8 @@ } | ||
try { | ||
AsyncTryCatch.stack.push( this.parent ) ; | ||
global.AsyncTryCatch.stack.push( this.parent ) ; | ||
this.catchFn( error ) ; | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
} | ||
catch ( error ) { | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
this.parent.callCatchFn( error ) ; | ||
@@ -129,3 +159,3 @@ } | ||
if ( typeof fn !== 'function' || ! AsyncTryCatch.stack.length ) | ||
if ( typeof fn !== 'function' || ! global.AsyncTryCatch.stack.length ) | ||
{ | ||
@@ -135,12 +165,12 @@ return originalMethod.apply( this , args ) ; | ||
context = AsyncTryCatch.stack[ AsyncTryCatch.stack.length - 1 ] ; | ||
context = global.AsyncTryCatch.stack[ global.AsyncTryCatch.stack.length - 1 ] ; | ||
wrapperFn = function() { | ||
try { | ||
AsyncTryCatch.stack.push( context ) ; | ||
global.AsyncTryCatch.stack.push( context ) ; | ||
fn.apply( this , arguments ) ; | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
} | ||
catch ( error ) { | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
context.callCatchFn( error ) ; | ||
@@ -170,3 +200,3 @@ } | ||
if ( typeof fn !== 'function' || ! AsyncTryCatch.stack.length ) | ||
if ( typeof fn !== 'function' || ! global.AsyncTryCatch.stack.length ) | ||
{ | ||
@@ -176,3 +206,3 @@ return originalMethod.call( this , eventName , fn , options ) ; | ||
context = AsyncTryCatch.stack[ AsyncTryCatch.stack.length - 1 ] ; | ||
context = global.AsyncTryCatch.stack[ global.AsyncTryCatch.stack.length - 1 ] ; | ||
@@ -194,8 +224,8 @@ // Assume that the function is only wrapped once per eventEmitter | ||
try { | ||
AsyncTryCatch.stack.push( context ) ; | ||
global.AsyncTryCatch.stack.push( context ) ; | ||
fn.apply( this , arguments ) ; | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
} | ||
catch ( error ) { | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
context.callCatchFn( error ) ; | ||
@@ -240,9 +270,3 @@ } | ||
{ | ||
try { | ||
AsyncTryCatch.addListenerWrapper.call( this , AsyncTryCatch.NodeEvents.__addListenerOnce , eventName , fn ) ; | ||
} catch ( error ) { | ||
console.log( AsyncTryCatch.NodeEvents ) ; | ||
console.log( AsyncTryCatch.NodeEvents.__addListenerOnce ) ; | ||
throw error ; | ||
} | ||
} ; | ||
@@ -281,4 +305,4 @@ | ||
//if ( AsyncTryCatch.substituted ) { return ; } | ||
AsyncTryCatch.substituted = true ; | ||
//if ( global.AsyncTryCatch.substituted ) { return ; } | ||
global.AsyncTryCatch.substituted = true ; | ||
@@ -321,5 +345,2 @@ global.setTimeout = AsyncTryCatch.setTimeout ; | ||
//global.Error = AsyncTryCatch.Error ; | ||
// Should do that for all error types, cause they will not inherit from the substituted constructor | ||
if ( AsyncTryCatch.NextGenEvents ) | ||
@@ -342,4 +363,4 @@ { | ||
//if ( ! AsyncTryCatch.substituted ) { return ; } | ||
AsyncTryCatch.substituted = false ; | ||
//if ( ! global.AsyncTryCatch.substituted ) { return ; } | ||
global.AsyncTryCatch.substituted = false ; | ||
@@ -358,4 +379,2 @@ global.setTimeout = global.Vanilla.setTimeout ; | ||
//global.Error = global.Vanilla.Error ; | ||
if ( AsyncTryCatch.NextGenEvents ) | ||
@@ -373,23 +392,4 @@ { | ||
/* | ||
AsyncTryCatch.Error = function Error( message ) | ||
{ | ||
global.Vanilla.Error.call( this ) ; | ||
global.Vanilla.Error.captureStackTrace && global.Vanilla.Error.captureStackTrace( this , this.constructor ) ; // jshint ignore:line | ||
Object.defineProperties( this , { | ||
message: { value: message , writable: true } , | ||
id: { value: '' + Math.floor( Math.random( 1000000 ) ) } | ||
} ) ; | ||
} ; | ||
AsyncTryCatch.Error.prototype = Object.create( global.Vanilla.Error.prototype ) ; | ||
AsyncTryCatch.Error.prototype.constructor = AsyncTryCatch.Error ; | ||
*/ | ||
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{"_process":3,"events":2,"nextgen-events":2}],2:[function(require,module,exports){ | ||
},{"../package.json":4,"_process":3,"events":2,"nextgen-events":2}],2:[function(require,module,exports){ | ||
@@ -492,3 +492,47 @@ },{}],3:[function(require,module,exports){ | ||
},{}],4:[function(require,module,exports){ | ||
module.exports={ | ||
"name": "async-try-catch", | ||
"version": "0.2.1", | ||
"description": "Async try catch", | ||
"main": "lib/AsyncTryCatch.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"browserify": "^13.0.1", | ||
"expect.js": "^0.3.1", | ||
"jshint": "^2.9.2", | ||
"mocha": "^2.5.3", | ||
"nextgen-events": "^0.5.16", | ||
"uglify-js": "^2.6.2" | ||
}, | ||
"scripts": { | ||
"test": "mocha -R dot" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/cronvel/async-try-catch.git" | ||
}, | ||
"keywords": [ | ||
"async", | ||
"try", | ||
"catch" | ||
], | ||
"author": "Cédric Ronvel", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/cronvel/async-try-catch/issues" | ||
}, | ||
"copyright": { | ||
"title": "Async Try-Catch", | ||
"years": [ | ||
2015, | ||
2016 | ||
], | ||
"owner": "Cédric Ronvel" | ||
} | ||
} | ||
},{}]},{},[1])(1) | ||
}); |
@@ -1,1 +0,1 @@ | ||
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.AsyncTryCatch=e()}})(function(){var e,t,n;return function r(e,t,n){function i(s,a){if(!t[s]){if(!e[s]){var c=typeof require=="function"&&require;if(!a&&c)return c(s,!0);if(o)return o(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var d=t[s]={exports:{}};e[s][0].call(d.exports,function(t){var n=e[s][1][t];return i(n?n:t)},d,d.exports,r,e,t,n)}return t[s].exports}var o=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i}({1:[function(e,t,n){(function(n,r){"use strict";function i(){throw new Error("Use AsyncTryCatch.try() instead.")}t.exports=i;r.AsyncTryCatch=i;if(n.browser&&!r.setImmediate){r.setImmediate=function o(e){return setTimeout(e,0)};r.clearImmediate=function s(e){return clearTimeout(e)}}if(!r.Vanilla){r.Vanilla={};if(!r.Vanilla.setTimeout){r.Vanilla.setTimeout=setTimeout}if(!r.Vanilla.setImmediate){r.Vanilla.setImmediate=setImmediate}if(!r.Vanilla.nextTick){r.Vanilla.nextTick=n.nextTick}}i.stack=[];i.substituted=false;i.try=function a(e){var t=Object.create(i.prototype,{fn:{value:e,enumerable:true},parent:{value:i.stack[i.stack.length-1]}});return t};i.prototype.catch=function c(e){Object.defineProperties(this,{catchFn:{value:e,enumerable:true}});if(!i.substituted){i.substitute()}try{i.stack.push(this);this.fn();i.stack.pop()}catch(t){i.stack.pop();this.callCatchFn(t)}};i.prototype.callCatchFn=function p(e){if(!this.parent){this.catchFn(e);return}try{i.stack.push(this.parent);this.catchFn(e);i.stack.pop()}catch(e){i.stack.pop();this.parent.callCatchFn(e)}};i.timerWrapper=function d(e,t){var t,n,r,o=Array.prototype.slice.call(arguments,1);if(typeof t!=="function"||!i.stack.length){return e.apply(this,o)}n=i.stack[i.stack.length-1];r=function(){try{i.stack.push(n);t.apply(this,arguments);i.stack.pop()}catch(e){i.stack.pop();n.callCatchFn(e)}};o[0]=r;return e.apply(this,o)};i.addListenerWrapper=function f(e,t,n,r){var n,o,s;if(typeof n==="object"){r=n;n=r.fn;delete r.fn}if(typeof n!=="function"||!i.stack.length){return e.call(this,t,n,r)}o=i.stack[i.stack.length-1];if(this.__fnToWrapperMap){s=this.__fnToWrapperMap.get(n)}else{Object.defineProperty(this,"__fnToWrapperMap",{value:new WeakMap})}if(!s){s=function(){try{i.stack.push(o);n.apply(this,arguments);i.stack.pop()}catch(e){i.stack.pop();o.callCatchFn(e)}};this.__fnToWrapperMap.set(n,s)}return e.call(this,t,s,r)};i.removeListenerWrapper=function l(e,t,n){if(typeof n==="function"&&this.__fnToWrapperMap){n=this.__fnToWrapperMap.get(n)||n}return e.call(this,t,n)};i.setTimeout=i.timerWrapper.bind(undefined,r.Vanilla.setTimeout);i.setImmediate=i.timerWrapper.bind(undefined,r.Vanilla.setImmediate);i.nextTick=i.timerWrapper.bind(n,r.Vanilla.nextTick);i.addListener=function u(e,t){i.addListenerWrapper.call(this,i.NodeEvents.__addListener,e,t)};i.addListenerOnce=function v(e,t){try{i.addListenerWrapper.call(this,i.NodeEvents.__addListenerOnce,e,t)}catch(n){console.log(i.NodeEvents);console.log(i.NodeEvents.__addListenerOnce);throw n}};i.removeListener=function h(e,t){i.removeListenerWrapper.call(this,i.NodeEvents.__removeListener,e,t)};i.ngevAddListener=function m(e,t,n){i.addListenerWrapper.call(this,i.NextGenEvents.on,e,t,n)};i.ngevAddListenerOnce=function y(e,t,n){i.addListenerWrapper.call(this,i.NextGenEvents.once,e,t,n)};i.ngevRemoveListener=function E(e,t){i.removeListenerWrapper.call(this,i.NextGenEvents.off,e,t)};i.substitute=function N(){i.substituted=true;r.setTimeout=i.setTimeout;r.setImmediate=i.setTimeout;n.nextTick=i.nextTick;try{i.NodeEvents=r.EventEmitter||e("events")}catch(t){}try{i.NextGenEvents=r.NextGenEvents||e("nextgen-events")}catch(t){}if(i.NodeEvents){if(!i.NodeEvents.__addListener){i.NodeEvents.__addListener=i.NodeEvents.prototype.on}if(!i.NodeEvents.__addListenerOnce){i.NodeEvents.__addListenerOnce=i.NodeEvents.prototype.once}if(!i.NodeEvents.__removeListener){i.NodeEvents.__removeListener=i.NodeEvents.prototype.removeListener}i.NodeEvents.prototype.on=i.addListener;i.NodeEvents.prototype.addListener=i.addListener;i.NodeEvents.prototype.once=i.addListenerOnce;i.NodeEvents.prototype.removeListener=i.removeListener}if(i.NextGenEvents){i.NextGenEvents.prototype.on=i.ngevAddListener;i.NextGenEvents.prototype.addListener=i.ngevAddListener;i.NextGenEvents.prototype.once=i.ngevAddListenerOnce;i.NextGenEvents.prototype.off=i.ngevRemoveListener;i.NextGenEvents.prototype.removeListener=i.ngevRemoveListener}};i.restore=function L(){i.substituted=false;r.setTimeout=r.Vanilla.setTimeout;r.setImmediate=r.Vanilla.setImmediate;n.nextTick=r.Vanilla.nextTick;if(i.NodeEvents){i.NodeEvents.prototype.on=i.NodeEvents.__addListener;i.NodeEvents.prototype.addListener=i.NodeEvents.__addListener;i.NodeEvents.prototype.once=i.NodeEvents.__addListenerOnce;i.NodeEvents.prototype.removeListener=i.NodeEvents.__removeListener}if(i.NextGenEvents){i.NextGenEvents.prototype.on=i.NextGenEvents.on;i.NextGenEvents.prototype.addListener=i.NextGenEvents.on;i.NextGenEvents.prototype.once=i.NextGenEvents.once;i.NextGenEvents.prototype.off=i.NextGenEvents.off;i.NextGenEvents.prototype.removeListener=i.NextGenEvents.removeListener}}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{_process:3,events:2,"nextgen-events":2}],2:[function(e,t,n){},{}],3:[function(e,t,n){var r=t.exports={};var i=[];var o=false;var s;var a=-1;function c(){if(!o||!s){return}o=false;if(s.length){i=s.concat(i)}else{a=-1}if(i.length){p()}}function p(){if(o){return}var e=setTimeout(c);o=true;var t=i.length;while(t){s=i;i=[];while(++a<t){if(s){s[a].run()}}a=-1;t=i.length}s=null;o=false;clearTimeout(e)}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1){for(var n=1;n<arguments.length;n++){t[n-1]=arguments[n]}}i.push(new d(e,t));if(i.length===1&&!o){setTimeout(p,0)}};function d(e,t){this.fun=e;this.array=t}d.prototype.run=function(){this.fun.apply(null,this.array)};r.title="browser";r.browser=true;r.env={};r.argv=[];r.version="";r.versions={};function f(){}r.on=f;r.addListener=f;r.once=f;r.off=f;r.removeListener=f;r.removeAllListeners=f;r.emit=f;r.binding=function(e){throw new Error("process.binding is not supported")};r.cwd=function(){return"/"};r.chdir=function(e){throw new Error("process.chdir is not supported")};r.umask=function(){return 0}},{}]},{},[1])(1)}); | ||
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.AsyncTryCatch=e()}})(function(){var e,t,n;return function r(e,t,n){function s(i,a){if(!t[i]){if(!e[i]){var c=typeof require=="function"&&require;if(!a&&c)return c(i,!0);if(o)return o(i,!0);var p=new Error("Cannot find module '"+i+"'");throw p.code="MODULE_NOT_FOUND",p}var y=t[i]={exports:{}};e[i][0].call(y.exports,function(t){var n=e[i][1][t];return s(n?n:t)},y,y.exports,r,e,t,n)}return t[i].exports}var o=typeof require=="function"&&require;for(var i=0;i<n.length;i++)s(n[i]);return s}({1:[function(e,t,n){(function(n,r){"use strict";function s(){throw new Error("Use AsyncTryCatch.try() instead.")}t.exports=s;s.prototype.__prototypeUID__="async-try-catch/AsyncTryCatch";s.prototype.__prototypeVersion__=e("../package.json").version;if(r.AsyncTryCatch){if(r.AsyncTryCatch.prototype.__prototypeUID__==="async-try-catch/AsyncTryCatch"){var o=s.prototype.__prototypeVersion__.split(".");var i=r.AsyncTryCatch.prototype.__prototypeVersion__.split(".");if(i[0]!==o[0]||o[0]==="0"&&i[1]!==o[1]){throw new Error("Incompatible version of AsyncTryCatch already installed on global.AsyncTryCatch: "+r.AsyncTryCatch.prototype.__prototypeVersion__+", current version: "+s.prototype.__prototypeVersion__)}}else{throw new Error("Incompatible module already installed on global.AsyncTryCatch")}}else{r.AsyncTryCatch=s;r.AsyncTryCatch.stack=[];r.AsyncTryCatch.substituted=false}if(n.browser&&!r.setImmediate){r.setImmediate=function a(e){return setTimeout(e,0)};r.clearImmediate=function c(e){return clearTimeout(e)}}if(!r.Vanilla){r.Vanilla={}}if(!r.Vanilla.setTimeout){r.Vanilla.setTimeout=setTimeout}if(!r.Vanilla.setImmediate){r.Vanilla.setImmediate=setImmediate}if(!r.Vanilla.nextTick){r.Vanilla.nextTick=n.nextTick}s.try=function p(e){var t=Object.create(s.prototype,{fn:{value:e,enumerable:true},parent:{value:r.AsyncTryCatch.stack[r.AsyncTryCatch.stack.length-1]}});return t};s.prototype.catch=function y(e){Object.defineProperties(this,{catchFn:{value:e,enumerable:true}});if(!r.AsyncTryCatch.substituted){s.substitute()}try{r.AsyncTryCatch.stack.push(this);this.fn();r.AsyncTryCatch.stack.pop()}catch(t){r.AsyncTryCatch.stack.pop();this.callCatchFn(t)}};s.prototype.callCatchFn=function d(e){if(!this.parent){this.catchFn(e);return}try{r.AsyncTryCatch.stack.push(this.parent);this.catchFn(e);r.AsyncTryCatch.stack.pop()}catch(e){r.AsyncTryCatch.stack.pop();this.parent.callCatchFn(e)}};s.timerWrapper=function l(e,t){var t,n,s,o=Array.prototype.slice.call(arguments,1);if(typeof t!=="function"||!r.AsyncTryCatch.stack.length){return e.apply(this,o)}n=r.AsyncTryCatch.stack[r.AsyncTryCatch.stack.length-1];s=function(){try{r.AsyncTryCatch.stack.push(n);t.apply(this,arguments);r.AsyncTryCatch.stack.pop()}catch(e){r.AsyncTryCatch.stack.pop();n.callCatchFn(e)}};o[0]=s;return e.apply(this,o)};s.addListenerWrapper=function f(e,t,n,s){var n,o,i;if(typeof n==="object"){s=n;n=s.fn;delete s.fn}if(typeof n!=="function"||!r.AsyncTryCatch.stack.length){return e.call(this,t,n,s)}o=r.AsyncTryCatch.stack[r.AsyncTryCatch.stack.length-1];if(this.__fnToWrapperMap){i=this.__fnToWrapperMap.get(n)}else{Object.defineProperty(this,"__fnToWrapperMap",{value:new WeakMap})}if(!i){i=function(){try{r.AsyncTryCatch.stack.push(o);n.apply(this,arguments);r.AsyncTryCatch.stack.pop()}catch(e){r.AsyncTryCatch.stack.pop();o.callCatchFn(e)}};this.__fnToWrapperMap.set(n,i)}return e.call(this,t,i,s)};s.removeListenerWrapper=function u(e,t,n){if(typeof n==="function"&&this.__fnToWrapperMap){n=this.__fnToWrapperMap.get(n)||n}return e.call(this,t,n)};s.setTimeout=s.timerWrapper.bind(undefined,r.Vanilla.setTimeout);s.setImmediate=s.timerWrapper.bind(undefined,r.Vanilla.setImmediate);s.nextTick=s.timerWrapper.bind(n,r.Vanilla.nextTick);s.addListener=function h(e,t){s.addListenerWrapper.call(this,s.NodeEvents.__addListener,e,t)};s.addListenerOnce=function v(e,t){s.addListenerWrapper.call(this,s.NodeEvents.__addListenerOnce,e,t)};s.removeListener=function m(e,t){s.removeListenerWrapper.call(this,s.NodeEvents.__removeListener,e,t)};s.ngevAddListener=function T(e,t,n){s.addListenerWrapper.call(this,s.NextGenEvents.on,e,t,n)};s.ngevAddListenerOnce=function _(e,t,n){s.addListenerWrapper.call(this,s.NextGenEvents.once,e,t,n)};s.ngevRemoveListener=function E(e,t){s.removeListenerWrapper.call(this,s.NextGenEvents.off,e,t)};s.substitute=function N(){r.AsyncTryCatch.substituted=true;r.setTimeout=s.setTimeout;r.setImmediate=s.setTimeout;n.nextTick=s.nextTick;try{s.NodeEvents=r.EventEmitter||e("events")}catch(t){}try{s.NextGenEvents=r.NextGenEvents||e("nextgen-events")}catch(t){}if(s.NodeEvents){if(!s.NodeEvents.__addListener){s.NodeEvents.__addListener=s.NodeEvents.prototype.on}if(!s.NodeEvents.__addListenerOnce){s.NodeEvents.__addListenerOnce=s.NodeEvents.prototype.once}if(!s.NodeEvents.__removeListener){s.NodeEvents.__removeListener=s.NodeEvents.prototype.removeListener}s.NodeEvents.prototype.on=s.addListener;s.NodeEvents.prototype.addListener=s.addListener;s.NodeEvents.prototype.once=s.addListenerOnce;s.NodeEvents.prototype.removeListener=s.removeListener}if(s.NextGenEvents){s.NextGenEvents.prototype.on=s.ngevAddListener;s.NextGenEvents.prototype.addListener=s.ngevAddListener;s.NextGenEvents.prototype.once=s.ngevAddListenerOnce;s.NextGenEvents.prototype.off=s.ngevRemoveListener;s.NextGenEvents.prototype.removeListener=s.ngevRemoveListener}};s.restore=function L(){r.AsyncTryCatch.substituted=false;r.setTimeout=r.Vanilla.setTimeout;r.setImmediate=r.Vanilla.setImmediate;n.nextTick=r.Vanilla.nextTick;if(s.NodeEvents){s.NodeEvents.prototype.on=s.NodeEvents.__addListener;s.NodeEvents.prototype.addListener=s.NodeEvents.__addListener;s.NodeEvents.prototype.once=s.NodeEvents.__addListenerOnce;s.NodeEvents.prototype.removeListener=s.NodeEvents.__removeListener}if(s.NextGenEvents){s.NextGenEvents.prototype.on=s.NextGenEvents.on;s.NextGenEvents.prototype.addListener=s.NextGenEvents.on;s.NextGenEvents.prototype.once=s.NextGenEvents.once;s.NextGenEvents.prototype.off=s.NextGenEvents.off;s.NextGenEvents.prototype.removeListener=s.NextGenEvents.removeListener}}}).call(this,e("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"../package.json":4,_process:3,events:2,"nextgen-events":2}],2:[function(e,t,n){},{}],3:[function(e,t,n){var r=t.exports={};var s=[];var o=false;var i;var a=-1;function c(){if(!o||!i){return}o=false;if(i.length){s=i.concat(s)}else{a=-1}if(s.length){p()}}function p(){if(o){return}var e=setTimeout(c);o=true;var t=s.length;while(t){i=s;s=[];while(++a<t){if(i){i[a].run()}}a=-1;t=s.length}i=null;o=false;clearTimeout(e)}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1){for(var n=1;n<arguments.length;n++){t[n-1]=arguments[n]}}s.push(new y(e,t));if(s.length===1&&!o){setTimeout(p,0)}};function y(e,t){this.fun=e;this.array=t}y.prototype.run=function(){this.fun.apply(null,this.array)};r.title="browser";r.browser=true;r.env={};r.argv=[];r.version="";r.versions={};function d(){}r.on=d;r.addListener=d;r.once=d;r.off=d;r.removeListener=d;r.removeAllListeners=d;r.emit=d;r.binding=function(e){throw new Error("process.binding is not supported")};r.cwd=function(){return"/"};r.chdir=function(e){throw new Error("process.chdir is not supported")};r.umask=function(){return 0}},{}],4:[function(e,t,n){t.exports={name:"async-try-catch",version:"0.2.1",description:"Async try catch",main:"lib/AsyncTryCatch.js",directories:{test:"test"},dependencies:{},devDependencies:{browserify:"^13.0.1","expect.js":"^0.3.1",jshint:"^2.9.2",mocha:"^2.5.3","nextgen-events":"^0.5.16","uglify-js":"^2.6.2"},scripts:{test:"mocha -R dot"},repository:{type:"git",url:"https://github.com/cronvel/async-try-catch.git"},keywords:["async","try","catch"],author:"Cédric Ronvel",license:"MIT",bugs:{url:"https://github.com/cronvel/async-try-catch/issues"},copyright:{title:"Async Try-Catch",years:[2015,2016],owner:"Cédric Ronvel"}}},{}]},{},[1])(1)}); |
@@ -33,6 +33,44 @@ /* | ||
module.exports = AsyncTryCatch ; | ||
global.AsyncTryCatch = AsyncTryCatch ; | ||
AsyncTryCatch.prototype.__prototypeUID__ = 'async-try-catch/AsyncTryCatch' ; | ||
AsyncTryCatch.prototype.__prototypeVersion__ = require( '../package.json' ).version ; | ||
if ( global.AsyncTryCatch ) | ||
{ | ||
if ( global.AsyncTryCatch.prototype.__prototypeUID__ === 'async-try-catch/AsyncTryCatch' ) | ||
{ | ||
//console.log( "Already installed:" , global.AsyncTryCatch.prototype.__prototypeVersion__ , "current:" , AsyncTryCatch.prototype.__prototypeVersion__ ) ; | ||
var currentVersions = AsyncTryCatch.prototype.__prototypeVersion__.split( '.' ) ; | ||
var installedVersions = global.AsyncTryCatch.prototype.__prototypeVersion__.split( '.' ) ; | ||
// Basic semver comparison | ||
if ( | ||
installedVersions[ 0 ] !== currentVersions[ 0 ] || | ||
( currentVersions[ 0 ] === "0" && installedVersions[ 1 ] !== currentVersions[ 1 ] ) | ||
) | ||
{ | ||
throw new Error( | ||
"Incompatible version of AsyncTryCatch already installed on global.AsyncTryCatch: " + | ||
global.AsyncTryCatch.prototype.__prototypeVersion__ + | ||
", current version: " + AsyncTryCatch.prototype.__prototypeVersion__ | ||
) ; | ||
} | ||
//global.AsyncTryCatch = AsyncTryCatch ; | ||
} | ||
else | ||
{ | ||
throw new Error( "Incompatible module already installed on global.AsyncTryCatch" ) ; | ||
} | ||
} | ||
else | ||
{ | ||
global.AsyncTryCatch = AsyncTryCatch ; | ||
global.AsyncTryCatch.stack = [] ; | ||
global.AsyncTryCatch.substituted = false ; | ||
} | ||
if ( process.browser && ! global.setImmediate ) | ||
@@ -46,17 +84,9 @@ { | ||
if ( ! global.Vanilla ) | ||
{ | ||
global.Vanilla = {} ; | ||
if ( ! global.Vanilla.setTimeout ) { global.Vanilla.setTimeout = setTimeout ; } | ||
if ( ! global.Vanilla.setImmediate ) { global.Vanilla.setImmediate = setImmediate ; } | ||
if ( ! global.Vanilla.nextTick ) { global.Vanilla.nextTick = process.nextTick ; } | ||
//if ( ! global.Vanilla.Error ) { global.Vanilla.Error = Error ; } | ||
} | ||
if ( ! global.Vanilla ) { global.Vanilla = {} ; } | ||
if ( ! global.Vanilla.setTimeout ) { global.Vanilla.setTimeout = setTimeout ; } | ||
if ( ! global.Vanilla.setImmediate ) { global.Vanilla.setImmediate = setImmediate ; } | ||
if ( ! global.Vanilla.nextTick ) { global.Vanilla.nextTick = process.nextTick ; } | ||
AsyncTryCatch.stack = [] ; | ||
AsyncTryCatch.substituted = false ; | ||
AsyncTryCatch.try = function try_( fn ) | ||
@@ -66,3 +96,3 @@ { | ||
fn: { value: fn , enumerable: true } , | ||
parent: { value: AsyncTryCatch.stack[ AsyncTryCatch.stack.length - 1 ] } | ||
parent: { value: global.AsyncTryCatch.stack[ global.AsyncTryCatch.stack.length - 1 ] } | ||
} ) ; | ||
@@ -81,11 +111,11 @@ | ||
if ( ! AsyncTryCatch.substituted ) { AsyncTryCatch.substitute() ; } | ||
if ( ! global.AsyncTryCatch.substituted ) { AsyncTryCatch.substitute() ; } | ||
try { | ||
AsyncTryCatch.stack.push( this ) ; | ||
global.AsyncTryCatch.stack.push( this ) ; | ||
this.fn() ; | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
} | ||
catch ( error ) { | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
this.callCatchFn( error ) ; | ||
@@ -108,8 +138,8 @@ } | ||
try { | ||
AsyncTryCatch.stack.push( this.parent ) ; | ||
global.AsyncTryCatch.stack.push( this.parent ) ; | ||
this.catchFn( error ) ; | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
} | ||
catch ( error ) { | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
this.parent.callCatchFn( error ) ; | ||
@@ -127,3 +157,3 @@ } | ||
if ( typeof fn !== 'function' || ! AsyncTryCatch.stack.length ) | ||
if ( typeof fn !== 'function' || ! global.AsyncTryCatch.stack.length ) | ||
{ | ||
@@ -133,12 +163,12 @@ return originalMethod.apply( this , args ) ; | ||
context = AsyncTryCatch.stack[ AsyncTryCatch.stack.length - 1 ] ; | ||
context = global.AsyncTryCatch.stack[ global.AsyncTryCatch.stack.length - 1 ] ; | ||
wrapperFn = function() { | ||
try { | ||
AsyncTryCatch.stack.push( context ) ; | ||
global.AsyncTryCatch.stack.push( context ) ; | ||
fn.apply( this , arguments ) ; | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
} | ||
catch ( error ) { | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
context.callCatchFn( error ) ; | ||
@@ -168,3 +198,3 @@ } | ||
if ( typeof fn !== 'function' || ! AsyncTryCatch.stack.length ) | ||
if ( typeof fn !== 'function' || ! global.AsyncTryCatch.stack.length ) | ||
{ | ||
@@ -174,3 +204,3 @@ return originalMethod.call( this , eventName , fn , options ) ; | ||
context = AsyncTryCatch.stack[ AsyncTryCatch.stack.length - 1 ] ; | ||
context = global.AsyncTryCatch.stack[ global.AsyncTryCatch.stack.length - 1 ] ; | ||
@@ -192,8 +222,8 @@ // Assume that the function is only wrapped once per eventEmitter | ||
try { | ||
AsyncTryCatch.stack.push( context ) ; | ||
global.AsyncTryCatch.stack.push( context ) ; | ||
fn.apply( this , arguments ) ; | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
} | ||
catch ( error ) { | ||
AsyncTryCatch.stack.pop() ; | ||
global.AsyncTryCatch.stack.pop() ; | ||
context.callCatchFn( error ) ; | ||
@@ -238,9 +268,3 @@ } | ||
{ | ||
try { | ||
AsyncTryCatch.addListenerWrapper.call( this , AsyncTryCatch.NodeEvents.__addListenerOnce , eventName , fn ) ; | ||
} catch ( error ) { | ||
console.log( AsyncTryCatch.NodeEvents ) ; | ||
console.log( AsyncTryCatch.NodeEvents.__addListenerOnce ) ; | ||
throw error ; | ||
} | ||
} ; | ||
@@ -279,4 +303,4 @@ | ||
//if ( AsyncTryCatch.substituted ) { return ; } | ||
AsyncTryCatch.substituted = true ; | ||
//if ( global.AsyncTryCatch.substituted ) { return ; } | ||
global.AsyncTryCatch.substituted = true ; | ||
@@ -319,5 +343,2 @@ global.setTimeout = AsyncTryCatch.setTimeout ; | ||
//global.Error = AsyncTryCatch.Error ; | ||
// Should do that for all error types, cause they will not inherit from the substituted constructor | ||
if ( AsyncTryCatch.NextGenEvents ) | ||
@@ -340,4 +361,4 @@ { | ||
//if ( ! AsyncTryCatch.substituted ) { return ; } | ||
AsyncTryCatch.substituted = false ; | ||
//if ( ! global.AsyncTryCatch.substituted ) { return ; } | ||
global.AsyncTryCatch.substituted = false ; | ||
@@ -356,4 +377,2 @@ global.setTimeout = global.Vanilla.setTimeout ; | ||
//global.Error = global.Vanilla.Error ; | ||
if ( AsyncTryCatch.NextGenEvents ) | ||
@@ -370,20 +389,1 @@ { | ||
/* | ||
AsyncTryCatch.Error = function Error( message ) | ||
{ | ||
global.Vanilla.Error.call( this ) ; | ||
global.Vanilla.Error.captureStackTrace && global.Vanilla.Error.captureStackTrace( this , this.constructor ) ; // jshint ignore:line | ||
Object.defineProperties( this , { | ||
message: { value: message , writable: true } , | ||
id: { value: '' + Math.floor( Math.random( 1000000 ) ) } | ||
} ) ; | ||
} ; | ||
AsyncTryCatch.Error.prototype = Object.create( global.Vanilla.Error.prototype ) ; | ||
AsyncTryCatch.Error.prototype.constructor = AsyncTryCatch.Error ; | ||
*/ | ||
{ | ||
"name": "async-try-catch", | ||
"version": "0.1.7", | ||
"version": "0.2.1", | ||
"description": "Async try catch", | ||
@@ -5,0 +5,0 @@ "main": "lib/AsyncTryCatch.js", |
@@ -58,6 +58,6 @@ /* | ||
asyncTry( function() { | ||
asyncTry( function syncTry() { | ||
throw new Error( 'sync error' ) ; | ||
} ) | ||
.catch( function( error ) { | ||
.catch( function syncCatch( error ) { | ||
expect( error.message ).to.be( 'sync error' ) ; | ||
@@ -69,7 +69,7 @@ } ) ; | ||
asyncTry( function() { | ||
asyncTry( function() { | ||
asyncTry( function syncNestedOuterTry() { | ||
asyncTry( function syncNestedInnerTry() { | ||
throw new Error( 'inner sync error' ) ; | ||
} ) | ||
.catch( function( error ) { | ||
.catch( function syncNestedInnerCatch( error ) { | ||
expect( error.message ).to.be( 'inner sync error' ) ; | ||
@@ -79,3 +79,3 @@ throw new Error( 're-throw sync error' ) ; | ||
} ) | ||
.catch( function( error ) { | ||
.catch( function syncNestedOuterCatch( error ) { | ||
expect( error.message ).to.be( 're-throw sync error' ) ; | ||
@@ -92,8 +92,8 @@ } ) ; | ||
asyncTry( function() { | ||
setTimeout( function() { | ||
asyncTry( function setTimeoutTry() { | ||
setTimeout( function setTimeoutTimeout() { | ||
throw new Error( 'setTimeout error' ) ; | ||
} , 0 ) ; | ||
} ) | ||
.catch( function( error ) { | ||
.catch( function setTimeoutCatch( error ) { | ||
expect( error.message ).to.be( 'setTimeout error' ) ; | ||
@@ -100,0 +100,0 @@ done() ; |
Sorry, the diff of this file is not supported yet
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
303622
5514