mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
This is a backport of 6c3647c38d from
v0.12 to v0.10.
Console.prototype.timeEnd() returns NaN if the timer label
corresponds to a property on Object.prototype. In v0.12, this was fixed
by using Object.create(null) to construct the _times object
However, the version of V8 in the v0.10 branch makes this fix not work
as expected. In v0.10, this commit changes the _times object into a
array of objects of the form:
{ label: someLabel, time: staringWallClockTime }
someLabel can thus be any string, including any string that represents
any Object.prototype field.
Fixes #9116.
PR: #9215
PR-URL: https://github.com/joyent/node/pull/9215
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
79 lines
2.7 KiB
JavaScript
79 lines
2.7 KiB
JavaScript
// 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 common = require('../common');
|
|
var assert = require('assert');
|
|
|
|
assert.ok(process.stdout.writable);
|
|
assert.ok(process.stderr.writable);
|
|
// Support legacy API
|
|
assert.equal('number', typeof process.stdout.fd);
|
|
assert.equal('number', typeof process.stderr.fd);
|
|
|
|
|
|
var stdout_write = global.process.stdout.write;
|
|
var strings = [];
|
|
global.process.stdout.write = function(string) {
|
|
strings.push(string);
|
|
};
|
|
|
|
console.log('foo');
|
|
console.log('foo', 'bar');
|
|
console.log('%s %s', 'foo', 'bar', 'hop');
|
|
console.log({slashes: '\\\\'});
|
|
|
|
console._stderr = process.stdout;
|
|
console.trace('This is a %j %d', { formatted: 'trace' }, 10, 'foo');
|
|
|
|
assert.throws(function () {
|
|
console.timeEnd('no such label');
|
|
});
|
|
|
|
assert.doesNotThrow(function () {
|
|
console.time('label');
|
|
console.timeEnd('label');
|
|
});
|
|
|
|
console.time('__proto__');
|
|
console.timeEnd('__proto__');
|
|
console.time('constructor');
|
|
console.timeEnd('constructor');
|
|
console.time('hasOwnProperty');
|
|
console.timeEnd('hasOwnProperty');
|
|
|
|
global.process.stdout.write = stdout_write;
|
|
|
|
assert.equal('foo\n', strings.shift());
|
|
assert.equal('foo bar\n', strings.shift());
|
|
assert.equal('foo bar hop\n', strings.shift());
|
|
assert.equal("{ slashes: '\\\\\\\\' }\n", strings.shift());
|
|
assert.equal('Trace: This is a {"formatted":"trace"} 10 foo',
|
|
strings.shift().split('\n').shift());
|
|
|
|
assert.ok(/^label: \d+ms$/.test(strings.shift().trim()));
|
|
assert.ok(/^__proto__: \d+ms$/.test(strings.shift().trim()));
|
|
assert.ok(/^constructor: \d+ms$/.test(strings.shift().trim()));
|
|
assert.ok(/^hasOwnProperty: \d+ms$/.test(strings.shift().trim()));
|
|
assert.equal(strings.length, 0);
|