-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathindex.nodom.amp.ts
More file actions
43 lines (36 loc) · 1.65 KB
/
Copy pathindex.nodom.amp.ts
File metadata and controls
43 lines (36 loc) · 1.65 KB
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
import { HydrateFunction } from './hydrate.js';
import { AMP } from './amp/amp.js';
import { callFunctionMessageHandler, exportFunction } from './function.js';
import { WorkerNoDOMGlobalScope } from './WorkerDOMGlobalScope.js';
import { DocumentStub } from './dom/DocumentStub.js';
import { deleteGlobals } from './amp/delete-globals.js';
import { initializeStorage } from './initialize-storage.js';
import { WorkerStorageInit } from './initialize-storage.js';
const noop = () => void 0;
export const workerDOM: WorkerNoDOMGlobalScope = (function (postMessage, addEventListener, removeEventListener) {
const document = new DocumentStub();
// TODO(choumx): Avoid polluting Document's public API.
document.postMessage = postMessage;
document.addGlobalEventListener = addEventListener;
document.removeGlobalEventListener = removeEventListener;
return document.defaultView;
})(postMessage.bind(self) || noop, addEventListener.bind(self) || noop, removeEventListener.bind(self) || noop);
// Modify global scope by removing disallowed properties.
deleteGlobals(self);
// Offer APIs like AMP.setState() on the global scope.
(self as any).AMP = new AMP(workerDOM.document);
// Allows for function invocation
(self as any).exportFunction = exportFunction;
addEventListener('message', (evt: MessageEvent) => callFunctionMessageHandler(evt, workerDOM.document));
export const hydrate: HydrateFunction = (
document: DocumentStub,
strings: {},
hydrateableNode: {},
cssKeys: {},
globalEventHandlerKeys: {},
size: {},
localStorageInit: WorkerStorageInit,
sessionStorageInit: WorkerStorageInit,
) => {
initializeStorage(document, localStorageInit, sessionStorageInit);
};