mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 07:25:15 +02:00
harness: Add a function to get well-known intrinsic objects
wellKnownIntrinsicObjects.js now exposes a getWellKnownIntrinsicObject() function which returns the object corresponding to a key like %Array%. If the object is not provided by the implementation, or not accessible, it throws a Test262Error. This is so that tests depending on that intrinsic object can easily fail.
This commit is contained in:
parent
e133564cfa
commit
2af27af915
@ -3,7 +3,7 @@
|
|||||||
/*---
|
/*---
|
||||||
description: |
|
description: |
|
||||||
An Array of all representable Well-Known Intrinsic Objects
|
An Array of all representable Well-Known Intrinsic Objects
|
||||||
defines: [WellKnownIntrinsicObjects]
|
defines: [WellKnownIntrinsicObjects, getWellKnownIntrinsicObject]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const WellKnownIntrinsicObjects = [
|
const WellKnownIntrinsicObjects = [
|
||||||
@ -306,3 +306,22 @@ WellKnownIntrinsicObjects.forEach((wkio) => {
|
|||||||
|
|
||||||
wkio.value = actual;
|
wkio.value = actual;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a well-known intrinsic object, if the implementation provides it.
|
||||||
|
* Otherwise, throws.
|
||||||
|
* @param {string} key - the specification's name for the intrinsic, for example
|
||||||
|
* "%Array%"
|
||||||
|
* @returns {object} the well-known intrinsic object.
|
||||||
|
*/
|
||||||
|
function getWellKnownIntrinsicObject(key) {
|
||||||
|
for (var ix = 0; ix < WellKnownIntrinsicObjects.length; ix++) {
|
||||||
|
if (WellKnownIntrinsicObjects[ix].name === key) {
|
||||||
|
var value = WellKnownIntrinsicObjects[ix].value;
|
||||||
|
if (value !== undefined)
|
||||||
|
return value;
|
||||||
|
throw new Test262Error('this implementation could not obtain ' + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Test262Error('unknown well-known intrinsic ' + key);
|
||||||
|
}
|
||||||
|
21
test/harness/wellKnownIntrinsicObjects.js
Normal file
21
test/harness/wellKnownIntrinsicObjects.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/*---
|
||||||
|
description: Basic tests for getWellKnownIntrinsicObject harness function
|
||||||
|
includes: [wellKnownIntrinsicObjects.js]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
// Accessible in every implementation
|
||||||
|
var intrinsicArray = getWellKnownIntrinsicObject('%Array%');
|
||||||
|
assert(Object.is(Array, intrinsicArray));
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function () {
|
||||||
|
// Exists but is not accessible in any implementation
|
||||||
|
getWellKnownIntrinsicObject('%AsyncFromSyncIteratorPrototype%');
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(Test262Error, function () {
|
||||||
|
// Does not exist in any implementation
|
||||||
|
getWellKnownIntrinsicObject('%NotSoWellKnownIntrinsicObject%');
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user