aboutsummaryrefslogtreecommitdiff
path: root/node_modules/process
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-03 15:35:00 +0200
commitde98e0b232509d5f40c135d540a70e415272ff85 (patch)
treea79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/process
parente0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff)
node_modules
Diffstat (limited to 'node_modules/process')
-rw-r--r--node_modules/process/.eslintrc21
-rw-r--r--node_modules/process/LICENSE22
-rw-r--r--node_modules/process/README.md26
-rw-r--r--node_modules/process/browser.js180
-rw-r--r--node_modules/process/index.js2
-rw-r--r--node_modules/process/package.json27
-rw-r--r--node_modules/process/test.js199
7 files changed, 477 insertions, 0 deletions
diff --git a/node_modules/process/.eslintrc b/node_modules/process/.eslintrc
new file mode 100644
index 000000000..1e7aab73e
--- /dev/null
+++ b/node_modules/process/.eslintrc
@@ -0,0 +1,21 @@
+{
+extends: "eslint:recommended",
+ "env": {
+ "node": true,
+ "browser": true,
+ "es6" : true,
+ "mocha": true
+ },
+ "rules": {
+ "indent": [2, 4],
+ "brace-style": [2, "1tbs"],
+ "quotes": [2, "single"],
+ "no-console": 0,
+ "no-shadow": 0,
+ "no-use-before-define": [2, "nofunc"],
+ "no-underscore-dangle": 0,
+ "no-constant-condition": 0,
+ "space-after-function-name": 0,
+ "consistent-return": 0
+ }
+}
diff --git a/node_modules/process/LICENSE b/node_modules/process/LICENSE
new file mode 100644
index 000000000..b8c1246cf
--- /dev/null
+++ b/node_modules/process/LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2013 Roman Shtylman <shtylman@gmail.com>
+
+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.
diff --git a/node_modules/process/README.md b/node_modules/process/README.md
new file mode 100644
index 000000000..6570729b2
--- /dev/null
+++ b/node_modules/process/README.md
@@ -0,0 +1,26 @@
+# process
+
+```require('process');``` just like any other module.
+
+Works in node.js and browsers via the browser.js shim provided with the module.
+
+## browser implementation
+
+The goal of this module is not to be a full-fledged alternative to the builtin process module. This module mostly exists to provide the nextTick functionality and little more. We keep this module lean because it will often be included by default by tools like browserify when it detects a module has used the `process` global.
+
+It also exposes a "browser" member (i.e. `process.browser`) which is `true` in this implementation but `undefined` in node. This can be used in isomorphic code that adjusts it's behavior depending on which environment it's running in.
+
+If you are looking to provide other process methods, I suggest you monkey patch them onto the process global in your app. A list of user created patches is below.
+
+* [hrtime](https://github.com/kumavis/browser-process-hrtime)
+* [stdout](https://github.com/kumavis/browser-stdout)
+
+## package manager notes
+
+If you are writing a bundler to package modules for client side use, make sure you use the ```browser``` field hint in package.json.
+
+See https://gist.github.com/4339901 for details.
+
+The [browserify](https://github.com/substack/node-browserify) module will properly handle this field when bundling your files.
+
+
diff --git a/node_modules/process/browser.js b/node_modules/process/browser.js
new file mode 100644
index 000000000..d3e30e9b3
--- /dev/null
+++ b/node_modules/process/browser.js
@@ -0,0 +1,180 @@
+// shim for using process in browser
+var process = module.exports = {};
+
+// cached from whatever global is present so that test runners that stub it
+// don't break things. But we need to wrap it in a try catch in case it is
+// wrapped in strict mode code which doesn't define any globals. It's inside a
+// function because try/catches deoptimize in certain engines.
+
+var cachedSetTimeout;
+var cachedClearTimeout;
+
+function defaultSetTimout() {
+ throw new Error('setTimeout has not been defined');
+}
+function defaultClearTimeout () {
+ throw new Error('clearTimeout has not been defined');
+}
+(function () {
+ try {
+ if (typeof setTimeout === 'function') {
+ cachedSetTimeout = setTimeout;
+ } else {
+ cachedSetTimeout = defaultSetTimout;
+ }
+ } catch (e) {
+ cachedSetTimeout = defaultSetTimout;
+ }
+ try {
+ if (typeof clearTimeout === 'function') {
+ cachedClearTimeout = clearTimeout;
+ } else {
+ cachedClearTimeout = defaultClearTimeout;
+ }
+ } catch (e) {
+ cachedClearTimeout = defaultClearTimeout;
+ }
+} ())
+function runTimeout(fun) {
+ if (cachedSetTimeout === setTimeout) {
+ //normal enviroments in sane situations
+ return setTimeout(fun, 0);
+ }
+ // if setTimeout wasn't available but was latter defined
+ if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
+ cachedSetTimeout = setTimeout;
+ return setTimeout(fun, 0);
+ }
+ try {
+ // when when somebody has screwed with setTimeout but no I.E. maddness
+ return cachedSetTimeout(fun, 0);
+ } catch(e){
+ try {
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
+ return cachedSetTimeout.call(null, fun, 0);
+ } catch(e){
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
+ return cachedSetTimeout.call(this, fun, 0);
+ }
+ }
+
+
+}
+function runClearTimeout(marker) {
+ if (cachedClearTimeout === clearTimeout) {
+ //normal enviroments in sane situations
+ return clearTimeout(marker);
+ }
+ // if clearTimeout wasn't available but was latter defined
+ if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
+ cachedClearTimeout = clearTimeout;
+ return clearTimeout(marker);
+ }
+ try {
+ // when when somebody has screwed with setTimeout but no I.E. maddness
+ return cachedClearTimeout(marker);
+ } catch (e){
+ try {
+ // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
+ return cachedClearTimeout.call(null, marker);
+ } catch (e){
+ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
+ // Some versions of I.E. have different rules for clearTimeout vs setTimeout
+ return cachedClearTimeout.call(this, marker);
+ }
+ }
+
+
+
+}
+var queue = [];
+var draining = false;
+var currentQueue;
+var queueIndex = -1;
+
+function cleanUpNextTick() {
+ if (!draining || !currentQueue) {
+ return;
+ }
+ draining = false;
+ if (currentQueue.length) {
+ queue = currentQueue.concat(queue);
+ } else {
+ queueIndex = -1;
+ }
+ if (queue.length) {
+ drainQueue();
+ }
+}
+
+function drainQueue() {
+ if (draining) {
+ return;
+ }
+ var timeout = runTimeout(cleanUpNextTick);
+ draining = true;
+
+ var len = queue.length;
+ while(len) {
+ currentQueue = queue;
+ queue = [];
+ while (++queueIndex < len) {
+ if (currentQueue) {
+ currentQueue[queueIndex].run();
+ }
+ }
+ queueIndex = -1;
+ len = queue.length;
+ }
+ currentQueue = null;
+ draining = false;
+ runClearTimeout(timeout);
+}
+
+process.nextTick = function (fun) {
+ var args = new Array(arguments.length - 1);
+ if (arguments.length > 1) {
+ for (var i = 1; i < arguments.length; i++) {
+ args[i - 1] = arguments[i];
+ }
+ }
+ queue.push(new Item(fun, args));
+ if (queue.length === 1 && !draining) {
+ runTimeout(drainQueue);
+ }
+};
+
+// v8 likes predictible objects
+function Item(fun, array) {
+ this.fun = fun;
+ this.array = array;
+}
+Item.prototype.run = function () {
+ this.fun.apply(null, this.array);
+};
+process.title = 'browser';
+process.browser = true;
+process.env = {};
+process.argv = [];
+process.version = ''; // empty string to avoid regexp issues
+process.versions = {};
+
+function noop() {}
+
+process.on = noop;
+process.addListener = noop;
+process.once = noop;
+process.off = noop;
+process.removeListener = noop;
+process.removeAllListeners = noop;
+process.emit = noop;
+
+process.binding = function (name) {
+ throw new Error('process.binding is not supported');
+};
+
+process.cwd = function () { return '/' };
+process.chdir = function (dir) {
+ throw new Error('process.chdir is not supported');
+};
+process.umask = function() { return 0; };
diff --git a/node_modules/process/index.js b/node_modules/process/index.js
new file mode 100644
index 000000000..8d8ed7df4
--- /dev/null
+++ b/node_modules/process/index.js
@@ -0,0 +1,2 @@
+// for now just expose the builtin process global from node.js
+module.exports = global.process;
diff --git a/node_modules/process/package.json b/node_modules/process/package.json
new file mode 100644
index 000000000..907a3b912
--- /dev/null
+++ b/node_modules/process/package.json
@@ -0,0 +1,27 @@
+{
+ "author": "Roman Shtylman <shtylman@gmail.com>",
+ "name": "process",
+ "description": "process information for node.js and browsers",
+ "keywords": [
+ "process"
+ ],
+ "scripts": {
+ "test": "mocha test.js",
+ "browser": "zuul --no-coverage --ui mocha-bdd --local 8080 -- test.js"
+ },
+ "version": "0.11.9",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/shtylman/node-process.git"
+ },
+ "license": "MIT",
+ "browser": "./browser.js",
+ "main": "./index.js",
+ "engines": {
+ "node": ">= 0.6.0"
+ },
+ "devDependencies": {
+ "mocha": "2.2.1",
+ "zuul": "^3.10.3"
+ }
+}
diff --git a/node_modules/process/test.js b/node_modules/process/test.js
new file mode 100644
index 000000000..8ba579c0a
--- /dev/null
+++ b/node_modules/process/test.js
@@ -0,0 +1,199 @@
+var assert = require('assert');
+var ourProcess = require('./browser');
+describe('test against our process', function () {
+ test(ourProcess);
+});
+if (!process.browser) {
+ describe('test against node', function () {
+ test(process);
+ });
+ vmtest();
+}
+function test (ourProcess) {
+ describe('test arguments', function () {
+ it ('works', function (done) {
+ var order = 0;
+
+
+ ourProcess.nextTick(function (num) {
+ assert.equal(num, order++, 'first one works');
+ ourProcess.nextTick(function (num) {
+ assert.equal(num, order++, 'recursive one is 4th');
+ }, 3);
+ }, 0);
+ ourProcess.nextTick(function (num) {
+ assert.equal(num, order++, 'second one starts');
+ ourProcess.nextTick(function (num) {
+ assert.equal(num, order++, 'this is third');
+ ourProcess.nextTick(function (num) {
+ assert.equal(num, order++, 'this is last');
+ done();
+ }, 5);
+ }, 4);
+ }, 1);
+ ourProcess.nextTick(function (num) {
+
+ assert.equal(num, order++, '3rd schedualed happens after the error');
+ }, 2);
+ });
+ });
+if (!process.browser) {
+ describe('test errors', function (t) {
+ it ('works', function (done) {
+ var order = 0;
+ process.removeAllListeners('uncaughtException');
+ process.once('uncaughtException', function(err) {
+ assert.equal(2, order++, 'error is third');
+ ourProcess.nextTick(function () {
+ assert.equal(5, order++, 'schedualed in error is last');
+ done();
+ });
+ });
+ ourProcess.nextTick(function () {
+ assert.equal(0, order++, 'first one works');
+ ourProcess.nextTick(function () {
+ assert.equal(4, order++, 'recursive one is 4th');
+ });
+ });
+ ourProcess.nextTick(function () {
+ assert.equal(1, order++, 'second one starts');
+ throw(new Error('an error is thrown'));
+ });
+ ourProcess.nextTick(function () {
+ assert.equal(3, order++, '3rd schedualed happens after the error');
+ });
+ });
+ });
+}
+ describe('rename globals', function (t) {
+ var oldTimeout = setTimeout;
+ var oldClear = clearTimeout;
+
+ it('clearTimeout', function (done){
+
+ var ok = true;
+ clearTimeout = function () {
+ ok = false;
+ }
+ var ran = false;
+ function cleanup() {
+ clearTimeout = oldClear;
+ var err;
+ try {
+ assert.ok(ok, 'fake clearTimeout ran');
+ assert.ok(ran, 'should have run');
+ } catch (e) {
+ err = e;
+ }
+ done(err);
+ }
+ setTimeout(cleanup, 1000);
+ ourProcess.nextTick(function () {
+ ran = true;
+ });
+ });
+ it('just setTimeout', function (done){
+
+
+ setTimeout = function () {
+ setTimeout = oldTimeout;
+ try {
+ assert.ok(false, 'fake setTimeout called')
+ } catch (e) {
+ done(e);
+ }
+
+ }
+
+ ourProcess.nextTick(function () {
+ setTimeout = oldTimeout;
+ done();
+ });
+ });
+ });
+}
+function vmtest() {
+ var vm = require('vm');
+ var fs = require('fs');
+ var process = fs.readFileSync('./browser.js', {encoding: 'utf8'});
+
+
+ describe('should work in vm in strict mode with no globals', function () {
+ it('should parse', function (done) {
+ var str = '"use strict";var module = {exports:{}};';
+ str += process;
+ str += 'this.works = process.browser;';
+ var script = new vm.Script(str);
+ var context = {
+ works: false
+ };
+ script.runInNewContext(context);
+ assert.ok(context.works);
+ done();
+ });
+ it('setTimeout throws error', function (done) {
+ var str = '"use strict";var module = {exports:{}};';
+ str += process;
+ str += 'try {process.nextTick(function () {})} catch (e){this.works = e;}';
+ var script = new vm.Script(str);
+ var context = {
+ works: false
+ };
+ script.runInNewContext(context);
+ assert.ok(context.works);
+ done();
+ });
+ it('should generally work', function (done) {
+ var str = '"use strict";var module = {exports:{}};';
+ str += process;
+ str += 'process.nextTick(function () {assert.ok(true);done();})';
+ var script = new vm.Script(str);
+ var context = {
+ clearTimeout: clearTimeout,
+ setTimeout: setTimeout,
+ done: done,
+ assert: assert
+ };
+ script.runInNewContext(context);
+ });
+ it('late defs setTimeout', function (done) {
+ var str = '"use strict";var module = {exports:{}};';
+ str += process;
+ str += 'var setTimeout = hiddenSetTimeout;process.nextTick(function () {assert.ok(true);done();})';
+ var script = new vm.Script(str);
+ var context = {
+ clearTimeout: clearTimeout,
+ hiddenSetTimeout: setTimeout,
+ done: done,
+ assert: assert
+ };
+ script.runInNewContext(context);
+ });
+ it('late defs clearTimeout', function (done) {
+ var str = '"use strict";var module = {exports:{}};';
+ str += process;
+ str += 'var clearTimeout = hiddenClearTimeout;process.nextTick(function () {assert.ok(true);done();})';
+ var script = new vm.Script(str);
+ var context = {
+ hiddenClearTimeout: clearTimeout,
+ setTimeout: setTimeout,
+ done: done,
+ assert: assert
+ };
+ script.runInNewContext(context);
+ });
+ it('late defs setTimeout and then redefine', function (done) {
+ var str = '"use strict";var module = {exports:{}};';
+ str += process;
+ str += 'var setTimeout = hiddenSetTimeout;process.nextTick(function () {setTimeout = function (){throw new Error("foo")};hiddenSetTimeout(function(){process.nextTick(function (){assert.ok(true);done();});});});';
+ var script = new vm.Script(str);
+ var context = {
+ clearTimeout: clearTimeout,
+ hiddenSetTimeout: setTimeout,
+ done: done,
+ assert: assert
+ };
+ script.runInNewContext(context);
+ });
+ });
+}