Skip to content

Commit

Permalink
Consistently use curly braces.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 18, 2014
1 parent cd85d24 commit 5ebc245
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 50 deletions.
6 changes: 4 additions & 2 deletions es6-sham.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
// because it's based on ES5 API.
// (probably just an IE <= 8 problem)
//
// NOTE: nodejs is fine in version 0.8, 0.10 and future versions.
if (!Object.setPrototypeOf) (function () {
// NOTE: nodejs is fine in version 0.8, 0.10, and future versions.
(function () {
if (Object.setPrototypeOf) { return; }

/*jshint proto: true */
// @author Andrea Giammarchi - @WebReflection
// define into target descriptors from source
Expand Down
93 changes: 49 additions & 44 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
var ArrayIterator; // make our implementation private

var defineProperty = function (object, name, value, force) {
if (!force && name in object) return;
if (!force && name in object) { return; }
if (supportsDescriptors) {
Object.defineProperty(object, name, {
configurable: true,
Expand Down Expand Up @@ -145,7 +145,7 @@
};

var emulateES6construct = function (o) {
if (!ES.TypeIsObject(o)) throw new TypeError('bad object');
if (!ES.TypeIsObject(o)) { throw new TypeError('bad object'); }
// es5 approximation to es6 subclass semantics: in es6, 'new Foo'
// would invoke Foo.@@create to allocation/initialize the new object.
// In es5 we just get the plain object. So if we detect an
Expand All @@ -162,8 +162,9 @@
var ES = {
CheckObjectCoercible: function (x, optMessage) {
/* jshint eqnull:true */
if (x == null)
throw new TypeError(optMessage || ('Cannot call method on ' + x));
if (x == null) {
throw new TypeError(optMessage || 'Cannot call method on ' + x);
}
return x;
},

Expand Down Expand Up @@ -194,22 +195,22 @@

ToInteger: function (value) {
var number = +value;
if (Number.isNaN(number)) return 0;
if (number === 0 || !Number.isFinite(number)) return number;
if (Number.isNaN(number)) { return 0; }
if (number === 0 || !Number.isFinite(number)) { return number; }
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
},

ToLength: function (value) {
var len = ES.ToInteger(value);
if (len <= 0) return 0; // includes converting -0 to +0
if (len > Number.MAX_SAFE_INTEGER) return Number.MAX_SAFE_INTEGER;
if (len <= 0) { return 0; } // includes converting -0 to +0
if (len > Number.MAX_SAFE_INTEGER) { return Number.MAX_SAFE_INTEGER; }
return len;
},

SameValue: function (a, b) {
if (a === b) {
// 0 === -0, but they are not identical.
if (a === 0) return 1 / a === 1 / b;
if (a === 0) { return 1 / a === 1 / b; }
return true;
}
return Number.isNaN(a) && Number.isNaN(b);
Expand Down Expand Up @@ -470,8 +471,8 @@
// Perf: http://jsperf.com/string-repeat2/2
repeat: (function () {
var repeat = function (s, times) {
if (times < 1) return '';
if (times % 2) return repeat(s, times - 1) + s;
if (times < 1) { return ''; }
if (times % 2) { return repeat(s, times - 1) + s; }
var half = repeat(s, times / 2);
return half + half;
};
Expand All @@ -488,7 +489,9 @@

startsWith: function (searchStr) {
var thisStr = String(ES.CheckObjectCoercible(this));
if (_toString.call(searchStr) === '[object RegExp]') throw new TypeError('Cannot call method "startsWith" with a regex');
if (_toString.call(searchStr) === '[object RegExp]') {
throw new TypeError('Cannot call method "startsWith" with a regex');
}
searchStr = String(searchStr);
var startArg = arguments.length > 1 ? arguments[1] : undefined;
var start = Math.max(ES.ToInteger(startArg), 0);
Expand All @@ -497,7 +500,9 @@

endsWith: function (searchStr) {
var thisStr = String(ES.CheckObjectCoercible(this));
if (_toString.call(searchStr) === '[object RegExp]') throw new TypeError('Cannot call method "endsWith" with a regex');
if (_toString.call(searchStr) === '[object RegExp]') {
throw new TypeError('Cannot call method "endsWith" with a regex');
}
searchStr = String(searchStr);
var thisLen = thisStr.length;
var posArg = arguments.length > 1 ? arguments[1] : undefined;
Expand All @@ -516,12 +521,12 @@
var thisStr = String(ES.CheckObjectCoercible(this));
var position = ES.ToInteger(pos);
var length = thisStr.length;
if (position < 0 || position >= length) return undefined;
if (position < 0 || position >= length) { return; }
var first = thisStr.charCodeAt(position);
var isEnd = (position + 1 === length);
if (first < 0xD800 || first > 0xDBFF || isEnd) return first;
if (first < 0xD800 || first > 0xDBFF || isEnd) { return first; }
var second = thisStr.charCodeAt(position + 1);
if (second < 0xDC00 || second > 0xDFFF) return first;
if (second < 0xDC00 || second > 0xDFFF) { return first; }
return ((first - 0xD800) * 1024) + (second - 0xDC00) + 0x10000;
}
};
Expand Down Expand Up @@ -974,9 +979,9 @@
var MathShims = {
acosh: function (value) {
value = Number(value);
if (Number.isNaN(value) || value < 1) return NaN;
if (value === 1) return 0;
if (value === Infinity) return value;
if (Number.isNaN(value) || value < 1) { return NaN; }
if (value === 1) { return 0; }
if (value === Infinity) { return value; }
return Math.log(value + Math.sqrt(value * value - 1));
},

Expand All @@ -993,17 +998,17 @@
if (Number.isNaN(value) || value < -1 || value > 1) {
return NaN;
}
if (value === -1) return -Infinity;
if (value === 1) return Infinity;
if (value === 0) return value;
if (value === -1) { return -Infinity; }
if (value === 1) { return Infinity; }
if (value === 0) { return value; }
return 0.5 * Math.log((1 + value) / (1 - value));
},

cbrt: function (value) {
value = Number(value);
if (value === 0) return value;
if (value === 0) { return value; }
var negate = value < 0, result;
if (negate) value = -value;
if (negate) { value = -value; }
result = Math.pow(value, 1 / 3);
return negate ? -result : result;
},
Expand All @@ -1020,18 +1025,18 @@

cosh: function (value) {
value = Number(value);
if (value === 0) return 1; // +0 or -0
if (Number.isNaN(value)) return NaN;
if (!global_isFinite(value)) return Infinity;
if (value < 0) value = -value;
if (value > 21) return Math.exp(value) / 2;
if (value === 0) { return 1; } // +0 or -0
if (Number.isNaN(value)) { return NaN; }
if (!global_isFinite(value)) { return Infinity; }
if (value < 0) { value = -value; }
if (value > 21) { return Math.exp(value) / 2; }
return (Math.exp(value) + Math.exp(-value)) / 2;
},

expm1: function (value) {
value = Number(value);
if (value === -Infinity) return -1;
if (!global_isFinite(value) || value === 0) return value;
if (value === -Infinity) { return -1; }
if (!global_isFinite(value) || value === 0) { return value; }
return Math.exp(value) - 1;
},

Expand All @@ -1056,9 +1061,9 @@
}
return true;
});
if (anyInfinity) return Infinity;
if (anyNaN) return NaN;
if (allZero) return 0;
if (anyInfinity) { return Infinity; }
if (anyNaN) { return NaN; }
if (allZero) { return 0; }

numbers.sort(function (a, b) { return b - a; });
var largest = numbers[0];
Expand All @@ -1077,13 +1082,13 @@

log1p: function (value) {
value = Number(value);
if (value < -1 || Number.isNaN(value)) return NaN;
if (value === 0 || value === Infinity) return value;
if (value === -1) return -Infinity;
if (value < -1 || Number.isNaN(value)) { return NaN; }
if (value === 0 || value === Infinity) { return value; }
if (value === -1) { return -Infinity; }
var result = 0;
var n = 50;

if (value < 0 || value > 1) return Math.log(1 + value);
if (value < 0 || value > 1) { return Math.log(1 + value); }
for (var i = 1; i < n; i++) {
if ((i % 2) === 0) {
result -= Math.pow(value, i) / i;
Expand All @@ -1097,22 +1102,22 @@

sign: function (value) {
var number = +value;
if (number === 0) return number;
if (Number.isNaN(number)) return number;
if (number === 0) { return number; }
if (Number.isNaN(number)) { return number; }
return number < 0 ? -1 : 1;
},

sinh: function (value) {
value = Number(value);
if (!global_isFinite(value) || value === 0) return value;
if (!global_isFinite(value) || value === 0) { return value; }
return (Math.exp(value) - Math.exp(-value)) / 2;
},

tanh: function (value) {
value = Number(value);
if (Number.isNaN(value) || value === 0) return value;
if (value === Infinity) return 1;
if (value === -Infinity) return -1;
if (Number.isNaN(value) || value === 0) { return value; }
if (value === Infinity) { return 1; }
if (value === -Infinity) { return -1; }
return (Math.exp(value) - Math.exp(-value)) / (Math.exp(value) + Math.exp(-value));
},

Expand Down
8 changes: 4 additions & 4 deletions test/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ describe('Collections', function () {
map = new Map();

range(1, 20).forEach(function (number) {
if (slowkeys) testMapping(number, {});
if (slowkeys) { testMapping(number, {}); }
testMapping(number / 100, {});
testMapping('key-' + number, {});
testMapping(String(number), {});
if (slowkeys) testMapping(Object(String(number)), {});
if (slowkeys) { testMapping(Object(String(number)), {}); }
});

var testkeys = [+0, Infinity, -Infinity, NaN];
Expand Down Expand Up @@ -495,12 +495,12 @@ describe('Collections', function () {
set = new Set();

range(1, 20).forEach(function (number) {
if (slowkeys) testSet({});
if (slowkeys) { testSet({}); }
testSet(number);
testSet(number / 100);
testSet('key-' + number);
testSet(String(number));
if (slowkeys) testSet(Object(String(number)));
if (slowkeys) { testSet(Object(String(number))); }
});

var testkeys = [+0, Infinity, -Infinity, NaN];
Expand Down

0 comments on commit 5ebc245

Please sign in to comment.