Skip to content

Commit 3454954

Browse files
committed
update buildin web modules to node 0.8.8
1 parent 592bcdd commit 3454954

15 files changed

+621
-117
lines changed

buildin/web_modules/assert.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ assert.AssertionError = function AssertionError(options) {
4949
Error.captureStackTrace(this, stackStartFunction);
5050
}
5151
};
52+
53+
// assert.AssertionError instanceof Error
5254
util.inherits(assert.AssertionError, Error);
5355

5456
function replacer(key, value) {
@@ -85,10 +87,6 @@ assert.AssertionError.prototype.toString = function() {
8587
}
8688
};
8789

88-
// assert.AssertionError instanceof Error
89-
90-
assert.AssertionError.__proto__ = Error.prototype;
91-
9290
// At present only the three keys mentioned above are used and
9391
// understood by the spec. Implementations or sub modules can pass
9492
// other keys to the AssertionError's constructor - they will be
@@ -308,11 +306,11 @@ function _throws(shouldThrow, block, expected, message) {
308306
(message ? ' ' + message : '.');
309307

310308
if (shouldThrow && !actual) {
311-
fail('Missing expected exception' + message);
309+
fail(actual, expected, 'Missing expected exception' + message);
312310
}
313311

314312
if (!shouldThrow && expectedException(actual, expected)) {
315-
fail('Got unwanted exception' + message);
313+
fail(actual, expected, 'Got unwanted exception' + message);
316314
}
317315

318316
if ((shouldThrow && actual && expected &&

buildin/web_modules/events.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ EventEmitter.prototype.emit = function() {
9494
}
9595
};
9696

97-
// EventEmitter is defined in src/node_events.cc
98-
// EventEmitter.prototype.emit() is also defined there.
9997
EventEmitter.prototype.addListener = function(type, listener) {
10098
if ('function' !== typeof listener) {
10199
throw new Error('addListener only takes instances of Function');
@@ -186,6 +184,8 @@ EventEmitter.prototype.removeListener = function(type, listener) {
186184

187185
if (position < 0) return this;
188186
list.splice(position, 1);
187+
if (list.length == 0)
188+
delete this._events[type];
189189
} else if (list === listener ||
190190
(list.listener && list.listener === listener))
191191
{
@@ -201,15 +201,8 @@ EventEmitter.prototype.removeAllListeners = function(type) {
201201
return this;
202202
}
203203

204-
var events = this._events && this._events[type];
205-
if (!events) return this;
206-
207-
if (isArray(events)) {
208-
events.splice(0);
209-
} else {
210-
this._events[type] = null;
211-
}
212-
204+
// does not use listeners(), so no side effect of creating _events[type]
205+
if (type && this._events && this._events[type]) this._events[type] = null;
213206
return this;
214207
};
215208

buildin/web_modules/path.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
var isWindows = process.platform === 'win32';
24-
var _deprecationWarning = require('util')._deprecationWarning;
24+
var util = require('util');
2525

2626

2727
// resolves . and .. elements in a path array with directory names there
@@ -179,6 +179,9 @@ if (isWindows) {
179179
tail += '\\';
180180
}
181181

182+
// Convert slashes to backslashes when `device` points to an UNC root.
183+
device = device.replace(/\//g, '\\');
184+
182185
return device + (isAbsolute ? '\\' : '') + tail;
183186
};
184187

@@ -258,6 +261,7 @@ if (isWindows) {
258261
return outputParts.join('\\');
259262
};
260263

264+
exports.sep = '\\';
261265

262266
} else /* posix */ {
263267

@@ -373,6 +377,7 @@ if (isWindows) {
373377
return outputParts.join('/');
374378
};
375379

380+
exports.sep = '/';
376381
}
377382

378383

@@ -410,16 +415,14 @@ exports.extname = function(path) {
410415
};
411416

412417
/*
413-
exports.exists = function(path, callback) {
418+
exports.exists = util.deprecate(function(path, callback) {
414419
require('fs').exists(path, callback);
415-
};
416-
module.deprecate('exists', 'It is now called `fs.exists`.');
420+
}, 'path.exists is now called `fs.exists`.');
417421
418422
419-
exports.existsSync = function(path) {
423+
exports.existsSync = util.deprecate(function(path) {
420424
return require('fs').existsSync(path);
421-
};
422-
module.deprecate('existsSync', 'It is now called `fs.existsSync`.');
425+
}, 'path.existsSync is now called `fs.existsSync`.');
423426
*/
424427

425428
if (isWindows) {

buildin/web_modules/querystring.js

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,34 @@ var stringifyPrimitive = function(v) {
6666
QueryString.stringify = QueryString.encode = function(obj, sep, eq, name) {
6767
sep = sep || '&';
6868
eq = eq || '=';
69-
obj = (obj === null) ? undefined : obj;
70-
71-
switch (typeof obj) {
72-
case 'object':
73-
return Object.keys(obj).map(function(k) {
74-
if (Array.isArray(obj[k])) {
75-
return obj[k].map(function(v) {
76-
return QueryString.escape(stringifyPrimitive(k)) +
77-
eq +
78-
QueryString.escape(stringifyPrimitive(v));
79-
}).join(sep);
80-
} else {
81-
return QueryString.escape(stringifyPrimitive(k)) +
82-
eq +
83-
QueryString.escape(stringifyPrimitive(obj[k]));
84-
}
85-
}).join(sep);
69+
if (obj === null) {
70+
obj = undefined;
71+
}
72+
73+
if (typeof obj === 'object') {
74+
return Object.keys(obj).map(function(k) {
75+
var ks = QueryString.escape(stringifyPrimitive(k)) + eq;
76+
if (Array.isArray(obj[k])) {
77+
return obj[k].map(function(v) {
78+
return ks + QueryString.escape(stringifyPrimitive(v));
79+
}).join(sep);
80+
} else {
81+
return ks + QueryString.escape(stringifyPrimitive(obj[k]));
82+
}
83+
}).join(sep);
8684

87-
default:
88-
if (!name) return '';
89-
return QueryString.escape(stringifyPrimitive(name)) + eq +
90-
QueryString.escape(stringifyPrimitive(obj));
9185
}
86+
87+
if (!name) return '';
88+
return QueryString.escape(stringifyPrimitive(name)) + eq +
89+
QueryString.escape(stringifyPrimitive(obj));
9290
};
9391

9492
// Parse a key=val string.
9593
QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
9694
sep = sep || '&';
9795
eq = eq || '=';
98-
var obj = {},
99-
maxKeys = 1000;
100-
101-
// Handle maxKeys = 0 case
102-
if (options && typeof options.maxKeys === 'number') {
103-
maxKeys = options.maxKeys;
104-
}
96+
var obj = {};
10597

10698
if (typeof qs !== 'string' || qs.length === 0) {
10799
return obj;
@@ -110,16 +102,29 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
110102
var regexp = /\+/g;
111103
qs = qs.split(sep);
112104

105+
var maxKeys = 1000;
106+
if (options && typeof options.maxKeys === 'number') {
107+
maxKeys = options.maxKeys;
108+
}
109+
110+
var len = qs.length;
113111
// maxKeys <= 0 means that we should not limit keys count
114-
if (maxKeys > 0) {
115-
qs = qs.slice(0, maxKeys);
112+
if (maxKeys > 0 && len > maxKeys) {
113+
len = maxKeys;
116114
}
117115

118-
for (var i = 0, len = qs.length; i < len; ++i) {
116+
for (var i = 0; i < len; ++i) {
119117
var x = qs[i].replace(regexp, '%20'),
120118
idx = x.indexOf(eq),
121-
kstr = x.substring(0, idx),
122-
vstr = x.substring(idx + 1), k, v;
119+
kstr, vstr, k, v;
120+
121+
if (idx >= 0) {
122+
kstr = x.substr(0, idx);
123+
vstr = x.substr(idx + 1);
124+
} else {
125+
kstr = x;
126+
vstr = '';
127+
}
123128

124129
try {
125130
k = decodeURIComponent(kstr);
@@ -131,10 +136,10 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) {
131136

132137
if (!hasOwnProperty(obj, k)) {
133138
obj[k] = v;
134-
} else if (!Array.isArray(obj[k])) {
135-
obj[k] = [obj[k], v];
136-
} else {
139+
} else if (Array.isArray(obj[k])) {
137140
obj[k].push(v);
141+
} else {
142+
obj[k] = [obj[k], v];
138143
}
139144
}
140145

buildin/web_modules/url.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ exports.format = urlFormat;
3232
// compiled once on the first module load.
3333
var protocolPattern = /^([a-z0-9.+-]+:)/i,
3434
portPattern = /:[0-9]*$/,
35+
3536
// RFC 2396: characters reserved for delimiting URLs.
37+
// We actually just auto-escape these.
3638
delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
39+
3740
// RFC 2396: characters not allowed for various reasons.
3841
unwise = ['{', '}', '|', '\\', '^', '~', '`'].concat(delims),
42+
3943
// Allowed by RFCs, but cause of XSS attacks. Always escape these.
40-
autoEscape = ['\''],
44+
autoEscape = ['\''].concat(delims),
4145
// Characters that are never ever allowed in a hostname.
4246
// Note that any invalid chars are also handled, but these
4347
// are the ones that are *expected* to be seen, so we fast-path
@@ -95,13 +99,9 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
9599
var out = {},
96100
rest = url;
97101

98-
// cut off any delimiters.
99-
// This is to support parse stuff like "<http://foo.com>"
100-
for (var i = 0, l = rest.length; i < l; i++) {
101-
if (delims.indexOf(rest.charAt(i)) === -1) break;
102-
}
103-
if (i !== 0) rest = rest.substr(i);
104-
102+
// trim before proceeding.
103+
// This is to support parse stuff like " http://foo.com \n"
104+
rest = rest.trim();
105105

106106
var proto = protocolPattern.exec(rest);
107107
if (proto) {
@@ -271,16 +271,6 @@ function urlParse(url, parseQueryString, slashesDenoteHost) {
271271
}
272272
rest = rest.split(ae).join(esc);
273273
}
274-
275-
// Now make sure that delims never appear in a url.
276-
var chop = rest.length;
277-
for (var i = 0, l = delims.length; i < l; i++) {
278-
var c = rest.indexOf(delims[i]);
279-
if (c !== -1) {
280-
chop = Math.min(c, chop);
281-
}
282-
}
283-
rest = rest.substr(0, chop);
284274
}
285275

286276

0 commit comments

Comments
 (0)