shell.js (27036B)
1 // GENERATED, DO NOT EDIT 2 // file: assert.js 3 // Copyright (C) 2017 Ecma International. All rights reserved. 4 // This code is governed by the BSD license found in the LICENSE file. 5 /*--- 6 description: | 7 Collection of assertion functions used throughout test262 8 defines: [assert] 9 ---*/ 10 11 12 function assert(mustBeTrue, message) { 13 if (mustBeTrue === true) { 14 return; 15 } 16 17 if (message === undefined) { 18 message = 'Expected true but got ' + assert._toString(mustBeTrue); 19 } 20 throw new Test262Error(message); 21 } 22 23 assert._isSameValue = function (a, b) { 24 if (a === b) { 25 // Handle +/-0 vs. -/+0 26 return a !== 0 || 1 / a === 1 / b; 27 } 28 29 // Handle NaN vs. NaN 30 return a !== a && b !== b; 31 }; 32 33 assert.sameValue = function (actual, expected, message) { 34 try { 35 if (assert._isSameValue(actual, expected)) { 36 return; 37 } 38 } catch (error) { 39 throw new Test262Error(message + ' (_isSameValue operation threw) ' + error); 40 return; 41 } 42 43 if (message === undefined) { 44 message = ''; 45 } else { 46 message += ' '; 47 } 48 49 message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(expected) + '») to be true'; 50 51 throw new Test262Error(message); 52 }; 53 54 assert.notSameValue = function (actual, unexpected, message) { 55 if (!assert._isSameValue(actual, unexpected)) { 56 return; 57 } 58 59 if (message === undefined) { 60 message = ''; 61 } else { 62 message += ' '; 63 } 64 65 message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(unexpected) + '») to be false'; 66 67 throw new Test262Error(message); 68 }; 69 70 assert.throws = function (expectedErrorConstructor, func, message) { 71 var expectedName, actualName; 72 if (typeof func !== "function") { 73 throw new Test262Error('assert.throws requires two arguments: the error constructor ' + 74 'and a function to run'); 75 return; 76 } 77 if (message === undefined) { 78 message = ''; 79 } else { 80 message += ' '; 81 } 82 83 try { 84 func(); 85 } catch (thrown) { 86 if (typeof thrown !== 'object' || thrown === null) { 87 message += 'Thrown value was not an object!'; 88 throw new Test262Error(message); 89 } else if (thrown.constructor !== expectedErrorConstructor) { 90 expectedName = expectedErrorConstructor.name; 91 actualName = thrown.constructor.name; 92 if (expectedName === actualName) { 93 message += 'Expected a ' + expectedName + ' but got a different error constructor with the same name'; 94 } else { 95 message += 'Expected a ' + expectedName + ' but got a ' + actualName; 96 } 97 throw new Test262Error(message); 98 } 99 return; 100 } 101 102 message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all'; 103 throw new Test262Error(message); 104 }; 105 106 function isPrimitive(value) { 107 return !value || (typeof value !== 'object' && typeof value !== 'function'); 108 } 109 110 assert.compareArray = function (actual, expected, message) { 111 message = message === undefined ? '' : message; 112 113 if (typeof message === 'symbol') { 114 message = message.toString(); 115 } 116 117 if (isPrimitive(actual)) { 118 assert(false, `Actual argument [${actual}] shouldn't be primitive. ${message}`); 119 } else if (isPrimitive(expected)) { 120 assert(false, `Expected argument [${expected}] shouldn't be primitive. ${message}`); 121 } 122 var result = compareArray(actual, expected); 123 if (result) return; 124 125 var format = compareArray.format; 126 assert(false, `Actual ${format(actual)} and expected ${format(expected)} should have the same contents. ${message}`); 127 }; 128 129 function compareArray(a, b) { 130 if (b.length !== a.length) { 131 return false; 132 } 133 for (var i = 0; i < a.length; i++) { 134 if (!assert._isSameValue(b[i], a[i])) { 135 return false; 136 } 137 } 138 return true; 139 } 140 141 compareArray.format = function (arrayLike) { 142 return `[${Array.prototype.map.call(arrayLike, String).join(', ')}]`; 143 }; 144 145 assert._formatIdentityFreeValue = function formatIdentityFreeValue(value) { 146 switch (value === null ? 'null' : typeof value) { 147 case 'string': 148 return typeof JSON !== "undefined" ? JSON.stringify(value) : `"${value}"`; 149 case 'bigint': 150 return `${value}n`; 151 case 'number': 152 if (value === 0 && 1 / value === -Infinity) return '-0'; 153 // falls through 154 case 'boolean': 155 case 'undefined': 156 case 'null': 157 return String(value); 158 } 159 }; 160 161 assert._toString = function (value) { 162 var basic = assert._formatIdentityFreeValue(value); 163 if (basic) return basic; 164 try { 165 return String(value); 166 } catch (err) { 167 if (err.name === 'TypeError') { 168 return Object.prototype.toString.call(value); 169 } 170 throw err; 171 } 172 }; 173 174 // file: compareArray.js 175 // Copyright (C) 2017 Ecma International. All rights reserved. 176 // This code is governed by the BSD license found in the LICENSE file. 177 /*--- 178 description: | 179 Deprecated now that compareArray is defined in assert.js. 180 defines: [compareArray] 181 ---*/ 182 183 // file: propertyHelper.js 184 // Copyright (C) 2017 Ecma International. All rights reserved. 185 // This code is governed by the BSD license found in the LICENSE file. 186 /*--- 187 description: | 188 Collection of functions used to safely verify the correctness of 189 property descriptors. 190 defines: 191 - verifyProperty 192 - verifyCallableProperty 193 - verifyEqualTo # deprecated 194 - verifyWritable # deprecated 195 - verifyNotWritable # deprecated 196 - verifyEnumerable # deprecated 197 - verifyNotEnumerable # deprecated 198 - verifyConfigurable # deprecated 199 - verifyNotConfigurable # deprecated 200 - verifyPrimordialProperty 201 - verifyPrimordialCallableProperty 202 ---*/ 203 204 // @ts-check 205 206 // Capture primordial functions and receiver-uncurried primordial methods that 207 // are used in verification but might be destroyed *by* that process itself. 208 var __isArray = Array.isArray; 209 var __defineProperty = Object.defineProperty; 210 var __getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; 211 var __getOwnPropertyNames = Object.getOwnPropertyNames; 212 var __join = Function.prototype.call.bind(Array.prototype.join); 213 var __push = Function.prototype.call.bind(Array.prototype.push); 214 var __hasOwnProperty = Function.prototype.call.bind(Object.prototype.hasOwnProperty); 215 var __propertyIsEnumerable = Function.prototype.call.bind(Object.prototype.propertyIsEnumerable); 216 var nonIndexNumericPropertyName = Math.pow(2, 32) - 1; 217 218 /** 219 * @param {object} obj 220 * @param {string|symbol} name 221 * @param {PropertyDescriptor|undefined} desc 222 * @param {object} [options] 223 * @param {boolean} [options.restore] revert mutations from verifying writable/configurable 224 */ 225 function verifyProperty(obj, name, desc, options) { 226 assert( 227 arguments.length > 2, 228 'verifyProperty should receive at least 3 arguments: obj, name, and descriptor' 229 ); 230 231 var originalDesc = __getOwnPropertyDescriptor(obj, name); 232 var nameStr = String(name); 233 234 // Allows checking for undefined descriptor if it's explicitly given. 235 if (desc === undefined) { 236 assert.sameValue( 237 originalDesc, 238 undefined, 239 "obj['" + nameStr + "'] descriptor should be undefined" 240 ); 241 242 // desc and originalDesc are both undefined, problem solved; 243 return true; 244 } 245 246 assert( 247 __hasOwnProperty(obj, name), 248 "obj should have an own property " + nameStr 249 ); 250 251 assert.notSameValue( 252 desc, 253 null, 254 "The desc argument should be an object or undefined, null" 255 ); 256 257 assert.sameValue( 258 typeof desc, 259 "object", 260 "The desc argument should be an object or undefined, " + String(desc) 261 ); 262 263 var names = __getOwnPropertyNames(desc); 264 for (var i = 0; i < names.length; i++) { 265 assert( 266 names[i] === "value" || 267 names[i] === "writable" || 268 names[i] === "enumerable" || 269 names[i] === "configurable" || 270 names[i] === "get" || 271 names[i] === "set", 272 "Invalid descriptor field: " + names[i], 273 ); 274 } 275 276 var failures = []; 277 278 if (__hasOwnProperty(desc, 'value')) { 279 if (!isSameValue(desc.value, originalDesc.value)) { 280 __push(failures, "obj['" + nameStr + "'] descriptor value should be " + desc.value); 281 } 282 if (!isSameValue(desc.value, obj[name])) { 283 __push(failures, "obj['" + nameStr + "'] value should be " + desc.value); 284 } 285 } 286 287 if (__hasOwnProperty(desc, 'enumerable') && desc.enumerable !== undefined) { 288 if (desc.enumerable !== originalDesc.enumerable || 289 desc.enumerable !== isEnumerable(obj, name)) { 290 __push(failures, "obj['" + nameStr + "'] descriptor should " + (desc.enumerable ? '' : 'not ') + "be enumerable"); 291 } 292 } 293 294 // Operations past this point are potentially destructive! 295 296 if (__hasOwnProperty(desc, 'writable') && desc.writable !== undefined) { 297 if (desc.writable !== originalDesc.writable || 298 desc.writable !== isWritable(obj, name)) { 299 __push(failures, "obj['" + nameStr + "'] descriptor should " + (desc.writable ? '' : 'not ') + "be writable"); 300 } 301 } 302 303 if (__hasOwnProperty(desc, 'configurable') && desc.configurable !== undefined) { 304 if (desc.configurable !== originalDesc.configurable || 305 desc.configurable !== isConfigurable(obj, name)) { 306 __push(failures, "obj['" + nameStr + "'] descriptor should " + (desc.configurable ? '' : 'not ') + "be configurable"); 307 } 308 } 309 310 if (failures.length) { 311 assert(false, __join(failures, '; ')); 312 } 313 314 if (options && options.restore) { 315 __defineProperty(obj, name, originalDesc); 316 } 317 318 return true; 319 } 320 321 function isConfigurable(obj, name) { 322 try { 323 delete obj[name]; 324 } catch (e) { 325 if (!(e instanceof TypeError)) { 326 throw new Test262Error("Expected TypeError, got " + e); 327 } 328 } 329 return !__hasOwnProperty(obj, name); 330 } 331 332 function isEnumerable(obj, name) { 333 var stringCheck = false; 334 335 if (typeof name === "string") { 336 for (var x in obj) { 337 if (x === name) { 338 stringCheck = true; 339 break; 340 } 341 } 342 } else { 343 // skip it if name is not string, works for Symbol names. 344 stringCheck = true; 345 } 346 347 return stringCheck && __hasOwnProperty(obj, name) && __propertyIsEnumerable(obj, name); 348 } 349 350 function isSameValue(a, b) { 351 if (a === 0 && b === 0) return 1 / a === 1 / b; 352 if (a !== a && b !== b) return true; 353 354 return a === b; 355 } 356 357 function isWritable(obj, name, verifyProp, value) { 358 var unlikelyValue = __isArray(obj) && name === "length" ? 359 nonIndexNumericPropertyName : 360 "unlikelyValue"; 361 var newValue = value || unlikelyValue; 362 var hadValue = __hasOwnProperty(obj, name); 363 var oldValue = obj[name]; 364 var writeSucceeded; 365 366 if (arguments.length < 4 && newValue === oldValue) { 367 newValue = newValue + "2"; 368 } 369 370 try { 371 obj[name] = newValue; 372 } catch (e) { 373 if (!(e instanceof TypeError)) { 374 throw new Test262Error("Expected TypeError, got " + e); 375 } 376 } 377 378 writeSucceeded = isSameValue(obj[verifyProp || name], newValue); 379 380 // Revert the change only if it was successful (in other cases, reverting 381 // is unnecessary and may trigger exceptions for certain property 382 // configurations) 383 if (writeSucceeded) { 384 if (hadValue) { 385 obj[name] = oldValue; 386 } else { 387 delete obj[name]; 388 } 389 } 390 391 return writeSucceeded; 392 } 393 394 /** 395 * Verify that there is a function of specified name, length, and containing 396 * descriptor associated with `obj[name]` and following the conventions for 397 * built-in objects. 398 * 399 * @param {object} obj 400 * @param {string|symbol} name 401 * @param {string} [functionName] defaults to name for strings, `[${name.description}]` for symbols 402 * @param {number} functionLength 403 * @param {PropertyDescriptor} [desc] defaults to data property conventions (writable, non-enumerable, configurable) 404 * @param {object} [options] 405 * @param {boolean} [options.restore] revert mutations from verifying writable/configurable 406 */ 407 function verifyCallableProperty(obj, name, functionName, functionLength, desc, options) { 408 var value = obj[name]; 409 410 assert.sameValue(typeof value, "function", 411 "obj['" + String(name) + "'] descriptor should be a function"); 412 413 // Every other data property described in clauses 19 through 28 and in 414 // Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, 415 // [[Configurable]]: true } unless otherwise specified. 416 // https://tc39.es/ecma262/multipage/ecmascript-standard-built-in-objects.html 417 if (desc === undefined) { 418 desc = { 419 writable: true, 420 enumerable: false, 421 configurable: true, 422 value: value 423 }; 424 } else if (!__hasOwnProperty(desc, "value") && !__hasOwnProperty(desc, "get")) { 425 desc.value = value; 426 } 427 428 verifyProperty(obj, name, desc, options); 429 430 if (functionName === undefined) { 431 if (typeof name === "symbol") { 432 functionName = "[" + name.description + "]"; 433 } else { 434 functionName = name; 435 } 436 } 437 // Unless otherwise specified, the "name" property of a built-in function 438 // object has the attributes { [[Writable]]: false, [[Enumerable]]: false, 439 // [[Configurable]]: true }. 440 // https://tc39.es/ecma262/multipage/ecmascript-standard-built-in-objects.html#sec-ecmascript-standard-built-in-objects 441 // https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-setfunctionname 442 verifyProperty(value, "name", { 443 value: functionName, 444 writable: false, 445 enumerable: false, 446 configurable: desc.configurable 447 }, options); 448 449 // Unless otherwise specified, the "length" property of a built-in function 450 // object has the attributes { [[Writable]]: false, [[Enumerable]]: false, 451 // [[Configurable]]: true }. 452 // https://tc39.es/ecma262/multipage/ecmascript-standard-built-in-objects.html#sec-ecmascript-standard-built-in-objects 453 // https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#sec-setfunctionlength 454 verifyProperty(value, "length", { 455 value: functionLength, 456 writable: false, 457 enumerable: false, 458 configurable: desc.configurable 459 }, options); 460 } 461 462 /** 463 * Deprecated; please use `verifyProperty` in new tests. 464 */ 465 function verifyEqualTo(obj, name, value) { 466 if (!isSameValue(obj[name], value)) { 467 throw new Test262Error("Expected obj[" + String(name) + "] to equal " + value + 468 ", actually " + obj[name]); 469 } 470 } 471 472 /** 473 * Deprecated; please use `verifyProperty` in new tests. 474 */ 475 function verifyWritable(obj, name, verifyProp, value) { 476 if (!verifyProp) { 477 assert(__getOwnPropertyDescriptor(obj, name).writable, 478 "Expected obj[" + String(name) + "] to have writable:true."); 479 } 480 if (!isWritable(obj, name, verifyProp, value)) { 481 throw new Test262Error("Expected obj[" + String(name) + "] to be writable, but was not."); 482 } 483 } 484 485 /** 486 * Deprecated; please use `verifyProperty` in new tests. 487 */ 488 function verifyNotWritable(obj, name, verifyProp, value) { 489 if (!verifyProp) { 490 assert(!__getOwnPropertyDescriptor(obj, name).writable, 491 "Expected obj[" + String(name) + "] to have writable:false."); 492 } 493 if (isWritable(obj, name, verifyProp)) { 494 throw new Test262Error("Expected obj[" + String(name) + "] NOT to be writable, but was."); 495 } 496 } 497 498 /** 499 * Deprecated; please use `verifyProperty` in new tests. 500 */ 501 function verifyEnumerable(obj, name) { 502 assert(__getOwnPropertyDescriptor(obj, name).enumerable, 503 "Expected obj[" + String(name) + "] to have enumerable:true."); 504 if (!isEnumerable(obj, name)) { 505 throw new Test262Error("Expected obj[" + String(name) + "] to be enumerable, but was not."); 506 } 507 } 508 509 /** 510 * Deprecated; please use `verifyProperty` in new tests. 511 */ 512 function verifyNotEnumerable(obj, name) { 513 assert(!__getOwnPropertyDescriptor(obj, name).enumerable, 514 "Expected obj[" + String(name) + "] to have enumerable:false."); 515 if (isEnumerable(obj, name)) { 516 throw new Test262Error("Expected obj[" + String(name) + "] NOT to be enumerable, but was."); 517 } 518 } 519 520 /** 521 * Deprecated; please use `verifyProperty` in new tests. 522 */ 523 function verifyConfigurable(obj, name) { 524 assert(__getOwnPropertyDescriptor(obj, name).configurable, 525 "Expected obj[" + String(name) + "] to have configurable:true."); 526 if (!isConfigurable(obj, name)) { 527 throw new Test262Error("Expected obj[" + String(name) + "] to be configurable, but was not."); 528 } 529 } 530 531 /** 532 * Deprecated; please use `verifyProperty` in new tests. 533 */ 534 function verifyNotConfigurable(obj, name) { 535 assert(!__getOwnPropertyDescriptor(obj, name).configurable, 536 "Expected obj[" + String(name) + "] to have configurable:false."); 537 if (isConfigurable(obj, name)) { 538 throw new Test262Error("Expected obj[" + String(name) + "] NOT to be configurable, but was."); 539 } 540 } 541 542 /** 543 * Use this function to verify the properties of a primordial object. 544 * For non-primordial objects, use verifyProperty. 545 * See: https://github.com/tc39/how-we-work/blob/main/terminology.md#primordial 546 */ 547 var verifyPrimordialProperty = verifyProperty; 548 549 /** 550 * Use this function to verify the primordial function-valued properties. 551 * For non-primordial functions, use verifyCallableProperty. 552 * See: https://github.com/tc39/how-we-work/blob/main/terminology.md#primordial 553 */ 554 var verifyPrimordialCallableProperty = verifyCallableProperty; 555 556 // file: sta.js 557 // Copyright (c) 2012 Ecma International. All rights reserved. 558 // This code is governed by the BSD license found in the LICENSE file. 559 /*--- 560 description: | 561 Provides both: 562 563 - An error class to avoid false positives when testing for thrown exceptions 564 - A function to explicitly throw an exception using the Test262Error class 565 defines: [Test262Error, $DONOTEVALUATE] 566 ---*/ 567 568 569 function Test262Error(message) { 570 this.message = message || ""; 571 } 572 573 Test262Error.prototype.toString = function () { 574 return "Test262Error: " + this.message; 575 }; 576 577 Test262Error.thrower = function (message) { 578 throw new Test262Error(message); 579 }; 580 581 function $DONOTEVALUATE() { 582 throw "Test262: This statement should not be evaluated."; 583 } 584 585 // file: test262-host.js 586 // This Source Code Form is subject to the terms of the Mozilla Public 587 // License, v. 2.0. If a copy of the MPL was not distributed with this 588 // file, You can obtain one at http://mozilla.org/MPL/2.0/. 589 590 // https://github.com/tc39/test262/blob/main/INTERPRETING.md#host-defined-functions 591 ;(function createHostObject(global) { 592 "use strict"; 593 594 // Save built-in functions and constructors. 595 var FunctionToString = global.Function.prototype.toString; 596 var ReflectApply = global.Reflect.apply; 597 var Atomics = global.Atomics; 598 var Error = global.Error; 599 var SharedArrayBuffer = global.SharedArrayBuffer; 600 var Int32Array = global.Int32Array; 601 602 // Save built-in shell functions. 603 var NewGlobal = global.newGlobal; 604 var setSharedArrayBuffer = global.setSharedArrayBuffer; 605 var getSharedArrayBuffer = global.getSharedArrayBuffer; 606 var evalInWorker = global.evalInWorker; 607 var monotonicNow = global.monotonicNow; 608 var gc = global.gc; 609 var clearKeptObjects = global.clearKeptObjects; 610 611 var hasCreateIsHTMLDDA = "createIsHTMLDDA" in global; 612 var hasThreads = ("helperThreadCount" in global ? global.helperThreadCount() > 0 : true); 613 var hasMailbox = typeof setSharedArrayBuffer === "function" && typeof getSharedArrayBuffer === "function"; 614 var hasEvalInWorker = typeof evalInWorker === "function"; 615 616 if (!hasCreateIsHTMLDDA && !("document" in global && "all" in global.document)) 617 throw new Error("no [[IsHTMLDDA]] object available for testing"); 618 619 var IsHTMLDDA = hasCreateIsHTMLDDA 620 ? global.createIsHTMLDDA() 621 : global.document.all; 622 623 // The $262.agent framework is not appropriate for browsers yet, and some 624 // test cases can't work in browsers (they block the main thread). 625 626 var shellCode = hasMailbox && hasEvalInWorker; 627 var sabTestable = Atomics && SharedArrayBuffer && hasThreads && shellCode; 628 629 global.$262 = { 630 __proto__: null, 631 createRealm() { 632 var newGlobalObject = NewGlobal(); 633 var createHostObjectFn = ReflectApply(FunctionToString, createHostObject, []); 634 newGlobalObject.Function(`${createHostObjectFn} createHostObject(this);`)(); 635 return newGlobalObject.$262; 636 }, 637 detachArrayBuffer: global.detachArrayBuffer, 638 evalScript: global.evaluateScript || global.evaluate, 639 global, 640 IsHTMLDDA, 641 gc() { 642 gc(); 643 }, 644 clearKeptObjects() { 645 clearKeptObjects(); 646 }, 647 agent: (function () { 648 649 // SpiderMonkey complication: With run-time argument --no-threads 650 // our test runner will not properly filter test cases that can't be 651 // run because agents can't be started, and so we do a little 652 // filtering here: We will quietly succeed and exit if an agent test 653 // should not have been run because threads cannot be started. 654 // 655 // Firefox complication: The test cases that use $262.agent can't 656 // currently work in the browser, so for now we rely on them not 657 // being run at all. 658 659 if (!sabTestable) { 660 let {reportCompare, quit} = global; 661 662 function notAvailable() { 663 // See comment above. 664 if (!hasThreads && shellCode) { 665 reportCompare(0, 0); 666 quit(0); 667 } 668 throw new Error("Agents not available"); 669 } 670 671 return { 672 start(script) { notAvailable() }, 673 broadcast(sab, id) { notAvailable() }, 674 getReport() { notAvailable() }, 675 sleep(s) { notAvailable() }, 676 monotonicNow, 677 } 678 } 679 680 // The SpiderMonkey implementation uses a designated shared buffer _ia 681 // for coordination, and spinlocks for everything except sleeping. 682 683 var _MSG_LOC = 0; // Low bit set: broadcast available; High bits: seq # 684 var _ID_LOC = 1; // ID sent with broadcast 685 var _ACK_LOC = 2; // Worker increments this to ack that broadcast was received 686 var _RDY_LOC = 3; // Worker increments this to ack that worker is up and running 687 var _LOCKTXT_LOC = 4; // Writer lock for the text buffer: 0=open, 1=closed 688 var _NUMTXT_LOC = 5; // Count of messages in text buffer 689 var _NEXT_LOC = 6; // First free location in the buffer 690 var _SLEEP_LOC = 7; // Used for sleeping 691 692 var _FIRST = 10; // First location of first message 693 694 var _ia = new Int32Array(new SharedArrayBuffer(65536)); 695 _ia[_NEXT_LOC] = _FIRST; 696 697 var _worker_prefix = 698 // BEGIN WORKER PREFIX 699 `if (typeof $262 === 'undefined') 700 $262 = {}; 701 $262.agent = (function (global) { 702 var ReflectApply = global.Reflect.apply; 703 var StringCharCodeAt = global.String.prototype.charCodeAt; 704 var { 705 add: Atomics_add, 706 compareExchange: Atomics_compareExchange, 707 load: Atomics_load, 708 store: Atomics_store, 709 wait: Atomics_wait, 710 } = global.Atomics; 711 712 var {getSharedArrayBuffer} = global; 713 714 var _finished = { done: false }; 715 716 var _ia = new Int32Array(getSharedArrayBuffer()); 717 var agent = { 718 receiveBroadcast(receiver) { 719 var k; 720 while (((k = Atomics_load(_ia, ${_MSG_LOC})) & 1) === 0) 721 ; 722 var received_sab = getSharedArrayBuffer(); 723 var received_id = Atomics_load(_ia, ${_ID_LOC}); 724 Atomics_add(_ia, ${_ACK_LOC}, 1); 725 while (Atomics_load(_ia, ${_MSG_LOC}) === k) 726 ; 727 receiver(received_sab, received_id); 728 waitForDone(_finished); 729 }, 730 731 report(msg) { 732 while (Atomics_compareExchange(_ia, ${_LOCKTXT_LOC}, 0, 1) === 1) 733 ; 734 msg = "" + msg; 735 var i = _ia[${_NEXT_LOC}]; 736 _ia[i++] = msg.length; 737 for ( let j=0 ; j < msg.length ; j++ ) 738 _ia[i++] = ReflectApply(StringCharCodeAt, msg, [j]); 739 _ia[${_NEXT_LOC}] = i; 740 Atomics_add(_ia, ${_NUMTXT_LOC}, 1); 741 Atomics_store(_ia, ${_LOCKTXT_LOC}, 0); 742 }, 743 744 sleep(s) { 745 Atomics_wait(_ia, ${_SLEEP_LOC}, 0, s); 746 }, 747 748 leaving() { 749 _finished.done = true; 750 }, 751 752 monotonicNow: global.monotonicNow, 753 }; 754 Atomics_add(_ia, ${_RDY_LOC}, 1); 755 return agent; 756 })(this);`; 757 // END WORKER PREFIX 758 759 var _numWorkers = 0; 760 var _numReports = 0; 761 var _reportPtr = _FIRST; 762 var { 763 add: Atomics_add, 764 load: Atomics_load, 765 store: Atomics_store, 766 wait: Atomics_wait, 767 } = Atomics; 768 var StringFromCharCode = global.String.fromCharCode; 769 770 return { 771 start(script) { 772 setSharedArrayBuffer(_ia.buffer); 773 var oldrdy = Atomics_load(_ia, _RDY_LOC); 774 evalInWorker(_worker_prefix + script); 775 while (Atomics_load(_ia, _RDY_LOC) === oldrdy) 776 ; 777 _numWorkers++; 778 }, 779 780 broadcast(sab, id) { 781 setSharedArrayBuffer(sab); 782 Atomics_store(_ia, _ID_LOC, id); 783 Atomics_store(_ia, _ACK_LOC, 0); 784 Atomics_add(_ia, _MSG_LOC, 1); 785 while (Atomics_load(_ia, _ACK_LOC) < _numWorkers) 786 ; 787 Atomics_add(_ia, _MSG_LOC, 1); 788 }, 789 790 getReport() { 791 if (_numReports === Atomics_load(_ia, _NUMTXT_LOC)) 792 return null; 793 var s = ""; 794 var i = _reportPtr; 795 var len = _ia[i++]; 796 for ( let j=0 ; j < len ; j++ ) 797 s += StringFromCharCode(_ia[i++]); 798 _reportPtr = i; 799 _numReports++; 800 return s; 801 }, 802 803 sleep(s) { 804 Atomics_wait(_ia, _SLEEP_LOC, 0, s); 805 }, 806 807 monotonicNow, 808 }; 809 })() 810 }; 811 })(this); 812 813 var $mozAsyncTestDone = false; 814 function $DONE(failure) { 815 // This function is generally called from within a Promise handler, so any 816 // exception thrown by this method will be swallowed and most likely 817 // ignored by the Promise machinery. 818 if ($mozAsyncTestDone) { 819 reportFailure("$DONE() already called"); 820 return; 821 } 822 $mozAsyncTestDone = true; 823 824 if (failure) 825 reportFailure(failure); 826 else 827 reportCompare(0, 0); 828 829 if (typeof jsTestDriverEnd === "function") { 830 gDelayTestDriverEnd = false; 831 jsTestDriverEnd(); 832 } 833 } 834 835 // Some tests in test262 leave promise rejections unhandled. 836 if ("ignoreUnhandledRejections" in this) { 837 ignoreUnhandledRejections(); 838 }