forked from w3c/ServiceWorker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_worker.js
874 lines (783 loc) · 28.2 KB
/
service_worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
// This API proposal depends on:
// DOM: http://www.w3.org/TR/domcore/
// URLs: http://url.spec.whatwg.org/
// Promises: https://github.com/slightlyoff/DOMPromise/
// Shared Workers:
// http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#shared-workers
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
// Semi-private to work around TS. Not for impl.
var _RegistrationOptionList = (function () {
function _RegistrationOptionList() {
this.scope = "/*";
}
return _RegistrationOptionList;
})();
var ReloadPageEvent = (function (_super) {
__extends(ReloadPageEvent, _super);
function ReloadPageEvent() {
_super.apply(this, arguments);
}
// Delay the page unload to serialise state to storage or get user's
// permission to reload.
ReloadPageEvent.prototype.waitUntil = function (f) {
};
return ReloadPageEvent;
})(_Event);
///////////////////////////////////////////////////////////////////////////////
// The Service Worker
///////////////////////////////////////////////////////////////////////////////
var InstallPhaseEvent = (function (_super) {
__extends(InstallPhaseEvent, _super);
function InstallPhaseEvent() {
_super.apply(this, arguments);
}
// Delay treating the installing worker until the passed Promise resolves
// successfully. This is primarily used to ensure that an ServiceWorker is not
// active until all of the "core" Caches it depends on are populated.
InstallPhaseEvent.prototype.waitUntil = function (f) {
};
return InstallPhaseEvent;
})(_Event);
var InstallEvent = (function (_super) {
__extends(InstallEvent, _super);
function InstallEvent() {
_super.apply(this, arguments);
this.activeWorker = null;
}
// Ensures that the worker is used in place of existing workers for
// the currently controlled set of window instances.
// NOTE(TOSPEC): this interacts with waitUntil in the following way:
// - replacement only happens upon successful installation
// - successful installation can be delayed by waitUntil, perhaps
// by subsequent event handlers.
// - therefore, replace doesn't happen immediately.
InstallEvent.prototype.replace = function () {
};
return InstallEvent;
})(InstallPhaseEvent);
var ServiceWorkerClients = (function () {
function ServiceWorkerClients() {
}
ServiceWorkerClients.prototype.getAll = function (options) {
return new Promise(function () {
// the objects returned will be new instances every time
});
};
return ServiceWorkerClients;
})();
var ServiceWorkerClient = (function () {
function ServiceWorkerClient(url) {
// attempt to open a new tab/window to url
}
return ServiceWorkerClient;
})();
// The scope in which worker code is executed
var ServiceWorkerGlobalScope = (function (_super) {
__extends(ServiceWorkerGlobalScope, _super);
function ServiceWorkerGlobalScope() {
_super.apply(this, arguments);
}
ServiceWorkerGlobalScope.prototype.fetch = function (request) {
// Notes:
// Promise resolves as soon as headers are available
// The Response object contains a toBlob() method that returns a
// Promise for the body content.
// The toBlob() promise will reject if the response is a OpaqueResponse.
return new Promise(function (r) {
r.resolve(_defaultToBrowserHTTP(request));
});
};
return ServiceWorkerGlobalScope;
})(WorkerGlobalScope);
///////////////////////////////////////////////////////////////////////////////
// Event Worker APIs
///////////////////////////////////////////////////////////////////////////////
// http://fetch.spec.whatwg.org/#requests
var Request = (function () {
function Request(params) {
// see: http://www.w3.org/TR/XMLHttpRequest/#the-timeout-attribute
this.timeout = 0;
this.method = "GET";
// FIXME: we only provide async!
this.synchronous = false;
this.forcePreflight = false;
this.omitCredentials = false;
if (params) {
if (typeof params.timeout != "undefined") {
this.timeout = params.timeout;
}
if (typeof params.url != "undefined") {
this.url = params.url;
}
if (typeof params.synchronous != "undefined") {
this.synchronous = params.synchronous;
}
if (typeof params.forcePreflight != "undefined") {
this.forcePreflight = params.forcePreflight;
}
if (typeof params.omitCredentials != "undefined") {
this.omitCredentials = params.omitCredentials;
}
if (typeof params.method != "undefined") {
this.method = params.method;
}
if (typeof params.headers != "undefined") {
this.headers = params.headers;
}
if (typeof params.body != "undefined") {
this.body = params.body;
}
}
}
return Request;
})();
// http://fetch.spec.whatwg.org/#responses
var AbstractResponse = (function () {
function AbstractResponse() {
}
return AbstractResponse;
})();
var OpaqueResponse = (function (_super) {
__extends(OpaqueResponse, _super);
function OpaqueResponse() {
_super.apply(this, arguments);
}
Object.defineProperty(OpaqueResponse.prototype, "url", {
get: // This class represents the result of cross-origin fetched resources that are
// tainted, e.g. <img src="http://cross-origin.example/test.png">
function () {
return "";
},
enumerable: true,
configurable: true
});
return OpaqueResponse;
})(AbstractResponse);
var Response = (function (_super) {
__extends(Response, _super);
function Response(params) {
if (params) {
if (typeof params.status != "undefined") {
this.status = params.status;
}
if (typeof params.statusText != "undefined") {
this.statusText = params.statusText;
}
if (typeof params.headers != "undefined") {
this.headers = params.headers;
}
/*
// FIXME: What do we want to do about passing in the body?
if (typeof params.body != "undefined") {
this.body = params.body;
}
*/
}
_super.call(this);
}
Object.defineProperty(Response.prototype, "headers", {
get: function () {
// TODO: outline the whitelist of readable headers
return this._headers;
},
set: function (items) {
var _this = this;
if (items instanceof Map) {
items.forEach(function (value, key, map) {
return _this._headers.set(key, value);
});
} else {
for (var x in items) {
(function (x) {
if (items.hasOwnProperty(x)) {
this._headers.set(x, items[x]);
}
}).call(this, x);
}
}
},
enumerable: true,
configurable: true
});
Response.prototype.toBlob = function () {
return accepted(new Blob());
};
Response.redirect = // http://fetch.spec.whatwg.org/#dom-response-redirect
function (url, status) {
return new Response();
};
return Response;
})(AbstractResponse);
var CORSResponse = (function (_super) {
__extends(CORSResponse, _super);
function CORSResponse() {
_super.apply(this, arguments);
}
return CORSResponse;
})(Response);
var FetchEvent = (function (_super) {
__extends(FetchEvent, _super);
function FetchEvent() {
_super.call(this, "fetch", { cancelable: true, bubbles: false });
// Can be one of:
// "connect",
// "font",
// "img",
// "object",
// "script",
// "style",
// "worker",
// "popup",
// "child",
// "navigate"
// TODO: this should go on the request object
this.context = "connect";
// Has the user provided intent for the page to be reloaded fresher than
// their current view? Eg: pressing the refresh button
// Clicking a link & hitting back shouldn't be considered a reload.
// Ctrl+l enter: Left to the UA to decide
this.isReload = false;
// This is the meat of the API for most use-cases.
// If preventDefault() is not called on the event, the request is sent to
// the default browser worker. That is to say, to respond with something
// from the cache, you must preventDefault() and respond with it manually,
// digging the resource out of the cache and calling
// evt.respondWith(cachedItem).
//
// Note:
// while preventDefault() must be called synchronously to cancel the
// default, responding does not need to be synchronous. That is to say,
// you can do something async (like fetch contents, go to IDB, whatever)
// within whatever the network time out is and as long as you still have
// the FetchEvent instance, you can fulfill the request later.
this.client = null;
}
// * If a Promise is provided, it must resolve with a Response, else a
// Network Error is thrown.
// * If the request isTopLevel navigation and the return value
// is a CrossOriginResponse (an opaque response body), a Network Error is
// thrown.
// * The final URL of all successful (non network-error) responses is
// the *requested* URL.
// * Renderer-side security checks about tainting for
// x-origin content are tied to the transparency (or opacity) of
// the Response body, not URLs.
//
// respondWith(r: Promise) : void;
// respondWith(r: Response) : void;
FetchEvent.prototype.respondWith = function (r) {
if (!(r instanceof Response) || !(r instanceof Promise)) {
throw new Error("Faux NetworkError because DOM is currently b0rken");
}
this.stopImmediatePropagation();
if (r instanceof Response) {
r = new Promise(function (resolver) {
resolver.resolve(r);
});
}
r.then(_useWorkerResponse, _defaultToBrowserHTTP);
};
// "any" to make the TS compiler happy:
FetchEvent.prototype.forwardTo = function (url) {
if (!(url instanceof _URL) || typeof url != "string") {
throw new Error("Faux NetworkError because DOM is currently b0rken");
}
this.stopImmediatePropagation();
return new Promise(function (resolver) {
resolver.resolve(Response.redirect(url.toString(), {
status: 302
}));
});
};
// event.default() returns a Promise, which resolves to…
// If it's a navigation
// If the response is a redirect
// It resolves to a OpaqueResponse for the redirect
// This is tagged with "other supermagic only-for-this happytime", meaning
// this request cannot be used for anything other than a response for this
// request (cannot go into cache)
// Else resolves as fetch(event.request)
// Else
// Follow all redirects
// Tag response as "supermagic change url"
// When the page receives this response it should update the resource url to
// the response url (for base url construction etc)
FetchEvent.prototype.default = function () {
return accepted();
};
return FetchEvent;
})(_Event);
// Design notes:
// - Caches are atomic: they are not complete until all of their resources are
// fetched
// - Updates are also atomic: the old contents are visible until all new
// contents are fetched/installed.
// - Caches should have version numbers and "update" should set/replace it
// This largely describes the current Application Cache API. It's only available
// inside worker instances (not in regular documents), meaning that caching is a
// feature of the event worker. This is likely to change!
var Cache = (function () {
function Cache() {
}
// also for spec purposes only
Cache.prototype._query = function (request, params) {
params = params || {};
var ignoreSearch = Boolean(params.ignoreSearch);
var ignoreMethod = Boolean(params.ignoreMethod);
var ignoreVary = Boolean(params.ignoreVary);
var prefixMatch = Boolean(params.prefixMatch);
request = _castToRequest(request);
if (!ignoreMethod && request.method !== 'GET' && request.method !== 'HEAD') {
// we only store GET responses at the moment, so no match
return [];
}
var cachedRequests = this._items.keys().filter(function (cachedRequest) {
var cachedUrl = new _URL(cachedRequest.url);
var requestUrl = new _URL(request.url);
if (ignoreSearch) {
cachedUrl.search = '';
requestUrl.search = '';
}
if (prefixMatch) {
cachedUrl.href = cachedUrl.href.slice(0, requestUrl.href.length);
}
return cachedUrl.href != cachedUrl.href;
});
var cachedResponses = cachedRequests.map(this._items.get.bind(this._items));
var results = [];
cachedResponses.forEach(function (cachedResponse, i) {
if (!cachedResponse.headers.has('vary') || ignoreVary) {
results.push([cachedRequests[i], cachedResponse]);
return;
}
var varyHeaders = cachedResponse.headers.get('vary').split(',');
var varyHeader;
for (var j = 0; j < varyHeaders.length; j++) {
varyHeader = varyHeaders[j].trim();
if (varyHeader == '*') {
continue;
}
if (cachedRequests[i].headers.get(varyHeader) != request.headers.get(varyHeader)) {
return;
}
}
results.push([cachedRequests[i], cachedResponse]);
});
return results;
};
Cache.prototype.match = function (request, params) {
// the UA may do something more optimal than this:
return this.matchAll(request, params).then(function (responses) {
if (responses[0]) {
return responses[0];
}
throw new Error("Faux NotFoundError");
});
};
Cache.prototype.matchAll = function (request, params) {
var thisCache = this;
return accepted().then(function () {
if (request) {
return thisCache._query(request, params).map(function (requestResponse) {
return requestResponse[1];
});
} else {
return thisCache._items.values();
}
});
};
Cache.prototype.add = function (request) {
return this.addAll([request]).then(function (responses) {
return responses[0];
});
};
Cache.prototype.addAll = function (requests) {
var thisCache = this;
requests = requests.map(_castToRequest);
var responsePromises = requests.map(function (request) {
return fetch(request);
});
// wait for all our requests to complete
return Promise.all(responsePromises).then(function (responses) {
return thisCache._batch(responses.map(function (response, i) {
return { type: 'put', request: requests[i], response: response };
}));
});
};
Cache.prototype.put = function (request, response) {
var thisCache = this;
return this._batch([
{ type: 'put', request: request, response: response }
]).then(function (results) {
return results[0];
});
};
// delete zero or more entries
Cache.prototype.delete = function (request, matchParams) {
return this._batch([
{ type: 'delete', request: request, matchParams: matchParams }
]).then(function (results) {
if (results) {
return true;
} else {
return false;
}
});
};
Cache.prototype.keys = function (request, matchParams) {
var thisCache = this;
return accepted().then(function () {
if (request) {
return thisCache._query(request, matchParams).map(function (requestResponse) {
return requestResponse[0];
});
} else {
return thisCache._items.keys();
}
});
};
Cache.prototype._batch = function (operations) {
var thisCache = this;
return Promise.resolve().then(function () {
var itemsCopy = thisCache._items;
var addedRequests = [];
try {
return operations.map(function handleOperation(operation, i) {
if (operation.type != 'delete' && operation.type != 'put') {
throw TypeError("Invalid operation type");
}
if (operation.type == "delete" && operation.response) {
throw TypeError("Cannot use response for delete operations");
}
var request = _castToRequest(operation.request);
var result = thisCache._query(request, operation.matchParams).reduce(function (previousResult, requestResponse) {
if (addedRequests.indexOf(requestResponse[0]) !== -1) {
throw Error("Batch operation at index " + i + " overrode previous put operation");
}
return thisCache._items.delete(requestResponse[0]) || previousResult;
}, false);
if (operation.type == 'put') {
if (!operation.response) {
throw TypeError("Put operation must have a response");
}
if (request.method !== 'GET') {
throw TypeError("Only GET requests are supported");
}
if (operation.matchParams) {
throw TypeError("Put operation cannot have match params");
}
if (!(operation.response instanceof AbstractResponse)) {
throw TypeError("Invalid response");
}
addedRequests.push(request);
thisCache._items.set(request, operation.response);
result = operation.response;
}
return operation.response;
});
} catch (err) {
// reverse the transaction
thisCache._items = itemsCopy;
throw err;
}
});
};
return Cache;
})();
var CacheStorage = (function () {
function CacheStorage() {
}
CacheStorage.prototype.match = function (request, params) {
var cacheName;
if (params) {
cacheName = params["cacheName"];
}
function getMatchFrom(cacheName) {
return this.get(cacheName).then(function (store) {
if (!store) {
throw Error("Not found");
}
return store.match(request, params);
});
}
if (cacheName) {
return getMatchFrom(cacheName);
}
return this.keys().then(function (keys) {
return keys.reduce(function (chain, key) {
return chain.catch(function () {
return getMatchFrom(key);
});
}, Promise.reject()).catch(function () {
throw Error("No match found");
});
});
};
CacheStorage.prototype.get = function (cacheName) {
cacheName = cacheName.toString();
return Promise.resolve(this._items.get(cacheName));
};
CacheStorage.prototype.has = function (cacheName) {
cacheName = cacheName.toString();
return Promise.resolve(this._items.has(cacheName));
};
CacheStorage.prototype.create = function (cacheName) {
cacheName = cacheName.toString();
var _items = this._items;
return this.has(cacheName).then(function (storeExists) {
if (storeExists) {
throw Error("Store with that name already exists");
}
var cache = new Cache();
_items.set(cacheName, cache);
return cache;
});
};
CacheStorage.prototype.delete = function (cacheName) {
cacheName = cacheName.toString();
if (this._items.delete(cacheName)) {
return Promise.resolve(true);
} else {
return Promise.resolve(false);
}
};
CacheStorage.prototype.keys = function () {
return Promise.resolve(this._items.keys());
};
return CacheStorage;
})();
////////////////////////////////////////////////////////////////////////////////
// Utility Decls to make the TypeScript compiler happy
////////////////////////////////////////////////////////////////////////////////
// See:
// http://www.whatwg.org/specs/web-apps/current-work/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts
var BroadcastChannel = (function () {
function BroadcastChannel(channelName) {
}
return BroadcastChannel;
})();
;
var WorkerGlobalScope = (function (_super) {
__extends(WorkerGlobalScope, _super);
function WorkerGlobalScope() {
_super.apply(this, arguments);
}
WorkerGlobalScope.prototype.setTimeout = function (handler, timeout) {
var args = [];
for (var _i = 0; _i < (arguments.length - 2); _i++) {
args[_i] = arguments[_i + 2];
}
return 0;
};
WorkerGlobalScope.prototype.setInterval = function (handler, timeout) {
var args = [];
for (var _i = 0; _i < (arguments.length - 2); _i++) {
args[_i] = arguments[_i + 2];
}
return 0;
};
// WindowTimerExtensions
WorkerGlobalScope.prototype.msSetImmediate = function (expression) {
var args = [];
for (var _i = 0; _i < (arguments.length - 1); _i++) {
args[_i] = arguments[_i + 1];
}
return 0;
};
WorkerGlobalScope.prototype.setImmediate = function (expression) {
var args = [];
for (var _i = 0; _i < (arguments.length - 1); _i++) {
args[_i] = arguments[_i + 1];
}
return 0;
};
// WindowBase64
WorkerGlobalScope.prototype.btoa = function (rawString) {
return "";
};
WorkerGlobalScope.prototype.atob = function (encodedString) {
return "";
};
return WorkerGlobalScope;
})(_EventTarget);
// Cause, you know, the stock definition claims that URL isn't a class. FML.
var _URL = (function () {
function _URL(url) {
}
Object.defineProperty(_URL.prototype, "search", {
get: function () {
return "";
},
enumerable: true,
configurable: true
});
Object.defineProperty(_URL.prototype, "pathname", {
get: function () {
return "";
},
enumerable: true,
configurable: true
});
Object.defineProperty(_URL.prototype, "href", {
get: function () {
return "";
},
enumerable: true,
configurable: true
});
return _URL;
})();
// http://tc39wiki.calculist.org/es6/map-set/
// http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets
// http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts
// http://people.mozilla.org/~jorendorff/es6-draft.html#sec-15.14.4
var _ES6Map = (function () {
function _ES6Map(iterable) {
}
_ES6Map.prototype.get = function (key) {
};
_ES6Map.prototype.has = function (key) {
return true;
};
_ES6Map.prototype.set = function (key, val) {
return new _ES6Map();
};
_ES6Map.prototype.clear = function () {
};
_ES6Map.prototype.delete = function (key) {
return true;
};
_ES6Map.prototype.forEach = function (callback, thisArg) {
};
_ES6Map.prototype.entries = function () {
return [];
};
_ES6Map.prototype.keys = function () {
return [];
};
_ES6Map.prototype.values = function () {
return [];
};
return _ES6Map;
})();
// the TS compiler is unhappy *both* with re-defining DOM types and with direct
// sublassing of most of them. This is sane (from a regular TS pespective), if
// frustrating. As a result, we describe the built-in Event type with a prefixed
// name so that we can subclass it later.
var _Event = (function () {
function _Event(type, eventInitDict) {
this.bubbles = false;
this.cancelable = true;
this.defaultPrevented = false;
this.isTrusted = false;
}
_Event.prototype.stopPropagation = function () {
};
_Event.prototype.stopImmediatePropagation = function () {
};
_Event.prototype.preventDefault = function () {
};
return _Event;
})();
var _CustomEvent = (function (_super) {
__extends(_CustomEvent, _super);
// Constructor(DOMString type, optional EventInit eventInitDict
function _CustomEvent(type, eventInitDict) {
_super.call(this, type, eventInitDict);
}
return _CustomEvent;
})(_Event);
var _EventTarget = (function () {
function _EventTarget() {
}
_EventTarget.prototype.dispatchEvent = function (e) {
return true;
};
return _EventTarget;
})();
// https://github.com/slightlyoff/DOMPromise/blob/master/DOMPromise.idl
var Resolver = (function () {
function Resolver() {
}
Resolver.prototype.accept = function (v) {
};
Resolver.prototype.reject = function (v) {
};
Resolver.prototype.resolve = function (v) {
};
return Resolver;
})();
var Promise = (function () {
// Callback type decl:
// callback : (n : number) => number
function Promise(init) {
}
Promise.prototype.then = function (fulfilled) {
return accepted();
};
Promise.prototype.catch = function (rejected) {
return accepted();
};
Promise.all = function () {
var stuff = [];
for (var _i = 0; _i < (arguments.length - 0); _i++) {
stuff[_i] = arguments[_i + 0];
}
return accepted();
};
Promise.resolve = function (val) {
return new Promise(function (r) {
r.accept(val);
});
};
Promise.reject = function (err) {
return new Promise(function (r) {
r.reject(err);
});
};
return Promise;
})();
function accepted(v) {
if (typeof v === "undefined") { v = true; }
return new Promise(function (r) {
r.accept(true);
});
}
function acceptedResponse() {
return new Promise(function (r) {
r.accept(new Response());
});
}
function fetch(url) {
return acceptedResponse();
}
// http://www.whatwg.org/specs/web-apps/current-work/multipage/workers.html#shared-workers-and-the-sharedworker-interface
var SharedWorker = (function (_super) {
__extends(SharedWorker, _super);
function SharedWorker(url, name) {
_super.call(this);
}
return SharedWorker;
})(_EventTarget);
////////////////////////////////////////////////////////////////////////////////
// Not part of any public standard but used above:
////////////////////////////////////////////////////////////////////////////////
var _useWorkerResponse = function () {
return accepted();
};
var _defaultToBrowserHTTP = function (url) {
return accepted();
};
function _castToRequest(request) {
if (!(request instanceof Request)) {
request = new Request({
'url': new _URL(request).href
});
}
return request;
}