Skip to content

Accessing localStorage fails #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
carson-katri opened this issue Jul 17, 2020 · 6 comments · Fixed by #19
Closed

Accessing localStorage fails #18

carson-katri opened this issue Jul 17, 2020 · 6 comments · Fixed by #19

Comments

@carson-katri
Copy link
Member

Here's a simple example:

let localStorage = JSObjectRef.global.localStorage.object!
print(localStorage.getItem!("hello"))
_ = localStorage.setItem!("hello", "world")
print(localStorage.getItem!("hello"))

Prints null then .string("world") as expected.

However, if you refresh the site after the value is set, it crashes with Reflect.get called on non-object.

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Jul 18, 2020

@carson-katri Thanks for report! Could you try this branch #19 ?

@carson-katri
Copy link
Member Author

Sorry, same crash 😕

@kateinoigakukun
Copy link
Member

@carson-katri Hmm, did you reference local runtime library in this repo instead of the released runtime library?
I think you may be using version 0.4.0. Please specify local built runtime library following these steps.

  1. Build runtime library on your machine
$ pwd
path/to/JavaScriptKit
$ cd Runtime && npm run build
  1. Update your package.json
{
  ...
  "dependencies": {
    ...
-    "javascript-kit-swift": "0.4.0"
+    "javascript-kit-swift": "file:path/to/JavaScriptKit/Runtime"
  },
  ...
}
  1. Update your Package.swift
let package = Package(
    ...
-    .package(url: "https://github.com/kateinoigakukun/JavaScriptKit.git", .revision("master")),
+    dependencies: [.package(name: "JavaScriptKit", path: "path/to/JavaScriptKit")],
    ...
)

@MaxDesiatov
Copy link
Contributor

I assume, if the project is built with carton it uses the runtime shipped with the dev entrypoint: https://github.com/swiftwasm/carton/blob/main/package.json

@MaxDesiatov
Copy link
Contributor

Most probably easier to test that branch without carton, maybe through some custom webpack project.

@carson-katri
Copy link
Member Author

Got it working, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants