Comparing version 0.12.5 to 0.13.0
/* | ||
Yaku v0.12.5 | ||
Yaku v0.13.0 | ||
(c) 2015 Yad Smood. http://ysmood.org | ||
@@ -13,2 +13,3 @@ License MIT | ||
, isLongStackTrace = false | ||
, process = root.process | ||
@@ -22,2 +23,3 @@ , $rejected = 0 | ||
, $unhandled = "_uh" | ||
, $promiseTrace = "_pt" | ||
@@ -31,4 +33,11 @@ , $settlerTrace = "_st" | ||
, $unhandledRejectionMsg = "Uncaught (in promise)" | ||
, $unhandledRejection = "unhandledRejection"; | ||
, $rejectionHandled = "rejectionHandled" | ||
, $unhandledRejection = "unhandledRejection" | ||
, $tryCatchFn | ||
, $tryCatchThis | ||
, $tryErr = { e: $null } | ||
, $noop = function () {} | ||
; | ||
/** | ||
@@ -319,3 +328,3 @@ * This class follows the [Promises/A+](https://promisesaplus.com) and | ||
*/ | ||
Yaku.onUnhandledRejection = function (reason, p) { | ||
Yaku.unhandledRejection = function (reason, p) { | ||
var con = root.console; | ||
@@ -329,2 +338,9 @@ if (con) { | ||
/** | ||
* Emitted whenever a Promise was rejected and an error handler was | ||
* attached to it (for example with .catch()) later than after an event loop turn. | ||
* @param {Yaku} p The handled promise. | ||
*/ | ||
Yaku.rejectionHandled = $noop; | ||
/** | ||
* It is used to enable the long stack trace. | ||
@@ -364,4 +380,4 @@ * Once it is enabled, it can't be reverted. | ||
*/ | ||
Yaku.nextTick = root.process ? | ||
root.process.nextTick : | ||
Yaku.nextTick = process ? | ||
process.nextTick : | ||
function (fn) { setTimeout(fn); }; | ||
@@ -380,7 +396,2 @@ | ||
var $tryCatchFn | ||
, $tryCatchThis | ||
, $tryErr = { e: $null } | ||
, $noop = function () {}; | ||
function extendPrototype (src, target) { | ||
@@ -551,15 +562,19 @@ for (var k in target) { | ||
if (!hashOnRejected(p)) { | ||
var process = root.process | ||
, onunhandledrejection = root.onunhandledrejection | ||
, reason = p._value; | ||
if (process && process.listeners($unhandledRejection).length) | ||
process.emit($unhandledRejection, reason, p); | ||
else if (onunhandledrejection) | ||
onunhandledrejection({ promise: p, reason: reason }); | ||
else | ||
Yaku.onUnhandledRejection(reason, p); | ||
p[$unhandled] = 1; | ||
emitEvent($unhandledRejection, p._value, p); | ||
} | ||
}); | ||
function emitEvent (name, arg1, arg2) { | ||
var browserEventName = "on" + name.toLowerCase() | ||
, browserHandler = root[browserEventName]; | ||
if (process && process.listeners(name).length) | ||
process.emit(name, arg1, arg2); | ||
else if (browserHandler) | ||
browserHandler({ reason: arg1, promise: arg2 }); | ||
else | ||
Yaku[name](arg1, arg2); | ||
} | ||
function isYaku (val) { return val && val._Yaku; } | ||
@@ -605,4 +620,7 @@ | ||
p2._onFulfilled = onFulfilled; | ||
if (isFunction(onRejected)) | ||
if (isFunction(onRejected)) { | ||
if (p1[$unhandled]) emitEvent($rejectionHandled, p1); | ||
p2._onRejected = onRejected; | ||
} | ||
@@ -609,0 +627,0 @@ if (isLongStackTrace) p2._pre = p1; |
{ | ||
"name": "yaku", | ||
"version": "0.12.5", | ||
"version": "0.13.0", | ||
"description": "A light-weight ES6 Promises/A+ implementation that doesn't hurt.", | ||
@@ -5,0 +5,0 @@ "main": "lib/yaku.js", |
@@ -24,3 +24,3 @@ <a href="http://promisesaplus.com/"> | ||
- The minified file is only 3.9KB (1.5KB gzipped) | ||
- The minified file is only 3.3KB (1.5KB gzipped) | ||
- [Better "possibly unhandled rejection" and "long stack trace"][docs/debugHelperComparison.md] than [Bluebird][] | ||
@@ -154,3 +154,4 @@ - Much better performance than the native Promise | ||
- [Yaku.speciesConstructor(O, defaultConstructor)](#yakuspeciesconstructoro-defaultconstructor) | ||
- [Yaku.onUnhandledRejection(reason, p)](#yakuonunhandledrejectionreason-p) | ||
- [Yaku.unhandledRejection(reason, p)](#yakuunhandledrejectionreason-p) | ||
- [Yaku.rejectionHandled(p)](#yakurejectionhandledp) | ||
- [Yaku.enableLongStackTrace](#yakuenablelongstacktrace) | ||
@@ -187,3 +188,3 @@ - [Yaku.nextTick](#yakunexttick) | ||
- ### **[Yaku(executor)](src/yaku.js?source#L34)** | ||
- ### **[Yaku(executor)](src/yaku.js?source#L43)** | ||
@@ -200,3 +201,3 @@ This class follows the [Promises/A+](https://promisesaplus.com) and | ||
- ### **[then(onFulfilled, onRejected)](src/yaku.js?source#L79)** | ||
- ### **[then(onFulfilled, onRejected)](src/yaku.js?source#L88)** | ||
@@ -230,3 +231,3 @@ Appends fulfillment and rejection handlers to the promise, | ||
- ### **[catch(onRejected)](src/yaku.js?source#L104)** | ||
- ### **[catch(onRejected)](src/yaku.js?source#L113)** | ||
@@ -256,3 +257,3 @@ The `catch()` method returns a Promise and deals with rejected cases only. | ||
- ### **[Yaku.resolve(value)](src/yaku.js?source#L131)** | ||
- ### **[Yaku.resolve(value)](src/yaku.js?source#L140)** | ||
@@ -277,3 +278,3 @@ The `Promise.resolve(value)` method returns a Promise object that is resolved with the given value. | ||
- ### **[Yaku.reject(reason)](src/yaku.js?source#L145)** | ||
- ### **[Yaku.reject(reason)](src/yaku.js?source#L154)** | ||
@@ -295,3 +296,3 @@ The `Promise.reject(reason)` method returns a Promise object that is rejected with the given reason. | ||
- ### **[Yaku.race(iterable)](src/yaku.js?source#L169)** | ||
- ### **[Yaku.race(iterable)](src/yaku.js?source#L178)** | ||
@@ -325,3 +326,3 @@ The `Promise.race(iterable)` method returns a promise that resolves or rejects | ||
- ### **[Yaku.all(iterable)](src/yaku.js?source#L229)** | ||
- ### **[Yaku.all(iterable)](src/yaku.js?source#L238)** | ||
@@ -370,3 +371,3 @@ The `Promise.all(iterable)` method returns a promise that resolves when | ||
- ### **[Yaku.Symbol](src/yaku.js?source#L281)** | ||
- ### **[Yaku.Symbol](src/yaku.js?source#L290)** | ||
@@ -386,3 +387,3 @@ The ES6 Symbol object that Yaku should use, by default it will use the | ||
- ### **[Yaku.speciesConstructor(O, defaultConstructor)](src/yaku.js?source#L289)** | ||
- ### **[Yaku.speciesConstructor(O, defaultConstructor)](src/yaku.js?source#L298)** | ||
@@ -398,3 +399,3 @@ Use this api to custom the species behavior. | ||
- ### **[Yaku.onUnhandledRejection(reason, p)](src/yaku.js?source#L311)** | ||
- ### **[Yaku.unhandledRejection(reason, p)](src/yaku.js?source#L320)** | ||
@@ -428,4 +429,13 @@ Catch all possibly unhandled rejections. If you want to use specific | ||
- ### **[Yaku.enableLongStackTrace](src/yaku.js?source#L331)** | ||
- ### **[Yaku.rejectionHandled(p)](src/yaku.js?source#L333)** | ||
Emitted whenever a Promise was rejected and an error handler was | ||
attached to it (for example with .catch()) later than after an event loop turn. | ||
- **<u>param</u>**: `p` { _Yaku_ } | ||
The handled promise. | ||
- ### **[Yaku.enableLongStackTrace](src/yaku.js?source#L347)** | ||
It is used to enable the long stack trace. | ||
@@ -444,3 +454,3 @@ Once it is enabled, it can't be reverted. | ||
- ### **[Yaku.nextTick](src/yaku.js?source#L354)** | ||
- ### **[Yaku.nextTick](src/yaku.js?source#L370)** | ||
@@ -447,0 +457,0 @@ Only Node has `process.nextTick` function. For browser there are |
84334
1534
1065