Skip to content

Commit 65c18df

Browse files
Resolve es5ClassCompat performance issue (microsoft#162583)
Co-authored-by: Qingpeng Li <[email protected]>
1 parent a69b853 commit 65c18df

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ import type * as vscode from 'vscode';
2828
* but new ones must not be added
2929
* */
3030
function es5ClassCompat(target: Function): any {
31-
///@ts-expect-error
32-
function _() { return Reflect.construct(target, arguments, this.constructor); }
33-
Object.defineProperty(_, 'name', Object.getOwnPropertyDescriptor(target, 'name')!);
34-
Object.setPrototypeOf(_, target);
35-
Object.setPrototypeOf(_.prototype, target.prototype);
36-
return _;
31+
const interceptFunctions = {
32+
apply: function () {
33+
const args = arguments.length === 1 ? [] : arguments[1];
34+
return Reflect.construct(target, args, arguments[0].constructor);
35+
},
36+
call: function () {
37+
if (arguments.length === 0) {
38+
return Reflect.construct(target, []);
39+
} else {
40+
const [thisArg, ...restArgs] = arguments;
41+
return Reflect.construct(target, restArgs, thisArg.constructor);
42+
}
43+
}
44+
};
45+
return Object.assign(target, interceptFunctions);
3746
}
3847

3948
@es5ClassCompat

0 commit comments

Comments
 (0)