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
8 changes: 4 additions & 4 deletions public/samples/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var createMeshConnection = function (connectionId) {
obj.websocket.onopen = function (e) { console.log('WebSocket Connected', e); };
obj.websocket.onmessage = function (e) {
console.log('WebSocket Message', e);
if ((obj.state = 1) && (e.data == 'c')) {

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.

🦩 πŸ”΄ relay.js: assignment used instead of equality check in onmessage handler, causing state check to always be truthy

Changed obj.state = 1 to obj.state == 1 on line 22 inside obj.websocket.onmessage in the obj.connect function. This fixes the assignment-used-as-equality-check bug so the condition now correctly tests whether the state is 1 rather than unconditionally assigning 1 and evaluating as truthy.

πŸ€– Prompt for AI agents
In public/samples/relay.js around line 22, review and complete this code-review fix: relay.js: assignment used instead of equality check in onmessage handler, causing state check to always be truthy.
What the draft fix changed: Changed `obj.state = 1` to `obj.state == 1` on line 22 inside `obj.websocket.onmessage` in the `obj.connect` function. This fixes the assignment-used-as-equality-check bug so the condition now correctly tests whether the state is 1 rather than unconditionally assigning 1 and evaluating as truthy.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 99 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer

if ((obj.state == 1) && (e.data == 'c')) {
obj.state = 2;
if (obj.onStateChanged) { onStateChanged(obj, 2); }

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.

🦩 πŸ”΄ relay.js: onStateChanged called as bare function instead of through obj reference, causing ReferenceError at runtime

Changed onStateChanged(obj, 2) to obj.onStateChanged(obj, 2) on line 24, and onStateChanged(obj, 0) to obj.onStateChanged(obj, 0) on line 33, both inside obj.connect. These were bare function calls that would throw a ReferenceError at runtime; they now correctly call through the obj reference. Note: the third call on line 38 (if (obj.onStateChanged) { onStateChanged(obj, 1); }) has the same pattern but was not listed in the findings, so it was left unchanged per the hard rules.

πŸ€– Prompt for AI agents
In public/samples/relay.js around line 24, review and complete this code-review fix: relay.js: onStateChanged called as bare function instead of through obj reference, causing ReferenceError at runtime.
What the draft fix changed: Changed `onStateChanged(obj, 2)` to `obj.onStateChanged(obj, 2)` on line 24, and `onStateChanged(obj, 0)` to `obj.onStateChanged(obj, 0)` on line 33, both inside `obj.connect`. These were bare function calls that would throw a ReferenceError at runtime; they now correctly call through the `obj` reference. Note: the third call on line 38 (`if (obj.onStateChanged) { onStateChanged(obj, 1); }`) has the same pattern but was not listed in the findings, so it was left unchanged per the hard rules.
Verify the change is correct and complete; do not refactor unrelated code.

fix confidence: 🟒 98 high β€” react πŸ‘/πŸ‘Ž to teach the reviewer

if (obj.onStateChanged) { obj.onStateChanged(obj, 2); }
console.log('WebSocket Peer Connection', e);
obj.send('bob');
} else {
Expand All @@ -31,7 +31,7 @@ var createMeshConnection = function (connectionId) {
obj.websocket.onclose = function (e) {
console.log('WebSocket Closed', e);
obj.state = 0;
if (obj.onStateChanged) { onStateChanged(obj, 0); }
if (obj.onStateChanged) { obj.onStateChanged(obj, 0); }
};
obj.websocket.onerror = function (e) { console.log('WebSocket Error', e); };
obj.state = 1;
Expand All @@ -45,4 +45,4 @@ var createMeshConnection = function (connectionId) {
};

return obj;
}
}