| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0f46c1c commit 6133a82
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,8 +94,17 @@ function debuglog(set, cb) { | |||
| 94 | 94 | // Only invokes debuglogImpl() when the debug function is | |
| 95 | 95 | // called for the first time. | |
| 96 | 96 | debug = debuglogImpl(enabled, set); | |
| 97 | - if (typeof cb === 'function') | ||
| 97 | + if (typeof cb === 'function') { | ||
| 98 | + ObjectDefineProperty(debug, 'enabled', { | ||
| 99 | + __proto__: null, | ||
| 100 | + get() { | ||
| 101 | + return enabled; | ||
| 102 | + }, | ||
| 103 | + configurable: true, | ||
| 104 | + enumerable: true, | ||
| 105 | + }); | ||
| 98 | 106 | cb(debug); | |
| 107 | + } | ||
| 99 | 108 | switch (args.length) { | |
| 100 | 109 | case 1: return debug(args[0]); | |
| 101 | 110 | case 2: return debug(args[0], args[1]); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,7 +57,7 @@ function parent() { | |||
| 57 | 57 | ||
| 58 | 58 | function test(environ, shouldWrite, section, forceColors = false) { | |
| 59 | 59 | let expectErr = ''; | |
| 60 | - const expectOut = shouldWrite ? 'enabled\n' : 'disabled\n'; | ||
| 60 | + const expectOut = shouldWrite ? 'outer enabled\ninner enabled\n' : 'outer disabled\ninner disabled\n'; | ||
| 61 | 61 | ||
| 62 | 62 | const spawn = require('child_process').spawn; | |
| 63 | 63 | const child = spawn(process.execPath, [__filename, 'child', section], { | |
@@ -117,11 +117,18 @@ function child(section) { | |||
| 117 | 117 | Object.defineProperty(process.stderr, 'hasColors', { | |
| 118 | 118 | value: tty.WriteStream.prototype.hasColors | |
| 119 | 119 | }); | |
| 120 | + | ||
| 121 | + let innerDebug = null; | ||
| 120 | 122 | // eslint-disable-next-line no-restricted-syntax | |
| 121 | 123 | const debug = util.debuglog(section, common.mustCall((cb) => { | |
| 122 | 124 | assert.strictEqual(typeof cb, 'function'); | |
| 125 | + innerDebug = cb; | ||
| 123 | 126 | })); | |
| 124 | 127 | debug('this', { is: 'a' }, /debugging/); | |
| 125 | 128 | debug('num=%d str=%s obj=%j', 1, 'a', { foo: 'bar' }); | |
| 126 | - console.log(debug.enabled ? 'enabled' : 'disabled'); | ||
| 129 | + console.log(debug.enabled ? 'outer enabled' : 'outer disabled'); | ||
| 130 | + console.log(innerDebug.enabled ? 'inner enabled' : 'inner disabled'); | ||
| 131 | + | ||
| 132 | + assert.strictEqual(typeof Object.getOwnPropertyDescriptor(debug, 'enabled').get, 'function'); | ||
| 133 | + assert.strictEqual(typeof Object.getOwnPropertyDescriptor(innerDebug, 'enabled').get, 'function'); | ||
| 127 | 134 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments