console.log should not call object methods
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- android, javascript
- Domaine
- developer-experience, mobile-dev
Piste de recherche
Commencez au point d’entrée du formatage des objets de console.log dans l’Android runtime et reproduisez les snippets TypeScript fournis, y compris l’exemple toJSON qui échoue. Comparez la sortie avec le comportement de Chrome décrit dans l’issue ; c’est terminé lorsque le logging n’invoque pas les méthodes des objets et ne s’interrompt pas lorsqu’une d’elles lève une exception.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):
- CLI: 8.1.5
- Cross-platform modules: 6.5.11
- Android Runtime: 6.5.3
- iOS Runtime (if applicable): Possibly irrelevant
- Plugin(s): Possibly irrelevant
Describe the bug
When an object contains a toString or toJSON method, and you print that object through console.log, it will automatically call that function. This is very different from what Chrome console.log does and may cause confusing behavior. For example:
The NativeScript HTTP client returns an object with a property called content that contains an object with a to toJSON method, when you console.log the return object, it will automatically call that toJSON method, while it might not even be JSON, causing the console.log to fail with a weird error from JSON.parse, like Unexpected end of JSON input.
To Reproduce
const randomVar = "test123";
const obj = {
toJSON: () => "toJSON => this should not be logged " + randomVar
};
console.log(obj);
Expected behavior
I think it should print something like:
{
"toJSON": ƒ
}
Or, it should catch any errors that happen during the format, and then fall back to it's normal behavior (going to toString, or not printing the property at all). It should not be breaking off the whole console.log and return the exception.
Additional context
Output when doing something like this in Chrome:

Output when doing something like this in NS:

When causing an error inside the function with:
const obj = {
toJSON: () => JSON.parse("fakejson")
};
console.log(obj);
In Chrome:

In NS:

- Langage dominant
- C++
- Étoiles
- 563
- Forks
- 144
- Merge moyen
- 10 h 46 min
- PR mergées (30 j)
- 14
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de NativeScript/android
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
NativeScript/android#2039 · 1 commentaire ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 48/100
NativeScript/android#2024 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
NativeScript/android#2020 ·
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 42/100
NativeScript/android#2019 ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
NativeScript/android#1986 ·
Toutes les issues de NativeScript/android
Issues similaires
-
Website Doc Typo Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
-
Difficulté 1/5 1-3 heures Accessibilité débutants 92/100
autowarefoundation/autoware_universe#13413 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
-
automated-analysis bug memory-safety
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100