jasonelle-archive / jasonelle-v2

🛸 🏘️ Jasonelle issues, releases, discussions and wiki repository.
https://jasonelle.com
Mozilla Public License 2.0
422 stars 58 forks source link

st.js crash #74

Closed realitix closed 4 years ago

realitix commented 4 years ago

Describe the bug My view was sometime blank on Android. After deep searching, I figured out that the cause was this error:

2019-11-10 10:36:24.636 23311-23405/com.jasonette W/JasonParser: _executeStringFunction : undefined:211: RangeError: Maximum call stack size exceeded
          str = str.replace(re, '$1');
                    ^
    RangeError: Maximum call stack size exceeded
        at RegExp.[Symbol.replace] (native)
        at String.replace (native)
        at Object.tokenize (<anonymous>:211:17)
        at Object.run (<anonymous>:455:31)
        at Object.run (<anonymous>:262:34)
        at Object.run (<anonymous>:479:36)
        at Object.run (<anonymous>:479:36)
        at Object.run (<anonymous>:479:36)
        at Object.run (<anonymous>:479:36)
        at Object.run (<anonymous>:479:36)
    com.eclipsesource.v8.V8ScriptExecutionException

After digging, it seems that the problem comes form this line HERE.

To Reproduce I am using this json with lot of linked actions (and that may be the problem because too much recursion):

{
    "$jason": {
        "head": {
            "title": "Chargement",
            "actions": {
                "$load": {
                    "type": "$network.request",
                    "options": {
                        "url": "https://abouletonfilm.fr/api-token-auth/",
                        "method": "post",
                        "content_type": "json",
                        "data": {
                            "username": "{{$global.auth_username}}",
                            "password": "{{$global.auth_password}}"
                        }
                    },
                    "success": {
                        "type": "$session.set",
                        "options": {
                            "domain": "https://abouletonfilm.fr",
                            "header": {
                                "Authorization": "Token {{$jason.token}}"
                            }
                        },
                        "success": {
                            "type": "$href",
                            "options": {
                                "url": "file://out/receipe.json"
                            }
                        }
                    },
                    "error": {
                        "type": "$global.reset",
                        "options": {
                            "items": [
                                "auth_username",
                                "auth_password"
                            ]
                        },
                        "success": {
                            "type": "$session.reset",
                            "options": {
                                "domain": "https://abouletonfilm.fr"
                            },
                            "success": {
                                "type": "$href",
                                "options": {
                                    "url": "file://out/login.json"
                                }
                            }
                        }
                    }
                }
            }
        },
        "body": {
            "header": {
                "title": "Chargement",
                "style": {
                    "background": "#646464",
                    "color": "#ffffff"
                }
            }
        }
    }
}

Smartphone (please complete the following information):

realitix commented 4 years ago

After more digging, here the json code in error:

{
    "$jason": {
        "head": {
            "title": "Recettes",
            "templates": {
                "header": {
                    "title": "Mes recettes",
                    "style": {
                        "background": "#646464",
                        "color": "#ffffff"
                    }
                },
                "body": {
                    "style": {
                        "border": "none",
                        "background": "#636363"
                    },
                    "header": {
                        "title": "Mes recettes"
                    },
                    "footer": {
                        "tabs": {
                            "items": [
                                {
                                    "text": "Planning",
                                    "url": "file://out/planning.json"
                                },
                                {
                                    "text": "Recettes",
                                    "url": "file://out/receipe.json"
                                },
                                {
                                    "text": "D\u00e9connexion",
                                    "url": "file://out/disconnect.json"
                                }
                            ]
                        }
                    },
                    "sections": [
                        {
                            "items": [
                                {
                                    "type": "button",
                                    "text": "Cr\u00e9er une nouvelle recettes",
                                    "action": {
                                        "type": "$util.alert",
                                        "options": {
                                            "title": "Cr\u00e9ation d'une recette",
                                            "description": "Indiquez le nom de la recette \u00e0 cr\u00e9er",
                                            "form": [
                                                {
                                                    "name": "receipe_name",
                                                    "placeholder": "Nom de la recette"
                                                }
                                            ]
                                        },
                                        "success": {
                                            "type": "$network.request",
                                            "options": {
                                                "url": "https://abouletonfilm.fr/receipes/",
                                                "method": "post",
                                                "content_type": "json",
                                                "data": {
                                                    "name": "{{$jason.receipe_name}}"
                                                }
                                            },
                                            "success": {
                                                "type": "$util.alert",
                                                "options": {
                                                    "title": "toto",
                                                    "description": "{{$root}}"
                                                }
                                            }
                                        }
                                    }
                                }
                            ]
                        },
                        {
                            "items": {
                                "{{$each $jason.results}}": {
                                    "type": "label",
                                    "text": "{{name}}"
                                }
                            }
                        }
                    ]
                }
            },
            "actions": {
                "$load": {
                    "type": "$network.request",
                    "options": {
                        "url": "https://abouletonfilm.fr/receipes/"
                    },
                    "success": {
                        "type": "$render"
                    }
                }
            }
        }
    }
}
realitix commented 4 years ago

