diff --git a/js/common/bootstrap/module-console.js b/js/common/bootstrap/module-console.js index 8010331d87..755cf013a4 100644 --- a/js/common/bootstrap/module-console.js +++ b/js/common/bootstrap/module-console.js @@ -289,23 +289,15 @@ /// log message. //////////////////////////////////////////////////////////////////////////////// - exports.log = function () { - 'use strict'; - - var msg; - - try { - msg = sprintf.apply(sprintf, arguments); - } - catch (err) { - msg = err + ": " + arguments; - } - - log("info", msg); - }; + exports.log = exports.info; //////////////////////////////////////////////////////////////////////////////// /// @brief time +/// +/// @FUN{console.time(@FA{name})} +/// +/// Creates a new timer under the given name. Call @FN{timeEnd} with the same +/// name to stop the timer and log the time elapsed. //////////////////////////////////////////////////////////////////////////////// exports.time = function (label) { @@ -316,6 +308,10 @@ //////////////////////////////////////////////////////////////////////////////// /// @brief timeEnd +/// +/// @FUN{console.timeEnd(@FA{name})} +/// +/// Stops a timer created by a call to @FN{time} and logs the time elapsed. //////////////////////////////////////////////////////////////////////////////// exports.timeEnd = function(label) { @@ -333,6 +329,23 @@ exports.log('%s: %dms', label, duration); }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief trace +/// +/// @FUN{console.trace()} +/// +/// Logs a static stack trace of JavaScript execution at the point where it is +/// called. +//////////////////////////////////////////////////////////////////////////////// + + exports.trace = function () { + var err = new Error(); + err.name = 'trace'; + err.message = sprintf.apply(sprintf, arguments); + Error.captureStackTrace(err, arguments.callee); + exports.log(err.stack); + }; + //////////////////////////////////////////////////////////////////////////////// /// @brief warn /// diff --git a/lib/V8/v8-utils.cpp b/lib/V8/v8-utils.cpp index 8f198bafee..4e97495243 100644 --- a/lib/V8/v8-utils.cpp +++ b/lib/V8/v8-utils.cpp @@ -696,7 +696,7 @@ static v8::Handle JS_SizeFile (v8::Arguments const& argv) { /// /// @FUN{console.getline()} /// -/// Reads in a line from the console. +/// Reads in a line from the console and returns it as string. //////////////////////////////////////////////////////////////////////////////// static v8::Handle JS_Getline (v8::Arguments const& argv) {