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