Skip to content

Commit b27a905

Browse files
committed
Make code snapshot-friendly
1 parent 936b796 commit b27a905

28 files changed

Lines changed: 248 additions & 225 deletions

File tree

src/vs/base/browser/dom.ts

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -251,41 +251,26 @@ export function addDisposableNonBubblingMouseOutListener(node: Element, handler:
251251
});
252252
}
253253

254-
const _animationFrame = (function () {
255-
let emulatedRequestAnimationFrame = (callback: (time: number) => void): number => {
256-
return setTimeout(() => callback(new Date().getTime()), 0);
257-
};
258-
let nativeRequestAnimationFrame: (callback: (time: number) => void) => number =
259-
self.requestAnimationFrame
260-
|| (<any>self).msRequestAnimationFrame
261-
|| (<any>self).webkitRequestAnimationFrame
262-
|| (<any>self).mozRequestAnimationFrame
263-
|| (<any>self).oRequestAnimationFrame;
264-
265-
266-
267-
let emulatedCancelAnimationFrame = (id: number) => { };
268-
let nativeCancelAnimationFrame: (id: number) => void =
269-
self.cancelAnimationFrame || (<any>self).cancelRequestAnimationFrame
270-
|| (<any>self).msCancelAnimationFrame || (<any>self).msCancelRequestAnimationFrame
271-
|| (<any>self).webkitCancelAnimationFrame || (<any>self).webkitCancelRequestAnimationFrame
272-
|| (<any>self).mozCancelAnimationFrame || (<any>self).mozCancelRequestAnimationFrame
273-
|| (<any>self).oCancelAnimationFrame || (<any>self).oCancelRequestAnimationFrame;
274-
275-
let isNative = !!nativeRequestAnimationFrame;
276-
let request = nativeRequestAnimationFrame || emulatedRequestAnimationFrame;
277-
let cancel = nativeCancelAnimationFrame || emulatedCancelAnimationFrame;
278-
279-
return {
280-
isNative: isNative,
281-
request: (callback: (time: number) => void): number => {
282-
return request(callback);
283-
},
284-
cancel: (id: number) => {
285-
return cancel(id);
286-
}
287-
};
288-
})();
254+
interface IRequestAnimationFrame {
255+
(callback: (time: number) => void): number;
256+
}
257+
let _animationFrame: IRequestAnimationFrame = null;
258+
function doRequestAnimationFrame(callback: (time: number) => void): number {
259+
if (!_animationFrame) {
260+
const emulatedRequestAnimationFrame = (callback: (time: number) => void): number => {
261+
return setTimeout(() => callback(new Date().getTime()), 0);
262+
};
263+
_animationFrame = (
264+
self.requestAnimationFrame
265+
|| (<any>self).msRequestAnimationFrame
266+
|| (<any>self).webkitRequestAnimationFrame
267+
|| (<any>self).mozRequestAnimationFrame
268+
|| (<any>self).oRequestAnimationFrame
269+
|| emulatedRequestAnimationFrame
270+
);
271+
}
272+
return _animationFrame(callback);
273+
}
289274

