Skip to content

Commit

Permalink
annoying escaping bugs
Browse files Browse the repository at this point in the history
Currently trying to make both:

"{\"name\":\"formic.id\",\"private\":true,\"version\":\"0.0.0\",\"type\":\"module\",\"scripts\":{\"dev\":\"vite\",\"build\":\"tsc && vite build\",\"preview\":\"vite preview\",\"test\":\"vitest\"},\"devDependencies\":{\"@types/react\":\"^18.2.35\",\"@types/react-dom\":\"^18.2.14\",\"@vitejs/plugin-react\":\"^4.1.1\",\"typescript\":\"^5.0.2\",\"vite\":\"^4.4.5\",\"vitest\":\"^0.34.6\"},\"dependencies\":{\"million\":\"^2.6.4\",\"react\":\"^18.2.0\",\"react-dom\":\"^18.2.0\"}}" json> >stor

and:

"{\"name\":\"formic.id\",\"private\":true,\"version\":\"0.0.0\",\"type\":\"module\",\"scripts\":{\"dev\":\"vite\",\"build\":\"tsc && vite build\",\"preview\":\"vite preview\",\"test\":\"vitest\"},\"devDependencies\":{\"@types/react\":\"^18.2.35\",\"@types/react-dom\":\"^18.2.14\",\"@vitejs/plugin-react\":\"^4.1.1\",\"typescript\":\"^5.0.2\",\"vite\":\"^4.4.5\",\"vitest\":\"^0.34.6\"},\"dependencies\":{\"million\":\"^2.6.4\",\"react\":\"^18.2.0\",\"react-dom\":\"^18.2.0\"}}" json> >sap

produce results without crashing.
  • Loading branch information
pcarrier committed Apr 26, 2024
1 parent e80a9bd commit 85d3fb3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import App from "./app.tsx";
const worker = (window.$worker = new Worker());

worker.onmessage = (e) => {
eval(e.data);
try {
eval(e.data);
} catch (err) {
console.error(err, e.data);
}
};

const root = createRoot(document.getElementById("app")!);
Expand Down
7 changes: 3 additions & 4 deletions src/wasm/js.nim
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import std/strutils

func jsString*(s: string, depth: uint8, replaceHTML: bool, externalQuotes: bool): string =
let repeatsOnQuotesAround = (1 shl depth) - 1
let repeatsOnBackslashInside = (1 shl (depth + 1))
let repeatsOnQuotesInside = repeatsOnBackslashInside - 1
let repeatsOnQuotesInside = 1 shl depth
let repeatsOnQuotesAround = repeatsOnQuotesInside - 1
let repeatsOnBackslashInside = repeatsOnQuotesInside + 1
let len = s.len
result = newStringOfCap(len + len shr 1)
if externalQuotes:
Expand All @@ -29,5 +29,4 @@ func jsString*(s: string, depth: uint8, replaceHTML: bool, externalQuotes: bool)
proc emscripten_run_script(code: cstring) {.header: "<emscripten.h>", importc: "emscripten_run_script".}

proc jsEval*(code: string) =
# echo "jsEval: ", cstring(code)
emscripten_run_script(cstring(code))

0 comments on commit 85d3fb3

Please sign in to comment.