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

Stack overflow when calling toString on cyclic values #645

Closed
folkertdev opened this Issue Jun 12, 2016 · 3 comments

Comments

Projects
None yet
4 participants
@folkertdev

folkertdev commented Jun 12, 2016

Someone ran into this in the elm slack channel.

Trying to print a Json.Decode.Value object that is generated by Html.Events' on function results
in a RangeError, originating in the addSlashes function (called by toString).

The weird thing is that when a Json.Value value
is generated with decoders in elm, everything works fine. #539 seems to suggest that the problem is with values that are generated by native modules. Here is an example that gives a RangeError on
elm-lang.org/try (in Chrome, v50 on linux mint)

import Html exposing (div, input)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick, on)

import Json.Decode as Json exposing (..)

import Debug

test : Json.Value
test =
    case Json.decodeString Json.value "{\"a\":\"1\"}" of 
        Ok v -> v
        Err e -> Debug.crash e


main =
  beginnerProgram { model = 0, view = view, update = update }


view model =
  div []
    [ input [ on "focus" (Json.map ValueMsg Json.value) ] []  
    ]


type Msg = ValueMsg Json.Value


update msg model =
  case msg of

    ValueMsg val -> 
        -- works just fine
        --Debug.log (toString test) model
        -- RangeError
        Debug.log (toString val) model

      -- RangeError: Maximum call stack size exceeded[Symbol.replace] @ 
        -- in the function addSlashes
@jinjor

This comment has been minimized.

Show comment
Hide comment
@jinjor

jinjor Jun 28, 2016

Contributor

I ran into the same problem when I tried Debug.log on a Json.Value object which includes AudioNode.

The infinite loop is occurring at here in Native/Utils.js.

function toString(v)
{

        ...

        if (type === 'object')
            {
                var output = [];
                for (var k in v)
                {
                    output.push(k + ' = ' + toString(v[k])); // this is called many times
                }

This is caused by circular reference. AudioContext.destination returns AudioDestinationNode and AudioDestinationNode.context returns AudioContext.destination.

Contributor

jinjor commented Jun 28, 2016

I ran into the same problem when I tried Debug.log on a Json.Value object which includes AudioNode.

The infinite loop is occurring at here in Native/Utils.js.

function toString(v)
{

        ...

        if (type === 'object')
            {
                var output = [];
                for (var k in v)
                {
                    output.push(k + ' = ' + toString(v[k])); // this is called many times
                }

This is caused by circular reference. AudioContext.destination returns AudioDestinationNode and AudioDestinationNode.context returns AudioContext.destination.

@lukewestby

This comment has been minimized.

Show comment
Hide comment
@lukewestby

lukewestby Aug 12, 2016

Member

@folkertdev could you rename this to something like "Stack overflow when calling toString on cyclic values"?

Member

lukewestby commented Aug 12, 2016

@folkertdev could you rename this to something like "Stack overflow when calling toString on cyclic values"?

@folkertdev folkertdev changed the title from RangeError in toString for Decode.Value objects to Stack overflow when calling toString on cyclic values Aug 13, 2016

@evancz evancz referenced this issue Sep 22, 2016

Closed

toString #723

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Sep 22, 2016

Member

Follow along in the #723 meta issue.

Member

evancz commented Sep 22, 2016

Follow along in the #723 meta issue.

@evancz evancz closed this Sep 22, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment