From c70b9ddb6dc232e22a49ddc757865bd3bc9c46a7 Mon Sep 17 00:00:00 2001
From: "Serge S. Gulin" <gulin.serge@gmail.com>
Date: Sat, 23 Mar 2024 16:27:40 +0300
Subject: [PATCH] JS: fix typos and namings (fixes #24602)

You may noted that I've also changed term of

```
, global "h$vt_double" ||= toJExpr IntV
```

See "IntV"

and

```
  WaitReadOp  -> \[] [fd] -> pure $ PRPrimCall $ returnS (app
"h$waidRead" [fd])
```

See "h$waidRead"
---
 compiler/GHC/StgToJS/Linker/Utils.hs | 2 +-
 compiler/GHC/StgToJS/Prim.hs         | 2 +-
 compiler/GHC/StgToJS/Rts/Rts.hs      | 3 ++-
 rts/js/gc.js                         | 5 +++--
 rts/js/mem.js                        | 3 ++-
 rts/js/string.js                     | 6 +++---
 6 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/compiler/GHC/StgToJS/Linker/Utils.hs b/compiler/GHC/StgToJS/Linker/Utils.hs
index de66e96be4ce..b5b28a77ca81 100644
--- a/compiler/GHC/StgToJS/Linker/Utils.hs
+++ b/compiler/GHC/StgToJS/Linker/Utils.hs
@@ -140,7 +140,7 @@ genCommonCppDefs profiling = mconcat
 
   -- Put Addr# in ByteArray# or at Addr# (same thing)
   , "#define PUT_ADDR(a,o,va,vo) if (!(a).arr) (a).arr = []; (a).arr[o] = va; (a).dv.setInt32(o,vo,true);\n"
-  , "#define GET_ADDR(a,o,ra,ro) var ra = (((a).arr && (a).arr[o]) ? (a).arr[o] : null_); var ro = (a).dv.getInt32(o,true);\n"
+  , "#define GET_ADDR(a,o,ra,ro) var ra = (((a).arr && (a).arr[o]) ? (a).arr[o] : null); var ro = (a).dv.getInt32(o,true);\n"
 
   -- Data.Maybe.Maybe
   , "#define HS_NOTHING h$ghczminternalZCGHCziInternalziMaybeziNothing\n"
diff --git a/compiler/GHC/StgToJS/Prim.hs b/compiler/GHC/StgToJS/Prim.hs
index 54be388b4d24..60c52d5662ff 100644
--- a/compiler/GHC/StgToJS/Prim.hs
+++ b/compiler/GHC/StgToJS/Prim.hs
@@ -940,7 +940,7 @@ genPrim prof bound ty op = case op of
 ------------------------------- Delay/Wait Ops ---------------------------------
 
   DelayOp     -> \[] [t]  -> pure $ PRPrimCall $ returnS (app "h$delayThread" [t])
-  WaitReadOp  -> \[] [fd] -> pure $ PRPrimCall $ returnS (app "h$waidRead" [fd])
+  WaitReadOp  -> \[] [fd] -> pure $ PRPrimCall $ returnS (app "h$waitRead" [fd])
   WaitWriteOp -> \[] [fd] -> pure $ PRPrimCall $ returnS (app "h$waitWrite" [fd])
 
 ------------------------------- Concurrency Primitives -------------------------
diff --git a/compiler/GHC/StgToJS/Rts/Rts.hs b/compiler/GHC/StgToJS/Rts/Rts.hs
index 2297ec60bea7..4f5e5e5f8545 100644
--- a/compiler/GHC/StgToJS/Rts/Rts.hs
+++ b/compiler/GHC/StgToJS/Rts/Rts.hs
@@ -371,7 +371,8 @@ rts_gen s = do
               , global "h$ct_stackframe" ||= toJExpr StackFrame
               , global "h$vt_ptr"    ||= toJExpr PtrV
               , global "h$vt_void"   ||= toJExpr VoidV
-              , global "h$vt_double" ||= toJExpr IntV
+              , global "h$vt_int"    ||= toJExpr IntV
+              , global "h$vt_double" ||= toJExpr DoubleV
               , global "h$vt_long"   ||= toJExpr LongV
               , global "h$vt_addr"   ||= toJExpr AddrV
               , global "h$vt_obj"    ||= toJExpr ObjV
diff --git a/rts/js/gc.js b/rts/js/gc.js
index eacb58c7990b..a06ca4511510 100644
--- a/rts/js/gc.js
+++ b/rts/js/gc.js
@@ -76,7 +76,7 @@ var h$retainCAFs = false;
 // var h$CAFs = [];
 // var h$CAFsReset = [];
 
-// 
+//
 var h$extensibleRetentionRoots     = [];
 var h$extensibleRetentionCallbacks = [];
 
@@ -206,7 +206,7 @@ function h$gc(t) {
 	h$markThread(nt);
 	h$resetThread(nt);
     }
-    
+
     // some blocked threads are always considered reachable, mark them
     //   - delayed threads
     //   - threads blocked on async FFI
@@ -531,6 +531,7 @@ function h$follow(obj, sp) {
                     extensibleMatched = true;
 #endif
                     if(x !== true) {
+                      var j;
                       for(j=x.length-1;j>=0;j--) {
 		          ADDW(x[j]);
 		      }
diff --git a/rts/js/mem.js b/rts/js/mem.js
index 3217abfe41c2..3baf27ef759c 100644
--- a/rts/js/mem.js
+++ b/rts/js/mem.js
@@ -1546,7 +1546,8 @@ function h$initHeapBufferLen(buf_d, buf_o, len) {
 // Allocate and copy a JS buffer on the heap
 function h$initHeapBuffer(str_d, str_o) {
   if(str_d === null) return null;
-  return ptr = h$initHeapBufferLen(str_d, str_o, str_d.len);
+  var ptr = h$initHeapBufferLen(str_d, str_o, str_d.len);
+  return ptr;
 }
 
 
diff --git a/rts/js/string.js b/rts/js/string.js
index 4797cb13b5ea..83f8fb03f19d 100644
--- a/rts/js/string.js
+++ b/rts/js/string.js
@@ -479,9 +479,9 @@ function h$decodeUtf16z(v,start) {
 
 function h$decodeUtf16l(v, byteLen, start) {
   // perhaps we can apply it with an Uint16Array view, but that might give us endianness problems
-  var a = [];
+  var arr = [];
   for(var i=0;i<byteLen;i+=2) {
-    a[i>>1] = v.dv.getUint16(i+start,true);
+    arr[i>>1] = v.dv.getUint16(i+start,true);
   }
   return h$charCodeArrayToString(arr);
 }
@@ -590,7 +590,7 @@ function h$charCodeArrayToString(arr) {
 }
 
 function h$hs_iconv_open(to,to_off,from,from_off) {
-  h$errno = h$EINVAL; // no encodings supported
+  h$setErrno("EINVAL"); // no encodings supported
   return -1;
 //  var fromStr = decodeUtf8(from, from_off);
 //  var toStr = decodeUtf8(to, to_off);
-- 
GitLab