forked from RubyLouvre/mmDeferred
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nextTick.html
137 lines (114 loc) · 5.09 KB
/
nextTick.html
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
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
window.onload = function() {
if (!window.console) {
window.console = {
log: function(str) {
var div = document.createElement("div")
div.innerHTML = str;
document.body.appendChild(div);
}
}
}
function useMutationObserver(a) {
var input = document.createElement("input")
var now = new Date - 0
var BrowserMutationObserver = window.MutationObserver || window.WebKitMutationObserver;
if (!BrowserMutationObserver)
return
var observer = new BrowserMutationObserver(function(mutations) {
mutations.forEach(function() {
console.log(new Date - now + " useMutationObserver")
});
});
observer.observe(input, {attributes: true});
input.setAttribute("value", Math.random())
}
useMutationObserver();
function useScriptReadystatechange() {
var now = new Date - 0;
var node = document.createElement("script");
node.onreadystatechange = node.onerror = function() {
console.log(new Date - now + " useScriptReadystatechange")
node.onreadystatechange = node.onerror = function() {
};
node.parentNode && node.parentNode.removeChild(node);
node = null;
};
// node.src = "xxx"
document.documentElement.appendChild(node);
}
useScriptReadystatechange()
function usePostMessage() {
// Installs an event handler on `global` for the `message` event: see
// * https://developer.mozilla.org/en/DOM/window.postMessage
// * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages
if (!window.postMessage)
return
function onGlobalMessage(event) {
if (typeof event.data === "string" && event.data.indexOf("usePostMessage") === 0) {
console.log(new Date - now + " usePostMessage")
}
}
if (window.addEventListener) {
window.addEventListener("message", onGlobalMessage, false);
} else {
window.attachEvent("onmessage", onGlobalMessage);
}
var now = new Date - 0;
window.postMessage("usePostMessage" + now, "*");
}
usePostMessage();
function useSetImmediate() {
if (window.setImmediate) {
var now = new Date - 0
setImmediate(function() {
console.log(new Date - now + " useSetImmediate")
});
}
}
useSetImmediate();
function useMessageChannel() {
//http://caniuse.com/channel-messaging
if (!window.MessageChannel)
return
var channel = new MessageChannel();
channel.port1.onmessage = function(event) {
if (typeof event.data === "string" && event.data.indexOf("MessageChannel") === 0) {
console.log(new Date - now + " useMessageChannel")
}
};
var now = new Date - 0
channel.port2.postMessage("MessageChannel" + now);
}
useMessageChannel();
function useImageError() {
var img = new Image();
var now = new Date - 0
img.onerror = function() {
img.onerror = function() {
}
console.log((new Date - now) + " useImageError")
img = null;
};
img.src = "data:image/png," + Math.random();
}
useImageError();
function useSetTimeout() {
var now = new Date - 0
setTimeout(function() {
console.log((new Date - now) + " useSetTimeout")
}, 0)
}
useSetTimeout()
}
</script>
</head>
<body>
<div>TODO write content</div>
</body>
</html>