←back to thread

517 points bkolobara | 5 comments | | HN request time: 0s | source
Show context
jmull ◴[] No.45043565[source]
The javascript browser bug has nothing to do with the language.

It’s just a logic bug.

E.g., the code doesn’t match their own English description of the logic: “If yes, redirect to the specific page. If not, go to the dashboard or onboarding page.”

The code is missing the “if not” (probably best expressed using an “else” clause following the if block).

replies(1): >>45044090 #
1. notfed ◴[] No.45044090[source]
I wouldn't say nothing. I mean, we're essentially talking about a global variable that's specified into the language.
replies(2): >>45044530 #>>45045058 #
2. pwdisswordfishz ◴[] No.45044530[source]
Where exactly?

https://tc39.es/ecma262/multipage/

3. jmull ◴[] No.45045058[source]
window and window.location aren't part of javascript. They are part of the javascript api that standard browsers provide.

It's fair to point out that browser api is confusing. You might not think of setting a property as kicking off an asynchronous operation, especially if it seems to has instantaneous effect at first.

But the basic control flow logic of that code is wrong. Confusion about whether a side-effect from an api call might bail you out from your error is beside the point.

replies(1): >>45046762 #
4. byw ◴[] No.45046762[source]
I'm curious if Rust (WASM through JS interop?) also has access to `window.location`, and if the API has some more safety mechanisms.
replies(1): >>45046852 #
5. steveklabnik ◴[] No.45046852{3}[source]
web_sys lets you call window.location, which returns a Location, which has href and set_href methods. They do the same thing the native APIs do, as that is their purpose.