GeezerVison is showing github.com — console: split console into global.js and constructor.js · nodejs/node@b549058
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +'use strict'; | | 23 | + | | 24 | +module.exports = require('internal/console/global'); |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/console/constructor.js +8-62Lines changed: 8 additions & 62 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 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 | +}; |
Collapse file Copy file name to clipboard +45Lines changed: 45 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | + | | 3 | +// See https://console.spec.whatwg.org/#console-namespace | | 4 | +// > For historical web-compatibility reasons, the namespace object | | 5 | +// > for console must have as its [[Prototype]] an empty object, | | 6 | +// > created as if by ObjectCreate(%ObjectPrototype%), | | 7 | +// > instead of %ObjectPrototype%. | | 8 | + | | 9 | +// Since in Node.js, the Console constructor has been exposed through | | 10 | +// require('console'), we need to keep the Console constructor but | | 11 | +// we cannot actually use `new Console` to construct the global console. | | 12 | +// Therefore, the console.Console.prototype is not | | 13 | +// in the global console prototype chain anymore. | | 14 | + | | 15 | +const { | | 16 | + Console, | | 17 | + kBindStreamsLazy, | | 18 | + kBindProperties | | 19 | +} = require('internal/console/constructor'); | | 20 | + | | 21 | +// This is only here for v11.x conflict resolution. | | 22 | +const globalConsole = Object.create(Console.prototype); | | 23 | + | | 24 | +// Since Console is not on the prototype chain of the global console, | | 25 | +// the symbol properties on Console.prototype have to be looked up from | | 26 | +// the global console itself. In addition, we need to make the global | | 27 | +// console a namespace by binding the console methods directly onto | | 28 | +// the global console with the receiver fixed. | | 29 | +for (const prop of Reflect.ownKeys(Console.prototype)) { | | 30 | + if (prop === 'constructor') { continue; } | | 31 | + const desc = Reflect.getOwnPropertyDescriptor(Console.prototype, prop); | | 32 | + if (typeof desc.value === 'function') { // fix the receiver | | 33 | + desc.value = desc.value.bind(globalConsole); | | 34 | + } | | 35 | + Reflect.defineProperty(globalConsole, prop, desc); | | 36 | +} | | 37 | + | | 38 | +globalConsole[kBindStreamsLazy](process); | | 39 | +globalConsole[kBindProperties](true, 'auto'); | | 40 | + | | 41 | +// This is a legacy feature - the Console constructor is exposed on | | 42 | +// the global console instance. | | 43 | +globalConsole.Console = Console; | | 44 | + | | 45 | +module.exports = globalConsole; |
Collapse file Copy file name to clipboardExpand all lines: node.gyp +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 96 | 96 | 'lib/internal/cluster/shared_handle.js', | 97 | 97 | 'lib/internal/cluster/utils.js', | 98 | 98 | 'lib/internal/cluster/worker.js', | | 99 | + 'lib/internal/console/constructor.js', | | 100 | + 'lib/internal/console/global.js', | 99 | 101 | 'lib/internal/crypto/certificate.js', | 100 | 102 | 'lib/internal/crypto/cipher.js', | 101 | 103 | 'lib/internal/crypto/diffiehellman.js', | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-bootstrap-modules.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,7 +9,7 @@ const common = require('../common'); | 9 | 9 | const assert = require('assert'); | 10 | 10 |
| 11 | 11 | const isMainThread = common.isMainThread; | 12 | | -const kMaxModuleCount = isMainThread ? 57 : 78; | | 12 | +const kMaxModuleCount = isMainThread ? 59 : 80; | 13 | 13 |
| 14 | 14 | assert(list.length <= kMaxModuleCount, | 15 | 15 | `Total length: ${list.length}\n` + list.join('\n') | |
|