1 // GENERATED, DO NOT EDIT
3 // Copyright (C) 2017 Ecma International. All rights reserved.
4 // This code is governed by the BSD license found in the LICENSE file.
7 Collection of assertion functions used throughout test262
12 function assert(mustBeTrue, message) {
13 if (mustBeTrue === true) {
17 if (message === undefined) {
18 message = 'Expected true but got ' + assert._toString(mustBeTrue);
20 throw new Test262Error(message);
23 assert._isSameValue = function (a, b) {
25 // Handle +/-0 vs. -/+0
26 return a !== 0 || 1 / a === 1 / b;
30 return a !== a && b !== b;
33 assert.sameValue = function (actual, expected, message) {
35 if (assert._isSameValue(actual, expected)) {
39 throw new Test262Error(message + ' (_isSameValue operation threw) ' + error);
43 if (message === undefined) {
49 message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(expected) + '») to be true';
51 throw new Test262Error(message);
54 assert.notSameValue = function (actual, unexpected, message) {
55 if (!assert._isSameValue(actual, unexpected)) {
59 if (message === undefined) {
65 message += 'Expected SameValue(«' + assert._toString(actual) + '», «' + assert._toString(unexpected) + '») to be false';
67 throw new Test262Error(message);
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');
77 if (message === undefined) {
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';
95 message += 'Expected a ' + expectedName + ' but got a ' + actualName;
97 throw new Test262Error(message);
102 message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all';
103 throw new Test262Error(message);
106 assert._toString = function (value) {
108 if (value === 0 && 1 / value === -Infinity) {
112 return String(value);
114 if (err.name === 'TypeError') {
115 return Object.prototype.toString.call(value);
122 // file: compareArray.js
123 // Copyright (C) 2017 Ecma International. All rights reserved.
124 // This code is governed by the BSD license found in the LICENSE file.
127 Compare the contents of two arrays
128 defines: [compareArray]
131 function compareArray(a, b) {
132 if (b.length !== a.length) {
136 for (var i = 0; i < a.length; i++) {
137 if (!compareArray.isSameValue(b[i], a[i])) {
144 compareArray.isSameValue = function(a, b) {
145 if (a === 0 && b === 0) return 1 / a === 1 / b;
146 if (a !== a && b !== b) return true;
151 compareArray.format = function(arrayLike) {
152 return `[${[].map.call(arrayLike, String).join(', ')}]`;
155 assert.compareArray = function(actual, expected, message) {
156 message = message === undefined ? '' : message;
158 if (typeof message === 'symbol') {
159 message = message.toString();
162 assert(actual != null, `First argument shouldn't be nullish. ${message}`);
163 assert(expected != null, `Second argument shouldn't be nullish. ${message}`);
164 var format = compareArray.format;
165 var result = compareArray(actual, expected);
167 // The following prevents actual and expected from being iterated and evaluated
168 // more than once unless absolutely necessary.
170 assert(false, `Expected ${format(actual)} and ${format(expected)} to have the same contents. ${message}`);
174 // file: propertyHelper.js
175 // Copyright (C) 2017 Ecma International. All rights reserved.
176 // This code is governed by the BSD license found in the LICENSE file.
179 Collection of functions used to safely verify the correctness of
180 property descriptors.
183 - verifyEqualTo # deprecated
184 - verifyWritable # deprecated
185 - verifyNotWritable # deprecated
186 - verifyEnumerable # deprecated
187 - verifyNotEnumerable # deprecated
188 - verifyConfigurable # deprecated
189 - verifyNotConfigurable # deprecated
195 * @param {object} obj
196 * @param {string|symbol} name
197 * @param {PropertyDescriptor|undefined} desc
198 * @param {object} [options]
199 * @param {boolean} [options.restore]
201 function verifyProperty(obj, name, desc, options) {
203 arguments.length > 2,
204 'verifyProperty should receive at least 3 arguments: obj, name, and descriptor'
207 var originalDesc = Object.getOwnPropertyDescriptor(obj, name);
208 var nameStr = String(name);
210 // Allows checking for undefined descriptor if it's explicitly given.
211 if (desc === undefined) {
215 "obj['" + nameStr + "'] descriptor should be undefined"
218 // desc and originalDesc are both undefined, problem solved;
223 Object.prototype.hasOwnProperty.call(obj, name),
224 "obj should have an own property " + nameStr
230 "The desc argument should be an object or undefined, null"
236 "The desc argument should be an object or undefined, " + String(desc)
239 var names = Object.getOwnPropertyNames(desc);
240 for (var i = 0; i < names.length; i++) {
242 names[i] === "value" ||
243 names[i] === "writable" ||
244 names[i] === "enumerable" ||
245 names[i] === "configurable" ||
246 names[i] === "get" ||
248 "Invalid descriptor field: " + names[i],
254 if (Object.prototype.hasOwnProperty.call(desc, 'value')) {
255 if (!isSameValue(desc.value, originalDesc.value)) {
256 failures.push("descriptor value should be " + desc.value);
258 if (!isSameValue(desc.value, obj[name])) {
259 failures.push("object value should be " + desc.value);
263 if (Object.prototype.hasOwnProperty.call(desc, 'enumerable')) {
264 if (desc.enumerable !== originalDesc.enumerable ||
265 desc.enumerable !== isEnumerable(obj, name)) {
266 failures.push('descriptor should ' + (desc.enumerable ? '' : 'not ') + 'be enumerable');
270 if (Object.prototype.hasOwnProperty.call(desc, 'writable')) {
271 if (desc.writable !== originalDesc.writable ||
272 desc.writable !== isWritable(obj, name)) {
273 failures.push('descriptor should ' + (desc.writable ? '' : 'not ') + 'be writable');
277 if (Object.prototype.hasOwnProperty.call(desc, 'configurable')) {
278 if (desc.configurable !== originalDesc.configurable ||
279 desc.configurable !== isConfigurable(obj, name)) {
280 failures.push('descriptor should ' + (desc.configurable ? '' : 'not ') + 'be configurable');
284 assert(!failures.length, failures.join('; '));
286 if (options && options.restore) {
287 Object.defineProperty(obj, name, originalDesc);
293 function isConfigurable(obj, name) {
294 var hasOwnProperty = Object.prototype.hasOwnProperty;
298 if (!(e instanceof TypeError)) {
299 throw new Test262Error("Expected TypeError, got " + e);
302 return !hasOwnProperty.call(obj, name);
305 function isEnumerable(obj, name) {
306 var stringCheck = false;
308 if (typeof name === "string") {
316 // skip it if name is not string, works for Symbol names.
320 return stringCheck &&
321 Object.prototype.hasOwnProperty.call(obj, name) &&
322 Object.prototype.propertyIsEnumerable.call(obj, name);
325 function isSameValue(a, b) {
326 if (a === 0 && b === 0) return 1 / a === 1 / b;
327 if (a !== a && b !== b) return true;
332 var __isArray = Array.isArray;
333 function isWritable(obj, name, verifyProp, value) {
334 var unlikelyValue = __isArray(obj) && name === "length" ?
335 Math.pow(2, 32) - 1 :
337 var newValue = value || unlikelyValue;
338 var hadValue = Object.prototype.hasOwnProperty.call(obj, name);
339 var oldValue = obj[name];
343 obj[name] = newValue;
345 if (!(e instanceof TypeError)) {
346 throw new Test262Error("Expected TypeError, got " + e);
350 writeSucceeded = isSameValue(obj[verifyProp || name], newValue);
352 // Revert the change only if it was successful (in other cases, reverting
353 // is unnecessary and may trigger exceptions for certain property
355 if (writeSucceeded) {
357 obj[name] = oldValue;
363 return writeSucceeded;
367 * Deprecated; please use `verifyProperty` in new tests.
369 function verifyEqualTo(obj, name, value) {
370 if (!isSameValue(obj[name], value)) {
371 throw new Test262Error("Expected obj[" + String(name) + "] to equal " + value +
372 ", actually " + obj[name]);
377 * Deprecated; please use `verifyProperty` in new tests.
379 function verifyWritable(obj, name, verifyProp, value) {
381 assert(Object.getOwnPropertyDescriptor(obj, name).writable,
382 "Expected obj[" + String(name) + "] to have writable:true.");
384 if (!isWritable(obj, name, verifyProp, value)) {
385 throw new Test262Error("Expected obj[" + String(name) + "] to be writable, but was not.");
390 * Deprecated; please use `verifyProperty` in new tests.
392 function verifyNotWritable(obj, name, verifyProp, value) {
394 assert(!Object.getOwnPropertyDescriptor(obj, name).writable,
395 "Expected obj[" + String(name) + "] to have writable:false.");
397 if (isWritable(obj, name, verifyProp)) {
398 throw new Test262Error("Expected obj[" + String(name) + "] NOT to be writable, but was.");
403 * Deprecated; please use `verifyProperty` in new tests.
405 function verifyEnumerable(obj, name) {
406 assert(Object.getOwnPropertyDescriptor(obj, name).enumerable,
407 "Expected obj[" + String(name) + "] to have enumerable:true.");
408 if (!isEnumerable(obj, name)) {
409 throw new Test262Error("Expected obj[" + String(name) + "] to be enumerable, but was not.");
414 * Deprecated; please use `verifyProperty` in new tests.
416 function verifyNotEnumerable(obj, name) {
417 assert(!Object.getOwnPropertyDescriptor(obj, name).enumerable,
418 "Expected obj[" + String(name) + "] to have enumerable:false.");
419 if (isEnumerable(obj, name)) {
420 throw new Test262Error("Expected obj[" + String(name) + "] NOT to be enumerable, but was.");
425 * Deprecated; please use `verifyProperty` in new tests.
427 function verifyConfigurable(obj, name) {
428 assert(Object.getOwnPropertyDescriptor(obj, name).configurable,
429 "Expected obj[" + String(name) + "] to have configurable:true.");
430 if (!isConfigurable(obj, name)) {
431 throw new Test262Error("Expected obj[" + String(name) + "] to be configurable, but was not.");
436 * Deprecated; please use `verifyProperty` in new tests.
438 function verifyNotConfigurable(obj, name) {
439 assert(!Object.getOwnPropertyDescriptor(obj, name).configurable,
440 "Expected obj[" + String(name) + "] to have configurable:false.");
441 if (isConfigurable(obj, name)) {
442 throw new Test262Error("Expected obj[" + String(name) + "] NOT to be configurable, but was.");
447 // Copyright (c) 2012 Ecma International. All rights reserved.
448 // This code is governed by the BSD license found in the LICENSE file.
453 - An error class to avoid false positives when testing for thrown exceptions
454 - A function to explicitly throw an exception using the Test262Error class
455 defines: [Test262Error, $DONOTEVALUATE]
459 function Test262Error(message) {
460 this.message = message || "";
463 Test262Error.prototype.toString = function () {
464 return "Test262Error: " + this.message;
467 Test262Error.thrower = function (message) {
468 throw new Test262Error(message);
471 function $DONOTEVALUATE() {
472 throw "Test262: This statement should not be evaluated.";
475 // file: test262-host.js
476 // This Source Code Form is subject to the terms of the Mozilla Public
477 // License, v. 2.0. If a copy of the MPL was not distributed with this
478 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
480 // https://github.com/tc39/test262/blob/main/INTERPRETING.md#host-defined-functions
481 ;(function createHostObject(global) {
484 // Save built-in functions and constructors.
485 var FunctionToString = global.Function.prototype.toString;
486 var ReflectApply = global.Reflect.apply;
487 var Atomics = global.Atomics;
488 var Error = global.Error;
489 var SharedArrayBuffer = global.SharedArrayBuffer;
490 var Int32Array = global.Int32Array;
492 // Save built-in shell functions.
493 var NewGlobal = global.newGlobal;
494 var setSharedArrayBuffer = global.setSharedArrayBuffer;
495 var getSharedArrayBuffer = global.getSharedArrayBuffer;
496 var evalInWorker = global.evalInWorker;
497 var monotonicNow = global.monotonicNow;
499 var clearKeptObjects = global.clearKeptObjects;
501 var hasCreateIsHTMLDDA = "createIsHTMLDDA" in global;
502 var hasThreads = ("helperThreadCount" in global ? global.helperThreadCount() > 0 : true);
503 var hasMailbox = typeof setSharedArrayBuffer === "function" && typeof getSharedArrayBuffer === "function";
504 var hasEvalInWorker = typeof evalInWorker === "function";
506 if (!hasCreateIsHTMLDDA && !("document" in global && "all" in global.document))
507 throw new Error("no [[IsHTMLDDA]] object available for testing");
509 var IsHTMLDDA = hasCreateIsHTMLDDA
510 ? global.createIsHTMLDDA()
511 : global.document.all;
513 // The $262.agent framework is not appropriate for browsers yet, and some
514 // test cases can't work in browsers (they block the main thread).
516 var shellCode = hasMailbox && hasEvalInWorker;
517 var sabTestable = Atomics && SharedArrayBuffer && hasThreads && shellCode;
522 var newGlobalObject = NewGlobal();
523 var createHostObjectFn = ReflectApply(FunctionToString, createHostObject, []);
524 newGlobalObject.Function(`${createHostObjectFn} createHostObject(this);`)();
525 return newGlobalObject.$262;
527 detachArrayBuffer: global.detachArrayBuffer,
528 evalScript: global.evaluateScript || global.evaluate,
537 agent: (function () {
539 // SpiderMonkey complication: With run-time argument --no-threads
540 // our test runner will not properly filter test cases that can't be
541 // run because agents can't be started, and so we do a little
542 // filtering here: We will quietly succeed and exit if an agent test
543 // should not have been run because threads cannot be started.
545 // Firefox complication: The test cases that use $262.agent can't
546 // currently work in the browser, so for now we rely on them not
550 let {reportCompare, quit} = global;
552 function notAvailable() {
553 // See comment above.
554 if (!hasThreads && shellCode) {
558 throw new Error("Agents not available");
562 start(script) { notAvailable() },
563 broadcast(sab, id) { notAvailable() },
564 getReport() { notAvailable() },
565 sleep(s) { notAvailable() },
570 // The SpiderMonkey implementation uses a designated shared buffer _ia
571 // for coordination, and spinlocks for everything except sleeping.
573 var _MSG_LOC = 0; // Low bit set: broadcast available; High bits: seq #
574 var _ID_LOC = 1; // ID sent with broadcast
575 var _ACK_LOC = 2; // Worker increments this to ack that broadcast was received
576 var _RDY_LOC = 3; // Worker increments this to ack that worker is up and running
577 var _LOCKTXT_LOC = 4; // Writer lock for the text buffer: 0=open, 1=closed
578 var _NUMTXT_LOC = 5; // Count of messages in text buffer
579 var _NEXT_LOC = 6; // First free location in the buffer
580 var _SLEEP_LOC = 7; // Used for sleeping
582 var _FIRST = 10; // First location of first message
584 var _ia = new Int32Array(new SharedArrayBuffer(65536));
585 _ia[_NEXT_LOC] = _FIRST;
588 // BEGIN WORKER PREFIX
589 `if (typeof $262 === 'undefined')
591 $262.agent = (function (global) {
592 var ReflectApply = global.Reflect.apply;
593 var StringCharCodeAt = global.String.prototype.charCodeAt;
596 compareExchange: Atomics_compareExchange,
598 store: Atomics_store,
602 var {getSharedArrayBuffer} = global;
604 var _ia = new Int32Array(getSharedArrayBuffer());
606 receiveBroadcast(receiver) {
608 while (((k = Atomics_load(_ia, ${_MSG_LOC})) & 1) === 0)
610 var received_sab = getSharedArrayBuffer();
611 var received_id = Atomics_load(_ia, ${_ID_LOC});
612 Atomics_add(_ia, ${_ACK_LOC}, 1);
613 while (Atomics_load(_ia, ${_MSG_LOC}) === k)
615 receiver(received_sab, received_id);
619 while (Atomics_compareExchange(_ia, ${_LOCKTXT_LOC}, 0, 1) === 1)
622 var i = _ia[${_NEXT_LOC}];
623 _ia[i++] = msg.length;
624 for ( let j=0 ; j < msg.length ; j++ )
625 _ia[i++] = ReflectApply(StringCharCodeAt, msg, [j]);
626 _ia[${_NEXT_LOC}] = i;
627 Atomics_add(_ia, ${_NUMTXT_LOC}, 1);
628 Atomics_store(_ia, ${_LOCKTXT_LOC}, 0);
632 Atomics_wait(_ia, ${_SLEEP_LOC}, 0, s);
637 monotonicNow: global.monotonicNow,
639 Atomics_add(_ia, ${_RDY_LOC}, 1);
646 var _reportPtr = _FIRST;
650 store: Atomics_store,
653 var StringFromCharCode = global.String.fromCharCode;
657 setSharedArrayBuffer(_ia.buffer);
658 var oldrdy = Atomics_load(_ia, _RDY_LOC);
659 evalInWorker(_worker_prefix + script);
660 while (Atomics_load(_ia, _RDY_LOC) === oldrdy)
666 setSharedArrayBuffer(sab);
667 Atomics_store(_ia, _ID_LOC, id);
668 Atomics_store(_ia, _ACK_LOC, 0);
669 Atomics_add(_ia, _MSG_LOC, 1);
670 while (Atomics_load(_ia, _ACK_LOC) < _numWorkers)
672 Atomics_add(_ia, _MSG_LOC, 1);
676 if (_numReports === Atomics_load(_ia, _NUMTXT_LOC))
681 for ( let j=0 ; j < len ; j++ )
682 s += StringFromCharCode(_ia[i++]);
689 Atomics_wait(_ia, _SLEEP_LOC, 0, s);
698 var $mozAsyncTestDone = false;
699 function $DONE(failure) {
700 // This function is generally called from within a Promise handler, so any
701 // exception thrown by this method will be swallowed and most likely
702 // ignored by the Promise machinery.
703 if ($mozAsyncTestDone) {
704 reportFailure("$DONE() already called");
707 $mozAsyncTestDone = true;
710 reportFailure(failure);
714 if (typeof jsTestDriverEnd === "function") {
715 gDelayTestDriverEnd = false;
720 // Some tests in test262 leave promise rejections unhandled.
721 if ("ignoreUnhandledRejections" in this) {
722 ignoreUnhandledRejections();