No longer use testBuiltInObject for built-in objects

This commit is contained in:
André Bargull 2017-12-21 12:08:28 -08:00 committed by Rick Waldron
parent ecf814bb4c
commit c81370348d
21 changed files with 50 additions and 51 deletions

View File

@ -9,56 +9,47 @@ description: |
* @description Tests that obj meets the requirements for built-in objects
* defined by the introduction of chapter 15 of the ECMAScript Language Specification.
* @param {Object} obj the object to be tested.
* @param {boolean} isFunction whether the specification describes obj as a function.
* @author Norbert Lindenberg
*/
function testBuiltInObject(obj, isFunction) {
function testBuiltInObject(obj) {
if (obj === undefined) {
$ERROR("Object being tested is undefined.");
}
var objString = Object.prototype.toString.call(obj);
if (isFunction) {
if (objString !== "[object Function]") {
$ERROR("The [[Class]] internal property of a built-in function must be " +
"\"Function\", but toString() returns " + objString);
}
} else {
if (objString !== "[object Object]") {
$ERROR("The [[Class]] internal property of a built-in non-function object must be " +
"\"Object\", but toString() returns " + objString);
}
if (objString !== "[object Function]") {
$ERROR("The [[Class]] internal property of a built-in function must be " +
"\"Function\", but toString() returns " + objString);
}
if (!Object.isExtensible(obj)) {
$ERROR("Built-in objects must be extensible.");
}
if (isFunction && Object.getPrototypeOf(obj) !== Function.prototype) {
if (Object.getPrototypeOf(obj) !== Function.prototype) {
$ERROR("Built-in functions must have Function.prototype as their prototype.");
}
var exception;
if (isFunction) {
// this is not a complete test for the presence of [[Construct]]:
// if it's absent, the exception must be thrown, but it may also
// be thrown if it's present and just has preconditions related to
// arguments or the this value that this statement doesn't meet.
try {
/*jshint newcap:false*/
var instance = new obj();
} catch (e) {
exception = e;
}
if (exception === undefined || exception.name !== "TypeError") {
$ERROR("Built-in functions that aren't constructors must throw TypeError when " +
"used in a \"new\" statement.");
}
// this is not a complete test for the presence of [[Construct]]:
// if it's absent, the exception must be thrown, but it may also
// be thrown if it's present and just has preconditions related to
// arguments or the this value that this statement doesn't meet.
try {
/*jshint newcap:false*/
var instance = new obj();
} catch (e) {
exception = e;
}
if (exception === undefined || exception.name !== "TypeError") {
$ERROR("Built-in functions that aren't constructors must throw TypeError when " +
"used in a \"new\" statement.");
}
if (isFunction && obj.hasOwnProperty("prototype")) {
if (obj.hasOwnProperty("prototype")) {
$ERROR("Built-in functions that aren't constructors must not have a prototype property.");
}

View File

@ -12,4 +12,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(new Intl.Collator().compare, true);
testBuiltInObject(new Intl.Collator().compare);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.Collator.prototype, "compare").get , true);
testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.Collator.prototype, "compare").get);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Intl.Collator.prototype.resolvedOptions, true);
testBuiltInObject(Intl.Collator.prototype.resolvedOptions);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Intl.Collator.supportedLocalesOf, true);
testBuiltInObject(Intl.Collator.supportedLocalesOf);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Date.prototype.toLocaleDateString, true);
testBuiltInObject(Date.prototype.toLocaleDateString);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Date.prototype.toLocaleString, true);
testBuiltInObject(Date.prototype.toLocaleString);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Date.prototype.toLocaleTimeString, true);
testBuiltInObject(Date.prototype.toLocaleTimeString);

View File

@ -12,4 +12,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(new Intl.DateTimeFormat().format, true);
testBuiltInObject(new Intl.DateTimeFormat().format);

View File

@ -12,4 +12,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.DateTimeFormat.prototype, "format").get , true);
testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.DateTimeFormat.prototype, "format").get);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Intl.DateTimeFormat.prototype.resolvedOptions, true);
testBuiltInObject(Intl.DateTimeFormat.prototype.resolvedOptions);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Intl.DateTimeFormat.supportedLocalesOf, true);
testBuiltInObject(Intl.DateTimeFormat.supportedLocalesOf);

View File

@ -8,8 +8,16 @@ description: >
defined by the introduction of chapter 17 of the ECMAScript
Language Specification.
author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(this.Intl, false);
testBuiltInObject(Intl, false);
assert.sameValue(Object.prototype.toString.call(Intl), "[object Object]",
"The [[Class]] internal property of a built-in non-function object must be " +
"\"Object\".");
assert(Object.isExtensible(Intl), "Built-in objects must be extensible.");
assert.sameValue(Object.getPrototypeOf(Intl), Object.prototype,
"The [[Prototype]] of Intl is %ObjectPrototype%.");
assert.sameValue(this.Intl, Intl,
"%Intl% is accessible as a property of the global object.");

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Number.prototype.toLocaleString, true);
testBuiltInObject(Number.prototype.toLocaleString);

View File

@ -12,4 +12,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(new Intl.NumberFormat().format, true);
testBuiltInObject(new Intl.NumberFormat().format);

View File

@ -12,4 +12,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get , true);
testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Intl.NumberFormat.prototype.resolvedOptions, true);
testBuiltInObject(Intl.NumberFormat.prototype.resolvedOptions);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Intl.NumberFormat.supportedLocalesOf, true);
testBuiltInObject(Intl.NumberFormat.supportedLocalesOf);

View File

@ -11,4 +11,4 @@ author: Zibi Braniecki
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Intl.PluralRules.prototype.resolvedOptions, true);
testBuiltInObject(Intl.PluralRules.prototype.resolvedOptions);

View File

@ -11,4 +11,4 @@ author: Zibi Braniecki
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(Intl.PluralRules.supportedLocalesOf, true);
testBuiltInObject(Intl.PluralRules.supportedLocalesOf);

View File

@ -11,4 +11,4 @@ author: Norbert Lindenberg
includes: [testBuiltInObject.js]
---*/
testBuiltInObject(String.prototype.localeCompare, true);
testBuiltInObject(String.prototype.localeCompare);