| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3ae04c9 commit 30060e1
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -141,6 +141,12 @@ function pendingDeprecate(fn, msg, code) { | |||
| 141 | 141 | emitDeprecationWarning(); | |
| 142 | 142 | return ReflectApply(fn, this, args); | |
| 143 | 143 | } | |
| 144 | + | ||
| 145 | + ObjectDefineProperty(deprecated, 'length', { | ||
| 146 | + __proto__: null, | ||
| 147 | + ...ObjectGetOwnPropertyDescriptor(fn, 'length'), | ||
| 148 | + }); | ||
| 149 | + | ||
| 144 | 150 | return deprecated; | |
| 145 | 151 | } | |
| 146 | 152 | ||
@@ -179,6 +185,11 @@ function deprecate(fn, msg, code, useEmitSync) { | |||
| 179 | 185 | deprecated.prototype = fn.prototype; | |
| 180 | 186 | } | |
| 181 | 187 | ||
| 188 | + ObjectDefineProperty(deprecated, 'length', { | ||
| 189 | + __proto__: null, | ||
| 190 | + ...ObjectGetOwnPropertyDescriptor(fn, 'length'), | ||
| 191 | + }); | ||
| 192 | + | ||
| 182 | 193 | return deprecated; | |
| 183 | 194 | } | |
| 184 | 195 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 1 | 2 | 'use strict'; | |
| 2 | 3 | ||
| 3 | 4 | require('../common'); | |
@@ -6,9 +7,27 @@ require('../common'); | |||
| 6 | 7 | ||
| 7 | 8 | const assert = require('assert'); | |
| 8 | 9 | const util = require('util'); | |
| 10 | + const internalUtil = require('internal/util'); | ||
| 9 | 11 | ||
| 10 | 12 | const expectedWarnings = new Map(); | |
| 11 | 13 | ||
| 14 | + // Deprecated function length is preserved | ||
| 15 | + for (const fn of [ | ||
| 16 | + function() {}, | ||
| 17 | + function(a) {}, | ||
| 18 | + function(a, b, c) {}, | ||
| 19 | + function(...args) {}, | ||
| 20 | + function(a, b, c, ...args) {}, | ||
| 21 | + () => {}, | ||
| 22 | + (a) => {}, | ||
| 23 | + (a, b, c) => {}, | ||
| 24 | + (...args) => {}, | ||
| 25 | + (a, b, c, ...args) => {}, | ||
| 26 | + ]) { | ||
| 27 | + assert.strictEqual(util.deprecate(fn).length, fn.length); | ||
| 28 | + assert.strictEqual(internalUtil.pendingDeprecate(fn).length, fn.length); | ||
| 29 | + } | ||
| 30 | + | ||
| 12 | 31 | // Emits deprecation only once if same function is called. | |
| 13 | 32 | { | |
| 14 | 33 | const msg = 'fhqwhgads'; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments