Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into apply
Browse files Browse the repository at this point in the history
  • Loading branch information
Xotic750 committed Dec 9, 2015
2 parents 1b9ce95 + a827b75 commit 0e52d67
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"max-statements": [1, 30],
"new-cap": [2, { "capIsNewExceptions": ["ToInteger", "ToObject", "ToPrimitive", "ToUint32"] }],
"no-constant-condition": [1],
"no-extend-native": [2, {"exceptions": ["Date", "Error"]}],
"no-extend-native": [2, {"exceptions": ["Date", "Error", "RegExp"]}],
"no-extra-parens": [0],
"no-extra-semi": [1],
"no-func-assign": [1],
Expand Down
14 changes: 13 additions & 1 deletion .jscs.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@

"requireSpacesInGenerator": {
"afterStar": true
}
},

"disallowSpacesInGenerator": {
"beforeStar": true
},

"disallowVar": false,

"requireArrayDestructuring": false,

"requireEnhancedObjectLiterals": false,

"requireObjectDestructuring": false
}

2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
node_js:
- "5.1"
- "5.0"
- "4.2"
- "4.1"
Expand Down Expand Up @@ -39,6 +40,7 @@ sudo: false
matrix:
fast_finish: true
allow_failures:
- node_js: "5.0"
- node_js: "4.1"
- node_js: "4.0"
- node_js: "iojs-v3.2"
Expand Down
2 changes: 1 addition & 1 deletion es5-sham.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
;

