| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d8365bc commit a9c5b33
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -131,6 +131,9 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) { | |||
| 131 | 131 | // the prototype so that users extending the Console can override them | |
| 132 | 132 | // from the prototype chain of the subclass. | |
| 133 | 133 | this[key] = this[key].bind(this); | |
| 134 | + ObjectDefineProperty(this[key], 'name', { | ||
| 135 | + value: key | ||
| 136 | + }); | ||
| 134 | 137 | } | |
| 135 | 138 | ||
| 136 | 139 | this[kBindStreamsEager](stdout, stderr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,9 @@ for (const prop of ReflectOwnKeys(Console.prototype)) { | |||
| 36 | 36 | if (prop === 'constructor') { continue; } | |
| 37 | 37 | const desc = ReflectGetOwnPropertyDescriptor(Console.prototype, prop); | |
| 38 | 38 | if (typeof desc.value === 'function') { // fix the receiver | |
| 39 | + const name = desc.value.name; | ||
| 39 | 40 | desc.value = desc.value.bind(globalConsole); | |
| 41 | + ReflectDefineProperty(desc.value, 'name', { value: name }); | ||
| 40 | 42 | } | |
| 41 | 43 | ReflectDefineProperty(globalConsole, prop, desc); | |
| 42 | 44 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ObjectDefineProperty, | ||
| 4 | 5 | ObjectKeys, | |
| 5 | 6 | } = primordials; | |
| 6 | 7 | ||
@@ -42,6 +43,9 @@ function wrapConsole(consoleFromNode, consoleFromVM) { | |||
| 42 | 43 | consoleFromNode[key] = consoleCall.bind(consoleFromNode, | |
| 43 | 44 | consoleFromVM[key], | |
| 44 | 45 | consoleFromNode[key]); | |
| 46 | + ObjectDefineProperty(consoleFromNode[key], 'name', { | ||
| 47 | + value: key | ||
| 48 | + }); | ||
| 45 | 49 | } else { | |
| 46 | 50 | // Add additional console APIs from the inspector | |
| 47 | 51 | consoleFromNode[key] = consoleFromVM[key]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,8 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | require('../common'); | |
| 3 | 3 | ||
| 4 | - // This test ensures that console methods | ||
| 5 | - // cannot be invoked as constructors | ||
| 4 | + // This test ensures that console methods cannot be invoked as constructors and | ||
| 5 | + // that their name is always correct. | ||
| 6 | 6 | ||
| 7 | 7 | const assert = require('assert'); | |
| 8 | 8 | ||
@@ -32,7 +32,30 @@ const methods = [ | |||
| 32 | 32 | 'groupCollapsed', | |
| 33 | 33 | ]; | |
| 34 | 34 | ||
| 35 | + const alternateNames = { | ||
| 36 | + debug: 'log', | ||
| 37 | + info: 'log', | ||
| 38 | + dirxml: 'log', | ||
| 39 | + error: 'warn', | ||
| 40 | + groupCollapsed: 'group' | ||
| 41 | + }; | ||
| 42 | + | ||
| 43 | + function assertEqualName(method) { | ||
| 44 | + try { | ||
| 45 | + assert.strictEqual(console[method].name, method); | ||
| 46 | + } catch { | ||
| 47 | + assert.strictEqual(console[method].name, alternateNames[method]); | ||
| 48 | + } | ||
| 49 | + try { | ||
| 50 | + assert.strictEqual(newInstance[method].name, method); | ||
| 51 | + } catch { | ||
| 52 | + assert.strictEqual(newInstance[method].name, alternateNames[method]); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + | ||
| 35 | 56 | for (const method of methods) { | |
| 57 | + assertEqualName(method); | ||
| 58 | + | ||
| 36 | 59 | assert.throws(() => new console[method](), err); | |
| 37 | 60 | assert.throws(() => new newInstance[method](), err); | |
| 38 | 61 | assert.throws(() => Reflect.construct({}, [], console[method]), err); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -754,6 +754,39 @@ const errorTests = [ | |||
| 754 | 754 | /^Uncaught SyntaxError: / | |
| 755 | 755 | ] | |
| 756 | 756 | }, | |
| 757 | + { | ||
| 758 | + send: 'console', | ||
| 759 | + expect: [ | ||
| 760 | + '{', | ||
| 761 | + ' log: [Function: log],', | ||
| 762 | + ' warn: [Function: warn],', | ||
| 763 | + ' dir: [Function: dir],', | ||
| 764 | + ' time: [Function: time],', | ||
| 765 | + ' timeEnd: [Function: timeEnd],', | ||
| 766 | + ' timeLog: [Function: timeLog],', | ||
| 767 | + ' trace: [Function: trace],', | ||
| 768 | + ' assert: [Function: assert],', | ||
| 769 | + ' clear: [Function: clear],', | ||
| 770 | + ' count: [Function: count],', | ||
| 771 | + ' countReset: [Function: countReset],', | ||
| 772 | + ' group: [Function: group],', | ||
| 773 | + ' groupEnd: [Function: groupEnd],', | ||
| 774 | + ' table: [Function: table],', | ||
| 775 | + / debug: \[Function: (debug|log)],/, | ||
| 776 | + / info: \[Function: (info|log)],/, | ||
| 777 | + / dirxml: \[Function: (dirxml|log)],/, | ||
| 778 | + / error: \[Function: (error|warn)],/, | ||
| 779 | + / groupCollapsed: \[Function: (groupCollapsed|group)],/, | ||
| 780 | + / Console: \[Function: Console],?/, | ||
| 781 | + ...process.features.inspector ? [ | ||
| 782 | + ' profile: [Function: profile],', | ||
| 783 | + ' profileEnd: [Function: profileEnd],', | ||
| 784 | + ' timeStamp: [Function: timeStamp],', | ||
| 785 | + ' context: [Function: context]', | ||
| 786 | + ] : [], | ||
| 787 | + '}', | ||
| 788 | + ] | ||
| 789 | + }, | ||
| 757 | 790 | ]; | |
| 758 | 791 | ||
| 759 | 792 | const tcpTests = [ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments