|
1 | | -// Copyright Joyent, Inc. and other Node contributors. |
2 | | -// |
3 | | -// Permission is hereby granted, free of charge, to any person obtaining a |
4 | | -// copy of this software and associated documentation files (the |
5 | | -// "Software"), to deal in the Software without restriction, including |
6 | | -// without limitation the rights to use, copy, modify, merge, publish, |
7 | | -// distribute, sublicense, and/or sell copies of the Software, and to permit |
8 | | -// persons to whom the Software is furnished to do so, subject to the |
9 | | -// following conditions: |
10 | | -// |
11 | | -// The above copyright notice and this permission notice shall be included |
12 | | -// in all copies or substantial portions of the Software. |
13 | | -// |
14 | | -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
15 | | -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
16 | | -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
17 | | -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
18 | | -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
19 | | -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
20 | | -// USE OR OTHER DEALINGS IN THE SOFTWARE. |
21 | | - |
22 | 1 | 'use strict'; |
23 | 2 |
|
| 3 | +// The Console constructor is not actually used to construct the global |
| 4 | +// console. It's exported for backwards compatibility. |
| 5 | + |
24 | 6 | const { trace } = internalBinding('trace_events'); |
25 | 7 | const { |
26 | 8 | isStackOverflowError, |
@@ -72,8 +54,6 @@ const kBindStreamsLazy = Symbol('kBindStreamsLazy'); |
72 | 54 | const kUseStdout = Symbol('kUseStdout'); |
73 | 55 | const kUseStderr = Symbol('kUseStderr'); |
74 | 56 |
|
75 | | -// This constructor is not used to construct the global console. |
76 | | -// It's exported for backwards compatibility. |
77 | 57 | function Console(options /* or: stdout, stderr, ignoreErrors = true */) { |
78 | 58 | // We have to test new.target here to see if this function is called |
79 | 59 | // with new, because we need to define a custom instanceof to accommodate |
@@ -533,42 +513,8 @@ Console.prototype.table = function(tabularData, properties) { |
533 | 513 |
|
534 | 514 | function noop() {} |
535 | 515 |
|
536 | | -// See https://console.spec.whatwg.org/#console-namespace |
537 | | -// > For historical web-compatibility reasons, the namespace object |
538 | | -// > for console must have as its [[Prototype]] an empty object, |
539 | | -// > created as if by ObjectCreate(%ObjectPrototype%), |
540 | | -// > instead of %ObjectPrototype%. |
541 | | - |
542 | | -// Since in Node.js, the Console constructor has been exposed through |
543 | | -// require('console'), we need to keep the Console constructor but |
544 | | -// we cannot actually use `new Console` to construct the global console. |
545 | | -// Therefore, the console.Console.prototype is not |
546 | | -// in the global console prototype chain anymore. |
547 | | - |
548 | | -// TODO(joyeecheung): |
549 | | -// - Move the Console constructor into internal/console.js |
550 | | -// - Move the global console creation code along with the inspector console |
551 | | -// wrapping code in internal/bootstrap/node.js into a separate file. |
552 | | -// - Make this file a simple re-export of those two files. |
553 | | -// This is only here for v11.x conflict resolution. |
554 | | -const globalConsole = Object.create(Console.prototype); |
555 | | - |
556 | | -// Since Console is not on the prototype chain of the global console, |
557 | | -// the symbol properties on Console.prototype have to be looked up from |
558 | | -// the global console itself. In addition, we need to make the global |
559 | | -// console a namespace by binding the console methods directly onto |
560 | | -// the global console with the receiver fixed. |
561 | | -for (const prop of Reflect.ownKeys(Console.prototype)) { |
562 | | - if (prop === 'constructor') { continue; } |
563 | | - const desc = Reflect.getOwnPropertyDescriptor(Console.prototype, prop); |
564 | | - if (typeof desc.value === 'function') { // fix the receiver |
565 | | - desc.value = desc.value.bind(globalConsole); |
566 | | - } |
567 | | - Reflect.defineProperty(globalConsole, prop, desc); |
568 | | -} |
569 | | - |
570 | | -globalConsole[kBindStreamsLazy](process); |
571 | | -globalConsole[kBindProperties](true, 'auto'); |
572 | | - |
573 | | -module.exports = globalConsole; |
574 | | -module.exports.Console = Console; |
| 516 | +module.exports = { |
| 517 | + Console, |
| 518 | + kBindStreamsLazy, |
| 519 | + kBindProperties |
| 520 | +}; |
0 commit comments