Ok I found out.

The problem is in my Json file. I set two times the key item in section...

realitix commented 4 years ago

Finally I encouneter the problem again. The problem was not my json but the json parser:

W/JasonParser: _executeStringFunction : undefined:211: RangeError: Maximum call stack size exceeded
          str = str.replace(re, '$1');
                    ^
    RangeError: Maximum call stack size exceeded
        at RegExp.[Symbol.replace] (native)
        at String.replace (native)
        at Object.tokenize (<anonymous>:211:17)
        at Object.run (<anonymous>:455:31)
        at Object.run (<anonymous>:479:36)
        at Object.run (<anonymous>:479:36)
        at Object.run (<anonymous>:479:36)
        at Object.run (<anonymous>:479:36)
        at Object.run (<anonymous>:479:36)
        at Object.run (<anonymous>:479:36)
    com.eclipsesource.v8.V8ScriptExecutionException
realitix commented 4 years ago

Here the json that create the error:

{
    "$jason": {
        "head": {
            "title": "Recettes",
            "templates": {
                "header": {
                    "title": "Ajout d'un repas",
                    "style": {
                        "background": "#646464",
                        "color": "#ffffff"
                    }
                },
                "body": {
                    "style": {
                        "border": "none",
                        "background": "#FFFFFF"
                    },
                    "header": {
                        "title": "Ajout d'un repas"
                    },
                    "footer": {
                        "tabs": {
                            "items": [
                                {
                                    "text": "Planning",
                                    "url": "file://out/planning.json"
                                },
                                {
                                    "text": "Recettes",
                                    "url": "file://out/receipes_list.json"
                                },
                                {
                                    "text": "D\u00e9connexion",
                                    "url": "file://out/disconnect.json"
                                }
                            ]
                        }
                    },
                    "sections": [
                        {
                            "items": [
                                {
                                    "type": "label",
                                    "text": "{{$get.selected_datetime}}",
                                    "action": {
                                        "type": "$util.datepicker",
                                        "options": {
                                            "date_format": "yyyy-MM-ddTHH:mm",
                                            "title": "S\u00e9lectionner la date",
                                            "description": "Date \u00e0 s\u00e9lectionner",
                                            "ampm": false
                                        },
                                        "success": {
                                            "type": "$set",
                                            "options": {
                                                "selected_datetime": "{{$jason.value}}"
                                            },
                                            "success": {
                                                "type": "$log.debug",
                                                "options": {
                                                    "text": "{{$root}}"
                                                }
                                            }
                                        }
                                    }
                                },
                                {
                                    "type": "button",
                                    "text": "Valider",
                                    "action": {
                                        "type": "$network.request",
                                        "options": {
                                            "url": "http://127.0.0.1:18385/meals/",
                                            "method": "post",
                                            "data_type": "json",
                                            "content_type": "json",
                                            "data": {
                                                "datetime": "{{$get.selected_datetime}}",
                                                "nb_people": 1
                                            }
                                        },
                                        "success": {
                                            "type": "$href",
                                            "options": {
                                                "url": "file://out/planning_meal.json",
                                                "options": {
                                                    "meal_url": "{{$jason.url}}"
                                                }
                                            }
                                        },
                                        "error": {
                                            "type": "$util.alert",
                                            "options": {
                                                "title": "Erreur",
                                                "description": "Une erreur est survenue"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                }
            },
            "actions": {
                "$load": {
                    "type": "$render"
                }
            }
        }
    }
}
realitix commented 4 years ago

I noticed something. If I change $root by test in the log.debug action, the error disappears. So I don't know what st.js do when it reads $root but it seems it did a lot.

clsource commented 4 years ago

Thanks @realitix. This is something that could be handled in the next release. Maybe doing some test for large jsons. Also the $root thing may need futher investigation.