mirror of https://github.com/tc39/test262.git
Added tests for requirements imposed on the built-in objects of the ECMAScript Internationalization API Specification by the introduction of chapter 15 of the ECMAScript Language Specification.
- Removed some old tests that were redundant with the new tests. - Added testBuiltInObject.js as standard include for all console tests in test262.py – see related bug 574.
This commit is contained in:
parent
1be52e222b
commit
8cad7d03ce
|
@ -0,0 +1,123 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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.
|
||||||
|
* @param {boolean} isConstructor whether the specification describes obj as a constructor.
|
||||||
|
* @param {String[]} properties an array with the names of the built-in properties of obj,
|
||||||
|
* excluding length, prototype, or properties with non-default attributes.
|
||||||
|
* @param {number} length for functions only: the length specified for the function
|
||||||
|
* or derived from the argument list.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
function testBuiltInObject(obj, isFunction, isConstructor, properties, length) {
|
||||||
|
|
||||||
|
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 (!Object.isExtensible(obj)) {
|
||||||
|
$ERROR("Built-in objects must be extensible.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFunction && Object.getPrototypeOf(obj) !== Function.prototype) {
|
||||||
|
$ERROR("Built-in functions must have Function.prototype as their prototype.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isConstructor && Object.getPrototypeOf(obj.prototype) !== Object.prototype) {
|
||||||
|
$ERROR("Built-in prototype objects must have Object.prototype as their prototype.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// verification of the absence of the [[Construct]] internal property has
|
||||||
|
// been moved to the end of the test
|
||||||
|
|
||||||
|
// verification of the absence of the prototype property has
|
||||||
|
// been moved to the end of the test
|
||||||
|
|
||||||
|
if (isFunction) {
|
||||||
|
|
||||||
|
if (typeof obj.length !== "number" || obj.length !== Math.floor(obj.length)) {
|
||||||
|
$ERROR("Built-in functions must have a length property with an integer value.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj.length !== length) {
|
||||||
|
$ERROR("Function's length property doesn't have specified value.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(obj, "length");
|
||||||
|
if (desc.writable) {
|
||||||
|
$ERROR("The length property of a built-in function must not be writable.");
|
||||||
|
}
|
||||||
|
if (desc.enumerable) {
|
||||||
|
$ERROR("The length property of a built-in function must not be enumerable.");
|
||||||
|
}
|
||||||
|
if (desc.configurable) {
|
||||||
|
$ERROR("The length property of a built-in function must not be configurable.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
properties.forEach(function(prop) {
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(obj, prop);
|
||||||
|
if (desc === undefined) {
|
||||||
|
$ERROR("Missing property " + prop + ".");
|
||||||
|
}
|
||||||
|
// accessor properties don't have writable attribute
|
||||||
|
if (desc.hasOwnProperty("writable") && !desc.writable) {
|
||||||
|
$ERROR("The " + prop + " property of this built-in function must be writable.");
|
||||||
|
}
|
||||||
|
if (desc.enumerable) {
|
||||||
|
$ERROR("The " + prop + " property of this built-in function must not be enumerable.");
|
||||||
|
}
|
||||||
|
if (!desc.configurable) {
|
||||||
|
$ERROR("The " + prop + " property of this built-in function must be configurable.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// The remaining sections have been moved to the end of the test because
|
||||||
|
// unbound non-constructor functions written in JavaScript cannot possibly
|
||||||
|
// pass them, and we still want to test JavaScript implementations as much
|
||||||
|
// as possible.
|
||||||
|
|
||||||
|
var exception;
|
||||||
|
if (isFunction && !isConstructor) {
|
||||||
|
// 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 && !isConstructor && obj.hasOwnProperty("prototype")) {
|
||||||
|
$ERROR("Built-in functions that aren't constructors must not have a prototype property.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// passed the complete test!
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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.
|
||||||
|
* @param {boolean} isConstructor whether the specification describes obj as a constructor.
|
||||||
|
* @param {String[]} properties an array with the names of the built-in properties of obj,
|
||||||
|
* excluding length, prototype, or properties with non-default attributes.
|
||||||
|
* @param {number} length for functions only: the length specified for the function
|
||||||
|
* or derived from the argument list.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
function testBuiltInObject(obj, isFunction, isConstructor, properties, length) {
|
||||||
|
|
||||||
|
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 (!Object.isExtensible(obj)) {
|
||||||
|
$ERROR("Built-in objects must be extensible.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFunction && Object.getPrototypeOf(obj) !== Function.prototype) {
|
||||||
|
$ERROR("Built-in functions must have Function.prototype as their prototype.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isConstructor && Object.getPrototypeOf(obj.prototype) !== Object.prototype) {
|
||||||
|
$ERROR("Built-in prototype objects must have Object.prototype as their prototype.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// verification of the absence of the [[Construct]] internal property has
|
||||||
|
// been moved to the end of the test
|
||||||
|
|
||||||
|
// verification of the absence of the prototype property has
|
||||||
|
// been moved to the end of the test
|
||||||
|
|
||||||
|
if (isFunction) {
|
||||||
|
|
||||||
|
if (typeof obj.length !== "number" || obj.length !== Math.floor(obj.length)) {
|
||||||
|
$ERROR("Built-in functions must have a length property with an integer value.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj.length !== length) {
|
||||||
|
$ERROR("Function's length property doesn't have specified value.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(obj, "length");
|
||||||
|
if (desc.writable) {
|
||||||
|
$ERROR("The length property of a built-in function must not be writable.");
|
||||||
|
}
|
||||||
|
if (desc.enumerable) {
|
||||||
|
$ERROR("The length property of a built-in function must not be enumerable.");
|
||||||
|
}
|
||||||
|
if (desc.configurable) {
|
||||||
|
$ERROR("The length property of a built-in function must not be configurable.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
properties.forEach(function(prop) {
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(obj, prop);
|
||||||
|
if (desc === undefined) {
|
||||||
|
$ERROR("Missing property " + prop + ".");
|
||||||
|
}
|
||||||
|
// accessor properties don't have writable attribute
|
||||||
|
if (desc.hasOwnProperty("writable") && !desc.writable) {
|
||||||
|
$ERROR("The " + prop + " property of this built-in function must be writable.");
|
||||||
|
}
|
||||||
|
if (desc.enumerable) {
|
||||||
|
$ERROR("The " + prop + " property of this built-in function must not be enumerable.");
|
||||||
|
}
|
||||||
|
if (!desc.configurable) {
|
||||||
|
$ERROR("The " + prop + " property of this built-in function must be configurable.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// The remaining sections have been moved to the end of the test because
|
||||||
|
// unbound non-constructor functions written in JavaScript cannot possibly
|
||||||
|
// pass them, and we still want to test JavaScript implementations as much
|
||||||
|
// as possible.
|
||||||
|
|
||||||
|
var exception;
|
||||||
|
if (isFunction && !isConstructor) {
|
||||||
|
// 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 && !isConstructor && obj.hasOwnProperty("prototype")) {
|
||||||
|
$ERROR("Built-in functions that aren't constructors must not have a prototype property.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// passed the complete test!
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
// Copyright 2012 Google Inc. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Tests properties of Intl object.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// We keep Intl extensible and not frozen.
|
|
||||||
if (Object.isFrozen(Intl) === true) {
|
|
||||||
$ERROR('isFrozen(Intl) returns true.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.isExtensible(Intl) === false) {
|
|
||||||
$ERROR('isExtensible(Intl) returns false.');
|
|
||||||
}
|
|
||||||
|
|
||||||
var falsey;
|
|
||||||
|
|
||||||
// Intl can't be constructed.
|
|
||||||
try {
|
|
||||||
falsey = new Intl();
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!!falsey) {
|
|
||||||
$ERROR('Intl object should not be constructable.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intl can't be called as a function.
|
|
||||||
try {
|
|
||||||
/*jshint newcap:false*/
|
|
||||||
falsey = Intl();
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!!falsey) {
|
|
||||||
$ERROR('Intl should not be callable.');
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl, false, false, ["Collator", "NumberFormat", "DateTimeFormat"]);
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
// Copyright 2012 Google Inc. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Tests that Intl object has proper constructors.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (Intl === undefined) {
|
|
||||||
$ERROR('Intl object is undefined.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof Intl.Collator !== 'function') {
|
|
||||||
$ERROR('Intl.Collator is not a function.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof Intl.NumberFormat !== 'function') {
|
|
||||||
$ERROR('Intl.NumberFormat is not a function.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof Intl.DateTimeFormat !== 'function') {
|
|
||||||
$ERROR('Intl.DateTimeFormat is not a function.');
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.Collator
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.Collator, true, true, ["supportedLocalesOf"], 0);
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
// Copyright 2012 Google Inc. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Tests that the Intl.Collator prototype object exists and
|
|
||||||
* is not writable, enumerable, or configurable.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var desc;
|
|
||||||
|
|
||||||
if (!Intl.Collator.hasOwnProperty('prototype')) {
|
|
||||||
$ERROR('Intl.Collator has no prototype property');
|
|
||||||
}
|
|
||||||
|
|
||||||
desc = Object.getOwnPropertyDescriptor(Intl.Collator, 'prototype');
|
|
||||||
if (desc.writable === true) {
|
|
||||||
$ERROR('Intl.Collator.prototype is writable.');
|
|
||||||
}
|
|
||||||
if (desc.enumerable === true) {
|
|
||||||
$ERROR('Intl.Collator.prototype is enumerable.');
|
|
||||||
}
|
|
||||||
if (desc.configurable === true) {
|
|
||||||
$ERROR('Intl.Collator.prototype is configurable.');
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.Collator.supportedLocalesOf
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.Collator.supportedLocalesOf, true, false, [], 1);
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
// Copyright 2012 Google Inc. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Tests that the Intl.Collator constructor has a length
|
|
||||||
* property that equals 2.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!Intl.Collator.hasOwnProperty('length')) {
|
|
||||||
$ERROR('Intl.Collator has no length property');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Intl.Collator.length != 2) {
|
|
||||||
$ERROR('Intl.Collator.length is not 2.');
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that the function returned by Intl.Collator.prototype.compare
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(new Intl.Collator().compare, true, false, [], 2);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that the getter for Intl.Collator.prototype.compare
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.Collator.prototype, "compare").get , true, false, [], 0);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.Collator.prototype.resolvedOptions
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.Collator.prototype.resolvedOptions, true, false, [], 0);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.Collator.prototype
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.Collator.prototype, false, false, ["constructor", "compare", "resolvedOptions"]);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.NumberFormat
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.NumberFormat, true, true, ["supportedLocalesOf"], 0);
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
// Copyright 2012 Google Inc. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Tests that the Intl.NumberFormat prototype object exists and
|
|
||||||
* is not writable, enumerable, or configurable.
|
|
||||||
* @author: Roozbeh Pournader
|
|
||||||
*/
|
|
||||||
|
|
||||||
var desc;
|
|
||||||
|
|
||||||
if (!Intl.NumberFormat.hasOwnProperty('prototype')) {
|
|
||||||
$ERROR('Intl.NumberFormat has no prototype property');
|
|
||||||
}
|
|
||||||
|
|
||||||
desc = Object.getOwnPropertyDescriptor(Intl.NumberFormat, 'prototype');
|
|
||||||
if (desc.writable === true) {
|
|
||||||
$ERROR('Intl.NumberFormat.prototype is writable.');
|
|
||||||
}
|
|
||||||
if (desc.enumerable === true) {
|
|
||||||
$ERROR('Intl.NumberFormat.prototype is enumerable.');
|
|
||||||
}
|
|
||||||
if (desc.configurable === true) {
|
|
||||||
$ERROR('Intl.NumberFormat.prototype is configurable.');
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.NumberFormat.supportedLocalesOf
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.NumberFormat.supportedLocalesOf, true, false, [], 1);
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
// Copyright 2012 Google Inc. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Tests that the Intl.NumberFormat constructor has a length
|
|
||||||
* property that equals 2.
|
|
||||||
* @author: Roozbeh Pournader
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!Intl.NumberFormat.hasOwnProperty('length')) {
|
|
||||||
$ERROR('Intl.NumberFormat has no length property');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Intl.NumberFormat.length != 2) {
|
|
||||||
$ERROR('Intl.NumberFormat.length is not 2.');
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that the function returned by Intl.NumberFormat.prototype.format
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(new Intl.NumberFormat().format, true, false, [], 1);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that the getter for Intl.NumberFormat.prototype.format
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, "format").get , true, false, [], 0);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.NumberFormat.prototype.resolvedOptions
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.NumberFormat.prototype.resolvedOptions, true, false, [], 0);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.NumberFormat.prototype
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.NumberFormat.prototype, false, false, ["constructor", "format", "resolvedOptions"]);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.DateTimeFormat
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.DateTimeFormat, true, true, ["supportedLocalesOf"], 0);
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
// Copyright 2012 Google Inc. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Tests that the Intl.DateTimeFormat prototype object exists and
|
|
||||||
* is not writable, enumerable, or configurable.
|
|
||||||
* @author: Roozbeh Pournader
|
|
||||||
*/
|
|
||||||
|
|
||||||
var desc;
|
|
||||||
|
|
||||||
if (!Intl.DateTimeFormat.hasOwnProperty('prototype')) {
|
|
||||||
$ERROR('Intl.DateTimeFormat has no prototype property');
|
|
||||||
}
|
|
||||||
|
|
||||||
desc = Object.getOwnPropertyDescriptor(Intl.DateTimeFormat, 'prototype');
|
|
||||||
if (desc.writable === true) {
|
|
||||||
$ERROR('Intl.DateTimeFormat.prototype is writable.');
|
|
||||||
}
|
|
||||||
if (desc.enumerable === true) {
|
|
||||||
$ERROR('Intl.DateTimeFormat.prototype is enumerable.');
|
|
||||||
}
|
|
||||||
if (desc.configurable === true) {
|
|
||||||
$ERROR('Intl.DateTimeFormat.prototype is configurable.');
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.DateTimeFormat.supportedLocalesOf
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.DateTimeFormat.supportedLocalesOf, true, false, [], 1);
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
// Copyright 2012 Google Inc. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Tests that the Intl.DateTimeFormat constructor has a length
|
|
||||||
* property that equals 2.
|
|
||||||
* @author: Roozbeh Pournader
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!Intl.DateTimeFormat.hasOwnProperty('length')) {
|
|
||||||
$ERROR('Intl.DateTimeFormat has no length property');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Intl.DateTimeFormat.length != 2) {
|
|
||||||
$ERROR('Intl.DateTimeFormat.length is not 2.');
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that the function returned by Intl.DateTimeFormat.prototype.format
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(new Intl.DateTimeFormat().format, true, false, [], 0);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that the getter for Intl.DateTimeFormat.prototype.format
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Object.getOwnPropertyDescriptor(Intl.DateTimeFormat.prototype, "format").get , true, false, [], 0);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.DateTimeFormat.prototype.resolvedOptions
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.DateTimeFormat.prototype.resolvedOptions, true, false, [], 0);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Intl.DateTimeFormat.prototype
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Intl.DateTimeFormat.prototype, false, false, ["constructor", "format", "resolvedOptions"]);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that String.prototype.localeCompare
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(String.prototype.localeCompare, true, false, [], 1);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Number.prototype.toLocaleString
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Number.prototype.toLocaleString, true, false, [], 0);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Date.prototype.toLocaleString
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Date.prototype.toLocaleString, true, false, [], 0);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Date.prototype.toLocaleDateString
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Date.prototype.toLocaleDateString, true, false, [], 0);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Tests that Date.prototype.toLocaleTimeString
|
||||||
|
* meets the requirements for built-in objects defined by the introduction of
|
||||||
|
* chapter 15 of the ECMAScript Language Specification.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
$INCLUDE("testBuiltInObject.js");
|
||||||
|
|
||||||
|
testBuiltInObject(Date.prototype.toLocaleTimeString, true, false, [], 0);
|
||||||
|
|
|
@ -211,6 +211,7 @@ class TestCase(object):
|
||||||
source = self.suite.GetInclude("cth.js") + \
|
source = self.suite.GetInclude("cth.js") + \
|
||||||
self.suite.GetInclude("sta.js") + \
|
self.suite.GetInclude("sta.js") + \
|
||||||
self.suite.GetInclude("ed.js") + \
|
self.suite.GetInclude("ed.js") + \
|
||||||
|
self.suite.GetInclude("testBuiltInObject.js") + \
|
||||||
self.test + '\n'
|
self.test + '\n'
|
||||||
|
|
||||||
if self.strict_mode:
|
if self.strict_mode:
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
// Copyright 2012 Mozilla Corporation. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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.
|
||||||
|
* @param {boolean} isConstructor whether the specification describes obj as a constructor.
|
||||||
|
* @param {String[]} properties an array with the names of the built-in properties of obj,
|
||||||
|
* excluding length, prototype, or properties with non-default attributes.
|
||||||
|
* @param {number} length for functions only: the length specified for the function
|
||||||
|
* or derived from the argument list.
|
||||||
|
* @author Norbert Lindenberg
|
||||||
|
*/
|
||||||
|
|
||||||
|
function testBuiltInObject(obj, isFunction, isConstructor, properties, length) {
|
||||||
|
|
||||||
|
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 (!Object.isExtensible(obj)) {
|
||||||
|
$ERROR("Built-in objects must be extensible.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFunction && Object.getPrototypeOf(obj) !== Function.prototype) {
|
||||||
|
$ERROR("Built-in functions must have Function.prototype as their prototype.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isConstructor && Object.getPrototypeOf(obj.prototype) !== Object.prototype) {
|
||||||
|
$ERROR("Built-in prototype objects must have Object.prototype as their prototype.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// verification of the absence of the [[Construct]] internal property has
|
||||||
|
// been moved to the end of the test
|
||||||
|
|
||||||
|
// verification of the absence of the prototype property has
|
||||||
|
// been moved to the end of the test
|
||||||
|
|
||||||
|
if (isFunction) {
|
||||||
|
|
||||||
|
if (typeof obj.length !== "number" || obj.length !== Math.floor(obj.length)) {
|
||||||
|
$ERROR("Built-in functions must have a length property with an integer value.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj.length !== length) {
|
||||||
|
$ERROR("Function's length property doesn't have specified value.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(obj, "length");
|
||||||
|
if (desc.writable) {
|
||||||
|
$ERROR("The length property of a built-in function must not be writable.");
|
||||||
|
}
|
||||||
|
if (desc.enumerable) {
|
||||||
|
$ERROR("The length property of a built-in function must not be enumerable.");
|
||||||
|
}
|
||||||
|
if (desc.configurable) {
|
||||||
|
$ERROR("The length property of a built-in function must not be configurable.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
properties.forEach(function(prop) {
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(obj, prop);
|
||||||
|
if (desc === undefined) {
|
||||||
|
$ERROR("Missing property " + prop + ".");
|
||||||
|
}
|
||||||
|
// accessor properties don't have writable attribute
|
||||||
|
if (desc.hasOwnProperty("writable") && !desc.writable) {
|
||||||
|
$ERROR("The " + prop + " property of this built-in function must be writable.");
|
||||||
|
}
|
||||||
|
if (desc.enumerable) {
|
||||||
|
$ERROR("The " + prop + " property of this built-in function must not be enumerable.");
|
||||||
|
}
|
||||||
|
if (!desc.configurable) {
|
||||||
|
$ERROR("The " + prop + " property of this built-in function must be configurable.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// The remaining sections have been moved to the end of the test because
|
||||||
|
// unbound non-constructor functions written in JavaScript cannot possibly
|
||||||
|
// pass them, and we still want to test JavaScript implementations as much
|
||||||
|
// as possible.
|
||||||
|
|
||||||
|
var exception;
|
||||||
|
if (isFunction && !isConstructor) {
|
||||||
|
// 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 && !isConstructor && obj.hasOwnProperty("prototype")) {
|
||||||
|
$ERROR("Built-in functions that aren't constructors must not have a prototype property.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// passed the complete test!
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
||||||
{"date":"2012-08-22","version":"ES5.1"}
|
{"date":"2012-08-26","version":"ES5.1"}
|
|
@ -1 +1 @@
|
||||||
{"numTests":25,"testSuite":["json/intl402.json"]}
|
{"numTests":41,"testSuite":["json/intl402.json"]}
|
Loading…
Reference in New Issue