Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
e4dd8b64
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e4dd8b64
编写于
10月 04, 2017
作者:
J
Johannes Rieken
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add native promise polyfill, #35516
上级
6d8cbf85
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
236 addition
and
0 deletion
+236
-0
src/vs/base/common/winjs.polyfill.promise.ts
src/vs/base/common/winjs.polyfill.promise.ts
+77
-0
src/vs/base/test/common/winjs.polyfill.promise.test.ts
src/vs/base/test/common/winjs.polyfill.promise.test.ts
+152
-0
src/vs/editor/editor.main.ts
src/vs/editor/editor.main.ts
+7
-0
未找到文件。
src/vs/base/common/winjs.polyfill.promise.ts
0 → 100644
浏览文件 @
e4dd8b64
/*---------------------------------------------------------------------------------------------
* 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
'
;
/**
* 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
<
T
=
any
>
implements
Promise
<
T
>
{
static
all
(
thenables
:
Thenable
<
any
>
[]):
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
<
any
>
[]):
PolyfillPromise
{
// WinJSPromise returns `{ key: <index/key>, value: <promise> }`
// from the `any` call and Promise.race just wants the value
return
new
PolyfillPromise
(
WinJSPromise
.
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
(
callback
:
WinJSPromise
|
((
resolve
:
(
value
?:
T
)
=>
void
,
reject
:
(
err
?:
any
)
=>
void
)
=>
any
))
{
if
(
WinJSPromise
.
is
(
callback
))
{
this
.
_winjsPromise
=
callback
;
}
else
{
this
.
_winjsPromise
=
new
WinJSPromise
((
resolve
,
reject
)
=>
{
let
initializing
=
true
;
callback
(
function
(
value
)
{
if
(
!
initializing
)
{
resolve
(
value
);
}
else
{
setImmediate
(
resolve
,
value
);
}
},
function
(
err
)
{
if
(
!
initializing
)
{
reject
(
err
);
}
else
{
setImmediate
(
reject
,
err
);
}
});
initializing
=
false
;
});
}
}
then
(
onFulfilled
?:
any
,
onRejected
?:
any
):
PolyfillPromise
{
return
new
PolyfillPromise
(
this
.
_winjsPromise
.
then
(
onFulfilled
,
onRejected
));
}
catch
(
onRejected
?:
any
):
PolyfillPromise
{
return
new
PolyfillPromise
(
this
.
_winjsPromise
.
then
(
null
,
onRejected
));
}
}
src/vs/base/test/common/winjs.polyfill.promise.test.ts
0 → 100644
浏览文件 @
e4dd8b64
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
*
as
assert
from
'
assert
'
;
import
{
PolyfillPromise
}
from
'
vs/base/common/winjs.polyfill.promise
'
;
import
{
Promise
as
WinJSPromise
}
from
'
vs/base/common/winjs.base
'
;
suite
(
'
Polyfill Promise
'
,
function
()
{
test
(
'
sync-resolve, NativePromise
'
,
function
()
{
// native promise behaviour
const
actual
:
string
[]
=
[];
const
promise
=
new
Promise
(
resolve
=>
{
actual
.
push
(
'
inCtor
'
);
resolve
(
null
);
}).
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
(
'
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
]();
});
});
// run the same tests for the native and polyfill promise
(
<
any
[]
>
[
Promise
,
PolyfillPromise
]).
forEach
(
PromiseCtor
=>
{
test
(
PromiseCtor
.
name
+
'
, resolved value
'
,
function
()
{
return
new
PromiseCtor
(
resolve
=>
resolve
(
1
)).
then
(
value
=>
assert
.
equal
(
value
,
1
));
});
test
(
PromiseCtor
.
name
+
'
, rejected value
'
,
function
()
{
return
new
PromiseCtor
((
_
,
reject
)
=>
reject
(
1
)).
then
(
null
,
value
=>
assert
.
equal
(
value
,
1
));
});
test
(
PromiseCtor
.
name
+
'
, catch
'
,
function
()
{
return
new
PromiseCtor
((
_
,
reject
)
=>
reject
(
1
)).
catch
(
value
=>
assert
.
equal
(
value
,
1
));
});
test
(
PromiseCtor
.
name
+
'
, static-resolve
'
,
function
()
{
return
PromiseCtor
.
resolve
(
42
).
then
(
value
=>
assert
.
equal
(
value
,
42
));
});
test
(
PromiseCtor
.
name
+
'
, static-reject
'
,
function
()
{
return
PromiseCtor
.
reject
(
42
).
then
(
null
,
value
=>
assert
.
equal
(
value
,
42
));
});
test
(
PromiseCtor
.
name
+
'
, static-all, 1
'
,
function
()
{
return
PromiseCtor
.
all
([
PromiseCtor
.
resolve
(
1
),
PromiseCtor
.
resolve
(
2
)
]).
then
(
values
=>
{
assert
.
deepEqual
(
values
,
[
1
,
2
]);
});
});
test
(
PromiseCtor
.
name
+
'
, static-all, 2
'
,
function
()
{
return
PromiseCtor
.
all
([
PromiseCtor
.
resolve
(
1
),
3
,
PromiseCtor
.
resolve
(
2
)
]).
then
(
values
=>
{
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
=>
{
assert
.
deepEqual
(
values
,
13
);
});
});
test
(
PromiseCtor
.
name
+
'
, static-race, 1
'
,
function
()
{
return
PromiseCtor
.
race
([
PromiseCtor
.
resolve
(
1
),
PromiseCtor
.
resolve
(
2
),
]).
then
(
value
=>
{
assert
.
deepEqual
(
value
,
1
);
});
});
test
(
PromiseCtor
.
name
+
'
, static-race, 2
'
,
function
()
{
return
PromiseCtor
.
race
([
PromiseCtor
.
reject
(
-
1
),
PromiseCtor
.
resolve
(
2
),
]).
catch
(
value
=>
{
assert
.
deepEqual
(
value
,
-
1
);
});
});
test
(
PromiseCtor
.
name
+
'
, static-race, 3
'
,
function
()
{
return
PromiseCtor
.
race
([
PromiseCtor
.
resolve
(
1
),
PromiseCtor
.
reject
(
2
),
]).
then
(
value
=>
{
assert
.
deepEqual
(
value
,
1
);
});
});
test
(
PromiseCtor
.
name
+
'
, throw in ctor
'
,
function
()
{
return
new
PromiseCtor
(()
=>
{
throw
new
Error
(
'
sooo bad
'
);
}).
catch
(
err
=>
{
assert
.
equal
(
err
.
message
,
'
sooo bad
'
);
});
});
});
});
src/vs/editor/editor.main.ts
浏览文件 @
e4dd8b64
...
...
@@ -19,6 +19,13 @@ import { createMonacoEditorAPI } from 'vs/editor/standalone/browser/standaloneEd
import
{
createMonacoLanguagesAPI
}
from
'
vs/editor/standalone/browser/standaloneLanguages
'
;
import
{
EDITOR_DEFAULTS
,
WrappingIndent
}
from
'
vs/editor/common/config/editorOptions
'
;
// When missing, polyfill the native promise
// with our winjs-based polyfill
import
{
PolyfillPromise
}
from
'
vs/base/common/winjs.polyfill.promise
'
;
if
(
typeof
global
.
Promise
===
'
undefined
'
)
{
global
.
Promise
=
PolyfillPromise
;
}
// Set defaults for standalone editor
(
<
any
>
EDITOR_DEFAULTS
).
wrappingIndent
=
WrappingIndent
.
None
;
(
<
any
>
EDITOR_DEFAULTS
.
contribInfo
).
folding
=
false
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录