Commit 73c3a3d
lib: make the global console [[Prototype]] an empty object
From the WHATWG console spec:
> For historical web-compatibility reasons, the namespace object for
> console must have as its [[Prototype]] an empty object, created as
> if by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%.
Since in Node.js, the Console constructor has been exposed through
require('console'), we need to keep the Console constructor but
we cannot actually use `new Console` to construct the global console.
This patch changes the prototype chain of the global console object,
so the console.Console.prototype is not in the global console prototype
chain anymore.
```
const proto = Object.getPrototypeOf(global.console);
// Before this patch
proto.constructor === global.console.Console
// After this patch
proto.constructor === Object
```
But, we still maintain that
```
global.console instanceof global.console.Console
```
through a custom Symbol.hasInstance function of Console that tests
for a special symbol kIsConsole for backwards compatibility.
This fixes a case in the console Web Platform Test that we commented
out.
PR-URL: #23509
Refs: whatwg/console#3
Refs: https://console.spec.whatwg.org/#console-namespace
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: John-David Dalton <john.david.dalton@gmail.com>1 parent 453bd18 commit 73c3a3dCopy full SHA for 73c3a3d
File tree
Expand file treeCollapse file tree
2 files changed
+98
-37
lines changedOpen diff view settings
Filter options
- lib
- test/parallel
Expand file treeCollapse file tree
2 files changed
+98
-37
lines changedOpen diff view settings
Collapse file
+50-6Lines changed: 50 additions & 6 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
60 | 60 | |
61 | 61 | |
62 | 62 | |
63 | | - |
64 | 63 | |
65 | 64 | |
66 | 65 | |
67 | 66 | |
| 67 | + |
68 | 68 | |
69 | 69 | |
70 | | - |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
71 | 74 | |
72 | 75 | |
73 | 76 | |
| 77 | + |
74 | 78 | |
75 | 79 | |
76 | 80 | |
| ||
128 | 132 | |
129 | 133 | |
130 | 134 | |
131 | | - |
| 135 | + |
132 | 136 | |
133 | 137 | |
134 | 138 | |
| ||
470 | 474 | |
471 | 475 | |
472 | 476 | |
473 | | - |
| 477 | + |
| 478 | + |
| 479 | + |
| 480 | + |
| 481 | + |
| 482 | + |
| 483 | + |
| 484 | + |
| 485 | + |
| 486 | + |
| 487 | + |
| 488 | + |
| 489 | + |
| 490 | + |
| 491 | + |
474 | 492 | |
475 | 493 | |
476 | 494 | |
477 | | - |
478 | 495 | |
479 | | - |
| 496 | + |
| 497 | + |
| 498 | + |
| 499 | + |
| 500 | + |
| 501 | + |
| 502 | + |
| 503 | + |
| 504 | + |
| 505 | + |
| 506 | + |
| 507 | + |
| 508 | + |
| 509 | + |
| 510 | + |
| 511 | + |
| 512 | + |
| 513 | + |
| 514 | + |
| 515 | + |
| 516 | + |
| 517 | + |
| 518 | + |
| 519 | + |
| 520 | + |
| 521 | + |
| 522 | + |
| 523 | + |
Collapse file
test/parallel/test-console-instance.js
Copy file name to clipboardExpand all lines: test/parallel/test-console-instance.js+48-31Lines changed: 48 additions & 31 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
23 | 23 | |
24 | 24 | |
25 | 25 | |
26 | | - |
| 26 | + |
| 27 | + |
27 | 28 | |
28 | 29 | |
29 | 30 | |
| ||
35 | 36 | |
36 | 37 | |
37 | 38 | |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
38 | 44 | |
39 | 45 | |
40 | 46 | |
| ||
62 | 68 | |
63 | 69 | |
64 | 70 | |
65 | | - |
| 71 | + |
| 72 | + |
| 73 | + |
66 | 74 | |
67 | | - |
68 | | - |
69 | | - |
| 75 | + |
| 76 | + |
| 77 | + |
70 | 78 | |
71 | | - |
72 | | - |
| 79 | + |
| 80 | + |
73 | 81 | |
74 | | - |
75 | | - |
76 | | - |
| 82 | + |
| 83 | + |
| 84 | + |
77 | 85 | |
78 | | - |
| 86 | + |
79 | 87 | |
80 | | - |
81 | | - |
82 | | - |
83 | | - |
84 | | - |
85 | | - |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
86 | 94 | |
87 | | - |
| 95 | + |
| 96 | + |
88 | 97 | |
89 | | - |
90 | | - |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
91 | 103 | |
92 | | - |
93 | | - |
94 | | - |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
95 | 112 | |
96 | | - |
97 | | - |
98 | 113 | |
99 | 114 | |
100 | | - |
| 115 | + |
| 116 | + |
101 | 117 | |
102 | | - |
103 | | - |
| 118 | + |
| 119 | + |
104 | 120 | |
105 | | - |
106 | | - |
107 | | - |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
0 commit comments