Encode does not work with window object
ChristopherHButler opened this issue · 0 comments
ChristopherHButler commented
I am making a console log input (very similar to the one on code sandbox) and I am using the Encode
function for the data property of the log object like this:
const result = eval(`${this.state.code}`);
const logs = [{
method: 'log',
id: shortid.generate(),
data: Encode(result),
}];
this.props.appendToConsoles({ logs });
This seems to work fine for other objects but if I type window
I get a warning and Encode kills my app.
The warning:
[Deprecation] 'window.webkitStorageInfo' is deprecated. Please use 'navigator.webkitTemporaryStorage' or 'navigator.webkitPersistentStorage' instead.
which seems to be coming from:
EncodingTransformer.prototype._handlePlainObject = function (obj) {
var result = Object.create(null);
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
var resultKey = KEY_REQUIRE_ESCAPING_RE.test(key) ? "#" + key : key;
result[resultKey] = this._handleValue(obj[key], result, resultKey); // <------- this line
I understand the issue now; the window object has circular references which cannot be serialized without some help. I had a peek into your library and you seem to be handling this so I'm not sure what my next move is. I found a little snippet I can use to pass as a replacer function to JSON.serialize
but that is pointless if you are already handling this case.