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

Do you plan to support function replacer in JSON.stringify? #266

Open
ayahito-saji opened this issue Mar 9, 2024 · 3 comments
Open

Do you plan to support function replacer in JSON.stringify? #266

ayahito-saji opened this issue Mar 9, 2024 · 3 comments

Comments

@ayahito-saji
Copy link

ayahito-saji commented Mar 9, 2024

It seems that js-interpreter currently does not support functions for JSON.stringify replacer.
Are there any plans for support in the future?

ECMAScript 5.1 does support them, as seen at https://262.ecma-international.org/5.1/#sec-15.12.3
For security reasons, it is difficult to make replacer functions native, so a custom implementation of JSON.stringify will be needed to support function replacer in JSON.stringify.
Considering speed, it would be best to use the custom implementation when function replacer is present and use the native implementation when it is not present.

Thank you.

@NeilFraser
Copy link
Owner

I agree with the approach you outline. It's the same as that used by String's .replace function which has native code wrapped by a polyfill:
https://github.com/NeilFraser/JS-Interpreter/blob/master/interpreter.js#L1759

There are no current plans to support functions in JSON.stringify. You are the first to ask about it. Out of curiosity, what are you using JS-Interpreter for? You are certainly digging deeply in a lot of areas. :)

@ayahito-saji
Copy link
Author

Thank you for sharing the code!

I am trying to use core-js, webpack, and babel to run a TypeScript program that supports ES2015 and later syntax.
Another purpose of this attempt is to test the js-interpreter with core.js, which utilizes many types of syntax.
While much of the code works with this wonderful interpreter, I found that core-js behaved unexpectedly depending on some unsupported syntaxes and unstable behavior.

@semireg
Copy link

semireg commented May 10, 2024

@ayahito-saji, can you offer any guidance on how you used webpack to bundle for JS Interpreter?

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

3 participants