From 816ac814e8a11897db45dfad83cfdd9d3dae55fb Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Mon, 16 Aug 2021 09:54:35 +0900 Subject: Web/JavaScript/Reference/Errors以下の5文書をMarkdown化 (#1971) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 5文書をMarkdown化 - 2021/08/07時点の最新版に同期 --- .../reference/errors/no_non-null_object/index.html | 69 -------------------- .../reference/errors/no_non-null_object/index.md | 73 ++++++++++++++++++++++ 2 files changed, 73 insertions(+), 69 deletions(-) delete mode 100644 files/ja/web/javascript/reference/errors/no_non-null_object/index.html create mode 100644 files/ja/web/javascript/reference/errors/no_non-null_object/index.md (limited to 'files/ja/web/javascript/reference/errors/no_non-null_object') diff --git a/files/ja/web/javascript/reference/errors/no_non-null_object/index.html b/files/ja/web/javascript/reference/errors/no_non-null_object/index.html deleted file mode 100644 index 93d167e25a..0000000000 --- a/files/ja/web/javascript/reference/errors/no_non-null_object/index.html +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: 'TypeError: "x" is not a non-null object' -slug: Web/JavaScript/Reference/Errors/No_non-null_object -tags: -- Error -- Errors -- JavaScript -- TypeError -translation_of: Web/JavaScript/Reference/Errors/No_non-null_object ---- -
{{JSSidebar("Errors")}}
- -

JavaScript の例外 "is not a non-null object" は、オブジェクトが何かを求めているのに提供されなかった場合に発生します。 {{jsxref("null")}} はオブジェクトではなく、動作しません。

- -

エラーメッセージ

- -
TypeError: Invalid descriptor for property {x} (Edge)
-TypeError: "x" is not a non-null object (Firefox)
-TypeError: Property description must be an object: "x" (Chrome)
-TypeError: Invalid value used in weak set (Chrome)
-
- -

エラータイプ

- -

{{jsxref("TypeError")}}

- -

何がうまくいかなかったのか?

- -

どこかでオブジェクトが期待されていますが、提供されませんでした。 {{jsxref("null")}} はオブジェクトではなく、動作しません。与えられた状況で適切なオブジェクトを提供しなければなりません。

- -

- -

プロパティディスクリプターが期待される場合

- -

{{jsxref("Object.create()")}} メソッドや {{jsxref("Object.defineProperty()")}} メソッド、{{jsxref("Object.defineProperties()")}} メソッドを使用するとき、省略可能なディスクリプター引数として、プロパティディスクリプターオブジェクトが想定されます。 (ただの数値のように) オブジェクトを提供しないと、エラーが発生します。

- -
Object.defineProperty({}, 'key', 1);
-// TypeError: 1 is not a non-null object
-
-Object.defineProperty({}, 'key', null);
-// TypeError: null is not a non-null object
-
- -

有効なプロパティディスクリプターはこのようになります。

- -
Object.defineProperty({}, 'key', { value: 'foo', writable: false });
-
- -

WeakMap オブジェクトと WeakSet オブジェクトはオブジェクトキーが必要

- -

{{jsxref("WeakMap")}} オブジェクトと {{jsxref("WeakSet")}} オブジェクトはオブジェクトキーを保持します。そのほかの型をキーとして使用できません。

- -
var ws = new WeakSet();
-ws.add('foo');
-// TypeError: "foo" is not a non-null object
- -

代わりにオブジェクトを使用してください。

- -
ws.add({foo: 'bar'});
-ws.add(window);
-
- -

関連項目

- - diff --git a/files/ja/web/javascript/reference/errors/no_non-null_object/index.md b/files/ja/web/javascript/reference/errors/no_non-null_object/index.md new file mode 100644 index 0000000000..b548d38c6a --- /dev/null +++ b/files/ja/web/javascript/reference/errors/no_non-null_object/index.md @@ -0,0 +1,73 @@ +--- +title: 'TypeError: "x" is not a non-null object' +slug: Web/JavaScript/Reference/Errors/No_non-null_object +tags: +- Error +- Errors +- JavaScript +- TypeError +translation_of: Web/JavaScript/Reference/Errors/No_non-null_object +--- +{{JSSidebar("Errors")}} + +JavaScript の例外 "is not a non-null object" は、ある場所でオブジェクトが期待されているのに提供されなかった場合に発生します。 {{jsxref("null")}} はオブジェクトではなく、動作しません。 + +## エラーメッセージ + +```js +TypeError: Invalid descriptor for property {x} (Edge) +TypeError: "x" is not a non-null object (Firefox) +TypeError: Property description must be an object: "x" (Chrome) +TypeError: Invalid value used in weak set (Chrome) +``` + +## エラーの種類 + +{{jsxref("TypeError")}} + +## エラーの原因 + +ある場所でオブジェクトが期待されていますが、提供されませんでした。 {{jsxref("null")}} はオブジェクトではなく、動作しません。与えられた状況で適切なオブジェクトを提供しなければなりません。 + +## 例 + +## プロパティ記述子が求められている場合 + +{{jsxref("Object.create()")}} メソッドや {{jsxref("Object.defineProperty()")}} メソッド、{{jsxref("Object.defineProperties()")}} メソッドを使用するとき、省略可能な記述子の引数として、プロパティ記述子オブジェクトが想定されます。 (ただの数値など) オブジェクト以外のものを提供すると、エラーが発生します。 + +```js example-bad +Object.defineProperty({}, 'key', 1); +// TypeError: 1 is not a non-null object + +Object.defineProperty({}, 'key', null); +// TypeError: null is not a non-null object +``` + +有効なプロパティ記述子はこのようになります。 + +```js example-good +Object.defineProperty({}, 'key', { value: 'foo', writable: false }); +``` + +## `WeakMap` および `WeakSet` オブジェクトにはオブジェクトキーが必要 + +{{jsxref("WeakMap")}} および {{jsxref("WeakSet")}} オブジェクトはオブジェクトをキーとして保持します。そのほかの型をキーとして使用できません。 + +```js example-bad +var ws = new WeakSet(); +ws.add('foo'); +// TypeError: "foo" is not a non-null object +``` + +代わりにオブジェクトを使用してください。 + +```js example-good +ws.add({foo: 'bar'}); +ws.add(window); +``` + +## 関連項目 + +- {{jsxref("Object.create()")}} +- {{jsxref("Object.defineProperty()")}}, {{jsxref("Object.defineProperties()")}} +- {{jsxref("WeakMap")}}, {{jsxref("WeakSet")}} -- cgit v1.2.3-54-g00ecf