Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/power-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function powerMonitor()
this.sleepDisplay = function sleepDispay(force)
{
var promise = require('promise');

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦩 🟠 require('promise') hoisted as local var reused across branches without inline pattern violation but note stray global leak

In sleepDisplay and wakeDisplay (both defined as this.sleepDisplay = function sleepDispay(force) {...} and this.wakeDisplay = function wakeDisplay() {...} in powerMonitor), the assignment p = new promise(...) was changed to var p = new promise(...) in both functions, declaring p as a local variable instead of leaking it to the global object in non-strict mode.

🤖 Prompt for AI agents
In modules/power-monitor.js around line 181, review and complete this code-review fix: require('promise') hoisted as local var reused across branches without inline pattern violation but note stray global leak.
What the draft fix changed: In `sleepDisplay` and `wakeDisplay` (both defined as `this.sleepDisplay = function sleepDispay(force) {...}` and `this.wakeDisplay = function wakeDisplay() {...}` in `powerMonitor`), the assignment `p = new promise(...)` was changed to `var p = new promise(...)` in both functions, declaring `p` as a local variable instead of leaking it to the global object in non-strict mode.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟢 95 high — react 👍/👎 to teach the reviewer

p = new promise(function (res, rej) { this._res = res; this._rej = rej; });
var p = new promise(function (res, rej) { this._res = res; this._rej = rej; });

switch (process.platform)
{
Expand Down Expand Up @@ -229,7 +229,7 @@ function powerMonitor()
this.wakeDisplay = function wakeDisplay()
{
var promise = require('promise');
p = new promise(function (res, rej) { this._res = res; this._rej = rej; });
var p = new promise(function (res, rej) { this._res = res; this._rej = rej; });
switch(process.platform)
{
case 'darwin':
Expand Down