GeezerVison is showing github.com — lib: enforce use of Promise from primordials · nodejs/node@31227e6
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 clipboardExpand all lines: lib/.eslintrc.yaml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 | message: "Use `const { Number } = primordials;` instead of the global." | 24 | 24 | - name: Object | 25 | 25 | message: "Use `const { Object } = primordials;` instead of the global." | | 26 | + - name: Promise | | 27 | + message: "Use `const { Promise } = primordials;` instead of the global." | 26 | 28 | - name: Reflect | 27 | 29 | message: "Use `const { Reflect } = primordials;` instead of the global." | 28 | 30 | - name: Symbol | |
Collapse file Copy file name to clipboardExpand all lines: lib/child_process.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,7 @@ const { | 27 | 27 | ObjectAssign, | 28 | 28 | ObjectDefineProperty, | 29 | 29 | ObjectPrototypeHasOwnProperty, | | 30 | + Promise, | 30 | 31 | } = primordials; | 31 | 32 |
| 32 | 33 | const { | |
Collapse file Copy file name to clipboardExpand all lines: lib/events.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,6 +29,7 @@ const { | 29 | 29 | ObjectDefineProperty, | 30 | 30 | ObjectGetPrototypeOf, | 31 | 31 | ObjectKeys, | | 32 | + Promise, | 32 | 33 | ReflectApply, | 33 | 34 | ReflectOwnKeys, | 34 | 35 | } = primordials; | |
Collapse file Copy file name to clipboardExpand all lines: lib/fs.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -30,6 +30,7 @@ const { | 30 | 30 | ObjectCreate, | 31 | 31 | ObjectDefineProperties, | 32 | 32 | ObjectDefineProperty, | | 33 | + Promise, | 33 | 34 | } = primordials; | 34 | 35 |
| 35 | 36 | const { fs: constants } = internalBinding('constants'); | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/dns/promises.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | const { | 4 | 4 | ObjectCreate, | 5 | 5 | ObjectDefineProperty, | | 6 | + Promise, | 6 | 7 | } = primordials; | 7 | 8 |
| 8 | 9 | const { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/fs/rimraf.js +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | // - Bring your own custom fs module is not currently supported. | 6 | 6 | // - Some basic code cleanup. | 7 | 7 | 'use strict'; | | 8 | + | | 9 | +const { | | 10 | + Promise, | | 11 | +} = primordials; | | 12 | + | 8 | 13 | const { | 9 | 14 | chmod, | 10 | 15 | chmodSync, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/http2/core.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,7 @@ const { | 10 | 10 | ObjectCreate, | 11 | 11 | ObjectDefineProperty, | 12 | 12 | ObjectPrototypeHasOwnProperty, | | 13 | + Promise, | 13 | 14 | ReflectGetPrototypeOf, | 14 | 15 | Symbol, | 15 | 16 | } = primordials; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/modules/esm/module_job.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const { | 4 | 4 | ObjectSetPrototypeOf, | | 5 | + PromiseAll, | 5 | 6 | SafeSet, | 6 | 7 | SafePromise, | 7 | 8 | } = primordials; | @@ -79,7 +80,7 @@ class ModuleJob { | 79 | 80 | } | 80 | 81 | jobsInGraph.add(moduleJob); | 81 | 82 | const dependencyJobs = await moduleJob.linked; | 82 | | - return Promise.all(dependencyJobs.map(addJobsToDependencyGraph)); | | 83 | + return PromiseAll(dependencyJobs.map(addJobsToDependencyGraph)); | 83 | 84 | }; | 84 | 85 | await addJobsToDependencyGraph(this); | 85 | 86 | try { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/per_context/primordials.js +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,6 +47,22 @@ function copyPropsRenamed(src, dest, prefix) { | 47 | 47 | } | 48 | 48 | } | 49 | 49 |
| | 50 | +function copyPropsRenamedBound(src, dest, prefix) { | | 51 | + for (const key of Reflect.ownKeys(src)) { | | 52 | + if (typeof key === 'string') { | | 53 | + const desc = Reflect.getOwnPropertyDescriptor(src, key); | | 54 | + if (typeof desc.value === 'function') { | | 55 | + desc.value = desc.value.bind(src); | | 56 | + } | | 57 | + Reflect.defineProperty( | | 58 | + dest, | | 59 | + `${prefix}${key[0].toUpperCase()}${key.slice(1)}`, | | 60 | + desc | | 61 | + ); | | 62 | + } | | 63 | + } | | 64 | +} | | 65 | + | 50 | 66 | function copyPrototype(src, dest, prefix) { | 51 | 67 | for (const key of Reflect.ownKeys(src)) { | 52 | 68 | if (typeof key === 'string') { | @@ -135,5 +151,17 @@ primordials.SafePromise = makeSafe( | 135 | 151 | copyPrototype(original.prototype, primordials, `${name}Prototype`); | 136 | 152 | }); | 137 | 153 |
| | 154 | +// Create copies of intrinsic objects that require a valid `this` to call | | 155 | +// static methods. | | 156 | +// Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all | | 157 | +[ | | 158 | + 'Promise', | | 159 | +].forEach((name) => { | | 160 | + const original = global[name]; | | 161 | + primordials[name] = original; | | 162 | + copyPropsRenamedBound(original, primordials, name); | | 163 | + copyPrototype(original.prototype, primordials, `${name}Prototype`); | | 164 | +}); | | 165 | + | 138 | 166 | Object.setPrototypeOf(primordials, null); | 139 | 167 | Object.freeze(primordials); |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/process/execution.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const { | 4 | 4 | JSONStringify, | | 5 | + PromiseResolve, | 5 | 6 | } = primordials; | 6 | 7 |
| 7 | 8 | const path = require('path'); | @@ -41,7 +42,7 @@ function evalModule(source, print) { | 41 | 42 | const { log, error } = require('internal/console/global'); | 42 | 43 | const { decorateErrorStack } = require('internal/util'); | 43 | 44 | const asyncESM = require('internal/process/esm_loader'); | 44 | | - Promise.resolve(asyncESM.ESMLoader).then(async (loader) => { | | 45 | + PromiseResolve(asyncESM.ESMLoader).then(async (loader) => { | 45 | 46 | const { result } = await loader.eval(source); | 46 | 47 | if (print) { | 47 | 48 | log(result); | |
|