NeilFraser / JS-Interpreter

A sandboxed JavaScript interpreter in JavaScript.
Apache License 2.0
1.96k stars 352 forks source link

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

Open ayahito-saji opened 4 months ago

ayahito-saji commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 2 months ago

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