Comparing version 0.12.4 to 0.12.5
/* | ||
Yaku v0.12.4 | ||
Yaku v0.12.5 | ||
(c) 2015 Yad Smood. http://ysmood.org | ||
@@ -9,3 +9,4 @@ License MIT | ||
var $nil | ||
var $undefined | ||
, $null = null | ||
, root = typeof global === "object" ? global : window | ||
@@ -24,5 +25,7 @@ , isLongStackTrace = false | ||
, $invalid_this = "invalid_this" | ||
, $invalid_argument = "invalid_argument" | ||
, $invalidThis = "Invalid this" | ||
, $invalidArgument = "Invalid argument" | ||
, $fromPrevious = "From previous event:" | ||
, $promiseCircularChain = "Chaining cycle detected for promise" | ||
, $unhandledRejectionMsg = "Uncaught (in promise)" | ||
, $unhandledRejection = "unhandledRejection"; | ||
@@ -42,4 +45,4 @@ | ||
if (!isYaku(self) || self._state !== $nil) | ||
throw genTypeError($invalid_this); | ||
if (!isYaku(self) || self._state !== $undefined) | ||
throw genTypeError($invalidThis); | ||
@@ -52,3 +55,3 @@ self._state = $pending; | ||
if (!isFunction(executor)) | ||
throw genTypeError($invalid_argument); | ||
throw genTypeError($invalidArgument); | ||
@@ -65,3 +68,3 @@ err = genTryCatcher(executor)( | ||
Yaku.default = Yaku; | ||
Yaku["default"] = Yaku; | ||
@@ -89,3 +92,3 @@ extendPrototype(Yaku, { | ||
this, | ||
newEmptyPromise(this.constructor), | ||
newEmptyPromise(Yaku.speciesConstructor(this, Yaku)), | ||
onFulfilled, | ||
@@ -113,3 +116,3 @@ onRejected | ||
"catch": function (onRejected) { | ||
return this.then($nil, onRejected); | ||
return this.then($undefined, onRejected); | ||
}, | ||
@@ -121,3 +124,3 @@ | ||
// The parent Yaku. | ||
_pre: null, | ||
_pre: $null, | ||
@@ -294,2 +297,10 @@ // A unique type flag, it helps different versions of Yaku know each other. | ||
/** | ||
* Use this api to custom the species behavior. | ||
* https://tc39.github.io/ecma262/#sec-speciesconstructor | ||
* @param {Any} O The current this object. | ||
* @param {Function} defaultConstructor | ||
*/ | ||
Yaku.speciesConstructor = function (O, D) { return O.constructor || D; }; | ||
/** | ||
* Catch all possibly unhandled rejections. If you want to use specific | ||
@@ -318,3 +329,3 @@ * format to display the error stack, overwrite it. | ||
var info = genStackInfo(reason, p); | ||
con.error($unhandledRejection, info[0], info[1] || ""); | ||
con.error($unhandledRejectionMsg, info[0], info[1] || ""); | ||
} | ||
@@ -375,3 +386,3 @@ }; | ||
, $tryCatchThis | ||
, $tryErr = { e: null } | ||
, $tryErr = { e: $null } | ||
, $noop = function () {}; | ||
@@ -454,4 +465,4 @@ | ||
fn(fnQueue[i], fnQueue[i + 1]); | ||
fnQueue[i++] = $nil; | ||
fnQueue[i++] = $nil; | ||
fnQueue[i++] = $undefined; | ||
fnQueue[i++] = $undefined; | ||
} | ||
@@ -489,3 +500,3 @@ | ||
return genTypeError($invalid_argument); | ||
return genTypeError($invalidArgument); | ||
} | ||
@@ -528,3 +539,3 @@ | ||
// 2.2.7.4 | ||
if (handler === $nil) { | ||
if (handler === $undefined) { | ||
settlePromise(p2, p1._state, p1._value); | ||
@@ -562,6 +573,6 @@ return; | ||
function newEmptyPromise (self) { | ||
if (!isYaku(self)) throw genTypeError($invalid_this); | ||
function newEmptyPromise (Self) { | ||
if (!isYaku(Self)) throw genTypeError($invalidThis); | ||
return new self($noop); | ||
return new Self($noop); | ||
} | ||
@@ -577,11 +588,13 @@ | ||
*/ | ||
function genSettler (self, state) { return function (value) { | ||
if (isLongStackTrace) | ||
self[$settlerTrace] = genTraceInfo(true); | ||
function genSettler (self, state) { | ||
return function (value) { | ||
if (isLongStackTrace) | ||
self[$settlerTrace] = genTraceInfo(true); | ||
if (state === $resolved) | ||
settleWithX(self, value); | ||
else | ||
settlePromise(self, state, value); | ||
}; } | ||
if (state === $resolved) | ||
settleWithX(self, value); | ||
else | ||
settlePromise(self, state, value); | ||
}; | ||
} | ||
@@ -734,3 +747,3 @@ /** | ||
if (x === p && x) { | ||
settlePromise(p, $rejected, genTypeError("promise_circular_chain")); | ||
settlePromise(p, $rejected, genTypeError($promiseCircularChain)); | ||
return p; | ||
@@ -741,3 +754,3 @@ } | ||
// 2.3.3 | ||
if (x != null && (isFunction(x) || isObject(x))) { | ||
if (x !== $null && (isFunction(x) || isObject(x))) { | ||
// 2.3.2.1 | ||
@@ -763,4 +776,3 @@ var xthen = genTryCatcher(getThen)(x); | ||
}); | ||
} | ||
else | ||
} else | ||
// 2.3.3.4 | ||
@@ -795,3 +807,3 @@ settlePromise(p, $resolved, x); | ||
if (x) { | ||
x = null; | ||
x = $null; | ||
@@ -804,3 +816,3 @@ // 2.3.3.3.1 | ||
if (x) { | ||
x = null; | ||
x = $null; | ||
@@ -816,3 +828,3 @@ // 2.3.3.3.2 | ||
settlePromise(p, $rejected, err.e); | ||
x = null; | ||
x = $null; | ||
} | ||
@@ -819,0 +831,0 @@ } |
{ | ||
"name": "yaku", | ||
"version": "0.12.4", | ||
"version": "0.12.5", | ||
"description": "A light-weight ES6 Promises/A+ implementation that doesn't hurt.", | ||
@@ -42,3 +42,5 @@ "main": "lib/yaku.js", | ||
"bluebird": "3.3.1", | ||
"core-js": "2.1.0", | ||
"es6-promise": "3.1.2", | ||
"es6-shim": "0.34.4", | ||
"eslint": "2.0.0", | ||
@@ -45,0 +47,0 @@ "junit": "1.1.3", |
@@ -24,3 +24,3 @@ <a href="http://promisesaplus.com/"> | ||
- The minified file is only 3.8KB (1.5KB gzipped) ([Bluebird][] / 73KB, [ES6-promise][] / 18KB) | ||
- The minified file is only 3.9KB (1.5KB gzipped) | ||
- [Better "possibly unhandled rejection" and "long stack trace"][docs/debugHelperComparison.md] than [Bluebird][] | ||
@@ -75,15 +75,32 @@ - Much better performance than the native Promise | ||
| Name | promises-es6-tests | 1ms async task / mem | Helpers | file size | | ||
| -------------------- | ------------------ | -------------------- | ------- | --------- | | ||
| Yaku v0.12 | ✓ | 247ms / 101mb | +++ | 3.8KB | | ||
| [Bluebird][] v3.3 | x | 166ms / 86mb | +++++++ | 73KB | | ||
| [ES6-promise][] v3.1 | x | 342ms / 104mb | + | 18KB | | ||
| [native][] v5.0 | x | 496ms / 166mb | + | 0KB | | ||
| [q][] v1.4 | x | 3109ms / 618mb | +++ | 24K | | ||
``` | ||
Node v5.6.0 | ||
OS darwin | ||
Arch x64 | ||
CPU Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz | ||
``` | ||
| name | unit tests | 1ms async task | optional helpers | helpers | min js | | ||
| ---- | ---------- | -------------- | ---------------- | ------- | ------ | | ||
| [yaku][]@0.11.6 | ✓ | 330ms / 106MB | ✓ | 29 | 3.8KB | | ||
| [bluebird][]@3.3.1 | x (18 failing) | 265ms / 88MB | partial | 100 | 52.2KB | | ||
| [es6-promise][]@3.1.2 | x (52 failing) | 426ms / 113MB | x | 10 | 6.3KB | | ||
| [native][]@0.12.4 | x ( 4 failing) | 590ms / 173MB | x | 13 | 0KB | | ||
| [core-js][]@2.1.0 | x ( 4 failing) | 838ms / 198MB | x | 11 | 13.9KB | | ||
| [es6-shim][]@0.34.4 | ✓ | 950ms / 145MB | x | 12 | 130.8KB | | ||
| [q][]@1.4.1 | x (47 failing) | 1599ms / 425MB | x | 74 | 15.4KB | | ||
- **Helpers**: extra methods that help with your promise programming, such as | ||
async flow control helpers, debug helpers. For more details: [docs/debugHelperComparison.md][]. | ||
- **1ms async task**: `npm run no -- benchmark`, the smaller the better. | ||
- **1ms async task**: `npm run no -- benchmark`, the smaller the better (total time / memory rss). | ||
- **promises-es6-tests**: If you want to test `bluebird` against promises-es6-tests, | ||
run `npm run no -- test-es6 --shim bluebird`. | ||
- **optional helpers**: Whether the helpers can be imported separately or not, | ||
which means you can load the lib without helpers. Such as the `bluebird-core`, it will inevitably load | ||
some nonstandard helpers: `spread`, `finally`, etc. | ||
# FAQ | ||
@@ -118,3 +135,3 @@ | ||
Yaku will report any unhandled rejection via `console.error` by default, in case you forget to write `catch`. | ||
You can catch with them manually: | ||
You can catch them manually: | ||
@@ -138,2 +155,3 @@ - Browser: `window.onunhandledrejection = ({ promise, reason }) => { /* Your Code */ };` | ||
- [Yaku.Symbol](#yakusymbol) | ||
- [Yaku.speciesConstructor(O, defaultConstructor)](#yakuspeciesconstructoro-defaultconstructor) | ||
- [Yaku.onUnhandledRejection(reason, p)](#yakuonunhandledrejectionreason-p) | ||
@@ -171,3 +189,3 @@ - [Yaku.enableLongStackTrace](#yakuenablelongstacktrace) | ||
- ### **[Yaku(executor)](src/yaku.js?source#L31)** | ||
- ### **[Yaku(executor)](src/yaku.js?source#L34)** | ||
@@ -184,3 +202,3 @@ This class follows the [Promises/A+](https://promisesaplus.com) and | ||
- ### **[then(onFulfilled, onRejected)](src/yaku.js?source#L76)** | ||
- ### **[then(onFulfilled, onRejected)](src/yaku.js?source#L79)** | ||
@@ -214,3 +232,3 @@ Appends fulfillment and rejection handlers to the promise, | ||
- ### **[catch(onRejected)](src/yaku.js?source#L101)** | ||
- ### **[catch(onRejected)](src/yaku.js?source#L104)** | ||
@@ -240,3 +258,3 @@ The `catch()` method returns a Promise and deals with rejected cases only. | ||
- ### **[Yaku.resolve(value)](src/yaku.js?source#L128)** | ||
- ### **[Yaku.resolve(value)](src/yaku.js?source#L131)** | ||
@@ -261,3 +279,3 @@ The `Promise.resolve(value)` method returns a Promise object that is resolved with the given value. | ||
- ### **[Yaku.reject(reason)](src/yaku.js?source#L142)** | ||
- ### **[Yaku.reject(reason)](src/yaku.js?source#L145)** | ||
@@ -279,3 +297,3 @@ The `Promise.reject(reason)` method returns a Promise object that is rejected with the given reason. | ||
- ### **[Yaku.race(iterable)](src/yaku.js?source#L166)** | ||
- ### **[Yaku.race(iterable)](src/yaku.js?source#L169)** | ||
@@ -309,3 +327,3 @@ The `Promise.race(iterable)` method returns a promise that resolves or rejects | ||
- ### **[Yaku.all(iterable)](src/yaku.js?source#L226)** | ||
- ### **[Yaku.all(iterable)](src/yaku.js?source#L229)** | ||
@@ -354,3 +372,3 @@ The `Promise.all(iterable)` method returns a promise that resolves when | ||
- ### **[Yaku.Symbol](src/yaku.js?source#L278)** | ||
- ### **[Yaku.Symbol](src/yaku.js?source#L281)** | ||
@@ -370,4 +388,15 @@ The ES6 Symbol object that Yaku should use, by default it will use the | ||
- ### **[Yaku.onUnhandledRejection(reason, p)](src/yaku.js?source#L300)** | ||
- ### **[Yaku.speciesConstructor(O, defaultConstructor)](src/yaku.js?source#L289)** | ||
Use this api to custom the species behavior. | ||
https://tc39.github.io/ecma262/#sec-speciesconstructor | ||
- **<u>param</u>**: `O` { _Any_ } | ||
The current this object. | ||
- **<u>param</u>**: `defaultConstructor` { _Function_ } | ||
- ### **[Yaku.onUnhandledRejection(reason, p)](src/yaku.js?source#L311)** | ||
Catch all possibly unhandled rejections. If you want to use specific | ||
@@ -400,3 +429,3 @@ format to display the error stack, overwrite it. | ||
- ### **[Yaku.enableLongStackTrace](src/yaku.js?source#L320)** | ||
- ### **[Yaku.enableLongStackTrace](src/yaku.js?source#L331)** | ||
@@ -416,3 +445,3 @@ It is used to enable the long stack trace. | ||
- ### **[Yaku.nextTick](src/yaku.js?source#L343)** | ||
- ### **[Yaku.nextTick](src/yaku.js?source#L354)** | ||
@@ -993,6 +1022,19 @@ Only Node has `process.nextTick` function. For browser there are | ||
Use `npm run no -- test` to run the unit test. | ||
Use `npm run no -- test` to run the unit test against yaku. | ||
## Test other libs | ||
### aplus test | ||
To test `bluebird`: `npm run no -- test-aplus --shim bluebird` | ||
The `bluebird` can be replaced with other lib, see the `test/getPromise.js` for which libs are supported. | ||
### es6 test | ||
To test `bluebird`: `npm run no -- test-es6 --shim bluebird` | ||
The `bluebird` can be replaced with other lib, see the `test/getPromise.js` for which libs are supported. | ||
# Benchmark | ||
@@ -1017,2 +1059,5 @@ | ||
[q]: https://github.com/kriskowal/q | ||
[core-js]: https://github.com/zloirock/core-js | ||
[yaku]: https://github.com/ysmood/yaku | ||
[es6-shim]: https://github.com/paulmillr/es6-shim | ||
[release page]: https://github.com/ysmood/yaku/releases | ||
@@ -1019,0 +1064,0 @@ [docs/minPromiseAplus.js]: docs/minPromiseAplus.js |
83537
1519
1055
14