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

View File

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

View File

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

View File

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

View File

@ -1,36 +1,36 @@
/// 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. /// This code is governed by the BSD license found in the LICENSE file.
function testRun(id, path, description, codeString, result, error) { function testRun(id, path, description, codeString, result, error) {
if (result!=="pass") { if (result!=="pass") {
throw new Error("Test '" + path + "'failed: " + error); throw new Error("Test '" + path + "'failed: " + error);
} }
} }
// define a default `print` function for async tests where there is no // define a default `print` function for async tests where there is no
// global `print` // global `print`
var print; var print;
// in node use console.log // in node use console.log
if (typeof console === "object") { if (typeof console === "object") {
print = function () { print = function () {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
console.log(args.join(" ")); console.log(args.join(" "));
}; };
} }
// in WScript, use WScript.Echo // in WScript, use WScript.Echo
if (typeof WScript === "object") { if (typeof WScript === "object") {
print = function () { print = function () {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
WScript.Echo(args.join(" ")); WScript.Echo(args.join(" "));
}; };
// also override $ERROR to force a nonzero exit code exit // also override $ERROR to force a nonzero exit code exit
// TODO? report syntax errors // TODO? report syntax errors
var oldError = $ERROR; var oldError = $ERROR;
$ERROR = function (message) { $ERROR = function (message) {
print("Test262 Error: " + message); print("Test262 Error: " + message);
WScript.Quit(1); WScript.Quit(1);
}; };
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,122 +3,121 @@
/** /**
* @description Tests that obj meets the requirements for built-in objects * @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 {Object} obj the object to be tested.
* @param {boolean} isFunction whether the specification describes obj as a function. * @param {boolean} isFunction whether the specification describes obj as a function.
* @param {boolean} isConstructor whether the specification describes obj as a constructor. * @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, * @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 * @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 * @author Norbert Lindenberg
*/ */
function testBuiltInObject(obj, isFunction, isConstructor, properties, length) { function testBuiltInObject(obj, isFunction, isConstructor, properties, length) {
if (obj === undefined) { if (obj === undefined) {
$ERROR("Object being tested is 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 (obj.length !== length) {
if (isFunction) { $ERROR("Function's length property doesn't have specified value; expected " +
if (objString !== "[object Function]") { length + ", got " + obj.length + ".");
$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)) { var desc = Object.getOwnPropertyDescriptor(obj, "length");
$ERROR("Built-in objects must be extensible."); if (desc.writable) {
$ERROR("The length property of a built-in function must not be writable.");
} }
if (desc.enumerable) {
if (isFunction && Object.getPrototypeOf(obj) !== Function.prototype) { $ERROR("The length property of a built-in function must not be enumerable.");
$ERROR("Built-in functions must have Function.prototype as their prototype.");
} }
if (!desc.configurable) {
if (isConstructor && Object.getPrototypeOf(obj.prototype) !== Object.prototype) { $ERROR("The length property of a built-in function must be configurable.");
$ERROR("Built-in prototype objects must have Object.prototype as their prototype.");
} }
}
// verification of the absence of the [[Construct]] internal property has properties.forEach(function(prop) {
// been moved to the end of the test var desc = Object.getOwnPropertyDescriptor(obj, prop);
if (desc === undefined) {
// verification of the absence of the prototype property has $ERROR("Missing property " + prop + ".");
// 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.");
}
} }
// accessor properties don't have writable attribute
properties.forEach(function(prop) { if (desc.hasOwnProperty("writable") && !desc.writable) {
var desc = Object.getOwnPropertyDescriptor(obj, prop); $ERROR("The " + prop + " property of this built-in object must be writable.");
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.");
}
} }
if (desc.enumerable) {
if (isFunction && !isConstructor && obj.hasOwnProperty("prototype")) { $ERROR("The " + prop + " property of this built-in object must not be enumerable.");
$ERROR("Built-in functions that aren't constructors must not have a prototype property.");
} }
if (!desc.configurable) {
$ERROR("The " + prop + " property of this built-in object must be configurable.");
}
});
// passed the complete test! // The remaining sections have been moved to the end of the test because
return true; // 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 //setTimeout is not available, hence this script was loaded
if(Promise === undefined && this.setTimeout === undefined){ if (Promise === undefined && this.setTimeout === undefined) {
if(/\$DONE()/.test(code)) if(/\$DONE()/.test(code))
$ERROR("Async test capability is not supported in your test environment"); $ERROR("Async test capability is not supported in your test environment");
} }
if(Promise !== undefined && this.setTimeout === undefined) if (Promise !== undefined && this.setTimeout === undefined) {
(function(that){ (function(that) {
that.setTimeout = function(callback, delay) { that.setTimeout = function(callback, delay) {
var p = Promise.resolve(); var p = Promise.resolve();
var start = Date.now(); var start = Date.now();
var end = start + delay; var end = start + delay;
function check(){ function check(){
var timeLeft = end - Date.now(); var timeLeft = end - Date.now();
if(timeLeft > 0) if(timeLeft > 0)
p.then(check); p.then(check);
else else
callback(); callback();
} }
p.then(check); p.then(check);
} }
})(this); })(this);
}

View File

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