dfahlander / typeson-registry

The type registry for typeson

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Circular references broken in structured-cloning-throwing

dumbmatter opened this issue · comments

Looks like a new bug introduced by the fix to #8. Run this code:

var Typeson = require('typeson');
var structuredCloningThrowing = require('typeson-registry/dist/presets/structured-cloning-throwing');

var TSON = new Typeson().register(structuredCloningThrowing);

var obj = [];
obj.push(obj);

TSON.stringify(obj);

I get this error on Node v8.9.4:

$ node bug.js
/home/jdscheff/projects/realistic-structured-clone/node_modules/typeson/dist/typeson-commonjs2.js:1
(function (exports, require, module, __filename, __dirname) { "use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},slicedToArray=function(){return function(e,n){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function sliceIterator(e,n){var t=[],r=!0,i=!1,o=void 0;try{for(var s,c=e[Symbol.iterator]();!(r=(s=c.next()).done)&&(t.push(s.value),!n||t.length!==n);r=!0);}catch(e){i=!0,o=e}finally{try{!r&&c.return&&c.return()}finally{if(i)throw o}}return t}(e,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),toConsumableArray=function(e){if(Array.isArray(e)){for(var n=0,t=Array(e.length);n<e.length;n++)t[n]=e[n];return t}return Array.from(e)},keys=Object.keys,isArray=Array.isArray,toString={}.

RangeError: Maximum call stack size exceeded
    at _encapsulate (/home/jdscheff/projects/realistic-structured-clone/node_modules/typeson/dist/typeson-commonjs2.js:1:4281)
    at replace (/home/jdscheff/projects/realistic-structured-clone/node_modules/typeson/dist/typeson-commonjs2.js:1:6543)
    at _encapsulate (/home/jdscheff/projects/realistic-structured-clone/node_modules/typeson/dist/typeson-commonjs2.js:1:5041)
    at /home/jdscheff/projects/realistic-structured-clone/node_modules/typeson/dist/typeson-commonjs2.js:1:5812
    at Array.forEach (<anonymous>)
    at _encapsulate (/home/jdscheff/projects/realistic-structured-clone/node_modules/typeson/dist/typeson-commonjs2.js:1:5677)
    at replace (/home/jdscheff/projects/realistic-structured-clone/node_modules/typeson/dist/typeson-commonjs2.js:1:6543)
    at _encapsulate (/home/jdscheff/projects/realistic-structured-clone/node_modules/typeson/dist/typeson-commonjs2.js:1:5041)
    at /home/jdscheff/projects/realistic-structured-clone/node_modules/typeson/dist/typeson-commonjs2.js:1:5812
    at Array.forEach (<anonymous>)

Downgrading from typeson-registry 1.0.0-alpha.19 to 1.0.0-alpha.18 has no effect, but downgrading from typeson 5.8.1 to 5.7.1 makes the bug go away.

Hmm--surprised the unit tests didn't catch it, but I think I at least know where to look... Thanks, intend to check shortly... (Probably not deleting an internally-used state object property as we should)

Really appreciate the reports... this should now be fixed in typeson-registry with 416f5b1 (which is based on a Typeson fix, dfahlander/typeson@02ac99f )

Yep, it's fixed now. Thanks!