OLD | NEW |
| (Empty) |
1 var msg = decodeURIComponent(location.hash.substr(1)); | |
2 | |
3 var log = []; | |
4 function check_true(actual, msg) { | |
5 if (actual !== true) { | |
6 log.push(msg); | |
7 return false; | |
8 } | |
9 return true; | |
10 } | |
11 | |
12 function check_Blob(msg, input, port, expect_File, orig_input) { | |
13 expect_File = !!expect_File; | |
14 orig_input = orig_input || input; | |
15 try { | |
16 var expected; | |
17 switch (msg) { | |
18 case 'Blob basic': | |
19 case 'File basic': | |
20 expected = [0x66, 0x6F, 0x6F]; | |
21 expected.type = 'text/x-bar'; | |
22 if (expect_File) { | |
23 expected.name = 'bar'; | |
24 expected.lastModified = 42; | |
25 } | |
26 break; | |
27 case 'Blob unpaired high surrogate (invalid utf-8)': | |
28 expected = [0xED, 0xA0, 0x80]; | |
29 expected.type = ''; | |
30 break; | |
31 case 'Blob unpaired low surrogate (invalid utf-8)': | |
32 expected = [0xED, 0xB0, 0x80]; | |
33 expected.type = ''; | |
34 break; | |
35 case 'Blob paired surrogates (invalid utf-8)': | |
36 expected = [0xED, 0xA0, 0x80, 0xED, 0xB0, 0x80]; | |
37 expected.type = ''; | |
38 break; | |
39 case 'Blob empty': | |
40 expected = []; | |
41 expected.type = ''; | |
42 break; | |
43 case 'Blob NUL': | |
44 var expected = [0x00]; | |
45 expected.type = ''; | |
46 break; | |
47 default: | |
48 check_true(false, 'check_Blob: unknown test'); | |
49 return; | |
50 break; | |
51 } | |
52 if (check_true(input instanceof Blob, 'input instanceof Blob') && | |
53 check_true((input instanceof File) == expect_File, '(input instanceof Fi
le) == expect_File') && | |
54 check_true(input.size === expected.length, 'input.size === expected.leng
th') && | |
55 check_true(input.type === expected.type, 'input.type === expected.type')
) { | |
56 if (!expect_File || (check_true(input.name === expected.name, 'input.name
=== expected.name') && | |
57 check_true(input.lastModified === expected.lastModifi
ed))) { | |
58 var reader = new FileReader(); | |
59 var read_done = function() { | |
60 try { | |
61 var result = reader.result; | |
62 check_true(result.byteLength === expected.length, 'result.byteLength
=== expected.length') | |
63 var view = new DataView(result); | |
64 for (var i = 0; i < result.byteLength; ++i) { | |
65 check_true(view.getUint8(i) === expected[i], 'view.getUint8('+i+')
=== expected['+i+']') | |
66 } | |
67 if (log.length === 0) { | |
68 port.postMessage(orig_input); | |
69 } else { | |
70 port.postMessage('FAIL '+log); | |
71 } | |
72 close(); | |
73 } catch(ex) { | |
74 postMessage('FAIL '+ex); | |
75 close(); | |
76 } | |
77 } | |
78 var read_error = function() { port.postMessage('FAIL (got FileReader err
or)'); close(); }; | |
79 reader.readAsArrayBuffer(input); | |
80 reader.onload = read_done; | |
81 reader.onabort = reader.onerror = read_error; | |
82 } | |
83 } else { | |
84 port.postMessage('FAIL '+log); | |
85 close(); | |
86 } | |
87 } catch(ex) { | |
88 postMessage('FAIL '+ex); | |
89 close(); | |
90 } | |
91 } | |
92 | |
93 function check_ImageData(input, expected) { | |
94 if (check_true(input instanceof ImageData, 'input instanceof ImageData') && | |
95 check_true(input.width === expected.width, 'input.width === '+expected.wid
th) && | |
96 check_true(input.height === expected.height, 'input.height === '+expected.
height) && | |
97 check_true(input.data instanceof Uint8ClampedArray, 'input.data instanceof
Uint8ClampedArray') && | |
98 check_true(input.data.length === expected.data.length, 'input.data.length
=== '+expected.data.length) && | |
99 check_true(!('CanvasPixelArray' in self), "!('CanvasPixelArray' in self)")
) { | |
100 for (var i = 0; i < input.length; ++i) { | |
101 if (!(check_true(input.data[i] === expected.data[i], 'input.data['+i+'] ==
= '+expected.data[i]))) { | |
102 return false; | |
103 } | |
104 } | |
105 return true; | |
106 } | |
107 return false; | |
108 } | |
109 | |
110 function check_ImageBitmap(input, expected) { | |
111 return check_true(input instanceof ImageBitmap, 'input instanceof ImageBitmap'
); | |
112 // XXX paint it on a proxy canvas and check the data | |
113 } | |
114 | |
115 function check_RegExp(msg, input) { | |
116 // XXX ES6 spec doesn't define exact serialization for `source` (it allows sev
eral ways to escape) | |
117 switch (msg) { | |
118 case 'RegExp flags and lastIndex': | |
119 return check_true(input instanceof RegExp, "input instanceof RegExp") && | |
120 check_true(input.source === 'foo', "input.source === 'foo'") && | |
121 check_true(input.global === true, "input.global === true") && | |
122 check_true(input.ignoreCase === true, "input.ignoreCase === true")
&& | |
123 check_true(input.multiline === true, "input.multiline === true") && | |
124 check_true(input.lastIndex === 0, "input.lastIndex === 0"); | |
125 break; | |
126 case 'RegExp sticky flag': | |
127 return check_true(input instanceof RegExp, "input instanceof RegExp") && | |
128 check_true(input.source === 'foo', "input.source === 'foo'") && | |
129 check_true(input.global === false, "input.global === false") && | |
130 check_true(input.ignoreCase === false, "input.ignoreCase === false"
) && | |
131 check_true(input.multiline === false, "input.multiline === false")
&& | |
132 check_true(input.sticky === true, "input.sticky === true") && | |
133 check_true(input.unicode === false, "input.unicode === false") && | |
134 check_true(input.lastIndex === 0, "input.lastIndex === 0"); | |
135 break; | |
136 case 'RegExp unicode flag': | |
137 return check_true(input instanceof RegExp, "input instanceof RegExp") && | |
138 check_true(input.source === 'foo', "input.source === 'foo'") && | |
139 check_true(input.global === false, "input.global === false") && | |
140 check_true(input.ignoreCase === false, "input.ignoreCase === false"
) && | |
141 check_true(input.multiline === false, "input.multiline === false")
&& | |
142 check_true(input.sticky === false, "input.sticky === false") && | |
143 check_true(input.unicode === true, "input.unicode === true") && | |
144 check_true(input.lastIndex === 0, "input.lastIndex === 0"); | |
145 break; | |
146 case 'RegExp empty': | |
147 return check_true(input instanceof RegExp, "input instanceof RegExp") && | |
148 check_true(input.source === '(?:)', "input.source === '(?:)'") && | |
149 check_true(input.global === false, "input.global === false") && | |
150 check_true(input.ignoreCase === false, "input.ignoreCase === false"
) && | |
151 check_true(input.multiline === false, "input.multiline === false")
&& | |
152 check_true(input.lastIndex === 0, "input.lastIndex === 0"); | |
153 break; | |
154 case 'RegExp slash': | |
155 return check_true(input instanceof RegExp, "input instanceof RegExp") && | |
156 check_true(input.source === '\\/', "input.source === '\\\\/'") && | |
157 check_true(input.global === false, "input.global === false") && | |
158 check_true(input.ignoreCase === false, "input.ignoreCase === false"
) && | |
159 check_true(input.multiline === false, "input.multiline === false")
&& | |
160 check_true(input.lastIndex === 0, "input.lastIndex === 0"); | |
161 break; | |
162 case 'RegExp new line': | |
163 return check_true(input instanceof RegExp, "input instanceof RegExp") && | |
164 check_true(input.source === '\\n', "input.source === '\\\\n'") && | |
165 check_true(input.global === false, "input.global === false") && | |
166 check_true(input.ignoreCase === false, "input.ignoreCase === false"
) && | |
167 check_true(input.multiline === false, "input.multiline === false")
&& | |
168 check_true(input.lastIndex === 0, "input.lastIndex === 0"); | |
169 break; | |
170 default: | |
171 check_true(false, 'check_RegExp: unknown test'); | |
172 return false; | |
173 break; | |
174 } | |
175 } | |
176 | |
177 function check_FileList(msg, input) { | |
178 try { | |
179 return check_true(input instanceof FileList, 'input instanceof FileList') && | |
180 check_true(input.length === 0, 'input.length === 0'); | |
181 } catch(ex) { | |
182 return check_true(false, ex); | |
183 } | |
184 } | |
185 | |
186 function check(input, port) { | |
187 try { | |
188 switch (msg) { | |
189 case 'primitive undefined': | |
190 if (check_true(input === undefined, 'input === undefined')) { | |
191 port.postMessage(input); | |
192 close(); | |
193 } | |
194 break; | |
195 case 'primitive null': | |
196 if (check_true(input === null, 'input === null')) { | |
197 port.postMessage(input); | |
198 close(); | |
199 } | |
200 break; | |
201 case 'primitive true': | |
202 if (check_true(input === true, 'input === true')) { | |
203 port.postMessage(input); | |
204 close(); | |
205 } | |
206 break; | |
207 case 'primitive false': | |
208 if (check_true(input === false, 'input === false')) { | |
209 port.postMessage(input); | |
210 close(); | |
211 } | |
212 break; | |
213 case 'primitive string, empty string': | |
214 if (check_true(input === '', "input === ''")) { | |
215 port.postMessage(input); | |
216 close(); | |
217 } | |
218 break; | |
219 case 'primitive string, lone high surrogate': | |
220 if (check_true(input === '\uD800', "input === '\uD800'")) { | |
221 port.postMessage(input); | |
222 close(); | |
223 } | |
224 break; | |
225 case 'primitive string, lone low surrogate': | |
226 if (check_true(input === '\uDC00', "input === '\uDC00'")) { | |
227 port.postMessage(input); | |
228 close(); | |
229 } | |
230 break; | |
231 case 'primitive string, NUL': | |
232 if (check_true(input === '\u0000', "input === '\u0000'")) { | |
233 port.postMessage(input); | |
234 close(); | |
235 } | |
236 break; | |
237 case 'primitive string, astral character': | |
238 if (check_true(input === '\uDBFF\uDFFD', "input === '\uDBFF\uDFFD'")) { | |
239 port.postMessage(input); | |
240 close(); | |
241 } | |
242 break; | |
243 case 'primitive number, 0.2': | |
244 if (check_true(input === 0.2, "input === 0.2")) { | |
245 port.postMessage(input); | |
246 close(); | |
247 } | |
248 break; | |
249 case 'primitive number, 0': | |
250 if (check_true(input === 0, "input === 0") && | |
251 check_true(1/input === Infinity, "1/input === Infinity")) { | |
252 port.postMessage(input); | |
253 close(); | |
254 } | |
255 break; | |
256 case 'primitive number, -0': | |
257 if (check_true(input === 0, "input === 0") && | |
258 check_true(1/input === -Infinity, "1/input === -Infinity")) { | |
259 port.postMessage(input); | |
260 close(); | |
261 } | |
262 break; | |
263 case 'primitive number, NaN': | |
264 if (check_true(input !== input, "input !== input")) { | |
265 port.postMessage(input); | |
266 close(); | |
267 } | |
268 break; | |
269 case 'primitive number, Infinity': | |
270 if (check_true(input === Infinity, "input === Infinity")) { | |
271 port.postMessage(input); | |
272 close(); | |
273 } | |
274 break; | |
275 case 'primitive number, -Infinity': | |
276 if (check_true(input === -Infinity, "input === -Infinity")) { | |
277 port.postMessage(input); | |
278 close(); | |
279 } | |
280 break; | |
281 case 'primitive number, 9007199254740992': | |
282 if (check_true(input === 9007199254740992, "input === 9007199254740992")
) { | |
283 port.postMessage(input); | |
284 close(); | |
285 } | |
286 break; | |
287 case 'primitive number, -9007199254740992': | |
288 if (check_true(input === -9007199254740992, "input === -9007199254740992
")) { | |
289 port.postMessage(input); | |
290 close(); | |
291 } | |
292 break; | |
293 case 'primitive number, 9007199254740994': | |
294 if (check_true(input === 9007199254740994, "input === 9007199254740994")
) { | |
295 port.postMessage(input); | |
296 close(); | |
297 } | |
298 break; | |
299 case 'primitive number, -9007199254740994': | |
300 if (check_true(input === -9007199254740994, "input === -9007199254740994
")) { | |
301 port.postMessage(input); | |
302 close(); | |
303 break; | |
304 } | |
305 case 'Array primitives': | |
306 if (check_true(input instanceof Array, 'input instanceof Array') && | |
307 check_true(input.length === 19, 'input.length === 19') && | |
308 check_true(input[0] === undefined, 'input[0] === undefined') && | |
309 check_true(input[1] === null, 'input[1] === null') && | |
310 check_true(input[2] === true, 'input[2] === true') && | |
311 check_true(input[3] === false, 'input[3] === false') && | |
312 check_true(input[4] === '', "input[4] === ''") && | |
313 check_true(input[5] === '\uD800', "input[5] === '\\uD800'") && | |
314 check_true(input[6] === '\uDC00', "input[6] === '\\uDC00'") && | |
315 check_true(input[7] === '\u0000', "input[7] === '\\u0000'") && | |
316 check_true(input[8] === '\uDBFF\uDFFD', "input[8] === '\\uDBFF\\uDFF
D'") && | |
317 check_true(input[9] === 0.2, "input[9] === 0.2") && | |
318 check_true(1/input[10] === Infinity, "1/input[10] === Infinity") && | |
319 check_true(1/input[11] === -Infinity, "1/input[11] === -Infinity") &
& | |
320 check_true(input[12] !== input[11], "input[12] !== input[11]") && | |
321 check_true(input[13] === Infinity, "input[13] === Infinity") && | |
322 check_true(input[14] === -Infinity, "input[14] === -Infinity") && | |
323 check_true(input[15] === 9007199254740992, "input[15] === 9007199254
740992") && | |
324 check_true(input[16] === -9007199254740992, "input[16] === -90071992
54740992") && | |
325 check_true(input[17] === 9007199254740994, "input[17] === 9007199254
740994") && | |
326 check_true(input[18] === -9007199254740994, "input[18] === -90071992
54740994")) { | |
327 port.postMessage(input); | |
328 close(); | |
329 } | |
330 break; | |
331 case 'Object primitives': | |
332 (function() { | |
333 if (check_true(input instanceof Object, 'input instanceof Object') && | |
334 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
335 check_true(input['undefined'] === undefined, "input['undefined'] =
== undefined") && | |
336 check_true(input['null'] === null, "input['null'] === null") && | |
337 check_true(input['true'] === true, "input['true'] === true") && | |
338 check_true(input['false'] === false, "input['false'] === false") &
& | |
339 check_true(input['empty'] === '', "input['empty'] === ''") && | |
340 check_true(input['high surrogate'] === '\uD800', "input['high surr
ogate'] === '\uD800'") && | |
341 check_true(input['low surrogate'] === '\uDC00', "input['low surrog
ate'] === '\uDC00'") && | |
342 check_true(input['nul'] === '\u0000', "input['nul'] === '\u0000'")
&& | |
343 check_true(input['astral'] === '\uDBFF\uDFFD', "input['astral'] ==
= '\uDBFF\uDFFD'") && | |
344 check_true(input['0.2'] === 0.2, "input['0.2'] === 0.2") && | |
345 check_true(1/input['0'] === Infinity, "1/input['0'] === Infinity")
&& | |
346 check_true(1/input['-0'] === -Infinity, "1/input['-0'] === -Infini
ty") && | |
347 check_true(input['NaN'] !== input['NaN'], "input['NaN'] !== input[
'NaN']") && | |
348 check_true(input['Infinity'] === Infinity, "input['Infinity'] ===
Infinity") && | |
349 check_true(input['-Infinity'] === -Infinity, "input['-Infinity'] =
== -Infinity") && | |
350 check_true(input['9007199254740992'] === 9007199254740992, "input[
'9007199254740992'] === 9007199254740992") && | |
351 check_true(input['-9007199254740992'] === -9007199254740992, "inpu
t['-9007199254740992'] === -9007199254740992") && | |
352 check_true(input['9007199254740994'] === 9007199254740994, "input[
'9007199254740994'] === 9007199254740994") && | |
353 check_true(input['-9007199254740994'] === -9007199254740994, "inpu
t['9007199254740994'] === -9007199254740994")) { | |
354 var i = 0; | |
355 for (var x in input) { | |
356 i++; | |
357 } | |
358 if (check_true(i === 19, 'i === 19')) { | |
359 port.postMessage(input); | |
360 close(); | |
361 } | |
362 } | |
363 })(); | |
364 break; | |
365 case 'Boolean true': | |
366 if (check_true(input instanceof Boolean, "input instanceof Boolean") && | |
367 check_true(String(input) === 'true', "String(input) === 'true'")) { | |
368 port.postMessage(input); | |
369 close(); | |
370 } | |
371 break; | |
372 case 'Boolean false': | |
373 if (check_true(input instanceof Boolean, "input instanceof Boolean") && | |
374 check_true(String(input) === 'false', "String(input) === 'false'"))
{ | |
375 port.postMessage(input); | |
376 close(); | |
377 } | |
378 break; | |
379 case 'Array Boolean objects': | |
380 (function() { | |
381 if (check_true(input instanceof Array, 'input instanceof Array') && | |
382 check_true(input.length === 2, 'input.length === 2') && | |
383 check_true(String(input[0]) === 'true', "String(input[0]) === 'tru
e'") && | |
384 check_true(String(input[1]) === 'false', "String(input[1]) === 'fa
lse'")) { | |
385 for (var i = 0; i < input.length; ++i) { | |
386 if (!check_true(input[i] instanceof Boolean, 'input['+i+'] instanc
eof Boolean')) | |
387 return; | |
388 } | |
389 port.postMessage(input); | |
390 close(); | |
391 } | |
392 })(); | |
393 break; | |
394 case 'Object Boolean objects': | |
395 (function() { | |
396 if (check_true(input instanceof Object, 'input instanceof Object') && | |
397 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
398 check_true(String(input['true']) === 'true', "String(input['true']
) === 'true'") && | |
399 check_true(String(input['false']) === 'false', "String(input['fals
e']) === 'false'")) { | |
400 var i = 0; | |
401 for (var x in input) { | |
402 i++; | |
403 if (!check_true(input[x] instanceof Boolean, 'input['+x+'] instanc
eof Boolean')) | |
404 return; | |
405 } | |
406 if (check_true(i === 2, 'i === 2')) { | |
407 port.postMessage(input); | |
408 close(); | |
409 } | |
410 } | |
411 })(); | |
412 break; | |
413 case 'String empty string': | |
414 if (check_true(input instanceof String, "input instanceof String") && | |
415 check_true(String(input) === '', "String(input) === ''")) { | |
416 port.postMessage(input); | |
417 close(); | |
418 } | |
419 break; | |
420 case 'String lone high surrogate': | |
421 if (check_true(input instanceof String, "input instanceof String") && | |
422 check_true(String(input) === '\uD800', "String(input) === '\\uD800'"
)) { | |
423 port.postMessage(input); | |
424 close(); | |
425 } | |
426 break; | |
427 case 'String lone low surrogate': | |
428 if (check_true(input instanceof String, "input instanceof String") && | |
429 check_true(String(input) === '\uDC00', "String(input) === '\\uDC00'"
)) { | |
430 port.postMessage(input); | |
431 close(); | |
432 } | |
433 break; | |
434 case 'String NUL': | |
435 if (check_true(input instanceof String, "input instanceof String") && | |
436 check_true(String(input) === '\u0000', "String(input) === '\\u0000'"
)) { | |
437 port.postMessage(input); | |
438 close(); | |
439 } | |
440 break; | |
441 case 'String astral character': | |
442 if (check_true(input instanceof String, "input instanceof String") && | |
443 check_true(String(input) === '\uDBFF\uDFFD', "String(input) === '\\u
DBFF\\uDFFD'")) { | |
444 port.postMessage(input); | |
445 close(); | |
446 } | |
447 break; | |
448 case 'Array String objects': | |
449 (function() { | |
450 if (check_true(input instanceof Array, 'input instanceof Array') && | |
451 check_true(input.length === 5, 'input.length === 5') && | |
452 check_true(String(input[0]) === '', "String(input[0]) === ''") && | |
453 check_true(String(input[1]) === '\uD800', "String(input[1]) === '\
\uD800'") && | |
454 check_true(String(input[2]) === '\uDC00', "String(input[1]) === '\
\uDC00'") && | |
455 check_true(String(input[3]) === '\u0000', "String(input[2]) === '\
\u0000'") && | |
456 check_true(String(input[4]) === '\uDBFF\uDFFD', "String(input[3])
=== '\\uDBFF\\uDFFD'")) { | |
457 for (var i = 0; i < input.length; ++i) { | |
458 if (!check_true(input[i] instanceof String, 'input['+i+'] instance
of String')) | |
459 return; | |
460 } | |
461 port.postMessage(input); | |
462 close(); | |
463 } | |
464 })(); | |
465 break; | |
466 case 'Object String objects': | |
467 (function() { | |
468 if (check_true(input instanceof Object, 'input instanceof Object') && | |
469 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
470 check_true(String(input['empty']) === '', "String(input['empty'])
=== ''") && | |
471 check_true(String(input['high surrogate']) === '\uD800', "String(i
nput['high surrogate']) === '\\uD800'") && | |
472 check_true(String(input['low surrogate']) === '\uDC00', "String(in
put['low surrogate']) === '\\uDC00'") && | |
473 check_true(String(input['nul']) === '\u0000', "String(input['nul']
) === '\\u0000'") && | |
474 check_true(String(input['astral']) === '\uDBFF\uDFFD', "String(inp
ut['astral']) === '\\uDBFF\\uDFFD'")) { | |
475 var i = 0; | |
476 for (var x in input) { | |
477 i++; | |
478 if (!check_true(input[x] instanceof String, 'input['+x+'] instance
of Boolean')) | |
479 return; | |
480 } | |
481 if (check_true(i === 5, 'i === 5')) { | |
482 port.postMessage(input); | |
483 close(); | |
484 } | |
485 } | |
486 })(); | |
487 break; | |
488 case 'Number 0.2': | |
489 if (check_true(input instanceof Number, "input instanceof Number") && | |
490 check_true(Number(input) === 0.2, "Number(input) === 0.2")) { | |
491 port.postMessage(input); | |
492 close(); | |
493 } | |
494 break; | |
495 case 'Number 0': | |
496 if (check_true(input instanceof Number, "input instanceof Number") && | |
497 check_true(1/Number(input) === Infinity, "1/Number(input) === Infini
ty")) { | |
498 port.postMessage(input); | |
499 close(); | |
500 } | |
501 break; | |
502 case 'Number -0': | |
503 if (check_true(input instanceof Number, "input instanceof Number") && | |
504 check_true(1/Number(input) === -Infinity, "1/Number(input) === -Infi
nity")) { | |
505 port.postMessage(input); | |
506 close(); | |
507 } | |
508 break; | |
509 case 'Number NaN': | |
510 if (check_true(input instanceof Number, "input instanceof Number") && | |
511 check_true(Number(input) !== Number(input), "Number(input) !== Numbe
r(input)")) { | |
512 port.postMessage(input); | |
513 close(); | |
514 } | |
515 break; | |
516 case 'Number Infinity': | |
517 if (check_true(input instanceof Number, "input instanceof Number") && | |
518 check_true(Number(input) === Infinity, "Number(input) === Infinity")
) { | |
519 port.postMessage(input); | |
520 close(); | |
521 } | |
522 break; | |
523 case 'Number -Infinity': | |
524 if (check_true(input instanceof Number, "input instanceof Number") && | |
525 check_true(Number(input) === -Infinity, "Number(input) === -Infinity
")) { | |
526 port.postMessage(input); | |
527 close(); | |
528 } | |
529 break; | |
530 case 'Number 9007199254740992': | |
531 if (check_true(input instanceof Number) && | |
532 check_true(Number(input) === 9007199254740992, "Number(input) === 90
07199254740992")) { | |
533 port.postMessage(input); | |
534 close(); | |
535 } | |
536 break; | |
537 case 'Number -9007199254740992': | |
538 if (check_true(input instanceof Number, "input instanceof Number") && | |
539 check_true(Number(input) === -9007199254740992, "Number(input) === -
9007199254740992")) { | |
540 port.postMessage(input); | |
541 close(); | |
542 } | |
543 break; | |
544 case 'Number 9007199254740994': | |
545 if (check_true(input instanceof Number, "input instanceof Number") && | |
546 check_true(Number(input) === 9007199254740994, "Number(input) === 90
07199254740994")) { | |
547 port.postMessage(input); | |
548 close(); | |
549 } | |
550 break; | |
551 case 'Number -9007199254740994': | |
552 if (check_true(input instanceof Number, "input instanceof Number") && | |
553 check_true(Number(input) === -9007199254740994, "Number(input) === -
9007199254740994")) { | |
554 port.postMessage(input); | |
555 close(); | |
556 } | |
557 break; | |
558 case 'Array Number objects': | |
559 (function() { | |
560 if (check_true(input instanceof Array, 'input instanceof Array') && | |
561 check_true(input.length === 10, 'input.length === 10') && | |
562 check_true(Number(input[0]) === 0.2, "Number(input[0]) === 0.2") &
& | |
563 check_true(1/Number(input[1]) === Infinity, "1/Number(input[1]) ==
= Infinity") && | |
564 check_true(1/Number(input[2]) === -Infinity, "1/Number(input[2]) =
== -Infinity") && | |
565 check_true(Number(input[3]) !== Number(input[3]), "Number(input[3]
) !== Number(input[3])") && | |
566 check_true(Number(input[4]) === Infinity, "Number(input[4]) === In
finity") && | |
567 check_true(Number(input[5]) === -Infinity, "Number(input[5]) === -
Infinity") && | |
568 check_true(Number(input[6]) === 9007199254740992, "Number(input[6]
) === 9007199254740992") && | |
569 check_true(Number(input[7]) === -9007199254740992, "Number(input[7
]) === -9007199254740992") && | |
570 check_true(Number(input[8]) === 9007199254740994, "Number(input[8]
) === 9007199254740994") && | |
571 check_true(Number(input[9]) === -9007199254740994, "Number(input[9
]) === -9007199254740994")) { | |
572 for (var i = 0; i < input.length; ++i) { | |
573 if (!check_true(input[i] instanceof Number, 'input['+i+'] instance
of Number')) | |
574 return; | |
575 } | |
576 port.postMessage(input); | |
577 close(); | |
578 } | |
579 })(); | |
580 break; | |
581 case 'Object Number objects': | |
582 (function() { | |
583 if (check_true(input instanceof Object, 'input instanceof Object') && | |
584 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
585 check_true(Number(input['0.2']) === 0.2, "Number(input['0.2']) ===
0.2") && | |
586 check_true(1/Number(input['0']) === Infinity, "1/Number(input['0']
) === Infinity") && | |
587 check_true(1/Number(input['-0']) === -Infinity, "1/Number(input['-
0']) === -Infinity") && | |
588 check_true(Number(input['NaN']) !== Number(input['NaN']), "Number(
input['NaN']) !== Number(input['NaN'])") && | |
589 check_true(Number(input['Infinity']) === Infinity, "Number(input['
Infinity']) === Infinity") && | |
590 check_true(Number(input['-Infinity']) === -Infinity, "Number(input
['-Infinity']) === -Infinity") && | |
591 check_true(Number(input['9007199254740992']) === 9007199254740992,
"Number(input['9007199254740992']) === 9007199254740992") && | |
592 check_true(Number(input['-9007199254740992']) === -900719925474099
2, "Number(input['-9007199254740992']) === -9007199254740992") && | |
593 check_true(Number(input['9007199254740994']) === 9007199254740994,
"Number(input['9007199254740994']) === 9007199254740994") && | |
594 check_true(Number(input['-9007199254740994']) === -900719925474099
4, "Number(input['-9007199254740994']) === -9007199254740994")) { | |
595 var i = 0; | |
596 for (var x in input) { | |
597 i++; | |
598 if (!check_true(input[x] instanceof Number, 'input['+x+'] instance
of Number')) | |
599 return; | |
600 } | |
601 if (check_true(i === 10, 'i === 10')) { | |
602 port.postMessage(input); | |
603 close(); | |
604 } | |
605 } | |
606 })(); | |
607 break; | |
608 case 'Date 0': | |
609 if (check_true(input instanceof Date, "input instanceof Date") && | |
610 check_true(1/Number(input) === 1/Number(new Date(0)), "1/Number(inpu
t) === 1/Number(new Date(0))")) { | |
611 port.postMessage(input); | |
612 close(); | |
613 } | |
614 break; | |
615 case 'Date -0': | |
616 if (check_true(input instanceof Date, "input instanceof Date") && | |
617 check_true(1/Number(input) === 1/Number(new Date(-0)), "1/Number(inp
ut) === 1/Number(new Date(-0))")) { | |
618 port.postMessage(input); | |
619 close(); | |
620 } | |
621 break; | |
622 case 'Date -8.64e15': | |
623 if (check_true(input instanceof Date, "input instanceof Date") && | |
624 check_true(Number(input) === -8.64e15, "Number(input) === -8.64e15")
) { | |
625 port.postMessage(input); | |
626 close(); | |
627 } | |
628 break; | |
629 case 'Date 8.64e15': | |
630 if (check_true(input instanceof Date, "input instanceof Date") && | |
631 check_true(Number(input) === 8.64e15, "Number(input) === 8.64e15"))
{ | |
632 port.postMessage(input); | |
633 close(); | |
634 } | |
635 break; | |
636 case 'Array Date objects': | |
637 (function() { | |
638 if (check_true(input instanceof Array, 'input instanceof Array') && | |
639 check_true(input.length === 4, 'input.length === 4') && | |
640 check_true(1/Number(input[0]) === 1/new Date(0), '1/Number(input[0
]) === 1/new Date(0)') && | |
641 check_true(1/Number(input[1]) === 1/new Date(-0), '1/Number(input[
1]) === 1/new Date(-0)') && | |
642 check_true(Number(input[2]) === -8.64e15, 'Number(input[2]) === -8
.64e15') && | |
643 check_true(Number(input[3]) === 8.64e15, 'Number(input[3]) === 8.6
4e15')) { | |
644 for (var i = 0; i < input.length; ++i) { | |
645 if (!check_true(input[i] instanceof Date, 'input['+i+'] instanceof
Date')) | |
646 return; | |
647 } | |
648 port.postMessage(input); | |
649 close(); | |
650 } | |
651 })(); | |
652 break; | |
653 case 'Object Date objects': | |
654 (function() { | |
655 if (check_true(input instanceof Object, 'input instanceof Object') && | |
656 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
657 check_true(1/Number(input['0']) === 1/new Date(0), "1/Number(input
['0']) === 1/new Date(0)") && | |
658 check_true(1/Number(input['-0']) === 1/new Date(-0), "1/Number(inp
ut[1]) === 1/new Date(-0)") && | |
659 check_true(Number(input['-8.64e15']) === -8.64e15, "Number(input['
-8.64e15']) === -8.64e15") && | |
660 check_true(Number(input['8.64e15']) === 8.64e15, "Number(input['8.
64e15']) === 8.64e15")) { | |
661 var i = 0; | |
662 for (var x in input) { | |
663 i++; | |
664 if (!check_true(input[x] instanceof Date, 'input['+x+'] instanceof
Date')) | |
665 return; | |
666 } | |
667 port.postMessage(input); | |
668 close(); | |
669 } | |
670 })(); | |
671 break; | |
672 case 'RegExp flags and lastIndex': | |
673 case 'RegExp empty': | |
674 case 'RegExp slash': | |
675 case 'RegExp new line': | |
676 if (check_RegExp(msg, input)) { | |
677 port.postMessage(input); | |
678 close(); | |
679 } | |
680 break; | |
681 case 'Array RegExp object, RegExp flags and lastIndex': | |
682 case 'Array RegExp object, RegExp empty': | |
683 case 'Array RegExp object, RegExp slash': | |
684 case 'Array RegExp object, RegExp new line': | |
685 if (check_true(input instanceof Array, 'input instanceof Array') && | |
686 check_true(input.length === 1, 'input.length === 1') && | |
687 check_RegExp(msg.substr('Array RegExp object, '.length), input[0]))
{ | |
688 port.postMessage(input); | |
689 close(); | |
690 } | |
691 break; | |
692 case 'Object RegExp object, RegExp flags and lastIndex': | |
693 case 'Object RegExp object, RegExp empty': | |
694 case 'Object RegExp object, RegExp slash': | |
695 case 'Object RegExp object, RegExp new line': | |
696 (function() { | |
697 if (check_true(input instanceof Object, 'input instanceof Object') && | |
698 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
699 check_RegExp(msg.substr('Object RegExp object, '.length), input['x
'])) { | |
700 var i = 0; | |
701 for (var x in input) { | |
702 i++; | |
703 } | |
704 if (check_true(i === 1, 'i === 1')) { | |
705 port.postMessage(input); | |
706 close(); | |
707 } | |
708 } | |
709 })(); | |
710 break; | |
711 case 'Blob basic': | |
712 case 'Blob unpaired high surrogate (invalid utf-8)': | |
713 case 'Blob unpaired low surrogate (invalid utf-8)': | |
714 case 'Blob paired surrogates (invalid utf-8)': | |
715 case 'Blob empty': | |
716 case 'Blob NUL': | |
717 check_Blob(msg, input, port); | |
718 // no postMessage or close here, check_Blob takes care of that | |
719 break; | |
720 case 'Array Blob object, Blob basic': | |
721 case 'Array Blob object, Blob unpaired high surrogate (invalid utf-8)': | |
722 case 'Array Blob object, Blob unpaired low surrogate (invalid utf-8)': | |
723 case 'Array Blob object, Blob paired surrogates (invalid utf-8)': | |
724 case 'Array Blob object, Blob empty': | |
725 case 'Array Blob object, Blob NUL': | |
726 if (check_true(input instanceof Array, 'input instanceof Array') && | |
727 check_true(input.length === 1, 'input.length === 1')) { | |
728 check_Blob(msg.substr('Array Blob object, '.length), input[0], port, f
alse, input); | |
729 // no postMessage or close here, check_Blob takes care of that | |
730 } | |
731 break; | |
732 case 'Object Blob object, Blob basic': | |
733 case 'Object Blob object, Blob unpaired high surrogate (invalid utf-8)': | |
734 case 'Object Blob object, Blob unpaired low surrogate (invalid utf-8)': | |
735 case 'Object Blob object, Blob paired surrogates (invalid utf-8)': | |
736 case 'Object Blob object, Blob empty': | |
737 case 'Object Blob object, Blob NUL': | |
738 (function() { | |
739 if (check_true(input instanceof Object, 'input instanceof Object') && | |
740 check_true(!(input instanceof Array), '!(input instanceof Array)')
) { | |
741 var i = 0; | |
742 for (var x in input) { | |
743 i++; | |
744 } | |
745 if (check_true(i === 1, 'i === 1')) { | |
746 check_Blob(msg.substr('Object Blob object, '.length), input['x'],
port, false, input); | |
747 // no postMessage or close here, check_Blob takes care of that | |
748 } | |
749 } | |
750 })(); | |
751 break; | |
752 case 'File basic': | |
753 check_Blob(msg, input, port, true); | |
754 // no postMessage or close here, check_Blob takes care of that | |
755 break; | |
756 case 'FileList empty': | |
757 if (check_FileList(msg, input)) { | |
758 port.postMessage(input); | |
759 close(); | |
760 } | |
761 break; | |
762 case 'Array FileList object, FileList empty': | |
763 if (check_true(input instanceof Array, 'input instanceof Array') && | |
764 check_true(input.length === 1, 'input.length === 1') && | |
765 check_FileList(msg.substr('Array FileList object, '.length), input[0
])) { | |
766 port.postMessage(input); | |
767 close(); | |
768 } | |
769 break; | |
770 case 'Object FileList object, FileList empty': | |
771 (function() { | |
772 if (check_true(input instanceof Object, 'input instanceof Object') && | |
773 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
774 check_FileList(msg.substr('Array FileList object, '.length), input
['x'])) { | |
775 var i = 0; | |
776 for (var x in input) { | |
777 i++; | |
778 } | |
779 if (check_true(i === 1, 'i === 1')) { | |
780 port.postMessage(input); | |
781 close(); | |
782 } | |
783 } | |
784 })(); | |
785 break; | |
786 case 'ImageData 1x1 transparent black': | |
787 if (check_ImageData(input, {width:1, height:1, data:[0,0,0,0]})) { | |
788 port.postMessage(input); | |
789 close(); | |
790 } | |
791 break; | |
792 case 'ImageData 1x1 non-transparent non-black': | |
793 if (check_ImageData(input, {width:1, height:1, data:[100, 101, 102, 103]
})) { | |
794 port.postMessage(input); | |
795 close(); | |
796 } | |
797 break; | |
798 case 'Array ImageData object, ImageData 1x1 transparent black': | |
799 if (check_true(input instanceof Array, 'input instanceof Array') && | |
800 check_true(input.length === 1, 'input.length === 1') && | |
801 check_ImageData(input[0], {width:1, height:1, data:[0,0,0,0]})) { | |
802 port.postMessage(input); | |
803 close(); | |
804 } | |
805 break; | |
806 case 'Array ImageData object, ImageData 1x1 non-transparent non-black': | |
807 if (check_true(input instanceof Array, 'input instanceof Array') && | |
808 check_true(input.length === 1, 'input.length === 1') && | |
809 check_ImageData(input[0], {width:1, height:1, data:[100, 101, 102, 1
03]})) { | |
810 port.postMessage(input); | |
811 close(); | |
812 } | |
813 break; | |
814 case 'Object ImageData object, ImageData 1x1 transparent black': | |
815 (function(){ | |
816 if (check_true(input instanceof Object, 'input instanceof Object') && | |
817 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
818 check_ImageData(input['x'], {width:1, height:1, data:[0,0,0,0]}))
{ | |
819 var i = 0; | |
820 for (var x in input) { | |
821 i++; | |
822 } | |
823 if (check_true(i === 1, 'i === 1')) { | |
824 port.postMessage(input); | |
825 close(); | |
826 } | |
827 } | |
828 })(); | |
829 break; | |
830 case 'Object ImageData object, ImageData 1x1 non-transparent non-black': | |
831 (function() { | |
832 if (check_true(input instanceof Object, 'input instanceof Object') && | |
833 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
834 check_ImageData(input['x'], {width:1, height:1, data:[100, 101, 10
2, 103]})) { | |
835 var i = 0; | |
836 for (var x in input) { | |
837 i++; | |
838 } | |
839 if (check_true(i === 1, 'i === 1')) { | |
840 port.postMessage(input); | |
841 close(); | |
842 } | |
843 } | |
844 })(); | |
845 break; | |
846 case 'ImageBitmap 1x1 transparent black': | |
847 if (check_ImageBitmap(input, {width:1, height:1, data:[0, 0, 0, 0]})) { | |
848 port.postMessage(input); | |
849 close(); | |
850 } | |
851 break; | |
852 case 'ImageBitmap 1x1 non-transparent non-black': | |
853 if (check_ImageBitmap(input, {width:1, height:1, data:[100, 101, 102, 10
3]})) { | |
854 port.postMessage(input); | |
855 close(); | |
856 } | |
857 break; | |
858 case 'Array ImageBitmap object, ImageBitmap 1x1 transparent black': | |
859 if (check_true(input instanceof Array, 'input instanceof Array') && | |
860 check_true(input.length === 1, 'input.length === 1') && | |
861 check_ImageBitmap(input[0], {width:1, height:1, data:[0, 0, 0, 0]}))
{ | |
862 port.postMessage(input); | |
863 close(); | |
864 } | |
865 break; | |
866 case 'Array ImageBitmap object, ImageBitmap 1x1 non-transparent non-black'
: | |
867 if (check_true(input instanceof Array, 'input instanceof Array') && | |
868 check_true(input.length === 1, 'input.length === 1') && | |
869 check_ImageBitmap(input[0], {width:1, height:1, data:[100, 101, 102,
103]})) { | |
870 port.postMessage(input); | |
871 close(); | |
872 } | |
873 break; | |
874 case 'Object ImageBitmap object, ImageBitmap 1x1 transparent black': | |
875 (function() { | |
876 if (check_true(input instanceof Object, 'input instanceof Object') && | |
877 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
878 check_ImageBitmap(input['x'], {width:1, height:1, data:[0, 0, 0, 0
]})) { | |
879 var i = 0; | |
880 for (var x in input) { | |
881 i++; | |
882 } | |
883 if (check_true(i === 1, 'i === 1')) { | |
884 port.postMessage(input); | |
885 close(); | |
886 } | |
887 } | |
888 })(); | |
889 break; | |
890 case 'Object ImageBitmap object, ImageBitmap 1x1 non-transparent non-black
': | |
891 (function() { | |
892 if (check_true(input instanceof Object, 'input instanceof Object') && | |
893 check_true(!(input instanceof Array), '!(input instanceof Array)')
&& | |
894 check_ImageBitmap(input['x'], {width:1, height:1, data:[100, 101,
102, 103]})) { | |
895 var i = 0; | |
896 for (var x in input) { | |
897 i++; | |
898 } | |
899 if (check_true(i === 1, 'i === 1')) { | |
900 port.postMessage(input); | |
901 close(); | |
902 } | |
903 } | |
904 })(); | |
905 break; | |
906 case 'Array sparse': | |
907 (function() { | |
908 if (check_true(input instanceof Array, 'input instanceof Array') && | |
909 check_true(input.length === 10, 'input.length === 10')) { | |
910 for (var x in input) { | |
911 check_true(false, 'unexpected enumerable property '+x); | |
912 return; | |
913 } | |
914 port.postMessage(input); | |
915 close(); | |
916 } | |
917 })(); | |
918 break; | |
919 case 'Array with non-index property': | |
920 if (check_true(input instanceof Array, 'input instanceof Array') && | |
921 check_true(input.length === 0, 'input.length === 0') && | |
922 check_true(input.foo === 'bar', "input.foo === 'bar'")) { | |
923 port.postMessage(input); | |
924 close(); | |
925 } | |
926 break; | |
927 case 'Object with index property and length': | |
928 if (check_true(input instanceof Object, 'input instanceof Object') && | |
929 check_true(!(input instanceof Array), '!(input instanceof Array)') &
& | |
930 check_true(input[0] === 'foo', "input[0] === 'foo'") && | |
931 check_true(input.length === 1, 'input.length === 1')) { | |
932 port.postMessage(input); | |
933 close(); | |
934 } | |
935 break; | |
936 case 'Array with circular reference': | |
937 if (check_true(input instanceof Array, 'input instanceof Array') && | |
938 check_true(input.length === 1, 'input.length === 1') && | |
939 check_true(input[0] === input, "input[0] === input")) { | |
940 port.postMessage(input); | |
941 close(); | |
942 } | |
943 break; | |
944 case 'Object with circular reference': | |
945 if (check_true(input instanceof Object, 'input instanceof Object') && | |
946 check_true(!(input instanceof Array), '!(input instanceof Array)') &
& | |
947 check_true(input['x'] === input, "input['x'] === input")) { | |
948 port.postMessage(input); | |
949 close(); | |
950 } | |
951 break; | |
952 case 'Array with identical property values': | |
953 if (check_true(input instanceof Array, 'input instanceof Array') && | |
954 check_true(input.length === 2, 'input.length === 2') && | |
955 check_true(input[0] === input[1], "input[0] === input[1]")) { | |
956 port.postMessage(input); | |
957 close(); | |
958 } | |
959 break; | |
960 case 'Object with identical property values': | |
961 if (check_true(input instanceof Object, 'input instanceof Object') && | |
962 check_true(!(input instanceof Array), '!(input instanceof Array)') &
& | |
963 check_true(input['x'] === input['y'], "input['x'] === input['y']"))
{ | |
964 port.postMessage(input); | |
965 close(); | |
966 } | |
967 break; | |
968 case 'Object with property on prototype': | |
969 case 'Object with non-enumerable property': | |
970 if (check_true(input instanceof Object, 'input instanceof Object') && | |
971 check_true(!(input instanceof Array), '!(input instanceof Array)') &
& | |
972 check_true(!('foo' in input), "!('foo' in input)")) { | |
973 input = {}; | |
974 Object.defineProperty(input, 'foo', {value:'bar', enumerable:false, wr
itable:true, configurable:true}); | |
975 port.postMessage(input); | |
976 close(); | |
977 } | |
978 break; | |
979 case 'Object with non-writable property': | |
980 if (check_true(input instanceof Object, 'input instanceof Object') && | |
981 check_true(!(input instanceof Array), '!(input instanceof Array)') &
& | |
982 check_true(input.foo === 'bar', "input.foo === bar")) { | |
983 input.foo += ' baz'; | |
984 if (check_true(input.foo === 'bar baz', "input.foo === 'bar baz'")) { | |
985 input = {}; | |
986 Object.defineProperty(input, 'foo', {value:'bar', enumerable:true, w
ritable:false, configurable:true}); | |
987 port.postMessage(input); | |
988 close(); | |
989 } | |
990 } | |
991 break; | |
992 case 'Object with non-configurable property': | |
993 if (check_true(input instanceof Object, 'input instanceof Object') && | |
994 check_true(!(input instanceof Array), '!(input instanceof Array)') &
& | |
995 check_true(input.foo === 'bar', "input.foo === bar")) { | |
996 delete input.foo; | |
997 if (check_true(!('foo' in input), "!('foo' in input)")) { | |
998 input = {}; | |
999 Object.defineProperty(input, 'foo', {value:'bar', enumerable:true, w
ritable:true, configurable:false}); | |
1000 port.postMessage(input); | |
1001 close(); | |
1002 } | |
1003 } | |
1004 break; | |
1005 | |
1006 default: | |
1007 port.postMessage('FAIL: unknown test'); | |
1008 close(); | |
1009 } | |
1010 if (log.length > 0) { | |
1011 port.postMessage('FAIL '+log); | |
1012 close(); | |
1013 } | |
1014 } catch (ex) { | |
1015 port.postMessage('FAIL '+ex); | |
1016 close(); | |
1017 } | |
1018 } | |
OLD | NEW |