fix(adhoc-public-samples-relay-js): 2 review findings in relay.js - #138
fix(adhoc-public-samples-relay-js): 2 review findings in relay.js#138flamingo[bot] wants to merge 1 commit into
Conversation
| 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')) { |
There was a problem hiding this comment.
🦩 🔴 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')) { | ||
| if ((obj.state == 1) && (e.data == 'c')) { | ||
| obj.state = 2; | ||
| if (obj.onStateChanged) { onStateChanged(obj, 2); } |
There was a problem hiding this comment.
🦩 🔴 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
Closes 2 review findings in
public/samples/relay.js.Draft — this is a starting point, not a finished change. The fix required judgment, so read it before trusting it.
public/samples/relay.js:22public/samples/relay.js:24What changed — and what was deliberately left — is explained per finding as inline review comments on the lines each finding touched.
Run: https://product-hub.flamingo.so/admin/code-review
Run id:
bd83e60f-661c-461b-b0a4-217f424f321cMerging this PR is recorded as acceptance of the rule that produced it;
closing it unmerged is recorded as rejection. Both feed rule health, so
closing a wrong suggestion is useful rather than merely tidy.