290275
/**
291276
* Schedule a callback to be run at the next animation frame.
@@ -375,7 +360,7 @@ class AnimationFrameQueueItem implements IDisposable {
375360

376361
if (!animFrameRequested) {
377362
animFrameRequested = true;
378-
_animationFrame.request(animationFrameRunner);
363+
doRequestAnimationFrame(animationFrameRunner);
379364
}
380365

381366
return item;
@@ -662,7 +647,13 @@ export function createStyleSheet(container: HTMLElement = document.getElementsBy
662647
return style;
663648
}
664649

665-
const sharedStyle = <any>createStyleSheet();
650+
let _sharedStyleSheet: HTMLStyleElement = null;
651+
function getSharedStyleSheet(): HTMLStyleElement {
652+
if (!_sharedStyleSheet) {
653+
_sharedStyleSheet = createStyleSheet();
654+
}
655+
return _sharedStyleSheet;
656+
}
666657

667658
function getDynamicStyleSheetRules(style: any) {
668659
if (style && style.sheet && style.sheet.rules) {
@@ -676,15 +667,15 @@ function getDynamicStyleSheetRules(style: any) {
676667
return [];
677668
}
678669

679-
export function createCSSRule(selector: string, cssText: string, style: HTMLStyleElement = sharedStyle): void {
670+
export function createCSSRule(selector: string, cssText: string, style: HTMLStyleElement = getSharedStyleSheet()): void {
680671
if (!style || !cssText) {
681672
return;
682673
}
683674

684675
(<CSSStyleSheet>style.sheet).insertRule(selector + '{' + cssText + '}', 0);
685676
}
686677

687-
export function removeCSSRulesContainingSelector(ruleName: string, style = sharedStyle): void {
678+
export function removeCSSRulesContainingSelector(ruleName: string, style: HTMLStyleElement = getSharedStyleSheet()): void {
688679
if (!style) {
689680
return;
690681
}
@@ -699,7 +690,7 @@ export function removeCSSRulesContainingSelector(ruleName: string, style = share
699690
}
700691

701692
for (let i = toDelete.length - 1; i >= 0; i--) {
702-
style.sheet.deleteRule(toDelete[i]);
693+
(<any>style.sheet).deleteRule(toDelete[i]);
703694
}
704695
}
705696

src/vs/base/common/async.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
'use strict';
77

88
import * as errors from 'vs/base/common/errors';
9-
import * as platform from 'vs/base/common/platform';
109
import { Promise, TPromise, ValueCallback, ErrorCallback, ProgressCallback } from 'vs/base/common/winjs.base';
1110
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
1211
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
@@ -525,7 +524,7 @@ export function setDisposableTimeout(handler: Function, timeout: number, ...args
525524
}
526525

527526
export class TimeoutTimer extends Disposable {
528-
private _token: platform.TimeoutToken;
527+
private _token: number;
529528

530529
constructor() {
531530
super();
@@ -539,14 +538,14 @@ export class TimeoutTimer extends Disposable {
539538

540539
cancel(): void {
541540
if (this._token !== -1) {
542-
platform.clearTimeout(this._token);
541+
clearTimeout(this._token);
543542
this._token = -1;
544543
}
545544
}
546545

547546
cancelAndSet(runner: () => void, timeout: number): void {
548547
this.cancel();
549-
this._token = platform.setTimeout(() => {
548+
this._token = setTimeout(() => {
550549
this._token = -1;
551550
runner();
552551
}, timeout);
@@ -557,7 +556,7 @@ export class TimeoutTimer extends Disposable {
557556
// timer is already set
558557
return;
559558
}
560-
this._token = platform.setTimeout(() => {
559+
this._token = setTimeout(() => {
561560
this._token = -1;
562561
runner();
563562
}, timeout);
@@ -566,7 +565,7 @@ export class TimeoutTimer extends Disposable {
566565

567566
export class IntervalTimer extends Disposable {
568567

569-
private _token: platform.IntervalToken;
568+
private _token: number;
570569

571570
constructor() {
572571
super();
@@ -580,22 +579,22 @@ export class IntervalTimer extends Disposable {
580579

581580
cancel(): void {
582581
if (this._token !== -1) {
583-
platform.clearInterval(this._token);
582+
clearInterval(this._token);
584583
this._token = -1;
585584
}
586585
}
587586

588587
cancelAndSet(runner: () => void, interval: number): void {
589588
this.cancel();
590-
this._token = platform.setInterval(() => {
589+
this._token = setInterval(() => {
591590
runner();
592591
}, interval);
593592
}
594593
}
595594

596595
export class RunOnceScheduler {
597596

598-
private timeoutToken: platform.TimeoutToken;
597+
private timeoutToken: number;
599598
private runner: () => void;
600599
private timeout: number;
601600
private timeoutHandler: () => void;
@@ -620,7 +619,7 @@ export class RunOnceScheduler {
620619
*/
621620
cancel(): void {
622621
if (this.isScheduled()) {
623-
platform.clearTimeout(this.timeoutToken);
622+
clearTimeout(this.timeoutToken);
624623
this.timeoutToken = -1;
625624
}
626625
}
@@ -630,7 +629,7 @@ export class RunOnceScheduler {
630629
*/
631630
schedule(delay = this.timeout): void {
632631
this.cancel();
633-
this.timeoutToken = platform.setTimeout(this.timeoutHandler, delay);
632+
this.timeoutToken = setTimeout(this.timeoutHandler, delay);
634633
}
635634

636635
/**

src/vs/base/common/diagnostics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function register(what: string, fn: Function): (...args: any[]) => void {
6262
const thisArguments = allArgs.shift();
6363
fn.apply(fn, thisArguments);
6464
if (allArgs.length > 0) {
65-
Platform.setTimeout(doIt, 500);
65+
setTimeout(doIt, 500);
6666
}
6767
};
6868
doIt();

src/vs/base/common/errors.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55
'use strict';
66

7-
import platform = require('vs/base/common/platform');
87
import types = require('vs/base/common/types');
98
import { IAction } from 'vs/base/common/actions';
109
import Severity from 'vs/base/common/severity';
@@ -79,7 +78,7 @@ export class ErrorHandler {
7978
this.listeners = [];
8079

8180
this.unexpectedErrorHandler = function (e: any) {
82-
platform.setTimeout(() => {
81+
setTimeout(() => {
8382
if (e.stack) {
8483
throw new Error(e.message + '\n\n' + e.stack);
8584
}

src/vs/base/common/performance.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// Because we want both instances to use the same perf-data
1212
// we store them globally
1313
// stores data as 'type','name','startTime','duration'
14-
global._performanceEntries = global._performanceEntries || [];
1514

1615
if (typeof define !== "function" && typeof module === "object" && typeof module.exports === "object") {
1716
// this is commonjs, fake amd
@@ -23,6 +22,12 @@ if (typeof define !== "function" && typeof module === "object" && typeof module.
2322

2423
define([], function () {
2524

25+
var _global = this;
26+
if (typeof global !== 'undefined') {
27+
_global = global;
28+
}
29+
_global._performanceEntries = _global._performanceEntries || [];
30+
2631
// const _now = global.performance && performance.now ? performance.now : Date.now
2732
const _now = Date.now;
2833

src/vs/base/common/platform.ts

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
*--------------------------------------------------------------------------------------------*/
55
'use strict';
66

7-
// --- THIS FILE IS TEMPORARY UNTIL ENV.TS IS CLEANED UP. IT CAN SAFELY BE USED IN ALL TARGET EXECUTION ENVIRONMENTS (node & dom) ---
8-
97
let _isWindows = false;
108
let _isMacintosh = false;
119
let _isLinux = false;
12-
let _isRootUser = false;
1310
let _isNative = false;
1411
let _isWeb = false;
1512
let _locale: string = undefined;
@@ -48,12 +45,11 @@ if (typeof process === 'object') {
4845
_isWindows = (process.platform === 'win32');
4946
_isMacintosh = (process.platform === 'darwin');
5047
_isLinux = (process.platform === 'linux');
51-
_isRootUser = !_isWindows && (process.getuid() === 0);
52-
let rawNlsConfig = process.env['VSCODE_NLS_CONFIG'];
48+
const rawNlsConfig = process.env['VSCODE_NLS_CONFIG'];
5349
if (rawNlsConfig) {
5450
try {
55-
let nlsConfig: NLSConfig = JSON.parse(rawNlsConfig);
56-
let resolved = nlsConfig.availableLanguages['*'];
51+
const nlsConfig: NLSConfig = JSON.parse(rawNlsConfig);
52+
const resolved = nlsConfig.availableLanguages['*'];
5753
_locale = nlsConfig.locale;
5854
// VSCode's default language is 'en'
5955
_language = resolved ? resolved : LANGUAGE_DEFAULT;
@@ -63,7 +59,7 @@ if (typeof process === 'object') {
6359
}
6460
_isNative = true;
6561
} else if (typeof navigator === 'object') {
66-
let userAgent = navigator.userAgent;
62+
const userAgent = navigator.userAgent;
6763
_isWindows = userAgent.indexOf('Windows') >= 0;
6864
_isMacintosh = userAgent.indexOf('Macintosh') >= 0;
6965
_isLinux = userAgent.indexOf('Linux') >= 0;
@@ -93,11 +89,14 @@ if (_isNative) {
9389
export const isWindows = _isWindows;
9490
export const isMacintosh = _isMacintosh;
9591
export const isLinux = _isLinux;
96-
export const isRootUser = _isRootUser;
9792
export const isNative = _isNative;
9893
export const isWeb = _isWeb;
9994
export const platform = _platform;
10095

96+
export function isRootUser(): boolean {
97+
return _isNative && !_isWindows && (process.getuid() === 0);
98+
}
99+
101100
/**
102101
* The language used for the user interface. The format of
103102
* the string is all lower case (e.g. zh-tw for Traditional
@@ -117,30 +116,9 @@ export const locale = _locale;
117116
*/
118117
export const translationsConfigFile = _translationsConfigFile;
119118

120-
export interface TimeoutToken {
121-
}
122-
123-
export interface IntervalToken {
124-
}
125-
126-
interface IGlobals {
127-
Worker?: any;
128-
setTimeout(callback: (...args: any[]) => void, delay: number, ...args: any[]): TimeoutToken;
129-
clearTimeout(token: TimeoutToken): void;
130-
131-
setInterval(callback: (...args: any[]) => void, delay: number, ...args: any[]): IntervalToken;
132-
clearInterval(token: IntervalToken): void;
133-
}
134-
135-
const _globals = <IGlobals>(typeof self === 'object' ? self : global);
119+
const _globals = (typeof self === 'object' ? self : typeof global === 'object' ? global : {} as any);
136120
export const globals: any = _globals;
137121

138-
export const setTimeout = _globals.setTimeout.bind(_globals);
139-
export const clearTimeout = _globals.clearTimeout.bind(_globals);
140-
141-
export const setInterval = _globals.setInterval.bind(_globals);
142-
export const clearInterval = _globals.clearInterval.bind(_globals);
143-
144122
export const enum OperatingSystem {
145123
Windows = 1,
146124
Macintosh = 2,

src/vs/base/common/winjs.base.raw.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
(function() {
99

10-
var _modules = {};
10+
var _modules = Object.create(null);//{};
1111
_modules["WinJS/Core/_WinJS"] = {};
1212

1313
var _winjs = function(moduleId, deps, factory) {
@@ -64,11 +64,24 @@ _winjs("WinJS/Core/_BaseCoreUtils", ["WinJS/Core/_Global"], function baseCoreUti
6464
return func;
6565
}
6666

67+
var actualSetImmediate = null;
68+
6769
return {
6870
hasWinRT: hasWinRT,
6971
markSupportedForProcessing: markSupportedForProcessing,
70-
_setImmediate: _Global.setImmediate ? _Global.setImmediate.bind(_Global) : function (handler) {
71-
_Global.setTimeout(handler, 0);
72+
_setImmediate: function (callback) {
73+
// BEGIN monaco change
74+
if (actualSetImmediate === null) {
75+
if (_Global.setImmediate) {
76+
actualSetImmediate = _Global.setImmediate.bind(_Global);
77+
} else if (typeof process !== 'undefined' && typeof process.nextTick === 'function') {
78+
actualSetImmediate = process.nextTick.bind(process);
79+
} else {
80+
actualSetImmediate = _Global.setTimeout.bind(_Global);
81+
}
82+
}
83+
actualSetImmediate(callback);
84+
// END monaco change
7285
}
7386
};
7487
});
@@ -2057,15 +2070,9 @@ _winjs("WinJS/Promise", ["WinJS/Core/_Base","WinJS/Promise/_StateMachine"], func
20572070
var exported = _modules["WinJS/Core/_WinJS"];
20582071

20592072
if (typeof exports === 'undefined' && typeof define === 'function' && define.amd) {
2060-
define(exported);
2073+
define([], exported);
20612074
} else {
20622075
module.exports = exported;
20632076
}
20642077

2065-
if (typeof process !== 'undefined' && typeof process.nextTick === 'function') {
2066-
_modules["WinJS/Core/_BaseCoreUtils"]._setImmediate = function(handler) {
2067-
return process.nextTick(handler);
2068-
};
2069-
}
2070-
2071-
})();
2078+
})();

0 commit comments

Comments
 (0)