// UMD (Universal Module Definition)
// see https://github.com/umdjs/umd/blob/master/returnExports.js
// see https://github.com/umdjs/umd/blob/master/templates/returnExports.js
(function (root, factory) {
'use strict';

Expand Down
116 changes: 86 additions & 30 deletions es5-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
;

// UMD (Universal Module Definition)
// see https://github.com/umdjs/umd/blob/master/returnExports.js
// see https://github.com/umdjs/umd/blob/master/templates/returnExports.js
(function (root, factory) {
'use strict';

Expand Down Expand Up @@ -70,19 +70,18 @@ var isRegex; /* inlined from https://npmjs.com/is-regex */ var regexExec = RegEx
var isString; /* inlined from https://npmjs.com/is-string */ var strValue = String.prototype.valueOf, tryStringObject = function tryStringObject(value) { try { strValue.call(value); return true; } catch (e) { return false; } }, stringClass = '[object String]'; isString = function isString(value) { if (typeof value === 'string') { return true; } if (typeof value !== 'object') { return false; } return hasToStringTag ? tryStringObject(value) : to_string.call(value) === stringClass; };

/* inlined from http://npmjs.com/define-properties */
var supportsDescriptors = $Object.defineProperty && (function () {
try {
var obj = {};
$Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
for (var _ in obj) { return false; }
return obj.x === obj;
} catch (e) { /* this is ES3 */
return false;
}
}());
var defineProperties = (function (has) {
var supportsDescriptors = $Object.defineProperty && (function () {
try {
var obj = {};
$Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
for (var _ in obj) { return false; }
return obj.x === obj;
} catch (e) { /* this is ES3 */
return false;
}
}());

// Define configurable, writable and non-enumerable props
// Define configurable, writable, and non-enumerable props
// if they don't exist.
var defineProperty;
if (supportsDescriptors) {
Expand Down Expand Up @@ -461,10 +460,13 @@ defineProperties(FunctionPrototype, {
// use it in defining shortcuts.
var owns = call.bind(ObjectPrototype.hasOwnProperty);
var toStr = call.bind(ObjectPrototype.toString);
var arraySlice = call.bind(array_slice);
var arraySliceApply = apply.bind(array_slice);
var strSlice = call.bind(StringPrototype.slice);
var strSplit = call.bind(StringPrototype.split);
var strIndexOf = call.bind(StringPrototype.indexOf);
var push = call.bind(array_push);
var isEnum = call.bind(ObjectPrototype.propertyIsEnumerable);

//
// Array
Expand Down Expand Up @@ -866,7 +868,7 @@ defineProperties(ArrayPrototype, {
var args = arguments;
this.length = max(ES.ToInteger(this.length), 0);
if (arguments.length > 0 && typeof deleteCount !== 'number') {
args = array_slice.call(arguments);
args = arraySlice(arguments);
if (args.length < 2) {
push(args, this.length - start);
} else {
Expand Down Expand Up @@ -915,7 +917,7 @@ defineProperties(ArrayPrototype, {
k += 1;
}

var items = array_slice.call(arguments, 2);
var items = arraySlice(arguments, 2);
var itemCount = items.length;
var to;
if (itemCount < actualDeleteCount) {
Expand Down Expand Up @@ -959,13 +961,26 @@ defineProperties(ArrayPrototype, {
}
}, !spliceWorksWithLargeSparseArrays || !spliceWorksWithSmallSparseArrays);

var hasJoinUndefinedBug = [1, 2].join(undefined) !== '1,2';
var originalJoin = ArrayPrototype.join;
defineProperties(ArrayPrototype, {
join: function join(separator) {
return originalJoin.call(this, typeof separator === 'undefined' ? ',' : separator);
}
}, hasJoinUndefinedBug);
var hasStringJoinBug = Array.prototype.join.call('123', ',') !== '1,2,3';
if (hasStringJoinBug) {
defineProperties(ArrayPrototype, {
join: function join(separator) {
var sep = typeof separator === 'undefined' ? ',' : separator;
return originalJoin.call(isString(this) ? strSplit(this, '') : this, sep);
}
}, hasStringJoinBug);
}

var hasJoinUndefinedBug = [1, 2].join(undefined) !== '1,2';
if (hasJoinUndefinedBug) {
defineProperties(ArrayPrototype, {
join: function join(separator) {
var sep = typeof separator === 'undefined' ? ',' : separator;
return originalJoin.call(this, sep);
}
}, hasJoinUndefinedBug);
}

var pushShim = function push(item) {
var O = ES.ToObject(this);
Expand Down Expand Up @@ -1001,6 +1016,16 @@ var pushUndefinedIsWeird = (function () {
}());
defineProperties(ArrayPrototype, { push: pushShim }, pushUndefinedIsWeird);

// ES5 15.2.3.14
// http://es5.github.io/#x15.4.4.10
// Fix boxed string bug
defineProperties(ArrayPrototype, {
slice: function (start, end) {
var arr = isString(this) ? strSplit(this, '') : this;
return arraySliceApply(arr, arguments);
}
}, splitString);

//
// Object
// ======
Expand All @@ -1026,7 +1051,8 @@ var blacklistedKeys = {
$frames: true,
$frameElement: true,
$webkitIndexedDB: true,
$webkitStorageInfo: true
$webkitStorageInfo: true,
$external: true
};
var hasAutomationEqualityBug = (function () {
/* globals window */
Expand Down Expand Up @@ -1128,7 +1154,7 @@ var originalKeys = $Object.keys;
defineProperties($Object, {
keys: function keys(object) {
if (isArguments(object)) {
return originalKeys(array_slice.call(object));
return originalKeys(arraySlice(object));
} else {
return originalKeys(object);
}
Expand Down Expand Up @@ -1184,8 +1210,8 @@ defineProperties(Date.prototype, {
}
// pad milliseconds to have three digits.
return (
year + '-' + array_slice.call(result, 0, 2).join('-') +
'T' + array_slice.call(result, 2).join(':') + '.' +
year + '-' + arraySlice(result, 0, 2).join('-') +
'T' + arraySlice(result, 2).join(':') + '.' +
strSlice('000' + this.getUTCMilliseconds(), -3) + 'Z'
);
}
Expand Down Expand Up @@ -1256,7 +1282,6 @@ if (doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) {
/* global Date: true */
/* eslint-disable no-undef */
var maxSafeUnsigned32Bit = Math.pow(2, 31) - 1;
var secondsWithinMaxSafeUnsigned32Bit = Math.floor(maxSafeUnsigned32Bit / 1e3);
var hasSafariSignedIntBug = isActualNaN(new Date(1970, 0, 1, 0, 0, 0, maxSafeUnsigned32Bit + 1).getTime());
Date = (function (NativeDate) {
/* eslint-enable no-undef */
Expand Down Expand Up @@ -1629,7 +1654,7 @@ if (
var maxSafe32BitInt = Math.pow(2, 32) - 1;

StringPrototype.split = function (separator, limit) {
var string = this;
var string = String(this);
if (typeof separator === 'undefined' && limit === 0) {
return [];
}
Expand All @@ -1648,7 +1673,6 @@ if (
// Make `global` and avoid `lastIndex` issues by working with a copy
separator2, match, lastIndex, lastLength;
var separatorCopy = new RegExp(separator.source, flags + 'g');
string += ''; // Type-convert
if (!compliantExecNpcg) {
// Doesn't need flags gy, but they don't hurt
separator2 = new RegExp('^' + separatorCopy.source + '$(?!\\s)', flags);
Expand Down Expand Up @@ -1681,7 +1705,7 @@ if (
/* eslint-enable no-loop-func */
}
if (match.length > 1 && match.index < string.length) {
array_push.apply(output, array_slice.call(match, 1));
array_push.apply(output, arraySlice(match, 1));
}
lastLength = match[0].length;
lastLastIndex = lastIndex;
Expand Down Expand Up @@ -1833,7 +1857,6 @@ if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
}

if (String(new RangeError('test')) !== 'RangeError: test') {
var originalErrorToString = Error.prototype.toString;
var errorToStringShim = function toString() {
if (typeof this === 'undefined' || this === null) {
throw new TypeError("can't convert " + this + ' to object');
Expand Down Expand Up @@ -1862,4 +1885,37 @@ if (String(new RangeError('test')) !== 'RangeError: test') {
Error.prototype.toString = errorToStringShim;
}

if (supportsDescriptors) {
var ensureNonEnumerable = function (obj, prop) {
if (isEnum(obj, prop)) {
var desc = Object.getOwnPropertyDescriptor(obj, prop);
desc.enumerable = false;
Object.defineProperty(obj, prop, desc);
}
};
ensureNonEnumerable(Error.prototype, 'message');
if (Error.prototype.message !== '') {
Error.prototype.message = '';
}
ensureNonEnumerable(Error.prototype, 'name');
}

if (String(/a/mig) !== '/a/gim') {
var regexToString = function toString() {
var str = '/' + this.source + '/';
if (this.global) {
str += 'g';
}
if (this.ignoreCase) {
str += 'i';
}
if (this.multiline) {
str += 'm';
}
return str;
};
// can't use defineProperties here because of toString enumeration issue in IE <= 8
RegExp.prototype.toString = regexToString;
}

}));
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
"jscs": "jscs tests/helpers/*.js tests/spec/*.js es5-shim.js es5-sham.js"
},
"devDependencies": {
"eslint": "^1.9.0",
"eslint": "^1.10.1",
"@ljharb/eslint-config": "^1.6.0",
"jasmine-node": "^1.14.5",
"jscs": "^2.5.1",
"uglify-js": "^2.6.0",
"jscs": "^2.6.0",
"uglify-js": "^2.6.1",
"replace": "^0.3.0",
"semver": "^5.0.3"
"semver": "^5.1.0"
},
"engines": {
"node": ">=0.4.0"
Expand Down
1 change: 1 addition & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<script src="spec/s-number.js"></script>
<script src="spec/s-object.js"></script>
<script src="spec/s-string.js"></script>
<script src="spec/s-regexp.js"></script>


<script type="text/javascript">
Expand Down
1 change: 1 addition & 0 deletions tests/native.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<script src="spec/s-number.js"></script>
<script src="spec/s-object.js"></script>
<script src="spec/s-string.js"></script>
<script src="spec/s-regexp.js"></script>


<script type="text/javascript">
Expand Down
30 changes: 29 additions & 1 deletion tests/spec/s-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,34 @@ describe('Array', function () {
it('defaults to a comma separator when undefined is provided', function () {
expect([1, 2].join(undefined)).toBe('1,2');
});

it('works, extended', function () {
expect([].join()).toBe('');
expect([undefined].join()).toBe('');
expect([undefined, undefined].join()).toBe(',');
expect([null, null].join()).toBe(',');
expect([undefined, undefined].join('|')).toBe('|');
expect([null, null].join('|')).toBe('|');
expect([1, 2, 3].join('|')).toBe('1|2|3');
expect([1, 2, 3].join(null)).toBe('1null2null3');
expect([1, 2, 3].join({})).toBe('1[object Object]2[object Object]3');
expect([1, 2, 3].join('')).toBe('123');
});

it('is generic', function () {
var obj = { 0: 1, 1: 2, 2: 3, 3: 4, length: 3 };
expect(Array.prototype.join.call(obj, ',')).toBe('1,2,3');
});

it('works with a string literal', function () {
var str = '123';
expect(Array.prototype.join.call(str, ',')).toBe('1,2,3');
});

it('works with `arguments`', function () {
var args = (function () { return arguments; }(1, 2, 3));
expect(Array.prototype.join.call(args, ',')).toBe('1,2,3');
});
});

describe('#push()', function () {
Expand Down Expand Up @@ -1554,7 +1582,7 @@ describe('Array', function () {
expect(result).toEqual([2, 3]);
});

it('works with arguments', function () {
it('works with `arguments`', function () {
var obj = (function () {
return arguments;
}(1, 2, 3, 4));
Expand Down
Loading

0 comments on commit 0e52d67

Please sign in to comment.