| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ | |||
| 6 | 6 | const { | |
| 7 | 7 | ArrayFrom, | |
| 8 | 8 | ArrayIsArray, | |
| 9 | + ArrayPrototypeForEach, | ||
| 9 | 10 | ArrayPrototypePush, | |
| 10 | 11 | ArrayPrototypeUnshift, | |
| 11 | 12 | Boolean, | |
@@ -19,7 +20,10 @@ const { | |||
| 19 | 20 | ObjectKeys, | |
| 20 | 21 | ObjectPrototypeHasOwnProperty, | |
| 21 | 22 | ObjectValues, | |
| 23 | + ReflectApply, | ||
| 24 | + ReflectConstruct, | ||
| 22 | 25 | ReflectOwnKeys, | |
| 26 | + SafeArrayIterator, | ||
| 23 | 27 | SafeMap, | |
| 24 | 28 | SafeWeakMap, | |
| 25 | 29 | StringPrototypeIncludes, | |
@@ -97,7 +101,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) { | |||
| 97 | 101 | // with new, because we need to define a custom instanceof to accommodate | |
| 98 | 102 | // the global console. | |
| 99 | 103 | if (!new.target) { | |
| 100 | - return new Console(...arguments); | ||
| 104 | + return ReflectConstruct(Console, arguments); | ||
| 101 | 105 | } | |
| 102 | 106 | ||
| 103 | 107 | if (!options || typeof options.write === 'function') { | |
@@ -147,16 +151,15 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) { | |||
| 147 | 151 | } | |
| 148 | 152 | ||
| 149 | 153 | // Bind the prototype functions to this Console instance | |
| 150 | - const keys = ObjectKeys(Console.prototype); | ||
| 151 | - for (const key of keys) { | ||
| 154 | + ArrayPrototypeForEach(ObjectKeys(Console.prototype), (key) => { | ||
| 152 | 155 | // We have to bind the methods grabbed from the instance instead of from | |
| 153 | 156 | // the prototype so that users extending the Console can override them | |
| 154 | 157 | // from the prototype chain of the subclass. | |
| 155 | 158 | this[key] = FunctionPrototypeBind(this[key], this); | |
| 156 | 159 | ObjectDefineProperty(this[key], 'name', { | |
| 157 | 160 | value: key | |
| 158 | 161 | }); | |
| 159 | - } | ||
| 162 | + }); | ||
| 160 | 163 | ||
| 161 | 164 | this[kBindStreamsEager](stdout, stderr); | |
| 162 | 165 | this[kBindProperties](ignoreErrors, colorMode, groupIndentation); | |
@@ -320,14 +323,16 @@ ObjectDefineProperties(Console.prototype, { | |||
| 320 | 323 | ...consolePropAttributes, | |
| 321 | 324 | value: function(args) { | |
| 322 | 325 | const opts = this[kGetInspectOptions](this._stdout); | |
| 323 | - return formatWithOptions(opts, ...args); | ||
| 326 | + ArrayPrototypeUnshift(args, opts); | ||
| 327 | + return ReflectApply(formatWithOptions, null, args); | ||
| 324 | 328 | } | |
| 325 | 329 | }, | |
| 326 | 330 | [kFormatForStderr]: { | |
| 327 | 331 | ...consolePropAttributes, | |
| 328 | 332 | value: function(args) { | |
| 329 | 333 | const opts = this[kGetInspectOptions](this._stderr); | |
| 330 | - return formatWithOptions(opts, ...args); | ||
| 334 | + ArrayPrototypeUnshift(args, opts); | ||
| 335 | + return ReflectApply(formatWithOptions, null, args); | ||
| 331 | 336 | } | |
| 332 | 337 | }, | |
| 333 | 338 | }); | |
@@ -412,7 +417,8 @@ const consoleMethods = { | |||
| 412 | 417 | assert(expression, ...args) { | |
| 413 | 418 | if (!expression) { | |
| 414 | 419 | args[0] = `Assertion failed${args.length === 0 ? '' : `: ${args[0]}`}`; | |
| 415 | - this.warn(...args); // The arguments will be formatted in warn() again | ||
| 420 | + // The arguments will be formatted in warn() again | ||
| 421 | + ReflectApply(this.warn, this, args); | ||
| 416 | 422 | } | |
| 417 | 423 | }, | |
| 418 | 424 | ||
@@ -458,7 +464,7 @@ const consoleMethods = { | |||
| 458 | 464 | ||
| 459 | 465 | group(...data) { | |
| 460 | 466 | if (data.length > 0) { | |
| 461 | - this.log(...data); | ||
| 467 | + ReflectApply(this.log, this, data); | ||
| 462 | 468 | } | |
| 463 | 469 | this[kGroupIndent] += | |
| 464 | 470 | StringPrototypeRepeat(' ', this[kGroupIndentationWidth]); | |
@@ -603,7 +609,7 @@ function timeLogImpl(self, name, label, data) { | |||
| 603 | 609 | if (data === undefined) { | |
| 604 | 610 | self.log('%s: %s', label, formatted); | |
| 605 | 611 | } else { | |
| 606 | - self.log('%s: %s', label, formatted, ...data); | ||
| 612 | + self.log('%s: %s', label, formatted, ...new SafeArrayIterator(data)); | ||
| 607 | 613 | } | |
| 608 | 614 | return true; | |
| 609 | 615 | } | |
@@ -630,10 +636,10 @@ function formatTime(ms) { | |||
| 630 | 636 | } | |
| 631 | 637 | ||
| 632 | 638 | if (hours !== 0 || minutes !== 0) { | |
| 633 | - [seconds, ms] = StringPrototypeSplit( | ||
| 639 | + ({ 0: seconds, 1: ms } = StringPrototypeSplit( | ||
| 634 | 640 | NumberPrototypeToFixed(seconds, 3), | |
| 635 | 641 | '.' | |
| 636 | - ); | ||
| 642 | + )); | ||
| 637 | 643 | const res = hours !== 0 ? `${hours}:${pad(minutes)}` : minutes; | |
| 638 | 644 | return `${res}:${pad(seconds)}.${ms} (${hours !== 0 ? 'h:m' : ''}m:ss.mmm)`; | |
| 639 | 645 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments