This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ECMAScript 2016 file, include in polyfill.js
- Loading branch information
1 parent
69ab81c
commit 891d4f1
Showing
14 changed files
with
324 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "js-polyfills", | ||
"version": "0.1.26", | ||
"version": "0.1.27", | ||
"homepage": "https://github.com/inexorabletash/polyfill", | ||
"authors": [ | ||
"Joshua Bell <[email protected]>" | ||
|
@@ -10,6 +10,7 @@ | |
"main": [ | ||
"es5.js", | ||
"es6.js", | ||
"es2016.js", | ||
"html.js", | ||
"dom.js", | ||
"xhr.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
//---------------------------------------------------------------------- | ||
// | ||
// ECMAScript 2016 Polyfills | ||
// | ||
//---------------------------------------------------------------------- | ||
|
||
(function (global) { | ||
"use strict"; | ||
var undefined = (void 0); // Paranoia | ||
|
||
// Helpers | ||
|
||
function assert(c, m) { | ||
if (!c) throw Error("Internal assertion failure" + (m ? ': ' + m : '')); | ||
} | ||
|
||
function define(o, p, v, override) { | ||
if (p in o && !override) | ||
return; | ||
|
||
if (typeof v === 'function') { | ||
// Sanity check that functions are appropriately named (where possible) | ||
assert((global.Symbol && p instanceof global.Symbol) || !('name' in v) || v.name === p || v.name === p + '_', 'Expected function name "' + p + '", was "' + v.name + '"'); | ||
Object.defineProperty(o, p, { | ||
value: v, | ||
configurable: true, | ||
enumerable: false, | ||
writable: true | ||
}); | ||
} else { | ||
Object.defineProperty(o, p, { | ||
value: v, | ||
configurable: false, | ||
enumerable: false, | ||
writable: false | ||
}); | ||
} | ||
} | ||
|
||
|
||
// Snapshot intrinsic functions | ||
var $isNaN = global.isNaN; | ||
|
||
var abs = Math.abs, | ||
floor = Math.floor, | ||
max = Math.max, | ||
min = Math.min; | ||
|
||
//---------------------------------------- | ||
// 7 Abstract Operations | ||
//---------------------------------------- | ||
|
||
// 7.1.4 | ||
function ToInteger(n) { | ||
n = Number(n); | ||
if ($isNaN(n)) return 0; | ||
if (n === 0 || n === Infinity || n === -Infinity) return n; | ||
return ((n < 0) ? -1 : 1) * floor(abs(n)); | ||
} | ||
|
||
// 7.1.13 ToObject | ||
function ToObject(v) { | ||
if (v === null || v === undefined) throw TypeError(); | ||
return Object(v); | ||
} | ||
|
||
// 7.1.15 ToLength ( argument ) | ||
function ToLength(v) { | ||
var len = ToInteger(v); | ||
if (len <= 0) { | ||
return 0; | ||
} | ||
return min(len, 0x20000000000000 - 1); // 2^53-1 | ||
} | ||
|
||
//---------------------------------------- | ||
// 7.2 Testing and Comparison Operations | ||
//---------------------------------------- | ||
|
||
// 7.2.10 SameValueZero(x, y) | ||
function SameValueZero(x, y) { | ||
if (typeof x !== typeof y) return false; | ||
switch (typeof x) { | ||
case 'undefined': | ||
return true; | ||
case 'number': | ||
if (x !== x && y !== y) return true; | ||
return x === y; | ||
case 'boolean': | ||
case 'string': | ||
case 'object': | ||
default: | ||
return x === y; | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------- | ||
// | ||
// ECMAScript 2016 | ||
// | ||
//---------------------------------------------------------------------- | ||
|
||
// https://github.com/tc39/Array.prototype.includes/ | ||
define( | ||
Array.prototype, 'includes', | ||
function includes(target) { | ||
var fromIndex = arguments[1]; | ||
|
||
var o = ToObject(this); | ||
var len = ToLength(o["length"]); | ||
if (len === 0) return false; | ||
var n = ToInteger(fromIndex); | ||
if (n >= 0) { | ||
var k = n; | ||
} else { | ||
k = len + n; | ||
if (k < 0) k = 0; | ||
} | ||
while (k < len) { | ||
var elementK = o[k]; | ||
if (SameValueZero(o[k], target)) | ||
return true; | ||
k += 1; | ||
} | ||
return false; | ||
}); | ||
|
||
}(this)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# ECMAScript 2016 Polyfill | ||
|
||
[script](es2016.js) - | ||
[unit tests](https://inexorabletash.github.io/polyfill/tests/es2016.html) | ||
|
||
This assumes ES6, so use [es5.js](es5.js) and [es6.js](es6.js) for older browsers (IE9-). | ||
|
||
[ECMAScript 2016 Standard](http://www.ecma-international.org/ecma-262/7.0/) | ||
|
||
* `Array.prototype.includes()` [ref](http://www.ecma-international.org/ecma-262/7.0/index.html#sec-array.prototype.includes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "js-polyfills", | ||
"author": "Joshua Bell <[email protected]>", | ||
"version": "0.1.26", | ||
"version": "0.1.27", | ||
"description": "Collection of Web polyfills.", | ||
"license": "Unlicense", | ||
"main": "polyfill.js", | ||
|
@@ -16,6 +16,8 @@ | |
"es5.js", | ||
"es6.md", | ||
"es6.js", | ||
"es2016.md", | ||
"es2016.js", | ||
"html.js", | ||
"dom.js", | ||
"xhr.js", | ||
|
Oops, something went wrong.