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