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,90 @@
|
|
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 smalloc = process.binding('smalloc');
|
23
|
+
var kMaxLength = smalloc.kMaxLength;
|
24
|
+
var util = require('util');
|
25
|
+
|
26
|
+
exports.alloc = alloc;
|
27
|
+
exports.copyOnto = smalloc.copyOnto;
|
28
|
+
exports.dispose = dispose;
|
29
|
+
exports.hasExternalData = smalloc.hasExternalData;
|
30
|
+
|
31
|
+
// don't allow kMaxLength to accidentally be overwritten. it's a lot less
|
32
|
+
// apparent when a primitive is accidentally changed.
|
33
|
+
Object.defineProperty(exports, 'kMaxLength', {
|
34
|
+
enumerable: true, value: kMaxLength, writable: false
|
35
|
+
});
|
36
|
+
|
37
|
+
// enumerated values for different external array types
|
38
|
+
var Types = {};
|
39
|
+
|
40
|
+
Object.defineProperties(Types, {
|
41
|
+
'Int8': { enumerable: true, value: 1, writable: false },
|
42
|
+
'Uint8': { enumerable: true, value: 2, writable: false },
|
43
|
+
'Int16': { enumerable: true, value: 3, writable: false },
|
44
|
+
'Uint16': { enumerable: true, value: 4, writable: false },
|
45
|
+
'Int32': { enumerable: true, value: 5, writable: false },
|
46
|
+
'Uint32': { enumerable: true, value: 6, writable: false },
|
47
|
+
'Float': { enumerable: true, value: 7, writable: false },
|
48
|
+
'Double': { enumerable: true, value: 8, writable: false },
|
49
|
+
'Uint8Clamped': { enumerable: true, value: 9, writable: false }
|
50
|
+
});
|
51
|
+
|
52
|
+
Object.defineProperty(exports, 'Types', {
|
53
|
+
enumerable: true, value: Types, writable: false
|
54
|
+
});
|
55
|
+
|
56
|
+
|
57
|
+
// usage: obj = alloc(n[, obj][, type]);
|
58
|
+
function alloc(n, obj, type) {
|
59
|
+
n = n >>> 0;
|
60
|
+
|
61
|
+
if (util.isUndefined(obj))
|
62
|
+
obj = {};
|
63
|
+
|
64
|
+
if (util.isNumber(obj)) {
|
65
|
+
type = obj >>> 0;
|
66
|
+
obj = {};
|
67
|
+
} else if (util.isPrimitive(obj)) {
|
68
|
+
throw new TypeError('obj must be an Object');
|
69
|
+
}
|
70
|
+
|
71
|
+
// 1 == v8::kExternalByteArray, 9 == v8::kExternalPixelArray
|
72
|
+
if (type < 1 || type > 9)
|
73
|
+
throw new TypeError('unknown external array type: ' + type);
|
74
|
+
if (util.isArray(obj))
|
75
|
+
throw new TypeError('Arrays are not supported');
|
76
|
+
if (n > kMaxLength)
|
77
|
+
throw new RangeError('n > kMaxLength');
|
78
|
+
|
79
|
+
return smalloc.alloc(obj, n, type);
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
function dispose(obj) {
|
84
|
+
if (util.isPrimitive(obj))
|
85
|
+
throw new TypeError('obj must be an Object');
|
86
|
+
if (util.isBuffer(obj))
|
87
|
+
throw new TypeError('obj cannot be a Buffer');
|
88
|
+
|
89
|
+
smalloc.dispose(obj);
|
90
|
+
}
|
@@ -0,0 +1,127 @@
|
|
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
|
+
module.exports = Stream;
|
23
|
+
|
24
|
+
var EE = require('events').EventEmitter;
|
25
|
+
var util = require('util');
|
26
|
+
|
27
|
+
util.inherits(Stream, EE);
|
28
|
+
Stream.Readable = require('_stream_readable');
|
29
|
+
Stream.Writable = require('_stream_writable');
|
30
|
+
Stream.Duplex = require('_stream_duplex');
|
31
|
+
Stream.Transform = require('_stream_transform');
|
32
|
+
Stream.PassThrough = require('_stream_passthrough');
|
33
|
+
|
34
|
+
// Backwards-compat with node 0.4.x
|
35
|
+
Stream.Stream = Stream;
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
// old-style streams. Note that the pipe method (the only relevant
|
40
|
+
// part of this class) is overridden in the Readable class.
|
41
|
+
|
42
|
+
function Stream() {
|
43
|
+
EE.call(this);
|
44
|
+
}
|
45
|
+
|
46
|
+
Stream.prototype.pipe = function(dest, options) {
|
47
|
+
var source = this;
|
48
|
+
|
49
|
+
function ondata(chunk) {
|
50
|
+
if (dest.writable) {
|
51
|
+
if (false === dest.write(chunk) && source.pause) {
|
52
|
+
source.pause();
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
source.on('data', ondata);
|
58
|
+
|
59
|
+
function ondrain() {
|
60
|
+
if (source.readable && source.resume) {
|
61
|
+
source.resume();
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
dest.on('drain', ondrain);
|
66
|
+
|
67
|
+
// If the 'end' option is not supplied, dest.end() will be called when
|
68
|
+
// source gets the 'end' or 'close' events. Only dest.end() once.
|
69
|
+
if (!dest._isStdio && (!options || options.end !== false)) {
|
70
|
+
source.on('end', onend);
|
71
|
+
source.on('close', onclose);
|
72
|
+
}
|
73
|
+
|
74
|
+
var didOnEnd = false;
|
75
|
+
function onend() {
|
76
|
+
if (didOnEnd) return;
|
77
|
+
didOnEnd = true;
|
78
|
+
|
79
|
+
dest.end();
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
function onclose() {
|
84
|
+
if (didOnEnd) return;
|
85
|
+
didOnEnd = true;
|
86
|
+
|
87
|
+
if (util.isFunction(dest.destroy)) dest.destroy();
|
88
|
+
}
|
89
|
+
|
90
|
+
// don't leave dangling pipes when there are errors.
|
91
|
+
function onerror(er) {
|
92
|
+
cleanup();
|
93
|
+
if (EE.listenerCount(this, 'error') === 0) {
|
94
|
+
throw er; // Unhandled stream error in pipe.
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
source.on('error', onerror);
|
99
|
+
dest.on('error', onerror);
|
100
|
+
|
101
|
+
// remove all the event listeners that were added.
|
102
|
+
function cleanup() {
|
103
|
+
source.removeListener('data', ondata);
|
104
|
+
dest.removeListener('drain', ondrain);
|
105
|
+
|
106
|
+
source.removeListener('end', onend);
|
107
|
+
source.removeListener('close', onclose);
|
108
|
+
|
109
|
+
source.removeListener('error', onerror);
|
110
|
+
dest.removeListener('error', onerror);
|
111
|
+
|
112
|
+
source.removeListener('end', cleanup);
|
113
|
+
source.removeListener('close', cleanup);
|
114
|
+
|
115
|
+
dest.removeListener('close', cleanup);
|
116
|
+
}
|
117
|
+
|
118
|
+
source.on('end', cleanup);
|
119
|
+
source.on('close', cleanup);
|
120
|
+
|
121
|
+
dest.on('close', cleanup);
|
122
|
+
|
123
|
+
dest.emit('pipe', source);
|
124
|
+
|
125
|
+
// Allow for unix-like usage: A.pipe(B).pipe(C)
|
126
|
+
return dest;
|
127
|
+
};
|
@@ -0,0 +1,189 @@
|
|
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
|
+
function assertEncoding(encoding) {
|
23
|
+
if (encoding && !Buffer.isEncoding(encoding)) {
|
24
|
+
throw new Error('Unknown encoding: ' + encoding);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
var StringDecoder = exports.StringDecoder = function(encoding) {
|
29
|
+
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
|
30
|
+
assertEncoding(encoding);
|
31
|
+
switch (this.encoding) {
|
32
|
+
case 'utf8':
|
33
|
+
// CESU-8 represents each of Surrogate Pair by 3-bytes
|
34
|
+
this.surrogateSize = 3;
|
35
|
+
break;
|
36
|
+
case 'ucs2':
|
37
|
+
case 'utf16le':
|
38
|
+
// UTF-16 represents each of Surrogate Pair by 2-bytes
|
39
|
+
this.surrogateSize = 2;
|
40
|
+
this.detectIncompleteChar = utf16DetectIncompleteChar;
|
41
|
+
break;
|
42
|
+
case 'base64':
|
43
|
+
// Base-64 stores 3 bytes in 4 chars, and pads the remainder.
|
44
|
+
this.surrogateSize = 3;
|
45
|
+
this.detectIncompleteChar = base64DetectIncompleteChar;
|
46
|
+
break;
|
47
|
+
default:
|
48
|
+
this.write = passThroughWrite;
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
|
52
|
+
this.charBuffer = new Buffer(6);
|
53
|
+
this.charReceived = 0;
|
54
|
+
this.charLength = 0;
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
StringDecoder.prototype.write = function(buffer) {
|
59
|
+
var charStr = '';
|
60
|
+
var offset = 0;
|
61
|
+
|
62
|
+
// if our last write ended with an incomplete multibyte character
|
63
|
+
while (this.charLength) {
|
64
|
+
// determine how many remaining bytes this buffer has to offer for this char
|
65
|
+
var i = (buffer.length >= this.charLength - this.charReceived) ?
|
66
|
+
this.charLength - this.charReceived :
|
67
|
+
buffer.length;
|
68
|
+
|
69
|
+
// add the new bytes to the char buffer
|
70
|
+
buffer.copy(this.charBuffer, this.charReceived, offset, i);
|
71
|
+
this.charReceived += (i - offset);
|
72
|
+
offset = i;
|
73
|
+
|
74
|
+
if (this.charReceived < this.charLength) {
|
75
|
+
// still not enough chars in this buffer? wait for more ...
|
76
|
+
return '';
|
77
|
+
}
|
78
|
+
|
79
|
+
// get the character that was split
|
80
|
+
charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding);
|
81
|
+
|
82
|
+
// lead surrogate (D800-DBFF) is also the incomplete character
|
83
|
+
var charCode = charStr.charCodeAt(charStr.length - 1);
|
84
|
+
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
85
|
+
this.charLength += this.surrogateSize;
|
86
|
+
charStr = '';
|
87
|
+
continue;
|
88
|
+
}
|
89
|
+
this.charReceived = this.charLength = 0;
|
90
|
+
|
91
|
+
// if there are no more bytes in this buffer, just emit our char
|
92
|
+
if (i == buffer.length) return charStr;
|
93
|
+
|
94
|
+
// otherwise cut off the characters end from the beginning of this buffer
|
95
|
+
buffer = buffer.slice(i, buffer.length);
|
96
|
+
break;
|
97
|
+
}
|
98
|
+
|
99
|
+
var lenIncomplete = this.detectIncompleteChar(buffer);
|
100
|
+
|
101
|
+
var end = buffer.length;
|
102
|
+
if (this.charLength) {
|
103
|
+
// buffer the incomplete character bytes we got
|
104
|
+
buffer.copy(this.charBuffer, 0, buffer.length - lenIncomplete, end);
|
105
|
+
this.charReceived = lenIncomplete;
|
106
|
+
end -= lenIncomplete;
|
107
|
+
}
|
108
|
+
|
109
|
+
charStr += buffer.toString(this.encoding, 0, end);
|
110
|
+
|
111
|
+
var end = charStr.length - 1;
|
112
|
+
var charCode = charStr.charCodeAt(end);
|
113
|
+
// lead surrogate (D800-DBFF) is also the incomplete character
|
114
|
+
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
|
115
|
+
var size = this.surrogateSize;
|
116
|
+
this.charLength += size;
|
117
|
+
this.charReceived += size;
|
118
|
+
this.charBuffer.copy(this.charBuffer, size, 0, size);
|
119
|
+
this.charBuffer.write(charStr.charAt(charStr.length - 1), this.encoding);
|
120
|
+
return charStr.substring(0, end);
|
121
|
+
}
|
122
|
+
|
123
|
+
// or just emit the charStr
|
124
|
+
return charStr;
|
125
|
+
};
|
126
|
+
|
127
|
+
StringDecoder.prototype.detectIncompleteChar = function(buffer) {
|
128
|
+
// determine how many bytes we have to check at the end of this buffer
|
129
|
+
var i = (buffer.length >= 3) ? 3 : buffer.length;
|
130
|
+
|
131
|
+
// Figure out if one of the last i bytes of our buffer announces an
|
132
|
+
// incomplete char.
|
133
|
+
for (; i > 0; i--) {
|
134
|
+
var c = buffer[buffer.length - i];
|
135
|
+
|
136
|
+
// See http://en.wikipedia.org/wiki/UTF-8#Description
|
137
|
+
|
138
|
+
// 110XXXXX
|
139
|
+
if (i == 1 && c >> 5 == 0x06) {
|
140
|
+
this.charLength = 2;
|
141
|
+
break;
|
142
|
+
}
|
143
|
+
|
144
|
+
// 1110XXXX
|
145
|
+
if (i <= 2 && c >> 4 == 0x0E) {
|
146
|
+
this.charLength = 3;
|
147
|
+
break;
|
148
|
+
}
|
149
|
+
|
150
|
+
// 11110XXX
|
151
|
+
if (i <= 3 && c >> 3 == 0x1E) {
|
152
|
+
this.charLength = 4;
|
153
|
+
break;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
return i;
|
158
|
+
};
|
159
|
+
|
160
|
+
StringDecoder.prototype.end = function(buffer) {
|
161
|
+
var res = '';
|
162
|
+
if (buffer && buffer.length)
|
163
|
+
res = this.write(buffer);
|
164
|
+
|
165
|
+
if (this.charReceived) {
|
166
|
+
var cr = this.charReceived;
|
167
|
+
var buf = this.charBuffer;
|
168
|
+
var enc = this.encoding;
|
169
|
+
res += buf.slice(0, cr).toString(enc);
|
170
|
+
}
|
171
|
+
|
172
|
+
return res;
|
173
|
+
};
|
174
|
+
|
175
|
+
function passThroughWrite(buffer) {
|
176
|
+
return buffer.toString(this.encoding);
|
177
|
+
}
|
178
|
+
|
179
|
+
function utf16DetectIncompleteChar(buffer) {
|
180
|
+
var incomplete = this.charReceived = buffer.length % 2;
|
181
|
+
this.charLength = incomplete ? 2 : 0;
|
182
|
+
return incomplete;
|
183
|
+
}
|
184
|
+
|
185
|
+
function base64DetectIncompleteChar(buffer) {
|
186
|
+
var incomplete = this.charReceived = buffer.length % 3;
|
187
|
+
this.charLength = incomplete ? 3 : 0;
|
188
|
+
return incomplete;
|
189
|
+
}
|
@@ -0,0 +1,24 @@
|
|
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
|
+
// the sys module was renamed to 'util'.
|
23
|
+
// this shim remains to keep old programs working.
|
24
|
+
module.exports = require('util');
|
@@ -0,0 +1,568 @@
|
|
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 Timer = process.binding('timer_wrap').Timer;
|
23
|
+
var L = require('_linklist');
|
24
|
+
var assert = require('assert').ok;
|
25
|
+
|
26
|
+
var kOnTimeout = Timer.kOnTimeout | 0;
|
27
|
+
|
28
|
+
// Timeout values > TIMEOUT_MAX are set to 1.
|
29
|
+
var TIMEOUT_MAX = 2147483647; // 2^31-1
|
30
|
+
|
31
|
+
var debug = require('util').debuglog('timer');
|
32
|
+
|
33
|
+
var asyncFlags = process._asyncFlags;
|
34
|
+
var runAsyncQueue = process._runAsyncQueue;
|
35
|
+
var loadAsyncQueue = process._loadAsyncQueue;
|
36
|
+
var unloadAsyncQueue = process._unloadAsyncQueue;
|
37
|
+
|
38
|
+
// Same as in AsyncListener in env.h
|
39
|
+
var kHasListener = 0;
|
40
|
+
|
41
|
+
// Do a little housekeeping.
|
42
|
+
delete process._asyncFlags;
|
43
|
+
delete process._runAsyncQueue;
|
44
|
+
delete process._loadAsyncQueue;
|
45
|
+
delete process._unloadAsyncQueue;
|
46
|
+
|
47
|
+
|
48
|
+
// IDLE TIMEOUTS
|
49
|
+
//
|
50
|
+
// Because often many sockets will have the same idle timeout we will not
|
51
|
+
// use one timeout watcher per item. It is too much overhead. Instead
|
52
|
+
// we'll use a single watcher for all sockets with the same timeout value
|
53
|
+
// and a linked list. This technique is described in the libev manual:
|
54
|
+
// http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#Be_smart_about_timeouts
|
55
|
+
|
56
|
+
// Object containing all lists, timers
|
57
|
+
// key = time in milliseconds
|
58
|
+
// value = list
|
59
|
+
var lists = {};
|
60
|
+
|
61
|
+
// Make Timer as monomorphic as possible.
|
62
|
+
Timer.prototype._asyncQueue = undefined;
|
63
|
+
Timer.prototype._asyncData = undefined;
|
64
|
+
Timer.prototype._asyncFlags = 0;
|
65
|
+
|
66
|
+
// the main function - creates lists on demand and the watchers associated
|
67
|
+
// with them.
|
68
|
+
function insert(item, msecs) {
|
69
|
+
item._idleStart = Timer.now();
|
70
|
+
item._idleTimeout = msecs;
|
71
|
+
|
72
|
+
if (msecs < 0) return;
|
73
|
+
|
74
|
+
var list;
|
75
|
+
|
76
|
+
if (lists[msecs]) {
|
77
|
+
list = lists[msecs];
|
78
|
+
} else {
|
79
|
+
list = new Timer();
|
80
|
+
list.start(msecs, 0);
|
81
|
+
|
82
|
+
L.init(list);
|
83
|
+
|
84
|
+
lists[msecs] = list;
|
85
|
+
list.msecs = msecs;
|
86
|
+
list[kOnTimeout] = listOnTimeout;
|
87
|
+
}
|
88
|
+
|
89
|
+
L.append(list, item);
|
90
|
+
assert(!L.isEmpty(list)); // list is not empty
|
91
|
+
}
|
92
|
+
|
93
|
+
function listOnTimeout() {
|
94
|
+
var msecs = this.msecs;
|
95
|
+
var list = this;
|
96
|
+
|
97
|
+
debug('timeout callback %d', msecs);
|
98
|
+
|
99
|
+
var now = Timer.now();
|
100
|
+
debug('now: %s', now);
|
101
|
+
|
102
|
+
var diff, first, hasQueue, threw;
|
103
|
+
while (first = L.peek(list)) {
|
104
|
+
diff = now - first._idleStart;
|
105
|
+
if (diff < msecs) {
|
106
|
+
list.start(msecs - diff, 0);
|
107
|
+
debug('%d list wait because diff is %d', msecs, diff);
|
108
|
+
return;
|
109
|
+
} else {
|
110
|
+
L.remove(first);
|
111
|
+
assert(first !== L.peek(list));
|
112
|
+
|
113
|
+
if (!first._onTimeout) continue;
|
114
|
+
|
115
|
+
// v0.4 compatibility: if the timer callback throws and the
|
116
|
+
// domain or uncaughtException handler ignore the exception,
|
117
|
+
// other timers that expire on this tick should still run.
|
118
|
+
//
|
119
|
+
// https://github.com/joyent/node/issues/2631
|
120
|
+
var domain = first.domain;
|
121
|
+
if (domain && domain._disposed)
|
122
|
+
continue;
|
123
|
+
|
124
|
+
hasQueue = !!first._asyncQueue;
|
125
|
+
|
126
|
+
try {
|
127
|
+
if (hasQueue)
|
128
|
+
loadAsyncQueue(first);
|
129
|
+
if (domain)
|
130
|
+
domain.enter();
|
131
|
+
threw = true;
|
132
|
+
first._onTimeout();
|
133
|
+
if (domain)
|
134
|
+
domain.exit();
|
135
|
+
if (hasQueue)
|
136
|
+
unloadAsyncQueue(first);
|
137
|
+
threw = false;
|
138
|
+
} finally {
|
139
|
+
if (threw) {
|
140
|
+
process.nextTick(function() {
|
141
|
+
list[kOnTimeout]();
|
142
|
+
});
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
debug('%d list empty', msecs);
|
149
|
+
assert(L.isEmpty(list));
|
150
|
+
list.close();
|
151
|
+
delete lists[msecs];
|
152
|
+
}
|
153
|
+
|
154
|
+
|
155
|
+
var unenroll = exports.unenroll = function(item) {
|
156
|
+
L.remove(item);
|
157
|
+
|
158
|
+
var list = lists[item._idleTimeout];
|
159
|
+
// if empty then stop the watcher
|
160
|
+
debug('unenroll');
|
161
|
+
if (list && L.isEmpty(list)) {
|
162
|
+
debug('unenroll: list empty');
|
163
|
+
list.close();
|
164
|
+
delete lists[item._idleTimeout];
|
165
|
+
}
|
166
|
+
// if active is called later, then we want to make sure not to insert again
|
167
|
+
item._idleTimeout = -1;
|
168
|
+
};
|
169
|
+
|
170
|
+
|
171
|
+
// Does not start the time, just sets up the members needed.
|
172
|
+
exports.enroll = function(item, msecs) {
|
173
|
+
// if this item was already in a list somewhere
|
174
|
+
// then we should unenroll it from that
|
175
|
+
if (item._idleNext) unenroll(item);
|
176
|
+
|
177
|
+
// Ensure that msecs fits into signed int32
|
178
|
+
if (msecs > 0x7fffffff) {
|
179
|
+
msecs = 0x7fffffff;
|
180
|
+
}
|
181
|
+
|
182
|
+
item._idleTimeout = msecs;
|
183
|
+
L.init(item);
|
184
|
+
};
|
185
|
+
|
186
|
+
|
187
|
+
// call this whenever the item is active (not idle)
|
188
|
+
// it will reset its timeout.
|
189
|
+
exports.active = function(item) {
|
190
|
+
var msecs = item._idleTimeout;
|
191
|
+
if (msecs >= 0) {
|
192
|
+
var list = lists[msecs];
|
193
|
+
if (!list || L.isEmpty(list)) {
|
194
|
+
insert(item, msecs);
|
195
|
+
} else {
|
196
|
+
item._idleStart = Timer.now();
|
197
|
+
L.append(list, item);
|
198
|
+
}
|
199
|
+
}
|
200
|
+
// Whether or not a new TimerWrap needed to be created, this should run
|
201
|
+
// for each item. This way each "item" (i.e. timer) can properly have
|
202
|
+
// their own domain assigned.
|
203
|
+
if (asyncFlags[kHasListener] > 0)
|
204
|
+
runAsyncQueue(item);
|
205
|
+
};
|
206
|
+
|
207
|
+
|
208
|
+
/*
|
209
|
+
* DOM-style timers
|
210
|
+
*/
|
211
|
+
|
212
|
+
|
213
|
+
exports.setTimeout = function(callback, after) {
|
214
|
+
var timer;
|
215
|
+
|
216
|
+
after *= 1; // coalesce to number or NaN
|
217
|
+
|
218
|
+
if (!(after >= 1 && after <= TIMEOUT_MAX)) {
|
219
|
+
after = 1; // schedule on next tick, follows browser behaviour
|
220
|
+
}
|
221
|
+
|
222
|
+
timer = new Timeout(after);
|
223
|
+
|
224
|
+
if (arguments.length <= 2) {
|
225
|
+
timer._onTimeout = callback;
|
226
|
+
} else {
|
227
|
+
/*
|
228
|
+
* Sometimes setTimeout is called with arguments, EG
|
229
|
+
*
|
230
|
+
* setTimeout(callback, 2000, "hello", "world")
|
231
|
+
*
|
232
|
+
* If that's the case we need to call the callback with
|
233
|
+
* those args. The overhead of an extra closure is not
|
234
|
+
* desired in the normal case.
|
235
|
+
*/
|
236
|
+
var args = Array.prototype.slice.call(arguments, 2);
|
237
|
+
timer._onTimeout = function() {
|
238
|
+
callback.apply(timer, args);
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
if (process.domain) timer.domain = process.domain;
|
243
|
+
|
244
|
+
exports.active(timer);
|
245
|
+
|
246
|
+
return timer;
|
247
|
+
};
|
248
|
+
|
249
|
+
|
250
|
+
exports.clearTimeout = function(timer) {
|
251
|
+
if (timer && (timer[kOnTimeout] || timer._onTimeout)) {
|
252
|
+
timer[kOnTimeout] = timer._onTimeout = null;
|
253
|
+
if (timer instanceof Timeout) {
|
254
|
+
timer.close(); // for after === 0
|
255
|
+
} else {
|
256
|
+
exports.unenroll(timer);
|
257
|
+
}
|
258
|
+
}
|
259
|
+
};
|
260
|
+
|
261
|
+
|
262
|
+
exports.setInterval = function(callback, repeat) {
|
263
|
+
repeat *= 1; // coalesce to number or NaN
|
264
|
+
|
265
|
+
if (!(repeat >= 1 && repeat <= TIMEOUT_MAX)) {
|
266
|
+
repeat = 1; // schedule on next tick, follows browser behaviour
|
267
|
+
}
|
268
|
+
|
269
|
+
var timer = new Timeout(repeat);
|
270
|
+
var args = Array.prototype.slice.call(arguments, 2);
|
271
|
+
timer._onTimeout = wrapper;
|
272
|
+
timer._repeat = true;
|
273
|
+
|
274
|
+
if (process.domain) timer.domain = process.domain;
|
275
|
+
exports.active(timer);
|
276
|
+
|
277
|
+
return timer;
|
278
|
+
|
279
|
+
function wrapper() {
|
280
|
+
callback.apply(this, args);
|
281
|
+
// If callback called clearInterval().
|
282
|
+
if (timer._repeat === false) return;
|
283
|
+
// If timer is unref'd (or was - it's permanently removed from the list.)
|
284
|
+
if (this._handle) {
|
285
|
+
this._handle.start(repeat, 0);
|
286
|
+
} else {
|
287
|
+
timer._idleTimeout = repeat;
|
288
|
+
exports.active(timer);
|
289
|
+
}
|
290
|
+
}
|
291
|
+
};
|
292
|
+
|
293
|
+
|
294
|
+
exports.clearInterval = function(timer) {
|
295
|
+
if (timer && timer._repeat) {
|
296
|
+
timer._repeat = false;
|
297
|
+
clearTimeout(timer);
|
298
|
+
}
|
299
|
+
};
|
300
|
+
|
301
|
+
|
302
|
+
var Timeout = function(after) {
|
303
|
+
this._idleTimeout = after;
|
304
|
+
this._idlePrev = this;
|
305
|
+
this._idleNext = this;
|
306
|
+
this._idleStart = null;
|
307
|
+
this._onTimeout = null;
|
308
|
+
this._repeat = false;
|
309
|
+
};
|
310
|
+
|
311
|
+
Timeout.prototype.unref = function() {
|
312
|
+
if (!this._handle) {
|
313
|
+
var now = Timer.now();
|
314
|
+
if (!this._idleStart) this._idleStart = now;
|
315
|
+
var delay = this._idleStart + this._idleTimeout - now;
|
316
|
+
if (delay < 0) delay = 0;
|
317
|
+
exports.unenroll(this);
|
318
|
+
this._handle = new Timer();
|
319
|
+
this._handle[kOnTimeout] = this._onTimeout;
|
320
|
+
this._handle.start(delay, 0);
|
321
|
+
this._handle.domain = this.domain;
|
322
|
+
this._handle.unref();
|
323
|
+
} else {
|
324
|
+
this._handle.unref();
|
325
|
+
}
|
326
|
+
};
|
327
|
+
|
328
|
+
Timeout.prototype.ref = function() {
|
329
|
+
if (this._handle)
|
330
|
+
this._handle.ref();
|
331
|
+
};
|
332
|
+
|
333
|
+
Timeout.prototype.close = function() {
|
334
|
+
this._onTimeout = null;
|
335
|
+
if (this._handle) {
|
336
|
+
this._handle[kOnTimeout] = null;
|
337
|
+
this._handle.close();
|
338
|
+
} else {
|
339
|
+
exports.unenroll(this);
|
340
|
+
}
|
341
|
+
};
|
342
|
+
|
343
|
+
|
344
|
+
var immediateQueue = {};
|
345
|
+
L.init(immediateQueue);
|
346
|
+
|
347
|
+
|
348
|
+
function processImmediate() {
|
349
|
+
var queue = immediateQueue;
|
350
|
+
var domain, hasQueue, immediate;
|
351
|
+
|
352
|
+
immediateQueue = {};
|
353
|
+
L.init(immediateQueue);
|
354
|
+
|
355
|
+
while (L.isEmpty(queue) === false) {
|
356
|
+
immediate = L.shift(queue);
|
357
|
+
hasQueue = !!immediate._asyncQueue;
|
358
|
+
domain = immediate.domain;
|
359
|
+
|
360
|
+
if (hasQueue)
|
361
|
+
loadAsyncQueue(immediate);
|
362
|
+
if (domain)
|
363
|
+
domain.enter();
|
364
|
+
|
365
|
+
var threw = true;
|
366
|
+
try {
|
367
|
+
immediate._onImmediate();
|
368
|
+
threw = false;
|
369
|
+
} finally {
|
370
|
+
if (threw) {
|
371
|
+
if (!L.isEmpty(queue)) {
|
372
|
+
// Handle any remaining on next tick, assuming we're still
|
373
|
+
// alive to do so.
|
374
|
+
while (!L.isEmpty(immediateQueue)) {
|
375
|
+
L.append(queue, L.shift(immediateQueue));
|
376
|
+
}
|
377
|
+
immediateQueue = queue;
|
378
|
+
process.nextTick(processImmediate);
|
379
|
+
}
|
380
|
+
}
|
381
|
+
}
|
382
|
+
|
383
|
+
if (domain)
|
384
|
+
domain.exit();
|
385
|
+
if (hasQueue)
|
386
|
+
unloadAsyncQueue(immediate);
|
387
|
+
}
|
388
|
+
|
389
|
+
// Only round-trip to C++ land if we have to. Calling clearImmediate() on an
|
390
|
+
// immediate that's in |queue| is okay. Worst case is we make a superfluous
|
391
|
+
// call to NeedImmediateCallbackSetter().
|
392
|
+
if (L.isEmpty(immediateQueue)) {
|
393
|
+
process._needImmediateCallback = false;
|
394
|
+
}
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
function Immediate() { }
|
399
|
+
|
400
|
+
Immediate.prototype.domain = undefined;
|
401
|
+
Immediate.prototype._onImmediate = undefined;
|
402
|
+
Immediate.prototype._asyncQueue = undefined;
|
403
|
+
Immediate.prototype._asyncData = undefined;
|
404
|
+
Immediate.prototype._idleNext = undefined;
|
405
|
+
Immediate.prototype._idlePrev = undefined;
|
406
|
+
Immediate.prototype._asyncFlags = 0;
|
407
|
+
|
408
|
+
|
409
|
+
exports.setImmediate = function(callback) {
|
410
|
+
var immediate = new Immediate();
|
411
|
+
var args, index;
|
412
|
+
|
413
|
+
L.init(immediate);
|
414
|
+
|
415
|
+
immediate._onImmediate = callback;
|
416
|
+
|
417
|
+
if (arguments.length > 1) {
|
418
|
+
args = [];
|
419
|
+
for (index = 1; index < arguments.length; index++)
|
420
|
+
args.push(arguments[index]);
|
421
|
+
|
422
|
+
immediate._onImmediate = function() {
|
423
|
+
callback.apply(immediate, args);
|
424
|
+
};
|
425
|
+
}
|
426
|
+
|
427
|
+
if (!process._needImmediateCallback) {
|
428
|
+
process._needImmediateCallback = true;
|
429
|
+
process._immediateCallback = processImmediate;
|
430
|
+
}
|
431
|
+
|
432
|
+
// setImmediates are handled more like nextTicks.
|
433
|
+
if (asyncFlags[kHasListener] > 0)
|
434
|
+
runAsyncQueue(immediate);
|
435
|
+
if (process.domain)
|
436
|
+
immediate.domain = process.domain;
|
437
|
+
|
438
|
+
L.append(immediateQueue, immediate);
|
439
|
+
|
440
|
+
return immediate;
|
441
|
+
};
|
442
|
+
|
443
|
+
|
444
|
+
exports.clearImmediate = function(immediate) {
|
445
|
+
if (!immediate) return;
|
446
|
+
|
447
|
+
immediate._onImmediate = undefined;
|
448
|
+
|
449
|
+
L.remove(immediate);
|
450
|
+
|
451
|
+
if (L.isEmpty(immediateQueue)) {
|
452
|
+
process._needImmediateCallback = false;
|
453
|
+
}
|
454
|
+
};
|
455
|
+
|
456
|
+
|
457
|
+
// Internal APIs that need timeouts should use timers._unrefActive isntead of
|
458
|
+
// timers.active as internal timeouts shouldn't hold the loop open
|
459
|
+
|
460
|
+
var unrefList, unrefTimer;
|
461
|
+
|
462
|
+
|
463
|
+
function unrefTimeout() {
|
464
|
+
var now = Timer.now();
|
465
|
+
|
466
|
+
debug('unrefTimer fired');
|
467
|
+
|
468
|
+
var diff, domain, first, hasQueue, threw;
|
469
|
+
while (first = L.peek(unrefList)) {
|
470
|
+
diff = now - first._idleStart;
|
471
|
+
|
472
|
+
if (diff < first._idleTimeout) {
|
473
|
+
diff = first._idleTimeout - diff;
|
474
|
+
unrefTimer.start(diff, 0);
|
475
|
+
unrefTimer.when = now + diff;
|
476
|
+
debug('unrefTimer rescheudling for later');
|
477
|
+
return;
|
478
|
+
}
|
479
|
+
|
480
|
+
L.remove(first);
|
481
|
+
|
482
|
+
domain = first.domain;
|
483
|
+
|
484
|
+
if (!first._onTimeout) continue;
|
485
|
+
if (domain && domain._disposed) continue;
|
486
|
+
hasQueue = !!first._asyncQueue;
|
487
|
+
|
488
|
+
try {
|
489
|
+
if (hasQueue)
|
490
|
+
loadAsyncQueue(first);
|
491
|
+
if (domain) domain.enter();
|
492
|
+
threw = true;
|
493
|
+
debug('unreftimer firing timeout');
|
494
|
+
first._onTimeout();
|
495
|
+
threw = false;
|
496
|
+
if (domain)
|
497
|
+
domain.exit();
|
498
|
+
if (hasQueue)
|
499
|
+
unloadAsyncQueue(first);
|
500
|
+
} finally {
|
501
|
+
if (threw) process.nextTick(unrefTimeout);
|
502
|
+
}
|
503
|
+
}
|
504
|
+
|
505
|
+
debug('unrefList is empty');
|
506
|
+
unrefTimer.when = -1;
|
507
|
+
}
|
508
|
+
|
509
|
+
|
510
|
+
exports._unrefActive = function(item) {
|
511
|
+
var msecs = item._idleTimeout;
|
512
|
+
if (!msecs || msecs < 0) return;
|
513
|
+
assert(msecs >= 0);
|
514
|
+
|
515
|
+
L.remove(item);
|
516
|
+
|
517
|
+
if (!unrefList) {
|
518
|
+
debug('unrefList initialized');
|
519
|
+
unrefList = {};
|
520
|
+
L.init(unrefList);
|
521
|
+
|
522
|
+
debug('unrefTimer initialized');
|
523
|
+
unrefTimer = new Timer();
|
524
|
+
unrefTimer.unref();
|
525
|
+
unrefTimer.when = -1;
|
526
|
+
unrefTimer[kOnTimeout] = unrefTimeout;
|
527
|
+
}
|
528
|
+
|
529
|
+
var now = Timer.now();
|
530
|
+
item._idleStart = now;
|
531
|
+
|
532
|
+
if (L.isEmpty(unrefList)) {
|
533
|
+
debug('unrefList empty');
|
534
|
+
L.append(unrefList, item);
|
535
|
+
|
536
|
+
unrefTimer.start(msecs, 0);
|
537
|
+
unrefTimer.when = now + msecs;
|
538
|
+
debug('unrefTimer scheduled');
|
539
|
+
return;
|
540
|
+
}
|
541
|
+
|
542
|
+
var when = now + msecs;
|
543
|
+
|
544
|
+
debug('unrefList find where we can insert');
|
545
|
+
|
546
|
+
var cur, them;
|
547
|
+
|
548
|
+
for (cur = unrefList._idlePrev; cur != unrefList; cur = cur._idlePrev) {
|
549
|
+
them = cur._idleStart + cur._idleTimeout;
|
550
|
+
|
551
|
+
if (when < them) {
|
552
|
+
debug('unrefList inserting into middle of list');
|
553
|
+
|
554
|
+
L.append(cur, item);
|
555
|
+
|
556
|
+
if (unrefTimer.when > when) {
|
557
|
+
debug('unrefTimer is scheduled to fire too late, reschedule');
|
558
|
+
unrefTimer.start(msecs, 0);
|
559
|
+
unrefTimer.when = when;
|
560
|
+
}
|
561
|
+
|
562
|
+
return;
|
563
|
+
}
|
564
|
+
}
|
565
|
+
|
566
|
+
debug('unrefList append to end');
|
567
|
+
L.append(unrefList, item);
|
568
|
+
};
|