From a99079f13a154b3e7cb8df9271cc3e9195e46b69 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 13 Dec 2018 10:14:42 +0100 Subject: [PATCH] remove winjs-based polyfill promse #53526 --- build/monaco/monaco.usage.recipe | 1 - src/tsconfig.strictNullChecks.json | 3 +- src/vs/base/common/winjs.polyfill.promise.ts | 133 ------------- .../common/winjs.polyfill.promise.test.ts | 183 ------------------ src/vs/monaco.d.ts | 1 + 5 files changed, 2 insertions(+), 319 deletions(-) delete mode 100644 src/vs/base/common/winjs.polyfill.promise.ts delete mode 100644 src/vs/base/test/common/winjs.polyfill.promise.test.ts diff --git a/build/monaco/monaco.usage.recipe b/build/monaco/monaco.usage.recipe index 663f7b7cc26..40e6ee6a67a 100644 --- a/build/monaco/monaco.usage.recipe +++ b/build/monaco/monaco.usage.recipe @@ -11,7 +11,6 @@ import { SimpleWorkerClient, create as create1 } from './vs/base/common/worker/s import { create as create2 } from './vs/editor/common/services/editorSimpleWorker'; import { QuickOpenWidget } from './vs/base/parts/quickopen/browser/quickOpenWidget'; import { SyncDescriptor0, SyncDescriptor1, SyncDescriptor2, SyncDescriptor3, SyncDescriptor4, SyncDescriptor5, SyncDescriptor6, SyncDescriptor7, SyncDescriptor8 } from './vs/platform/instantiation/common/descriptors'; -import { PolyfillPromise } from './vs/base/common/winjs.polyfill.promise'; import { DiffNavigator } from './vs/editor/browser/widget/diffNavigator'; import * as editorAPI from './vs/editor/editor.api'; diff --git a/src/tsconfig.strictNullChecks.json b/src/tsconfig.strictNullChecks.json index 9e4af5f51df..f3bd8c9df97 100644 --- a/src/tsconfig.strictNullChecks.json +++ b/src/tsconfig.strictNullChecks.json @@ -136,7 +136,6 @@ "./vs/base/test/common/types.test.ts", "./vs/base/test/common/utils.ts", "./vs/base/test/common/uuid.test.ts", - "./vs/base/test/common/winjs.polyfill.promise.test.ts", "./vs/base/test/common/winjs.promise.test.ts", "./vs/base/test/node/console.test.ts", "./vs/base/test/node/decoder.test.ts", @@ -772,4 +771,4 @@ "exclude": [ "./typings/require-monaco.d.ts" ] -} \ No newline at end of file +} diff --git a/src/vs/base/common/winjs.polyfill.promise.ts b/src/vs/base/common/winjs.polyfill.promise.ts deleted file mode 100644 index 3b24d0dbf8e..00000000000 --- a/src/vs/base/common/winjs.polyfill.promise.ts +++ /dev/null @@ -1,133 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { Promise as WinJSPromise } from './winjs.base'; -import * as platform from 'vs/base/common/platform'; -import { isThenable } from 'vs/base/common/async'; - -function isWinJSPromise(candidate: any): candidate is WinJSPromise { - return isThenable(candidate) && typeof (candidate as any).done === 'function'; -} - -declare class WinJSPromiseRemovals { - any(promises: (T | PromiseLike)[]): WinJSPromise<{ key: string; value: WinJSPromise; }>; -} - -/** - * A polyfill for the native promises. The implementation is based on - * WinJS promises but tries to gap differences between winjs promises - * and native promises. - */ -export class PolyfillPromise implements Promise { - - static all(thenables: Thenable[]): PolyfillPromise { - return new PolyfillPromise(WinJSPromise.join(thenables).then(null, values => { - // WinJSPromise returns a sparse array whereas - // native promises return the *first* error - for (var key in values) { - if (values.hasOwnProperty(key)) { - return values[key]; - } - } - })); - } - - static race(thenables: Thenable[]): PolyfillPromise { - // WinJSPromise returns `{ key: , value: }` - // from the `any` call and Promise.race just wants the value - return new PolyfillPromise((WinJSPromise as any as WinJSPromiseRemovals).any(thenables).then(entry => entry.value, err => err.value)); - } - - static resolve(value): PolyfillPromise { - return new PolyfillPromise(WinJSPromise.wrap(value)); - } - - static reject(value): PolyfillPromise { - return new PolyfillPromise(WinJSPromise.wrapError(value)); - } - - private _winjsPromise: WinJSPromise; - - constructor(winjsPromise: WinJSPromise); - constructor(callback: (resolve: (value?: T) => void, reject: (err?: any) => void) => any); - constructor(initOrPromise: WinJSPromise | ((resolve: (value?: T) => void, reject: (err?: any) => void) => any)) { - - if (isWinJSPromise(initOrPromise)) { - this._winjsPromise = initOrPromise; - } else { - this._winjsPromise = new WinJSPromise((resolve, reject) => { - let initializing = true; - initOrPromise(function (value) { - if (!initializing) { - resolve(value); - } else { - platform.setImmediate(() => resolve(value)); - } - }, function (err) { - if (!initializing) { - reject(err); - } else { - platform.setImmediate(() => reject(err)); - } - }); - initializing = false; - }); - } - } - - then(onFulfilled?: any, onRejected?: any): PolyfillPromise { - let sync = true; - // To support chaining, we need to return the value of the - // onFulfilled and onRejected callback. - // WinJSPromise supports a flat-map style #then, ie. the callbacks - // passed to WinJSPromise#then can return a Promise. - let promise = new PolyfillPromise(this._winjsPromise.then( - onFulfilled && function (value) { - if (!sync) { - return onFulfilled(value); - } else { - return new WinJSPromise((resolve, reject) => { - platform.setImmediate(() => { - let result; - try { - result = onFulfilled(value); - } - catch (err2) { - reject(err2); - return; - } - resolve(result); - }); - }); - } - }, - onRejected && function (err) { - if (!sync) { - return onRejected(err); - } else { - return new WinJSPromise((resolve, reject) => { - platform.setImmediate(() => { - let result; - try { - result = onRejected(err); - } - catch (err2) { - reject(err2); - return; - } - resolve(result); - }); - }); - } - } - )); - sync = false; - return promise; - } - - catch(onRejected?: any): PolyfillPromise { - return this.then(null, onRejected); - } -} diff --git a/src/vs/base/test/common/winjs.polyfill.promise.test.ts b/src/vs/base/test/common/winjs.polyfill.promise.test.ts deleted file mode 100644 index 2d601daf7cd..00000000000 --- a/src/vs/base/test/common/winjs.polyfill.promise.test.ts +++ /dev/null @@ -1,183 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -import * as assert from 'assert'; -import { Promise as WinJSPromise } from 'vs/base/common/winjs.base'; -import { PolyfillPromise } from 'vs/base/common/winjs.polyfill.promise'; - -suite('Polyfill Promise', function () { - - test('sync-resolve, NativePromise', function () { - // native promise behaviour - const actual: string[] = []; - const promise = new Promise(resolve => { - actual.push('inCtor'); - resolve(void 0); - }).then(() => actual.push('inThen')); - actual.push('afterCtor'); - return promise.then(() => { - assert.deepEqual(actual, ['inCtor', 'afterCtor', 'inThen']); - }); - }); - - test('sync-resolve, WinJSPromise', function () { - - // winjs promise behaviour - const actual: string[] = []; - const promise = new WinJSPromise(resolve => { - actual.push('inCtor'); - resolve(null); - }).then(() => actual.push('inThen')); - actual.push('afterCtor'); - return promise.then(() => { - assert.deepEqual(actual, ['inCtor', 'inThen', 'afterCtor']); - }); - }); - - test('sync-resolve, PolyfillPromise', function () { - - // winjs promise behaviour - const actual: string[] = []; - const promise = new PolyfillPromise(resolve => { - actual.push('inCtor'); - resolve(null); - }).then(() => actual.push('inThen')); - actual.push('afterCtor'); - return promise.then(() => { - assert.deepEqual(actual, ['inCtor', 'afterCtor', 'inThen']); - }); - }); - - test('sync-then, NativePromise', function () { - const actual: string[] = []; - const promise = Promise.resolve(123).then(() => actual.push('inThen')); - actual.push('afterThen'); - return promise.then(() => { - assert.deepEqual(actual, ['afterThen', 'inThen']); - }); - }); - - test('sync-then, WinJSPromise', function () { - const actual: string[] = []; - const promise = WinJSPromise.as(123).then(() => actual.push('inThen')); - actual.push('afterThen'); - return promise.then(() => { - assert.deepEqual(actual, ['inThen', 'afterThen']); - }); - }); - - test('sync-then, PolyfillPromise', function () { - const actual: string[] = []; - const promise = PolyfillPromise.resolve(123).then(() => actual.push('inThen')); - actual.push('afterThen'); - return promise.then(() => { - assert.deepEqual(actual, ['afterThen', 'inThen']); - }); - }); - - test('PolyfillPromise, executor has two params', function () { - return new PolyfillPromise(function () { - assert.equal(arguments.length, 2); - assert.equal(typeof arguments[0], 'function'); - assert.equal(typeof arguments[1], 'function'); - - arguments[0](); - }); - }); - - test('Promises polyfill does not support chaining then and catch #57722', function () { - return PolyfillPromise.resolve(1).then(function (x) { return x + 1; }).then(function (x) { - assert.equal(x, 2); - }); - }); - - // run the same tests for the native and polyfill promise - ([Promise, PolyfillPromise]).forEach(PromiseCtor => { - - test(PromiseCtor.name + ', resolved value', function () { - return new PromiseCtor((resolve: Function) => resolve(1)).then((value: number) => assert.equal(value, 1)); - }); - - test(PromiseCtor.name + ', rejected value', function () { - return new PromiseCtor((_: Function, reject: Function) => reject(1)).then(null, (value: number) => assert.equal(value, 1)); - }); - - test(PromiseCtor.name + ', catch', function () { - return new PromiseCtor((_: Function, reject: Function) => reject(1)).catch((value: number) => assert.equal(value, 1)); - }); - - test(PromiseCtor.name + ', static-resolve', function () { - return PromiseCtor.resolve(42).then((value: number) => assert.equal(value, 42)); - }); - - test(PromiseCtor.name + ', static-reject', function () { - return PromiseCtor.reject(42).then(null, (value: number) => assert.equal(value, 42)); - }); - - test(PromiseCtor.name + ', static-all, 1', function () { - return PromiseCtor.all([ - PromiseCtor.resolve(1), - PromiseCtor.resolve(2) - ]).then((values: number[]) => { - assert.deepEqual(values, [1, 2]); - }); - }); - - test(PromiseCtor.name + ', static-all, 2', function () { - return PromiseCtor.all([ - PromiseCtor.resolve(1), - 3, - PromiseCtor.resolve(2) - ]).then((values: number[]) => { - assert.deepEqual(values, [1, 3, 2]); - }); - }); - - test(PromiseCtor.name + ', static-all, 3', function () { - return PromiseCtor.all([ - PromiseCtor.resolve(1), - PromiseCtor.reject(13), - PromiseCtor.reject(12), - ]).catch((values: number) => { - assert.deepEqual(values, 13); - }); - }); - - test(PromiseCtor.name + ', static-race, 1', function () { - return PromiseCtor.race([ - PromiseCtor.resolve(1), - PromiseCtor.resolve(2), - ]).then((value: number) => { - assert.deepEqual(value, 1); - }); - }); - - test(PromiseCtor.name + ', static-race, 2', function () { - return PromiseCtor.race([ - PromiseCtor.reject(-1), - PromiseCtor.resolve(2), - ]).catch((value: number) => { - assert.deepEqual(value, -1); - }); - }); - - test(PromiseCtor.name + ', static-race, 3', function () { - return PromiseCtor.race([ - PromiseCtor.resolve(1), - PromiseCtor.reject(2), - ]).then((value: number) => { - assert.deepEqual(value, 1); - }); - }); - - test(PromiseCtor.name + ', throw in ctor', function () { - return new PromiseCtor(() => { - throw new Error('sooo bad'); - }).catch((err: Error) => { - assert.equal(err.message, 'sooo bad'); - }); - }); - - }); -}); diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 0a0edec247e..e49a496e4eb 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -362,6 +362,7 @@ declare namespace monaco { */ MAX_VALUE = 112 } + export class KeyMod { static readonly CtrlCmd: number; static readonly Shift: number; -- GitLab