メッセージ
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)
エラータイプ
何がうまくいかなかったのか?
どこかでオブジェクトが期待されていますが、提供されませんでした。null はオブジェクトではなく、動作しません。与えられた状況で適切なオブジェクトを提供しなければなりません。
例
プロパティディスクリプタが想定される
Object.create() メソッドや Object.defineProperty() メソッド、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 オブジェクトはオブジェクトキーが必要
WeakMap オブジェクトと WeakSet オブジェクトはオブジェクトキーを保持します。そのほかの型をキーとして使用できません。
var ws = new WeakSet();
ws.add('foo');
// TypeError: "foo" is not a non-null object
代わりにオブジェクトを使用します:
ws.add({foo: 'bar'});
ws.add(window);