From d606038e0317e1be199e3ca96356940586ce501e Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Tue, 8 May 2018 12:50:23 +0200 Subject: [PATCH] use Object#setPrototypeOf, #49386 --- src/vs/workbench/api/node/extHostTypes.ts | 6 ++++++ .../test/electron-browser/api/extHostTypes.test.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/vs/workbench/api/node/extHostTypes.ts b/src/vs/workbench/api/node/extHostTypes.ts index 743bf0c8d1b..9d3588ab7bf 100644 --- a/src/vs/workbench/api/node/extHostTypes.ts +++ b/src/vs/workbench/api/node/extHostTypes.ts @@ -1890,6 +1890,12 @@ export class FileSystemError extends Error { super(URI.isUri(uriOrMessage) ? uriOrMessage.toString(true) : uriOrMessage); this.name = code ? `${code} (FileSystemError)` : `FileSystemError`; + // workaround when extending builtin objects and when compiling to ES5, see: + // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work + if (typeof (Object).setPrototypeOf === 'function') { + (Object).setPrototypeOf(this, FileSystemError.prototype); + } + if (typeof Error.captureStackTrace === 'function' && typeof terminator === 'function') { // nice stack traces Error.captureStackTrace(this, terminator); diff --git a/src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts b/src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts index 7b846b18529..0b63e1b277a 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostTypes.test.ts @@ -513,4 +513,10 @@ suite('ExtHostTypes', function () { assert.equal(string.value, '${BAR}'); }); + + test('instanceof doesn\'t work for FileSystemError #49386', function () { + const error = types.FileSystemError.Unavailable('foo'); + assert.ok(error instanceof Error); + assert.ok(error instanceof types.FileSystemError); + }); });