├── .gitignore ├── tests ├── helpers │ ├── h.js │ ├── h-matchers.js │ └── h-kill.js ├── lib │ ├── jasmine_favicon.png │ ├── jasmine.css │ ├── jasmine-html.js │ └── json2.js ├── spec │ ├── s-string.js │ ├── s-object.js │ ├── s-function.js │ ├── s-date.js │ └── s-array.js └── index.html ├── minify ├── LICENSE ├── package.json ├── CONTRIBUTORS.md ├── es5-sham.min.js ├── CHANGES ├── README.md ├── es5-shim.min.js ├── es5-sham.js └── es5-shim.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /tests/helpers/h.js: -------------------------------------------------------------------------------- 1 | function implement() { 2 | throw 'Not implemented'; 3 | } -------------------------------------------------------------------------------- /minify: -------------------------------------------------------------------------------- 1 | closure < es5-shim.js > es5-shim.min.js 2 | closure < es5-sham.js > es5-sham.min.js 3 | -------------------------------------------------------------------------------- /tests/lib/jasmine_favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/subtleGradient/es5-shim/master/tests/lib/jasmine_favicon.png -------------------------------------------------------------------------------- /tests/helpers/h-matchers.js: -------------------------------------------------------------------------------- 1 | beforeEach(function() { 2 | this.addMatchers({ 3 | toExactlyMatch: function(expected) { 4 | var a1, a2, 5 | l, i, 6 | key, 7 | actual = this.actual; 8 | 9 | var getKeys = function(o) { 10 | var a = []; 11 | for(key in o) { 12 | if(o.hasOwnProperty(key)) { 13 | a.push(key); 14 | } 15 | } 16 | return a; 17 | } 18 | a1 = getKeys(actual); 19 | a2 = getKeys(expected); 20 | 21 | l = a1.length; 22 | if(l !== a2.length) { 23 | return false; 24 | } 25 | for(i = 0; i < l; i++) { 26 | key = a1[i]; 27 | expect(key).toEqual(a2[i]); 28 | expect(actual[key]).toEqual(expected[key]); 29 | } 30 | 31 | return true; 32 | } 33 | }) 34 | }); 35 | -------------------------------------------------------------------------------- /tests/spec/s-string.js: -------------------------------------------------------------------------------- 1 | describe('String', function() { 2 | "use strict"; 3 | describe("trim", function() { 4 | var test = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFFHello, World!\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF"; 5 | 6 | it('trims all ES5 whitespace', function() { 7 | expect(test.trim()).toEqual("Hello, World!"); 8 | expect(test.trim().length).toEqual(13); 9 | }); 10 | }); 11 | 12 | describe("split", function() { 13 | var test = "ab"; 14 | 15 | it('If "separator" is undefined must return Array with one String - "this" string', function() { 16 | expect(test.split()).toEqual([test]); 17 | expect(test.split(void 0)).toEqual([test]); 18 | }); 19 | 20 | it('If "separator" is undefined and "limit" set to 0 must return Array[]', function() { 21 | expect(test.split(void 0, 0)).toEqual([]); 22 | }); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright 2009, 2010 Kristopher Michael Kowal. All rights reserved. 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to 5 | deal in the Software without restriction, including without limitation the 6 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 | sell copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 | IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "es5-shim", 3 | "version": "2.0.2", 4 | "description": "ES5 as implementable on previous engines", 5 | "homepage": "http://github.com/kriskowal/es5-shim/", 6 | "contributors": [ 7 | "Kris Kowal (http://github.com/kriskowal/)", 8 | "Sami Samhuri (http://samhuri.net/)", 9 | "Florian Schäfer (http://github.com/fschaefer)", 10 | "Irakli Gozalishvili (http://jeditoolkit.com)", 11 | "Kit Cambridge (http://kitcambridge.github.com)" 12 | ], 13 | "bugs": { 14 | "mail": "kris@cixar.com", 15 | "url": "http://github.com/kriskowal/es5-shim/issues" 16 | }, 17 | "licenses": [ 18 | { 19 | "type": "MIT", 20 | "url": "http://github.com/kriskowal/es5-shim/raw/master/LICENSE" 21 | } 22 | ], 23 | "main": "es5-shim.js", 24 | "repository": { 25 | "type": "git", 26 | "url": "http://github.com/kriskowal/es5-shim.git" 27 | }, 28 | "engines": { 29 | "node": ">=0.2.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | 2 | - kriskowal Kris Kowal Copyright (C) 2009-2011 MIT License 3 | - tlrobinson Tom Robinson Copyright (C) 2009-2010 MIT License (Narwhal 4 | Project) 5 | - dantman Daniel Friesen Copyright (C) 2010 XXX TODO License or CLA 6 | - fschaefer Florian Schäfer Copyright (C) 2010 MIT License 7 | - Gozala Irakli Gozalishvili Copyright (C) 2010 MIT License 8 | - kitcambridge Kit Cambridge Copyright (C) 2011 MIT License 9 | - kossnocorp Sasha Koss XXX TODO License or CLA 10 | - bryanforbes Bryan Forbes XXX TODO License or CLA 11 | - killdream Quildreen Motta Copyright (C) 2011 MIT Licence 12 | - michaelficarra Michael Ficarra Copyright (C) 2011 3-clause BSD 13 | License 14 | - sharkbrainguy Gerard Paapu Copyright (C) 2011 MIT License 15 | - bbqsrc Brendan Molloy (C) 2011 Creative Commons Zero (public domain) 16 | - iwyg XXX TODO License or CLA 17 | - DomenicDenicola Domenic Denicola Copyright (C) 2011 MIT License 18 | - xavierm02 Montillet Xavier Copyright (C) 2011 MIT License 19 | - Raynos Jake Verbaten Copyright (C) 2011 MIT Licence 20 | - samsonjs Sami Samhuri Copyright (C) 2010 MIT License 21 | - rwldrn Rick Waldron Copyright (C) 2011 MIT License 22 | - lexer Alexey Zakharov XXX TODO License or CLA 23 | - 280 North Inc. (Now Motorola LLC, a subsidiary of Google Inc.) 24 | Copyright (C) 2009 MIT License 25 | 26 | -------------------------------------------------------------------------------- /tests/helpers/h-kill.js: -------------------------------------------------------------------------------- 1 | // This methods allows the killing of built-in functions, 2 | // so the shim can take over with that implementation 3 | var HLP = (function() { 4 | "use strict"; 5 | var kill; 6 | 7 | kill = function(_class, methods) { 8 | /*if(!Array.isArray(methods)) 9 | return;*/ 10 | if(!_class.originals) 11 | _class.originals = {}; 12 | 13 | for (var i = 0, len = methods.length; i < len; i++) { 14 | var obj = methods[i]; 15 | _class.originals[obj] = _class[obj]; 16 | delete _class[obj]; 17 | if (obj in _class) { 18 | // try something more aggressive since V8 at least 19 | // appears to ignore the delete. 20 | _class[obj] = null; 21 | if (_class[obj]) { 22 | console.log("Couln't overwrite", obj, "of", _class); 23 | } 24 | } 25 | } 26 | }; 27 | return { kill: kill }; 28 | }()); 29 | 30 | HLP.kill(Function.prototype, [ 31 | 'bind' 32 | ]); 33 | 34 | HLP.kill(Array, [ 35 | 'isArray' 36 | ]); 37 | 38 | HLP.kill(String.prototype, [ 39 | "trim" 40 | ]); 41 | 42 | HLP.kill(Object, [ 43 | 'keys' 44 | ]); 45 | 46 | HLP.kill(Date, [ 47 | 'now', 'parse' 48 | ]); 49 | 50 | HLP.kill(Date.prototype, [ 51 | "toJSON", "toISOString" 52 | ]); 53 | 54 | HLP.kill(Array.prototype, [ 55 | 'forEach', 'some', 'every', 56 | 'indexOf', 'lastIndexOf', 57 | 'map', 'filter', 58 | 'reduce', 'reduceRight' 59 | ]); 60 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Jasmine Spec Runner 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /es5-sham.min.js: -------------------------------------------------------------------------------- 1 | (function(d){"function"==typeof define?define(d):"function"==typeof YUI?YUI.add("es5-sham",d):d()})(function(){function d(a){try{return Object.defineProperty(a,"sentinel",{}),"sentinel"in a}catch(b){}}Object.getPrototypeOf||(Object.getPrototypeOf=function(a){return a.__proto__||(a.constructor?a.constructor.prototype:prototypeOfObject)});Object.getOwnPropertyDescriptor||(Object.getOwnPropertyDescriptor=function(a,b){if(typeof a!="object"&&typeof a!="function"||a===null)throw new TypeError("Object.getOwnPropertyDescriptor called on a non-object: "+ 2 | a);if(owns(a,b)){var c={enumerable:true,configurable:true};if(supportsAccessors){var g=a.__proto__;a.__proto__=prototypeOfObject;var d=lookupGetter(a,b),e=lookupSetter(a,b);a.__proto__=g;if(d||e){if(d)c.get=d;if(e)c.set=e;return c}}c.value=a[b];return c}});Object.getOwnPropertyNames||(Object.getOwnPropertyNames=function(a){return Object.keys(a)});Object.create||(Object.create=function(a,b){function c(){}var d;if(a===null)d={__proto__:null};else{if(typeof a!=="object"&&typeof a!=="function")throw new TypeError("Object prototype may only be an Object or null"); 3 | c.prototype=a;d=new c;d.__proto__=a}b!==void 0&&Object.defineProperties(d,b);return d});if(Object.defineProperty){var f=d({}),h="undefined"==typeof document||d(document.createElement("div"));if(!f||!h)var e=Object.defineProperty}if(!Object.defineProperty||e)Object.defineProperty=function(a,b,c){if(typeof a!="object"&&typeof a!="function"||a===null)throw new TypeError("Object.defineProperty called on non-object: "+a);if(typeof c!="object"&&typeof c!="function"||c===null)throw new TypeError("Property description must be an object: "+ 4 | c);if(e)try{return e.call(Object,a,b,c)}catch(d){}if(owns(c,"value"))if(supportsAccessors&&(lookupGetter(a,b)||lookupSetter(a,b))){var f=a.__proto__;a.__proto__=prototypeOfObject;delete a[b];a[b]=c.value;a.__proto__=f}else a[b]=c.value;else{if(!supportsAccessors)throw new TypeError("getters & setters can not be defined on this javascript engine");owns(c,"get")&&defineGetter(a,b,c.get);owns(c,"set")&&defineSetter(a,b,c.set)}return a};Object.defineProperties||(Object.defineProperties=function(a,b){for(var c in b)owns(b, 5 | c)&&c!="__proto__"&&Object.defineProperty(a,c,b[c]);return a});Object.seal||(Object.seal=function(a){return a});Object.freeze||(Object.freeze=function(a){return a});try{Object.freeze(function(){})}catch(j){var i=Object.freeze;Object.freeze=function(a){return typeof a=="function"?a:i(a)}}Object.preventExtensions||(Object.preventExtensions=function(a){return a});Object.isSealed||(Object.isSealed=function(){return false});Object.isFrozen||(Object.isFrozen=function(){return false});Object.isExtensible|| 6 | (Object.isExtensible=function(a){if(Object(a)!==a)throw new TypeError;for(var b="";owns(a,b);)b=b+"?";a[b]=true;var c=owns(a,b);delete a[b];return c})}); 7 | -------------------------------------------------------------------------------- /tests/spec/s-object.js: -------------------------------------------------------------------------------- 1 | describe('Object', function () { 2 | "use strict"; 3 | 4 | describe("Object.keys", function () { 5 | var obj = { 6 | "str": "boz", 7 | "obj": { }, 8 | "arr": [], 9 | "bool": true, 10 | "num": 42, 11 | "null": null, 12 | "undefined": undefined 13 | }; 14 | 15 | var loopedValues = []; 16 | for (var k in obj) { 17 | loopedValues.push(k); 18 | } 19 | 20 | var keys = Object.keys(obj); 21 | it('should have correct length', function () { 22 | expect(keys.length).toBe(7); 23 | }); 24 | 25 | it('should return an Array', function () { 26 | expect(Array.isArray(keys)).toBe(true); 27 | }); 28 | 29 | it('should return names which are own properties', function () { 30 | keys.forEach(function (name) { 31 | expect(obj.hasOwnProperty(name)).toBe(true); 32 | }); 33 | }); 34 | 35 | it('should return names which are enumerable', function () { 36 | keys.forEach(function (name) { 37 | expect(loopedValues.indexOf(name)).toNotBe(-1); 38 | }) 39 | }); 40 | 41 | it('should throw error for non object', function () { 42 | var e = {}; 43 | expect(function () { 44 | try { 45 | Object.keys(42) 46 | } catch (err) { 47 | throw e; 48 | } 49 | }).toThrow(e); 50 | }); 51 | }); 52 | 53 | describe("Object.isExtensible", function () { 54 | var obj = { }; 55 | 56 | it('should return true if object is extensible', function () { 57 | expect(Object.isExtensible(obj)).toBe(true); 58 | }); 59 | 60 | it('should return false if object is not extensible', function () { 61 | expect(Object.isExtensible(Object.preventExtensions(obj))).toBe(false); 62 | }); 63 | 64 | it('should return false if object is seal', function () { 65 | expect(Object.isExtensible(Object.seal(obj))).toBe(false); 66 | }); 67 | 68 | it('should return false if object is freeze', function () { 69 | expect(Object.isExtensible(Object.freeze(obj))).toBe(false); 70 | }); 71 | 72 | it('should throw error for non object', function () { 73 | var e1 = {}; 74 | expect(function () { 75 | try { 76 | Object.isExtensible(42) 77 | } catch (err) { 78 | throw e1; 79 | } 80 | }).toThrow(e1); 81 | }); 82 | }); 83 | 84 | }); -------------------------------------------------------------------------------- /tests/lib/jasmine.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif; 3 | } 4 | 5 | 6 | .jasmine_reporter a:visited, .jasmine_reporter a { 7 | color: #303; 8 | } 9 | 10 | .jasmine_reporter a:hover, .jasmine_reporter a:active { 11 | color: blue; 12 | } 13 | 14 | .run_spec { 15 | float:right; 16 | padding-right: 5px; 17 | font-size: .8em; 18 | text-decoration: none; 19 | } 20 | 21 | .jasmine_reporter { 22 | margin: 0 5px; 23 | } 24 | 25 | .banner { 26 | color: #303; 27 | background-color: #fef; 28 | padding: 5px; 29 | } 30 | 31 | .logo { 32 | float: left; 33 | font-size: 1.1em; 34 | padding-left: 5px; 35 | } 36 | 37 | .logo .version { 38 | font-size: .6em; 39 | padding-left: 1em; 40 | } 41 | 42 | .runner.running { 43 | background-color: yellow; 44 | } 45 | 46 | 47 | .options { 48 | text-align: right; 49 | font-size: .8em; 50 | } 51 | 52 | 53 | 54 | 55 | .suite { 56 | border: 1px outset gray; 57 | margin: 5px 0; 58 | padding-left: 1em; 59 | } 60 | 61 | .suite .suite { 62 | margin: 5px; 63 | } 64 | 65 | .suite.passed { 66 | background-color: #dfd; 67 | } 68 | 69 | .suite.failed { 70 | background-color: #fdd; 71 | } 72 | 73 | .spec { 74 | margin: 5px; 75 | padding-left: 1em; 76 | clear: both; 77 | } 78 | 79 | .spec.failed, .spec.passed, .spec.skipped { 80 | padding-bottom: 5px; 81 | border: 1px solid gray; 82 | } 83 | 84 | .spec.failed { 85 | background-color: #fbb; 86 | border-color: red; 87 | } 88 | 89 | .spec.passed { 90 | background-color: #bfb; 91 | border-color: green; 92 | } 93 | 94 | .spec.skipped { 95 | background-color: #bbb; 96 | } 97 | 98 | .messages { 99 | border-left: 1px dashed gray; 100 | padding-left: 1em; 101 | padding-right: 1em; 102 | } 103 | 104 | .passed { 105 | background-color: #cfc; 106 | display: none; 107 | } 108 | 109 | .failed { 110 | background-color: #fbb; 111 | } 112 | 113 | .skipped { 114 | color: #777; 115 | background-color: #eee; 116 | display: none; 117 | } 118 | 119 | 120 | /*.resultMessage {*/ 121 | /*white-space: pre;*/ 122 | /*}*/ 123 | 124 | .resultMessage span.result { 125 | display: block; 126 | line-height: 2em; 127 | color: black; 128 | } 129 | 130 | .resultMessage .mismatch { 131 | color: black; 132 | } 133 | 134 | .stackTrace { 135 | white-space: pre; 136 | font-size: .8em; 137 | margin-left: 10px; 138 | max-height: 5em; 139 | overflow: auto; 140 | border: 1px inset red; 141 | padding: 1em; 142 | background: #eef; 143 | } 144 | 145 | .finished-at { 146 | padding-left: 1em; 147 | font-size: .6em; 148 | } 149 | 150 | .show-passed .passed, 151 | .show-skipped .skipped { 152 | display: block; 153 | } 154 | 155 | 156 | #jasmine_content { 157 | position:fixed; 158 | right: 100%; 159 | } 160 | 161 | .runner { 162 | border: 1px solid gray; 163 | display: block; 164 | margin: 5px 0; 165 | padding: 2px 0 2px 10px; 166 | } 167 | -------------------------------------------------------------------------------- /CHANGES: -------------------------------------------------------------------------------- 1 | 2 | 2.0.0 3 | - Separate reliable shims from dubious shims (shams). 4 | 5 | 1.2.10 6 | - Group-effort Style Cleanup 7 | - Took a stab at fixing Object.defineProperty on IE8 without 8 | bad side-effects. (@hax) 9 | - Object.isExtensible no longer fakes it. (@xavierm) 10 | - Date.prototype.toISOString no longer deals with partial 11 | ISO dates, per spec (@kitcambridge) 12 | - More (mostly from @bryanforbes) 13 | 14 | 1.2.9 15 | - Corrections to toISOString by @kitcambridge 16 | - Fixed three bugs in array methods revealed by Jasmine tests. 17 | - Cleaned up Function.prototype.bind with more fixes and tests from 18 | @bryanforbes. 19 | 20 | 1.2.8 21 | - Actually fixed problems with Function.prototype.bind, and regressions 22 | from 1.2.7 (@bryanforbes, @jdalton #36) 23 | 24 | 1.2.7 - REGRESSED 25 | - Fixed problems with Function.prototype.bind when called as a constructor. 26 | (@jdalton #36) 27 | 28 | 1.2.6 29 | - Revised Date.parse to match ES 5.1 (kitcambridge) 30 | 31 | 1.2.5 32 | - Fixed a bug for padding it Date..toISOString (tadfisher issue #33) 33 | 34 | 1.2.4 35 | - Fixed a descriptor bug in Object.defineProperty (raynos) 36 | 37 | 1.2.3 38 | - Cleaned up RequireJS and