Unify indentation and add .editorconfig (#973)

This commit is contained in:
Mathias Bynens 2017-04-13 16:37:32 +02:00 committed by Leo Balter
parent 96aa8c77b3
commit a621155bcd
17 changed files with 1488 additions and 1473 deletions

16
.editorconfig Normal file
View File

@ -0,0 +1,16 @@
root = true
[*]
charset = utf-8
indent_style = tab
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[{README.md,package.json,.travis.yml,*.sh,*.js}]
indent_style = space
indent_size = 2
[{.jshintrc,*.py}]
indent_style = space
indent_size = 4

View File

@ -35,49 +35,50 @@ var $LocalTZ,
$DST_end_minutes;
(function () {
/**
* Finds the first date, starting from |start|, where |predicate|
* holds.
*/
var findNearestDateBefore = function(start, predicate) {
var current = start;
var month = 1000 * 60 * 60 * 24 * 30;
for (var step = month; step > 0; step = Math.floor(step / 3)) {
if (!predicate(current)) {
while (!predicate(current))
current = new Date(current.getTime() + step);
current = new Date(current.getTime() - step);
}
}
/**
* Finds the first date, starting from |start|, where |predicate|
* holds.
*/
var findNearestDateBefore = function(start, predicate) {
var current = start;
var month = 1000 * 60 * 60 * 24 * 30;
for (var step = month; step > 0; step = Math.floor(step / 3)) {
if (!predicate(current)) {
while (!predicate(current)) {
current = new Date(current.getTime() + 1);
current = new Date(current.getTime() + step);
current = new Date(current.getTime() - step);
}
return current;
};
}
}
while (!predicate(current)) {
current = new Date(current.getTime() + 1);
}
return current;
};
var juneDate = new Date(2000, 5, 20, 0, 0, 0, 0);
var decemberDate = new Date(2000, 11, 20, 0, 0, 0, 0);
var juneOffset = juneDate.getTimezoneOffset();
var decemberOffset = decemberDate.getTimezoneOffset();
var isSouthernHemisphere = (juneOffset > decemberOffset);
var winterTime = isSouthernHemisphere ? juneDate : decemberDate;
var summerTime = isSouthernHemisphere ? decemberDate : juneDate;
var juneDate = new Date(2000, 5, 20, 0, 0, 0, 0);
var decemberDate = new Date(2000, 11, 20, 0, 0, 0, 0);
var juneOffset = juneDate.getTimezoneOffset();
var decemberOffset = decemberDate.getTimezoneOffset();
var isSouthernHemisphere = (juneOffset > decemberOffset);
var winterTime = isSouthernHemisphere ? juneDate : decemberDate;
var summerTime = isSouthernHemisphere ? decemberDate : juneDate;
var dstStart = findNearestDateBefore(winterTime, function (date) {
return date.getTimezoneOffset() == summerTime.getTimezoneOffset();
});
$DST_start_month = dstStart.getMonth();
$DST_start_sunday = dstStart.getDate() > 15 ? '"last"' : '"first"';
$DST_start_hour = dstStart.getHours();
$DST_start_minutes = dstStart.getMinutes();
var dstStart = findNearestDateBefore(winterTime, function (date) {
return date.getTimezoneOffset() == summerTime.getTimezoneOffset();
});
$DST_start_month = dstStart.getMonth();
$DST_start_sunday = dstStart.getDate() > 15 ? '"last"' : '"first"';
$DST_start_hour = dstStart.getHours();
$DST_start_minutes = dstStart.getMinutes();
var dstEnd = findNearestDateBefore(summerTime, function (date) {
return date.getTimezoneOffset() == winterTime.getTimezoneOffset();
});
$DST_end_month = dstEnd.getMonth();
$DST_end_sunday = dstEnd.getDate() > 15 ? '"last"' : '"first"';
$DST_end_hour = dstEnd.getHours();
$DST_end_minutes = dstEnd.getMinutes();
var dstEnd = findNearestDateBefore(summerTime, function (date) {
return date.getTimezoneOffset() == winterTime.getTimezoneOffset();
});
$DST_end_month = dstEnd.getMonth();
$DST_end_sunday = dstEnd.getDate() > 15 ? '"last"' : '"first"';
$DST_end_hour = dstEnd.getHours();
$DST_end_minutes = dstEnd.getMinutes();
return;
return;
})();

View File

@ -1,9 +1,9 @@
//-----------------------------------------------------------------------------
function checkSequence(arr, message) {
arr.forEach(function(e, i) {
if (e !== (i+1)) {
$ERROR((message ? message : "Steps in unexpected sequence:") +
" '" + arr.join(',') + "'");
}
});
arr.forEach(function(e, i) {
if (e !== (i+1)) {
$ERROR((message ? message : "Steps in unexpected sequence:") +
" '" + arr.join(',') + "'");
}
});
}

View File

@ -1,17 +1,17 @@
//-----------------------------------------------------------------------------
function arrayContains(arr, expected) {
var found;
for (var i = 0; i < expected.length; i++) {
found = false;
for (var j = 0; j < arr.length; j++) {
if (expected[i] === arr[j]) {
found = true;
break;
}
}
if (!found) {
return false;
}
var found;
for (var i = 0; i < expected.length; i++) {
found = false;
for (var j = 0; j < arr.length; j++) {
if (expected[i] === arr[j]) {
found = true;
break;
}
}
return true;
if (!found) {
return false;
}
}
return true;
}

View File

@ -1,81 +1,81 @@
function assert(mustBeTrue, message) {
if (mustBeTrue === true) {
return;
}
if (mustBeTrue === true) {
return;
}
if (message === undefined) {
message = 'Expected true but got ' + String(mustBeTrue);
}
$ERROR(message);
if (message === undefined) {
message = 'Expected true but got ' + String(mustBeTrue);
}
$ERROR(message);
}
assert._isSameValue = function (a, b) {
if (a === b) {
// Handle +/-0 vs. -/+0
return a !== 0 || 1 / a === 1 / b;
}
if (a === b) {
// Handle +/-0 vs. -/+0
return a !== 0 || 1 / a === 1 / b;
}
// Handle NaN vs. NaN
return a !== a && b !== b;
// Handle NaN vs. NaN
return a !== a && b !== b;
};
assert.sameValue = function (actual, expected, message) {
if (assert._isSameValue(actual, expected)) {
return;
}
if (assert._isSameValue(actual, expected)) {
return;
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}
message += 'Expected SameValue(«' + String(actual) + '», «' + String(expected) + '») to be true';
message += 'Expected SameValue(«' + String(actual) + '», «' + String(expected) + '») to be true';
$ERROR(message);
$ERROR(message);
};
assert.notSameValue = function (actual, unexpected, message) {
if (!assert._isSameValue(actual, unexpected)) {
return;
}
if (!assert._isSameValue(actual, unexpected)) {
return;
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}
message += 'Expected SameValue(«' + String(actual) + '», «' + String(unexpected) + '») to be false';
message += 'Expected SameValue(«' + String(actual) + '», «' + String(unexpected) + '») to be false';
$ERROR(message);
$ERROR(message);
};
assert.throws = function (expectedErrorConstructor, func, message) {
if (typeof func !== "function") {
$ERROR('assert.throws requires two arguments: the error constructor ' +
'and a function to run');
return;
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}
if (typeof func !== "function") {
$ERROR('assert.throws requires two arguments: the error constructor ' +
'and a function to run');
return;
}
if (message === undefined) {
message = '';
} else {
message += ' ';
}
try {
func();
} catch (thrown) {
if (typeof thrown !== 'object' || thrown === null) {
message += 'Thrown value was not an object!';
$ERROR(message);
} else if (thrown.constructor !== expectedErrorConstructor) {
message += 'Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name;
$ERROR(message);
}
return;
try {
func();
} catch (thrown) {
if (typeof thrown !== 'object' || thrown === null) {
message += 'Thrown value was not an object!';
$ERROR(message);
} else if (thrown.constructor !== expectedErrorConstructor) {
message += 'Expected a ' + expectedErrorConstructor.name + ' but got a ' + thrown.constructor.name;
$ERROR(message);
}
return;
}
message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all';
$ERROR(message);
message += 'Expected a ' + expectedErrorConstructor.name + ' to be thrown but no exception was thrown at all';
$ERROR(message);
};

View File

@ -13,24 +13,24 @@ var print;
// in node use console.log
if (typeof console === "object") {
print = function () {
var args = Array.prototype.slice.call(arguments);
console.log(args.join(" "));
};
print = function () {
var args = Array.prototype.slice.call(arguments);
console.log(args.join(" "));
};
}
// in WScript, use WScript.Echo
if (typeof WScript === "object") {
print = function () {
var args = Array.prototype.slice.call(arguments);
WScript.Echo(args.join(" "));
};
print = function () {
var args = Array.prototype.slice.call(arguments);
WScript.Echo(args.join(" "));
};
// also override $ERROR to force a nonzero exit code exit
// TODO? report syntax errors
var oldError = $ERROR;
$ERROR = function (message) {
print("Test262 Error: " + message);
WScript.Quit(1);
};
// also override $ERROR to force a nonzero exit code exit
// TODO? report syntax errors
var oldError = $ERROR;
$ERROR = function (message) {
print("Test262 Error: " + message);
WScript.Quit(1);
};
}

View File

@ -1,10 +1,10 @@
function __consolePrintHandle__(msg){
print(msg);
print(msg);
}
function $DONE(){
if(!arguments[0])
__consolePrintHandle__('Test262:AsyncTestComplete');
else
__consolePrintHandle__('Error: ' + arguments[0]);
if(!arguments[0])
__consolePrintHandle__('Test262:AsyncTestComplete');
else
__consolePrintHandle__('Error: ' + arguments[0]);
}

View File

@ -1,5 +1,5 @@
//-----------------------------------------------------------------------------
var __globalObject = Function("return this;")();
function fnGlobalObject() {
return __globalObject;
return __globalObject;
}

View File

@ -1,127 +1,126 @@
function isConfigurable(obj, name) {
try {
delete obj[name];
} catch (e) {
if (!(e instanceof TypeError)) {
$ERROR("Expected TypeError, got " + e);
}
try {
delete obj[name];
} catch (e) {
if (!(e instanceof TypeError)) {
$ERROR("Expected TypeError, got " + e);
}
return !Object.prototype.hasOwnProperty.call(obj, name);
}
return !Object.prototype.hasOwnProperty.call(obj, name);
}
function isEnumerable(obj, name) {
var stringCheck;
var stringCheck;
if (typeof name === "string") {
for (var x in obj) {
if (x === name) {
stringCheck = true;
break;
}
}
} else {
// skip it if name is not string, works for Symbol names.
if (typeof name === "string") {
for (var x in obj) {
if (x === name) {
stringCheck = true;
break;
}
}
} else {
// skip it if name is not string, works for Symbol names.
stringCheck = true;
}
return stringCheck &&
Object.prototype.hasOwnProperty.call(obj, name) &&
Object.prototype.propertyIsEnumerable.call(obj, name);
return stringCheck &&
Object.prototype.hasOwnProperty.call(obj, name) &&
Object.prototype.propertyIsEnumerable.call(obj, name);
}
function isEqualTo(obj, name, expectedValue) {
var actualValue = obj[name];
var actualValue = obj[name];
return assert._isSameValue(actualValue, expectedValue);
return assert._isSameValue(actualValue, expectedValue);
}
function isWritable(obj, name, verifyProp, value) {
var newValue = value || "unlikelyValue";
var hadValue = Object.prototype.hasOwnProperty.call(obj, name);
var oldValue = obj[name];
var writeSucceeded;
var newValue = value || "unlikelyValue";
var hadValue = Object.prototype.hasOwnProperty.call(obj, name);
var oldValue = obj[name];
var writeSucceeded;
try {
obj[name] = newValue;
} catch (e) {
if (!(e instanceof TypeError)) {
$ERROR("Expected TypeError, got " + e);
}
try {
obj[name] = newValue;
} catch (e) {
if (!(e instanceof TypeError)) {
$ERROR("Expected TypeError, got " + e);
}
}
writeSucceeded = isEqualTo(obj, verifyProp || name, newValue);
writeSucceeded = isEqualTo(obj, verifyProp || name, newValue);
// Revert the change only if it was successful (in other cases, reverting
// is unnecessary and may trigger exceptions for certain property
// configurations)
if (writeSucceeded) {
if (hadValue) {
obj[name] = oldValue;
} else {
delete obj[name];
}
// Revert the change only if it was successful (in other cases, reverting
// is unnecessary and may trigger exceptions for certain property
// configurations)
if (writeSucceeded) {
if (hadValue) {
obj[name] = oldValue;
} else {
delete obj[name];
}
}
return writeSucceeded;
return writeSucceeded;
}
function verifyEqualTo(obj, name, value) {
if (!isEqualTo(obj, name, value)) {
$ERROR("Expected obj[" + String(name) + "] to equal " + value +
", actually " + obj[name]);
}
if (!isEqualTo(obj, name, value)) {
$ERROR("Expected obj[" + String(name) + "] to equal " + value +
", actually " + obj[name]);
}
}
function verifyWritable(obj, name, verifyProp, value) {
if (!verifyProp) {
assert(Object.getOwnPropertyDescriptor(obj, name).writable,
"Expected obj[" + String(name) + "] to have writable:true.");
}
if (!isWritable(obj, name, verifyProp, value)) {
$ERROR("Expected obj[" + String(name) + "] to be writable, but was not.");
}
if (!verifyProp) {
assert(Object.getOwnPropertyDescriptor(obj, name).writable,
"Expected obj[" + String(name) + "] to have writable:true.");
}
if (!isWritable(obj, name, verifyProp, value)) {
$ERROR("Expected obj[" + String(name) + "] to be writable, but was not.");
}
}
function verifyNotWritable(obj, name, verifyProp, value) {
if (!verifyProp) {
assert(!Object.getOwnPropertyDescriptor(obj, name).writable,
"Expected obj[" + String(name) + "] to have writable:false.");
}
if (isWritable(obj, name, verifyProp)) {
$ERROR("Expected obj[" + String(name) + "] NOT to be writable, but was.");
}
if (!verifyProp) {
assert(!Object.getOwnPropertyDescriptor(obj, name).writable,
"Expected obj[" + String(name) + "] to have writable:false.");
}
if (isWritable(obj, name, verifyProp)) {
$ERROR("Expected obj[" + String(name) + "] NOT to be writable, but was.");
}
}
function verifyEnumerable(obj, name) {
assert(Object.getOwnPropertyDescriptor(obj, name).enumerable,
"Expected obj[" + String(name) + "] to have enumerable:true.");
if (!isEnumerable(obj, name)) {
$ERROR("Expected obj[" + String(name) + "] to be enumerable, but was not.");
}
assert(Object.getOwnPropertyDescriptor(obj, name).enumerable,
"Expected obj[" + String(name) + "] to have enumerable:true.");
if (!isEnumerable(obj, name)) {
$ERROR("Expected obj[" + String(name) + "] to be enumerable, but was not.");
}
}
function verifyNotEnumerable(obj, name) {
assert(!Object.getOwnPropertyDescriptor(obj, name).enumerable,
"Expected obj[" + String(name) + "] to have enumerable:false.");
if (isEnumerable(obj, name)) {
$ERROR("Expected obj[" + String(name) + "] NOT to be enumerable, but was.");
}
assert(!Object.getOwnPropertyDescriptor(obj, name).enumerable,
"Expected obj[" + String(name) + "] to have enumerable:false.");
if (isEnumerable(obj, name)) {
$ERROR("Expected obj[" + String(name) + "] NOT to be enumerable, but was.");
}
}
function verifyConfigurable(obj, name) {
assert(Object.getOwnPropertyDescriptor(obj, name).configurable,
"Expected obj[" + String(name) + "] to have configurable:true.");
if (!isConfigurable(obj, name)) {
$ERROR("Expected obj[" + String(name) + "] to be configurable, but was not.");
}
assert(Object.getOwnPropertyDescriptor(obj, name).configurable,
"Expected obj[" + String(name) + "] to have configurable:true.");
if (!isConfigurable(obj, name)) {
$ERROR("Expected obj[" + String(name) + "] to be configurable, but was not.");
}
}
function verifyNotConfigurable(obj, name) {
assert(!Object.getOwnPropertyDescriptor(obj, name).configurable,
"Expected obj[" + String(name) + "] to have configurable:false.");
if (isConfigurable(obj, name)) {
$ERROR("Expected obj[" + String(name) + "] NOT to be configurable, but was.");
}
assert(!Object.getOwnPropertyDescriptor(obj, name).configurable,
"Expected obj[" + String(name) + "] to have configurable:false.");
if (isConfigurable(obj, name)) {
$ERROR("Expected obj[" + String(name) + "] NOT to be configurable, but was.");
}
}

View File

@ -1,22 +1,22 @@
function allowProxyTraps(overrides) {
function throwTest262Error(msg) {
return function () { throw new Test262Error(msg); };
}
if (!overrides) { overrides = {}; }
return {
getPrototypeOf: overrides.getPrototypeOf || throwTest262Error('[[GetPrototypeOf]] trap called'),
setPrototypeOf: overrides.setPrototypeOf || throwTest262Error('[[SetPrototypeOf]] trap called'),
isExtensible: overrides.isExtensible || throwTest262Error('[[IsExtensible]] trap called'),
preventExtensions: overrides.preventExtensions || throwTest262Error('[[PreventExtensions]] trap called'),
getOwnPropertyDescriptor: overrides.getOwnPropertyDescriptor || throwTest262Error('[[GetOwnProperty]] trap called'),
has: overrides.has || throwTest262Error('[[HasProperty]] trap called'),
get: overrides.get || throwTest262Error('[[Get]] trap called'),
set: overrides.set || throwTest262Error('[[Set]] trap called'),
deleteProperty: overrides.deleteProperty || throwTest262Error('[[Delete]] trap called'),
defineProperty: overrides.defineProperty || throwTest262Error('[[DefineOwnProperty]] trap called'),
enumerate: throwTest262Error('[[Enumerate]] trap called: this trap has been removed'),
ownKeys: overrides.ownKeys || throwTest262Error('[[OwnPropertyKeys]] trap called'),
apply: overrides.apply || throwTest262Error('[[Call]] trap called'),
construct: overrides.construct || throwTest262Error('[[Construct]] trap called')
};
function throwTest262Error(msg) {
return function () { throw new Test262Error(msg); };
}
if (!overrides) { overrides = {}; }
return {
getPrototypeOf: overrides.getPrototypeOf || throwTest262Error('[[GetPrototypeOf]] trap called'),
setPrototypeOf: overrides.setPrototypeOf || throwTest262Error('[[SetPrototypeOf]] trap called'),
isExtensible: overrides.isExtensible || throwTest262Error('[[IsExtensible]] trap called'),
preventExtensions: overrides.preventExtensions || throwTest262Error('[[PreventExtensions]] trap called'),
getOwnPropertyDescriptor: overrides.getOwnPropertyDescriptor || throwTest262Error('[[GetOwnProperty]] trap called'),
has: overrides.has || throwTest262Error('[[HasProperty]] trap called'),
get: overrides.get || throwTest262Error('[[Get]] trap called'),
set: overrides.set || throwTest262Error('[[Set]] trap called'),
deleteProperty: overrides.deleteProperty || throwTest262Error('[[Delete]] trap called'),
defineProperty: overrides.defineProperty || throwTest262Error('[[DefineOwnProperty]] trap called'),
enumerate: throwTest262Error('[[Enumerate]] trap called: this trap has been removed'),
ownKeys: overrides.ownKeys || throwTest262Error('[[OwnPropertyKeys]] trap called'),
apply: overrides.apply || throwTest262Error('[[Call]] trap called'),
construct: overrides.construct || throwTest262Error('[[Construct]] trap called')
};
}

View File

@ -3,14 +3,14 @@
function minNum(x, y) {
return x != x ? y :
y != y ? x :
Math.min(x, y);
y != y ? x :
Math.min(x, y);
}
function maxNum(x, y) {
return x != x ? y :
y != y ? x :
Math.max(x, y);
y != y ? x :
Math.max(x, y);
}
function sameValue(x, y) {
@ -26,13 +26,13 @@ if (typeof Math.imul !== "undefined") {
binaryImul = Math.imul;
} else {
binaryImul = function(a, b) {
var ah = (a >>> 16) & 0xffff;
var al = a & 0xffff;
var bh = (b >>> 16) & 0xffff;
var bl = b & 0xffff;
// the shift by 0 fixes the sign on the high part
// the final |0 converts the unsigned value into a signed value
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0);
var ah = (a >>> 16) & 0xffff;
var al = a & 0xffff;
var bh = (b >>> 16) & 0xffff;
var bl = b & 0xffff;
// the shift by 0 fixes the sign on the high part
// the final |0 converts the unsigned value into a signed value
return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0);
};
}
@ -236,9 +236,9 @@ uint16x8.fromBits = [float32x4, int32x4, int16x8, int8x16, uint32x4, uint8x16];
uint8x16.fromBits = [float32x4, int32x4, int16x8, int8x16, uint32x4, uint16x8];
var simdTypes = [float32x4,
int32x4, int16x8, int8x16,
uint32x4, uint16x8, uint8x16,
bool32x4, bool16x8, bool8x16];
int32x4, int16x8, int8x16,
uint32x4, uint16x8, uint8x16,
bool32x4, bool16x8, bool8x16];
if (typeof simdPhase2 !== "undefined") {
var float64x2 = {
@ -254,7 +254,7 @@ if (typeof simdPhase2 !== "undefined") {
view: Float64Array,
buffer: _f64x2,
mulFn: binaryMul,
}
};
var bool64x2 = {
name: "Bool64x2",
@ -263,7 +263,7 @@ if (typeof simdPhase2 !== "undefined") {
lanes: 2,
laneSize: 8,
interestingValues: [true, false],
}
};
float64x2.boolType = bool64x2;
@ -332,12 +332,12 @@ function checkValue(type, a, expect) {
fail = true;
}
if (fail) {
var lanes = [];
for (var i = 0; i < type.lanes; i++){
lanes.push(simdConvert(type, expect(i)));
}
$ERROR("expected SIMD." + type.name + "(" + lanes +
") but found " + a.toString());
var lanes = [];
for (var i = 0; i < type.lanes; i++){
lanes.push(simdConvert(type, expect(i)));
}
$ERROR("expected SIMD." + type.name + "(" + lanes +
") but found " + a.toString());
}
}
@ -356,13 +356,13 @@ function simdToLocaleString(type, value) {
function equalInt32x4(a, b) {
assert.sameValue(SIMD.Int32x4.extractLane(a, 0),
SIMD.Int32x4.extractLane(b, 0));
SIMD.Int32x4.extractLane(b, 0));
assert.sameValue(SIMD.Int32x4.extractLane(a, 1),
SIMD.Int32x4.extractLane(b, 1));
SIMD.Int32x4.extractLane(b, 1));
assert.sameValue(SIMD.Int32x4.extractLane(a, 2),
SIMD.Int32x4.extractLane(b, 2));
SIMD.Int32x4.extractLane(b, 2));
assert.sameValue(SIMD.Int32x4.extractLane(a, 3),
SIMD.Int32x4.extractLane(b, 3));
SIMD.Int32x4.extractLane(b, 3));
}
// Compare unary op's behavior to ref op at each lane.
@ -384,7 +384,7 @@ function testBinaryOp(type, op, refOp) {
for (var av of type.interestingValues) {
for (var bv of type.interestingValues) {
var expected = simdConvert(type, refOp(simdConvert(type, av),
simdConvert(type, bv)));
simdConvert(type, bv)));
var a = type.fn.splat(av);
var b = type.fn.splat(bv);
var result = type.fn[op](a, b);
@ -416,7 +416,7 @@ var skipValueTests = false;
function testSimdFunction(name, func) {
currentName = name;
if (typeof skipValueTests !== "undefined" && skipValueTests &&
name.indexOf("value semantics") != -1) return;
name.indexOf("value semantics") != -1) return;
try {
func();
} catch (e) {

View File

@ -2,18 +2,18 @@
/// This code is governed by the BSD license found in the LICENSE file.
function Test262Error(message) {
this.message = message || "";
this.message = message || "";
}
Test262Error.prototype.toString = function () {
return "Test262Error: " + this.message;
return "Test262Error: " + this.message;
};
var $ERROR;
$ERROR = function $ERROR(message) {
throw new Test262Error(message);
throw new Test262Error(message);
};
function testFailed(message) {
$ERROR(message);
$ERROR(message);
}

View File

@ -9,24 +9,24 @@
* @param f - the function to call for each bad index.
*/
function testWithAtomicsOutOfBoundsIndices(f) {
var bad_indices = [
(view) => -1,
(view) => view.length,
(view) => view.length*2,
(view) => Number.POSITIVE_INFINITY,
(view) => Number.NEGATIVE_INFINITY,
(view) => ({ valueOf: () => 125 }),
(view) => ({ toString: () => '125', valueOf: false }) // non-callable valueOf triggers invocation of toString
];
var bad_indices = [
(view) => -1,
(view) => view.length,
(view) => view.length*2,
(view) => Number.POSITIVE_INFINITY,
(view) => Number.NEGATIVE_INFINITY,
(view) => ({ valueOf: () => 125 }),
(view) => ({ toString: () => '125', valueOf: false }) // non-callable valueOf triggers invocation of toString
];
for (let IdxGen of bad_indices) {
try {
f(IdxGen);
} catch (e) {
e.message += " (Testing with index gen " + IdxGen + ".)";
throw e;
}
for (let IdxGen of bad_indices) {
try {
f(IdxGen);
} catch (e) {
e.message += " (Testing with index gen " + IdxGen + ".)";
throw e;
}
}
}
/**
@ -38,29 +38,29 @@ function testWithAtomicsOutOfBoundsIndices(f) {
* @param f - the function to call for each good index.
*/
function testWithAtomicsInBoundsIndices(f) {
// Most of these are eventually coerced to +0 by ToIndex.
var good_indices = [
(view) => 0/-1,
(view) => '-0',
(view) => undefined,
(view) => NaN,
(view) => 0.5,
(view) => '0.5',
(view) => -0.9,
(view) => ({ password: "qumquat" }),
(view) => view.length - 1,
(view) => ({ valueOf: () => 0 }),
(view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString
];
// Most of these are eventually coerced to +0 by ToIndex.
var good_indices = [
(view) => 0/-1,
(view) => '-0',
(view) => undefined,
(view) => NaN,
(view) => 0.5,
(view) => '0.5',
(view) => -0.9,
(view) => ({ password: "qumquat" }),
(view) => view.length - 1,
(view) => ({ valueOf: () => 0 }),
(view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString
];
for (let IdxGen of good_indices) {
try {
f(IdxGen);
} catch (e) {
e.message += " (Testing with index gen " + IdxGen + ".)";
throw e;
}
for (let IdxGen of good_indices) {
try {
f(IdxGen);
} catch (e) {
e.message += " (Testing with index gen " + IdxGen + ".)";
throw e;
}
}
}
/**
@ -71,44 +71,44 @@ function testWithAtomicsInBoundsIndices(f) {
*/
function testWithAtomicsNonViewValues(f) {
var values = [
null,
undefined,
true,
false,
new Boolean(true),
10,
3.14,
new Number(4),
"Hi there",
new Date,
/a*utomaton/g,
{ password: "qumquat" },
new DataView(new ArrayBuffer(10)),
new ArrayBuffer(128),
new SharedArrayBuffer(128),
new Error("Ouch"),
[1,1,2,3,5,8],
((x) => -x),
new Map(),
new Set(),
new WeakMap(),
new WeakSet(),
Symbol("halleluja"),
// TODO: Proxy?
Object,
Int32Array,
Date,
Math,
Atomics
];
var values = [
null,
undefined,
true,
false,
new Boolean(true),
10,
3.14,
new Number(4),
"Hi there",
new Date,
/a*utomaton/g,
{ password: "qumquat" },
new DataView(new ArrayBuffer(10)),
new ArrayBuffer(128),
new SharedArrayBuffer(128),
new Error("Ouch"),
[1,1,2,3,5,8],
((x) => -x),
new Map(),
new Set(),
new WeakMap(),
new WeakSet(),
Symbol("halleluja"),
// TODO: Proxy?
Object,
Int32Array,
Date,
Math,
Atomics
];
for (let nonView of values) {
try {
f(nonView);
} catch (e) {
e.message += " (Testing with non-view value " + nonView + ".)";
throw e;
}
for (let nonView of values) {
try {
f(nonView);
} catch (e) {
e.message += " (Testing with non-view value " + nonView + ".)";
throw e;
}
}
}

View File

@ -3,122 +3,121 @@
/**
* @description Tests that obj meets the requirements for built-in objects
* defined by the introduction of chapter 15 of the ECMAScript Language Specification.
* 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.
* 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.
* 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.");
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.");
}
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 (obj.length !== length) {
$ERROR("Function's length property doesn't have specified value; expected " +
length + ", got " + obj.length + ".");
}
if (!Object.isExtensible(obj)) {
$ERROR("Built-in objects must be extensible.");
var desc = Object.getOwnPropertyDescriptor(obj, "length");
if (desc.writable) {
$ERROR("The length property of a built-in function must not be writable.");
}
if (isFunction && Object.getPrototypeOf(obj) !== Function.prototype) {
$ERROR("Built-in functions must have Function.prototype as their prototype.");
if (desc.enumerable) {
$ERROR("The length property of a built-in function must not be enumerable.");
}
if (isConstructor && Object.getPrototypeOf(obj.prototype) !== Object.prototype) {
$ERROR("Built-in prototype objects must have Object.prototype as their prototype.");
if (!desc.configurable) {
$ERROR("The length property of a built-in function must be configurable.");
}
}
// 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; expected " +
length + ", got " + obj.length + ".");
}
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 be configurable.");
}
properties.forEach(function(prop) {
var desc = Object.getOwnPropertyDescriptor(obj, prop);
if (desc === undefined) {
$ERROR("Missing property " + prop + ".");
}
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 object must be writable.");
}
if (desc.enumerable) {
$ERROR("The " + prop + " property of this built-in object must not be enumerable.");
}
if (!desc.configurable) {
$ERROR("The " + prop + " property of this built-in object 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.");
}
// accessor properties don't have writable attribute
if (desc.hasOwnProperty("writable") && !desc.writable) {
$ERROR("The " + prop + " property of this built-in object must be writable.");
}
if (isFunction && !isConstructor && obj.hasOwnProperty("prototype")) {
$ERROR("Built-in functions that aren't constructors must not have a prototype property.");
if (desc.enumerable) {
$ERROR("The " + prop + " property of this built-in object must not be enumerable.");
}
if (!desc.configurable) {
$ERROR("The " + prop + " property of this built-in object must be configurable.");
}
});
// passed the complete test!
return true;
// 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 it is too large Load Diff

View File

@ -1,22 +1,23 @@
//setTimeout is not available, hence this script was loaded
if(Promise === undefined && this.setTimeout === undefined){
if(/\$DONE()/.test(code))
$ERROR("Async test capability is not supported in your test environment");
if (Promise === undefined && this.setTimeout === undefined) {
if(/\$DONE()/.test(code))
$ERROR("Async test capability is not supported in your test environment");
}
if(Promise !== undefined && this.setTimeout === undefined)
(function(that){
that.setTimeout = function(callback, delay) {
var p = Promise.resolve();
var start = Date.now();
var end = start + delay;
function check(){
var timeLeft = end - Date.now();
if(timeLeft > 0)
p.then(check);
else
callback();
}
p.then(check);
}
})(this);
if (Promise !== undefined && this.setTimeout === undefined) {
(function(that) {
that.setTimeout = function(callback, delay) {
var p = Promise.resolve();
var start = Date.now();
var end = start + delay;
function check(){
var timeLeft = end - Date.now();
if(timeLeft > 0)
p.then(check);
else
callback();
}
p.then(check);
}
})(this);
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2012 Ecma International. All rights reserved.
# Copyright (c) 2012 Ecma International. All rights reserved.
# This code is governed by the BSD license found in the LICENSE file.
@ -11,48 +11,48 @@ CVG_DICT = {}
#--HELPERS---------------------------------------------------------------------
def getCoverageData(directory):
tempList = os.listdir(directory)
#Build up a list of directories under directory
dirList = [x for x in tempList if os.path.isdir(os.path.join(directory, x))]
#Build up a list of JavaScript files under the current directory
jsList = [x for xin in tempList if x.endswith(".js")]
tempList = os.listdir(directory)
#Build up a list of directories under directory
dirList = [x for x in tempList if os.path.isdir(os.path.join(directory, x))]
#Build up a list of JavaScript files under the current directory
jsList = [x for xin in tempList if x.endswith(".js")]
#If the directory contains JavaScript files we'll assume they're all test
#cases
if len(jsList)!=0:
CVG_DICT[os.path.split(directory)[1]] = len(jsList)
#If the directory contains JavaScript files we'll assume they're all test
#cases
if len(jsList)!=0:
CVG_DICT[os.path.split(directory)[1]] = len(jsList)
#This might have just been a directory containing other dirs. Call ourself on
#it as well
for x in dirList:
getCoverageData(os.path.join(directory, x))
#This might have just been a directory containing other dirs. Call ourself on
#it as well
for x in dirList:
getCoverageData(os.path.join(directory, x))
def emitCoverageData(cvgDict):
totalTests = 0
totalSections = 0
keyList = cvgDict.keys()
keyList.sort(chapterCompare)
for cvgKey in keyList:
print cvgKey, ",", cvgDict[cvgKey]
totalSections+=1
totalTests+=cvgDict[cvgKey]
print
print "Total number of tests is:", totalTests, "."
print "These tests cover", totalSections, "ECMAScript 5 sections."
totalTests = 0
totalSections = 0
keyList = cvgDict.keys()
keyList.sort(chapterCompare)
for cvgKey in keyList:
print cvgKey, ",", cvgDict[cvgKey]
totalSections+=1
totalTests+=cvgDict[cvgKey]
print
print "Total number of tests is:", totalTests, "."
print "These tests cover", totalSections, "ECMAScript 5 sections."
def chapterCompare(x, y):
if ("." in x) and ("." in y):
try:
x1 = int(x[0:x.index(".")])
y1 = int(y[0:y.index(".")])
if x1==y1:
return chapterCompare(x[x.index(".")+1:], y[y.index(".")+1:])
return cmp(x1, y1)
except ValueError:
pass
return cmp(x, y)
if ("." in x) and ("." in y):
try:
x1 = int(x[0:x.index(".")])
y1 = int(y[0:y.index(".")])
if x1==y1:
return chapterCompare(x[x.index(".")+1:], y[y.index(".")+1:])
return cmp(x1, y1)
except ValueError:
pass
return cmp(x, y)
#--MAIN------------------------------------------------------------------------
startDir = sys.argv[1]