From a986b601d5132baae0345b6462da2b908405580e Mon Sep 17 00:00:00 2001
From: Petka Antonov
Date: Mon, 22 Dec 2014 00:43:39 +0200
Subject: [PATCH] Make browser testing more sensical
---
.gitignore | 2 +-
.travis.yml | 8 +-
Gruntfile.js | 18 +-
README.md | 5 +-
browser/bundle.js | 32492 ----------------------------------------
browser/bundler.js | 43 -
browser/do_run.js | 52 -
browser/index.html | 8 +-
browser/init_run.js | 21 -
browser/main.js | 130 +
browser/mocha.css | 158 +-
browser/mocha.js | 2781 +++-
browser/mocha_init.js | 7 -
browser/setup | 4 -
package.json | 5 +-
src/race.js | 3 +-
test/mocha/cancel.js | 12 +-
test/mocha/timers.js | 57 +-
18 files changed, 2407 insertions(+), 33399 deletions(-)
delete mode 100644 browser/bundle.js
delete mode 100644 browser/bundler.js
delete mode 100644 browser/do_run.js
delete mode 100644 browser/init_run.js
create mode 100644 browser/main.js
delete mode 100644 browser/mocha_init.js
delete mode 100644 browser/setup
diff --git a/.gitignore b/.gitignore
index e285ade6f..5c4abe416 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,9 +6,9 @@ benchmark/async-compare/node_modules/*
benchmark/promises-benchmark/node_modules/*
benchmark/promises-benchmark/fixtures/*
benchmark/perf-promises/node_modules/*
-browser/main.js
async
sync
+browser/bundle.js
mixed
bench.json
js/bluebird_sync.min.js
diff --git a/.travis.yml b/.travis.yml
index b6c37e5f9..713238953 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,7 @@
language: node_js
node_js:
- '0.10'
-install: 'npm install grunt grunt-contrib-jshint grunt-contrib-watch acorn q mocha sinon grunt-cli grunt-contrib-connect grunt-saucelabs mkdirp'
+install: 'npm install browserify grunt grunt-contrib-jshint grunt-contrib-watch acorn q mocha sinon grunt-cli grunt-contrib-connect grunt-saucelabs mkdirp'
before_script:
- git submodule update --init --recursive
-script: 'grunt test --ci && grunt test-browser --ci'
-env:
- global:
- - secure: lFeRife2Lr6vaiVAKjRg2VyTP8Gu+1z6i0JeQ4w6BfAbIkpAgFLOsyVH5QGlnmOLclBtMIHMcNGOCH3RfozVd26TPZMPslPCgh4zal0hCYQHE1n0Cpqsq/m7aA8WlhYd2RGx4A/zZaJ5ZVhUPLnpAAnEocslMsW4aRzkb3aJHIs=
- - secure: U4//Sr89P3kGimkmxRr7gqYRtvaoy4HQXtPIORAlIX1BPXxS4EJ63JCgbEtqNSnIZ0/ybjTlpT7AHcBkMUX7BWjQojTj4sEmUeYe4jorK8NVCpam3r99q5XhsdFzJ3t2R0pLiC4q9GyuTyUitJmZ4U7jHbrXkfh7UJ3FdqIECv4=
+script: 'grunt test --ci && npm run browsers && grunt test-browser --ci'
diff --git a/Gruntfile.js b/Gruntfile.js
index bb9610828..571b2a2b0 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -26,12 +26,11 @@ module.exports = function( grunt ) {
function getBrowsers() {
//Terse format to generate the verbose format required by sauce
var browsers = {
- "internet explorer|WIN8": ["10"],
- "internet explorer|WIN8.1": ["11"],
- "firefox|Windows 7": ["3.5", "4", "25"],
- "chrome|Windows 7": null,
- "safari|Windows 7": ["5"],
- "iphone|OS X 10.8": ["6.0"]
+ "internet explorer|Windows XP": ["7", "8"],
+ "internet explorer|Windows 7": ["9"],
+ "firefox|Windows 7": ["3.5", "4", "25", "33"],
+ "chrome|Windows 7": ["beta"],
+ "safari|Windows 7": ["5"]
};
var ret = [];
@@ -51,7 +50,7 @@ module.exports = function( grunt ) {
}
else {
ret.push({
- browserName: browser,
+ browserNAme: browser,
platform: platform
});
}
@@ -326,9 +325,10 @@ module.exports = function( grunt ) {
all: {
options: {
urls: ["http://127.0.0.1:9999/index.html"],
- tunnelTimeout: 5,
+ tunnelTimeout: 30,
build: process.env.TRAVIS_JOB_ID,
- concurrency: 3,
+ maxPollRetries: 3,
+ throttled: 3,
browsers: getBrowsers(),
testname: "mocha tests",
tags: ["master"]
diff --git a/README.md b/README.md
index 0884c481d..140410ebf 100644
--- a/README.md
+++ b/README.md
@@ -475,10 +475,9 @@ The reason for the unusual way of testing is because the majority of tests are f
To test in browsers:
- cd browser
- setup
+ npm run browsers
-Then open the `index.html` in your browser. Requires bash (on windows the mingw32 that comes with git works fine too).
+Then open the `browser/index.html` in your browser.
You may also [visit the github hosted page](http://petkaantonov.github.io/bluebird/browser/).
diff --git a/browser/bundle.js b/browser/bundle.js
deleted file mode 100644
index 7b20c280b..000000000
--- a/browser/bundle.js
+++ /dev/null
@@ -1,32492 +0,0 @@
-;(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o i; ++i) {
- if (array.hasOwnProperty(i)) {
- if (isValueSet) {
- value = callback(value, array[i], i, array);
- }
- else {
- value = array[i];
- isValueSet = true;
- }
- }
- }
-
- return value;
-};
-
-// String.prototype.substr - negative index don't work in IE8
-if ('ab'.substr(-1) !== 'b') {
- exports.substr = function (str, start, length) {
- // did we get a negative start, calculate how much it is from the beginning of the string
- if (start < 0) start = str.length + start;
-
- // call the original function
- return str.substr(start, length);
- };
-} else {
- exports.substr = function (str, start, length) {
- return str.substr(start, length);
- };
-}
-
-// String.prototype.trim is supported in IE9
-exports.trim = function (str) {
- if (str.trim) return str.trim();
- return str.replace(/^\s+|\s+$/g, '');
-};
-
-// Function.prototype.bind is supported in IE9
-exports.bind = function () {
- var args = Array.prototype.slice.call(arguments);
- var fn = args.shift();
- if (fn.bind) return fn.bind.apply(fn, args);
- var self = args.shift();
- return function () {
- fn.apply(self, args.concat([Array.prototype.slice.call(arguments)]));
- };
-};
-
-// Object.create is supported in IE9
-function create(prototype, properties) {
- var object;
- if (prototype === null) {
- object = { '__proto__' : null };
- }
- else {
- if (typeof prototype !== 'object') {
- throw new TypeError(
- 'typeof prototype[' + (typeof prototype) + '] != \'object\''
- );
- }
- var Type = function () {};
- Type.prototype = prototype;
- object = new Type();
- object.__proto__ = prototype;
- }
- if (typeof properties !== 'undefined' && Object.defineProperties) {
- Object.defineProperties(object, properties);
- }
- return object;
-}
-exports.create = typeof Object.create === 'function' ? Object.create : create;
-
-// Object.keys and Object.getOwnPropertyNames is supported in IE9 however
-// they do show a description and number property on Error objects
-function notObject(object) {
- return ((typeof object != "object" && typeof object != "function") || object === null);
-}
-
-function keysShim(object) {
- if (notObject(object)) {
- throw new TypeError("Object.keys called on a non-object");
- }
-
- var result = [];
- for (var name in object) {
- if (hasOwnProperty.call(object, name)) {
- result.push(name);
- }
- }
- return result;
-}
-
-// getOwnPropertyNames is almost the same as Object.keys one key feature
-// is that it returns hidden properties, since that can't be implemented,
-// this feature gets reduced so it just shows the length property on arrays
-function propertyShim(object) {
- if (notObject(object)) {
- throw new TypeError("Object.getOwnPropertyNames called on a non-object");
- }
-
- var result = keysShim(object);
- if (exports.isArray(object) && exports.indexOf(object, 'length') === -1) {
- result.push('length');
- }
- return result;
-}
-
-var keys = typeof Object.keys === 'function' ? Object.keys : keysShim;
-var getOwnPropertyNames = typeof Object.getOwnPropertyNames === 'function' ?
- Object.getOwnPropertyNames : propertyShim;
-
-if (new Error().hasOwnProperty('description')) {
- var ERROR_PROPERTY_FILTER = function (obj, array) {
- if (toString.call(obj) === '[object Error]') {
- array = exports.filter(array, function (name) {
- return name !== 'description' && name !== 'number' && name !== 'message';
- });
- }
- return array;
- };
-
- exports.keys = function (object) {
- return ERROR_PROPERTY_FILTER(object, keys(object));
- };
- exports.getOwnPropertyNames = function (object) {
- return ERROR_PROPERTY_FILTER(object, getOwnPropertyNames(object));
- };
-} else {
- exports.keys = keys;
- exports.getOwnPropertyNames = getOwnPropertyNames;
-}
-
-// Object.getOwnPropertyDescriptor - supported in IE8 but only on dom elements
-function valueObject(value, key) {
- return { value: value[key] };
-}
-
-if (typeof Object.getOwnPropertyDescriptor === 'function') {
- try {
- Object.getOwnPropertyDescriptor({'a': 1}, 'a');
- exports.getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
- } catch (e) {
- // IE8 dom element issue - use a try catch and default to valueObject
- exports.getOwnPropertyDescriptor = function (value, key) {
- try {
- return Object.getOwnPropertyDescriptor(value, key);
- } catch (e) {
- return valueObject(value, key);
- }
- };
- }
-} else {
- exports.getOwnPropertyDescriptor = valueObject;
-}
-
-},{}],2:[function(require,module,exports){
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-// UTILITY
-var util = require('util');
-var shims = require('_shims');
-var pSlice = Array.prototype.slice;
-
-// 1. The assert module provides functions that throw
-// AssertionError's when particular conditions are not met. The
-// assert module must conform to the following interface.
-
-var assert = module.exports = ok;
-
-// 2. The AssertionError is defined in assert.
-// new assert.AssertionError({ message: message,
-// actual: actual,
-// expected: expected })
-
-assert.AssertionError = function AssertionError(options) {
- this.name = 'AssertionError';
- this.actual = options.actual;
- this.expected = options.expected;
- this.operator = options.operator;
- this.message = options.message || getMessage(this);
-};
-
-// assert.AssertionError instanceof Error
-util.inherits(assert.AssertionError, Error);
-
-function replacer(key, value) {
- if (util.isUndefined(value)) {
- return '' + value;
- }
- if (util.isNumber(value) && (isNaN(value) || !isFinite(value))) {
- return value.toString();
- }
- if (util.isFunction(value) || util.isRegExp(value)) {
- return value.toString();
- }
- return value;
-}
-
-function truncate(s, n) {
- if (util.isString(s)) {
- return s.length < n ? s : s.slice(0, n);
- } else {
- return s;
- }
-}
-
-function getMessage(self) {
- return truncate(JSON.stringify(self.actual, replacer), 128) + ' ' +
- self.operator + ' ' +
- truncate(JSON.stringify(self.expected, replacer), 128);
-}
-
-// At present only the three keys mentioned above are used and
-// understood by the spec. Implementations or sub modules can pass
-// other keys to the AssertionError's constructor - they will be
-// ignored.
-
-// 3. All of the following functions must throw an AssertionError
-// when a corresponding condition is not met, with a message that
-// may be undefined if not provided. All assertion methods provide
-// both the actual and expected values to the assertion error for
-// display purposes.
-
-function fail(actual, expected, message, operator, stackStartFunction) {
- throw new assert.AssertionError({
- message: message,
- actual: actual,
- expected: expected,
- operator: operator,
- stackStartFunction: stackStartFunction
- });
-}
-
-// EXTENSION! allows for well behaved errors defined elsewhere.
-assert.fail = fail;
-
-// 4. Pure assertion tests whether a value is truthy, as determined
-// by !!guard.
-// assert.ok(guard, message_opt);
-// This statement is equivalent to assert.equal(true, !!guard,
-// message_opt);. To test strictly for the value true, use
-// assert.strictEqual(true, guard, message_opt);.
-
-function ok(value, message) {
- if (!value) fail(value, true, message, '==', assert.ok);
-}
-assert.ok = ok;
-
-// 5. The equality assertion tests shallow, coercive equality with
-// ==.
-// assert.equal(actual, expected, message_opt);
-
-assert.equal = function equal(actual, expected, message) {
- if (actual != expected) fail(actual, expected, message, '==', assert.equal);
-};
-
-// 6. The non-equality assertion tests for whether two objects are not equal
-// with != assert.notEqual(actual, expected, message_opt);
-
-assert.notEqual = function notEqual(actual, expected, message) {
- if (actual == expected) {
- fail(actual, expected, message, '!=', assert.notEqual);
- }
-};
-
-// 7. The equivalence assertion tests a deep equality relation.
-// assert.deepEqual(actual, expected, message_opt);
-
-assert.deepEqual = function deepEqual(actual, expected, message) {
- if (!_deepEqual(actual, expected)) {
- fail(actual, expected, message, 'deepEqual', assert.deepEqual);
- }
-};
-
-function _deepEqual(actual, expected) {
- // 7.1. All identical values are equivalent, as determined by ===.
- if (actual === expected) {
- return true;
-
- } else if (util.isBuffer(actual) && util.isBuffer(expected)) {
- if (actual.length != expected.length) return false;
-
- for (var i = 0; i < actual.length; i++) {
- if (actual[i] !== expected[i]) return false;
- }
-
- return true;
-
- // 7.2. If the expected value is a Date object, the actual value is
- // equivalent if it is also a Date object that refers to the same time.
- } else if (util.isDate(actual) && util.isDate(expected)) {
- return actual.getTime() === expected.getTime();
-
- // 7.3 If the expected value is a RegExp object, the actual value is
- // equivalent if it is also a RegExp object with the same source and
- // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
- } else if (util.isRegExp(actual) && util.isRegExp(expected)) {
- return actual.source === expected.source &&
- actual.global === expected.global &&
- actual.multiline === expected.multiline &&
- actual.lastIndex === expected.lastIndex &&
- actual.ignoreCase === expected.ignoreCase;
-
- // 7.4. Other pairs that do not both pass typeof value == 'object',
- // equivalence is determined by ==.
- } else if (!util.isObject(actual) && !util.isObject(expected)) {
- return actual == expected;
-
- // 7.5 For all other Object pairs, including Array objects, equivalence is
- // determined by having the same number of owned properties (as verified
- // with Object.prototype.hasOwnProperty.call), the same set of keys
- // (although not necessarily the same order), equivalent values for every
- // corresponding key, and an identical 'prototype' property. Note: this
- // accounts for both named and indexed properties on Arrays.
- } else {
- return objEquiv(actual, expected);
- }
-}
-
-function isArguments(object) {
- return Object.prototype.toString.call(object) == '[object Arguments]';
-}
-
-function objEquiv(a, b) {
- if (util.isNullOrUndefined(a) || util.isNullOrUndefined(b))
- return false;
- // an identical 'prototype' property.
- if (a.prototype !== b.prototype) return false;
- //~~~I've managed to break Object.keys through screwy arguments passing.
- // Converting to array solves the problem.
- if (isArguments(a)) {
- if (!isArguments(b)) {
- return false;
- }
- a = pSlice.call(a);
- b = pSlice.call(b);
- return _deepEqual(a, b);
- }
- try {
- var ka = shims.keys(a),
- kb = shims.keys(b),
- key, i;
- } catch (e) {//happens when one is a string literal and the other isn't
- return false;
- }
- // having the same number of owned properties (keys incorporates
- // hasOwnProperty)
- if (ka.length != kb.length)
- return false;
- //the same set of keys (although not necessarily the same order),
- ka.sort();
- kb.sort();
- //~~~cheap key test
- for (i = ka.length - 1; i >= 0; i--) {
- if (ka[i] != kb[i])
- return false;
- }
- //equivalent values for every corresponding key, and
- //~~~possibly expensive deep test
- for (i = ka.length - 1; i >= 0; i--) {
- key = ka[i];
- if (!_deepEqual(a[key], b[key])) return false;
- }
- return true;
-}
-
-// 8. The non-equivalence assertion tests for any deep inequality.
-// assert.notDeepEqual(actual, expected, message_opt);
-
-assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
- if (_deepEqual(actual, expected)) {
- fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
- }
-};
-
-// 9. The strict equality assertion tests strict equality, as determined by ===.
-// assert.strictEqual(actual, expected, message_opt);
-
-assert.strictEqual = function strictEqual(actual, expected, message) {
- if (actual !== expected) {
- fail(actual, expected, message, '===', assert.strictEqual);
- }
-};
-
-// 10. The strict non-equality assertion tests for strict inequality, as
-// determined by !==. assert.notStrictEqual(actual, expected, message_opt);
-
-assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
- if (actual === expected) {
- fail(actual, expected, message, '!==', assert.notStrictEqual);
- }
-};
-
-function expectedException(actual, expected) {
- if (!actual || !expected) {
- return false;
- }
-
- if (Object.prototype.toString.call(expected) == '[object RegExp]') {
- return expected.test(actual);
- } else if (actual instanceof expected) {
- return true;
- } else if (expected.call({}, actual) === true) {
- return true;
- }
-
- return false;
-}
-
-function _throws(shouldThrow, block, expected, message) {
- var actual;
-
- if (util.isString(expected)) {
- message = expected;
- expected = null;
- }
-
- try {
- block();
- } catch (e) {
- actual = e;
- }
-
- message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
- (message ? ' ' + message : '.');
-
- if (shouldThrow && !actual) {
- fail(actual, expected, 'Missing expected exception' + message);
- }
-
- if (!shouldThrow && expectedException(actual, expected)) {
- fail(actual, expected, 'Got unwanted exception' + message);
- }
-
- if ((shouldThrow && actual && expected &&
- !expectedException(actual, expected)) || (!shouldThrow && actual)) {
- throw actual;
- }
-}
-
-// 11. Expected to throw an error:
-// assert.throws(block, Error_opt, message_opt);
-
-assert.throws = function(block, /*optional*/error, /*optional*/message) {
- _throws.apply(this, [true].concat(pSlice.call(arguments)));
-};
-
-// EXTENSION! This is annoying to write outside this module.
-assert.doesNotThrow = function(block, /*optional*/message) {
- _throws.apply(this, [false].concat(pSlice.call(arguments)));
-};
-
-assert.ifError = function(err) { if (err) {throw err;}};
-},{"_shims":1,"util":6}],3:[function(require,module,exports){
-
-// not implemented
-// The reason for having an empty file and not throwing is to allow
-// untraditional implementation of this module.
-
-},{}],4:[function(require,module,exports){
-module.exports=require(3)
-},{}],5:[function(require,module,exports){
-var process=require("__browserify_process");// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-var util = require('util');
-var shims = require('_shims');
-
-// resolves . and .. elements in a path array with directory names there
-// must be no slashes, empty elements, or device names (c:\) in the array
-// (so also no leading and trailing slashes - it does not distinguish
-// relative and absolute paths)
-function normalizeArray(parts, allowAboveRoot) {
- // if the path tries to go above the root, `up` ends up > 0
- var up = 0;
- for (var i = parts.length - 1; i >= 0; i--) {
- var last = parts[i];
- if (last === '.') {
- parts.splice(i, 1);
- } else if (last === '..') {
- parts.splice(i, 1);
- up++;
- } else if (up) {
- parts.splice(i, 1);
- up--;
- }
- }
-
- // if the path is allowed to go above the root, restore leading ..s
- if (allowAboveRoot) {
- for (; up--; up) {
- parts.unshift('..');
- }
- }
-
- return parts;
-}
-
-// Split a filename into [root, dir, basename, ext], unix version
-// 'root' is just a slash, or nothing.
-var splitPathRe =
- /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
-var splitPath = function(filename) {
- return splitPathRe.exec(filename).slice(1);
-};
-
-// path.resolve([from ...], to)
-// posix version
-exports.resolve = function() {
- var resolvedPath = '',
- resolvedAbsolute = false;
-
- for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
- var path = (i >= 0) ? arguments[i] : process.cwd();
-
- // Skip empty and invalid entries
- if (!util.isString(path)) {
- throw new TypeError('Arguments to path.resolve must be strings');
- } else if (!path) {
- continue;
- }
-
- resolvedPath = path + '/' + resolvedPath;
- resolvedAbsolute = path.charAt(0) === '/';
- }
-
- // At this point the path should be resolved to a full absolute path, but
- // handle relative paths to be safe (might happen when process.cwd() fails)
-
- // Normalize the path
- resolvedPath = normalizeArray(shims.filter(resolvedPath.split('/'), function(p) {
- return !!p;
- }), !resolvedAbsolute).join('/');
-
- return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
-};
-
-// path.normalize(path)
-// posix version
-exports.normalize = function(path) {
- var isAbsolute = exports.isAbsolute(path),
- trailingSlash = shims.substr(path, -1) === '/';
-
- // Normalize the path
- path = normalizeArray(shims.filter(path.split('/'), function(p) {
- return !!p;
- }), !isAbsolute).join('/');
-
- if (!path && !isAbsolute) {
- path = '.';
- }
- if (path && trailingSlash) {
- path += '/';
- }
-
- return (isAbsolute ? '/' : '') + path;
-};
-
-// posix version
-exports.isAbsolute = function(path) {
- return path.charAt(0) === '/';
-};
-
-// posix version
-exports.join = function() {
- var paths = Array.prototype.slice.call(arguments, 0);
- return exports.normalize(shims.filter(paths, function(p, index) {
- if (!util.isString(p)) {
- throw new TypeError('Arguments to path.join must be strings');
- }
- return p;
- }).join('/'));
-};
-
-
-// path.relative(from, to)
-// posix version
-exports.relative = function(from, to) {
- from = exports.resolve(from).substr(1);
- to = exports.resolve(to).substr(1);
-
- function trim(arr) {
- var start = 0;
- for (; start < arr.length; start++) {
- if (arr[start] !== '') break;
- }
-
- var end = arr.length - 1;
- for (; end >= 0; end--) {
- if (arr[end] !== '') break;
- }
-
- if (start > end) return [];
- return arr.slice(start, end - start + 1);
- }
-
- var fromParts = trim(from.split('/'));
- var toParts = trim(to.split('/'));
-
- var length = Math.min(fromParts.length, toParts.length);
- var samePartsLength = length;
- for (var i = 0; i < length; i++) {
- if (fromParts[i] !== toParts[i]) {
- samePartsLength = i;
- break;
- }
- }
-
- var outputParts = [];
- for (var i = samePartsLength; i < fromParts.length; i++) {
- outputParts.push('..');
- }
-
- outputParts = outputParts.concat(toParts.slice(samePartsLength));
-
- return outputParts.join('/');
-};
-
-exports.sep = '/';
-exports.delimiter = ':';
-
-exports.dirname = function(path) {
- var result = splitPath(path),
- root = result[0],
- dir = result[1];
-
- if (!root && !dir) {
- // No dirname whatsoever
- return '.';
- }
-
- if (dir) {
- // It has a dirname, strip trailing slash
- dir = dir.substr(0, dir.length - 1);
- }
-
- return root + dir;
-};
-
-
-exports.basename = function(path, ext) {
- var f = splitPath(path)[2];
- // TODO: make this comparison case-insensitive on windows?
- if (ext && f.substr(-1 * ext.length) === ext) {
- f = f.substr(0, f.length - ext.length);
- }
- return f;
-};
-
-
-exports.extname = function(path) {
- return splitPath(path)[3];
-};
-
-},{"__browserify_process":16,"_shims":1,"util":6}],6:[function(require,module,exports){
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-var shims = require('_shims');
-
-var formatRegExp = /%[sdj%]/g;
-exports.format = function(f) {
- if (!isString(f)) {
- var objects = [];
- for (var i = 0; i < arguments.length; i++) {
- objects.push(inspect(arguments[i]));
- }
- return objects.join(' ');
- }
-
- var i = 1;
- var args = arguments;
- var len = args.length;
- var str = String(f).replace(formatRegExp, function(x) {
- if (x === '%%') return '%';
- if (i >= len) return x;
- switch (x) {
- case '%s': return String(args[i++]);
- case '%d': return Number(args[i++]);
- case '%j':
- try {
- return JSON.stringify(args[i++]);
- } catch (_) {
- return '[Circular]';
- }
- default:
- return x;
- }
- });
- for (var x = args[i]; i < len; x = args[++i]) {
- if (isNull(x) || !isObject(x)) {
- str += ' ' + x;
- } else {
- str += ' ' + inspect(x);
- }
- }
- return str;
-};
-
-/**
- * Echos the value of a value. Trys to print the value out
- * in the best way possible given the different types.
- *
- * @param {Object} obj The object to print out.
- * @param {Object} opts Optional options object that alters the output.
- */
-/* legacy: obj, showHidden, depth, colors*/
-function inspect(obj, opts) {
- // default options
- var ctx = {
- seen: [],
- stylize: stylizeNoColor
- };
- // legacy...
- if (arguments.length >= 3) ctx.depth = arguments[2];
- if (arguments.length >= 4) ctx.colors = arguments[3];
- if (isBoolean(opts)) {
- // legacy...
- ctx.showHidden = opts;
- } else if (opts) {
- // got an "options" object
- exports._extend(ctx, opts);
- }
- // set default options
- if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
- if (isUndefined(ctx.depth)) ctx.depth = 2;
- if (isUndefined(ctx.colors)) ctx.colors = false;
- if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
- if (ctx.colors) ctx.stylize = stylizeWithColor;
- return formatValue(ctx, obj, ctx.depth);
-}
-exports.inspect = inspect;
-
-
-// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
-inspect.colors = {
- 'bold' : [1, 22],
- 'italic' : [3, 23],
- 'underline' : [4, 24],
- 'inverse' : [7, 27],
- 'white' : [37, 39],
- 'grey' : [90, 39],
- 'black' : [30, 39],
- 'blue' : [34, 39],
- 'cyan' : [36, 39],
- 'green' : [32, 39],
- 'magenta' : [35, 39],
- 'red' : [31, 39],
- 'yellow' : [33, 39]
-};
-
-// Don't use 'blue' not visible on cmd.exe
-inspect.styles = {
- 'special': 'cyan',
- 'number': 'yellow',
- 'boolean': 'yellow',
- 'undefined': 'grey',
- 'null': 'bold',
- 'string': 'green',
- 'date': 'magenta',
- // "name": intentionally not styling
- 'regexp': 'red'
-};
-
-
-function stylizeWithColor(str, styleType) {
- var style = inspect.styles[styleType];
-
- if (style) {
- return '\u001b[' + inspect.colors[style][0] + 'm' + str +
- '\u001b[' + inspect.colors[style][1] + 'm';
- } else {
- return str;
- }
-}
-
-
-function stylizeNoColor(str, styleType) {
- return str;
-}
-
-
-function arrayToHash(array) {
- var hash = {};
-
- shims.forEach(array, function(val, idx) {
- hash[val] = true;
- });
-
- return hash;
-}
-
-
-function formatValue(ctx, value, recurseTimes) {
- // Provide a hook for user-specified inspect functions.
- // Check that value is an object with an inspect function on it
- if (ctx.customInspect &&
- value &&
- isFunction(value.inspect) &&
- // Filter out the util module, it's inspect function is special
- value.inspect !== exports.inspect &&
- // Also filter out any prototype objects using the circular check.
- !(value.constructor && value.constructor.prototype === value)) {
- var ret = value.inspect(recurseTimes);
- if (!isString(ret)) {
- ret = formatValue(ctx, ret, recurseTimes);
- }
- return ret;
- }
-
- // Primitive types cannot have properties
- var primitive = formatPrimitive(ctx, value);
- if (primitive) {
- return primitive;
- }
-
- // Look up the keys of the object.
- var keys = shims.keys(value);
- var visibleKeys = arrayToHash(keys);
-
- if (ctx.showHidden) {
- keys = shims.getOwnPropertyNames(value);
- }
-
- // Some type of object without properties can be shortcutted.
- if (keys.length === 0) {
- if (isFunction(value)) {
- var name = value.name ? ': ' + value.name : '';
- return ctx.stylize('[Function' + name + ']', 'special');
- }
- if (isRegExp(value)) {
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
- }
- if (isDate(value)) {
- return ctx.stylize(Date.prototype.toString.call(value), 'date');
- }
- if (isError(value)) {
- return formatError(value);
- }
- }
-
- var base = '', array = false, braces = ['{', '}'];
-
- // Make Array say that they are Array
- if (isArray(value)) {
- array = true;
- braces = ['[', ']'];
- }
-
- // Make functions say that they are functions
- if (isFunction(value)) {
- var n = value.name ? ': ' + value.name : '';
- base = ' [Function' + n + ']';
- }
-
- // Make RegExps say that they are RegExps
- if (isRegExp(value)) {
- base = ' ' + RegExp.prototype.toString.call(value);
- }
-
- // Make dates with properties first say the date
- if (isDate(value)) {
- base = ' ' + Date.prototype.toUTCString.call(value);
- }
-
- // Make error with message first say the error
- if (isError(value)) {
- base = ' ' + formatError(value);
- }
-
- if (keys.length === 0 && (!array || value.length == 0)) {
- return braces[0] + base + braces[1];
- }
-
- if (recurseTimes < 0) {
- if (isRegExp(value)) {
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
- } else {
- return ctx.stylize('[Object]', 'special');
- }
- }
-
- ctx.seen.push(value);
-
- var output;
- if (array) {
- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
- } else {
- output = keys.map(function(key) {
- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
- });
- }
-
- ctx.seen.pop();
-
- return reduceToSingleString(output, base, braces);
-}
-
-
-function formatPrimitive(ctx, value) {
- if (isUndefined(value))
- return ctx.stylize('undefined', 'undefined');
- if (isString(value)) {
- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
- .replace(/'/g, "\\'")
- .replace(/\\"/g, '"') + '\'';
- return ctx.stylize(simple, 'string');
- }
- if (isNumber(value))
- return ctx.stylize('' + value, 'number');
- if (isBoolean(value))
- return ctx.stylize('' + value, 'boolean');
- // For some reason typeof null is "object", so special case here.
- if (isNull(value))
- return ctx.stylize('null', 'null');
-}
-
-
-function formatError(value) {
- return '[' + Error.prototype.toString.call(value) + ']';
-}
-
-
-function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
- var output = [];
- for (var i = 0, l = value.length; i < l; ++i) {
- if (hasOwnProperty(value, String(i))) {
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
- String(i), true));
- } else {
- output.push('');
- }
- }
-
- shims.forEach(keys, function(key) {
- if (!key.match(/^\d+$/)) {
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
- key, true));
- }
- });
- return output;
-}
-
-
-function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
- var name, str, desc;
- desc = shims.getOwnPropertyDescriptor(value, key) || { value: value[key] };
- if (desc.get) {
- if (desc.set) {
- str = ctx.stylize('[Getter/Setter]', 'special');
- } else {
- str = ctx.stylize('[Getter]', 'special');
- }
- } else {
- if (desc.set) {
- str = ctx.stylize('[Setter]', 'special');
- }
- }
-
- if (!hasOwnProperty(visibleKeys, key)) {
- name = '[' + key + ']';
- }
- if (!str) {
- if (shims.indexOf(ctx.seen, desc.value) < 0) {
- if (isNull(recurseTimes)) {
- str = formatValue(ctx, desc.value, null);
- } else {
- str = formatValue(ctx, desc.value, recurseTimes - 1);
- }
- if (str.indexOf('\n') > -1) {
- if (array) {
- str = str.split('\n').map(function(line) {
- return ' ' + line;
- }).join('\n').substr(2);
- } else {
- str = '\n' + str.split('\n').map(function(line) {
- return ' ' + line;
- }).join('\n');
- }
- }
- } else {
- str = ctx.stylize('[Circular]', 'special');
- }
- }
- if (isUndefined(name)) {
- if (array && key.match(/^\d+$/)) {
- return str;
- }
- name = JSON.stringify('' + key);
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
- name = name.substr(1, name.length - 2);
- name = ctx.stylize(name, 'name');
- } else {
- name = name.replace(/'/g, "\\'")
- .replace(/\\"/g, '"')
- .replace(/(^"|"$)/g, "'");
- name = ctx.stylize(name, 'string');
- }
- }
-
- return name + ': ' + str;
-}
-
-
-function reduceToSingleString(output, base, braces) {
- var numLinesEst = 0;
- var length = shims.reduce(output, function(prev, cur) {
- numLinesEst++;
- if (cur.indexOf('\n') >= 0) numLinesEst++;
- return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
- }, 0);
-
- if (length > 60) {
- return braces[0] +
- (base === '' ? '' : base + '\n ') +
- ' ' +
- output.join(',\n ') +
- ' ' +
- braces[1];
- }
-
- return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
-}
-
-
-// NOTE: These type checking functions intentionally don't use `instanceof`
-// because it is fragile and can be easily faked with `Object.create()`.
-function isArray(ar) {
- return shims.isArray(ar);
-}
-exports.isArray = isArray;
-
-function isBoolean(arg) {
- return typeof arg === 'boolean';
-}
-exports.isBoolean = isBoolean;
-
-function isNull(arg) {
- return arg === null;
-}
-exports.isNull = isNull;
-
-function isNullOrUndefined(arg) {
- return arg == null;
-}
-exports.isNullOrUndefined = isNullOrUndefined;
-
-function isNumber(arg) {
- return typeof arg === 'number';
-}
-exports.isNumber = isNumber;
-
-function isString(arg) {
- return typeof arg === 'string';
-}
-exports.isString = isString;
-
-function isSymbol(arg) {
- return typeof arg === 'symbol';
-}
-exports.isSymbol = isSymbol;
-
-function isUndefined(arg) {
- return arg === void 0;
-}
-exports.isUndefined = isUndefined;
-
-function isRegExp(re) {
- return isObject(re) && objectToString(re) === '[object RegExp]';
-}
-exports.isRegExp = isRegExp;
-
-function isObject(arg) {
- return typeof arg === 'object' && arg;
-}
-exports.isObject = isObject;
-
-function isDate(d) {
- return isObject(d) && objectToString(d) === '[object Date]';
-}
-exports.isDate = isDate;
-
-function isError(e) {
- return isObject(e) && objectToString(e) === '[object Error]';
-}
-exports.isError = isError;
-
-function isFunction(arg) {
- return typeof arg === 'function';
-}
-exports.isFunction = isFunction;
-
-function isPrimitive(arg) {
- return arg === null ||
- typeof arg === 'boolean' ||
- typeof arg === 'number' ||
- typeof arg === 'string' ||
- typeof arg === 'symbol' || // ES6 symbol
- typeof arg === 'undefined';
-}
-exports.isPrimitive = isPrimitive;
-
-function isBuffer(arg) {
- return arg && typeof arg === 'object'
- && typeof arg.copy === 'function'
- && typeof arg.fill === 'function'
- && typeof arg.binarySlice === 'function'
- ;
-}
-exports.isBuffer = isBuffer;
-
-function objectToString(o) {
- return Object.prototype.toString.call(o);
-}
-
-
-function pad(n) {
- return n < 10 ? '0' + n.toString(10) : n.toString(10);
-}
-
-
-var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
- 'Oct', 'Nov', 'Dec'];
-
-// 26 Feb 16:19:34
-function timestamp() {
- var d = new Date();
- var time = [pad(d.getHours()),
- pad(d.getMinutes()),
- pad(d.getSeconds())].join(':');
- return [d.getDate(), months[d.getMonth()], time].join(' ');
-}
-
-
-// log is just a thin wrapper to console.log that prepends a timestamp
-exports.log = function() {
- console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
-};
-
-
-/**
- * Inherit the prototype methods from one constructor into another.
- *
- * The Function.prototype.inherits from lang.js rewritten as a standalone
- * function (not on Function.prototype). NOTE: If this file is to be loaded
- * during bootstrapping this function needs to be rewritten using some native
- * functions as prototype setup using normal JavaScript does not work as
- * expected during bootstrapping (see mirror.js in r114903).
- *
- * @param {function} ctor Constructor function which needs to inherit the
- * prototype.
- * @param {function} superCtor Constructor function to inherit prototype from.
- */
-exports.inherits = function(ctor, superCtor) {
- ctor.super_ = superCtor;
- ctor.prototype = shims.create(superCtor.prototype, {
- constructor: {
- value: ctor,
- enumerable: false,
- writable: true,
- configurable: true
- }
- });
-};
-
-exports._extend = function(origin, add) {
- // Don't do anything if add isn't an object
- if (!add || !isObject(add)) return origin;
-
- var keys = shims.keys(add);
- var i = keys.length;
- while (i--) {
- origin[keys[i]] = add[keys[i]];
- }
- return origin;
-};
-
-function hasOwnProperty(obj, prop) {
- return Object.prototype.hasOwnProperty.call(obj, prop);
-}
-
-},{"_shims":1}],7:[function(require,module,exports){
-exports.readIEEE754 = function(buffer, offset, isBE, mLen, nBytes) {
- var e, m,
- eLen = nBytes * 8 - mLen - 1,
- eMax = (1 << eLen) - 1,
- eBias = eMax >> 1,
- nBits = -7,
- i = isBE ? 0 : (nBytes - 1),
- d = isBE ? 1 : -1,
- s = buffer[offset + i];
-
- i += d;
-
- e = s & ((1 << (-nBits)) - 1);
- s >>= (-nBits);
- nBits += eLen;
- for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);
-
- m = e & ((1 << (-nBits)) - 1);
- e >>= (-nBits);
- nBits += mLen;
- for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);
-
- if (e === 0) {
- e = 1 - eBias;
- } else if (e === eMax) {
- return m ? NaN : ((s ? -1 : 1) * Infinity);
- } else {
- m = m + Math.pow(2, mLen);
- e = e - eBias;
- }
- return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
-};
-
-exports.writeIEEE754 = function(buffer, value, offset, isBE, mLen, nBytes) {
- var e, m, c,
- eLen = nBytes * 8 - mLen - 1,
- eMax = (1 << eLen) - 1,
- eBias = eMax >> 1,
- rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
- i = isBE ? (nBytes - 1) : 0,
- d = isBE ? -1 : 1,
- s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
-
- value = Math.abs(value);
-
- if (isNaN(value) || value === Infinity) {
- m = isNaN(value) ? 1 : 0;
- e = eMax;
- } else {
- e = Math.floor(Math.log(value) / Math.LN2);
- if (value * (c = Math.pow(2, -e)) < 1) {
- e--;
- c *= 2;
- }
- if (e + eBias >= 1) {
- value += rt / c;
- } else {
- value += rt * Math.pow(2, 1 - eBias);
- }
- if (value * c >= 2) {
- e++;
- c /= 2;
- }
-
- if (e + eBias >= eMax) {
- m = 0;
- e = eMax;
- } else if (e + eBias >= 1) {
- m = (value * c - 1) * Math.pow(2, mLen);
- e = e + eBias;
- } else {
- m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
- e = 0;
- }
- }
-
- for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);
-
- e = (e << mLen) | m;
- eLen += mLen;
- for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);
-
- buffer[offset + i - d] |= s * 128;
-};
-
-},{}],8:[function(require,module,exports){
-var assert;
-exports.Buffer = Buffer;
-exports.SlowBuffer = Buffer;
-Buffer.poolSize = 8192;
-exports.INSPECT_MAX_BYTES = 50;
-
-function stringtrim(str) {
- if (str.trim) return str.trim();
- return str.replace(/^\s+|\s+$/g, '');
-}
-
-function Buffer(subject, encoding, offset) {
- if(!assert) assert= require('assert');
- if (!(this instanceof Buffer)) {
- return new Buffer(subject, encoding, offset);
- }
- this.parent = this;
- this.offset = 0;
-
- // Work-around: node's base64 implementation
- // allows for non-padded strings while base64-js
- // does not..
- if (encoding == "base64" && typeof subject == "string") {
- subject = stringtrim(subject);
- while (subject.length % 4 != 0) {
- subject = subject + "=";
- }
- }
-
- var type;
-
- // Are we slicing?
- if (typeof offset === 'number') {
- this.length = coerce(encoding);
- // slicing works, with limitations (no parent tracking/update)
- // check https://github.com/toots/buffer-browserify/issues/19
- for (var i = 0; i < this.length; i++) {
- this[i] = subject.get(i+offset);
- }
- } else {
- // Find the length
- switch (type = typeof subject) {
- case 'number':
- this.length = coerce(subject);
- break;
-
- case 'string':
- this.length = Buffer.byteLength(subject, encoding);
- break;
-
- case 'object': // Assume object is an array
- this.length = coerce(subject.length);
- break;
-
- default:
- throw new Error('First argument needs to be a number, ' +
- 'array or string.');
- }
-
- // Treat array-ish objects as a byte array.
- if (isArrayIsh(subject)) {
- for (var i = 0; i < this.length; i++) {
- if (subject instanceof Buffer) {
- this[i] = subject.readUInt8(i);
- }
- else {
- this[i] = subject[i];
- }
- }
- } else if (type == 'string') {
- // We are a string
- this.length = this.write(subject, 0, encoding);
- } else if (type === 'number') {
- for (var i = 0; i < this.length; i++) {
- this[i] = 0;
- }
- }
- }
-}
-
-Buffer.prototype.get = function get(i) {
- if (i < 0 || i >= this.length) throw new Error('oob');
- return this[i];
-};
-
-Buffer.prototype.set = function set(i, v) {
- if (i < 0 || i >= this.length) throw new Error('oob');
- return this[i] = v;
-};
-
-Buffer.byteLength = function (str, encoding) {
- switch (encoding || "utf8") {
- case 'hex':
- return str.length / 2;
-
- case 'utf8':
- case 'utf-8':
- return utf8ToBytes(str).length;
-
- case 'ascii':
- case 'binary':
- return str.length;
-
- case 'base64':
- return base64ToBytes(str).length;
-
- default:
- throw new Error('Unknown encoding');
- }
-};
-
-Buffer.prototype.utf8Write = function (string, offset, length) {
- var bytes, pos;
- return Buffer._charsWritten = blitBuffer(utf8ToBytes(string), this, offset, length);
-};
-
-Buffer.prototype.asciiWrite = function (string, offset, length) {
- var bytes, pos;
- return Buffer._charsWritten = blitBuffer(asciiToBytes(string), this, offset, length);
-};
-
-Buffer.prototype.binaryWrite = Buffer.prototype.asciiWrite;
-
-Buffer.prototype.base64Write = function (string, offset, length) {
- var bytes, pos;
- return Buffer._charsWritten = blitBuffer(base64ToBytes(string), this, offset, length);
-};
-
-Buffer.prototype.base64Slice = function (start, end) {
- var bytes = Array.prototype.slice.apply(this, arguments)
- return require("base64-js").fromByteArray(bytes);
-};
-
-Buffer.prototype.utf8Slice = function () {
- var bytes = Array.prototype.slice.apply(this, arguments);
- var res = "";
- var tmp = "";
- var i = 0;
- while (i < bytes.length) {
- if (bytes[i] <= 0x7F) {
- res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i]);
- tmp = "";
- } else
- tmp += "%" + bytes[i].toString(16);
-
- i++;
- }
-
- return res + decodeUtf8Char(tmp);
-}
-
-Buffer.prototype.asciiSlice = function () {
- var bytes = Array.prototype.slice.apply(this, arguments);
- var ret = "";
- for (var i = 0; i < bytes.length; i++)
- ret += String.fromCharCode(bytes[i]);
- return ret;
-}
-
-Buffer.prototype.binarySlice = Buffer.prototype.asciiSlice;
-
-Buffer.prototype.inspect = function() {
- var out = [],
- len = this.length;
- for (var i = 0; i < len; i++) {
- out[i] = toHex(this[i]);
- if (i == exports.INSPECT_MAX_BYTES) {
- out[i + 1] = '...';
- break;
- }
- }
- return '';
-};
-
-
-Buffer.prototype.hexSlice = function(start, end) {
- var len = this.length;
-
- if (!start || start < 0) start = 0;
- if (!end || end < 0 || end > len) end = len;
-
- var out = '';
- for (var i = start; i < end; i++) {
- out += toHex(this[i]);
- }
- return out;
-};
-
-
-Buffer.prototype.toString = function(encoding, start, end) {
- encoding = String(encoding || 'utf8').toLowerCase();
- start = +start || 0;
- if (typeof end == 'undefined') end = this.length;
-
- // Fastpath empty strings
- if (+end == start) {
- return '';
- }
-
- switch (encoding) {
- case 'hex':
- return this.hexSlice(start, end);
-
- case 'utf8':
- case 'utf-8':
- return this.utf8Slice(start, end);
-
- case 'ascii':
- return this.asciiSlice(start, end);
-
- case 'binary':
- return this.binarySlice(start, end);
-
- case 'base64':
- return this.base64Slice(start, end);
-
- case 'ucs2':
- case 'ucs-2':
- return this.ucs2Slice(start, end);
-
- default:
- throw new Error('Unknown encoding');
- }
-};
-
-
-Buffer.prototype.hexWrite = function(string, offset, length) {
- offset = +offset || 0;
- var remaining = this.length - offset;
- if (!length) {
- length = remaining;
- } else {
- length = +length;
- if (length > remaining) {
- length = remaining;
- }
- }
-
- // must be an even number of digits
- var strLen = string.length;
- if (strLen % 2) {
- throw new Error('Invalid hex string');
- }
- if (length > strLen / 2) {
- length = strLen / 2;
- }
- for (var i = 0; i < length; i++) {
- var byte = parseInt(string.substr(i * 2, 2), 16);
- if (isNaN(byte)) throw new Error('Invalid hex string');
- this[offset + i] = byte;
- }
- Buffer._charsWritten = i * 2;
- return i;
-};
-
-
-Buffer.prototype.write = function(string, offset, length, encoding) {
- // Support both (string, offset, length, encoding)
- // and the legacy (string, encoding, offset, length)
- if (isFinite(offset)) {
- if (!isFinite(length)) {
- encoding = length;
- length = undefined;
- }
- } else { // legacy
- var swap = encoding;
- encoding = offset;
- offset = length;
- length = swap;
- }
-
- offset = +offset || 0;
- var remaining = this.length - offset;
- if (!length) {
- length = remaining;
- } else {
- length = +length;
- if (length > remaining) {
- length = remaining;
- }
- }
- encoding = String(encoding || 'utf8').toLowerCase();
-
- switch (encoding) {
- case 'hex':
- return this.hexWrite(string, offset, length);
-
- case 'utf8':
- case 'utf-8':
- return this.utf8Write(string, offset, length);
-
- case 'ascii':
- return this.asciiWrite(string, offset, length);
-
- case 'binary':
- return this.binaryWrite(string, offset, length);
-
- case 'base64':
- return this.base64Write(string, offset, length);
-
- case 'ucs2':
- case 'ucs-2':
- return this.ucs2Write(string, offset, length);
-
- default:
- throw new Error('Unknown encoding');
- }
-};
-
-// slice(start, end)
-function clamp(index, len, defaultValue) {
- if (typeof index !== 'number') return defaultValue;
- index = ~~index; // Coerce to integer.
- if (index >= len) return len;
- if (index >= 0) return index;
- index += len;
- if (index >= 0) return index;
- return 0;
-}
-
-Buffer.prototype.slice = function(start, end) {
- var len = this.length;
- start = clamp(start, len, 0);
- end = clamp(end, len, len);
- return new Buffer(this, end - start, +start);
-};
-
-// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
-Buffer.prototype.copy = function(target, target_start, start, end) {
- var source = this;
- start || (start = 0);
- if (end === undefined || isNaN(end)) {
- end = this.length;
- }
- target_start || (target_start = 0);
-
- if (end < start) throw new Error('sourceEnd < sourceStart');
-
- // Copy 0 bytes; we're done
- if (end === start) return 0;
- if (target.length == 0 || source.length == 0) return 0;
-
- if (target_start < 0 || target_start >= target.length) {
- throw new Error('targetStart out of bounds');
- }
-
- if (start < 0 || start >= source.length) {
- throw new Error('sourceStart out of bounds');
- }
-
- if (end < 0 || end > source.length) {
- throw new Error('sourceEnd out of bounds');
- }
-
- // Are we oob?
- if (end > this.length) {
- end = this.length;
- }
-
- if (target.length - target_start < end - start) {
- end = target.length - target_start + start;
- }
-
- var temp = [];
- for (var i=start; i= this.length) {
- throw new Error('start out of bounds');
- }
-
- if (end < 0 || end > this.length) {
- throw new Error('end out of bounds');
- }
-
- for (var i = start; i < end; i++) {
- this[i] = value;
- }
-}
-
-// Static methods
-Buffer.isBuffer = function isBuffer(b) {
- return b instanceof Buffer || b instanceof Buffer;
-};
-
-Buffer.concat = function (list, totalLength) {
- if (!isArray(list)) {
- throw new Error("Usage: Buffer.concat(list, [totalLength])\n \
- list should be an Array.");
- }
-
- if (list.length === 0) {
- return new Buffer(0);
- } else if (list.length === 1) {
- return list[0];
- }
-
- if (typeof totalLength !== 'number') {
- totalLength = 0;
- for (var i = 0; i < list.length; i++) {
- var buf = list[i];
- totalLength += buf.length;
- }
- }
-
- var buffer = new Buffer(totalLength);
- var pos = 0;
- for (var i = 0; i < list.length; i++) {
- var buf = list[i];
- buf.copy(buffer, pos);
- pos += buf.length;
- }
- return buffer;
-};
-
-Buffer.isEncoding = function(encoding) {
- switch ((encoding + '').toLowerCase()) {
- case 'hex':
- case 'utf8':
- case 'utf-8':
- case 'ascii':
- case 'binary':
- case 'base64':
- case 'ucs2':
- case 'ucs-2':
- case 'utf16le':
- case 'utf-16le':
- case 'raw':
- return true;
-
- default:
- return false;
- }
-};
-
-// helpers
-
-function coerce(length) {
- // Coerce length to a number (possibly NaN), round up
- // in case it's fractional (e.g. 123.456) then do a
- // double negate to coerce a NaN to 0. Easy, right?
- length = ~~Math.ceil(+length);
- return length < 0 ? 0 : length;
-}
-
-function isArray(subject) {
- return (Array.isArray ||
- function(subject){
- return {}.toString.apply(subject) == '[object Array]'
- })
- (subject)
-}
-
-function isArrayIsh(subject) {
- return isArray(subject) || Buffer.isBuffer(subject) ||
- subject && typeof subject === 'object' &&
- typeof subject.length === 'number';
-}
-
-function toHex(n) {
- if (n < 16) return '0' + n.toString(16);
- return n.toString(16);
-}
-
-function utf8ToBytes(str) {
- var byteArray = [];
- for (var i = 0; i < str.length; i++)
- if (str.charCodeAt(i) <= 0x7F)
- byteArray.push(str.charCodeAt(i));
- else {
- var h = encodeURIComponent(str.charAt(i)).substr(1).split('%');
- for (var j = 0; j < h.length; j++)
- byteArray.push(parseInt(h[j], 16));
- }
-
- return byteArray;
-}
-
-function asciiToBytes(str) {
- var byteArray = []
- for (var i = 0; i < str.length; i++ )
- // Node's code seems to be doing this and not & 0x7F..
- byteArray.push( str.charCodeAt(i) & 0xFF );
-
- return byteArray;
-}
-
-function base64ToBytes(str) {
- return require("base64-js").toByteArray(str);
-}
-
-function blitBuffer(src, dst, offset, length) {
- var pos, i = 0;
- while (i < length) {
- if ((i+offset >= dst.length) || (i >= src.length))
- break;
-
- dst[i + offset] = src[i];
- i++;
- }
- return i;
-}
-
-function decodeUtf8Char(str) {
- try {
- return decodeURIComponent(str);
- } catch (err) {
- return String.fromCharCode(0xFFFD); // UTF 8 invalid char
- }
-}
-
-// read/write bit-twiddling
-
-Buffer.prototype.readUInt8 = function(offset, noAssert) {
- var buffer = this;
-
- if (!noAssert) {
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset < buffer.length,
- 'Trying to read beyond buffer length');
- }
-
- if (offset >= buffer.length) return;
-
- return buffer[offset];
-};
-
-function readUInt16(buffer, offset, isBigEndian, noAssert) {
- var val = 0;
-
-
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset + 1 < buffer.length,
- 'Trying to read beyond buffer length');
- }
-
- if (offset >= buffer.length) return 0;
-
- if (isBigEndian) {
- val = buffer[offset] << 8;
- if (offset + 1 < buffer.length) {
- val |= buffer[offset + 1];
- }
- } else {
- val = buffer[offset];
- if (offset + 1 < buffer.length) {
- val |= buffer[offset + 1] << 8;
- }
- }
-
- return val;
-}
-
-Buffer.prototype.readUInt16LE = function(offset, noAssert) {
- return readUInt16(this, offset, false, noAssert);
-};
-
-Buffer.prototype.readUInt16BE = function(offset, noAssert) {
- return readUInt16(this, offset, true, noAssert);
-};
-
-function readUInt32(buffer, offset, isBigEndian, noAssert) {
- var val = 0;
-
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
-
- if (offset >= buffer.length) return 0;
-
- if (isBigEndian) {
- if (offset + 1 < buffer.length)
- val = buffer[offset + 1] << 16;
- if (offset + 2 < buffer.length)
- val |= buffer[offset + 2] << 8;
- if (offset + 3 < buffer.length)
- val |= buffer[offset + 3];
- val = val + (buffer[offset] << 24 >>> 0);
- } else {
- if (offset + 2 < buffer.length)
- val = buffer[offset + 2] << 16;
- if (offset + 1 < buffer.length)
- val |= buffer[offset + 1] << 8;
- val |= buffer[offset];
- if (offset + 3 < buffer.length)
- val = val + (buffer[offset + 3] << 24 >>> 0);
- }
-
- return val;
-}
-
-Buffer.prototype.readUInt32LE = function(offset, noAssert) {
- return readUInt32(this, offset, false, noAssert);
-};
-
-Buffer.prototype.readUInt32BE = function(offset, noAssert) {
- return readUInt32(this, offset, true, noAssert);
-};
-
-
-/*
- * Signed integer types, yay team! A reminder on how two's complement actually
- * works. The first bit is the signed bit, i.e. tells us whether or not the
- * number should be positive or negative. If the two's complement value is
- * positive, then we're done, as it's equivalent to the unsigned representation.
- *
- * Now if the number is positive, you're pretty much done, you can just leverage
- * the unsigned translations and return those. Unfortunately, negative numbers
- * aren't quite that straightforward.
- *
- * At first glance, one might be inclined to use the traditional formula to
- * translate binary numbers between the positive and negative values in two's
- * complement. (Though it doesn't quite work for the most negative value)
- * Mainly:
- * - invert all the bits
- * - add one to the result
- *
- * Of course, this doesn't quite work in Javascript. Take for example the value
- * of -128. This could be represented in 16 bits (big-endian) as 0xff80. But of
- * course, Javascript will do the following:
- *
- * > ~0xff80
- * -65409
- *
- * Whoh there, Javascript, that's not quite right. But wait, according to
- * Javascript that's perfectly correct. When Javascript ends up seeing the
- * constant 0xff80, it has no notion that it is actually a signed number. It
- * assumes that we've input the unsigned value 0xff80. Thus, when it does the
- * binary negation, it casts it into a signed value, (positive 0xff80). Then
- * when you perform binary negation on that, it turns it into a negative number.
- *
- * Instead, we're going to have to use the following general formula, that works
- * in a rather Javascript friendly way. I'm glad we don't support this kind of
- * weird numbering scheme in the kernel.
- *
- * (BIT-MAX - (unsigned)val + 1) * -1
- *
- * The astute observer, may think that this doesn't make sense for 8-bit numbers
- * (really it isn't necessary for them). However, when you get 16-bit numbers,
- * you do. Let's go back to our prior example and see how this will look:
- *
- * (0xffff - 0xff80 + 1) * -1
- * (0x007f + 1) * -1
- * (0x0080) * -1
- */
-Buffer.prototype.readInt8 = function(offset, noAssert) {
- var buffer = this;
- var neg;
-
- if (!noAssert) {
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset < buffer.length,
- 'Trying to read beyond buffer length');
- }
-
- if (offset >= buffer.length) return;
-
- neg = buffer[offset] & 0x80;
- if (!neg) {
- return (buffer[offset]);
- }
-
- return ((0xff - buffer[offset] + 1) * -1);
-};
-
-function readInt16(buffer, offset, isBigEndian, noAssert) {
- var neg, val;
-
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset + 1 < buffer.length,
- 'Trying to read beyond buffer length');
- }
-
- val = readUInt16(buffer, offset, isBigEndian, noAssert);
- neg = val & 0x8000;
- if (!neg) {
- return val;
- }
-
- return (0xffff - val + 1) * -1;
-}
-
-Buffer.prototype.readInt16LE = function(offset, noAssert) {
- return readInt16(this, offset, false, noAssert);
-};
-
-Buffer.prototype.readInt16BE = function(offset, noAssert) {
- return readInt16(this, offset, true, noAssert);
-};
-
-function readInt32(buffer, offset, isBigEndian, noAssert) {
- var neg, val;
-
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
-
- val = readUInt32(buffer, offset, isBigEndian, noAssert);
- neg = val & 0x80000000;
- if (!neg) {
- return (val);
- }
-
- return (0xffffffff - val + 1) * -1;
-}
-
-Buffer.prototype.readInt32LE = function(offset, noAssert) {
- return readInt32(this, offset, false, noAssert);
-};
-
-Buffer.prototype.readInt32BE = function(offset, noAssert) {
- return readInt32(this, offset, true, noAssert);
-};
-
-function readFloat(buffer, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset + 3 < buffer.length,
- 'Trying to read beyond buffer length');
- }
-
- return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
- 23, 4);
-}
-
-Buffer.prototype.readFloatLE = function(offset, noAssert) {
- return readFloat(this, offset, false, noAssert);
-};
-
-Buffer.prototype.readFloatBE = function(offset, noAssert) {
- return readFloat(this, offset, true, noAssert);
-};
-
-function readDouble(buffer, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset + 7 < buffer.length,
- 'Trying to read beyond buffer length');
- }
-
- return require('./buffer_ieee754').readIEEE754(buffer, offset, isBigEndian,
- 52, 8);
-}
-
-Buffer.prototype.readDoubleLE = function(offset, noAssert) {
- return readDouble(this, offset, false, noAssert);
-};
-
-Buffer.prototype.readDoubleBE = function(offset, noAssert) {
- return readDouble(this, offset, true, noAssert);
-};
-
-
-/*
- * We have to make sure that the value is a valid integer. This means that it is
- * non-negative. It has no fractional component and that it does not exceed the
- * maximum allowed value.
- *
- * value The number to check for validity
- *
- * max The maximum value
- */
-function verifuint(value, max) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
-
- assert.ok(value >= 0,
- 'specified a negative value for writing an unsigned value');
-
- assert.ok(value <= max, 'value is larger than maximum value for type');
-
- assert.ok(Math.floor(value) === value, 'value has a fractional component');
-}
-
-Buffer.prototype.writeUInt8 = function(value, offset, noAssert) {
- var buffer = this;
-
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset < buffer.length,
- 'trying to write beyond buffer length');
-
- verifuint(value, 0xff);
- }
-
- if (offset < buffer.length) {
- buffer[offset] = value;
- }
-};
-
-function writeUInt16(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
-
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset + 1 < buffer.length,
- 'trying to write beyond buffer length');
-
- verifuint(value, 0xffff);
- }
-
- for (var i = 0; i < Math.min(buffer.length - offset, 2); i++) {
- buffer[offset + i] =
- (value & (0xff << (8 * (isBigEndian ? 1 - i : i)))) >>>
- (isBigEndian ? 1 - i : i) * 8;
- }
-
-}
-
-Buffer.prototype.writeUInt16LE = function(value, offset, noAssert) {
- writeUInt16(this, value, offset, false, noAssert);
-};
-
-Buffer.prototype.writeUInt16BE = function(value, offset, noAssert) {
- writeUInt16(this, value, offset, true, noAssert);
-};
-
-function writeUInt32(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
-
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset + 3 < buffer.length,
- 'trying to write beyond buffer length');
-
- verifuint(value, 0xffffffff);
- }
-
- for (var i = 0; i < Math.min(buffer.length - offset, 4); i++) {
- buffer[offset + i] =
- (value >>> (isBigEndian ? 3 - i : i) * 8) & 0xff;
- }
-}
-
-Buffer.prototype.writeUInt32LE = function(value, offset, noAssert) {
- writeUInt32(this, value, offset, false, noAssert);
-};
-
-Buffer.prototype.writeUInt32BE = function(value, offset, noAssert) {
- writeUInt32(this, value, offset, true, noAssert);
-};
-
-
-/*
- * We now move onto our friends in the signed number category. Unlike unsigned
- * numbers, we're going to have to worry a bit more about how we put values into
- * arrays. Since we are only worrying about signed 32-bit values, we're in
- * slightly better shape. Unfortunately, we really can't do our favorite binary
- * & in this system. It really seems to do the wrong thing. For example:
- *
- * > -32 & 0xff
- * 224
- *
- * What's happening above is really: 0xe0 & 0xff = 0xe0. However, the results of
- * this aren't treated as a signed number. Ultimately a bad thing.
- *
- * What we're going to want to do is basically create the unsigned equivalent of
- * our representation and pass that off to the wuint* functions. To do that
- * we're going to do the following:
- *
- * - if the value is positive
- * we can pass it directly off to the equivalent wuint
- * - if the value is negative
- * we do the following computation:
- * mb + val + 1, where
- * mb is the maximum unsigned value in that byte size
- * val is the Javascript negative integer
- *
- *
- * As a concrete value, take -128. In signed 16 bits this would be 0xff80. If
- * you do out the computations:
- *
- * 0xffff - 128 + 1
- * 0xffff - 127
- * 0xff80
- *
- * You can then encode this value as the signed version. This is really rather
- * hacky, but it should work and get the job done which is our goal here.
- */
-
-/*
- * A series of checks to make sure we actually have a signed 32-bit number
- */
-function verifsint(value, max, min) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
-
- assert.ok(value <= max, 'value larger than maximum allowed value');
-
- assert.ok(value >= min, 'value smaller than minimum allowed value');
-
- assert.ok(Math.floor(value) === value, 'value has a fractional component');
-}
-
-function verifIEEE754(value, max, min) {
- assert.ok(typeof (value) == 'number',
- 'cannot write a non-number as a number');
-
- assert.ok(value <= max, 'value larger than maximum allowed value');
-
- assert.ok(value >= min, 'value smaller than minimum allowed value');
-}
-
-Buffer.prototype.writeInt8 = function(value, offset, noAssert) {
- var buffer = this;
-
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset < buffer.length,
- 'Trying to write beyond buffer length');
-
- verifsint(value, 0x7f, -0x80);
- }
-
- if (value >= 0) {
- buffer.writeUInt8(value, offset, noAssert);
- } else {
- buffer.writeUInt8(0xff + value + 1, offset, noAssert);
- }
-};
-
-function writeInt16(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
-
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset + 1 < buffer.length,
- 'Trying to write beyond buffer length');
-
- verifsint(value, 0x7fff, -0x8000);
- }
-
- if (value >= 0) {
- writeUInt16(buffer, value, offset, isBigEndian, noAssert);
- } else {
- writeUInt16(buffer, 0xffff + value + 1, offset, isBigEndian, noAssert);
- }
-}
-
-Buffer.prototype.writeInt16LE = function(value, offset, noAssert) {
- writeInt16(this, value, offset, false, noAssert);
-};
-
-Buffer.prototype.writeInt16BE = function(value, offset, noAssert) {
- writeInt16(this, value, offset, true, noAssert);
-};
-
-function writeInt32(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
-
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset + 3 < buffer.length,
- 'Trying to write beyond buffer length');
-
- verifsint(value, 0x7fffffff, -0x80000000);
- }
-
- if (value >= 0) {
- writeUInt32(buffer, value, offset, isBigEndian, noAssert);
- } else {
- writeUInt32(buffer, 0xffffffff + value + 1, offset, isBigEndian, noAssert);
- }
-}
-
-Buffer.prototype.writeInt32LE = function(value, offset, noAssert) {
- writeInt32(this, value, offset, false, noAssert);
-};
-
-Buffer.prototype.writeInt32BE = function(value, offset, noAssert) {
- writeInt32(this, value, offset, true, noAssert);
-};
-
-function writeFloat(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
-
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset + 3 < buffer.length,
- 'Trying to write beyond buffer length');
-
- verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38);
- }
-
- require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
- 23, 4);
-}
-
-Buffer.prototype.writeFloatLE = function(value, offset, noAssert) {
- writeFloat(this, value, offset, false, noAssert);
-};
-
-Buffer.prototype.writeFloatBE = function(value, offset, noAssert) {
- writeFloat(this, value, offset, true, noAssert);
-};
-
-function writeDouble(buffer, value, offset, isBigEndian, noAssert) {
- if (!noAssert) {
- assert.ok(value !== undefined && value !== null,
- 'missing value');
-
- assert.ok(typeof (isBigEndian) === 'boolean',
- 'missing or invalid endian');
-
- assert.ok(offset !== undefined && offset !== null,
- 'missing offset');
-
- assert.ok(offset + 7 < buffer.length,
- 'Trying to write beyond buffer length');
-
- verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308);
- }
-
- require('./buffer_ieee754').writeIEEE754(buffer, value, offset, isBigEndian,
- 52, 8);
-}
-
-Buffer.prototype.writeDoubleLE = function(value, offset, noAssert) {
- writeDouble(this, value, offset, false, noAssert);
-};
-
-Buffer.prototype.writeDoubleBE = function(value, offset, noAssert) {
- writeDouble(this, value, offset, true, noAssert);
-};
-
-},{"./buffer_ieee754":7,"assert":2,"base64-js":9}],9:[function(require,module,exports){
-(function (exports) {
- 'use strict';
-
- var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
-
- function b64ToByteArray(b64) {
- var i, j, l, tmp, placeHolders, arr;
-
- if (b64.length % 4 > 0) {
- throw 'Invalid string. Length must be a multiple of 4';
- }
-
- // the number of equal signs (place holders)
- // if there are two placeholders, than the two characters before it
- // represent one byte
- // if there is only one, then the three characters before it represent 2 bytes
- // this is just a cheap hack to not do indexOf twice
- placeHolders = b64.indexOf('=');
- placeHolders = placeHolders > 0 ? b64.length - placeHolders : 0;
-
- // base64 is 4/3 + up to two characters of the original data
- arr = [];//new Uint8Array(b64.length * 3 / 4 - placeHolders);
-
- // if there are placeholders, only get up to the last complete 4 chars
- l = placeHolders > 0 ? b64.length - 4 : b64.length;
-
- for (i = 0, j = 0; i < l; i += 4, j += 3) {
- tmp = (lookup.indexOf(b64[i]) << 18) | (lookup.indexOf(b64[i + 1]) << 12) | (lookup.indexOf(b64[i + 2]) << 6) | lookup.indexOf(b64[i + 3]);
- arr.push((tmp & 0xFF0000) >> 16);
- arr.push((tmp & 0xFF00) >> 8);
- arr.push(tmp & 0xFF);
- }
-
- if (placeHolders === 2) {
- tmp = (lookup.indexOf(b64[i]) << 2) | (lookup.indexOf(b64[i + 1]) >> 4);
- arr.push(tmp & 0xFF);
- } else if (placeHolders === 1) {
- tmp = (lookup.indexOf(b64[i]) << 10) | (lookup.indexOf(b64[i + 1]) << 4) | (lookup.indexOf(b64[i + 2]) >> 2);
- arr.push((tmp >> 8) & 0xFF);
- arr.push(tmp & 0xFF);
- }
-
- return arr;
- }
-
- function uint8ToBase64(uint8) {
- var i,
- extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
- output = "",
- temp, length;
-
- function tripletToBase64 (num) {
- return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
- };
-
- // go through the array every three bytes, we'll deal with trailing stuff later
- for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
- temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]);
- output += tripletToBase64(temp);
- }
-
- // pad the end with zeros, but make sure to not forget the extra bytes
- switch (extraBytes) {
- case 1:
- temp = uint8[uint8.length - 1];
- output += lookup[temp >> 2];
- output += lookup[(temp << 4) & 0x3F];
- output += '==';
- break;
- case 2:
- temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]);
- output += lookup[temp >> 10];
- output += lookup[(temp >> 4) & 0x3F];
- output += lookup[(temp << 2) & 0x3F];
- output += '=';
- break;
- }
-
- return output;
- }
-
- module.exports.toByteArray = b64ToByteArray;
- module.exports.fromByteArray = uint8ToBase64;
-}());
-
-},{}],10:[function(require,module,exports){
-var Buffer = require('buffer').Buffer;
-var intSize = 4;
-var zeroBuffer = new Buffer(intSize); zeroBuffer.fill(0);
-var chrsz = 8;
-
-function toArray(buf, bigEndian) {
- if ((buf.length % intSize) !== 0) {
- var len = buf.length + (intSize - (buf.length % intSize));
- buf = Buffer.concat([buf, zeroBuffer], len);
- }
-
- var arr = [];
- var fn = bigEndian ? buf.readInt32BE : buf.readInt32LE;
- for (var i = 0; i < buf.length; i += intSize) {
- arr.push(fn.call(buf, i));
- }
- return arr;
-}
-
-function toBuffer(arr, size, bigEndian) {
- var buf = new Buffer(size);
- var fn = bigEndian ? buf.writeInt32BE : buf.writeInt32LE;
- for (var i = 0; i < arr.length; i++) {
- fn.call(buf, arr[i], i * 4, true);
- }
- return buf;
-}
-
-function hash(buf, fn, hashSize, bigEndian) {
- if (!Buffer.isBuffer(buf)) buf = new Buffer(buf);
- var arr = fn(toArray(buf, bigEndian), buf.length * chrsz);
- return toBuffer(arr, hashSize, bigEndian);
-}
-
-module.exports = { hash: hash };
-
-},{"buffer":8}],11:[function(require,module,exports){
-var Buffer = require('buffer').Buffer
-var sha = require('./sha')
-var sha256 = require('./sha256')
-var rng = require('./rng')
-var md5 = require('./md5')
-
-var algorithms = {
- sha1: sha,
- sha256: sha256,
- md5: md5
-}
-
-var blocksize = 64
-var zeroBuffer = new Buffer(blocksize); zeroBuffer.fill(0)
-function hmac(fn, key, data) {
- if(!Buffer.isBuffer(key)) key = new Buffer(key)
- if(!Buffer.isBuffer(data)) data = new Buffer(data)
-
- if(key.length > blocksize) {
- key = fn(key)
- } else if(key.length < blocksize) {
- key = Buffer.concat([key, zeroBuffer], blocksize)
- }
-
- var ipad = new Buffer(blocksize), opad = new Buffer(blocksize)
- for(var i = 0; i < blocksize; i++) {
- ipad[i] = key[i] ^ 0x36
- opad[i] = key[i] ^ 0x5C
- }
-
- var hash = fn(Buffer.concat([ipad, data]))
- return fn(Buffer.concat([opad, hash]))
-}
-
-function hash(alg, key) {
- alg = alg || 'sha1'
- var fn = algorithms[alg]
- var bufs = []
- var length = 0
- if(!fn) error('algorithm:', alg, 'is not yet supported')
- return {
- update: function (data) {
- bufs.push(data)
- length += data.length
- return this
- },
- digest: function (enc) {
- var buf = Buffer.concat(bufs)
- var r = key ? hmac(fn, key, buf) : fn(buf)
- bufs = null
- return enc ? r.toString(enc) : r
- }
- }
-}
-
-function error () {
- var m = [].slice.call(arguments).join(' ')
- throw new Error([
- m,
- 'we accept pull requests',
- 'http://github.com/dominictarr/crypto-browserify'
- ].join('\n'))
-}
-
-exports.createHash = function (alg) { return hash(alg) }
-exports.createHmac = function (alg, key) { return hash(alg, key) }
-exports.randomBytes = function(size, callback) {
- if (callback && callback.call) {
- try {
- callback.call(this, undefined, new Buffer(rng(size)))
- } catch (err) { callback(err) }
- } else {
- return new Buffer(rng(size))
- }
-}
-
-function each(a, f) {
- for(var i in a)
- f(a[i], i)
-}
-
-// the least I can do is make error messages for the rest of the node.js/crypto api.
-each(['createCredentials'
-, 'createCipher'
-, 'createCipheriv'
-, 'createDecipher'
-, 'createDecipheriv'
-, 'createSign'
-, 'createVerify'
-, 'createDiffieHellman'
-, 'pbkdf2'], function (name) {
- exports[name] = function () {
- error('sorry,', name, 'is not implemented yet')
- }
-})
-
-},{"./md5":12,"./rng":13,"./sha":14,"./sha256":15,"buffer":8}],12:[function(require,module,exports){
-/*
- * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
- * Digest Algorithm, as defined in RFC 1321.
- * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
- * Distributed under the BSD License
- * See http://pajhome.org.uk/crypt/md5 for more info.
- */
-
-var helpers = require('./helpers');
-
-/*
- * Perform a simple self-test to see if the VM is working
- */
-function md5_vm_test()
-{
- return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
-}
-
-/*
- * Calculate the MD5 of an array of little-endian words, and a bit length
- */
-function core_md5(x, len)
-{
- /* append padding */
- x[len >> 5] |= 0x80 << ((len) % 32);
- x[(((len + 64) >>> 9) << 4) + 14] = len;
-
- var a = 1732584193;
- var b = -271733879;
- var c = -1732584194;
- var d = 271733878;
-
- for(var i = 0; i < x.length; i += 16)
- {
- var olda = a;
- var oldb = b;
- var oldc = c;
- var oldd = d;
-
- a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
- d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
- c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
- b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
- a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
- d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
- c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
- b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
- a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
- d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
- c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
- b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
- a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
- d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
- c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
- b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
-
- a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
- d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
- c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
- b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
- a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
- d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
- c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
- b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
- a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
- d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
- c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
- b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
- a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
- d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
- c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
- b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
-
- a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
- d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
- c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
- b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
- a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
- d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
- c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
- b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
- a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
- d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
- c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
- b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
- a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
- d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
- c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
- b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
-
- a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
- d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
- c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
- b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
- a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
- d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
- c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
- b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
- a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
- d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
- c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
- b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
- a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
- d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
- c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
- b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
-
- a = safe_add(a, olda);
- b = safe_add(b, oldb);
- c = safe_add(c, oldc);
- d = safe_add(d, oldd);
- }
- return Array(a, b, c, d);
-
-}
-
-/*
- * These functions implement the four basic operations the algorithm uses.
- */
-function md5_cmn(q, a, b, x, s, t)
-{
- return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
-}
-function md5_ff(a, b, c, d, x, s, t)
-{
- return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
-}
-function md5_gg(a, b, c, d, x, s, t)
-{
- return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
-}
-function md5_hh(a, b, c, d, x, s, t)
-{
- return md5_cmn(b ^ c ^ d, a, b, x, s, t);
-}
-function md5_ii(a, b, c, d, x, s, t)
-{
- return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
-}
-
-/*
- * Add integers, wrapping at 2^32. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
- */
-function safe_add(x, y)
-{
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
- return (msw << 16) | (lsw & 0xFFFF);
-}
-
-/*
- * Bitwise rotate a 32-bit number to the left.
- */
-function bit_rol(num, cnt)
-{
- return (num << cnt) | (num >>> (32 - cnt));
-}
-
-module.exports = function md5(buf) {
- return helpers.hash(buf, core_md5, 16);
-};
-
-},{"./helpers":10}],13:[function(require,module,exports){
-// Original code adapted from Robert Kieffer.
-// details at https://github.com/broofa/node-uuid
-(function() {
- var _global = this;
-
- var mathRNG, whatwgRNG;
-
- // NOTE: Math.random() does not guarantee "cryptographic quality"
- mathRNG = function(size) {
- var bytes = new Array(size);
- var r;
-
- for (var i = 0, r; i < size; i++) {
- if ((i & 0x03) == 0) r = Math.random() * 0x100000000;
- bytes[i] = r >>> ((i & 0x03) << 3) & 0xff;
- }
-
- return bytes;
- }
-
- if (_global.crypto && crypto.getRandomValues) {
- var _rnds = new Uint32Array(4);
- whatwgRNG = function(size) {
- var bytes = new Array(size);
- crypto.getRandomValues(_rnds);
-
- for (var c = 0 ; c < size; c++) {
- bytes[c] = _rnds[c >> 2] >>> ((c & 0x03) * 8) & 0xff;
- }
- return bytes;
- }
- }
-
- module.exports = whatwgRNG || mathRNG;
-
-}())
-
-},{}],14:[function(require,module,exports){
-/*
- * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
- * in FIPS PUB 180-1
- * Version 2.1a Copyright Paul Johnston 2000 - 2002.
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
- * Distributed under the BSD License
- * See http://pajhome.org.uk/crypt/md5 for details.
- */
-
-var helpers = require('./helpers');
-
-/*
- * Perform a simple self-test to see if the VM is working
- */
-function sha1_vm_test()
-{
- return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
-}
-
-/*
- * Calculate the SHA-1 of an array of big-endian words, and a bit length
- */
-function core_sha1(x, len)
-{
- /* append padding */
- x[len >> 5] |= 0x80 << (24 - len % 32);
- x[((len + 64 >> 9) << 4) + 15] = len;
-
- var w = Array(80);
- var a = 1732584193;
- var b = -271733879;
- var c = -1732584194;
- var d = 271733878;
- var e = -1009589776;
-
- for(var i = 0; i < x.length; i += 16)
- {
- var olda = a;
- var oldb = b;
- var oldc = c;
- var oldd = d;
- var olde = e;
-
- for(var j = 0; j < 80; j++)
- {
- if(j < 16) w[j] = x[i + j];
- else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
- var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
- safe_add(safe_add(e, w[j]), sha1_kt(j)));
- e = d;
- d = c;
- c = rol(b, 30);
- b = a;
- a = t;
- }
-
- a = safe_add(a, olda);
- b = safe_add(b, oldb);
- c = safe_add(c, oldc);
- d = safe_add(d, oldd);
- e = safe_add(e, olde);
- }
- return Array(a, b, c, d, e);
-
-}
-
-/*
- * Perform the appropriate triplet combination function for the current
- * iteration
- */
-function sha1_ft(t, b, c, d)
-{
- if(t < 20) return (b & c) | ((~b) & d);
- if(t < 40) return b ^ c ^ d;
- if(t < 60) return (b & c) | (b & d) | (c & d);
- return b ^ c ^ d;
-}
-
-/*
- * Determine the appropriate additive constant for the current iteration
- */
-function sha1_kt(t)
-{
- return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
- (t < 60) ? -1894007588 : -899497514;
-}
-
-/*
- * Add integers, wrapping at 2^32. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
- */
-function safe_add(x, y)
-{
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
- return (msw << 16) | (lsw & 0xFFFF);
-}
-
-/*
- * Bitwise rotate a 32-bit number to the left.
- */
-function rol(num, cnt)
-{
- return (num << cnt) | (num >>> (32 - cnt));
-}
-
-module.exports = function sha1(buf) {
- return helpers.hash(buf, core_sha1, 20, true);
-};
-
-},{"./helpers":10}],15:[function(require,module,exports){
-
-/**
- * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
- * in FIPS 180-2
- * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
- *
- */
-
-var helpers = require('./helpers');
-
-var safe_add = function(x, y) {
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
- return (msw << 16) | (lsw & 0xFFFF);
-};
-
-var S = function(X, n) {
- return (X >>> n) | (X << (32 - n));
-};
-
-var R = function(X, n) {
- return (X >>> n);
-};
-
-var Ch = function(x, y, z) {
- return ((x & y) ^ ((~x) & z));
-};
-
-var Maj = function(x, y, z) {
- return ((x & y) ^ (x & z) ^ (y & z));
-};
-
-var Sigma0256 = function(x) {
- return (S(x, 2) ^ S(x, 13) ^ S(x, 22));
-};
-
-var Sigma1256 = function(x) {
- return (S(x, 6) ^ S(x, 11) ^ S(x, 25));
-};
-
-var Gamma0256 = function(x) {
- return (S(x, 7) ^ S(x, 18) ^ R(x, 3));
-};
-
-var Gamma1256 = function(x) {
- return (S(x, 17) ^ S(x, 19) ^ R(x, 10));
-};
-
-var core_sha256 = function(m, l) {
- var K = new Array(0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0xFC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x6CA6351,0x14292967,0x27B70A85,0x2E1B2138,0x4D2C6DFC,0x53380D13,0x650A7354,0x766A0ABB,0x81C2C92E,0x92722C85,0xA2BFE8A1,0xA81A664B,0xC24B8B70,0xC76C51A3,0xD192E819,0xD6990624,0xF40E3585,0x106AA070,0x19A4C116,0x1E376C08,0x2748774C,0x34B0BCB5,0x391C0CB3,0x4ED8AA4A,0x5B9CCA4F,0x682E6FF3,0x748F82EE,0x78A5636F,0x84C87814,0x8CC70208,0x90BEFFFA,0xA4506CEB,0xBEF9A3F7,0xC67178F2);
- var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
- var W = new Array(64);
- var a, b, c, d, e, f, g, h, i, j;
- var T1, T2;
- /* append padding */
- m[l >> 5] |= 0x80 << (24 - l % 32);
- m[((l + 64 >> 9) << 4) + 15] = l;
- for (var i = 0; i < m.length; i += 16) {
- a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7];
- for (var j = 0; j < 64; j++) {
- if (j < 16) {
- W[j] = m[j + i];
- } else {
- W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);
- }
- T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
- T2 = safe_add(Sigma0256(a), Maj(a, b, c));
- h = g; g = f; f = e; e = safe_add(d, T1); d = c; c = b; b = a; a = safe_add(T1, T2);
- }
- HASH[0] = safe_add(a, HASH[0]); HASH[1] = safe_add(b, HASH[1]); HASH[2] = safe_add(c, HASH[2]); HASH[3] = safe_add(d, HASH[3]);
- HASH[4] = safe_add(e, HASH[4]); HASH[5] = safe_add(f, HASH[5]); HASH[6] = safe_add(g, HASH[6]); HASH[7] = safe_add(h, HASH[7]);
- }
- return HASH;
-};
-
-module.exports = function sha256(buf) {
- return helpers.hash(buf, core_sha256, 32, true);
-};
-
-},{"./helpers":10}],16:[function(require,module,exports){
-// shim for using process in browser
-
-var process = module.exports = {};
-
-process.nextTick = (function () {
- var canSetImmediate = typeof window !== 'undefined'
- && window.setImmediate;
- var canPost = typeof window !== 'undefined'
- && window.postMessage && window.addEventListener
- ;
-
- if (canSetImmediate) {
- return function (f) { return window.setImmediate(f) };
- }
-
- if (canPost) {
- var queue = [];
- window.addEventListener('message', function (ev) {
- if (ev.source === window && ev.data === 'process-tick') {
- ev.stopPropagation();
- if (queue.length > 0) {
- var fn = queue.shift();
- fn();
- }
- }
- }, true);
-
- return function nextTick(fn) {
- queue.push(fn);
- window.postMessage('process-tick', '*');
- };
- }
-
- return function nextTick(fn) {
- setTimeout(fn, 0);
- };
-})();
-
-process.title = 'browser';
-process.browser = true;
-process.env = {};
-process.argv = [];
-
-process.binding = function (name) {
- throw new Error('process.binding is not supported');
-}
-
-// TODO(shtylman)
-process.cwd = function () { return '/' };
-process.chdir = function (dir) {
- throw new Error('process.chdir is not supported');
-};
-
-},{}],17:[function(require,module,exports){
-var Promise = require("../js/debug/bluebird.js");
-Promise.onPossiblyUnhandledRejection();(function (){
- var global = window;
- global.adapter = Promise;
- global.sinon = require("sinon");
- global.assert = require("assert");
- global.setImmediate = function(fn){
- setTimeout(fn, 0);
- };
-})();
-
-;window.tests = [{fn: function(){ return require('../test/mocha/2.1.2.js');}, name: '../test/mocha/2.1.2.js'},
-{fn: function(){ return require('../test/mocha/2.1.3.js');}, name: '../test/mocha/2.1.3.js'},
-{fn: function(){ return require('../test/mocha/2.2.1.js');}, name: '../test/mocha/2.2.1.js'},
-{fn: function(){ return require('../test/mocha/2.2.2.js');}, name: '../test/mocha/2.2.2.js'},
-{fn: function(){ return require('../test/mocha/2.2.3.js');}, name: '../test/mocha/2.2.3.js'},
-{fn: function(){ return require('../test/mocha/2.2.4.js');}, name: '../test/mocha/2.2.4.js'},
-{fn: function(){ return require('../test/mocha/2.2.5.js');}, name: '../test/mocha/2.2.5.js'},
-{fn: function(){ return require('../test/mocha/2.2.6.js');}, name: '../test/mocha/2.2.6.js'},
-{fn: function(){ return require('../test/mocha/2.2.7.js');}, name: '../test/mocha/2.2.7.js'},
-{fn: function(){ return require('../test/mocha/2.3.1.js');}, name: '../test/mocha/2.3.1.js'},
-{fn: function(){ return require('../test/mocha/2.3.2.js');}, name: '../test/mocha/2.3.2.js'},
-{fn: function(){ return require('../test/mocha/2.3.3.js');}, name: '../test/mocha/2.3.3.js'},
-{fn: function(){ return require('../test/mocha/2.3.4.js');}, name: '../test/mocha/2.3.4.js'},
-{fn: function(){ return require('../test/mocha/3.2.1.js');}, name: '../test/mocha/3.2.1.js'},
-{fn: function(){ return require('../test/mocha/3.2.2.js');}, name: '../test/mocha/3.2.2.js'},
-{fn: function(){ return require('../test/mocha/3.2.3.js');}, name: '../test/mocha/3.2.3.js'},
-{fn: function(){ return require('../test/mocha/3.2.4.js');}, name: '../test/mocha/3.2.4.js'},
-{fn: function(){ return require('../test/mocha/3.2.5.js');}, name: '../test/mocha/3.2.5.js'},
-{fn: function(){ return require('../test/mocha/3.2.6.js');}, name: '../test/mocha/3.2.6.js'},
-{fn: function(){ return require('../test/mocha/api_exceptions.js');}, name: '../test/mocha/api_exceptions.js'},
-{fn: function(){ return require('../test/mocha/async.js');}, name: '../test/mocha/async.js'},
-{fn: function(){ return require('../test/mocha/bind.js');}, name: '../test/mocha/bind.js'},
-{fn: function(){ return require('../test/mocha/bluebird-multiple-instances.js');}, name: '../test/mocha/bluebird-multiple-instances.js'},
-{fn: function(){ return require('../test/mocha/call.js');}, name: '../test/mocha/call.js'},
-{fn: function(){ return require('../test/mocha/cancel.js');}, name: '../test/mocha/cancel.js'},
-{fn: function(){ return require('../test/mocha/catch_filter.js');}, name: '../test/mocha/catch_filter.js'},
-{fn: function(){ return require('../test/mocha/collections_thenables.js');}, name: '../test/mocha/collections_thenables.js'},
-{fn: function(){ return require('../test/mocha/constructor.js');}, name: '../test/mocha/constructor.js'},
-{fn: function(){ return require('../test/mocha/cycles.js');}, name: '../test/mocha/cycles.js'},
-{fn: function(){ return require('../test/mocha/direct_resolving.js');}, name: '../test/mocha/direct_resolving.js'},
-{fn: function(){ return require('../test/mocha/domain.js');}, name: '../test/mocha/domain.js'},
-{fn: function(){ return require('../test/mocha/each.js');}, name: '../test/mocha/each.js'},
-{fn: function(){ return require('../test/mocha/error.js');}, name: '../test/mocha/error.js'},
-{fn: function(){ return require('../test/mocha/filter.js');}, name: '../test/mocha/filter.js'},
-{fn: function(){ return require('../test/mocha/following.js');}, name: '../test/mocha/following.js'},
-{fn: function(){ return require('../test/mocha/get.js');}, name: '../test/mocha/get.js'},
-{fn: function(){ return require('../test/mocha/github-2xx-76.js');}, name: '../test/mocha/github-2xx-76.js'},
-{fn: function(){ return require('../test/mocha/github-3.6.4.js');}, name: '../test/mocha/github-3.6.4.js'},
-{fn: function(){ return require('../test/mocha/github-3.7.3.js');}, name: '../test/mocha/github-3.7.3.js'},
-{fn: function(){ return require('../test/mocha/github36.js');}, name: '../test/mocha/github36.js'},
-{fn: function(){ return require('../test/mocha/late_buffer_safety.js');}, name: '../test/mocha/late_buffer_safety.js'},
-{fn: function(){ return require('../test/mocha/method.js');}, name: '../test/mocha/method.js'},
-{fn: function(){ return require('../test/mocha/promisify.js');}, name: '../test/mocha/promisify.js'},
-{fn: function(){ return require('../test/mocha/props.js');}, name: '../test/mocha/props.js'},
-{fn: function(){ return require('../test/mocha/q_all.js');}, name: '../test/mocha/q_all.js'},
-{fn: function(){ return require('../test/mocha/q_done.js');}, name: '../test/mocha/q_done.js'},
-{fn: function(){ return require('../test/mocha/q_fin.js');}, name: '../test/mocha/q_fin.js'},
-{fn: function(){ return require('../test/mocha/q_inspect.js');}, name: '../test/mocha/q_inspect.js'},
-{fn: function(){ return require('../test/mocha/q_make_node_resolver.js');}, name: '../test/mocha/q_make_node_resolver.js'},
-{fn: function(){ return require('../test/mocha/q_nodeify.js');}, name: '../test/mocha/q_nodeify.js'},
-{fn: function(){ return require('../test/mocha/q_progress.js');}, name: '../test/mocha/q_progress.js'},
-{fn: function(){ return require('../test/mocha/q_propagation.js');}, name: '../test/mocha/q_propagation.js'},
-{fn: function(){ return require('../test/mocha/q_settle.js');}, name: '../test/mocha/q_settle.js'},
-{fn: function(){ return require('../test/mocha/q_spread.js');}, name: '../test/mocha/q_spread.js'},
-{fn: function(){ return require('../test/mocha/race.js');}, name: '../test/mocha/race.js'},
-{fn: function(){ return require('../test/mocha/reduce.js');}, name: '../test/mocha/reduce.js'},
-{fn: function(){ return require('../test/mocha/reflect.js');}, name: '../test/mocha/reflect.js'},
-{fn: function(){ return require('../test/mocha/resolution.js');}, name: '../test/mocha/resolution.js'},
-{fn: function(){ return require('../test/mocha/reused_promise.js');}, name: '../test/mocha/reused_promise.js'},
-{fn: function(){ return require('../test/mocha/schedule.js');}, name: '../test/mocha/schedule.js'},
-{fn: function(){ return require('../test/mocha/some.js');}, name: '../test/mocha/some.js'},
-{fn: function(){ return require('../test/mocha/tap.js');}, name: '../test/mocha/tap.js'},
-{fn: function(){ return require('../test/mocha/timers.js');}, name: '../test/mocha/timers.js'},
-{fn: function(){ return require('../test/mocha/try.js');}, name: '../test/mocha/try.js'},
-{fn: function(){ return require('../test/mocha/unhandled_rejections.js');}, name: '../test/mocha/unhandled_rejections.js'},
-{fn: function(){ return require('../test/mocha/using.js');}, name: '../test/mocha/using.js'},
-{fn: function(){ return require('../test/mocha/when_all.js');}, name: '../test/mocha/when_all.js'},
-{fn: function(){ return require('../test/mocha/when_any.js');}, name: '../test/mocha/when_any.js'},
-{fn: function(){ return require('../test/mocha/when_defer.js');}, name: '../test/mocha/when_defer.js'},
-{fn: function(){ return require('../test/mocha/when_join.js');}, name: '../test/mocha/when_join.js'},
-{fn: function(){ return require('../test/mocha/when_map.js');}, name: '../test/mocha/when_map.js'},
-{fn: function(){ return require('../test/mocha/when_reduce.js');}, name: '../test/mocha/when_reduce.js'},
-{fn: function(){ return require('../test/mocha/when_settle.js');}, name: '../test/mocha/when_settle.js'},
-{fn: function(){ return require('../test/mocha/when_some.js');}, name: '../test/mocha/when_some.js'},
-{fn: function(){ return require('../test/mocha/when_spread.js');}, name: '../test/mocha/when_spread.js'}];
-},{"../js/debug/bluebird.js":21,"../test/mocha/2.1.2.js":70,"../test/mocha/2.1.3.js":71,"../test/mocha/2.2.1.js":72,"../test/mocha/2.2.2.js":73,"../test/mocha/2.2.3.js":74,"../test/mocha/2.2.4.js":75,"../test/mocha/2.2.5.js":76,"../test/mocha/2.2.6.js":77,"../test/mocha/2.2.7.js":78,"../test/mocha/2.3.1.js":79,"../test/mocha/2.3.2.js":80,"../test/mocha/2.3.3.js":81,"../test/mocha/2.3.4.js":82,"../test/mocha/3.2.1.js":83,"../test/mocha/3.2.2.js":84,"../test/mocha/3.2.3.js":85,"../test/mocha/3.2.4.js":86,"../test/mocha/3.2.5.js":87,"../test/mocha/3.2.6.js":88,"../test/mocha/api_exceptions.js":89,"../test/mocha/async.js":90,"../test/mocha/bind.js":91,"../test/mocha/bluebird-multiple-instances.js":92,"../test/mocha/call.js":93,"../test/mocha/cancel.js":94,"../test/mocha/catch_filter.js":95,"../test/mocha/collections_thenables.js":96,"../test/mocha/constructor.js":97,"../test/mocha/cycles.js":98,"../test/mocha/direct_resolving.js":99,"../test/mocha/domain.js":100,"../test/mocha/each.js":101,"../test/mocha/error.js":102,"../test/mocha/filter.js":103,"../test/mocha/following.js":104,"../test/mocha/get.js":105,"../test/mocha/github-2xx-76.js":106,"../test/mocha/github-3.6.4.js":107,"../test/mocha/github-3.7.3.js":108,"../test/mocha/github36.js":109,"../test/mocha/late_buffer_safety.js":114,"../test/mocha/method.js":115,"../test/mocha/promisify.js":116,"../test/mocha/props.js":117,"../test/mocha/q_all.js":118,"../test/mocha/q_done.js":119,"../test/mocha/q_fin.js":120,"../test/mocha/q_inspect.js":121,"../test/mocha/q_make_node_resolver.js":122,"../test/mocha/q_nodeify.js":123,"../test/mocha/q_progress.js":124,"../test/mocha/q_propagation.js":125,"../test/mocha/q_settle.js":126,"../test/mocha/q_spread.js":127,"../test/mocha/race.js":128,"../test/mocha/reduce.js":129,"../test/mocha/reflect.js":130,"../test/mocha/resolution.js":131,"../test/mocha/reused_promise.js":132,"../test/mocha/schedule.js":133,"../test/mocha/some.js":134,"../test/mocha/tap.js":135,"../test/mocha/timers.js":136,"../test/mocha/try.js":137,"../test/mocha/unhandled_rejections.js":138,"../test/mocha/using.js":139,"../test/mocha/when_all.js":140,"../test/mocha/when_any.js":141,"../test/mocha/when_defer.js":142,"../test/mocha/when_join.js":143,"../test/mocha/when_map.js":144,"../test/mocha/when_reduce.js":145,"../test/mocha/when_settle.js":146,"../test/mocha/when_some.js":147,"../test/mocha/when_spread.js":148,"assert":2,"sinon":55}],18:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise) {
-var SomePromiseArray = Promise._SomePromiseArray;
-var ASSERT = require("./assert.js");
-
-function any(promises) {
- var ret = new SomePromiseArray(promises);
- var promise = ret.promise();
- if (promise.isRejected()) {
- return promise;
- }
- ASSERT((ret instanceof SomePromiseArray),
- "ret instanceof SomePromiseArray");
- ret.setHowMany(1);
- ret.setUnwrap();
- ret.init();
- return promise;
-}
-
-Promise.any = function (promises) {
- return any(promises);
-};
-
-Promise.prototype.any = function () {
- return any(this);
-};
-
-};
-
-},{"./assert.js":19}],19:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = (function(){
-var AssertionError = (function() {
- function AssertionError(a) {
- this.constructor$(a);
- this.message = a;
- this.name = "AssertionError";
- }
- AssertionError.prototype = new Error();
- AssertionError.prototype.constructor = AssertionError;
- AssertionError.prototype.constructor$ = Error;
- return AssertionError;
-})();
-
-function getParams(args) {
- var params = [];
- for (var i = 0; i < args.length; ++i) params.push("arg" + i);
- return params;
-}
-
-function nativeAssert(callName, args, expect) {
- try {
- var params = getParams(args);
- var constructorArgs = params;
- constructorArgs.push("return " +
- callName + "("+ params.join(",") + ");");
- var fn = Function.apply(null, constructorArgs);
- return fn.apply(null, args);
- } catch (e) {
- if (!(e instanceof SyntaxError)) {
- throw e;
- } else {
- return expect;
- }
- }
-}
-
-return function assert(boolExpr, message) {
- if (boolExpr === true) return;
-
- if (typeof boolExpr === "string" &&
- boolExpr.charAt(0) === "%") {
- var nativeCallName = boolExpr;
- var $_len = arguments.length;var args = new Array($_len - 2); for(var $_i = 2; $_i < $_len; ++$_i) {args[$_i - 2] = arguments[$_i];}
- if (nativeAssert(nativeCallName, args, message) === message) return;
- message = (nativeCallName + " !== " + message);
- }
-
- var ret = new AssertionError(message);
- if (Error.captureStackTrace) {
- Error.captureStackTrace(ret, assert);
- }
- if (console && console.error) {
- console.error(ret.stack + "");
- }
- throw ret;
-
-};
-})();
-
-},{}],20:[function(require,module,exports){
-var process=require("__browserify_process");/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var firstLineError = new Error();
-var ASSERT = require("./assert.js");
-var schedule = require("./schedule.js");
-var Queue = require("./queue.js");
-var errorObj = require("./util.js").errorObj;
-var tryCatch1 = require("./util.js").tryCatch1;
-var _process = typeof process !== "undefined" ? process : undefined;
-
-function Async() {
- this._isTickUsed = false;
- this._schedule = schedule;
- this._lateBuffer = new Queue(16);
- this._functionBuffer = new Queue(65536);
- var self = this;
- this.consumeFunctionBuffer = function () {
- self._consumeFunctionBuffer();
- };
-}
-
-Async.prototype.haveItemsQueued = function () {
- return this._functionBuffer.length() > 0;
-};
-
-Async.prototype.invokeLater = function (fn, receiver, arg) {
- ASSERT(((typeof fn) === "function"),
- "typeof fn === \u0022function\u0022");
- ASSERT((arguments.length === 3),
- "arguments.length === 3");
- if (_process !== undefined &&
- _process.domain != null &&
- !fn.domain) {
- fn = _process.domain.bind(fn);
- }
- this._lateBuffer.push(fn, receiver, arg);
- this._queueTick();
-};
-
-Async.prototype._withDomain = function(fn) {
- ASSERT(((typeof fn) === "function"),
- "typeof fn === \u0022function\u0022");
- if (_process !== undefined &&
- _process.domain != null &&
- !fn.domain) {
- fn = _process.domain.bind(fn);
- }
- return fn;
-};
-
-Async.prototype.invokeFirst = function (fn, receiver, arg) {
- ASSERT((arguments.length === 3),
- "arguments.length === 3");
- fn = this._withDomain(fn);
- this._functionBuffer.unshift(fn, receiver, arg);
- this._queueTick();
-};
-
-Async.prototype.invoke = function (fn, receiver, arg) {
- ASSERT((arguments.length === 3),
- "arguments.length === 3");
- fn = this._withDomain(fn);
- this._functionBuffer.push(fn, receiver, arg);
- this._queueTick();
-};
-
-Async.prototype._consumeFunctionBuffer = function () {
- var functionBuffer = this._functionBuffer;
- ASSERT(this._isTickUsed,
- "this._isTickUsed");
- while (functionBuffer.length() > 0) {
- var fn = functionBuffer.shift();
- var receiver = functionBuffer.shift();
- var arg = functionBuffer.shift();
- fn.call(receiver, arg);
- }
- this._reset();
- this._consumeLateBuffer();
-};
-
-Async.prototype._consumeLateBuffer = function () {
- var buffer = this._lateBuffer;
- while(buffer.length() > 0) {
- var fn = buffer.shift();
- var receiver = buffer.shift();
- var arg = buffer.shift();
- var res = tryCatch1(fn, receiver, arg);
- if (res === errorObj) {
- this._queueTick();
- if (fn.domain != null) {
- fn.domain.emit("error", res.e);
- } else {
- throw res.e;
- }
- }
- }
-};
-
-Async.prototype._queueTick = function () {
- if (!this._isTickUsed) {
- this._isTickUsed = true;
- this._schedule(this.consumeFunctionBuffer);
- }
-};
-
-Async.prototype._reset = function () {
- this._isTickUsed = false;
-};
-
-module.exports = new Async();
-module.exports.firstLineError = firstLineError;
-
-},{"./assert.js":19,"./queue.js":43,"./schedule.js":46,"./util.js":53,"__browserify_process":16}],21:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var old;
-if (typeof Promise !== "undefined") old = Promise;
-function noConflict(bluebird) {
- try { if (Promise === bluebird) Promise = old; }
- catch (e) {}
- return bluebird;
-}
-module.exports = require("./promise.js")();
-module.exports.noConflict = noConflict;
-
-},{"./promise.js":38}],22:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var cr = Object.create;
-if (cr) {
- var callerCache = cr(null);
- var getterCache = cr(null);
- callerCache[" size"] = getterCache[" size"] = 0;
-}
-
-module.exports = function(Promise) {
-var util = require("./util.js");
-var canEvaluate = util.canEvaluate;
-var isIdentifier = util.isIdentifier;
-
-function makeMethodCaller (methodName) {
- return new Function("obj", " \n\
- 'use strict' \n\
- var len = this.length; \n\
- switch(len) { \n\
- case 1: return obj.methodName(this[0]); \n\
- case 2: return obj.methodName(this[0], this[1]); \n\
- case 3: return obj.methodName(this[0], this[1], this[2]); \n\
- case 0: return obj.methodName(); \n\
- default: return obj.methodName.apply(obj, this); \n\
- } \n\
- ".replace(/methodName/g, methodName));
-}
-
-function makeGetter (propertyName) {
- return new Function("obj", " \n\
- 'use strict'; \n\
- return obj.propertyName; \n\
- ".replace("propertyName", propertyName));
-}
-
-function getCompiled(name, compiler, cache) {
- var ret = cache[name];
- if (typeof ret !== "function") {
- if (!isIdentifier(name)) {
- return null;
- }
- ret = compiler(name);
- cache[name] = ret;
- cache[" size"]++;
- if (cache[" size"] > 512) {
- var keys = Object.keys(cache);
- for (var i = 0; i < 256; ++i) delete cache[keys[i]];
- cache[" size"] = keys.length - 256;
- }
- }
- return ret;
-}
-
-function getMethodCaller(name) {
- return getCompiled(name, makeMethodCaller, callerCache);
-}
-
-function getGetter(name) {
- return getCompiled(name, makeGetter, getterCache);
-}
-
-function caller(obj) {
- return obj[this.pop()].apply(obj, this);
-}
-Promise.prototype.call = function (methodName) {
- var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
- if (canEvaluate) {
- var maybeCaller = getMethodCaller(methodName);
- if (maybeCaller !== null) {
- return this._then(
- maybeCaller, undefined, undefined, args, undefined);
- }
- }
- args.push(methodName);
- return this._then(caller, undefined, undefined, args, undefined);
-};
-
-function namedGetter(obj) {
- return obj[this];
-}
-function indexedGetter(obj) {
- return obj[this];
-}
-Promise.prototype.get = function (propertyName) {
- var isIndex = (typeof propertyName === "number");
- var getter;
- if (!isIndex) {
- if (canEvaluate) {
- var maybeGetter = getGetter(propertyName);
- getter = maybeGetter !== null ? maybeGetter : namedGetter;
- } else {
- getter = namedGetter;
- }
- } else {
- getter = indexedGetter;
- }
- return this._then(getter, undefined, undefined, propertyName, undefined);
-};
-};
-
-},{"./util.js":53}],23:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, INTERNAL) {
-var errors = require("./errors.js");
-var canAttachTrace = errors.canAttachTrace;
-var async = require("./async.js");
-var ASSERT = require("./assert.js");
-var CancellationError = errors.CancellationError;
-
-Promise.prototype._cancel = function (reason) {
- if (!this.isCancellable()) return this;
- var parent;
- var promiseToReject = this;
- while ((parent = promiseToReject._cancellationParent) !== undefined &&
- parent.isCancellable()) {
- promiseToReject = parent;
- }
- ASSERT(promiseToReject.isCancellable(),
- "promiseToReject.isCancellable()");
- this._unsetCancellable();
- promiseToReject._attachExtraTrace(reason);
- promiseToReject._rejectUnchecked(reason);
-};
-
-Promise.prototype.cancel = function (reason) {
- if (!this.isCancellable()) return this;
- reason = reason !== undefined
- ? (canAttachTrace(reason) ? reason : new Error(reason + ""))
- : new CancellationError();
- async.invokeLater(this._cancel, this, reason);
- return this;
-};
-
-Promise.prototype.cancellable = function () {
- if (this._cancellable()) return this;
- this._setCancellable();
- this._cancellationParent = undefined;
- return this;
-};
-
-Promise.prototype.uncancellable = function () {
- var ret = new Promise(INTERNAL);
- ret._propagateFrom(this, 2 | 4);
- ret._follow(this);
- ret._unsetCancellable();
- return ret;
-};
-
-Promise.prototype.fork = function (didFulfill, didReject, didProgress) {
- var ret = this._then(didFulfill, didReject, didProgress,
- undefined, undefined);
-
- ret._setCancellable();
- ret._cancellationParent = undefined;
- return ret;
-};
-};
-
-},{"./assert.js":19,"./async.js":20,"./errors.js":28}],24:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function() {
-var ASSERT = require("./assert.js");
-var inherits = require("./util.js").inherits;
-var defineProperty = require("./es5.js").defineProperty;
-var rtraceline = null;
-var formatStack = null;
-
-function CapturedTrace(parent) {
- ASSERT(((parent === undefined) || (parent instanceof CapturedTrace)),
- "parent === undefined || parent instanceof CapturedTrace");
- this._parent = parent;
- captureStackTrace(this, CapturedTrace);
-
-}
-inherits(CapturedTrace, Error);
-
-CapturedTrace.prototype.parent = function() {
- return this._parent;
-};
-
-CapturedTrace.prototype.setParent = function(parent) {
- if (parent === this) return;
- ASSERT((parent instanceof CapturedTrace),
- "parent instanceof CapturedTrace");
- this._parent = parent;
-};
-
-CapturedTrace.prototype.hasParent = function() {
- return this._parent !== undefined;
-};
-
-CapturedTrace.prototype.attachExtraTrace = function(error) {
- var trace = this;
- var stack = error.stack;
- stack = typeof stack === "string" ? stack.split("\n") : [];
- this.protectErrorMessageNewlines(stack);
- var headerLineCount = 1;
- var combinedTraces = 1;
-
- do {
- stack = trace.combine(stack);
- combinedTraces++;
- } while ((trace = trace.parent()) != null);
-
- var stackTraceLimit = Error.stackTraceLimit || 10;
- var max = (stackTraceLimit + headerLineCount) * combinedTraces;
- var len = stack.length;
- if (len > max) {
- stack.length = max;
- }
-
- if (len > 0)
- stack[0] = stack[0].split("\u0002\u0000\u0001").join("\n");
-
- if (stack.length <= headerLineCount) {
- error.stack = "(No stack trace)";
- } else {
- error.stack = stack.join("\n");
- }
-};
-
-CapturedTrace.prototype.combine = function(current) {
- var prev = this.stack.split("\n");
- var currentLastIndex = current.length - 1;
- var currentLastLine = current[currentLastIndex];
- var commonRootMeetPoint = -1;
- for (var i = prev.length - 1; i >= 0; --i) {
- if (prev[i] === currentLastLine) {
- commonRootMeetPoint = i;
- break;
- }
- }
-
- for (var i = commonRootMeetPoint; i >= 0; --i) {
- var line = prev[i];
- if (current[currentLastIndex] === line) {
- current.pop();
- currentLastIndex--;
- } else {
- break;
- }
- }
-
- current.push("From previous event:");
- var lines = current.concat(prev);
-
- var ret = [];
-
- for (var i = 0, len = lines.length; i < len; ++i) {
- if (((rtraceline.test(lines[i]) && shouldIgnore(lines[i])) ||
- (i > 0 && !rtraceline.test(lines[i])) &&
- lines[i] !== "From previous event:")
- ) {
- continue;
- }
- ret.push(lines[i]);
- }
- return ret;
-};
-
-CapturedTrace.prototype.protectErrorMessageNewlines = function(stack) {
- for (var i = 0; i < stack.length; ++i) {
- if (rtraceline.test(stack[i])) {
- break;
- }
- }
-
- if (i <= 1) return;
-
- var errorMessageLines = [];
- for (var j = 0; j < i; ++j) {
- errorMessageLines.push(stack.shift());
- }
- stack.unshift(errorMessageLines.join("\u0002\u0000\u0001"));
-};
-
-CapturedTrace.formatAndLogError = function(error, title) {
- if (typeof console === "object") {
- var message;
- if (typeof error === "object" || typeof error === "function") {
- var stack = error.stack;
- message = title + formatStack(stack, error);
- } else {
- message = title + String(error);
- }
- if (typeof console.warn === "function" ||
- typeof console.warn === "object") {
- console.warn(message);
- } else if (typeof console.log === "function" ||
- typeof console.log === "object") {
- console.log(message);
- }
- }
-};
-
-CapturedTrace.unhandledRejection = function (reason) {
- CapturedTrace.formatAndLogError(
- reason, "^--- With additional stack trace: ");
-};
-
-CapturedTrace.possiblyUnhandledRejection = function (reason) {
- CapturedTrace.formatAndLogError(
- reason, "Possibly unhandled ");
-};
-
-CapturedTrace.isSupported = function () {
- return typeof captureStackTrace === "function";
-};
-
-function formatNonError(obj) {
- var str;
- if (typeof obj === "function") {
- str = "[function " +
- (obj.name || "anonymous") +
- "]";
- } else {
- str = obj.toString();
- var ruselessToString = /\[object [a-zA-Z0-9$_]+\]/;
- if (ruselessToString.test(str)) {
- try {
- var newStr = JSON.stringify(obj);
- str = newStr;
- }
- catch(e) {
-
- }
- }
- if (str.length === 0) {
- str = "(empty array)";
- }
- }
- return ("(<" + snip(str) + ">, no stack trace)");
-}
-
-function snip(str) {
- var maxChars = 41;
- if (str.length < maxChars) {
- return str;
- }
- return str.substr(0, maxChars - 3) + "...";
-}
-
-var shouldIgnore = function() { return false; };
-var parseLineInfoRegex = /[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;
-function parseLineInfo(line) {
- var matches = line.match(parseLineInfoRegex);
- if (matches) {
- return {
- fileName: matches[1],
- line: parseInt(matches[2], 10)
- };
- }
-}
-CapturedTrace.setBounds = function(firstLineError, lastLineError) {
- if (!CapturedTrace.isSupported()) return;
- var firstStackLines = firstLineError.stack.split("\n");
- var lastStackLines = lastLineError.stack.split("\n");
- var firstIndex = -1;
- var lastIndex = -1;
- var firstFileName;
- var lastFileName;
- for (var i = 0; i < firstStackLines.length; ++i) {
- var result = parseLineInfo(firstStackLines[i]);
- if (result) {
- firstFileName = result.fileName;
- firstIndex = result.line;
- break;
- }
- }
- for (var i = 0; i < lastStackLines.length; ++i) {
- var result = parseLineInfo(lastStackLines[i]);
- if (result) {
- lastFileName = result.fileName;
- lastIndex = result.line;
- break;
- }
- }
- if (firstIndex < 0 || lastIndex < 0 || !firstFileName || !lastFileName ||
- firstFileName !== lastFileName || firstIndex >= lastIndex) {
- return;
- }
-
- shouldIgnore = function(line) {
- var info = parseLineInfo(line);
- if (info) {
- if (info.fileName === firstFileName &&
- (firstIndex <= info.line && info.line <= lastIndex)) {
- return true;
- }
- }
- return false;
- };
-};
-
-var captureStackTrace = (function stackDetection() {
- if (typeof Error.stackTraceLimit === "number" &&
- typeof Error.captureStackTrace === "function") {
- rtraceline = /^\s*at\s*/;
- formatStack = function(stack, error) {
- ASSERT((error !== null),
- "error !== null");
-
- if (typeof stack === "string") return stack;
-
- if (error.name !== undefined &&
- error.message !== undefined) {
- return error.name + ". " + error.message;
- }
- return formatNonError(error);
-
-
- };
- var captureStackTrace = Error.captureStackTrace;
- var bluebirdRegexp = /[\\\/]bluebird[\\\/]js[\\\/](main|debug|zalgo)/;
- shouldIgnore = function(line) {
- return bluebirdRegexp.test(line);
- };
- return function(receiver, ignoreUntil) {
- captureStackTrace(receiver, ignoreUntil);
- };
- }
- var err = new Error();
-
- if (typeof err.stack === "string" &&
- typeof "".startsWith === "function" &&
- (err.stack.startsWith("stackDetection@")) &&
- stackDetection.name === "stackDetection") {
-
- defineProperty(Error, "stackTraceLimit", {
- writable: true,
- enumerable: false,
- configurable: false,
- value: 25
- });
- rtraceline = /@/;
- var rline = /[@\n]/;
-
- formatStack = function(stack, error) {
- if (typeof stack === "string") {
- return (error.name + ". " + error.message + "\n" + stack);
- }
-
- if (error.name !== undefined &&
- error.message !== undefined) {
- return error.name + ". " + error.message;
- }
- return formatNonError(error);
- };
-
- return function captureStackTrace(o) {
- var stack = new Error().stack;
- var split = stack.split(rline);
- var len = split.length;
- var ret = "";
- for (var i = 0; i < len; i += 2) {
- ret += split[i];
- ret += "@";
- ret += split[i + 1];
- ret += "\n";
- }
- o.stack = ret;
- };
- } else {
- formatStack = function(stack, error) {
- if (typeof stack === "string") return stack;
-
- if ((typeof error === "object" ||
- typeof error === "function") &&
- error.name !== undefined &&
- error.message !== undefined) {
- return error.name + ". " + error.message;
- }
- return formatNonError(error);
- };
-
- return null;
- }
-})();
-
-return CapturedTrace;
-};
-
-},{"./assert.js":19,"./es5.js":30,"./util.js":53}],25:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(NEXT_FILTER) {
-var util = require("./util.js");
-var errors = require("./errors.js");
-var tryCatch1 = util.tryCatch1;
-var errorObj = util.errorObj;
-var keys = require("./es5.js").keys;
-var TypeError = errors.TypeError;
-
-function CatchFilter(instances, callback, promise) {
- this._instances = instances;
- this._callback = callback;
- this._promise = promise;
-}
-
-function safePredicate(predicate, e) {
- var safeObject = {};
- var retfilter = tryCatch1(predicate, safeObject, e);
-
- if (retfilter === errorObj) return retfilter;
-
- var safeKeys = keys(safeObject);
- if (safeKeys.length) {
- errorObj.e = new TypeError("Catch filter must inherit from Error or be a simple predicate function\u000a\u000a See http://goo.gl/o84o68\u000a");
- return errorObj;
- }
- return retfilter;
-}
-
-CatchFilter.prototype.doFilter = function (e) {
- var cb = this._callback;
- var promise = this._promise;
- var boundTo = promise._boundTo;
- for (var i = 0, len = this._instances.length; i < len; ++i) {
- var item = this._instances[i];
- var itemIsErrorType = item === Error ||
- (item != null && item.prototype instanceof Error);
-
- if (itemIsErrorType && e instanceof item) {
- var ret = tryCatch1(cb, boundTo, e);
- if (ret === errorObj) {
- NEXT_FILTER.e = ret.e;
- return NEXT_FILTER;
- }
- return ret;
- } else if (typeof item === "function" && !itemIsErrorType) {
- var shouldHandle = safePredicate(item, e);
- if (shouldHandle === errorObj) {
- var trace = errors.canAttachTrace(errorObj.e)
- ? errorObj.e
- : new Error(errorObj.e + "");
- this._promise._attachExtraTrace(trace);
- e = errorObj.e;
- break;
- } else if (shouldHandle) {
- var ret = tryCatch1(cb, boundTo, e);
- if (ret === errorObj) {
- NEXT_FILTER.e = ret.e;
- return NEXT_FILTER;
- }
- return ret;
- }
- }
- }
- NEXT_FILTER.e = e;
- return NEXT_FILTER;
-};
-
-return CatchFilter;
-};
-
-},{"./errors.js":28,"./es5.js":30,"./util.js":53}],26:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var util = require("./util.js");
-var ASSERT = require("./assert.js");
-var isPrimitive = util.isPrimitive;
-var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
-
-module.exports = function(Promise) {
-var returner = function () {
- return this;
-};
-var thrower = function () {
- throw this;
-};
-
-var wrapper = function (value, action) {
- if (action === 1) {
- return function () {
- throw value;
- };
- } else if (action === 2) {
- return function () {
- return value;
- };
- }
- ASSERT(false,
- "false");
-};
-
-
-Promise.prototype["return"] =
-Promise.prototype.thenReturn = function (value) {
- if (wrapsPrimitiveReceiver && isPrimitive(value)) {
- return this._then(
- wrapper(value, 2),
- undefined,
- undefined,
- undefined,
- undefined
- );
- }
- return this._then(returner, undefined, undefined, value, undefined);
-};
-
-Promise.prototype["throw"] =
-Promise.prototype.thenThrow = function (reason) {
- if (wrapsPrimitiveReceiver && isPrimitive(reason)) {
- return this._then(
- wrapper(reason, 1),
- undefined,
- undefined,
- undefined,
- undefined
- );
- }
- return this._then(thrower, undefined, undefined, reason, undefined);
-};
-};
-
-},{"./assert.js":19,"./util.js":53}],27:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, INTERNAL) {
-var PromiseReduce = Promise.reduce;
-
-Promise.prototype.each = function (fn) {
- return PromiseReduce(this, fn, null, INTERNAL);
-};
-
-Promise.each = function (promises, fn) {
- return PromiseReduce(promises, fn, null, INTERNAL);
-};
-};
-
-},{}],28:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var Objectfreeze = require("./es5.js").freeze;
-var propertyIsWritable = require("./es5.js").propertyIsWritable;
-var util = require("./util.js");
-var inherits = util.inherits;
-var notEnumerableProp = util.notEnumerableProp;
-
-function markAsOriginatingFromRejection(e) {
- try {
- notEnumerableProp(e, "isOperational", true);
- }
- catch(ignore) {}
-}
-
-function originatesFromRejection(e) {
- if (e == null) return false;
- return ((e instanceof OperationalError) ||
- e["isOperational"] === true);
-}
-
-function isError(obj) {
- return obj instanceof Error;
-}
-
-function canAttachTrace(obj) {
- return isError(obj) && propertyIsWritable(obj, "stack");
-}
-
-function subError(nameProperty, defaultMessage) {
- function SubError(message) {
- if (!(this instanceof SubError)) return new SubError(message);
- notEnumerableProp(this, "message",
- typeof message === "string" ? message : defaultMessage);
- notEnumerableProp(this, "name", nameProperty);
- if (Error.captureStackTrace) {
- Error.captureStackTrace(this, this.constructor);
- }
- }
- inherits(SubError, Error);
- return SubError;
-}
-
-var _TypeError, _RangeError;
-var CancellationError = subError("CancellationError", "cancellation error");
-var TimeoutError = subError("TimeoutError", "timeout error");
-var AggregateError = subError("AggregateError", "aggregate error");
-try {
- _TypeError = TypeError;
- _RangeError = RangeError;
-} catch(e) {
- _TypeError = subError("TypeError", "type error");
- _RangeError = subError("RangeError", "range error");
-}
-
-var methods = ("join pop push shift unshift slice filter forEach some " +
- "every map indexOf lastIndexOf reduce reduceRight sort reverse").split(" ");
-
-for (var i = 0; i < methods.length; ++i) {
- if (typeof Array.prototype[methods[i]] === "function") {
- AggregateError.prototype[methods[i]] = Array.prototype[methods[i]];
- }
-}
-
-AggregateError.prototype.length = 0;
-AggregateError.prototype["isOperational"] = true;
-var level = 0;
-AggregateError.prototype.toString = function() {
- var indent = Array(level * 4 + 1).join(" ");
- var ret = "\n" + indent + "AggregateError of:" + "\n";
- level++;
- indent = Array(level * 4 + 1).join(" ");
- for (var i = 0; i < this.length; ++i) {
- var str = this[i] === this ? "[Circular AggregateError]" : this[i] + "";
- var lines = str.split("\n");
- for (var j = 0; j < lines.length; ++j) {
- lines[j] = indent + lines[j];
- }
- str = lines.join("\n");
- ret += str + "\n";
- }
- level--;
- return ret;
-};
-
-function OperationalError(message) {
- notEnumerableProp(this, "name", "OperationalError");
- notEnumerableProp(this, "message", message);
- this.cause = message;
- this["isOperational"] = true;
-
- if (message instanceof Error) {
- notEnumerableProp(this, "message", message.message);
- notEnumerableProp(this, "stack", message.stack);
- } else if (Error.captureStackTrace) {
- Error.captureStackTrace(this, this.constructor);
- }
-
-}
-inherits(OperationalError, Error);
-
-var key = "__BluebirdErrorTypes__";
-var errorTypes = Error[key];
-if (!errorTypes) {
- errorTypes = Objectfreeze({
- CancellationError: CancellationError,
- TimeoutError: TimeoutError,
- OperationalError: OperationalError,
- RejectionError: OperationalError,
- AggregateError: AggregateError
- });
- notEnumerableProp(Error, key, errorTypes);
-}
-
-module.exports = {
- Error: Error,
- TypeError: _TypeError,
- RangeError: _RangeError,
- CancellationError: errorTypes.CancellationError,
- OperationalError: errorTypes.OperationalError,
- TimeoutError: errorTypes.TimeoutError,
- AggregateError: errorTypes.AggregateError,
- originatesFromRejection: originatesFromRejection,
- markAsOriginatingFromRejection: markAsOriginatingFromRejection,
- canAttachTrace: canAttachTrace
-};
-
-},{"./es5.js":30,"./util.js":53}],29:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise) {
-var TypeError = require('./errors.js').TypeError;
-
-function apiRejection(msg) {
- var error = new TypeError(msg);
- var ret = Promise.rejected(error);
- var parent = ret._peekContext();
- if (parent != null) {
- parent.attachExtraTrace(error);
- }
- return ret;
-}
-
-return apiRejection;
-};
-
-},{"./errors.js":28}],30:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-var isES5 = (function(){
- "use strict";
- return this === undefined;
-})();
-
-if (isES5) {
- module.exports = {
- freeze: Object.freeze,
- defineProperty: Object.defineProperty,
- keys: Object.keys,
- getPrototypeOf: Object.getPrototypeOf,
- isArray: Array.isArray,
- isES5: isES5,
- propertyIsWritable: function(obj, prop) {
- var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
- return !!(!descriptor || descriptor.writable || descriptor.set);
- }
- };
-} else {
- var has = {}.hasOwnProperty;
- var str = {}.toString;
- var proto = {}.constructor.prototype;
-
- var ObjectKeys = function (o) {
- var ret = [];
- for (var key in o) {
- if (has.call(o, key)) {
- ret.push(key);
- }
- }
- return ret;
- }
-
- var ObjectDefineProperty = function (o, key, desc) {
- o[key] = desc.value;
- return o;
- }
-
- var ObjectFreeze = function (obj) {
- return obj;
- }
-
- var ObjectGetPrototypeOf = function (obj) {
- try {
- return Object(obj).constructor.prototype;
- }
- catch (e) {
- return proto;
- }
- }
-
- var ArrayIsArray = function (obj) {
- try {
- return str.call(obj) === "[object Array]";
- }
- catch(e) {
- return false;
- }
- }
-
- module.exports = {
- isArray: ArrayIsArray,
- keys: ObjectKeys,
- defineProperty: ObjectDefineProperty,
- freeze: ObjectFreeze,
- getPrototypeOf: ObjectGetPrototypeOf,
- isES5: isES5,
- propertyIsWritable: function() {
- return true;
- }
- };
-}
-
-},{}],31:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, INTERNAL) {
-var PromiseMap = Promise.map;
-
-Promise.prototype.filter = function (fn, options) {
- return PromiseMap(this, fn, options, INTERNAL);
-};
-
-Promise.filter = function (promises, fn, options) {
- return PromiseMap(promises, fn, options, INTERNAL);
-};
-};
-
-},{}],32:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, NEXT_FILTER, tryConvertToPromise) {
-var util = require("./util.js");
-var wrapsPrimitiveReceiver = util.wrapsPrimitiveReceiver;
-var isPrimitive = util.isPrimitive;
-var thrower = util.thrower;
-
-function returnThis() {
- return this;
-}
-function throwThis() {
- throw this;
-}
-function return$(r) {
- return function() {
- return r;
- };
-}
-function throw$(r) {
- return function() {
- throw r;
- };
-}
-function promisedFinally(ret, reasonOrValue, isFulfilled) {
- var then;
- if (wrapsPrimitiveReceiver && isPrimitive(reasonOrValue)) {
- then = isFulfilled ? return$(reasonOrValue) : throw$(reasonOrValue);
- } else {
- then = isFulfilled ? returnThis : throwThis;
- }
- return ret._then(then, thrower, undefined, reasonOrValue, undefined);
-}
-
-function finallyHandler(reasonOrValue) {
- var promise = this.promise;
- var handler = this.handler;
-
- var ret = promise._isBound()
- ? handler.call(promise._boundTo)
- : handler();
-
- if (ret !== undefined) {
- var maybePromise = tryConvertToPromise(ret, undefined);
- if (maybePromise instanceof Promise) {
- return promisedFinally(maybePromise, reasonOrValue,
- promise.isFulfilled());
- }
- }
-
- if (promise.isRejected()) {
- NEXT_FILTER.e = reasonOrValue;
- return NEXT_FILTER;
- } else {
- return reasonOrValue;
- }
-}
-
-function tapHandler(value) {
- var promise = this.promise;
- var handler = this.handler;
-
- var ret = promise._isBound()
- ? handler.call(promise._boundTo, value)
- : handler(value);
-
- if (ret !== undefined) {
- var maybePromise = tryConvertToPromise(ret, undefined);
- if (maybePromise instanceof Promise) {
- return promisedFinally(maybePromise, value, true);
- }
- }
- return value;
-}
-
-Promise.prototype._passThroughHandler = function (handler, isFinally) {
- if (typeof handler !== "function") return this.then();
-
- var promiseAndHandler = {
- promise: this,
- handler: handler
- };
-
- return this._then(
- isFinally ? finallyHandler : tapHandler,
- isFinally ? finallyHandler : undefined, undefined,
- promiseAndHandler, undefined);
-};
-
-Promise.prototype.lastly =
-Promise.prototype["finally"] = function (handler) {
- return this._passThroughHandler(handler, true);
-};
-
-Promise.prototype.tap = function (handler) {
- return this._passThroughHandler(handler, false);
-};
-};
-
-},{"./util.js":53}],33:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise,
- apiRejection,
- INTERNAL,
- tryConvertToPromise) {
-var errors = require("./errors.js");
-var TypeError = errors.TypeError;
-var ASSERT = require("./assert.js");
-var deprecated = require("./util.js").deprecated;
-var util = require("./util.js");
-var errorObj = util.errorObj;
-var tryCatch1 = util.tryCatch1;
-var yieldHandlers = [];
-
-function promiseFromYieldHandler(value, yieldHandlers, traceParent) {
- var _errorObj = errorObj;
- var _Promise = Promise;
- var len = yieldHandlers.length;
- for (var i = 0; i < len; ++i) {
- var result = tryCatch1(yieldHandlers[i], undefined, value);
- if (result === _errorObj) {
- return _Promise.reject(_errorObj.e);
- }
- var maybePromise = tryConvertToPromise(result, traceParent);
- if (maybePromise instanceof _Promise) return maybePromise;
- }
- return null;
-}
-
-function PromiseSpawn(generatorFunction, receiver, yieldHandler) {
- var promise = this._promise = new Promise(INTERNAL);
- promise._setTrace(undefined);
- this._generatorFunction = generatorFunction;
- this._receiver = receiver;
- this._generator = undefined;
- this._yieldHandlers = typeof yieldHandler === "function"
- ? [yieldHandler].concat(yieldHandlers)
- : yieldHandlers;
-}
-
-PromiseSpawn.prototype.promise = function () {
- return this._promise;
-};
-
-PromiseSpawn.prototype._run = function () {
- this._generator = this._generatorFunction.call(this._receiver);
- this._receiver =
- this._generatorFunction = undefined;
- this._next(undefined);
-};
-
-PromiseSpawn.prototype._continue = function (result) {
- if (result === errorObj) {
- this._generator = undefined;
- var trace = errors.canAttachTrace(result.e)
- ? result.e : new Error(result.e + "");
- this._promise._attachExtraTrace(trace);
- this._promise._reject(result.e, trace);
- return;
- }
-
- var value = result.value;
- if (result.done === true) {
- this._generator = undefined;
- if (!this._promise._tryFollow(value)) {
- this._promise._fulfill(value);
- }
- } else {
- var maybePromise = tryConvertToPromise(value, this._promise);
- if (!(maybePromise instanceof Promise)) {
- maybePromise =
- promiseFromYieldHandler(maybePromise,
- this._yieldHandlers,
- this._promise);
- ASSERT(((maybePromise === null) || (maybePromise instanceof Promise)),
- "maybePromise === null || maybePromise instanceof Promise");
- if (maybePromise === null) {
- this._throw(new TypeError("A value was yielded that could not be treated as a promise\u000a\u000a See http://goo.gl/4Y4pDk\u000a"));
- return;
- }
- }
- maybePromise._then(
- this._next,
- this._throw,
- undefined,
- this,
- null
- );
- }
-};
-
-PromiseSpawn.prototype._throw = function (reason) {
- if (errors.canAttachTrace(reason))
- this._promise._attachExtraTrace(reason);
- this._continue(
- tryCatch1(this._generator["throw"], this._generator, reason)
- );
-};
-
-PromiseSpawn.prototype._next = function (value) {
- this._continue(
- tryCatch1(this._generator.next, this._generator, value)
- );
-};
-
-Promise.coroutine = function (generatorFunction, options) {
- if (typeof generatorFunction !== "function") {
- throw new TypeError("generatorFunction must be a function\u000a\u000a See http://goo.gl/6Vqhm0\u000a");
- }
- var yieldHandler = Object(options).yieldHandler;
- var PromiseSpawn$ = PromiseSpawn;
- return function () {
- var generator = generatorFunction.apply(this, arguments);
- var spawn = new PromiseSpawn$(undefined, undefined, yieldHandler);
- spawn._generator = generator;
- spawn._next(undefined);
- return spawn.promise();
- };
-};
-
-Promise.coroutine.addYieldHandler = function(fn) {
- if (typeof fn !== "function") throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- yieldHandlers.push(fn);
-};
-
-Promise.spawn = function (generatorFunction) {
- deprecated("Promise.spawn is deprecated. Use Promise.coroutine instead.");
- if (typeof generatorFunction !== "function") {
- return apiRejection("generatorFunction must be a function\u000a\u000a See http://goo.gl/6Vqhm0\u000a");
- }
- var spawn = new PromiseSpawn(generatorFunction, this);
- var ret = spawn.promise();
- spawn._run(Promise.spawn);
- return ret;
-};
-};
-
-},{"./assert.js":19,"./errors.js":28,"./util.js":53}],34:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports =
-function(Promise, PromiseArray, tryConvertToPromise, INTERNAL) {
-var util = require("./util.js");
-var canEvaluate = util.canEvaluate;
-var tryCatch1 = util.tryCatch1;
-var errorObj = util.errorObj;
-
-
-if (canEvaluate) {
- var thenCallback = function(i) {
- return new Function("value", "holder", " \n\
- 'use strict'; \n\
- holder.pIndex = value; \n\
- holder.checkFulfillment(this); \n\
- ".replace(/Index/g, i));
- };
-
- var caller = function(count) {
- var values = [];
- for (var i = 1; i <= count; ++i) values.push("holder.p" + i);
- return new Function("holder", " \n\
- 'use strict'; \n\
- var callback = holder.fn; \n\
- return callback(values); \n\
- ".replace(/values/g, values.join(", ")));
- };
- var thenCallbacks = [];
- var callers = [undefined];
- for (var i = 1; i <= 5; ++i) {
- thenCallbacks.push(thenCallback(i));
- callers.push(caller(i));
- }
-
- var Holder = function(total, fn) {
- this.p1 = this.p2 = this.p3 = this.p4 = this.p5 = null;
- this.fn = fn;
- this.total = total;
- this.now = 0;
- };
-
- Holder.prototype.callers = callers;
- Holder.prototype.checkFulfillment = function(promise) {
- var now = this.now;
- now++;
- var total = this.total;
- if (now >= total) {
- var handler = this.callers[total];
- var ret = tryCatch1(handler, undefined, this);
- if (ret === errorObj) {
- promise._rejectUnchecked(ret.e);
- } else if (!promise._tryFollow(ret)) {
- promise._fulfillUnchecked(ret);
- }
- } else {
- this.now = now;
- }
- };
-}
-
-function reject(reason) {
- this._reject(reason);
-}
-
-Promise.join = function () {
- var last = arguments.length - 1;
- var fn;
- if (last > 0 && typeof arguments[last] === "function") {
- fn = arguments[last];
- if (last < 6 && canEvaluate) {
- var ret = new Promise(INTERNAL);
- ret._setTrace(undefined);
- var holder = new Holder(last, fn);
- var callbacks = thenCallbacks;
- for (var i = 0; i < last; ++i) {
- var maybePromise = tryConvertToPromise(arguments[i], undefined);
- if (maybePromise instanceof Promise) {
- if (maybePromise.isPending()) {
- maybePromise._then(callbacks[i], reject,
- undefined, ret, holder);
- } else if (maybePromise.isFulfilled()) {
- callbacks[i].call(ret,
- maybePromise._settledValue, holder);
- } else {
- ret._reject(maybePromise._settledValue);
- maybePromise._unsetRejectionIsUnhandled();
- }
- } else {
- callbacks[i].call(ret, maybePromise, holder);
- }
- }
- return ret;
- }
- }
- var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
- var ret = new PromiseArray(args).promise();
- return fn !== undefined ? ret.spread(fn) : ret;
-};
-
-};
-
-},{"./util.js":53}],35:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise,
- PromiseArray,
- apiRejection,
- tryConvertToPromise,
- INTERNAL) {
-var ASSERT = require("./assert.js");
-var util = require("./util.js");
-var tryCatch3 = util.tryCatch3;
-var errorObj = util.errorObj;
-var PENDING = {};
-var EMPTY_ARRAY = [];
-
-function MappingPromiseArray(promises, fn, limit, _filter) {
- this.constructor$(promises);
- this._callback = fn;
- this._preservedValues = _filter === INTERNAL
- ? new Array(this.length())
- : null;
- this._limit = limit;
- this._inFlight = 0;
- this._queue = limit >= 1 ? [] : EMPTY_ARRAY;
- this._init$(undefined, -2);
-}
-util.inherits(MappingPromiseArray, PromiseArray);
-
-MappingPromiseArray.prototype._init = function () {};
-
-MappingPromiseArray.prototype._promiseFulfilled = function (value, index) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- var values = this._values;
- var length = this.length();
- var preservedValues = this._preservedValues;
- var limit = this._limit;
- if (values[index] === PENDING) {
- values[index] = value;
- if (limit >= 1) {
- this._inFlight--;
- this._drainQueue();
- if (this._isResolved()) return;
- }
- } else {
- if (limit >= 1 && this._inFlight >= limit) {
- values[index] = value;
- this._queue.push(index);
- return;
- }
- if (preservedValues !== null) preservedValues[index] = value;
-
- var callback = this._callback;
- var receiver = this._promise._boundTo;
- var ret = tryCatch3(callback, receiver, value, index, length);
- if (ret === errorObj) return this._reject(ret.e);
-
- var maybePromise = tryConvertToPromise(ret, this._promise);
- if (maybePromise instanceof Promise) {
- if (maybePromise.isPending()) {
- if (limit >= 1) this._inFlight++;
- values[index] = PENDING;
- return maybePromise._proxyPromiseArray(this, index);
- } else if (maybePromise.isFulfilled()) {
- ret = maybePromise._settledValue;
- } else {
- maybePromise._unsetRejectionIsUnhandled();
- return this._reject(maybePromise._settledValue);
- }
- }
- values[index] = ret;
- }
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= length) {
- if (preservedValues !== null) {
- this._filter(values, preservedValues);
- } else {
- this._resolve(values);
- }
-
- }
-};
-
-MappingPromiseArray.prototype._drainQueue = function () {
- var queue = this._queue;
- var limit = this._limit;
- var values = this._values;
- while (queue.length > 0 && this._inFlight < limit) {
- if (this._isResolved()) return;
- var index = queue.pop();
- this._promiseFulfilled(values[index], index);
- }
-};
-
-MappingPromiseArray.prototype._filter = function (booleans, values) {
- var len = values.length;
- var ret = new Array(len);
- var j = 0;
- for (var i = 0; i < len; ++i) {
- if (booleans[i]) ret[j++] = values[i];
- }
- ret.length = j;
- this._resolve(ret);
-};
-
-MappingPromiseArray.prototype.preservedValues = function () {
- return this._preservedValues;
-};
-
-function map(promises, fn, options, _filter) {
- var limit = typeof options === "object" && options !== null
- ? options.concurrency
- : 0;
- limit = typeof limit === "number" &&
- isFinite(limit) && limit >= 1 ? limit : 0;
- return new MappingPromiseArray(promises, fn, limit, _filter);
-}
-
-Promise.prototype.map = function (fn, options) {
- if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
-
- return map(this, fn, options, null).promise();
-};
-
-Promise.map = function (promises, fn, options, _filter) {
- if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- return map(promises, fn, options, _filter).promise();
-};
-
-
-};
-
-},{"./assert.js":19,"./util.js":53}],36:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise) {
-var util = require("./util.js");
-var async = require("./async.js");
-var ASSERT = require("./assert.js");
-var tryCatch2 = util.tryCatch2;
-var tryCatch1 = util.tryCatch1;
-var errorObj = util.errorObj;
-
-function thrower(r) {
- throw r;
-}
-
-function spreadAdapter(val, receiver) {
- if (!util.isArray(val)) return successAdapter(val, receiver);
- var ret = util.tryCatchApply(this, [null].concat(val), receiver);
- if (ret === errorObj) {
- async.invokeLater(thrower, undefined, ret.e);
- }
-}
-
-function successAdapter(val, receiver) {
- var nodeback = this;
- ASSERT(((typeof nodeback) == "function"),
- "typeof nodeback == \u0022function\u0022");
- var ret = val === undefined
- ? tryCatch1(nodeback, receiver, null)
- : tryCatch2(nodeback, receiver, null, val);
- if (ret === errorObj) {
- async.invokeLater(thrower, undefined, ret.e);
- }
-}
-function errorAdapter(reason, receiver) {
- var nodeback = this;
- ASSERT(((typeof nodeback) == "function"),
- "typeof nodeback == \u0022function\u0022");
- var ret = tryCatch1(nodeback, receiver, reason);
- if (ret === errorObj) {
- async.invokeLater(thrower, undefined, ret.e);
- }
-}
-
-Promise.prototype.nodeify = function (nodeback, options) {
- if (typeof nodeback == "function") {
- var adapter = successAdapter;
- if (options !== undefined && Object(options).spread) {
- adapter = spreadAdapter;
- }
- this._then(
- adapter,
- errorAdapter,
- undefined,
- nodeback,
- this._boundTo
- );
- }
- return this;
-};
-};
-
-},{"./assert.js":19,"./async.js":20,"./util.js":53}],37:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, PromiseArray) {
-var ASSERT = require("./assert.js");
-var util = require("./util.js");
-var async = require("./async.js");
-var errors = require("./errors.js");
-var tryCatch1 = util.tryCatch1;
-var errorObj = util.errorObj;
-
-Promise.prototype.progressed = function (handler) {
- return this._then(undefined, undefined, handler, undefined, undefined);
-};
-
-Promise.prototype._progress = function (progressValue) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- this._progressUnchecked(progressValue);
-
-};
-
-Promise.prototype._progressHandlerAt = function (index) {
- return index === 0
- ? this._progressHandler0
- : this[(index << 2) + index - 5 + 2];
-};
-
-Promise.prototype._doProgressWith = function (progression) {
- var progressValue = progression.value;
- var handler = progression.handler;
- var promise = progression.promise;
- var receiver = progression.receiver;
-
- ASSERT(((typeof handler) === "function"),
- "typeof handler === \u0022function\u0022");
- ASSERT((promise instanceof Promise),
- "promise instanceof Promise");
- var ret = tryCatch1(handler, receiver, progressValue);
- if (ret === errorObj) {
- if (ret.e != null &&
- ret.e.name !== "StopProgressPropagation") {
- var trace = errors.canAttachTrace(ret.e)
- ? ret.e : new Error(ret.e + "");
- promise._attachExtraTrace(trace);
- promise._progress(ret.e);
- }
- } else if (ret instanceof Promise) {
- ret._then(promise._progress, null, null, promise, undefined);
- } else {
- promise._progress(ret);
- }
-};
-
-
-Promise.prototype._progressUnchecked = function (progressValue) {
- if (!this.isPending()) return;
- var len = this._length();
- var progress = this._progress;
- for (var i = 0; i < len; i++) {
- var handler = this._progressHandlerAt(i);
- var promise = this._promiseAt(i);
- if (!(promise instanceof Promise)) {
- var receiver = this._receiverAt(i);
- if (typeof handler === "function") {
- handler.call(receiver, progressValue, promise);
- } else if (receiver instanceof Promise && receiver._isProxied()) {
- receiver._progressUnchecked(progressValue);
- } else if (receiver instanceof PromiseArray &&
- !receiver._isResolved()) {
- receiver._promiseProgressed(progressValue, promise);
- }
- continue;
- }
-
- if (typeof handler === "function") {
- async.invoke(this._doProgressWith, this, {
- handler: handler,
- promise: promise,
- receiver: this._receiverAt(i),
- value: progressValue
- });
- } else {
- async.invoke(progress, promise, progressValue);
- }
- }
-};
-};
-
-},{"./assert.js":19,"./async.js":20,"./errors.js":28,"./util.js":53}],38:[function(require,module,exports){
-var process=require("__browserify_process");/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function() {
-var makeSelfResolutionError = function () {
- return new TypeError("circular promise resolution chain\u000a\u000a See http://goo.gl/LhFpo0\u000a");
-};
-var reflect = function() {
- return new Promise.PromiseInspection(this);
-};
-var returnFirstElement = function(elements) { return elements[0]; };
-var ASSERT = require("./assert.js");
-var util = require("./util.js");
-var async = require("./async.js");
-var errors = require("./errors.js");
-var INTERNAL = function(){};
-var APPLY = {};
-var NEXT_FILTER = {e: null};
-var tryConvertToPromise = require("./thenables.js")(Promise, INTERNAL);
-var PromiseArray =
- require("./promise_array.js")(Promise, INTERNAL, tryConvertToPromise);
-var CapturedTrace = require("./captured_trace.js")();
-var CatchFilter = require("./catch_filter.js")(NEXT_FILTER);
-var PromiseResolver = require("./promise_resolver.js");
-var isArray = util.isArray;
-var errorObj = util.errorObj;
-var tryCatch1 = util.tryCatch1;
-var tryCatch2 = util.tryCatch2;
-var tryCatchApply = util.tryCatchApply;
-var RangeError = errors.RangeError;
-var TypeError = errors.TypeError;
-var CancellationError = errors.CancellationError;
-var TimeoutError = errors.TimeoutError;
-var OperationalError = errors.OperationalError;
-var originatesFromRejection = errors.originatesFromRejection;
-var markAsOriginatingFromRejection = errors.markAsOriginatingFromRejection;
-var canAttachTrace = errors.canAttachTrace;
-var apiRejection = require("./errors_api_rejection")(Promise);
-var unhandledRejectionHandled;
-var debugging = true || !!(
- typeof process !== "undefined" &&
- typeof process.execPath === "string" &&
- typeof process.env === "object" &&
- (process.env["BLUEBIRD_DEBUG"] ||
- process.env["NODE_ENV"] === "development")
-);
-
-function Promise(resolver) {
- if (typeof resolver !== "function") {
- throw new TypeError("the promise constructor requires a resolver function\u000a\u000a See http://goo.gl/EC22Yn\u000a");
- }
- if (this.constructor !== Promise) {
- throw new TypeError("the promise constructor cannot be invoked directly\u000a\u000a See http://goo.gl/KsIlge\u000a");
- }
- this._bitField = 0;
- this._fulfillmentHandler0 = undefined;
- this._rejectionHandler0 = undefined;
- this._progressHandler0 = undefined;
- this._promise0 = undefined;
- this._receiver0 = undefined;
- this._settledValue = undefined;
- this._boundTo = undefined;
- if (resolver !== INTERNAL) this._resolveFromResolver(resolver);
-}
-
-Promise.prototype.bind = function (thisArg) {
- var maybePromise = tryConvertToPromise(thisArg, this);
- var ret = new Promise(INTERNAL);
- ret._propagateFrom(this, 2 | 1);
- if (maybePromise instanceof Promise) {
- var binder = maybePromise.then(function(thisArg) {
- ret._setBoundTo(thisArg);
- });
- var p = Promise.all([this, binder]).then(returnFirstElement);
- ret._follow(p);
- } else {
- ret._follow(this);
- ret._setBoundTo(thisArg);
- }
-
- return ret;
-};
-
-Promise.prototype.toString = function () {
- return "[object Promise]";
-};
-
-Promise.prototype.caught = Promise.prototype["catch"] = function (fn) {
- var len = arguments.length;
- if (len > 1) {
- var catchInstances = new Array(len - 1),
- j = 0, i;
- for (i = 0; i < len - 1; ++i) {
- var item = arguments[i];
- if (typeof item === "function") {
- catchInstances[j++] = item;
- } else {
- var error = new TypeError("Catch filter must inherit from Error or be a simple predicate function\u000a\u000a See http://goo.gl/o84o68\u000a");
- this._attachExtraTrace(error);
- return Promise.reject(error);
- }
- }
- catchInstances.length = j;
- fn = arguments[i];
-
- this._resetTrace();
- var catchFilter = new CatchFilter(catchInstances, fn, this);
- return this._then(undefined, catchFilter.doFilter, undefined,
- catchFilter, undefined);
- }
- return this._then(undefined, fn, undefined, undefined, undefined);
-};
-
-Promise.prototype.reflect = function () {
- return this._then(reflect, reflect, undefined, this, undefined);
-};
-
-Promise.prototype.then = function (didFulfill, didReject, didProgress) {
- return this._then(didFulfill, didReject, didProgress,
- undefined, undefined);
-};
-
-
-Promise.prototype.done = function (didFulfill, didReject, didProgress) {
- var promise = this._then(didFulfill, didReject, didProgress,
- undefined, undefined);
- promise._setIsFinal();
-};
-
-Promise.prototype.spread = function (didFulfill, didReject) {
- return this.all()._then(didFulfill, didReject, undefined, APPLY, undefined);
-};
-
-Promise.prototype.isCancellable = function () {
- return !this.isResolved() &&
- this._cancellable();
-};
-
-Promise.prototype.toJSON = function () {
- var ret = {
- isFulfilled: false,
- isRejected: false,
- fulfillmentValue: undefined,
- rejectionReason: undefined
- };
- if (this.isFulfilled()) {
- ret.fulfillmentValue = this._settledValue;
- ret.isFulfilled = true;
- } else if (this.isRejected()) {
- ret.rejectionReason = this._settledValue;
- ret.isRejected = true;
- }
- return ret;
-};
-
-Promise.prototype.all = function () {
- return new PromiseArray(this).promise();
-};
-
-Promise.prototype.error = function (fn) {
- return this.caught(originatesFromRejection, fn);
-};
-
-Promise.is = function (val) {
- return val instanceof Promise;
-};
-
-Promise.all = function (promises) {
- return new PromiseArray(promises).promise();
-};
-
-Promise.method = function (fn) {
- if (typeof fn !== "function") {
- throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- }
- return function () {
- var value;
- switch(arguments.length) {
- case 0: value = tryCatch1(fn, this, undefined); break;
- case 1: value = tryCatch1(fn, this, arguments[0]); break;
- case 2: value = tryCatch2(fn, this, arguments[0], arguments[1]); break;
- default:
- var $_len = arguments.length;var args = new Array($_len); for(var $_i = 0; $_i < $_len; ++$_i) {args[$_i] = arguments[$_i];}
- value = tryCatchApply(fn, args, this); break;
- }
- var ret = new Promise(INTERNAL);
- ret._setTrace(undefined);
- ret._resolveFromSyncValue(value);
- return ret;
- };
-};
-
-Promise.attempt = Promise["try"] = function (fn, args, ctx) {
- if (typeof fn !== "function") {
- return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- }
- var value = isArray(args)
- ? tryCatchApply(fn, args, ctx)
- : tryCatch1(fn, ctx, args);
-
- var ret = new Promise(INTERNAL);
- ret._setTrace(undefined);
- ret._resolveFromSyncValue(value);
- return ret;
-};
-
-Promise.defer = Promise.pending = function () {
- var promise = new Promise(INTERNAL);
- promise._setTrace(undefined);
- return new PromiseResolver(promise);
-};
-
-Promise.bind = function (thisArg) {
- var maybePromise = tryConvertToPromise(thisArg, undefined);
- var ret = new Promise(INTERNAL);
- ret._setTrace(undefined);
-
- if (maybePromise instanceof Promise) {
- var p = maybePromise.then(function(thisArg) {
- ret._setBoundTo(thisArg);
- });
- ret._follow(p);
- } else {
- ret._setBoundTo(thisArg);
- ret._setFulfilled();
- }
- return ret;
-};
-
-Promise.cast = function (obj) {
- var ret = tryConvertToPromise(obj, undefined);
- if (!(ret instanceof Promise)) {
- var val = ret;
- ret = new Promise(INTERNAL);
- ret._setTrace(undefined);
- ret._setFulfilled();
- ret._settledValue = val;
- ret._cleanValues();
- }
- return ret;
-};
-
-Promise.resolve = Promise.fulfilled = Promise.cast;
-
-Promise.reject = Promise.rejected = function (reason) {
- var ret = new Promise(INTERNAL);
- ret._setTrace(undefined);
- markAsOriginatingFromRejection(reason);
- ret._setRejected();
- ret._settledValue = reason;
- ret._cleanValues();
- if (!canAttachTrace(reason)) {
- var trace = new Error(reason + "");
- ret._setCarriedStackTrace(trace);
- }
- ret._ensurePossibleRejectionHandled();
- return ret;
-};
-
-Promise.onPossiblyUnhandledRejection = function (fn) {
- CapturedTrace.possiblyUnhandledRejection = typeof fn === "function"
- ? fn : undefined;
-};
-
-Promise.onUnhandledRejectionHandled = function (fn) {
- unhandledRejectionHandled = typeof fn === "function" ? fn : undefined;
-};
-
-Promise.longStackTraces = function () {
- if (async.haveItemsQueued() &&
- debugging === false
- ) {
- throw new Error("cannot enable long stack traces after promises have been created\u000a\u000a See http://goo.gl/DT1qyG\u000a");
- }
- debugging = CapturedTrace.isSupported();
-};
-
-Promise.hasLongStackTraces = function () {
- return debugging && CapturedTrace.isSupported();
-};
-
-Promise.setScheduler = function(fn) {
- if (typeof fn !== "function") throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- async._schedule = fn;
-};
-
-Promise.prototype._then = function (
- didFulfill,
- didReject,
- didProgress,
- receiver,
- internalData
-) {
- ASSERT((arguments.length === 5),
- "arguments.length === 5");
- var haveInternalData = internalData !== undefined;
- var ret = haveInternalData ? internalData : new Promise(INTERNAL);
-
- if (!haveInternalData) {
- ret._propagateFrom(this, 7);
- }
-
- var callbackIndex =
- this._addCallbacks(didFulfill, didReject, didProgress, ret, receiver);
-
- if (this.isResolved() && !this._isSettlePromisesQueued()) {
- async.invoke(this._settlePromiseAtPostResolution, this, callbackIndex);
- }
-
- return ret;
-};
-
-Promise.prototype._settlePromiseAtPostResolution = function (index) {
- ASSERT(((typeof index) === "number"),
- "typeof index === \u0022number\u0022");
- ASSERT((index >= 0),
- "index >= 0");
- ASSERT((this.isFulfilled() || this.isRejected()),
- "this.isFulfilled() || this.isRejected()");
- ASSERT((this._promiseAt(index) !== undefined),
- "this._promiseAt(index) !== undefined");
- if (this._isRejectionUnhandled()) this._unsetRejectionIsUnhandled();
- this._setLength(0);
- this._settlePromiseAt(index);
-};
-
-Promise.prototype._length = function () {
- ASSERT((arguments.length === 0),
- "arguments.length === 0");
- return this._bitField & 262143;
-};
-
-Promise.prototype._isFollowingOrFulfilledOrRejected = function () {
- return (this._bitField & 939524096) > 0;
-};
-
-Promise.prototype._isFollowing = function () {
- return (this._bitField & 536870912) === 536870912;
-};
-
-Promise.prototype._setLength = function (len) {
- this._bitField = (this._bitField & -262144) |
- (len & 262143);
-};
-
-Promise.prototype._setFulfilled = function () {
- this._bitField = this._bitField | 268435456;
-};
-
-Promise.prototype._setRejected = function () {
- this._bitField = this._bitField | 134217728;
-};
-
-Promise.prototype._setFollowing = function () {
- this._bitField = this._bitField | 536870912;
-};
-
-Promise.prototype._setIsFinal = function () {
- this._bitField = this._bitField | 33554432;
-};
-
-Promise.prototype._isFinal = function () {
- return (this._bitField & 33554432) > 0;
-};
-
-Promise.prototype._cancellable = function () {
- return (this._bitField & 67108864) > 0;
-};
-
-Promise.prototype._setCancellable = function () {
- this._bitField = this._bitField | 67108864;
-};
-
-Promise.prototype._unsetCancellable = function () {
- this._bitField = this._bitField & (~67108864);
-};
-
-Promise.prototype._setRejectionIsUnhandled = function () {
- ASSERT(this.isRejected(),
- "this.isRejected()");
- this._bitField = this._bitField | 2097152;
-};
-
-Promise.prototype._unsetRejectionIsUnhandled = function () {
- this._bitField = this._bitField & (~2097152);
- if (this._isUnhandledRejectionNotified()) {
- this._unsetUnhandledRejectionIsNotified();
- this._notifyUnhandledRejectionIsHandled();
- }
-};
-
-Promise.prototype._isRejectionUnhandled = function () {
- return (this._bitField & 2097152) > 0;
-};
-
-Promise.prototype._setUnhandledRejectionIsNotified = function () {
- this._bitField = this._bitField | 524288;
-};
-
-Promise.prototype._unsetUnhandledRejectionIsNotified = function () {
- this._bitField = this._bitField & (~524288);
-};
-
-Promise.prototype._isUnhandledRejectionNotified = function () {
- return (this._bitField & 524288) > 0;
-};
-
-Promise.prototype._setCarriedStackTrace = function (capturedTrace) {
- ASSERT(this.isRejected(),
- "this.isRejected()");
- this._bitField = this._bitField | 1048576;
- this._fulfillmentHandler0 = capturedTrace;
-};
-
-Promise.prototype._unsetCarriedStackTrace = function () {
- ASSERT(this.isRejected(),
- "this.isRejected()");
- this._bitField = this._bitField & (~1048576);
- this._fulfillmentHandler0 = undefined;
-};
-
-Promise.prototype._isCarryingStackTrace = function () {
- return (this._bitField & 1048576) > 0;
-};
-
-Promise.prototype._getCarriedStackTrace = function () {
- ASSERT(this.isRejected(),
- "this.isRejected()");
- return this._isCarryingStackTrace()
- ? this._fulfillmentHandler0
- : undefined;
-};
-
-Promise.prototype._receiverAt = function (index) {
- var ret = index === 0
- ? this._receiver0
- : this[(index << 2) + index - 5 + 4];
- if (this._isBound() && ret === undefined) {
- return this._boundTo;
- }
- return ret;
-};
-
-Promise.prototype._promiseAt = function (index) {
- return index === 0
- ? this._promise0
- : this[(index << 2) + index - 5 + 3];
-};
-
-Promise.prototype._fulfillmentHandlerAt = function (index) {
- ASSERT((! this._isCarryingStackTrace()),
- "!this._isCarryingStackTrace()");
- return index === 0
- ? this._fulfillmentHandler0
- : this[(index << 2) + index - 5 + 0];
-};
-
-Promise.prototype._rejectionHandlerAt = function (index) {
- return index === 0
- ? this._rejectionHandler0
- : this[(index << 2) + index - 5 + 1];
-};
-
-Promise.prototype._addCallbacks = function (
- fulfill,
- reject,
- progress,
- promise,
- receiver
-) {
- var index = this._length();
-
- if (index >= 262143 - 5) {
- index = 0;
- this._setLength(0);
- }
-
- if (index === 0) {
- ASSERT((this._promise0 === undefined),
- "this._promise0 === undefined");
- ASSERT((this._receiver0 === undefined),
- "this._receiver0 === undefined");
- ASSERT(((this._fulfillmentHandler0 === undefined) || this._isCarryingStackTrace()),
- "this._fulfillmentHandler0 === undefined ||\u000a this._isCarryingStackTrace()");
- ASSERT((this._rejectionHandler0 === undefined),
- "this._rejectionHandler0 === undefined");
- ASSERT((this._progressHandler0 === undefined),
- "this._progressHandler0 === undefined");
-
- this._promise0 = promise;
- if (receiver !== undefined) this._receiver0 = receiver;
- if (typeof fulfill === "function" && !this._isCarryingStackTrace())
- this._fulfillmentHandler0 = fulfill;
- if (typeof reject === "function") this._rejectionHandler0 = reject;
- if (typeof progress === "function") this._progressHandler0 = progress;
- } else {
- ASSERT((this[(base + 3)] === undefined),
- "this[base + CALLBACK_PROMISE_OFFSET] === undefined");
- ASSERT((this[(base + 4)] === undefined),
- "this[base + CALLBACK_RECEIVER_OFFSET] === undefined");
- ASSERT((this[(base + 0)] === undefined),
- "this[base + CALLBACK_FULFILL_OFFSET] === undefined");
- ASSERT((this[(base + 1)] === undefined),
- "this[base + CALLBACK_REJECT_OFFSET] === undefined");
- ASSERT((this[(base + 2)] === undefined),
- "this[base + CALLBACK_PROGRESS_OFFSET] === undefined");
- var base = index * 5 - 5;
- this[base + 3] = promise;
- this[base + 4] = receiver;
- if (typeof fulfill === "function")
- this[base + 0] = fulfill;
- if (typeof reject === "function")
- this[base + 1] = reject;
- if (typeof progress === "function")
- this[base + 2] = progress;
- }
- this._setLength(index + 1);
- return index;
-};
-
-Promise.prototype._setProxyHandlers = function (receiver, promiseSlotValue) {
- var index = this._length();
-
- if (index >= 262143 - 5) {
- index = 0;
- this._setLength(0);
- }
- if (index === 0) {
- this._promise0 = promiseSlotValue;
- this._receiver0 = receiver;
- } else {
- var base = index * 5 - 5;
- this[base + 3] = promiseSlotValue;
- this[base + 4] = receiver;
- }
- this._setLength(index + 1);
-};
-
-Promise.prototype._proxyPromiseArray = function (promiseArray, index) {
- ASSERT((! this.isResolved()),
- "!this.isResolved()");
- ASSERT((arguments.length === 2),
- "arguments.length === 2");
- ASSERT(((typeof index) === "number"),
- "typeof index === \u0022number\u0022");
- ASSERT(((index | 0) === index),
- "(index | 0) === index");
- this._setProxyHandlers(promiseArray, index);
-};
-
-Promise.prototype._proxyPromise = function (promise) {
- ASSERT((! promise._isProxied()),
- "!promise._isProxied()");
- ASSERT((! this.isResolved()),
- "!this.isResolved()");
- ASSERT((arguments.length === 1),
- "arguments.length === 1");
- promise._setProxied();
- this._setProxyHandlers(promise, -15);
-};
-
-Promise.prototype._setBoundTo = function (obj) {
- if (obj !== undefined) {
- this._bitField = this._bitField | 8388608;
- this._boundTo = obj;
- } else {
- this._bitField = this._bitField & (~8388608);
- }
-};
-
-Promise.prototype._isBound = function () {
- return (this._bitField & 8388608) === 8388608;
-};
-
-Promise.prototype._resolveFromResolver = function (resolver) {
- ASSERT(((typeof resolver) === "function"),
- "typeof resolver === \u0022function\u0022");
- var promise = this;
- this._setTrace(undefined);
-
- this._pushContext();
- var r = tryCatch2(resolver, undefined, function(val) {
- if (promise._tryFollow(val)) {
- return;
- }
- promise._fulfill(val);
- }, function (val) {
- var trace = canAttachTrace(val) ? val : new Error(val + "");
- promise._attachExtraTrace(trace);
- markAsOriginatingFromRejection(val);
- promise._reject(val, trace === val ? undefined : trace);
- });
- this._popContext();
-
- if (r !== undefined && r === errorObj) {
- var e = r.e;
- var trace = canAttachTrace(e) ? e : new Error(e + "");
- promise._reject(e, trace);
- }
-};
-
-Promise.prototype._callHandler = function (
- handler, receiver, promise, value) {
- var x;
- promise._pushContext();
- if (receiver === APPLY && !this.isRejected()) {
- ASSERT(isArray(value),
- "isArray(value)");
- x = tryCatchApply(handler, value, this._boundTo);
- } else {
- x = tryCatch1(handler, receiver, value);
- }
- promise._popContext();
- return x;
-};
-
-Promise.prototype._settlePromiseFromHandler = function (
- handler, receiver, value, promise
-) {
- if (promise.isRejected()) return;
- ASSERT((! promise._isFollowingOrFulfilledOrRejected()),
- "!promise._isFollowingOrFulfilledOrRejected()");
- var x = this._callHandler(handler, receiver, promise, value);
- if (promise._isFollowing()) return;
-
- if (x === errorObj || x === promise || x === NEXT_FILTER) {
- var err = x === promise
- ? makeSelfResolutionError()
- : x.e;
- var trace = canAttachTrace(err) ? err : new Error(err + "");
- if (x !== NEXT_FILTER) promise._attachExtraTrace(trace);
- promise._rejectUnchecked(err, trace);
- } else {
- var castValue = tryConvertToPromise(x, promise);
- if (castValue instanceof Promise) {
- if (castValue.isRejected() &&
- !castValue._isCarryingStackTrace() &&
- !canAttachTrace(castValue._settledValue)) {
- var trace = new Error(castValue._settledValue + "");
- promise._attachExtraTrace(trace);
- castValue._setCarriedStackTrace(trace);
- }
- promise._follow(castValue);
- promise._propagateFrom(castValue, 1);
- } else {
- promise._fulfillUnchecked(x);
- }
- }
-};
-
-Promise.prototype._follow = function (promise) {
- ASSERT((arguments.length === 1),
- "arguments.length === 1");
- ASSERT((this._isFollowingOrFulfilledOrRejected() === false),
- "this._isFollowingOrFulfilledOrRejected() === false");
- ASSERT((promise !== this),
- "promise !== this");
- this._setFollowing();
-
- if (promise.isPending()) {
- this._propagateFrom(promise, 1);
- promise._proxyPromise(this);
- } else if (promise.isFulfilled()) {
- this._fulfillUnchecked(promise._settledValue);
- } else {
- this._rejectUnchecked(promise._settledValue,
- promise._getCarriedStackTrace());
- }
-
- if (promise._isRejectionUnhandled()) promise._unsetRejectionIsUnhandled();
-
- if (debugging &&
- !promise._trace.hasParent()) {
- ASSERT((this._trace instanceof CapturedTrace),
- "this._trace instanceof CapturedTrace");
- promise._trace.setParent(this._trace);
- }
-};
-
-Promise.prototype._tryFollow = function (value) {
- ASSERT((arguments.length === 1),
- "arguments.length === 1");
- if (this._isFollowingOrFulfilledOrRejected() ||
- value === this) {
- return false;
- }
- var maybePromise = tryConvertToPromise(value, this);
- if (!(maybePromise instanceof Promise)) {
- return false;
- }
- this._follow(maybePromise);
- return true;
-};
-
-Promise.prototype._resetTrace = function () {
- if (debugging) {
- this._trace = new CapturedTrace(this._peekContext());
- }
-};
-
-Promise.prototype._setTrace = function (parent) {
- ASSERT((this._trace == null),
- "this._trace == null");
- if (debugging) {
- var context = this._peekContext();
- if (parent !== undefined &&
- parent._trace.parent() === context) {
- this._trace = parent._trace;
- } else {
- this._trace = new CapturedTrace(context);
- }
- }
- return this;
-};
-
-Promise.prototype._attachExtraTrace = function (error) {
- if (debugging && canAttachTrace(error)) {
- this._trace.attachExtraTrace(error);
- }
-};
-
-Promise.prototype._cleanValues = function () {
- if (this._cancellable()) {
- this._cancellationParent = undefined;
- }
-};
-
-Promise.prototype._propagateFrom = function (parent, flags) {
- if ((flags & 1) > 0 && parent._cancellable()) {
- this._setCancellable();
- this._cancellationParent = parent;
- }
- if ((flags & 4) > 0) {
- this._setBoundTo(parent._boundTo);
- }
- if ((flags & 2) > 0) {
- this._setTrace(parent);
- }
-};
-
-Promise.prototype._fulfill = function (value) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- this._fulfillUnchecked(value);
-};
-
-Promise.prototype._reject = function (reason, carriedStackTrace) {
- if (this._isFollowingOrFulfilledOrRejected()) return;
- this._rejectUnchecked(reason, carriedStackTrace);
-};
-
-Promise.prototype._settlePromiseAt = function (index) {
- var handler = this.isFulfilled()
- ? this._fulfillmentHandlerAt(index)
- : this._rejectionHandlerAt(index);
-
- ASSERT((this.isFulfilled() || this.isRejected()),
- "this.isFulfilled() || this.isRejected()");
-
- var carriedStackTrace =
- this._isCarryingStackTrace() ? this._getCarriedStackTrace() : undefined;
- var value = this._settledValue;
- var receiver = this._receiverAt(index);
- var promise = this._promiseAt(index);
- this._clearCallbackDataAtIndex(index);
-
- if (typeof handler === "function") {
- if (!(promise instanceof Promise)) {
- handler.call(receiver, value, promise);
- } else {
- this._settlePromiseFromHandler(handler, receiver, value, promise);
- }
- } else {
- var done = false;
- var isFulfilled = this.isFulfilled();
- if (receiver !== undefined) {
- if (receiver instanceof Promise &&
- receiver._isProxied()) {
- if (receiver.isRejected()) return;
- ASSERT(((! receiver.isFulfilled()) && (! receiver.isRejected())),
- "!receiver.isFulfilled() && !receiver.isRejected()");
- receiver._unsetProxied();
-
- if (isFulfilled) receiver._fulfillUnchecked(value);
- else receiver._rejectUnchecked(value,
- this._getCarriedStackTrace());
- done = true;
- } else if (receiver instanceof PromiseArray) {
- if (!receiver._isResolved()) {
- if (isFulfilled) {
- receiver._promiseFulfilled(value, promise);
- }
- else {
- receiver._promiseRejected(value, promise);
- }
- }
- done = true;
- }
- }
-
- if (!done) {
- if (isFulfilled) promise._fulfill(value);
- else promise._reject(value, carriedStackTrace);
- }
- }
-};
-
-Promise.prototype._clearCallbackDataAtIndex = function(index) {
- if (index === 0) {
- if (!this._isCarryingStackTrace()) {
- this._fulfillmentHandler0 = undefined;
- }
- this._rejectionHandler0 =
- this._progressHandler0 =
- this._receiver0 =
- this._promise0 = undefined;
- } else {
- var base = index * 5 - 5;
- this[base + 3] =
- this[base + 4] =
- this[base + 0] =
- this[base + 1] =
- this[base + 2] = undefined;
- }
-};
-
-Promise.prototype._isProxied = function () {
- return (this._bitField & 4194304) === 4194304;
-};
-
-Promise.prototype._setProxied = function () {
- this._bitField = this._bitField | 4194304;
-};
-
-Promise.prototype._unsetProxied = function () {
- this._bitField = this._bitField & (~4194304);
-};
-
-Promise.prototype._isSettlePromisesQueued = function () {
- return (this._bitField &
- -1073741824) === -1073741824;
-};
-
-Promise.prototype._setSettlePromisesQueued = function () {
- this._bitField = this._bitField | -1073741824;
-};
-
-Promise.prototype._unsetSettlePromisesQueued = function () {
- this._bitField = this._bitField & (~-1073741824);
-};
-
-Promise.prototype._queueSettlePromises = function() {
- if (!this._isSettlePromisesQueued()) {
- async.invoke(this._settlePromises, this, undefined);
- this._setSettlePromisesQueued();
- }
-};
-
-Promise.prototype._fulfillUnchecked = function (value) {
- ASSERT(((! this.isFulfilled()) && (! this.isRejected())),
- "!this.isFulfilled() && !this.isRejected()");
- if (value === this) {
- var err = makeSelfResolutionError();
- this._attachExtraTrace(err);
- return this._rejectUnchecked(err, undefined);
- }
- this._setFulfilled();
- this._settledValue = value;
- this._cleanValues();
-
- if (this._length() > 0) {
- this._queueSettlePromises();
- }
-};
-
-Promise.prototype._rejectUncheckedCheckError = function (reason) {
- var trace = canAttachTrace(reason) ? reason : new Error(reason + "");
- this._rejectUnchecked(reason, trace === reason ? undefined : trace);
-};
-
-Promise.prototype._rejectUnchecked = function (reason, trace) {
- ASSERT(((! this.isFulfilled()) && (! this.isRejected())),
- "!this.isFulfilled() && !this.isRejected()");
- if (reason === this) {
- var err = makeSelfResolutionError();
- this._attachExtraTrace(err);
- return this._rejectUnchecked(err);
- }
- this._setRejected();
- this._settledValue = reason;
- this._cleanValues();
-
- if (this._isFinal()) {
- ASSERT((this._length() === 0),
- "this._length() === 0");
- async.invokeLater(function(e) {
- if ("stack" in e) {
- async.invokeFirst(
- CapturedTrace.unhandledRejection, undefined, e);
- }
- throw e;
- }, undefined, trace === undefined ? reason : trace);
- return;
- }
-
- if (trace !== undefined) this._setCarriedStackTrace(trace);
-
- if (this._length() > 0) {
- this._queueSettlePromises();
- } else {
- this._ensurePossibleRejectionHandled();
- }
-};
-
-Promise.prototype._settlePromises = function () {
- this._unsetSettlePromisesQueued();
- var len = this._length();
- this._setLength(0);
- for (var i = 0; i < len; i++) {
- this._settlePromiseAt(i);
- }
-};
-
-Promise.prototype._ensurePossibleRejectionHandled = function () {
- this._setRejectionIsUnhandled();
- if (CapturedTrace.possiblyUnhandledRejection !== undefined) {
- async.invokeLater(this._notifyUnhandledRejection, this, undefined);
- }
-};
-
-Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
- if (typeof unhandledRejectionHandled === "function") {
- async.invokeLater(unhandledRejectionHandled, undefined, this);
- }
-};
-
-Promise.prototype._notifyUnhandledRejection = function () {
- if (this._isRejectionUnhandled()) {
- var reason = this._settledValue;
- var trace = this._getCarriedStackTrace();
-
- this._setUnhandledRejectionIsNotified();
-
- if (trace !== undefined) {
- this._unsetCarriedStackTrace();
- reason = trace;
- }
- if (typeof CapturedTrace.possiblyUnhandledRejection === "function") {
- CapturedTrace.possiblyUnhandledRejection(reason, this);
- }
- }
-};
-
-var contextStack = [];
-Promise.prototype._peekContext = function () {
- var lastIndex = contextStack.length - 1;
- if (lastIndex >= 0) {
- return contextStack[lastIndex];
- }
- return undefined;
-
-};
-
-Promise.prototype._pushContext = function () {
- if (!debugging) return;
- contextStack.push(this._trace);
-};
-
-Promise.prototype._popContext = function () {
- if (!debugging) return;
- contextStack.pop();
-};
-
-Promise.prototype._resolveFromSyncValue = function (value) {
- if (value === errorObj) {
- this._setRejected();
- var reason = value.e;
- this._settledValue = reason;
- this._cleanValues();
- this._attachExtraTrace(reason);
- this._ensurePossibleRejectionHandled();
- } else {
- var maybePromise = tryConvertToPromise(value, this);
- if (maybePromise instanceof Promise) {
- this._follow(maybePromise);
- } else {
- this._setFulfilled();
- this._settledValue = value;
- this._cleanValues();
- }
- }
-};
-
-if (!CapturedTrace.isSupported()) {
- Promise.longStackTraces = function(){};
- debugging = false;
-}
-
-Promise._makeSelfResolutionError = makeSelfResolutionError;
-require("./finally.js")(Promise, NEXT_FILTER, tryConvertToPromise);
-require("./direct_resolve.js")(Promise);
-require("./synchronous_inspection.js")(Promise);
-require("./join.js")(Promise, PromiseArray, tryConvertToPromise, INTERNAL);
-Promise.RangeError = RangeError;
-Promise.CancellationError = CancellationError;
-Promise.TimeoutError = TimeoutError;
-Promise.TypeError = TypeError;
-Promise.OperationalError = OperationalError;
-Promise.RejectionError = OperationalError;
-Promise.AggregateError = errors.AggregateError;
-
-util.toFastProperties(Promise);
-util.toFastProperties(Promise.prototype);
-Promise.Promise = Promise;
-CapturedTrace.setBounds(async.firstLineError, util.lastLineError);
-require('./timers.js')(Promise,INTERNAL,tryConvertToPromise);
-require('./race.js')(Promise,INTERNAL,tryConvertToPromise);
-require('./call_get.js')(Promise);
-require('./generators.js')(Promise,apiRejection,INTERNAL,tryConvertToPromise);
-require('./map.js')(Promise,PromiseArray,apiRejection,tryConvertToPromise,INTERNAL);
-require('./nodeify.js')(Promise);
-require('./promisify.js')(Promise,INTERNAL);
-require('./props.js')(Promise,PromiseArray,tryConvertToPromise);
-require('./reduce.js')(Promise,PromiseArray,apiRejection,tryConvertToPromise,INTERNAL);
-require('./settle.js')(Promise,PromiseArray);
-require('./some.js')(Promise,PromiseArray,apiRejection);
-require('./progress.js')(Promise,PromiseArray);
-require('./cancel.js')(Promise,INTERNAL);
-require('./filter.js')(Promise,INTERNAL);
-require('./any.js')(Promise,PromiseArray);
-require('./each.js')(Promise,INTERNAL);
-require('./using.js')(Promise,apiRejection,tryConvertToPromise);
-
-Promise.prototype = Promise.prototype;
-return Promise;
-
-};
-
-},{"./any.js":18,"./assert.js":19,"./async.js":20,"./call_get.js":22,"./cancel.js":23,"./captured_trace.js":24,"./catch_filter.js":25,"./direct_resolve.js":26,"./each.js":27,"./errors.js":28,"./errors_api_rejection":29,"./filter.js":31,"./finally.js":32,"./generators.js":33,"./join.js":34,"./map.js":35,"./nodeify.js":36,"./progress.js":37,"./promise_array.js":39,"./promise_resolver.js":40,"./promisify.js":41,"./props.js":42,"./race.js":44,"./reduce.js":45,"./settle.js":47,"./some.js":48,"./synchronous_inspection.js":49,"./thenables.js":50,"./timers.js":51,"./using.js":52,"./util.js":53,"__browserify_process":16}],39:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, INTERNAL, tryConvertToPromise) {
-var ASSERT = require("./assert.js");
-var canAttachTrace = require("./errors.js").canAttachTrace;
-var util = require("./util.js");
-var isArray = util.isArray;
-
-function toResolutionValue(val) {
- switch(val) {
- case -1: return undefined;
- case -2: return [];
- case -3: return {};
- }
- ASSERT(false,
- "false");
-}
-
-function PromiseArray(values) {
- ASSERT((arguments.length === 1),
- "arguments.length === 1");
- var promise = this._promise = new Promise(INTERNAL);
- var parent;
- if (values instanceof Promise) {
- parent = values;
- promise._propagateFrom(parent, 1 | 4);
- }
- promise._setTrace(parent);
- this._values = values;
- this._length = 0;
- this._totalResolved = 0;
- this._init(undefined, -2);
-}
-PromiseArray.prototype.length = function () {
- return this._length;
-};
-
-PromiseArray.prototype.promise = function () {
- return this._promise;
-};
-
-PromiseArray.prototype._init = function init(_, resolveValueIfEmpty) {
-
- var values = tryConvertToPromise(this._values, undefined);
- if (values instanceof Promise) {
- this._values = values;
- values._setBoundTo(this._promise._boundTo);
- if (values.isFulfilled()) {
- values = values._settledValue;
- if (!isArray(values)) {
- var err = new Promise.TypeError("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
- this.__hardReject__(err);
- return;
- }
- } else if (values.isPending()) {
- ASSERT(((typeof resolveValueIfEmpty) === "number"),
- "typeof resolveValueIfEmpty === \u0022number\u0022");
- ASSERT((resolveValueIfEmpty < 0),
- "resolveValueIfEmpty < 0");
- values._then(
- init,
- this._reject,
- undefined,
- this,
- resolveValueIfEmpty
- );
- return;
- } else {
- values._unsetRejectionIsUnhandled();
- this._reject(values._settledValue);
- return;
- }
- } else if (!isArray(values)) {
- var err = new Promise.TypeError("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
- this.__hardReject__(err);
- return;
- }
-
- if (values.length === 0) {
- if (resolveValueIfEmpty === -5) {
- this._resolveEmptyArray();
- }
- else {
- this._resolve(toResolutionValue(resolveValueIfEmpty));
- }
- return;
- }
- var len = this.getActualLength(values.length);
- this._length = len;
- this._values = this.shouldCopyValues() ? new Array(len) : this._values;
- var promise = this._promise;
- for (var i = 0; i < len; ++i) {
- if (this._isResolved()) return;
- var maybePromise = tryConvertToPromise(values[i], promise);
- if (maybePromise instanceof Promise) {
- if (maybePromise.isPending()) {
- maybePromise._proxyPromiseArray(this, i);
- } else if (maybePromise.isFulfilled()) {
- this._promiseFulfilled(maybePromise._settledValue, i);
- } else {
- maybePromise._unsetRejectionIsUnhandled();
- this._promiseRejected(maybePromise._settledValue, i);
- }
- } else {
- this._promiseFulfilled(maybePromise, i);
- }
- }
-};
-
-PromiseArray.prototype._isResolved = function () {
- return this._values === null;
-};
-
-PromiseArray.prototype._resolve = function (value) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- ASSERT((! (value instanceof Promise)),
- "!(value instanceof Promise)");
- this._values = null;
- this._promise._fulfill(value);
-};
-
-PromiseArray.prototype.__hardReject__ =
-PromiseArray.prototype._reject = function (reason) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- this._values = null;
- var trace = canAttachTrace(reason) ? reason : new Error(reason + "");
- this._promise._attachExtraTrace(trace);
- this._promise._reject(reason, trace);
-};
-
-PromiseArray.prototype._promiseProgressed = function (progressValue, index) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- ASSERT(isArray(this._values),
- "isArray(this._values)");
- this._promise._progress({
- index: index,
- value: progressValue
- });
-};
-
-
-PromiseArray.prototype._promiseFulfilled = function (value, index) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- ASSERT(isArray(this._values),
- "isArray(this._values)");
- ASSERT(((typeof index) === "number"),
- "typeof index === \u0022number\u0022");
- this._values[index] = value;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- this._resolve(this._values);
- }
-};
-
-PromiseArray.prototype._promiseRejected = function (reason, index) {
- ASSERT((index >= 0),
- "index >= 0");
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- ASSERT(isArray(this._values),
- "isArray(this._values)");
- this._totalResolved++;
- this._reject(reason);
-};
-
-PromiseArray.prototype.shouldCopyValues = function () {
- return true;
-};
-
-PromiseArray.prototype.getActualLength = function (len) {
- return len;
-};
-
-return PromiseArray;
-};
-
-},{"./assert.js":19,"./errors.js":28,"./util.js":53}],40:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var util = require("./util.js");
-var maybeWrapAsError = util.maybeWrapAsError;
-var errors = require("./errors.js");
-var TimeoutError = errors.TimeoutError;
-var OperationalError = errors.OperationalError;
-var async = require("./async.js");
-var haveGetters = util.haveGetters;
-var es5 = require("./es5.js");
-
-function isUntypedError(obj) {
- return obj instanceof Error &&
- es5.getPrototypeOf(obj) === Error.prototype;
-}
-
-function wrapAsOperationalError(obj) {
- var ret;
- if (isUntypedError(obj)) {
- ret = new OperationalError(obj);
- } else {
- ret = obj;
- }
- errors.markAsOriginatingFromRejection(ret);
- return ret;
-}
-
-function nodebackForPromise(promise) {
- return function(err, value) {
- if (promise === null) return;
-
- if (err) {
- var wrapped = wrapAsOperationalError(maybeWrapAsError(err));
- promise._attachExtraTrace(wrapped);
- promise._reject(wrapped);
- } else if (arguments.length > 2) {
- var $_len = arguments.length;var args = new Array($_len - 1); for(var $_i = 1; $_i < $_len; ++$_i) {args[$_i - 1] = arguments[$_i];}
- promise._fulfill(args);
- } else {
- promise._fulfill(value);
- }
-
- promise = null;
- };
-}
-
-
-var PromiseResolver;
-if (!haveGetters) {
- PromiseResolver = function (promise) {
- this.promise = promise;
- this.asCallback = nodebackForPromise(promise);
- this.callback = this.asCallback;
- };
-}
-else {
- PromiseResolver = function (promise) {
- this.promise = promise;
- };
-}
-if (haveGetters) {
- var prop = {
- get: function() {
- return nodebackForPromise(this.promise);
- }
- };
- es5.defineProperty(PromiseResolver.prototype, "asCallback", prop);
- es5.defineProperty(PromiseResolver.prototype, "callback", prop);
-}
-
-PromiseResolver._nodebackForPromise = nodebackForPromise;
-
-PromiseResolver.prototype.toString = function () {
- return "[object PromiseResolver]";
-};
-
-PromiseResolver.prototype.resolve =
-PromiseResolver.prototype.fulfill = function (value) {
- if (!(this instanceof PromiseResolver)) {
- throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
- }
-
- var promise = this.promise;
- if (promise._tryFollow(value)) {
- return;
- }
- async.invoke(promise._fulfill, promise, value);
-};
-
-PromiseResolver.prototype.reject = function (reason) {
- if (!(this instanceof PromiseResolver)) {
- throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
- }
-
- var promise = this.promise;
- errors.markAsOriginatingFromRejection(reason);
- var trace = errors.canAttachTrace(reason) ? reason : new Error(reason + "");
- promise._attachExtraTrace(trace);
- async.invoke(promise._reject, promise, reason);
- if (trace !== reason) {
- async.invoke(this._setCarriedStackTrace, this, trace);
- }
-};
-
-PromiseResolver.prototype.progress = function (value) {
- if (!(this instanceof PromiseResolver)) {
- throw new TypeError("Illegal invocation, resolver resolve/reject must be called within a resolver context. Consider using the promise constructor instead.\u000a\u000a See http://goo.gl/sdkXL9\u000a");
- }
- async.invoke(this.promise._progress, this.promise, value);
-};
-
-PromiseResolver.prototype.cancel = function () {
- async.invoke(this.promise.cancel, this.promise, undefined);
-};
-
-PromiseResolver.prototype.timeout = function () {
- this.reject(new TimeoutError("timeout"));
-};
-
-PromiseResolver.prototype.isResolved = function () {
- return this.promise.isResolved();
-};
-
-PromiseResolver.prototype.toJSON = function () {
- return this.promise.toJSON();
-};
-
-PromiseResolver.prototype._setCarriedStackTrace = function (trace) {
- if (this.promise.isRejected()) {
- this.promise._setCarriedStackTrace(trace);
- }
-};
-
-module.exports = PromiseResolver;
-
-},{"./async.js":20,"./errors.js":28,"./es5.js":30,"./util.js":53}],41:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, INTERNAL) {
-var THIS = {};
-var util = require("./util.js");
-var nodebackForPromise = require("./promise_resolver.js")
- ._nodebackForPromise;
-var withAppended = util.withAppended;
-var maybeWrapAsError = util.maybeWrapAsError;
-var canEvaluate = util.canEvaluate;
-var ASSERT = require("./assert.js");
-var TypeError = require("./errors").TypeError;
-var defaultSuffix = "Async";
-var defaultFilter = function(name, func) {
- return util.isIdentifier(name) &&
- name.charAt(0) !== "_" &&
- !util.isClass(func);
-};
-var defaultPromisified = {__isPromisified__: true};
-
-
-function escapeIdentRegex(str) {
- return str.replace(/([$])/, "\\$");
-}
-
-function isPromisified(fn) {
- try {
- return fn.__isPromisified__ === true;
- }
- catch (e) {
- return false;
- }
-}
-
-function hasPromisified(obj, key, suffix) {
- var val = util.getDataPropertyOrDefault(obj, key + suffix,
- defaultPromisified);
- return val ? isPromisified(val) : false;
-}
-function checkValid(ret, suffix, suffixRegexp) {
- for (var i = 0; i < ret.length; i += 2) {
- var key = ret[i];
- if (suffixRegexp.test(key)) {
- var keyWithoutAsyncSuffix = key.replace(suffixRegexp, "");
- for (var j = 0; j < ret.length; j += 2) {
- if (ret[j] === keyWithoutAsyncSuffix) {
- throw new TypeError("Cannot promisify an API that has normal methods with '%s'-suffix\u000a\u000a See http://goo.gl/iWrZbw\u000a"
- .replace("%s", suffix));
- }
- }
- }
- }
-}
-
-function promisifiableMethods(obj, suffix, suffixRegexp, filter) {
- var keys = util.inheritedDataKeys(obj);
- var ret = [];
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- var value = obj[key];
- if (typeof value === "function" &&
- !isPromisified(value) &&
- !hasPromisified(obj, key, suffix) &&
- filter(key, value, obj)) {
- ret.push(key, value);
- }
- }
- checkValid(ret, suffix, suffixRegexp);
- return ret;
-}
-
-function switchCaseArgumentOrder(likelyArgumentCount) {
- var ret = [likelyArgumentCount];
- var min = Math.max(0, likelyArgumentCount - 1 - 5);
- for(var i = likelyArgumentCount - 1; i >= min; --i) {
- if (i === likelyArgumentCount) continue;
- ret.push(i);
- }
- for(var i = likelyArgumentCount + 1; i <= 5; ++i) {
- ret.push(i);
- }
- return ret;
-}
-
-function argumentSequence(argumentCount) {
- return util.filledRange(argumentCount, "arguments[", "]");
-}
-
-function parameterDeclaration(parameterCount) {
- return util.filledRange(parameterCount, "_arg", "");
-}
-
-function parameterCount(fn) {
- if (typeof fn.length === "number") {
- return Math.max(Math.min(fn.length, 1023 + 1), 0);
- }
- return 0;
-}
-
-function generatePropertyAccess(key) {
- if (util.isIdentifier(key)) {
- return "." + key;
- }
- else return "['" + key.replace(/(['\\])/g, "\\$1") + "']";
-}
-
-function makeNodePromisifiedEval(callback, receiver, originalName, fn, suffix) {
- var newParameterCount = Math.max(0, parameterCount(fn) - 1);
- var argumentOrder = switchCaseArgumentOrder(newParameterCount);
- var callbackName =
- (typeof originalName === "string" && util.isIdentifier(originalName)
- ? originalName + suffix
- : "promisified");
-
- function generateCallForArgumentCount(count) {
- var args = argumentSequence(count).join(", ");
- var comma = count > 0 ? ", " : "";
- var ret;
- if (typeof callback === "string") {
- ret = " \n\
- this.method({{args}}, fn); \n\
- break; \n\
- ".replace(".method", generatePropertyAccess(callback));
- } else if (receiver === THIS) {
- ret = " \n\
- callback.call(this, {{args}}, fn); \n\
- break; \n\
- ";
- } else if (receiver !== undefined) {
- ret = " \n\
- callback.call(receiver, {{args}}, fn); \n\
- break; \n\
- ";
- } else {
- ret = " \n\
- callback({{args}}, fn); \n\
- break; \n\
- ";
- }
- return ret.replace("{{args}}", args).replace(", ", comma);
- }
-
- function generateArgumentSwitchCase() {
- var ret = "";
- for(var i = 0; i < argumentOrder.length; ++i) {
- ret += "case " + argumentOrder[i] +":" +
- generateCallForArgumentCount(argumentOrder[i]);
- }
- var codeForCall;
- if (typeof callback === "string") {
- codeForCall = " \n\
- this.property.apply(this, args); \n\
- "
- .replace(".property", generatePropertyAccess(callback));
- } else if (receiver === THIS) {
- codeForCall = " \n\
- callback.apply(this, args); \n\
- ";
- } else {
- codeForCall = " \n\
- callback.apply(receiver, args); \n\
- ";
- }
-
- ret += " \n\
- default: \n\
- var args = new Array(len + 1); \n\
- var i = 0; \n\
- for (var i = 0; i < len; ++i) { \n\
- args[i] = arguments[i]; \n\
- } \n\
- args[i] = fn; \n\
- [CodeForCall] \n\
- break; \n\
- ".replace("[CodeForCall]", codeForCall);
- return ret;
- }
-
- return new Function("Promise",
- "callback",
- "receiver",
- "withAppended",
- "maybeWrapAsError",
- "nodebackForPromise",
- "INTERNAL"," \n\
- var ret = function (Parameters) { \n\
- 'use strict'; \n\
- var len = arguments.length; \n\
- var promise = new Promise(INTERNAL); \n\
- promise._setTrace(undefined); \n\
- var fn = nodebackForPromise(promise); \n\
- try { \n\
- switch(len) { \n\
- [CodeForSwitchCase] \n\
- } \n\
- } catch (e) { \n\
- var wrapped = maybeWrapAsError(e); \n\
- promise._attachExtraTrace(wrapped); \n\
- promise._reject(wrapped); \n\
- } \n\
- return promise; \n\
- }; \n\
- ret.__isPromisified__ = true; \n\
- return ret; \n\
- "
- .replace("FunctionName", callbackName)
- .replace("Parameters", parameterDeclaration(newParameterCount))
- .replace("[CodeForSwitchCase]", generateArgumentSwitchCase()))(
- Promise,
- callback,
- receiver,
- withAppended,
- maybeWrapAsError,
- nodebackForPromise,
- INTERNAL
- );
-}
-
-function makeNodePromisifiedClosure(callback, receiver) {
- function promisified() {
- var _receiver = receiver;
- if (receiver === THIS) _receiver = this;
- if (typeof callback === "string") {
- callback = _receiver[callback];
- }
- ASSERT(((typeof callback) === "function"),
- "typeof callback === \u0022function\u0022");
- var promise = new Promise(INTERNAL);
- promise._setTrace(undefined);
- var fn = nodebackForPromise(promise);
- try {
- callback.apply(_receiver, withAppended(arguments, fn));
- } catch(e) {
- var wrapped = maybeWrapAsError(e);
- promise._attachExtraTrace(wrapped);
- promise._reject(wrapped);
- }
- return promise;
- }
- promisified.__isPromisified__ = true;
- return promisified;
-}
-
-var makeNodePromisified = canEvaluate
- ? makeNodePromisifiedEval
- : makeNodePromisifiedClosure;
-
-function promisifyAll(obj, suffix, filter, promisifier) {
- ASSERT(((typeof suffix) === "string"),
- "typeof suffix === \u0022string\u0022");
- ASSERT(((typeof filter) === "function"),
- "typeof filter === \u0022function\u0022");
- var suffixRegexp = new RegExp(escapeIdentRegex(suffix) + "$");
- var methods =
- promisifiableMethods(obj, suffix, suffixRegexp, filter);
-
- for (var i = 0, len = methods.length; i < len; i+= 2) {
- var key = methods[i];
- var fn = methods[i+1];
- var promisifiedKey = key + suffix;
- obj[promisifiedKey] = promisifier === makeNodePromisified
- ? makeNodePromisified(key, THIS, key, fn, suffix)
- : promisifier(fn);
- }
- util.toFastProperties(obj);
- return obj;
-}
-
-function promisify(callback, receiver) {
- return makeNodePromisified(callback, receiver, undefined, callback);
-}
-
-Promise.promisify = function (fn, receiver) {
- if (typeof fn !== "function") {
- throw new TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- }
- if (isPromisified(fn)) {
- return fn;
- }
- return promisify(fn, arguments.length < 2 ? THIS : receiver);
-};
-
-Promise.promisifyAll = function (target, options) {
- if (typeof target !== "function" && typeof target !== "object") {
- throw new TypeError("the target of promisifyAll must be an object or a function\u000a\u000a See http://goo.gl/9ITlV0\u000a");
- }
- options = Object(options);
- var suffix = options.suffix;
- if (typeof suffix !== "string") suffix = defaultSuffix;
- var filter = options.filter;
- if (typeof filter !== "function") filter = defaultFilter;
- var promisifier = options.promisifier;
- if (typeof promisifier !== "function") promisifier = makeNodePromisified;
-
- if (!util.isIdentifier(suffix)) {
- throw new RangeError("suffix must be a valid identifier\u000a\u000a See http://goo.gl/8FZo5V\u000a");
- }
-
- var keys = util.inheritedDataKeys(target, {includeHidden: true});
- for (var i = 0; i < keys.length; ++i) {
- var value = target[keys[i]];
- if (keys[i] !== "constructor" &&
- util.isClass(value)) {
- promisifyAll(value.prototype, suffix, filter, promisifier);
- promisifyAll(value, suffix, filter, promisifier);
- }
- }
-
- return promisifyAll(target, suffix, filter, promisifier);
-};
-};
-
-
-},{"./assert.js":19,"./errors":28,"./promise_resolver.js":40,"./util.js":53}],42:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, PromiseArray, tryConvertToPromise) {
-var ASSERT = require("./assert.js");
-var util = require("./util.js");
-var apiRejection = require("./errors_api_rejection")(Promise);
-var isObject = util.isObject;
-var es5 = require("./es5.js");
-
-function PropertiesPromiseArray(obj) {
- var keys = es5.keys(obj);
- var len = keys.length;
- var values = new Array(len * 2);
- for (var i = 0; i < len; ++i) {
- var key = keys[i];
- values[i] = obj[key];
- values[i + len] = key;
- }
- this.constructor$(values);
-}
-util.inherits(PropertiesPromiseArray, PromiseArray);
-
-PropertiesPromiseArray.prototype._init = function () {
- this._init$(undefined, -3) ;
-};
-
-PropertiesPromiseArray.prototype._promiseFulfilled = function (value, index) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- ASSERT((! (value instanceof Promise)),
- "!(value instanceof Promise)");
- this._values[index] = value;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- var val = {};
- var keyOffset = this.length();
- for (var i = 0, len = this.length(); i < len; ++i) {
- val[this._values[i + keyOffset]] = this._values[i];
- }
- this._resolve(val);
- }
-};
-
-PropertiesPromiseArray.prototype._promiseProgressed = function (value, index) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
-
- this._promise._progress({
- key: this._values[index + this.length()],
- value: value
- });
-};
-
-PropertiesPromiseArray.prototype.shouldCopyValues = function () {
- return false;
-};
-
-PropertiesPromiseArray.prototype.getActualLength = function (len) {
- return len >> 1;
-};
-
-function props(promises) {
- var ret;
- var castValue = tryConvertToPromise(promises, undefined);
-
- if (!isObject(castValue)) {
- return apiRejection("cannot await properties of a non-object\u000a\u000a See http://goo.gl/OsFKC8\u000a");
- } else if (castValue instanceof Promise) {
- ret = castValue._then(
- Promise.props, undefined, undefined, undefined, undefined);
- } else {
- ret = new PropertiesPromiseArray(castValue).promise();
- }
-
- if (castValue instanceof Promise) {
- ret._propagateFrom(castValue, 4);
- }
- return ret;
-}
-
-Promise.prototype.props = function () {
- return props(this);
-};
-
-Promise.props = function (promises) {
- return props(promises);
-};
-};
-
-},{"./assert.js":19,"./errors_api_rejection":29,"./es5.js":30,"./util.js":53}],43:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var ASSERT = require("./assert.js");
-function arrayCopy(src, srcIndex, dst, dstIndex, len) {
- for (var j = 0; j < len; ++j) {
- dst[j + dstIndex] = src[j + srcIndex];
- }
-}
-
-function Queue(capacity) {
- this._capacity = capacity;
- this._length = 0;
- this._front = 0;
- this._makeCapacity();
-}
-
-Queue.prototype._willBeOverCapacity = function (size) {
- return this._capacity < size;
-};
-
-Queue.prototype._pushOne = function (arg) {
- var length = this.length();
- this._checkCapacity(length + 1);
- var i = (this._front + length) & (this._capacity - 1);
- this[i] = arg;
- this._length = length + 1;
-};
-
-Queue.prototype._unshiftOne = function(value) {
- var capacity = this._capacity;
- this._checkCapacity(this.length() + 1);
- var front = this._front;
- var i = (((( front - 1 ) &
- ( capacity - 1) ) ^ capacity ) - capacity );
- this[i] = value;
- this._front = i;
- this._length = this.length() + 1;
-};
-
-Queue.prototype.unshift = function(fn, receiver, arg) {
- this._unshiftOne(arg);
- this._unshiftOne(receiver);
- this._unshiftOne(fn);
-};
-
-Queue.prototype.push = function (fn, receiver, arg) {
- ASSERT((arguments.length === 3),
- "arguments.length === 3");
- ASSERT(((typeof fn) === "function"),
- "typeof fn === \u0022function\u0022");
- var length = this.length() + 3;
- if (this._willBeOverCapacity(length)) {
- this._pushOne(fn);
- this._pushOne(receiver);
- this._pushOne(arg);
- return;
- }
- var j = this._front + length - 3;
- this._checkCapacity(length);
- var wrapMask = this._capacity - 1;
- this[(j + 0) & wrapMask] = fn;
- this[(j + 1) & wrapMask] = receiver;
- this[(j + 2) & wrapMask] = arg;
- this._length = length;
-};
-
-Queue.prototype.shift = function () {
- ASSERT((this.length() > 0),
- "this.length() > 0");
- var front = this._front,
- ret = this[front];
-
- this[front] = undefined;
- this._front = (front + 1) & (this._capacity - 1);
- this._length--;
- return ret;
-};
-
-Queue.prototype.length = function () {
- return this._length;
-};
-
-Queue.prototype._makeCapacity = function () {
- var len = this._capacity;
- for (var i = 0; i < len; ++i) {
- this[i] = undefined;
- }
-};
-
-Queue.prototype._checkCapacity = function (size) {
- if (this._capacity < size) {
- this._resizeTo(this._capacity << 3);
- }
-};
-
-Queue.prototype._resizeTo = function (capacity) {
- var oldFront = this._front;
- var oldCapacity = this._capacity;
- var oldQueue = new Array(oldCapacity);
- var length = this.length();
-
- arrayCopy(this, 0, oldQueue, 0, oldCapacity);
- this._capacity = capacity;
- this._makeCapacity();
- this._front = 0;
- if (oldFront + length <= oldCapacity) {
- arrayCopy(oldQueue, oldFront, this, 0, length);
- } else { var lengthBeforeWrapping =
- length - ((oldFront + length) & (oldCapacity - 1));
-
- arrayCopy(oldQueue, oldFront, this, 0, lengthBeforeWrapping);
- arrayCopy(oldQueue, 0, this, lengthBeforeWrapping,
- length - lengthBeforeWrapping);
- }
-};
-
-module.exports = Queue;
-
-},{"./assert.js":19}],44:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, INTERNAL, tryConvertToPromise) {
-var apiRejection = require("./errors_api_rejection.js")(Promise);
-var isArray = require("./util.js").isArray;
-
-var raceLater = function (promise) {
- return promise.then(function(array) {
- return race(array, promise);
- });
-};
-
-var hasOwn = {}.hasOwnProperty;
-function race(promises, parent) {
- var maybePromise = tryConvertToPromise(promises, undefined);
-
- if (maybePromise instanceof Promise) {
- return raceLater(maybePromise);
- } else if (!isArray(promises)) {
- return apiRejection("expecting an array, a promise or a thenable\u000a\u000a See http://goo.gl/s8MMhc\u000a");
- }
-
- var ret = new Promise(INTERNAL);
- if (parent !== undefined) {
- ret._propagateFrom(parent, 7);
- } else {
- ret._setTrace(undefined);
- }
- var fulfill = ret._fulfill;
- var reject = ret._reject;
- for (var i = 0, len = promises.length; i < len; ++i) {
- var val = promises[i];
-
- if (val === undefined && !(hasOwn.call(promises, i))) {
- continue;
- }
-
- Promise.cast(val)._then(fulfill, reject, undefined, ret, null);
- }
- return ret;
-}
-
-Promise.race = function (promises) {
- return race(promises, undefined);
-};
-
-Promise.prototype.race = function () {
- return race(this, undefined);
-};
-
-};
-
-},{"./errors_api_rejection.js":29,"./util.js":53}],45:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise,
- PromiseArray,
- apiRejection,
- tryConvertToPromise,
- INTERNAL) {
-var ASSERT = require("./assert.js");
-var util = require("./util.js");
-var tryCatch4 = util.tryCatch4;
-var tryCatch3 = util.tryCatch3;
-var errorObj = util.errorObj;
-function ReductionPromiseArray(promises, fn, accum, _each) {
- this.constructor$(promises);
- this._preservedValues = _each === INTERNAL ? [] : null;
- this._zerothIsAccum = (accum === undefined);
- this._gotAccum = false;
- this._reducingIndex = (this._zerothIsAccum ? 1 : 0);
- this._valuesPhase = undefined;
-
- var maybePromise = tryConvertToPromise(accum, undefined);
- var rejected = false;
- var isPromise = maybePromise instanceof Promise;
- if (isPromise) {
- if (maybePromise.isPending()) {
- maybePromise._proxyPromiseArray(this, -1);
- } else if (maybePromise.isFulfilled()) {
- accum = maybePromise._settledValue;
- this._gotAccum = true;
- } else {
- maybePromise._unsetRejectionIsUnhandled();
- this._reject(maybePromise.reason());
- rejected = true;
- }
- }
- if (!(isPromise || this._zerothIsAccum)) this._gotAccum = true;
- this._callback = fn;
- this._accum = accum;
- if (!rejected) this._init$(undefined, -5);
-}
-util.inherits(ReductionPromiseArray, PromiseArray);
-
-ReductionPromiseArray.prototype._init = function () {};
-
-ReductionPromiseArray.prototype._resolveEmptyArray = function () {
- if (this._gotAccum || this._zerothIsAccum) {
- this._resolve(this._preservedValues !== null
- ? [] : this._accum);
- }
-};
-
-ReductionPromiseArray.prototype._promiseFulfilled = function (value, index) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- var values = this._values;
- values[index] = value;
- var length = this.length();
- var preservedValues = this._preservedValues;
- var isEach = preservedValues !== null;
- var gotAccum = this._gotAccum;
- var valuesPhase = this._valuesPhase;
- var valuesPhaseIndex;
- if (!valuesPhase) {
- valuesPhase = this._valuesPhase = Array(length);
- for (valuesPhaseIndex=0; valuesPhaseIndex
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var ASSERT = require("./assert.js");
-var schedule;
-var _MutationObserver;
-if (typeof process === "object" && typeof process.version === "string") {
- schedule = function (fn) {
- process.nextTick(fn);
- };
-}
-else if ((typeof MutationObserver !== "undefined" &&
- (_MutationObserver = MutationObserver)) ||
- (typeof WebKitMutationObserver !== "undefined" &&
- (_MutationObserver = WebKitMutationObserver))) {
- schedule = (function() {
- var div = document.createElement("div");
- var queuedFn;
- var observer = new _MutationObserver(function() {
- ASSERT((queuedFn !== undefined),
- "queuedFn !== undefined");
- var fn = queuedFn;
- queuedFn = undefined;
- fn();
- });
- observer.observe(div, {
- attributes: true
- });
- return function(fn) {
- ASSERT((queuedFn === undefined),
- "queuedFn === undefined");
- queuedFn = fn;
- div.classList.toggle("foo");
- };
-
- })();
-}
-else if (typeof setTimeout !== "undefined") {
- schedule = function (fn) {
- setTimeout(fn, 0);
- };
-}
-else throw new Error("no async scheduler available");
-module.exports = schedule;
-
-},{"./assert.js":19,"__browserify_process":16}],47:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports =
- function(Promise, PromiseArray) {
-var ASSERT = require("./assert.js");
-var PromiseInspection = Promise.PromiseInspection;
-var util = require("./util.js");
-
-function SettledPromiseArray(values) {
- this.constructor$(values);
-}
-util.inherits(SettledPromiseArray, PromiseArray);
-
-SettledPromiseArray.prototype._promiseResolved = function (index, inspection) {
- ASSERT(((typeof index) === "number"),
- "typeof index === \u0022number\u0022");
- this._values[index] = inspection;
- var totalResolved = ++this._totalResolved;
- if (totalResolved >= this._length) {
- this._resolve(this._values);
- }
-};
-
-SettledPromiseArray.prototype._promiseFulfilled = function (value, index) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- ASSERT(((typeof index) === "number"),
- "typeof index === \u0022number\u0022");
- var ret = new PromiseInspection();
- ret._bitField = 268435456;
- ret._settledValue = value;
- this._promiseResolved(index, ret);
-};
-SettledPromiseArray.prototype._promiseRejected = function (reason, index) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- ASSERT(((typeof index) === "number"),
- "typeof index === \u0022number\u0022");
- var ret = new PromiseInspection();
- ret._bitField = 134217728;
- ret._settledValue = reason;
- this._promiseResolved(index, ret);
-};
-
-Promise.settle = function (promises) {
- return new SettledPromiseArray(promises).promise();
-};
-
-Promise.prototype.settle = function () {
- return new SettledPromiseArray(this).promise();
-};
-};
-
-},{"./assert.js":19,"./util.js":53}],48:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports =
-function(Promise, PromiseArray, apiRejection) {
-var ASSERT = require("./assert.js");
-var util = require("./util.js");
-var RangeError = require("./errors.js").RangeError;
-var AggregateError = require("./errors.js").AggregateError;
-var isArray = util.isArray;
-
-
-function SomePromiseArray(values) {
- this.constructor$(values);
- this._howMany = 0;
- this._unwrap = false;
- this._initialized = false;
-}
-util.inherits(SomePromiseArray, PromiseArray);
-
-SomePromiseArray.prototype._init = function () {
- if (!this._initialized) {
- return;
- }
- if (this._howMany === 0) {
- this._resolve([]);
- return;
- }
- this._init$(undefined, -5);
- var isArrayResolved = isArray(this._values);
- if (!this._isResolved() &&
- isArrayResolved &&
- this._howMany > this._canPossiblyFulfill()) {
- this._reject(this._getRangeError(this.length()));
- }
-};
-
-SomePromiseArray.prototype.init = function () {
- this._initialized = true;
- this._init();
-};
-
-SomePromiseArray.prototype.setUnwrap = function () {
- this._unwrap = true;
-};
-
-SomePromiseArray.prototype.howMany = function () {
- return this._howMany;
-};
-
-SomePromiseArray.prototype.setHowMany = function (count) {
- if (this._isResolved()) return;
- this._howMany = count;
-};
-
-SomePromiseArray.prototype._promiseFulfilled = function (value) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- this._addFulfilled(value);
- if (this._fulfilled() === this.howMany()) {
- this._values.length = this.howMany();
- if (this.howMany() === 1 && this._unwrap) {
- this._resolve(this._values[0]);
- } else {
- this._resolve(this._values);
- }
- }
-
-};
-SomePromiseArray.prototype._promiseRejected = function (reason) {
- ASSERT((! this._isResolved()),
- "!this._isResolved()");
- this._addRejected(reason);
- if (this.howMany() > this._canPossiblyFulfill()) {
- var e = new AggregateError();
- for (var i = this.length(); i < this._values.length; ++i) {
- e.push(this._values[i]);
- }
- this._reject(e);
- }
-};
-
-SomePromiseArray.prototype._fulfilled = function () {
- return this._totalResolved;
-};
-
-SomePromiseArray.prototype._rejected = function () {
- return this._values.length - this.length();
-};
-
-SomePromiseArray.prototype._addRejected = function (reason) {
- this._values.push(reason);
-};
-
-SomePromiseArray.prototype._addFulfilled = function (value) {
- this._values[this._totalResolved++] = value;
-};
-
-SomePromiseArray.prototype._canPossiblyFulfill = function () {
- return this.length() - this._rejected();
-};
-
-SomePromiseArray.prototype._getRangeError = function (count) {
- var message = "Input array must contain at least " +
- this._howMany + " items but contains only " + count + " items";
- return new RangeError(message);
-};
-
-SomePromiseArray.prototype._resolveEmptyArray = function () {
- this._reject(this._getRangeError(0));
-};
-
-function some(promises, howMany) {
- if ((howMany | 0) !== howMany || howMany < 0) {
- return apiRejection("expecting a positive integer\u000a\u000a See http://goo.gl/1wAmHx\u000a");
- }
- var ret = new SomePromiseArray(promises);
- var promise = ret.promise();
- if (promise.isRejected()) {
- return promise;
- }
- ASSERT((ret instanceof SomePromiseArray),
- "ret instanceof SomePromiseArray");
- ret.setHowMany(howMany);
- ret.init();
- return promise;
-}
-
-Promise.some = function (promises, howMany) {
- return some(promises, howMany);
-};
-
-Promise.prototype.some = function (howMany) {
- return some(this, howMany);
-};
-
-Promise._SomePromiseArray = SomePromiseArray;
-};
-
-},{"./assert.js":19,"./errors.js":28,"./util.js":53}],49:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise) {
-function PromiseInspection(promise) {
- if (promise !== undefined) {
- this._bitField = promise._bitField;
- this._settledValue = promise.isResolved()
- ? promise._settledValue
- : undefined;
- }
- else {
- this._bitField = 0;
- this._settledValue = undefined;
- }
-}
-
-PromiseInspection.prototype.isFulfilled =
-Promise.prototype.isFulfilled = function () {
- return (this._bitField & 268435456) > 0;
-};
-
-PromiseInspection.prototype.isRejected =
-Promise.prototype.isRejected = function () {
- return (this._bitField & 134217728) > 0;
-};
-
-PromiseInspection.prototype.isPending =
-Promise.prototype.isPending = function () {
- return (this._bitField & 402653184) === 0;
-};
-
-PromiseInspection.prototype.value =
-Promise.prototype.value = function () {
- if (!this.isFulfilled()) {
- throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\u000a\u000a See http://goo.gl/hc1DLj\u000a");
- }
- return this._settledValue;
-};
-
-PromiseInspection.prototype.error =
-PromiseInspection.prototype.reason =
-Promise.prototype.reason = function () {
- if (!this.isRejected()) {
- throw new TypeError("cannot get rejection reason of a non-rejected promise\u000a\u000a See http://goo.gl/hPuiwB\u000a");
- }
- return this._settledValue;
-};
-
-PromiseInspection.prototype.isResolved =
-Promise.prototype.isResolved = function () {
- return (this._bitField & 402653184) > 0;
-};
-
-Promise.PromiseInspection = PromiseInspection;
-};
-
-},{}],50:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function(Promise, INTERNAL) {
-var ASSERT = require("./assert.js");
-var util = require("./util.js");
-var canAttachTrace = require("./errors.js").canAttachTrace;
-var errorObj = util.errorObj;
-var isObject = util.isObject;
-
-function getThen(obj) {
- try {
- return obj.then;
- }
- catch(e) {
- errorObj.e = e;
- return errorObj;
- }
-}
-
-function tryConvertToPromise(obj, traceParent) {
- ASSERT((arguments.length === 2),
- "arguments.length === 2");
- if (isObject(obj)) {
- if (obj instanceof Promise) {
- return obj;
- }
- else if (isAnyBluebirdPromise(obj)) {
- var ret = new Promise(INTERNAL);
- ret._setTrace(undefined);
- obj._then(
- ret._fulfillUnchecked,
- ret._rejectUncheckedCheckError,
- ret._progressUnchecked,
- ret,
- null
- );
- ret._setFollowing();
- return ret;
- }
- var then = getThen(obj);
- if (then === errorObj) {
- if (traceParent !== undefined && canAttachTrace(then.e)) {
- traceParent._attachExtraTrace(then.e);
- }
- return Promise.reject(then.e);
- } else if (typeof then === "function") {
- return doThenable(obj, then, traceParent);
- }
- }
- return obj;
-}
-
-var hasProp = {}.hasOwnProperty;
-function isAnyBluebirdPromise(obj) {
- return hasProp.call(obj, "_promise0");
-}
-
-function doThenable(x, then, traceParent) {
- ASSERT(((typeof then) === "function"),
- "typeof then === \u0022function\u0022");
- ASSERT((arguments.length === 3),
- "arguments.length === 3");
- var resolver = Promise.defer();
- var called = false;
- try {
- then.call(
- x,
- resolveFromThenable,
- rejectFromThenable,
- progressFromThenable
- );
- } catch(e) {
- if (!called) {
- called = true;
- var trace = canAttachTrace(e) ? e : new Error(e + "");
- if (traceParent !== undefined) {
- traceParent._attachExtraTrace(trace);
- }
- resolver.promise._reject(e, trace);
- }
- }
- return resolver.promise;
-
- function resolveFromThenable(y) {
- if (called) return;
- called = true;
-
- if (x === y) {
- var e = Promise._makeSelfResolutionError();
- if (traceParent !== undefined) {
- traceParent._attachExtraTrace(e);
- }
- resolver.promise._reject(e, undefined);
- return;
- }
- resolver.resolve(y);
- }
-
- function rejectFromThenable(r) {
- if (called) return;
- called = true;
- var trace = canAttachTrace(r) ? r : new Error(r + "");
- if (traceParent !== undefined) {
- traceParent._attachExtraTrace(trace);
- }
- resolver.promise._reject(r, trace);
- }
-
- function progressFromThenable(v) {
- if (called) return;
- var promise = resolver.promise;
- if (typeof promise._progress === "function") {
- promise._progress(v);
- }
- }
-}
-
-return tryConvertToPromise;
-};
-
-},{"./assert.js":19,"./errors.js":28,"./util.js":53}],51:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var ASSERT = require("./assert.js");
-module.exports = function(Promise, INTERNAL, tryConvertToPromise) {
-var util = require("./util.js");
-var errors = require("./errors.js");
-var apiRejection = require("./errors_api_rejection")(Promise);
-var TimeoutError = Promise.TimeoutError;
-
-var afterTimeout = function (promise, parent, message) {
- if (!promise.isPending()) return;
- if (typeof message !== "string") {
- message = "operation timed out";
- }
- var err = new TimeoutError(message);
- errors.markAsOriginatingFromRejection(err);
- promise._attachExtraTrace(err);
- promise._cancel(err);
-};
-
-var afterDelay = function (value, promise) {
- promise._fulfill(value);
-};
-
-var delay = Promise.delay = function (value, ms) {
- if (ms === undefined) {
- ms = value;
- value = undefined;
- }
- ms = +ms;
- var maybePromise = tryConvertToPromise(value, undefined);
- var promise = new Promise(INTERNAL);
-
- if (maybePromise instanceof Promise) {
- promise._propagateFrom(maybePromise, 7);
- promise._follow(maybePromise);
- return promise.then(function(value) {
- return Promise.delay(value, ms);
- });
- } else {
- promise._setTrace(undefined);
- setTimeout(function delayTimeout() {
- afterDelay(value, promise);
- }, ms);
- }
- return promise;
-};
-
-Promise.prototype.delay = function (ms) {
- return delay(this, ms);
-};
-
-function successClear(value) {
- var handle = this;
- if (handle instanceof Number) handle = +handle;
- clearTimeout(handle);
- return value;
-}
-
-function failureClear(reason) {
- var handle = this;
- if (handle instanceof Number) handle = +handle;
- clearTimeout(handle);
- throw reason;
-}
-
-Promise.prototype.timeout = function (ms, message) {
- ms = +ms;
- var ret = new Promise(INTERNAL).cancellable();
- ret._propagateFrom(this, 7);
- ret._follow(this);
- var handle = setTimeout(function timeoutTimeout() {
- afterTimeout(ret, this, message);
- }, ms);
- return ret._then(successClear, failureClear, undefined, handle, undefined);
-};
-
-};
-
-},{"./assert.js":19,"./errors.js":28,"./errors_api_rejection":29,"./util.js":53}],52:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-module.exports = function (Promise, apiRejection, tryConvertToPromise) {
- var TypeError = require("./errors.js").TypeError;
- var inherits = require("./util.js").inherits;
- var PromiseInspection = Promise.PromiseInspection;
-
- function inspectionMapper(inspections) {
- var len = inspections.length;
- for (var i = 0; i < len; ++i) {
- var inspection = inspections[i];
- if (inspection.isRejected()) {
- return Promise.reject(inspection.error());
- }
- inspections[i] = inspection._settledValue;
- }
- return inspections;
- }
-
- function thrower(e) {
- setTimeout(function(){throw e;}, 0);
- }
-
- function castPreservingDisposable(thenable) {
- var maybePromise = tryConvertToPromise(thenable, undefined);
- if (maybePromise !== thenable &&
- typeof thenable._isDisposable === "function" &&
- typeof thenable._getDisposer === "function" &&
- thenable._isDisposable()) {
- maybePromise._setDisposable(thenable._getDisposer());
- }
- return maybePromise;
- }
- function dispose(resources, inspection) {
- var i = 0;
- var len = resources.length;
- var ret = Promise.defer();
- function iterator() {
- if (i >= len) return ret.resolve();
- var maybePromise = castPreservingDisposable(resources[i++]);
- if (maybePromise instanceof Promise &&
- maybePromise._isDisposable()) {
- try {
- maybePromise = tryConvertToPromise(
- maybePromise._getDisposer().tryDispose(inspection),
- undefined);
- } catch (e) {
- return thrower(e);
- }
- if (maybePromise instanceof Promise) {
- return maybePromise._then(iterator, thrower,
- null, null, null);
- }
- }
- iterator();
- }
- iterator();
- return ret.promise;
- }
-
- function disposerSuccess(value) {
- var inspection = new PromiseInspection();
- inspection._settledValue = value;
- inspection._bitField = 268435456;
- return dispose(this, inspection).thenReturn(value);
- }
-
- function disposerFail(reason) {
- var inspection = new PromiseInspection();
- inspection._settledValue = reason;
- inspection._bitField = 134217728;
- return dispose(this, inspection).thenThrow(reason);
- }
-
- function Disposer(data, promise) {
- this._data = data;
- this._promise = promise;
- }
-
- Disposer.prototype.data = function () {
- return this._data;
- };
-
- Disposer.prototype.promise = function () {
- return this._promise;
- };
-
- Disposer.prototype.resource = function () {
- if (this.promise().isFulfilled()) {
- return this.promise()._settledValue;
- }
- return null;
- };
-
- Disposer.prototype.tryDispose = function(inspection) {
- var resource = this.resource();
- var ret = resource !== null
- ? this.doDispose(resource, inspection) : null;
- this._promise._unsetDisposable();
- this._data = this._promise = null;
- return ret;
- };
-
- Disposer.isDisposer = function (d) {
- return (d != null &&
- typeof d.resource === "function" &&
- typeof d.tryDispose === "function");
- };
-
- function FunctionDisposer(fn, promise) {
- this.constructor$(fn, promise);
- }
- inherits(FunctionDisposer, Disposer);
-
- FunctionDisposer.prototype.doDispose = function (resource, inspection) {
- var fn = this.data();
- return fn.call(resource, resource, inspection);
- };
-
- Promise.using = function () {
- var len = arguments.length;
- if (len < 2) return apiRejection(
- "you must pass at least 2 arguments to Promise.using");
- var fn = arguments[len - 1];
- if (typeof fn !== "function") return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
- len--;
- var resources = new Array(len);
- for (var i = 0; i < len; ++i) {
- var resource = arguments[i];
- if (Disposer.isDisposer(resource)) {
- var disposer = resource;
- resource = resource.promise();
- resource._setDisposable(disposer);
- }
- resources[i] = resource;
- }
-
- return Promise.settle(resources)
- .then(inspectionMapper)
- .spread(fn)
- ._then(
- disposerSuccess, disposerFail, undefined, resources, undefined);
- };
-
- Promise.prototype._setDisposable = function (disposer) {
- this._bitField = this._bitField | 262144;
- this._disposer = disposer;
- };
-
- Promise.prototype._isDisposable = function () {
- return (this._bitField & 262144) > 0;
- };
-
- Promise.prototype._getDisposer = function () {
- return this._disposer;
- };
-
- Promise.prototype._unsetDisposable = function () {
- this._bitField = this._bitField & (~262144);
- this._disposer = undefined;
- };
-
- Promise.prototype.disposer = function (fn) {
- if (typeof fn === "function") {
- return new FunctionDisposer(fn, this);
- }
- throw new TypeError();
- };
-
-};
-
-},{"./errors.js":28,"./util.js":53}],53:[function(require,module,exports){
-/**
- * The MIT License (MIT)
- *
- * Copyright (c) 2014 Petka Antonov
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-"use strict";
-var ASSERT = require("./assert.js");
-var es5 = require("./es5.js");
-var haveGetters = (function(){
- try {
- var o = {};
- es5.defineProperty(o, "f", {
- get: function () {
- return 3;
- }
- });
- return o.f === 3;
- }
- catch (e) {
- return false;
- }
-
-})();
-var canEvaluate = typeof navigator == "undefined";
-var errorObj = {e: {}};
-function tryCatch1(fn, receiver, arg) {
- try { return fn.call(receiver, arg); }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
-}
-
-function tryCatch2(fn, receiver, arg, arg2) {
- try { return fn.call(receiver, arg, arg2); }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
-}
-
-function tryCatch3(fn, receiver, arg, arg2, arg3) {
- try { return fn.call(receiver, arg, arg2, arg3); }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
-}
-
-function tryCatch4(fn, receiver, arg, arg2, arg3, arg4) {
- try { return fn.call(receiver, arg, arg2, arg3, arg4); }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
-}
-
-function tryCatchApply(fn, args, receiver) {
- try { return fn.apply(receiver, args); }
- catch (e) {
- errorObj.e = e;
- return errorObj;
- }
-}
-
-var inherits = function(Child, Parent) {
- var hasProp = {}.hasOwnProperty;
-
- function T() {
- this.constructor = Child;
- this.constructor$ = Parent;
- for (var propertyName in Parent.prototype) {
- if (hasProp.call(Parent.prototype, propertyName) &&
- propertyName.charAt(propertyName.length-1) !== "$"
- ) {
- this[propertyName + "$"] = Parent.prototype[propertyName];
- }
- }
- }
- T.prototype = Parent.prototype;
- Child.prototype = new T();
- return Child.prototype;
-};
-
-function asString(val) {
- return typeof val === "string" ? val : ("" + val);
-}
-
-function isPrimitive(val) {
- return val == null || val === true || val === false ||
- typeof val === "string" || typeof val === "number";
-
-}
-
-function isObject(value) {
- return !isPrimitive(value);
-}
-
-function maybeWrapAsError(maybeError) {
- if (!isPrimitive(maybeError)) return maybeError;
-
- return new Error(asString(maybeError));
-}
-
-function withAppended(target, appendee) {
- var len = target.length;
- var ret = new Array(len + 1);
- var i;
- for (i = 0; i < len; ++i) {
- ret[i] = target[i];
- }
- ret[i] = appendee;
- return ret;
-}
-
-function getDataPropertyOrDefault(obj, key, defaultValue) {
- if (es5.isES5) {
- var desc = Object.getOwnPropertyDescriptor(obj, key);
- if (desc != null) {
- return desc.get == null && desc.set == null
- ? desc.value
- : defaultValue;
- }
- } else {
- return {}.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
- }
-}
-
-function notEnumerableProp(obj, name, value) {
- if (isPrimitive(obj)) return obj;
- var descriptor = {
- value: value,
- configurable: true,
- enumerable: false,
- writable: true
- };
- es5.defineProperty(obj, name, descriptor);
- return obj;
-}
-
-
-var wrapsPrimitiveReceiver = (function() {
- return this !== "string";
-}).call("string");
-
-function thrower(r) {
- throw r;
-}
-
-var inheritedDataKeys = (function() {
- if (es5.isES5) {
- return function(obj, opts) {
- var ret = [];
- var visitedKeys = Object.create(null);
- var getKeys = Object(opts).includeHidden
- ? Object.getOwnPropertyNames
- : Object.keys;
- while (obj != null) {
- var keys;
- try {
- keys = getKeys(obj);
- } catch (e) {
- return ret;
- }
- for (var i = 0; i < keys.length; ++i) {
- var key = keys[i];
- if (visitedKeys[key]) continue;
- visitedKeys[key] = true;
- var desc = Object.getOwnPropertyDescriptor(obj, key);
- if (desc != null && desc.get == null && desc.set == null) {
- ret.push(key);
- }
- }
- obj = es5.getPrototypeOf(obj);
- }
- return ret;
- };
- } else {
- return function(obj) {
- var ret = [];
- /*jshint forin:false */
- for (var key in obj) {
- ret.push(key);
- }
- return ret;
- };
- }
-
-})();
-
-function isClass(fn) {
- try {
- if (typeof fn === "function") {
- var keys = es5.keys(fn.prototype);
- return keys.length > 0 &&
- !(keys.length === 1 && keys[0] === "constructor");
- }
- return false;
- } catch (e) {
- return false;
- }
-}
-
-function toFastProperties(obj) {
- /*jshint -W027*/
- function f() {}
- f.prototype = obj;
- ASSERT("%HasFastProperties", true, obj);
- return f;
- eval(obj);
-}
-
-var rident = /^[a-z$_][a-z$_0-9]*$/i;
-function isIdentifier(str) {
- return rident.test(str);
-}
-
-function filledRange(count, prefix, suffix) {
- var ret = new Array(count);
- for(var i = 0; i < count; ++i) {
- ret[i] = prefix + i + suffix;
- }
- return ret;
-}
-
-var ret = {
- isClass: isClass,
- isIdentifier: isIdentifier,
- inheritedDataKeys: inheritedDataKeys,
- getDataPropertyOrDefault: getDataPropertyOrDefault,
- thrower: thrower,
- isArray: es5.isArray,
- haveGetters: haveGetters,
- notEnumerableProp: notEnumerableProp,
- isPrimitive: isPrimitive,
- isObject: isObject,
- canEvaluate: canEvaluate,
- errorObj: errorObj,
- tryCatch1: tryCatch1,
- tryCatch2: tryCatch2,
- tryCatch3: tryCatch3,
- tryCatch4: tryCatch4,
- tryCatchApply: tryCatchApply,
- inherits: inherits,
- withAppended: withAppended,
- asString: asString,
- maybeWrapAsError: maybeWrapAsError,
- wrapsPrimitiveReceiver: wrapsPrimitiveReceiver,
- toFastProperties: toFastProperties,
- filledRange: filledRange,
- lastLineError: new Error()
-};
-
-module.exports = ret;
-
-},{"./assert.js":19,"./es5.js":30}],54:[function(require,module,exports){
-var process=require("__browserify_process");// vim:ts=4:sts=4:sw=4:
-/*!
- *
- * Copyright 2009-2012 Kris Kowal under the terms of the MIT
- * license found at http://github.com/kriskowal/q/raw/master/LICENSE
- *
- * With parts by Tyler Close
- * Copyright 2007-2009 Tyler Close under the terms of the MIT X license found
- * at http://www.opensource.org/licenses/mit-license.html
- * Forked at ref_send.js version: 2009-05-11
- *
- * With parts by Mark Miller
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-(function (definition) {
- // Turn off strict mode for this function so we can assign to global.Q
- /* jshint strict: false */
-
- // This file will function properly as a
-
-
+
+
-
-