macgyver 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Growl +0 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Growl +0 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Headers/Growl.h +5 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Headers/GrowlApplicationBridge.h +551 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Headers/GrowlDefines.h +341 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Resources/Info.plist +40 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/_CodeSignature/CodeResources +34 -0
- data/assets/MacGap.app/Contents/Info.plist +48 -0
- data/assets/MacGap.app/Contents/MacOS/MacGap +0 -0
- data/assets/MacGap.app/Contents/PkgInfo +1 -0
- data/assets/MacGap.app/Contents/Resources/_debugger.js +1718 -0
- data/assets/MacGap.app/Contents/Resources/_http_agent.js +310 -0
- data/assets/MacGap.app/Contents/Resources/_http_client.js +533 -0
- data/assets/MacGap.app/Contents/Resources/_http_common.js +222 -0
- data/assets/MacGap.app/Contents/Resources/_http_incoming.js +194 -0
- data/assets/MacGap.app/Contents/Resources/_http_outgoing.js +597 -0
- data/assets/MacGap.app/Contents/Resources/_http_server.js +510 -0
- data/assets/MacGap.app/Contents/Resources/_linklist.js +76 -0
- data/assets/MacGap.app/Contents/Resources/_stream_duplex.js +69 -0
- data/assets/MacGap.app/Contents/Resources/_stream_passthrough.js +41 -0
- data/assets/MacGap.app/Contents/Resources/_stream_readable.js +900 -0
- data/assets/MacGap.app/Contents/Resources/_stream_transform.js +204 -0
- data/assets/MacGap.app/Contents/Resources/_stream_writable.js +456 -0
- data/assets/MacGap.app/Contents/Resources/_tls_legacy.js +887 -0
- data/assets/MacGap.app/Contents/Resources/_tls_wrap.js +831 -0
- data/assets/MacGap.app/Contents/Resources/application.icns +0 -0
- data/assets/MacGap.app/Contents/Resources/assert.js +326 -0
- data/assets/MacGap.app/Contents/Resources/buffer.js +724 -0
- data/assets/MacGap.app/Contents/Resources/child_process.js +1107 -0
- data/assets/MacGap.app/Contents/Resources/cluster.js +613 -0
- data/assets/MacGap.app/Contents/Resources/console.js +108 -0
- data/assets/MacGap.app/Contents/Resources/constants.js +22 -0
- data/assets/MacGap.app/Contents/Resources/crypto.js +691 -0
- data/assets/MacGap.app/Contents/Resources/dgram.js +459 -0
- data/assets/MacGap.app/Contents/Resources/dns.js +274 -0
- data/assets/MacGap.app/Contents/Resources/domain.js +292 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/Credits.rtf +29 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/InfoPlist.strings +0 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/MainMenu.nib +0 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/Window.nib +0 -0
- data/assets/MacGap.app/Contents/Resources/events.js +312 -0
- data/assets/MacGap.app/Contents/Resources/freelist.js +43 -0
- data/assets/MacGap.app/Contents/Resources/fs.js +1732 -0
- data/assets/MacGap.app/Contents/Resources/http.js +119 -0
- data/assets/MacGap.app/Contents/Resources/https.js +134 -0
- data/assets/MacGap.app/Contents/Resources/module.js +529 -0
- data/assets/MacGap.app/Contents/Resources/net.js +1378 -0
- data/assets/MacGap.app/Contents/Resources/nodelike.js +195 -0
- data/assets/MacGap.app/Contents/Resources/os.js +64 -0
- data/assets/MacGap.app/Contents/Resources/path.js +517 -0
- data/assets/MacGap.app/Contents/Resources/public/index.html +38 -0
- data/assets/MacGap.app/Contents/Resources/punycode.js +507 -0
- data/assets/MacGap.app/Contents/Resources/querystring.js +206 -0
- data/assets/MacGap.app/Contents/Resources/readline.js +1311 -0
- data/assets/MacGap.app/Contents/Resources/repl.js +945 -0
- data/assets/MacGap.app/Contents/Resources/smalloc.js +90 -0
- data/assets/MacGap.app/Contents/Resources/stream.js +127 -0
- data/assets/MacGap.app/Contents/Resources/string_decoder.js +189 -0
- data/assets/MacGap.app/Contents/Resources/sys.js +24 -0
- data/assets/MacGap.app/Contents/Resources/timers.js +568 -0
- data/assets/MacGap.app/Contents/Resources/tls.js +220 -0
- data/assets/MacGap.app/Contents/Resources/tty.js +129 -0
- data/assets/MacGap.app/Contents/Resources/url.js +693 -0
- data/assets/MacGap.app/Contents/Resources/util.js +688 -0
- data/assets/MacGap.app/Contents/Resources/vm.js +73 -0
- data/assets/MacGap.app/Contents/Resources/zlib.js +524 -0
- data/assets/index.html +38 -0
- data/bin/macgyver +104 -0
- data/macgyver.gemspec +19 -0
- data/test/public/index.html +27 -0
- metadata +121 -0
@@ -0,0 +1,274 @@
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
// copy of this software and associated documentation files (the
|
5
|
+
// 'Software'), to deal in the Software without restriction, including
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
9
|
+
// following conditions:
|
10
|
+
//
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
12
|
+
// in all copies or substantial portions of the Software.
|
13
|
+
//
|
14
|
+
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
var net = require('net');
|
23
|
+
var util = require('util');
|
24
|
+
|
25
|
+
var cares = process.binding('cares_wrap');
|
26
|
+
var uv = process.binding('uv');
|
27
|
+
|
28
|
+
var isIp = net.isIP;
|
29
|
+
|
30
|
+
|
31
|
+
function errnoException(err, syscall, hostname) {
|
32
|
+
// FIXME(bnoordhuis) Remove this backwards compatibility shite and pass
|
33
|
+
// the true error to the user. ENOTFOUND is not even a proper POSIX error!
|
34
|
+
if (err === uv.UV_EAI_MEMORY ||
|
35
|
+
err === uv.UV_EAI_NODATA ||
|
36
|
+
err === uv.UV_EAI_NONAME) {
|
37
|
+
err = 'ENOTFOUND';
|
38
|
+
}
|
39
|
+
var ex = null;
|
40
|
+
if (typeof err === 'string') { // c-ares error code.
|
41
|
+
ex = new Error(syscall + ' ' + err);
|
42
|
+
ex.code = err;
|
43
|
+
ex.errno = err;
|
44
|
+
ex.syscall = syscall;
|
45
|
+
} else {
|
46
|
+
ex = util._errnoException(err, syscall);
|
47
|
+
}
|
48
|
+
if (hostname) {
|
49
|
+
ex.hostname = hostname;
|
50
|
+
}
|
51
|
+
return ex;
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
// c-ares invokes a callback either synchronously or asynchronously,
|
56
|
+
// but the dns API should always invoke a callback asynchronously.
|
57
|
+
//
|
58
|
+
// This function makes sure that the callback is invoked asynchronously.
|
59
|
+
// It returns a function that invokes the callback within nextTick().
|
60
|
+
//
|
61
|
+
// To avoid invoking unnecessary nextTick(), `immediately` property of
|
62
|
+
// returned function should be set to true after c-ares returned.
|
63
|
+
//
|
64
|
+
// Usage:
|
65
|
+
//
|
66
|
+
// function someAPI(callback) {
|
67
|
+
// callback = makeAsync(callback);
|
68
|
+
// channel.someAPI(..., callback);
|
69
|
+
// callback.immediately = true;
|
70
|
+
// }
|
71
|
+
function makeAsync(callback) {
|
72
|
+
if (!util.isFunction(callback)) {
|
73
|
+
return callback;
|
74
|
+
}
|
75
|
+
return function asyncCallback() {
|
76
|
+
if (asyncCallback.immediately) {
|
77
|
+
// The API already returned, we can invoke the callback immediately.
|
78
|
+
callback.apply(null, arguments);
|
79
|
+
} else {
|
80
|
+
var args = arguments;
|
81
|
+
process.nextTick(function() {
|
82
|
+
callback.apply(null, args);
|
83
|
+
});
|
84
|
+
}
|
85
|
+
};
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
function onlookup(err, addresses) {
|
90
|
+
if (err) {
|
91
|
+
return this.callback(errnoException(err, 'getaddrinfo', this.hostname));
|
92
|
+
}
|
93
|
+
if (this.family) {
|
94
|
+
this.callback(null, addresses[0], this.family);
|
95
|
+
} else {
|
96
|
+
this.callback(null, addresses[0], addresses[0].indexOf(':') >= 0 ? 6 : 4);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
// Easy DNS A/AAAA look up
|
102
|
+
// lookup(hostname, [family,] callback)
|
103
|
+
exports.lookup = function(hostname, family, callback) {
|
104
|
+
// parse arguments
|
105
|
+
if (arguments.length === 2) {
|
106
|
+
callback = family;
|
107
|
+
family = 0;
|
108
|
+
} else if (!family) {
|
109
|
+
family = 0;
|
110
|
+
} else {
|
111
|
+
family = +family;
|
112
|
+
if (family !== 4 && family !== 6) {
|
113
|
+
throw new Error('invalid argument: `family` must be 4 or 6');
|
114
|
+
}
|
115
|
+
}
|
116
|
+
callback = makeAsync(callback);
|
117
|
+
|
118
|
+
if (!hostname) {
|
119
|
+
callback(null, null, family === 6 ? 6 : 4);
|
120
|
+
return {};
|
121
|
+
}
|
122
|
+
|
123
|
+
var matchedFamily = net.isIP(hostname);
|
124
|
+
if (matchedFamily) {
|
125
|
+
callback(null, hostname, matchedFamily);
|
126
|
+
return {};
|
127
|
+
}
|
128
|
+
|
129
|
+
var req = {
|
130
|
+
callback: callback,
|
131
|
+
family: family,
|
132
|
+
hostname: hostname,
|
133
|
+
oncomplete: onlookup
|
134
|
+
};
|
135
|
+
var err = cares.getaddrinfo(req, hostname, family);
|
136
|
+
if (err) throw errnoException(err, 'getaddrinfo', hostname);
|
137
|
+
|
138
|
+
callback.immediately = true;
|
139
|
+
return req;
|
140
|
+
};
|
141
|
+
|
142
|
+
|
143
|
+
function onresolve(err, result) {
|
144
|
+
if (err)
|
145
|
+
this.callback(errnoException(err, this.bindingName, this.hostname));
|
146
|
+
else
|
147
|
+
this.callback(null, result);
|
148
|
+
}
|
149
|
+
|
150
|
+
|
151
|
+
function resolver(bindingName) {
|
152
|
+
var binding = cares[bindingName];
|
153
|
+
|
154
|
+
return function query(name, callback) {
|
155
|
+
callback = makeAsync(callback);
|
156
|
+
var req = {
|
157
|
+
bindingName: bindingName,
|
158
|
+
callback: callback,
|
159
|
+
hostname: name,
|
160
|
+
oncomplete: onresolve
|
161
|
+
};
|
162
|
+
var err = binding(req, name);
|
163
|
+
if (err) throw errnoException(err, bindingName);
|
164
|
+
callback.immediately = true;
|
165
|
+
return req;
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
var resolveMap = {};
|
171
|
+
exports.resolve4 = resolveMap.A = resolver('queryA');
|
172
|
+
exports.resolve6 = resolveMap.AAAA = resolver('queryAaaa');
|
173
|
+
exports.resolveCname = resolveMap.CNAME = resolver('queryCname');
|
174
|
+
exports.resolveMx = resolveMap.MX = resolver('queryMx');
|
175
|
+
exports.resolveNs = resolveMap.NS = resolver('queryNs');
|
176
|
+
exports.resolveTxt = resolveMap.TXT = resolver('queryTxt');
|
177
|
+
exports.resolveSrv = resolveMap.SRV = resolver('querySrv');
|
178
|
+
exports.resolveNaptr = resolveMap.NAPTR = resolver('queryNaptr');
|
179
|
+
exports.resolveSoa = resolveMap.SOA = resolver('querySoa');
|
180
|
+
exports.reverse = resolveMap.PTR = resolver('getHostByAddr');
|
181
|
+
|
182
|
+
|
183
|
+
exports.resolve = function(hostname, type_, callback_) {
|
184
|
+
var resolver, callback;
|
185
|
+
if (util.isString(type_)) {
|
186
|
+
resolver = resolveMap[type_];
|
187
|
+
callback = callback_;
|
188
|
+
} else {
|
189
|
+
resolver = exports.resolve4;
|
190
|
+
callback = type_;
|
191
|
+
}
|
192
|
+
|
193
|
+
if (util.isFunction(resolver)) {
|
194
|
+
return resolver(hostname, callback);
|
195
|
+
} else {
|
196
|
+
throw new Error('Unknown type "' + type_ + '"');
|
197
|
+
}
|
198
|
+
};
|
199
|
+
|
200
|
+
|
201
|
+
exports.getServers = function() {
|
202
|
+
return cares.getServers();
|
203
|
+
};
|
204
|
+
|
205
|
+
|
206
|
+
exports.setServers = function(servers) {
|
207
|
+
// cache the original servers because in the event of an error setting the
|
208
|
+
// servers cares won't have any servers available for resolution
|
209
|
+
var orig = cares.getServers();
|
210
|
+
|
211
|
+
var newSet = [];
|
212
|
+
|
213
|
+
servers.forEach(function(serv) {
|
214
|
+
var ver = isIp(serv);
|
215
|
+
|
216
|
+
if (ver)
|
217
|
+
return newSet.push([ver, serv]);
|
218
|
+
|
219
|
+
var match = serv.match(/\[(.*)\](:\d+)?/);
|
220
|
+
|
221
|
+
// we have an IPv6 in brackets
|
222
|
+
if (match) {
|
223
|
+
ver = isIp(match[1]);
|
224
|
+
if (ver)
|
225
|
+
return newSet.push([ver, match[1]]);
|
226
|
+
}
|
227
|
+
|
228
|
+
var s = serv.split(/:\d+$/)[0];
|
229
|
+
ver = isIp(s);
|
230
|
+
|
231
|
+
if (ver)
|
232
|
+
return newSet.push([ver, s]);
|
233
|
+
|
234
|
+
throw new Error('IP address is not properly formatted: ' + serv);
|
235
|
+
});
|
236
|
+
|
237
|
+
var r = cares.setServers(newSet);
|
238
|
+
|
239
|
+
if (r) {
|
240
|
+
// reset the servers to the old servers, because ares probably unset them
|
241
|
+
cares.setServers(orig.join(','));
|
242
|
+
|
243
|
+
var err = cares.strerror(r);
|
244
|
+
throw new Error('c-ares failed to set servers: "' + err +
|
245
|
+
'" [' + servers + ']');
|
246
|
+
}
|
247
|
+
};
|
248
|
+
|
249
|
+
|
250
|
+
// ERROR CODES
|
251
|
+
exports.NODATA = 'ENODATA';
|
252
|
+
exports.FORMERR = 'EFORMERR';
|
253
|
+
exports.SERVFAIL = 'ESERVFAIL';
|
254
|
+
exports.NOTFOUND = 'ENOTFOUND';
|
255
|
+
exports.NOTIMP = 'ENOTIMP';
|
256
|
+
exports.REFUSED = 'EREFUSED';
|
257
|
+
exports.BADQUERY = 'EBADQUERY';
|
258
|
+
exports.ADNAME = 'EADNAME';
|
259
|
+
exports.BADFAMILY = 'EBADFAMILY';
|
260
|
+
exports.BADRESP = 'EBADRESP';
|
261
|
+
exports.CONNREFUSED = 'ECONNREFUSED';
|
262
|
+
exports.TIMEOUT = 'ETIMEOUT';
|
263
|
+
exports.EOF = 'EOF';
|
264
|
+
exports.FILE = 'EFILE';
|
265
|
+
exports.NOMEM = 'ENOMEM';
|
266
|
+
exports.DESTRUCTION = 'EDESTRUCTION';
|
267
|
+
exports.BADSTR = 'EBADSTR';
|
268
|
+
exports.BADFLAGS = 'EBADFLAGS';
|
269
|
+
exports.NONAME = 'ENONAME';
|
270
|
+
exports.BADHINTS = 'EBADHINTS';
|
271
|
+
exports.NOTINITIALIZED = 'ENOTINITIALIZED';
|
272
|
+
exports.LOADIPHLPAPI = 'ELOADIPHLPAPI';
|
273
|
+
exports.ADDRGETNETWORKPARAMS = 'EADDRGETNETWORKPARAMS';
|
274
|
+
exports.CANCELLED = 'ECANCELLED';
|
@@ -0,0 +1,292 @@
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
// copy of this software and associated documentation files (the
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
9
|
+
// following conditions:
|
10
|
+
//
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
12
|
+
// in all copies or substantial portions of the Software.
|
13
|
+
//
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
var util = require('util');
|
23
|
+
var EventEmitter = require('events');
|
24
|
+
var inherits = util.inherits;
|
25
|
+
|
26
|
+
// communicate with events module, but don't require that
|
27
|
+
// module to have to load this one, since this module has
|
28
|
+
// a few side effects.
|
29
|
+
EventEmitter.usingDomains = true;
|
30
|
+
|
31
|
+
// overwrite process.domain with a getter/setter that will allow for more
|
32
|
+
// effective optimizations
|
33
|
+
var _domain = [null];
|
34
|
+
Object.defineProperty(process, 'domain', {
|
35
|
+
enumerable: true,
|
36
|
+
get: function() {
|
37
|
+
return _domain[0];
|
38
|
+
},
|
39
|
+
set: function(arg) {
|
40
|
+
return _domain[0] = arg;
|
41
|
+
}
|
42
|
+
});
|
43
|
+
|
44
|
+
// objects with external array data are excellent ways to communicate state
|
45
|
+
// between js and c++ w/o much overhead
|
46
|
+
var _domain_flag = {};
|
47
|
+
|
48
|
+
// let the process know we're using domains
|
49
|
+
process._setupDomainUse(_domain, _domain_flag);
|
50
|
+
|
51
|
+
exports.Domain = Domain;
|
52
|
+
|
53
|
+
exports.create = exports.createDomain = function() {
|
54
|
+
return new Domain();
|
55
|
+
};
|
56
|
+
|
57
|
+
// it's possible to enter one domain while already inside
|
58
|
+
// another one. the stack is each entered domain.
|
59
|
+
var stack = [];
|
60
|
+
exports._stack = stack;
|
61
|
+
// the active domain is always the one that we're currently in.
|
62
|
+
exports.active = null;
|
63
|
+
|
64
|
+
|
65
|
+
inherits(Domain, EventEmitter);
|
66
|
+
|
67
|
+
function Domain() {
|
68
|
+
EventEmitter.call(this);
|
69
|
+
|
70
|
+
this.members = [];
|
71
|
+
}
|
72
|
+
|
73
|
+
Domain.prototype.members = undefined;
|
74
|
+
Domain.prototype._disposed = undefined;
|
75
|
+
|
76
|
+
|
77
|
+
// Called by process._fatalException in case an error was thrown.
|
78
|
+
Domain.prototype._errorHandler = function errorHandler(er) {
|
79
|
+
var caught = false;
|
80
|
+
// ignore errors on disposed domains.
|
81
|
+
//
|
82
|
+
// XXX This is a bit stupid. We should probably get rid of
|
83
|
+
// domain.dispose() altogether. It's almost always a terrible
|
84
|
+
// idea. --isaacs
|
85
|
+
if (this._disposed)
|
86
|
+
return true;
|
87
|
+
|
88
|
+
er.domain = this;
|
89
|
+
er.domainThrown = true;
|
90
|
+
// wrap this in a try/catch so we don't get infinite throwing
|
91
|
+
try {
|
92
|
+
// One of three things will happen here.
|
93
|
+
//
|
94
|
+
// 1. There is a handler, caught = true
|
95
|
+
// 2. There is no handler, caught = false
|
96
|
+
// 3. It throws, caught = false
|
97
|
+
//
|
98
|
+
// If caught is false after this, then there's no need to exit()
|
99
|
+
// the domain, because we're going to crash the process anyway.
|
100
|
+
caught = this.emit('error', er);
|
101
|
+
|
102
|
+
// Exit all domains on the stack. Uncaught exceptions end the
|
103
|
+
// current tick and no domains should be left on the stack
|
104
|
+
// between ticks.
|
105
|
+
stack.length = 0;
|
106
|
+
exports.active = process.domain = null;
|
107
|
+
} catch (er2) {
|
108
|
+
// The domain error handler threw! oh no!
|
109
|
+
// See if another domain can catch THIS error,
|
110
|
+
// or else crash on the original one.
|
111
|
+
// If the user already exited it, then don't double-exit.
|
112
|
+
if (this === exports.active) {
|
113
|
+
stack.pop();
|
114
|
+
}
|
115
|
+
if (stack.length) {
|
116
|
+
exports.active = process.domain = stack[stack.length - 1];
|
117
|
+
caught = process._fatalException(er2);
|
118
|
+
} else {
|
119
|
+
caught = false;
|
120
|
+
}
|
121
|
+
return caught;
|
122
|
+
}
|
123
|
+
return caught;
|
124
|
+
};
|
125
|
+
|
126
|
+
|
127
|
+
Domain.prototype.enter = function() {
|
128
|
+
if (this._disposed) return;
|
129
|
+
|
130
|
+
// note that this might be a no-op, but we still need
|
131
|
+
// to push it onto the stack so that we can pop it later.
|
132
|
+
exports.active = process.domain = this;
|
133
|
+
stack.push(this);
|
134
|
+
_domain_flag[0] = stack.length;
|
135
|
+
};
|
136
|
+
|
137
|
+
|
138
|
+
Domain.prototype.exit = function() {
|
139
|
+
// skip disposed domains, as usual, but also don't do anything if this
|
140
|
+
// domain is not on the stack.
|
141
|
+
var index = stack.lastIndexOf(this);
|
142
|
+
if (this._disposed || index === -1) return;
|
143
|
+
|
144
|
+
// exit all domains until this one.
|
145
|
+
stack.splice(index);
|
146
|
+
_domain_flag[0] = stack.length;
|
147
|
+
|
148
|
+
exports.active = stack[stack.length - 1];
|
149
|
+
process.domain = exports.active;
|
150
|
+
};
|
151
|
+
|
152
|
+
|
153
|
+
// note: this works for timers as well.
|
154
|
+
Domain.prototype.add = function(ee) {
|
155
|
+
// If the domain is disposed or already added, then nothing left to do.
|
156
|
+
if (this._disposed || ee.domain === this)
|
157
|
+
return;
|
158
|
+
|
159
|
+
// has a domain already - remove it first.
|
160
|
+
if (ee.domain)
|
161
|
+
ee.domain.remove(ee);
|
162
|
+
|
163
|
+
// check for circular Domain->Domain links.
|
164
|
+
// This causes bad insanity!
|
165
|
+
//
|
166
|
+
// For example:
|
167
|
+
// var d = domain.create();
|
168
|
+
// var e = domain.create();
|
169
|
+
// d.add(e);
|
170
|
+
// e.add(d);
|
171
|
+
// e.emit('error', er); // RangeError, stack overflow!
|
172
|
+
if (this.domain && (ee instanceof Domain)) {
|
173
|
+
for (var d = this.domain; d; d = d.domain) {
|
174
|
+
if (ee === d) return;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
ee.domain = this;
|
179
|
+
this.members.push(ee);
|
180
|
+
};
|
181
|
+
|
182
|
+
|
183
|
+
Domain.prototype.remove = function(ee) {
|
184
|
+
ee.domain = null;
|
185
|
+
var index = this.members.indexOf(ee);
|
186
|
+
if (index !== -1)
|
187
|
+
this.members.splice(index, 1);
|
188
|
+
};
|
189
|
+
|
190
|
+
|
191
|
+
Domain.prototype.run = function(fn) {
|
192
|
+
if (this._disposed)
|
193
|
+
return;
|
194
|
+
this.enter();
|
195
|
+
var ret = fn.call(this);
|
196
|
+
this.exit();
|
197
|
+
return ret;
|
198
|
+
};
|
199
|
+
|
200
|
+
|
201
|
+
function intercepted(_this, self, cb, fnargs) {
|
202
|
+
if (self._disposed)
|
203
|
+
return;
|
204
|
+
|
205
|
+
if (fnargs[0] && fnargs[0] instanceof Error) {
|
206
|
+
var er = fnargs[0];
|
207
|
+
util._extend(er, {
|
208
|
+
domainBound: cb,
|
209
|
+
domainThrown: false,
|
210
|
+
domain: self
|
211
|
+
});
|
212
|
+
self.emit('error', er);
|
213
|
+
return;
|
214
|
+
}
|
215
|
+
|
216
|
+
var len = fnargs.length;
|
217
|
+
var args = [];
|
218
|
+
var i, ret;
|
219
|
+
|
220
|
+
self.enter();
|
221
|
+
if (fnargs.length > 1) {
|
222
|
+
for (i = 1; i < fnargs.length; i++)
|
223
|
+
args.push(fnargs[i]);
|
224
|
+
ret = cb.apply(_this, args);
|
225
|
+
} else {
|
226
|
+
ret = cb.call(_this);
|
227
|
+
}
|
228
|
+
self.exit();
|
229
|
+
|
230
|
+
return ret;
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
Domain.prototype.intercept = function(cb) {
|
235
|
+
var self = this;
|
236
|
+
|
237
|
+
function runIntercepted() {
|
238
|
+
return intercepted(this, self, cb, arguments);
|
239
|
+
}
|
240
|
+
|
241
|
+
return runIntercepted;
|
242
|
+
};
|
243
|
+
|
244
|
+
|
245
|
+
function bound(_this, self, cb, fnargs) {
|
246
|
+
if (self._disposed)
|
247
|
+
return;
|
248
|
+
|
249
|
+
var len = fnargs.length;
|
250
|
+
var args = [];
|
251
|
+
var i, ret;
|
252
|
+
|
253
|
+
self.enter();
|
254
|
+
if (fnargs.length > 0)
|
255
|
+
ret = cb.apply(_this, fnargs);
|
256
|
+
else
|
257
|
+
ret = cb.call(_this);
|
258
|
+
self.exit();
|
259
|
+
|
260
|
+
return ret;
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
Domain.prototype.bind = function(cb) {
|
265
|
+
var self = this;
|
266
|
+
|
267
|
+
function runBound() {
|
268
|
+
return bound(this, self, cb, arguments);
|
269
|
+
}
|
270
|
+
|
271
|
+
runBound.domain = this;
|
272
|
+
|
273
|
+
return runBound;
|
274
|
+
};
|
275
|
+
|
276
|
+
|
277
|
+
Domain.prototype.dispose = util.deprecate(function() {
|
278
|
+
if (this._disposed) return;
|
279
|
+
|
280
|
+
// if we're the active domain, then get out now.
|
281
|
+
this.exit();
|
282
|
+
|
283
|
+
// remove from parent domain, if there is one.
|
284
|
+
if (this.domain) this.domain.remove(this);
|
285
|
+
|
286
|
+
// kill the references so that they can be properly gc'ed.
|
287
|
+
this.members.length = 0;
|
288
|
+
|
289
|
+
// mark this domain as 'no longer relevant'
|
290
|
+
// so that it can't be entered or activated.
|
291
|
+
this._disposed = true;
|
292
|
+
});
|