PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/workers/semantics/structured-clone/worker-common.js

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