Skip to content
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

JSON.stringify cannot render preloaded object #1145

Closed
tve opened this issue Jun 8, 2023 · 3 comments
Closed

JSON.stringify cannot render preloaded object #1145

tve opened this issue Jun 8, 2023 · 3 comments

Comments

@tve
Copy link
Contributor

tve commented Jun 8, 2023

Build environment: Linux
Moddable SDK version: 3.9.2
Target device: Moddable Two

Description
Trying to JSON.stringify a preloaded object throws an exception:

var test = { x: 1, y: 2 }
trace(`test: ${JSON.stringify(test)}\n`)

export default function() {
    trace(`test: ${JSON.stringify(test)}\n`)
}

The manifest contains "preload": "main".
The first trace is printed at compile time as expected.
The second fails with "stringify: read only value!".

Expected behavior
I expected JSON.stringify to succeed.

@phoddie
Copy link
Collaborator

phoddie commented Jun 8, 2023

Yes, this has been reported before (see #340). There's no immediate intention to address it. A workaround is to use structuredClone.

@phoddie phoddie closed this as completed Jun 8, 2023
@tve
Copy link
Contributor Author

tve commented Jun 8, 2023

thanks, my searches didn't show this one...
two suggestions: document it (e.g. in the XS preload doc in the section on what can't be preloaded) and detect it in JSON;.stringify and produce a more explicit error and perhaps even suggest structuredClone

@phoddie
Copy link
Collaborator

phoddie commented Jun 8, 2023

I've updated the doc. Thank you for the suggestion.

Adding documentation into the runtime is a slippery slope, and not great for a runtime targeting extremely resource constrained targets.

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

No branches or pull requests

2 participants