console.log should not call object methods
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- android, javascript
調査の方向性
Android runtime の console.log のオブジェクトフォーマット処理のエントリーポイントから始め、失敗する toJSON の例を含め、提供された TypeScript スニペットを再現してください。出力を issue に記載されている Chrome の動作と比較します。ロギングがオブジェクトのメソッドを呼び出さず、そのうちの 1 つが例外をスローしても中断しなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
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:

- 主要言語
- C++
- スター
- 563
- フォーク
- 144
- 平均マージ
- 10時間 46分
- マージ済み PR(30日)
- 14
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NativeScript/android のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
NativeScript/android#2039 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
NativeScript/android#2024 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
NativeScript/android#2020 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 42/100
NativeScript/android#2019 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
NativeScript/android#1986 ·
NativeScript/android の issue をすべて見る
似ている issue
-
[BUG] オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
eunomia-bpf/llvmbpf#51 · コメント 1 件 ·
-
status:needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
PX4/PX4-Autopilot#28776 ·
-
Website Doc Typo オープン
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
autowarefoundation/autoware_universe#13413 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100