rest-ftp-daemon 0.400.0 → 0.410.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +26 -6
  3. data/Rakefile +5 -3
  4. data/bin/rest-ftp-daemon +2 -1
  5. data/config.ru +8 -2
  6. data/lib/rest-ftp-daemon.rb +10 -2
  7. data/lib/rest-ftp-daemon/api/debug.rb +17 -5
  8. data/lib/rest-ftp-daemon/api/{job_presenter.rb → entities/job.rb} +25 -2
  9. data/lib/rest-ftp-daemon/api/entities/options.rb +15 -0
  10. data/lib/rest-ftp-daemon/api/jobs.rb +46 -13
  11. data/lib/rest-ftp-daemon/api/root-real.rb +80 -0
  12. data/lib/rest-ftp-daemon/api/root-test.rb +69 -0
  13. data/lib/rest-ftp-daemon/api/root.rb +21 -5
  14. data/lib/rest-ftp-daemon/constants.rb +18 -1
  15. data/lib/rest-ftp-daemon/counters.rb +0 -3
  16. data/lib/rest-ftp-daemon/exceptions.rb +16 -12
  17. data/lib/rest-ftp-daemon/helpers/api.rb +3 -3
  18. data/lib/rest-ftp-daemon/helpers/common.rb +12 -5
  19. data/lib/rest-ftp-daemon/helpers/views.rb +41 -11
  20. data/lib/rest-ftp-daemon/job.rb +118 -420
  21. data/lib/rest-ftp-daemon/job_queue.rb +34 -5
  22. data/lib/rest-ftp-daemon/jobs/dummy.rb +20 -0
  23. data/lib/rest-ftp-daemon/jobs/transfer.rb +319 -0
  24. data/lib/rest-ftp-daemon/jobs/video.rb +107 -0
  25. data/lib/rest-ftp-daemon/location.rb +125 -0
  26. data/lib/rest-ftp-daemon/path.rb +3 -0
  27. data/lib/rest-ftp-daemon/remote_ftp.rb +2 -2
  28. data/lib/rest-ftp-daemon/remote_sftp.rb +2 -2
  29. data/lib/rest-ftp-daemon/static/config.json +411 -0
  30. data/lib/rest-ftp-daemon/static/css/bootstrap.min.css +14 -0
  31. data/lib/rest-ftp-daemon/static/css/{bootstrap.css → bootstrap.old.css} +0 -0
  32. data/lib/rest-ftp-daemon/static/fonts/glyphicons-halflings-regular.eot +0 -0
  33. data/lib/rest-ftp-daemon/static/fonts/glyphicons-halflings-regular.svg +288 -0
  34. data/lib/rest-ftp-daemon/static/fonts/glyphicons-halflings-regular.ttf +0 -0
  35. data/lib/rest-ftp-daemon/static/fonts/glyphicons-halflings-regular.woff +0 -0
  36. data/lib/rest-ftp-daemon/static/fonts/glyphicons-halflings-regular.woff2 +0 -0
  37. data/lib/rest-ftp-daemon/static/swagger.html +83 -0
  38. data/lib/rest-ftp-daemon/static/swagger/css/print.css +1362 -0
  39. data/lib/rest-ftp-daemon/static/swagger/css/reset.css +125 -0
  40. data/lib/rest-ftp-daemon/static/swagger/css/screen.css +1489 -0
  41. data/lib/rest-ftp-daemon/static/swagger/css/style.css +250 -0
  42. data/lib/rest-ftp-daemon/static/swagger/css/typography.css +14 -0
  43. data/lib/rest-ftp-daemon/static/swagger/fonts/DroidSans-Bold.ttf +0 -0
  44. data/lib/rest-ftp-daemon/static/swagger/fonts/DroidSans.ttf +0 -0
  45. data/lib/rest-ftp-daemon/static/swagger/images/collapse.gif +0 -0
  46. data/lib/rest-ftp-daemon/static/swagger/images/expand.gif +0 -0
  47. data/lib/rest-ftp-daemon/static/swagger/images/explorer_icons.png +0 -0
  48. data/lib/rest-ftp-daemon/static/swagger/images/favicon-16x16.png +0 -0
  49. data/lib/rest-ftp-daemon/static/swagger/images/favicon-32x32.png +0 -0
  50. data/lib/rest-ftp-daemon/static/swagger/images/favicon.ico +0 -0
  51. data/lib/rest-ftp-daemon/static/swagger/images/logo_small.png +0 -0
  52. data/lib/rest-ftp-daemon/static/swagger/images/pet_store_api.png +0 -0
  53. data/lib/rest-ftp-daemon/static/swagger/images/throbber.gif +0 -0
  54. data/lib/rest-ftp-daemon/static/swagger/images/wordnik_api.png +0 -0
  55. data/lib/rest-ftp-daemon/static/swagger/lib/backbone-min.js +15 -0
  56. data/lib/rest-ftp-daemon/static/swagger/lib/es5-shim.js +2065 -0
  57. data/lib/rest-ftp-daemon/static/swagger/lib/handlebars-4.0.5.js +4608 -0
  58. data/lib/rest-ftp-daemon/static/swagger/lib/highlight.9.1.0.pack.js +2 -0
  59. data/lib/rest-ftp-daemon/static/swagger/lib/highlight.9.1.0.pack_extended.js +34 -0
  60. data/lib/rest-ftp-daemon/static/swagger/lib/jquery-1.8.0.min.js +2 -0
  61. data/lib/rest-ftp-daemon/static/swagger/lib/jquery.ba-bbq.min.js +18 -0
  62. data/lib/rest-ftp-daemon/static/swagger/lib/jquery.slideto.min.js +1 -0
  63. data/lib/rest-ftp-daemon/static/swagger/lib/jquery.wiggle.min.js +8 -0
  64. data/lib/rest-ftp-daemon/static/swagger/lib/js-yaml.min.js +3 -0
  65. data/lib/rest-ftp-daemon/static/swagger/lib/jsoneditor.min.js +11 -0
  66. data/lib/rest-ftp-daemon/static/swagger/lib/lodash.min.js +102 -0
  67. data/lib/rest-ftp-daemon/static/swagger/lib/marked.js +1272 -0
  68. data/lib/rest-ftp-daemon/static/swagger/lib/object-assign-pollyfill.js +23 -0
  69. data/lib/rest-ftp-daemon/static/swagger/lib/swagger-oauth.js +347 -0
  70. data/lib/rest-ftp-daemon/static/swagger/lib/swagger-ui.min.js +10 -0
  71. data/lib/rest-ftp-daemon/uri.rb +9 -1
  72. data/lib/rest-ftp-daemon/views/dashboard.haml +1 -1
  73. data/lib/rest-ftp-daemon/views/dashboard_footer.haml +6 -3
  74. data/lib/rest-ftp-daemon/views/dashboard_jobs.haml +3 -3
  75. data/lib/rest-ftp-daemon/views/dashboard_table.haml +25 -20
  76. data/lib/rest-ftp-daemon/workers/transfer.rb +14 -0
  77. data/rest-ftp-daemon.gemspec +14 -4
  78. data/spec/rest-ftp-daemon/features/swagger_spec.rb +24 -0
  79. data/spec/spec_helper.rb +4 -4
  80. metadata +119 -14
@@ -0,0 +1,250 @@
1
+ .swagger-section #header a#logo {
2
+ font-size: 1.5em;
3
+ font-weight: bold;
4
+ text-decoration: none;
5
+ background: transparent url(../images/logo.png) no-repeat left center;
6
+ padding: 20px 0 20px 40px;
7
+ }
8
+ #text-head {
9
+ font-size: 80px;
10
+ font-family: 'Roboto', sans-serif;
11
+ color: #ffffff;
12
+ float: right;
13
+ margin-right: 20%;
14
+ }
15
+ .navbar-fixed-top .navbar-nav {
16
+ height: auto;
17
+ }
18
+ .navbar-fixed-top .navbar-brand {
19
+ height: auto;
20
+ }
21
+ .navbar-header {
22
+ height: auto;
23
+ }
24
+ .navbar-inverse {
25
+ background-color: #000;
26
+ border-color: #000;
27
+ }
28
+ #navbar-brand {
29
+ margin-left: 20%;
30
+ }
31
+ .navtext {
32
+ font-size: 10px;
33
+ }
34
+ .h1,
35
+ h1 {
36
+ font-size: 60px;
37
+ }
38
+ .navbar-default .navbar-header .navbar-brand {
39
+ color: #a2dfee;
40
+ }
41
+ /* tag titles */
42
+ .swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a {
43
+ color: #393939;
44
+ font-family: 'Arvo', serif;
45
+ font-size: 1.5em;
46
+ }
47
+ .swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 a:hover {
48
+ color: black;
49
+ }
50
+ .swagger-section .swagger-ui-wrap ul#resources li.resource div.heading h2 {
51
+ color: #525252;
52
+ padding-left: 0px;
53
+ display: block;
54
+ clear: none;
55
+ float: left;
56
+ font-family: 'Arvo', serif;
57
+ font-weight: bold;
58
+ }
59
+ .navbar-default .navbar-collapse,
60
+ .navbar-default .navbar-form {
61
+ border-color: #0A0A0A;
62
+ }
63
+ .container1 {
64
+ width: 1500px;
65
+ margin: auto;
66
+ margin-top: 0;
67
+ background-image: url('../images/shield.png');
68
+ background-repeat: no-repeat;
69
+ background-position: -40px -20px;
70
+ margin-bottom: 210px;
71
+ }
72
+ .container-inner {
73
+ width: 1200px;
74
+ margin: auto;
75
+ background-color: rgba(223, 227, 228, 0.75);
76
+ padding-bottom: 40px;
77
+ padding-top: 40px;
78
+ border-radius: 15px;
79
+ }
80
+ .header-content {
81
+ padding: 0;
82
+ width: 1000px;
83
+ }
84
+ .title1 {
85
+ font-size: 80px;
86
+ font-family: 'Vollkorn', serif;
87
+ color: #404040;
88
+ text-align: center;
89
+ padding-top: 40px;
90
+ padding-bottom: 100px;
91
+ }
92
+ #icon {
93
+ margin-top: -18px;
94
+ }
95
+ .subtext {
96
+ font-size: 25px;
97
+ font-style: italic;
98
+ color: #08b;
99
+ text-align: right;
100
+ padding-right: 250px;
101
+ }
102
+ .bg-primary {
103
+ background-color: #00468b;
104
+ }
105
+ .navbar-default .nav > li > a,
106
+ .navbar-default .nav > li > a:focus {
107
+ color: #08b;
108
+ }
109
+ .navbar-default .nav > li > a,
110
+ .navbar-default .nav > li > a:hover {
111
+ color: #08b;
112
+ }
113
+ .navbar-default .nav > li > a,
114
+ .navbar-default .nav > li > a:focus:hover {
115
+ color: #08b;
116
+ }
117
+ .text-faded {
118
+ font-size: 25px;
119
+ font-family: 'Vollkorn', serif;
120
+ }
121
+ .section-heading {
122
+ font-family: 'Vollkorn', serif;
123
+ font-size: 45px;
124
+ padding-bottom: 10px;
125
+ }
126
+ hr {
127
+ border-color: #00468b;
128
+ padding-bottom: 10px;
129
+ }
130
+ .description {
131
+ margin-top: 20px;
132
+ padding-bottom: 200px;
133
+ }
134
+ .description li {
135
+ font-family: 'Vollkorn', serif;
136
+ font-size: 25px;
137
+ color: #525252;
138
+ margin-left: 28%;
139
+ padding-top: 5px;
140
+ }
141
+ .gap {
142
+ margin-top: 200px;
143
+ }
144
+ .troubleshootingtext {
145
+ color: rgba(255, 255, 255, 0.7);
146
+ padding-left: 30%;
147
+ }
148
+ .troubleshootingtext li {
149
+ list-style-type: circle;
150
+ font-size: 25px;
151
+ padding-bottom: 5px;
152
+ }
153
+ .overlay {
154
+ position: absolute;
155
+ top: 0;
156
+ left: 0;
157
+ width: 100%;
158
+ height: 100%;
159
+ z-index: 1000;
160
+ }
161
+ .block.response_body.json:hover {
162
+ cursor: pointer;
163
+ }
164
+ .backdrop {
165
+ color: blue;
166
+ }
167
+ #myModal {
168
+ height: 100%;
169
+ }
170
+ .modal-backdrop {
171
+ bottom: 0;
172
+ position: fixed;
173
+ }
174
+ .curl {
175
+ padding: 10px;
176
+ font-family: "Anonymous Pro", "Menlo", "Consolas", "Bitstream Vera Sans Mono", "Courier New", monospace;
177
+ font-size: 0.9em;
178
+ max-height: 400px;
179
+ margin-top: 5px;
180
+ overflow-y: auto;
181
+ background-color: #fcf6db;
182
+ border: 1px solid #e5e0c6;
183
+ border-radius: 4px;
184
+ }
185
+ .curl_title {
186
+ font-size: 1.1em;
187
+ margin: 0;
188
+ padding: 15px 0 5px;
189
+ font-family: 'Open Sans', 'Helvetica Neue', Arial, sans-serif;
190
+ font-weight: 500;
191
+ line-height: 1.1;
192
+ }
193
+ .footer {
194
+ display: none;
195
+ }
196
+ .swagger-section .swagger-ui-wrap h2 {
197
+ padding: 0;
198
+ }
199
+ h2 {
200
+ margin: 0;
201
+ margin-bottom: 5px;
202
+ }
203
+ .markdown p {
204
+ font-size: 15px;
205
+ font-family: 'Arvo', serif;
206
+ }
207
+ .swagger-section .swagger-ui-wrap .code {
208
+ font-size: 15px;
209
+ font-family: 'Arvo', serif;
210
+ }
211
+ .swagger-section .swagger-ui-wrap b {
212
+ font-family: 'Arvo', serif;
213
+ }
214
+ #signin:hover {
215
+ cursor: pointer;
216
+ }
217
+ .dropdown-menu {
218
+ padding: 15px;
219
+ }
220
+ .navbar-right .dropdown-menu {
221
+ left: 0;
222
+ right: auto;
223
+ }
224
+ #signinbutton {
225
+ width: 100%;
226
+ height: 32px;
227
+ font-size: 13px;
228
+ font-weight: bold;
229
+ color: #08b;
230
+ }
231
+ .navbar-default .nav > li .details {
232
+ color: #000000;
233
+ text-transform: none;
234
+ font-size: 15px;
235
+ font-weight: normal;
236
+ font-family: 'Open Sans', sans-serif;
237
+ font-style: italic;
238
+ line-height: 20px;
239
+ top: -2px;
240
+ }
241
+ .navbar-default .nav > li .details:hover {
242
+ color: black;
243
+ }
244
+ #signout {
245
+ width: 100%;
246
+ height: 32px;
247
+ font-size: 13px;
248
+ font-weight: bold;
249
+ color: #08b;
250
+ }
@@ -0,0 +1,14 @@
1
+ /* Google Font's Droid Sans */
2
+ @font-face {
3
+ font-family: 'Droid Sans';
4
+ font-style: normal;
5
+ font-weight: 400;
6
+ src: local('Droid Sans'), local('DroidSans'), url('../fonts/DroidSans.ttf'), format('truetype');
7
+ }
8
+ /* Google Font's Droid Sans Bold */
9
+ @font-face {
10
+ font-family: 'Droid Sans';
11
+ font-style: normal;
12
+ font-weight: 700;
13
+ src: local('Droid Sans Bold'), local('DroidSans-Bold'), url('../fonts/DroidSans-Bold.ttf'), format('truetype');
14
+ }
@@ -0,0 +1,15 @@
1
+ // Backbone.js 1.1.2
2
+
3
+ (function(t,e){if(typeof define==="function"&&define.amd){define(["underscore","jquery","exports"],function(i,r,s){t.Backbone=e(t,s,i,r)})}else if(typeof exports!=="undefined"){var i=require("underscore");e(t,exports,i)}else{t.Backbone=e(t,{},t._,t.jQuery||t.Zepto||t.ender||t.$)}})(this,function(t,e,i,r){var s=t.Backbone;var n=[];var a=n.push;var o=n.slice;var h=n.splice;e.VERSION="1.1.2";e.$=r;e.noConflict=function(){t.Backbone=s;return this};e.emulateHTTP=false;e.emulateJSON=false;var u=e.Events={on:function(t,e,i){if(!c(this,"on",t,[e,i])||!e)return this;this._events||(this._events={});var r=this._events[t]||(this._events[t]=[]);r.push({callback:e,context:i,ctx:i||this});return this},once:function(t,e,r){if(!c(this,"once",t,[e,r])||!e)return this;var s=this;var n=i.once(function(){s.off(t,n);e.apply(this,arguments)});n._callback=e;return this.on(t,n,r)},off:function(t,e,r){var s,n,a,o,h,u,l,f;if(!this._events||!c(this,"off",t,[e,r]))return this;if(!t&&!e&&!r){this._events=void 0;return this}o=t?[t]:i.keys(this._events);for(h=0,u=o.length;h<u;h++){t=o[h];if(a=this._events[t]){this._events[t]=s=[];if(e||r){for(l=0,f=a.length;l<f;l++){n=a[l];if(e&&e!==n.callback&&e!==n.callback._callback||r&&r!==n.context){s.push(n)}}}if(!s.length)delete this._events[t]}}return this},trigger:function(t){if(!this._events)return this;var e=o.call(arguments,1);if(!c(this,"trigger",t,e))return this;var i=this._events[t];var r=this._events.all;if(i)f(i,e);if(r)f(r,arguments);return this},stopListening:function(t,e,r){var s=this._listeningTo;if(!s)return this;var n=!e&&!r;if(!r&&typeof e==="object")r=this;if(t)(s={})[t._listenId]=t;for(var a in s){t=s[a];t.off(e,r,this);if(n||i.isEmpty(t._events))delete this._listeningTo[a]}return this}};var l=/\s+/;var c=function(t,e,i,r){if(!i)return true;if(typeof i==="object"){for(var s in i){t[e].apply(t,[s,i[s]].concat(r))}return false}if(l.test(i)){var n=i.split(l);for(var a=0,o=n.length;a<o;a++){t[e].apply(t,[n[a]].concat(r))}return false}return true};var f=function(t,e){var i,r=-1,s=t.length,n=e[0],a=e[1],o=e[2];switch(e.length){case 0:while(++r<s)(i=t[r]).callback.call(i.ctx);return;case 1:while(++r<s)(i=t[r]).callback.call(i.ctx,n);return;case 2:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a);return;case 3:while(++r<s)(i=t[r]).callback.call(i.ctx,n,a,o);return;default:while(++r<s)(i=t[r]).callback.apply(i.ctx,e);return}};var d={listenTo:"on",listenToOnce:"once"};i.each(d,function(t,e){u[e]=function(e,r,s){var n=this._listeningTo||(this._listeningTo={});var a=e._listenId||(e._listenId=i.uniqueId("l"));n[a]=e;if(!s&&typeof r==="object")s=this;e[t](r,s,this);return this}});u.bind=u.on;u.unbind=u.off;i.extend(e,u);var p=e.Model=function(t,e){var r=t||{};e||(e={});this.cid=i.uniqueId("c");this.attributes={};if(e.collection)this.collection=e.collection;if(e.parse)r=this.parse(r,e)||{};r=i.defaults({},r,i.result(this,"defaults"));this.set(r,e);this.changed={};this.initialize.apply(this,arguments)};i.extend(p.prototype,u,{changed:null,validationError:null,idAttribute:"id",initialize:function(){},toJSON:function(t){return i.clone(this.attributes)},sync:function(){return e.sync.apply(this,arguments)},get:function(t){return this.attributes[t]},escape:function(t){return i.escape(this.get(t))},has:function(t){return this.get(t)!=null},set:function(t,e,r){var s,n,a,o,h,u,l,c;if(t==null)return this;if(typeof t==="object"){n=t;r=e}else{(n={})[t]=e}r||(r={});if(!this._validate(n,r))return false;a=r.unset;h=r.silent;o=[];u=this._changing;this._changing=true;if(!u){this._previousAttributes=i.clone(this.attributes);this.changed={}}c=this.attributes,l=this._previousAttributes;if(this.idAttribute in n)this.id=n[this.idAttribute];for(s in n){e=n[s];if(!i.isEqual(c[s],e))o.push(s);if(!i.isEqual(l[s],e)){this.changed[s]=e}else{delete this.changed[s]}a?delete c[s]:c[s]=e}if(!h){if(o.length)this._pending=r;for(var f=0,d=o.length;f<d;f++){this.trigger("change:"+o[f],this,c[o[f]],r)}}if(u)return this;if(!h){while(this._pending){r=this._pending;this._pending=false;this.trigger("change",this,r)}}this._pending=false;this._changing=false;return this},unset:function(t,e){return this.set(t,void 0,i.extend({},e,{unset:true}))},clear:function(t){var e={};for(var r in this.attributes)e[r]=void 0;return this.set(e,i.extend({},t,{unset:true}))},hasChanged:function(t){if(t==null)return!i.isEmpty(this.changed);return i.has(this.changed,t)},changedAttributes:function(t){if(!t)return this.hasChanged()?i.clone(this.changed):false;var e,r=false;var s=this._changing?this._previousAttributes:this.attributes;for(var n in t){if(i.isEqual(s[n],e=t[n]))continue;(r||(r={}))[n]=e}return r},previous:function(t){if(t==null||!this._previousAttributes)return null;return this._previousAttributes[t]},previousAttributes:function(){return i.clone(this._previousAttributes)},fetch:function(t){t=t?i.clone(t):{};if(t.parse===void 0)t.parse=true;var e=this;var r=t.success;t.success=function(i){if(!e.set(e.parse(i,t),t))return false;if(r)r(e,i,t);e.trigger("sync",e,i,t)};q(this,t);return this.sync("read",this,t)},save:function(t,e,r){var s,n,a,o=this.attributes;if(t==null||typeof t==="object"){s=t;r=e}else{(s={})[t]=e}r=i.extend({validate:true},r);if(s&&!r.wait){if(!this.set(s,r))return false}else{if(!this._validate(s,r))return false}if(s&&r.wait){this.attributes=i.extend({},o,s)}if(r.parse===void 0)r.parse=true;var h=this;var u=r.success;r.success=function(t){h.attributes=o;var e=h.parse(t,r);if(r.wait)e=i.extend(s||{},e);if(i.isObject(e)&&!h.set(e,r)){return false}if(u)u(h,t,r);h.trigger("sync",h,t,r)};q(this,r);n=this.isNew()?"create":r.patch?"patch":"update";if(n==="patch")r.attrs=s;a=this.sync(n,this,r);if(s&&r.wait)this.attributes=o;return a},destroy:function(t){t=t?i.clone(t):{};var e=this;var r=t.success;var s=function(){e.trigger("destroy",e,e.collection,t)};t.success=function(i){if(t.wait||e.isNew())s();if(r)r(e,i,t);if(!e.isNew())e.trigger("sync",e,i,t)};if(this.isNew()){t.success();return false}q(this,t);var n=this.sync("delete",this,t);if(!t.wait)s();return n},url:function(){var t=i.result(this,"urlRoot")||i.result(this.collection,"url")||M();if(this.isNew())return t;return t.replace(/([^\/])$/,"$1/")+encodeURIComponent(this.id)},parse:function(t,e){return t},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return!this.has(this.idAttribute)},isValid:function(t){return this._validate({},i.extend(t||{},{validate:true}))},_validate:function(t,e){if(!e.validate||!this.validate)return true;t=i.extend({},this.attributes,t);var r=this.validationError=this.validate(t,e)||null;if(!r)return true;this.trigger("invalid",this,r,i.extend(e,{validationError:r}));return false}});var v=["keys","values","pairs","invert","pick","omit"];i.each(v,function(t){p.prototype[t]=function(){var e=o.call(arguments);e.unshift(this.attributes);return i[t].apply(i,e)}});var g=e.Collection=function(t,e){e||(e={});if(e.model)this.model=e.model;if(e.comparator!==void 0)this.comparator=e.comparator;this._reset();this.initialize.apply(this,arguments);if(t)this.reset(t,i.extend({silent:true},e))};var m={add:true,remove:true,merge:true};var y={add:true,remove:false};i.extend(g.prototype,u,{model:p,initialize:function(){},toJSON:function(t){return this.map(function(e){return e.toJSON(t)})},sync:function(){return e.sync.apply(this,arguments)},add:function(t,e){return this.set(t,i.extend({merge:false},e,y))},remove:function(t,e){var r=!i.isArray(t);t=r?[t]:i.clone(t);e||(e={});var s,n,a,o;for(s=0,n=t.length;s<n;s++){o=t[s]=this.get(t[s]);if(!o)continue;delete this._byId[o.id];delete this._byId[o.cid];a=this.indexOf(o);this.models.splice(a,1);this.length--;if(!e.silent){e.index=a;o.trigger("remove",o,this,e)}this._removeReference(o,e)}return r?t[0]:t},set:function(t,e){e=i.defaults({},e,m);if(e.parse)t=this.parse(t,e);var r=!i.isArray(t);t=r?t?[t]:[]:i.clone(t);var s,n,a,o,h,u,l;var c=e.at;var f=this.model;var d=this.comparator&&c==null&&e.sort!==false;var v=i.isString(this.comparator)?this.comparator:null;var g=[],y=[],_={};var b=e.add,w=e.merge,x=e.remove;var E=!d&&b&&x?[]:false;for(s=0,n=t.length;s<n;s++){h=t[s]||{};if(h instanceof p){a=o=h}else{a=h[f.prototype.idAttribute||"id"]}if(u=this.get(a)){if(x)_[u.cid]=true;if(w){h=h===o?o.attributes:h;if(e.parse)h=u.parse(h,e);u.set(h,e);if(d&&!l&&u.hasChanged(v))l=true}t[s]=u}else if(b){o=t[s]=this._prepareModel(h,e);if(!o)continue;g.push(o);this._addReference(o,e)}o=u||o;if(E&&(o.isNew()||!_[o.id]))E.push(o);_[o.id]=true}if(x){for(s=0,n=this.length;s<n;++s){if(!_[(o=this.models[s]).cid])y.push(o)}if(y.length)this.remove(y,e)}if(g.length||E&&E.length){if(d)l=true;this.length+=g.length;if(c!=null){for(s=0,n=g.length;s<n;s++){this.models.splice(c+s,0,g[s])}}else{if(E)this.models.length=0;var k=E||g;for(s=0,n=k.length;s<n;s++){this.models.push(k[s])}}}if(l)this.sort({silent:true});if(!e.silent){for(s=0,n=g.length;s<n;s++){(o=g[s]).trigger("add",o,this,e)}if(l||E&&E.length)this.trigger("sort",this,e)}return r?t[0]:t},reset:function(t,e){e||(e={});for(var r=0,s=this.models.length;r<s;r++){this._removeReference(this.models[r],e)}e.previousModels=this.models;this._reset();t=this.add(t,i.extend({silent:true},e));if(!e.silent)this.trigger("reset",this,e);return t},push:function(t,e){return this.add(t,i.extend({at:this.length},e))},pop:function(t){var e=this.at(this.length-1);this.remove(e,t);return e},unshift:function(t,e){return this.add(t,i.extend({at:0},e))},shift:function(t){var e=this.at(0);this.remove(e,t);return e},slice:function(){return o.apply(this.models,arguments)},get:function(t){if(t==null)return void 0;return this._byId[t]||this._byId[t.id]||this._byId[t.cid]},at:function(t){return this.models[t]},where:function(t,e){if(i.isEmpty(t))return e?void 0:[];return this[e?"find":"filter"](function(e){for(var i in t){if(t[i]!==e.get(i))return false}return true})},findWhere:function(t){return this.where(t,true)},sort:function(t){if(!this.comparator)throw new Error("Cannot sort a set without a comparator");t||(t={});if(i.isString(this.comparator)||this.comparator.length===1){this.models=this.sortBy(this.comparator,this)}else{this.models.sort(i.bind(this.comparator,this))}if(!t.silent)this.trigger("sort",this,t);return this},pluck:function(t){return i.invoke(this.models,"get",t)},fetch:function(t){t=t?i.clone(t):{};if(t.parse===void 0)t.parse=true;var e=t.success;var r=this;t.success=function(i){var s=t.reset?"reset":"set";r[s](i,t);if(e)e(r,i,t);r.trigger("sync",r,i,t)};q(this,t);return this.sync("read",this,t)},create:function(t,e){e=e?i.clone(e):{};if(!(t=this._prepareModel(t,e)))return false;if(!e.wait)this.add(t,e);var r=this;var s=e.success;e.success=function(t,i){if(e.wait)r.add(t,e);if(s)s(t,i,e)};t.save(null,e);return t},parse:function(t,e){return t},clone:function(){return new this.constructor(this.models)},_reset:function(){this.length=0;this.models=[];this._byId={}},_prepareModel:function(t,e){if(t instanceof p)return t;e=e?i.clone(e):{};e.collection=this;var r=new this.model(t,e);if(!r.validationError)return r;this.trigger("invalid",this,r.validationError,e);return false},_addReference:function(t,e){this._byId[t.cid]=t;if(t.id!=null)this._byId[t.id]=t;if(!t.collection)t.collection=this;t.on("all",this._onModelEvent,this)},_removeReference:function(t,e){if(this===t.collection)delete t.collection;t.off("all",this._onModelEvent,this)},_onModelEvent:function(t,e,i,r){if((t==="add"||t==="remove")&&i!==this)return;if(t==="destroy")this.remove(e,r);if(e&&t==="change:"+e.idAttribute){delete this._byId[e.previous(e.idAttribute)];if(e.id!=null)this._byId[e.id]=e}this.trigger.apply(this,arguments)}});var _=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","difference","indexOf","shuffle","lastIndexOf","isEmpty","chain","sample"];i.each(_,function(t){g.prototype[t]=function(){var e=o.call(arguments);e.unshift(this.models);return i[t].apply(i,e)}});var b=["groupBy","countBy","sortBy","indexBy"];i.each(b,function(t){g.prototype[t]=function(e,r){var s=i.isFunction(e)?e:function(t){return t.get(e)};return i[t](this.models,s,r)}});var w=e.View=function(t){this.cid=i.uniqueId("view");t||(t={});i.extend(this,i.pick(t,E));this._ensureElement();this.initialize.apply(this,arguments);this.delegateEvents()};var x=/^(\S+)\s*(.*)$/;var E=["model","collection","el","id","attributes","className","tagName","events"];i.extend(w.prototype,u,{tagName:"div",$:function(t){return this.$el.find(t)},initialize:function(){},render:function(){return this},remove:function(){this.$el.remove();this.stopListening();return this},setElement:function(t,i){if(this.$el)this.undelegateEvents();this.$el=t instanceof e.$?t:e.$(t);this.el=this.$el[0];if(i!==false)this.delegateEvents();return this},delegateEvents:function(t){if(!(t||(t=i.result(this,"events"))))return this;this.undelegateEvents();for(var e in t){var r=t[e];if(!i.isFunction(r))r=this[t[e]];if(!r)continue;var s=e.match(x);var n=s[1],a=s[2];r=i.bind(r,this);n+=".delegateEvents"+this.cid;if(a===""){this.$el.on(n,r)}else{this.$el.on(n,a,r)}}return this},undelegateEvents:function(){this.$el.off(".delegateEvents"+this.cid);return this},_ensureElement:function(){if(!this.el){var t=i.extend({},i.result(this,"attributes"));if(this.id)t.id=i.result(this,"id");if(this.className)t["class"]=i.result(this,"className");var r=e.$("<"+i.result(this,"tagName")+">").attr(t);this.setElement(r,false)}else{this.setElement(i.result(this,"el"),false)}}});e.sync=function(t,r,s){var n=T[t];i.defaults(s||(s={}),{emulateHTTP:e.emulateHTTP,emulateJSON:e.emulateJSON});var a={type:n,dataType:"json"};if(!s.url){a.url=i.result(r,"url")||M()}if(s.data==null&&r&&(t==="create"||t==="update"||t==="patch")){a.contentType="application/json";a.data=JSON.stringify(s.attrs||r.toJSON(s))}if(s.emulateJSON){a.contentType="application/x-www-form-urlencoded";a.data=a.data?{model:a.data}:{}}if(s.emulateHTTP&&(n==="PUT"||n==="DELETE"||n==="PATCH")){a.type="POST";if(s.emulateJSON)a.data._method=n;var o=s.beforeSend;s.beforeSend=function(t){t.setRequestHeader("X-HTTP-Method-Override",n);if(o)return o.apply(this,arguments)}}if(a.type!=="GET"&&!s.emulateJSON){a.processData=false}if(a.type==="PATCH"&&k){a.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")}}var h=s.xhr=e.ajax(i.extend(a,s));r.trigger("request",r,h,s);return h};var k=typeof window!=="undefined"&&!!window.ActiveXObject&&!(window.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent);var T={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};e.ajax=function(){return e.$.ajax.apply(e.$,arguments)};var $=e.Router=function(t){t||(t={});if(t.routes)this.routes=t.routes;this._bindRoutes();this.initialize.apply(this,arguments)};var S=/\((.*?)\)/g;var H=/(\(\?)?:\w+/g;var A=/\*\w+/g;var I=/[\-{}\[\]+?.,\\\^$|#\s]/g;i.extend($.prototype,u,{initialize:function(){},route:function(t,r,s){if(!i.isRegExp(t))t=this._routeToRegExp(t);if(i.isFunction(r)){s=r;r=""}if(!s)s=this[r];var n=this;e.history.route(t,function(i){var a=n._extractParameters(t,i);n.execute(s,a);n.trigger.apply(n,["route:"+r].concat(a));n.trigger("route",r,a);e.history.trigger("route",n,r,a)});return this},execute:function(t,e){if(t)t.apply(this,e)},navigate:function(t,i){e.history.navigate(t,i);return this},_bindRoutes:function(){if(!this.routes)return;this.routes=i.result(this,"routes");var t,e=i.keys(this.routes);while((t=e.pop())!=null){this.route(t,this.routes[t])}},_routeToRegExp:function(t){t=t.replace(I,"\\$&").replace(S,"(?:$1)?").replace(H,function(t,e){return e?t:"([^/?]+)"}).replace(A,"([^?]*?)");return new RegExp("^"+t+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(t,e){var r=t.exec(e).slice(1);return i.map(r,function(t,e){if(e===r.length-1)return t||null;return t?decodeURIComponent(t):null})}});var N=e.History=function(){this.handlers=[];i.bindAll(this,"checkUrl");if(typeof window!=="undefined"){this.location=window.location;this.history=window.history}};var R=/^[#\/]|\s+$/g;var O=/^\/+|\/+$/g;var P=/msie [\w.]+/;var C=/\/$/;var j=/#.*$/;N.started=false;i.extend(N.prototype,u,{interval:50,atRoot:function(){return this.location.pathname.replace(/[^\/]$/,"$&/")===this.root},getHash:function(t){var e=(t||this).location.href.match(/#(.*)$/);return e?e[1]:""},getFragment:function(t,e){if(t==null){if(this._hasPushState||!this._wantsHashChange||e){t=decodeURI(this.location.pathname+this.location.search);var i=this.root.replace(C,"");if(!t.indexOf(i))t=t.slice(i.length)}else{t=this.getHash()}}return t.replace(R,"")},start:function(t){if(N.started)throw new Error("Backbone.history has already been started");N.started=true;this.options=i.extend({root:"/"},this.options,t);this.root=this.options.root;this._wantsHashChange=this.options.hashChange!==false;this._wantsPushState=!!this.options.pushState;this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var r=this.getFragment();var s=document.documentMode;var n=P.exec(navigator.userAgent.toLowerCase())&&(!s||s<=7);this.root=("/"+this.root+"/").replace(O,"/");if(n&&this._wantsHashChange){var a=e.$('<iframe src="javascript:0" tabindex="-1">');this.iframe=a.hide().appendTo("body")[0].contentWindow;this.navigate(r)}if(this._hasPushState){e.$(window).on("popstate",this.checkUrl)}else if(this._wantsHashChange&&"onhashchange"in window&&!n){e.$(window).on("hashchange",this.checkUrl)}else if(this._wantsHashChange){this._checkUrlInterval=setInterval(this.checkUrl,this.interval)}this.fragment=r;var o=this.location;if(this._wantsHashChange&&this._wantsPushState){if(!this._hasPushState&&!this.atRoot()){this.fragment=this.getFragment(null,true);this.location.replace(this.root+"#"+this.fragment);return true}else if(this._hasPushState&&this.atRoot()&&o.hash){this.fragment=this.getHash().replace(R,"");this.history.replaceState({},document.title,this.root+this.fragment)}}if(!this.options.silent)return this.loadUrl()},stop:function(){e.$(window).off("popstate",this.checkUrl).off("hashchange",this.checkUrl);if(this._checkUrlInterval)clearInterval(this._checkUrlInterval);N.started=false},route:function(t,e){this.handlers.unshift({route:t,callback:e})},checkUrl:function(t){var e=this.getFragment();if(e===this.fragment&&this.iframe){e=this.getFragment(this.getHash(this.iframe))}if(e===this.fragment)return false;if(this.iframe)this.navigate(e);this.loadUrl()},loadUrl:function(t){t=this.fragment=this.getFragment(t);return i.any(this.handlers,function(e){if(e.route.test(t)){e.callback(t);return true}})},navigate:function(t,e){if(!N.started)return false;if(!e||e===true)e={trigger:!!e};var i=this.root+(t=this.getFragment(t||""));t=t.replace(j,"");if(this.fragment===t)return;this.fragment=t;if(t===""&&i!=="/")i=i.slice(0,-1);if(this._hasPushState){this.history[e.replace?"replaceState":"pushState"]({},document.title,i)}else if(this._wantsHashChange){this._updateHash(this.location,t,e.replace);if(this.iframe&&t!==this.getFragment(this.getHash(this.iframe))){if(!e.replace)this.iframe.document.open().close();this._updateHash(this.iframe.location,t,e.replace)}}else{return this.location.assign(i)}if(e.trigger)return this.loadUrl(t)},_updateHash:function(t,e,i){if(i){var r=t.href.replace(/(javascript:|#).*$/,"");t.replace(r+"#"+e)}else{t.hash="#"+e}}});e.history=new N;var U=function(t,e){var r=this;var s;if(t&&i.has(t,"constructor")){s=t.constructor}else{s=function(){return r.apply(this,arguments)}}i.extend(s,r,e);var n=function(){this.constructor=s};n.prototype=r.prototype;s.prototype=new n;if(t)i.extend(s.prototype,t);s.__super__=r.prototype;return s};p.extend=g.extend=$.extend=w.extend=N.extend=U;var M=function(){throw new Error('A "url" property or function must be specified')};var q=function(t,e){var i=e.error;e.error=function(r){if(i)i(t,r,e);t.trigger("error",t,r,e)}};return e});
4
+
5
+ // From http://stackoverflow.com/a/19431552
6
+ // Compatibility override - Backbone 1.1 got rid of the 'options' binding
7
+ // automatically to views in the constructor - we need to keep that.
8
+ Backbone.View = (function(View) {
9
+ return View.extend({
10
+ constructor: function(options) {
11
+ this.options = options || {};
12
+ View.apply(this, arguments);
13
+ }
14
+ });
15
+ })(Backbone.View);
@@ -0,0 +1,2065 @@
1
+ /*!
2
+ * https://github.com/es-shims/es5-shim
3
+ * @license es5-shim Copyright 2009-2015 by contributors, MIT License
4
+ * see https://github.com/es-shims/es5-shim/blob/master/LICENSE
5
+ */
6
+
7
+ // vim: ts=4 sts=4 sw=4 expandtab
8
+
9
+ // Add semicolon to prevent IIFE from being passed as argument to concatenated code.
10
+ ;
11
+
12
+ // UMD (Universal Module Definition)
13
+ // see https://github.com/umdjs/umd/blob/master/templates/returnExports.js
14
+ (function (root, factory) {
15
+ 'use strict';
16
+
17
+ /* global define, exports, module */
18
+ if (typeof define === 'function' && define.amd) {
19
+ // AMD. Register as an anonymous module.
20
+ define(factory);
21
+ } else if (typeof exports === 'object') {
22
+ // Node. Does not work with strict CommonJS, but
23
+ // only CommonJS-like enviroments that support module.exports,
24
+ // like Node.
25
+ module.exports = factory();
26
+ } else {
27
+ // Browser globals (root is window)
28
+ root.returnExports = factory();
29
+ }
30
+ }(this, function () {
31
+ /**
32
+ * Brings an environment as close to ECMAScript 5 compliance
33
+ * as is possible with the facilities of erstwhile engines.
34
+ *
35
+ * Annotated ES5: http://es5.github.com/ (specific links below)
36
+ * ES5 Spec: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
37
+ * Required reading: http://javascriptweblog.wordpress.com/2011/12/05/extending-javascript-natives/
38
+ */
39
+
40
+ // Shortcut to an often accessed properties, in order to avoid multiple
41
+ // dereference that costs universally. This also holds a reference to known-good
42
+ // functions.
43
+ var $Array = Array;
44
+ var ArrayPrototype = $Array.prototype;
45
+ var $Object = Object;
46
+ var ObjectPrototype = $Object.prototype;
47
+ var $Function = Function;
48
+ var FunctionPrototype = $Function.prototype;
49
+ var $String = String;
50
+ var StringPrototype = $String.prototype;
51
+ var $Number = Number;
52
+ var NumberPrototype = $Number.prototype;
53
+ var array_slice = ArrayPrototype.slice;
54
+ var array_splice = ArrayPrototype.splice;
55
+ var array_push = ArrayPrototype.push;
56
+ var array_unshift = ArrayPrototype.unshift;
57
+ var array_concat = ArrayPrototype.concat;
58
+ var array_join = ArrayPrototype.join;
59
+ var call = FunctionPrototype.call;
60
+ var apply = FunctionPrototype.apply;
61
+ var max = Math.max;
62
+ var min = Math.min;
63
+
64
+ // Having a toString local variable name breaks in Opera so use to_string.
65
+ var to_string = ObjectPrototype.toString;
66
+
67
+ /* global Symbol */
68
+ /* eslint-disable one-var-declaration-per-line, no-redeclare, max-statements-per-line */
69
+ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
70
+ var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, constructorRegex = /^\s*class /, isES6ClassFn = function isES6ClassFn(value) { try { var fnStr = fnToStr.call(value); var singleStripped = fnStr.replace(/\/\/.*\n/g, ''); var multiStripped = singleStripped.replace(/\/\*[.\s\S]*\*\//g, ''); var spaceStripped = multiStripped.replace(/\n/mg, ' ').replace(/ {2}/g, ' '); return constructorRegex.test(spaceStripped); } catch (e) { return false; /* not a function */ } }, tryFunctionObject = function tryFunctionObject(value) { try { if (isES6ClassFn(value)) { return false; } fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]', isCallable = function isCallable(value) { if (!value) { return false; } if (typeof value !== 'function' && typeof value !== 'object') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } if (isES6ClassFn(value)) { return false; } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
71
+
72
+ var isRegex; /* inlined from https://npmjs.com/is-regex */ var regexExec = RegExp.prototype.exec, tryRegexExec = function tryRegexExec(value) { try { regexExec.call(value); return true; } catch (e) { return false; } }, regexClass = '[object RegExp]'; isRegex = function isRegex(value) { if (typeof value !== 'object') { return false; } return hasToStringTag ? tryRegexExec(value) : to_string.call(value) === regexClass; };
73
+ 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; };
74
+ /* eslint-enable one-var-declaration-per-line, no-redeclare, max-statements-per-line */
75
+
76
+ /* inlined from http://npmjs.com/define-properties */
77
+ var supportsDescriptors = $Object.defineProperty && (function () {
78
+ try {
79
+ var obj = {};
80
+ $Object.defineProperty(obj, 'x', { enumerable: false, value: obj });
81
+ for (var _ in obj) { // jscs:ignore disallowUnusedVariables
82
+ return false;
83
+ }
84
+ return obj.x === obj;
85
+ } catch (e) { /* this is ES3 */
86
+ return false;
87
+ }
88
+ }());
89
+ var defineProperties = (function (has) {
90
+ // Define configurable, writable, and non-enumerable props
91
+ // if they don't exist.
92
+ var defineProperty;
93
+ if (supportsDescriptors) {
94
+ defineProperty = function (object, name, method, forceAssign) {
95
+ if (!forceAssign && (name in object)) {
96
+ return;
97
+ }
98
+ $Object.defineProperty(object, name, {
99
+ configurable: true,
100
+ enumerable: false,
101
+ writable: true,
102
+ value: method
103
+ });
104
+ };
105
+ } else {
106
+ defineProperty = function (object, name, method, forceAssign) {
107
+ if (!forceAssign && (name in object)) {
108
+ return;
109
+ }
110
+ object[name] = method;
111
+ };
112
+ }
113
+ return function defineProperties(object, map, forceAssign) {
114
+ for (var name in map) {
115
+ if (has.call(map, name)) {
116
+ defineProperty(object, name, map[name], forceAssign);
117
+ }
118
+ }
119
+ };
120
+ }(ObjectPrototype.hasOwnProperty));
121
+
122
+ //
123
+ // Util
124
+ // ======
125
+ //
126
+
127
+ /* replaceable with https://npmjs.com/package/es-abstract /helpers/isPrimitive */
128
+ var isPrimitive = function isPrimitive(input) {
129
+ var type = typeof input;
130
+ return input === null || (type !== 'object' && type !== 'function');
131
+ };
132
+
133
+ var isActualNaN = $Number.isNaN || function isActualNaN(x) {
134
+ return x !== x;
135
+ };
136
+
137
+ var ES = {
138
+ // ES5 9.4
139
+ // http://es5.github.com/#x9.4
140
+ // http://jsperf.com/to-integer
141
+ /* replaceable with https://npmjs.com/package/es-abstract ES5.ToInteger */
142
+ ToInteger: function ToInteger(num) {
143
+ var n = +num;
144
+ if (isActualNaN(n)) {
145
+ n = 0;
146
+ } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
147
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
148
+ }
149
+ return n;
150
+ },
151
+
152
+ /* replaceable with https://npmjs.com/package/es-abstract ES5.ToPrimitive */
153
+ ToPrimitive: function ToPrimitive(input) {
154
+ var val, valueOf, toStr;
155
+ if (isPrimitive(input)) {
156
+ return input;
157
+ }
158
+ valueOf = input.valueOf;
159
+ if (isCallable(valueOf)) {
160
+ val = valueOf.call(input);
161
+ if (isPrimitive(val)) {
162
+ return val;
163
+ }
164
+ }
165
+ toStr = input.toString;
166
+ if (isCallable(toStr)) {
167
+ val = toStr.call(input);
168
+ if (isPrimitive(val)) {
169
+ return val;
170
+ }
171
+ }
172
+ throw new TypeError();
173
+ },
174
+
175
+ // ES5 9.9
176
+ // http://es5.github.com/#x9.9
177
+ /* replaceable with https://npmjs.com/package/es-abstract ES5.ToObject */
178
+ ToObject: function (o) {
179
+ if (o == null) { // this matches both null and undefined
180
+ throw new TypeError("can't convert " + o + ' to object');
181
+ }
182
+ return $Object(o);
183
+ },
184
+
185
+ /* replaceable with https://npmjs.com/package/es-abstract ES5.ToUint32 */
186
+ ToUint32: function ToUint32(x) {
187
+ return x >>> 0;
188
+ }
189
+ };
190
+
191
+ //
192
+ // Function
193
+ // ========
194
+ //
195
+
196
+ // ES-5 15.3.4.5
197
+ // http://es5.github.com/#x15.3.4.5
198
+
199
+ var Empty = function Empty() {};
200
+
201
+ defineProperties(FunctionPrototype, {
202
+ bind: function bind(that) { // .length is 1
203
+ // 1. Let Target be the this value.
204
+ var target = this;
205
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
206
+ if (!isCallable(target)) {
207
+ throw new TypeError('Function.prototype.bind called on incompatible ' + target);
208
+ }
209
+ // 3. Let A be a new (possibly empty) internal list of all of the
210
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
211
+ // XXX slicedArgs will stand in for "A" if used
212
+ var args = array_slice.call(arguments, 1); // for normal call
213
+ // 4. Let F be a new native ECMAScript object.
214
+ // 11. Set the [[Prototype]] internal property of F to the standard
215
+ // built-in Function prototype object as specified in 15.3.3.1.
216
+ // 12. Set the [[Call]] internal property of F as described in
217
+ // 15.3.4.5.1.
218
+ // 13. Set the [[Construct]] internal property of F as described in
219
+ // 15.3.4.5.2.
220
+ // 14. Set the [[HasInstance]] internal property of F as described in
221
+ // 15.3.4.5.3.
222
+ var bound;
223
+ var binder = function () {
224
+
225
+ if (this instanceof bound) {
226
+ // 15.3.4.5.2 [[Construct]]
227
+ // When the [[Construct]] internal method of a function object,
228
+ // F that was created using the bind function is called with a
229
+ // list of arguments ExtraArgs, the following steps are taken:
230
+ // 1. Let target be the value of F's [[TargetFunction]]
231
+ // internal property.
232
+ // 2. If target has no [[Construct]] internal method, a
233
+ // TypeError exception is thrown.
234
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
235
+ // property.
236
+ // 4. Let args be a new list containing the same values as the
237
+ // list boundArgs in the same order followed by the same
238
+ // values as the list ExtraArgs in the same order.
239
+ // 5. Return the result of calling the [[Construct]] internal
240
+ // method of target providing args as the arguments.
241
+
242
+ var result = apply.call(
243
+ target,
244
+ this,
245
+ array_concat.call(args, array_slice.call(arguments))
246
+ );
247
+ if ($Object(result) === result) {
248
+ return result;
249
+ }
250
+ return this;
251
+
252
+ } else {
253
+ // 15.3.4.5.1 [[Call]]
254
+ // When the [[Call]] internal method of a function object, F,
255
+ // which was created using the bind function is called with a
256
+ // this value and a list of arguments ExtraArgs, the following
257
+ // steps are taken:
258
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
259
+ // property.
260
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
261
+ // property.
262
+ // 3. Let target be the value of F's [[TargetFunction]] internal
263
+ // property.
264
+ // 4. Let args be a new list containing the same values as the
265
+ // list boundArgs in the same order followed by the same
266
+ // values as the list ExtraArgs in the same order.
267
+ // 5. Return the result of calling the [[Call]] internal method
268
+ // of target providing boundThis as the this value and
269
+ // providing args as the arguments.
270
+
271
+ // equiv: target.call(this, ...boundArgs, ...args)
272
+ return apply.call(
273
+ target,
274
+ that,
275
+ array_concat.call(args, array_slice.call(arguments))
276
+ );
277
+
278
+ }
279
+
280
+ };
281
+
282
+ // 15. If the [[Class]] internal property of Target is "Function", then
283
+ // a. Let L be the length property of Target minus the length of A.
284
+ // b. Set the length own property of F to either 0 or L, whichever is
285
+ // larger.
286
+ // 16. Else set the length own property of F to 0.
287
+
288
+ var boundLength = max(0, target.length - args.length);
289
+
290
+ // 17. Set the attributes of the length own property of F to the values
291
+ // specified in 15.3.5.1.
292
+ var boundArgs = [];
293
+ for (var i = 0; i < boundLength; i++) {
294
+ array_push.call(boundArgs, '$' + i);
295
+ }
296
+
297
+ // XXX Build a dynamic function with desired amount of arguments is the only
298
+ // way to set the length property of a function.
299
+ // In environments where Content Security Policies enabled (Chrome extensions,
300
+ // for ex.) all use of eval or Function costructor throws an exception.
301
+ // However in all of these environments Function.prototype.bind exists
302
+ // and so this code will never be executed.
303
+ bound = $Function('binder', 'return function (' + array_join.call(boundArgs, ',') + '){ return binder.apply(this, arguments); }')(binder);
304
+
305
+ if (target.prototype) {
306
+ Empty.prototype = target.prototype;
307
+ bound.prototype = new Empty();
308
+ // Clean up dangling references.
309
+ Empty.prototype = null;
310
+ }
311
+
312
+ // TODO
313
+ // 18. Set the [[Extensible]] internal property of F to true.
314
+
315
+ // TODO
316
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
317
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
318
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
319
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
320
+ // false.
321
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
322
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
323
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
324
+ // and false.
325
+
326
+ // TODO
327
+ // NOTE Function objects created using Function.prototype.bind do not
328
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
329
+ // [[Scope]] internal properties.
330
+ // XXX can't delete prototype in pure-js.
331
+
332
+ // 22. Return F.
333
+ return bound;
334
+ }
335
+ });
336
+
337
+ // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
338
+ // use it in defining shortcuts.
339
+ var owns = call.bind(ObjectPrototype.hasOwnProperty);
340
+ var toStr = call.bind(ObjectPrototype.toString);
341
+ var arraySlice = call.bind(array_slice);
342
+ var arraySliceApply = apply.bind(array_slice);
343
+ var strSlice = call.bind(StringPrototype.slice);
344
+ var strSplit = call.bind(StringPrototype.split);
345
+ var strIndexOf = call.bind(StringPrototype.indexOf);
346
+ var pushCall = call.bind(array_push);
347
+ var isEnum = call.bind(ObjectPrototype.propertyIsEnumerable);
348
+ var arraySort = call.bind(ArrayPrototype.sort);
349
+
350
+ //
351
+ // Array
352
+ // =====
353
+ //
354
+
355
+ var isArray = $Array.isArray || function isArray(obj) {
356
+ return toStr(obj) === '[object Array]';
357
+ };
358
+
359
+ // ES5 15.4.4.12
360
+ // http://es5.github.com/#x15.4.4.13
361
+ // Return len+argCount.
362
+ // [bugfix, ielt8]
363
+ // IE < 8 bug: [].unshift(0) === undefined but should be "1"
364
+ var hasUnshiftReturnValueBug = [].unshift(0) !== 1;
365
+ defineProperties(ArrayPrototype, {
366
+ unshift: function () {
367
+ array_unshift.apply(this, arguments);
368
+ return this.length;
369
+ }
370
+ }, hasUnshiftReturnValueBug);
371
+
372
+ // ES5 15.4.3.2
373
+ // http://es5.github.com/#x15.4.3.2
374
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
375
+ defineProperties($Array, { isArray: isArray });
376
+
377
+ // The IsCallable() check in the Array functions
378
+ // has been replaced with a strict check on the
379
+ // internal class of the object to trap cases where
380
+ // the provided function was actually a regular
381
+ // expression literal, which in V8 and
382
+ // JavaScriptCore is a typeof "function". Only in
383
+ // V8 are regular expression literals permitted as
384
+ // reduce parameters, so it is desirable in the
385
+ // general case for the shim to match the more
386
+ // strict and common behavior of rejecting regular
387
+ // expressions.
388
+
389
+ // ES5 15.4.4.18
390
+ // http://es5.github.com/#x15.4.4.18
391
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
392
+
393
+ // Check failure of by-index access of string characters (IE < 9)
394
+ // and failure of `0 in boxedString` (Rhino)
395
+ var boxedString = $Object('a');
396
+ var splitString = boxedString[0] !== 'a' || !(0 in boxedString);
397
+
398
+ var properlyBoxesContext = function properlyBoxed(method) {
399
+ // Check node 0.6.21 bug where third parameter is not boxed
400
+ var properlyBoxesNonStrict = true;
401
+ var properlyBoxesStrict = true;
402
+ var threwException = false;
403
+ if (method) {
404
+ try {
405
+ method.call('foo', function (_, __, context) {
406
+ if (typeof context !== 'object') {
407
+ properlyBoxesNonStrict = false;
408
+ }
409
+ });
410
+
411
+ method.call([1], function () {
412
+ 'use strict';
413
+
414
+ properlyBoxesStrict = typeof this === 'string';
415
+ }, 'x');
416
+ } catch (e) {
417
+ threwException = true;
418
+ }
419
+ }
420
+ return !!method && !threwException && properlyBoxesNonStrict && properlyBoxesStrict;
421
+ };
422
+
423
+ defineProperties(ArrayPrototype, {
424
+ forEach: function forEach(callbackfn/*, thisArg*/) {
425
+ var object = ES.ToObject(this);
426
+ var self = splitString && isString(this) ? strSplit(this, '') : object;
427
+ var i = -1;
428
+ var length = ES.ToUint32(self.length);
429
+ var T;
430
+ if (arguments.length > 1) {
431
+ T = arguments[1];
432
+ }
433
+
434
+ // If no callback function or if callback is not a callable function
435
+ if (!isCallable(callbackfn)) {
436
+ throw new TypeError('Array.prototype.forEach callback must be a function');
437
+ }
438
+
439
+ while (++i < length) {
440
+ if (i in self) {
441
+ // Invoke the callback function with call, passing arguments:
442
+ // context, property value, property key, thisArg object
443
+ if (typeof T === 'undefined') {
444
+ callbackfn(self[i], i, object);
445
+ } else {
446
+ callbackfn.call(T, self[i], i, object);
447
+ }
448
+ }
449
+ }
450
+ }
451
+ }, !properlyBoxesContext(ArrayPrototype.forEach));
452
+
453
+ // ES5 15.4.4.19
454
+ // http://es5.github.com/#x15.4.4.19
455
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
456
+ defineProperties(ArrayPrototype, {
457
+ map: function map(callbackfn/*, thisArg*/) {
458
+ var object = ES.ToObject(this);
459
+ var self = splitString && isString(this) ? strSplit(this, '') : object;
460
+ var length = ES.ToUint32(self.length);
461
+ var result = $Array(length);
462
+ var T;
463
+ if (arguments.length > 1) {
464
+ T = arguments[1];
465
+ }
466
+
467
+ // If no callback function or if callback is not a callable function
468
+ if (!isCallable(callbackfn)) {
469
+ throw new TypeError('Array.prototype.map callback must be a function');
470
+ }
471
+
472
+ for (var i = 0; i < length; i++) {
473
+ if (i in self) {
474
+ if (typeof T === 'undefined') {
475
+ result[i] = callbackfn(self[i], i, object);
476
+ } else {
477
+ result[i] = callbackfn.call(T, self[i], i, object);
478
+ }
479
+ }
480
+ }
481
+ return result;
482
+ }
483
+ }, !properlyBoxesContext(ArrayPrototype.map));
484
+
485
+ // ES5 15.4.4.20
486
+ // http://es5.github.com/#x15.4.4.20
487
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
488
+ defineProperties(ArrayPrototype, {
489
+ filter: function filter(callbackfn/*, thisArg*/) {
490
+ var object = ES.ToObject(this);
491
+ var self = splitString && isString(this) ? strSplit(this, '') : object;
492
+ var length = ES.ToUint32(self.length);
493
+ var result = [];
494
+ var value;
495
+ var T;
496
+ if (arguments.length > 1) {
497
+ T = arguments[1];
498
+ }
499
+
500
+ // If no callback function or if callback is not a callable function
501
+ if (!isCallable(callbackfn)) {
502
+ throw new TypeError('Array.prototype.filter callback must be a function');
503
+ }
504
+
505
+ for (var i = 0; i < length; i++) {
506
+ if (i in self) {
507
+ value = self[i];
508
+ if (typeof T === 'undefined' ? callbackfn(value, i, object) : callbackfn.call(T, value, i, object)) {
509
+ pushCall(result, value);
510
+ }
511
+ }
512
+ }
513
+ return result;
514
+ }
515
+ }, !properlyBoxesContext(ArrayPrototype.filter));
516
+
517
+ // ES5 15.4.4.16
518
+ // http://es5.github.com/#x15.4.4.16
519
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
520
+ defineProperties(ArrayPrototype, {
521
+ every: function every(callbackfn/*, thisArg*/) {
522
+ var object = ES.ToObject(this);
523
+ var self = splitString && isString(this) ? strSplit(this, '') : object;
524
+ var length = ES.ToUint32(self.length);
525
+ var T;
526
+ if (arguments.length > 1) {
527
+ T = arguments[1];
528
+ }
529
+
530
+ // If no callback function or if callback is not a callable function
531
+ if (!isCallable(callbackfn)) {
532
+ throw new TypeError('Array.prototype.every callback must be a function');
533
+ }
534
+
535
+ for (var i = 0; i < length; i++) {
536
+ if (i in self && !(typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
537
+ return false;
538
+ }
539
+ }
540
+ return true;
541
+ }
542
+ }, !properlyBoxesContext(ArrayPrototype.every));
543
+
544
+ // ES5 15.4.4.17
545
+ // http://es5.github.com/#x15.4.4.17
546
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
547
+ defineProperties(ArrayPrototype, {
548
+ some: function some(callbackfn/*, thisArg */) {
549
+ var object = ES.ToObject(this);
550
+ var self = splitString && isString(this) ? strSplit(this, '') : object;
551
+ var length = ES.ToUint32(self.length);
552
+ var T;
553
+ if (arguments.length > 1) {
554
+ T = arguments[1];
555
+ }
556
+
557
+ // If no callback function or if callback is not a callable function
558
+ if (!isCallable(callbackfn)) {
559
+ throw new TypeError('Array.prototype.some callback must be a function');
560
+ }
561
+
562
+ for (var i = 0; i < length; i++) {
563
+ if (i in self && (typeof T === 'undefined' ? callbackfn(self[i], i, object) : callbackfn.call(T, self[i], i, object))) {
564
+ return true;
565
+ }
566
+ }
567
+ return false;
568
+ }
569
+ }, !properlyBoxesContext(ArrayPrototype.some));
570
+
571
+ // ES5 15.4.4.21
572
+ // http://es5.github.com/#x15.4.4.21
573
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
574
+ var reduceCoercesToObject = false;
575
+ if (ArrayPrototype.reduce) {
576
+ reduceCoercesToObject = typeof ArrayPrototype.reduce.call('es5', function (_, __, ___, list) {
577
+ return list;
578
+ }) === 'object';
579
+ }
580
+ defineProperties(ArrayPrototype, {
581
+ reduce: function reduce(callbackfn/*, initialValue*/) {
582
+ var object = ES.ToObject(this);
583
+ var self = splitString && isString(this) ? strSplit(this, '') : object;
584
+ var length = ES.ToUint32(self.length);
585
+
586
+ // If no callback function or if callback is not a callable function
587
+ if (!isCallable(callbackfn)) {
588
+ throw new TypeError('Array.prototype.reduce callback must be a function');
589
+ }
590
+
591
+ // no value to return if no initial value and an empty array
592
+ if (length === 0 && arguments.length === 1) {
593
+ throw new TypeError('reduce of empty array with no initial value');
594
+ }
595
+
596
+ var i = 0;
597
+ var result;
598
+ if (arguments.length >= 2) {
599
+ result = arguments[1];
600
+ } else {
601
+ do {
602
+ if (i in self) {
603
+ result = self[i++];
604
+ break;
605
+ }
606
+
607
+ // if array contains no values, no initial value to return
608
+ if (++i >= length) {
609
+ throw new TypeError('reduce of empty array with no initial value');
610
+ }
611
+ } while (true);
612
+ }
613
+
614
+ for (; i < length; i++) {
615
+ if (i in self) {
616
+ result = callbackfn(result, self[i], i, object);
617
+ }
618
+ }
619
+
620
+ return result;
621
+ }
622
+ }, !reduceCoercesToObject);
623
+
624
+ // ES5 15.4.4.22
625
+ // http://es5.github.com/#x15.4.4.22
626
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
627
+ var reduceRightCoercesToObject = false;
628
+ if (ArrayPrototype.reduceRight) {
629
+ reduceRightCoercesToObject = typeof ArrayPrototype.reduceRight.call('es5', function (_, __, ___, list) {
630
+ return list;
631
+ }) === 'object';
632
+ }
633
+ defineProperties(ArrayPrototype, {
634
+ reduceRight: function reduceRight(callbackfn/*, initial*/) {
635
+ var object = ES.ToObject(this);
636
+ var self = splitString && isString(this) ? strSplit(this, '') : object;
637
+ var length = ES.ToUint32(self.length);
638
+
639
+ // If no callback function or if callback is not a callable function
640
+ if (!isCallable(callbackfn)) {
641
+ throw new TypeError('Array.prototype.reduceRight callback must be a function');
642
+ }
643
+
644
+ // no value to return if no initial value, empty array
645
+ if (length === 0 && arguments.length === 1) {
646
+ throw new TypeError('reduceRight of empty array with no initial value');
647
+ }
648
+
649
+ var result;
650
+ var i = length - 1;
651
+ if (arguments.length >= 2) {
652
+ result = arguments[1];
653
+ } else {
654
+ do {
655
+ if (i in self) {
656
+ result = self[i--];
657
+ break;
658
+ }
659
+
660
+ // if array contains no values, no initial value to return
661
+ if (--i < 0) {
662
+ throw new TypeError('reduceRight of empty array with no initial value');
663
+ }
664
+ } while (true);
665
+ }
666
+
667
+ if (i < 0) {
668
+ return result;
669
+ }
670
+
671
+ do {
672
+ if (i in self) {
673
+ result = callbackfn(result, self[i], i, object);
674
+ }
675
+ } while (i--);
676
+
677
+ return result;
678
+ }
679
+ }, !reduceRightCoercesToObject);
680
+
681
+ // ES5 15.4.4.14
682
+ // http://es5.github.com/#x15.4.4.14
683
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
684
+ var hasFirefox2IndexOfBug = ArrayPrototype.indexOf && [0, 1].indexOf(1, 2) !== -1;
685
+ defineProperties(ArrayPrototype, {
686
+ indexOf: function indexOf(searchElement/*, fromIndex */) {
687
+ var self = splitString && isString(this) ? strSplit(this, '') : ES.ToObject(this);
688
+ var length = ES.ToUint32(self.length);
689
+
690
+ if (length === 0) {
691
+ return -1;
692
+ }
693
+
694
+ var i = 0;
695
+ if (arguments.length > 1) {
696
+ i = ES.ToInteger(arguments[1]);
697
+ }
698
+
699
+ // handle negative indices
700
+ i = i >= 0 ? i : max(0, length + i);
701
+ for (; i < length; i++) {
702
+ if (i in self && self[i] === searchElement) {
703
+ return i;
704
+ }
705
+ }
706
+ return -1;
707
+ }
708
+ }, hasFirefox2IndexOfBug);
709
+
710
+ // ES5 15.4.4.15
711
+ // http://es5.github.com/#x15.4.4.15
712
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/lastIndexOf
713
+ var hasFirefox2LastIndexOfBug = ArrayPrototype.lastIndexOf && [0, 1].lastIndexOf(0, -3) !== -1;
714
+ defineProperties(ArrayPrototype, {
715
+ lastIndexOf: function lastIndexOf(searchElement/*, fromIndex */) {
716
+ var self = splitString && isString(this) ? strSplit(this, '') : ES.ToObject(this);
717
+ var length = ES.ToUint32(self.length);
718
+
719
+ if (length === 0) {
720
+ return -1;
721
+ }
722
+ var i = length - 1;
723
+ if (arguments.length > 1) {
724
+ i = min(i, ES.ToInteger(arguments[1]));
725
+ }
726
+ // handle negative indices
727
+ i = i >= 0 ? i : length - Math.abs(i);
728
+ for (; i >= 0; i--) {
729
+ if (i in self && searchElement === self[i]) {
730
+ return i;
731
+ }
732
+ }
733
+ return -1;
734
+ }
735
+ }, hasFirefox2LastIndexOfBug);
736
+
737
+ // ES5 15.4.4.12
738
+ // http://es5.github.com/#x15.4.4.12
739
+ var spliceNoopReturnsEmptyArray = (function () {
740
+ var a = [1, 2];
741
+ var result = a.splice();
742
+ return a.length === 2 && isArray(result) && result.length === 0;
743
+ }());
744
+ defineProperties(ArrayPrototype, {
745
+ // Safari 5.0 bug where .splice() returns undefined
746
+ splice: function splice(start, deleteCount) {
747
+ if (arguments.length === 0) {
748
+ return [];
749
+ } else {
750
+ return array_splice.apply(this, arguments);
751
+ }
752
+ }
753
+ }, !spliceNoopReturnsEmptyArray);
754
+
755
+ var spliceWorksWithEmptyObject = (function () {
756
+ var obj = {};
757
+ ArrayPrototype.splice.call(obj, 0, 0, 1);
758
+ return obj.length === 1;
759
+ }());
760
+ defineProperties(ArrayPrototype, {
761
+ splice: function splice(start, deleteCount) {
762
+ if (arguments.length === 0) {
763
+ return [];
764
+ }
765
+ var args = arguments;
766
+ this.length = max(ES.ToInteger(this.length), 0);
767
+ if (arguments.length > 0 && typeof deleteCount !== 'number') {
768
+ args = arraySlice(arguments);
769
+ if (args.length < 2) {
770
+ pushCall(args, this.length - start);
771
+ } else {
772
+ args[1] = ES.ToInteger(deleteCount);
773
+ }
774
+ }
775
+ return array_splice.apply(this, args);
776
+ }
777
+ }, !spliceWorksWithEmptyObject);
778
+ var spliceWorksWithLargeSparseArrays = (function () {
779
+ // Per https://github.com/es-shims/es5-shim/issues/295
780
+ // Safari 7/8 breaks with sparse arrays of size 1e5 or greater
781
+ var arr = new $Array(1e5);
782
+ // note: the index MUST be 8 or larger or the test will false pass
783
+ arr[8] = 'x';
784
+ arr.splice(1, 1);
785
+ // note: this test must be defined *after* the indexOf shim
786
+ // per https://github.com/es-shims/es5-shim/issues/313
787
+ return arr.indexOf('x') === 7;
788
+ }());
789
+ var spliceWorksWithSmallSparseArrays = (function () {
790
+ // Per https://github.com/es-shims/es5-shim/issues/295
791
+ // Opera 12.15 breaks on this, no idea why.
792
+ var n = 256;
793
+ var arr = [];
794
+ arr[n] = 'a';
795
+ arr.splice(n + 1, 0, 'b');
796
+ return arr[n] === 'a';
797
+ }());
798
+ defineProperties(ArrayPrototype, {
799
+ splice: function splice(start, deleteCount) {
800
+ var O = ES.ToObject(this);
801
+ var A = [];
802
+ var len = ES.ToUint32(O.length);
803
+ var relativeStart = ES.ToInteger(start);
804
+ var actualStart = relativeStart < 0 ? max((len + relativeStart), 0) : min(relativeStart, len);
805
+ var actualDeleteCount = min(max(ES.ToInteger(deleteCount), 0), len - actualStart);
806
+
807
+ var k = 0;
808
+ var from;
809
+ while (k < actualDeleteCount) {
810
+ from = $String(actualStart + k);
811
+ if (owns(O, from)) {
812
+ A[k] = O[from];
813
+ }
814
+ k += 1;
815
+ }
816
+
817
+ var items = arraySlice(arguments, 2);
818
+ var itemCount = items.length;
819
+ var to;
820
+ if (itemCount < actualDeleteCount) {
821
+ k = actualStart;
822
+ var maxK = len - actualDeleteCount;
823
+ while (k < maxK) {
824
+ from = $String(k + actualDeleteCount);
825
+ to = $String(k + itemCount);
826
+ if (owns(O, from)) {
827
+ O[to] = O[from];
828
+ } else {
829
+ delete O[to];
830
+ }
831
+ k += 1;
832
+ }
833
+ k = len;
834
+ var minK = len - actualDeleteCount + itemCount;
835
+ while (k > minK) {
836
+ delete O[k - 1];
837
+ k -= 1;
838
+ }
839
+ } else if (itemCount > actualDeleteCount) {
840
+ k = len - actualDeleteCount;
841
+ while (k > actualStart) {
842
+ from = $String(k + actualDeleteCount - 1);
843
+ to = $String(k + itemCount - 1);
844
+ if (owns(O, from)) {
845
+ O[to] = O[from];
846
+ } else {
847
+ delete O[to];
848
+ }
849
+ k -= 1;
850
+ }
851
+ }
852
+ k = actualStart;
853
+ for (var i = 0; i < items.length; ++i) {
854
+ O[k] = items[i];
855
+ k += 1;
856
+ }
857
+ O.length = len - actualDeleteCount + itemCount;
858
+
859
+ return A;
860
+ }
861
+ }, !spliceWorksWithLargeSparseArrays || !spliceWorksWithSmallSparseArrays);
862
+
863
+ var originalJoin = ArrayPrototype.join;
864
+ var hasStringJoinBug;
865
+ try {
866
+ hasStringJoinBug = Array.prototype.join.call('123', ',') !== '1,2,3';
867
+ } catch (e) {
868
+ hasStringJoinBug = true;
869
+ }
870
+ if (hasStringJoinBug) {
871
+ defineProperties(ArrayPrototype, {
872
+ join: function join(separator) {
873
+ var sep = typeof separator === 'undefined' ? ',' : separator;
874
+ return originalJoin.call(isString(this) ? strSplit(this, '') : this, sep);
875
+ }
876
+ }, hasStringJoinBug);
877
+ }
878
+
879
+ var hasJoinUndefinedBug = [1, 2].join(undefined) !== '1,2';
880
+ if (hasJoinUndefinedBug) {
881
+ defineProperties(ArrayPrototype, {
882
+ join: function join(separator) {
883
+ var sep = typeof separator === 'undefined' ? ',' : separator;
884
+ return originalJoin.call(this, sep);
885
+ }
886
+ }, hasJoinUndefinedBug);
887
+ }
888
+
889
+ var pushShim = function push(item) {
890
+ var O = ES.ToObject(this);
891
+ var n = ES.ToUint32(O.length);
892
+ var i = 0;
893
+ while (i < arguments.length) {
894
+ O[n + i] = arguments[i];
895
+ i += 1;
896
+ }
897
+ O.length = n + i;
898
+ return n + i;
899
+ };
900
+
901
+ var pushIsNotGeneric = (function () {
902
+ var obj = {};
903
+ var result = Array.prototype.push.call(obj, undefined);
904
+ return result !== 1 || obj.length !== 1 || typeof obj[0] !== 'undefined' || !owns(obj, 0);
905
+ }());
906
+ defineProperties(ArrayPrototype, {
907
+ push: function push(item) {
908
+ if (isArray(this)) {
909
+ return array_push.apply(this, arguments);
910
+ }
911
+ return pushShim.apply(this, arguments);
912
+ }
913
+ }, pushIsNotGeneric);
914
+
915
+ // This fixes a very weird bug in Opera 10.6 when pushing `undefined
916
+ var pushUndefinedIsWeird = (function () {
917
+ var arr = [];
918
+ var result = arr.push(undefined);
919
+ return result !== 1 || arr.length !== 1 || typeof arr[0] !== 'undefined' || !owns(arr, 0);
920
+ }());
921
+ defineProperties(ArrayPrototype, { push: pushShim }, pushUndefinedIsWeird);
922
+
923
+ // ES5 15.2.3.14
924
+ // http://es5.github.io/#x15.4.4.10
925
+ // Fix boxed string bug
926
+ defineProperties(ArrayPrototype, {
927
+ slice: function (start, end) {
928
+ var arr = isString(this) ? strSplit(this, '') : this;
929
+ return arraySliceApply(arr, arguments);
930
+ }
931
+ }, splitString);
932
+
933
+ var sortIgnoresNonFunctions = (function () {
934
+ try {
935
+ [1, 2].sort(null);
936
+ [1, 2].sort({});
937
+ return true;
938
+ } catch (e) {}
939
+ return false;
940
+ }());
941
+ var sortThrowsOnRegex = (function () {
942
+ // this is a problem in Firefox 4, in which `typeof /a/ === 'function'`
943
+ try {
944
+ [1, 2].sort(/a/);
945
+ return false;
946
+ } catch (e) {}
947
+ return true;
948
+ }());
949
+ var sortIgnoresUndefined = (function () {
950
+ // applies in IE 8, for one.
951
+ try {
952
+ [1, 2].sort(undefined);
953
+ return true;
954
+ } catch (e) {}
955
+ return false;
956
+ }());
957
+ defineProperties(ArrayPrototype, {
958
+ sort: function sort(compareFn) {
959
+ if (typeof compareFn === 'undefined') {
960
+ return arraySort(this);
961
+ }
962
+ if (!isCallable(compareFn)) {
963
+ throw new TypeError('Array.prototype.sort callback must be a function');
964
+ }
965
+ return arraySort(this, compareFn);
966
+ }
967
+ }, sortIgnoresNonFunctions || !sortIgnoresUndefined || !sortThrowsOnRegex);
968
+
969
+ //
970
+ // Object
971
+ // ======
972
+ //
973
+
974
+ // ES5 15.2.3.14
975
+ // http://es5.github.com/#x15.2.3.14
976
+
977
+ // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
978
+ var hasDontEnumBug = !isEnum({ 'toString': null }, 'toString');
979
+ var hasProtoEnumBug = isEnum(function () {}, 'prototype');
980
+ var hasStringEnumBug = !owns('x', '0');
981
+ var equalsConstructorPrototype = function (o) {
982
+ var ctor = o.constructor;
983
+ return ctor && ctor.prototype === o;
984
+ };
985
+ var blacklistedKeys = {
986
+ $window: true,
987
+ $console: true,
988
+ $parent: true,
989
+ $self: true,
990
+ $frame: true,
991
+ $frames: true,
992
+ $frameElement: true,
993
+ $webkitIndexedDB: true,
994
+ $webkitStorageInfo: true,
995
+ $external: true
996
+ };
997
+ var hasAutomationEqualityBug = (function () {
998
+ /* globals window */
999
+ if (typeof window === 'undefined') {
1000
+ return false;
1001
+ }
1002
+ for (var k in window) {
1003
+ try {
1004
+ if (!blacklistedKeys['$' + k] && owns(window, k) && window[k] !== null && typeof window[k] === 'object') {
1005
+ equalsConstructorPrototype(window[k]);
1006
+ }
1007
+ } catch (e) {
1008
+ return true;
1009
+ }
1010
+ }
1011
+ return false;
1012
+ }());
1013
+ var equalsConstructorPrototypeIfNotBuggy = function (object) {
1014
+ if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
1015
+ return equalsConstructorPrototype(object);
1016
+ }
1017
+ try {
1018
+ return equalsConstructorPrototype(object);
1019
+ } catch (e) {
1020
+ return false;
1021
+ }
1022
+ };
1023
+ var dontEnums = [
1024
+ 'toString',
1025
+ 'toLocaleString',
1026
+ 'valueOf',
1027
+ 'hasOwnProperty',
1028
+ 'isPrototypeOf',
1029
+ 'propertyIsEnumerable',
1030
+ 'constructor'
1031
+ ];
1032
+ var dontEnumsLength = dontEnums.length;
1033
+
1034
+ // taken directly from https://github.com/ljharb/is-arguments/blob/master/index.js
1035
+ // can be replaced with require('is-arguments') if we ever use a build process instead
1036
+ var isStandardArguments = function isArguments(value) {
1037
+ return toStr(value) === '[object Arguments]';
1038
+ };
1039
+ var isLegacyArguments = function isArguments(value) {
1040
+ return value !== null &&
1041
+ typeof value === 'object' &&
1042
+ typeof value.length === 'number' &&
1043
+ value.length >= 0 &&
1044
+ !isArray(value) &&
1045
+ isCallable(value.callee);
1046
+ };
1047
+ var isArguments = isStandardArguments(arguments) ? isStandardArguments : isLegacyArguments;
1048
+
1049
+ defineProperties($Object, {
1050
+ keys: function keys(object) {
1051
+ var isFn = isCallable(object);
1052
+ var isArgs = isArguments(object);
1053
+ var isObject = object !== null && typeof object === 'object';
1054
+ var isStr = isObject && isString(object);
1055
+
1056
+ if (!isObject && !isFn && !isArgs) {
1057
+ throw new TypeError('Object.keys called on a non-object');
1058
+ }
1059
+
1060
+ var theKeys = [];
1061
+ var skipProto = hasProtoEnumBug && isFn;
1062
+ if ((isStr && hasStringEnumBug) || isArgs) {
1063
+ for (var i = 0; i < object.length; ++i) {
1064
+ pushCall(theKeys, $String(i));
1065
+ }
1066
+ }
1067
+
1068
+ if (!isArgs) {
1069
+ for (var name in object) {
1070
+ if (!(skipProto && name === 'prototype') && owns(object, name)) {
1071
+ pushCall(theKeys, $String(name));
1072
+ }
1073
+ }
1074
+ }
1075
+
1076
+ if (hasDontEnumBug) {
1077
+ var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
1078
+ for (var j = 0; j < dontEnumsLength; j++) {
1079
+ var dontEnum = dontEnums[j];
1080
+ if (!(skipConstructor && dontEnum === 'constructor') && owns(object, dontEnum)) {
1081
+ pushCall(theKeys, dontEnum);
1082
+ }
1083
+ }
1084
+ }
1085
+ return theKeys;
1086
+ }
1087
+ });
1088
+
1089
+ var keysWorksWithArguments = $Object.keys && (function () {
1090
+ // Safari 5.0 bug
1091
+ return $Object.keys(arguments).length === 2;
1092
+ }(1, 2));
1093
+ var keysHasArgumentsLengthBug = $Object.keys && (function () {
1094
+ var argKeys = $Object.keys(arguments);
1095
+ return arguments.length !== 1 || argKeys.length !== 1 || argKeys[0] !== 1;
1096
+ }(1));
1097
+ var originalKeys = $Object.keys;
1098
+ defineProperties($Object, {
1099
+ keys: function keys(object) {
1100
+ if (isArguments(object)) {
1101
+ return originalKeys(arraySlice(object));
1102
+ } else {
1103
+ return originalKeys(object);
1104
+ }
1105
+ }
1106
+ }, !keysWorksWithArguments || keysHasArgumentsLengthBug);
1107
+
1108
+ //
1109
+ // Date
1110
+ // ====
1111
+ //
1112
+
1113
+ var hasNegativeMonthYearBug = new Date(-3509827329600292).getUTCMonth() !== 0;
1114
+ var aNegativeTestDate = new Date(-1509842289600292);
1115
+ var aPositiveTestDate = new Date(1449662400000);
1116
+ var hasToUTCStringFormatBug = aNegativeTestDate.toUTCString() !== 'Mon, 01 Jan -45875 11:59:59 GMT';
1117
+ var hasToDateStringFormatBug;
1118
+ var hasToStringFormatBug;
1119
+ var timeZoneOffset = aNegativeTestDate.getTimezoneOffset();
1120
+ if (timeZoneOffset < -720) {
1121
+ hasToDateStringFormatBug = aNegativeTestDate.toDateString() !== 'Tue Jan 02 -45875';
1122
+ hasToStringFormatBug = !(/^Thu Dec 10 2015 \d\d:\d\d:\d\d GMT[-\+]\d\d\d\d(?: |$)/).test(aPositiveTestDate.toString());
1123
+ } else {
1124
+ hasToDateStringFormatBug = aNegativeTestDate.toDateString() !== 'Mon Jan 01 -45875';
1125
+ hasToStringFormatBug = !(/^Wed Dec 09 2015 \d\d:\d\d:\d\d GMT[-\+]\d\d\d\d(?: |$)/).test(aPositiveTestDate.toString());
1126
+ }
1127
+
1128
+ var originalGetFullYear = call.bind(Date.prototype.getFullYear);
1129
+ var originalGetMonth = call.bind(Date.prototype.getMonth);
1130
+ var originalGetDate = call.bind(Date.prototype.getDate);
1131
+ var originalGetUTCFullYear = call.bind(Date.prototype.getUTCFullYear);
1132
+ var originalGetUTCMonth = call.bind(Date.prototype.getUTCMonth);
1133
+ var originalGetUTCDate = call.bind(Date.prototype.getUTCDate);
1134
+ var originalGetUTCDay = call.bind(Date.prototype.getUTCDay);
1135
+ var originalGetUTCHours = call.bind(Date.prototype.getUTCHours);
1136
+ var originalGetUTCMinutes = call.bind(Date.prototype.getUTCMinutes);
1137
+ var originalGetUTCSeconds = call.bind(Date.prototype.getUTCSeconds);
1138
+ var originalGetUTCMilliseconds = call.bind(Date.prototype.getUTCMilliseconds);
1139
+ var dayName = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
1140
+ var monthName = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
1141
+ var daysInMonth = function daysInMonth(month, year) {
1142
+ return originalGetDate(new Date(year, month, 0));
1143
+ };
1144
+
1145
+ defineProperties(Date.prototype, {
1146
+ getFullYear: function getFullYear() {
1147
+ if (!this || !(this instanceof Date)) {
1148
+ throw new TypeError('this is not a Date object.');
1149
+ }
1150
+ var year = originalGetFullYear(this);
1151
+ if (year < 0 && originalGetMonth(this) > 11) {
1152
+ return year + 1;
1153
+ }
1154
+ return year;
1155
+ },
1156
+ getMonth: function getMonth() {
1157
+ if (!this || !(this instanceof Date)) {
1158
+ throw new TypeError('this is not a Date object.');
1159
+ }
1160
+ var year = originalGetFullYear(this);
1161
+ var month = originalGetMonth(this);
1162
+ if (year < 0 && month > 11) {
1163
+ return 0;
1164
+ }
1165
+ return month;
1166
+ },
1167
+ getDate: function getDate() {
1168
+ if (!this || !(this instanceof Date)) {
1169
+ throw new TypeError('this is not a Date object.');
1170
+ }
1171
+ var year = originalGetFullYear(this);
1172
+ var month = originalGetMonth(this);
1173
+ var date = originalGetDate(this);
1174
+ if (year < 0 && month > 11) {
1175
+ if (month === 12) {
1176
+ return date;
1177
+ }
1178
+ var days = daysInMonth(0, year + 1);
1179
+ return (days - date) + 1;
1180
+ }
1181
+ return date;
1182
+ },
1183
+ getUTCFullYear: function getUTCFullYear() {
1184
+ if (!this || !(this instanceof Date)) {
1185
+ throw new TypeError('this is not a Date object.');
1186
+ }
1187
+ var year = originalGetUTCFullYear(this);
1188
+ if (year < 0 && originalGetUTCMonth(this) > 11) {
1189
+ return year + 1;
1190
+ }
1191
+ return year;
1192
+ },
1193
+ getUTCMonth: function getUTCMonth() {
1194
+ if (!this || !(this instanceof Date)) {
1195
+ throw new TypeError('this is not a Date object.');
1196
+ }
1197
+ var year = originalGetUTCFullYear(this);
1198
+ var month = originalGetUTCMonth(this);
1199
+ if (year < 0 && month > 11) {
1200
+ return 0;
1201
+ }
1202
+ return month;
1203
+ },
1204
+ getUTCDate: function getUTCDate() {
1205
+ if (!this || !(this instanceof Date)) {
1206
+ throw new TypeError('this is not a Date object.');
1207
+ }
1208
+ var year = originalGetUTCFullYear(this);
1209
+ var month = originalGetUTCMonth(this);
1210
+ var date = originalGetUTCDate(this);
1211
+ if (year < 0 && month > 11) {
1212
+ if (month === 12) {
1213
+ return date;
1214
+ }
1215
+ var days = daysInMonth(0, year + 1);
1216
+ return (days - date) + 1;
1217
+ }
1218
+ return date;
1219
+ }
1220
+ }, hasNegativeMonthYearBug);
1221
+
1222
+ defineProperties(Date.prototype, {
1223
+ toUTCString: function toUTCString() {
1224
+ if (!this || !(this instanceof Date)) {
1225
+ throw new TypeError('this is not a Date object.');
1226
+ }
1227
+ var day = originalGetUTCDay(this);
1228
+ var date = originalGetUTCDate(this);
1229
+ var month = originalGetUTCMonth(this);
1230
+ var year = originalGetUTCFullYear(this);
1231
+ var hour = originalGetUTCHours(this);
1232
+ var minute = originalGetUTCMinutes(this);
1233
+ var second = originalGetUTCSeconds(this);
1234
+ return dayName[day] + ', ' +
1235
+ (date < 10 ? '0' + date : date) + ' ' +
1236
+ monthName[month] + ' ' +
1237
+ year + ' ' +
1238
+ (hour < 10 ? '0' + hour : hour) + ':' +
1239
+ (minute < 10 ? '0' + minute : minute) + ':' +
1240
+ (second < 10 ? '0' + second : second) + ' GMT';
1241
+ }
1242
+ }, hasNegativeMonthYearBug || hasToUTCStringFormatBug);
1243
+
1244
+ // Opera 12 has `,`
1245
+ defineProperties(Date.prototype, {
1246
+ toDateString: function toDateString() {
1247
+ if (!this || !(this instanceof Date)) {
1248
+ throw new TypeError('this is not a Date object.');
1249
+ }
1250
+ var day = this.getDay();
1251
+ var date = this.getDate();
1252
+ var month = this.getMonth();
1253
+ var year = this.getFullYear();
1254
+ return dayName[day] + ' ' +
1255
+ monthName[month] + ' ' +
1256
+ (date < 10 ? '0' + date : date) + ' ' +
1257
+ year;
1258
+ }
1259
+ }, hasNegativeMonthYearBug || hasToDateStringFormatBug);
1260
+
1261
+ // can't use defineProperties here because of toString enumeration issue in IE <= 8
1262
+ if (hasNegativeMonthYearBug || hasToStringFormatBug) {
1263
+ Date.prototype.toString = function toString() {
1264
+ if (!this || !(this instanceof Date)) {
1265
+ throw new TypeError('this is not a Date object.');
1266
+ }
1267
+ var day = this.getDay();
1268
+ var date = this.getDate();
1269
+ var month = this.getMonth();
1270
+ var year = this.getFullYear();
1271
+ var hour = this.getHours();
1272
+ var minute = this.getMinutes();
1273
+ var second = this.getSeconds();
1274
+ var timezoneOffset = this.getTimezoneOffset();
1275
+ var hoursOffset = Math.floor(Math.abs(timezoneOffset) / 60);
1276
+ var minutesOffset = Math.floor(Math.abs(timezoneOffset) % 60);
1277
+ return dayName[day] + ' ' +
1278
+ monthName[month] + ' ' +
1279
+ (date < 10 ? '0' + date : date) + ' ' +
1280
+ year + ' ' +
1281
+ (hour < 10 ? '0' + hour : hour) + ':' +
1282
+ (minute < 10 ? '0' + minute : minute) + ':' +
1283
+ (second < 10 ? '0' + second : second) + ' GMT' +
1284
+ (timezoneOffset > 0 ? '-' : '+') +
1285
+ (hoursOffset < 10 ? '0' + hoursOffset : hoursOffset) +
1286
+ (minutesOffset < 10 ? '0' + minutesOffset : minutesOffset);
1287
+ };
1288
+ if (supportsDescriptors) {
1289
+ $Object.defineProperty(Date.prototype, 'toString', {
1290
+ configurable: true,
1291
+ enumerable: false,
1292
+ writable: true
1293
+ });
1294
+ }
1295
+ }
1296
+
1297
+ // ES5 15.9.5.43
1298
+ // http://es5.github.com/#x15.9.5.43
1299
+ // This function returns a String value represent the instance in time
1300
+ // represented by this Date object. The format of the String is the Date Time
1301
+ // string format defined in 15.9.1.15. All fields are present in the String.
1302
+ // The time zone is always UTC, denoted by the suffix Z. If the time value of
1303
+ // this object is not a finite Number a RangeError exception is thrown.
1304
+ var negativeDate = -62198755200000;
1305
+ var negativeYearString = '-000001';
1306
+ var hasNegativeDateBug = Date.prototype.toISOString && new Date(negativeDate).toISOString().indexOf(negativeYearString) === -1;
1307
+ var hasSafari51DateBug = Date.prototype.toISOString && new Date(-1).toISOString() !== '1969-12-31T23:59:59.999Z';
1308
+
1309
+ var getTime = call.bind(Date.prototype.getTime);
1310
+
1311
+ defineProperties(Date.prototype, {
1312
+ toISOString: function toISOString() {
1313
+ if (!isFinite(this) || !isFinite(getTime(this))) {
1314
+ // Adope Photoshop requires the second check.
1315
+ throw new RangeError('Date.prototype.toISOString called on non-finite value.');
1316
+ }
1317
+
1318
+ var year = originalGetUTCFullYear(this);
1319
+
1320
+ var month = originalGetUTCMonth(this);
1321
+ // see https://github.com/es-shims/es5-shim/issues/111
1322
+ year += Math.floor(month / 12);
1323
+ month = (month % 12 + 12) % 12;
1324
+
1325
+ // the date time string format is specified in 15.9.1.15.
1326
+ var result = [month + 1, originalGetUTCDate(this), originalGetUTCHours(this), originalGetUTCMinutes(this), originalGetUTCSeconds(this)];
1327
+ year = (
1328
+ (year < 0 ? '-' : (year > 9999 ? '+' : '')) +
1329
+ strSlice('00000' + Math.abs(year), (0 <= year && year <= 9999) ? -4 : -6)
1330
+ );
1331
+
1332
+ for (var i = 0; i < result.length; ++i) {
1333
+ // pad months, days, hours, minutes, and seconds to have two digits.
1334
+ result[i] = strSlice('00' + result[i], -2);
1335
+ }
1336
+ // pad milliseconds to have three digits.
1337
+ return (
1338
+ year + '-' + arraySlice(result, 0, 2).join('-') +
1339
+ 'T' + arraySlice(result, 2).join(':') + '.' +
1340
+ strSlice('000' + originalGetUTCMilliseconds(this), -3) + 'Z'
1341
+ );
1342
+ }
1343
+ }, hasNegativeDateBug || hasSafari51DateBug);
1344
+
1345
+ // ES5 15.9.5.44
1346
+ // http://es5.github.com/#x15.9.5.44
1347
+ // This function provides a String representation of a Date object for use by
1348
+ // JSON.stringify (15.12.3).
1349
+ var dateToJSONIsSupported = (function () {
1350
+ try {
1351
+ return Date.prototype.toJSON &&
1352
+ new Date(NaN).toJSON() === null &&
1353
+ new Date(negativeDate).toJSON().indexOf(negativeYearString) !== -1 &&
1354
+ Date.prototype.toJSON.call({ // generic
1355
+ toISOString: function () { return true; }
1356
+ });
1357
+ } catch (e) {
1358
+ return false;
1359
+ }
1360
+ }());
1361
+ if (!dateToJSONIsSupported) {
1362
+ Date.prototype.toJSON = function toJSON(key) {
1363
+ // When the toJSON method is called with argument key, the following
1364
+ // steps are taken:
1365
+
1366
+ // 1. Let O be the result of calling ToObject, giving it the this
1367
+ // value as its argument.
1368
+ // 2. Let tv be ES.ToPrimitive(O, hint Number).
1369
+ var O = $Object(this);
1370
+ var tv = ES.ToPrimitive(O);
1371
+ // 3. If tv is a Number and is not finite, return null.
1372
+ if (typeof tv === 'number' && !isFinite(tv)) {
1373
+ return null;
1374
+ }
1375
+ // 4. Let toISO be the result of calling the [[Get]] internal method of
1376
+ // O with argument "toISOString".
1377
+ var toISO = O.toISOString;
1378
+ // 5. If IsCallable(toISO) is false, throw a TypeError exception.
1379
+ if (!isCallable(toISO)) {
1380
+ throw new TypeError('toISOString property is not callable');
1381
+ }
1382
+ // 6. Return the result of calling the [[Call]] internal method of
1383
+ // toISO with O as the this value and an empty argument list.
1384
+ return toISO.call(O);
1385
+
1386
+ // NOTE 1 The argument is ignored.
1387
+
1388
+ // NOTE 2 The toJSON function is intentionally generic; it does not
1389
+ // require that its this value be a Date object. Therefore, it can be
1390
+ // transferred to other kinds of objects for use as a method. However,
1391
+ // it does require that any such object have a toISOString method. An
1392
+ // object is free to use the argument key to filter its
1393
+ // stringification.
1394
+ };
1395
+ }
1396
+
1397
+ // ES5 15.9.4.2
1398
+ // http://es5.github.com/#x15.9.4.2
1399
+ // based on work shared by Daniel Friesen (dantman)
1400
+ // http://gist.github.com/303249
1401
+ var supportsExtendedYears = Date.parse('+033658-09-27T01:46:40.000Z') === 1e15;
1402
+ var acceptsInvalidDates = !isNaN(Date.parse('2012-04-04T24:00:00.500Z')) || !isNaN(Date.parse('2012-11-31T23:59:59.000Z')) || !isNaN(Date.parse('2012-12-31T23:59:60.000Z'));
1403
+ var doesNotParseY2KNewYear = isNaN(Date.parse('2000-01-01T00:00:00.000Z'));
1404
+ if (doesNotParseY2KNewYear || acceptsInvalidDates || !supportsExtendedYears) {
1405
+ // XXX global assignment won't work in embeddings that use
1406
+ // an alternate object for the context.
1407
+ /* global Date: true */
1408
+ /* eslint-disable no-undef */
1409
+ var maxSafeUnsigned32Bit = Math.pow(2, 31) - 1;
1410
+ var hasSafariSignedIntBug = isActualNaN(new Date(1970, 0, 1, 0, 0, 0, maxSafeUnsigned32Bit + 1).getTime());
1411
+ /* eslint-disable no-implicit-globals */
1412
+ Date = (function (NativeDate) {
1413
+ /* eslint-enable no-implicit-globals */
1414
+ /* eslint-enable no-undef */
1415
+ // Date.length === 7
1416
+ var DateShim = function Date(Y, M, D, h, m, s, ms) {
1417
+ var length = arguments.length;
1418
+ var date;
1419
+ if (this instanceof NativeDate) {
1420
+ var seconds = s;
1421
+ var millis = ms;
1422
+ if (hasSafariSignedIntBug && length >= 7 && ms > maxSafeUnsigned32Bit) {
1423
+ // work around a Safari 8/9 bug where it treats the seconds as signed
1424
+ var msToShift = Math.floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
1425
+ var sToShift = Math.floor(msToShift / 1e3);
1426
+ seconds += sToShift;
1427
+ millis -= sToShift * 1e3;
1428
+ }
1429
+ date = length === 1 && $String(Y) === Y ? // isString(Y)
1430
+ // We explicitly pass it through parse:
1431
+ new NativeDate(DateShim.parse(Y)) :
1432
+ // We have to manually make calls depending on argument
1433
+ // length here
1434
+ length >= 7 ? new NativeDate(Y, M, D, h, m, seconds, millis) :
1435
+ length >= 6 ? new NativeDate(Y, M, D, h, m, seconds) :
1436
+ length >= 5 ? new NativeDate(Y, M, D, h, m) :
1437
+ length >= 4 ? new NativeDate(Y, M, D, h) :
1438
+ length >= 3 ? new NativeDate(Y, M, D) :
1439
+ length >= 2 ? new NativeDate(Y, M) :
1440
+ length >= 1 ? new NativeDate(Y instanceof NativeDate ? +Y : Y) :
1441
+ new NativeDate();
1442
+ } else {
1443
+ date = NativeDate.apply(this, arguments);
1444
+ }
1445
+ if (!isPrimitive(date)) {
1446
+ // Prevent mixups with unfixed Date object
1447
+ defineProperties(date, { constructor: DateShim }, true);
1448
+ }
1449
+ return date;
1450
+ };
1451
+
1452
+ // 15.9.1.15 Date Time String Format.
1453
+ var isoDateExpression = new RegExp('^' +
1454
+ '(\\d{4}|[+-]\\d{6})' + // four-digit year capture or sign +
1455
+ // 6-digit extended year
1456
+ '(?:-(\\d{2})' + // optional month capture
1457
+ '(?:-(\\d{2})' + // optional day capture
1458
+ '(?:' + // capture hours:minutes:seconds.milliseconds
1459
+ 'T(\\d{2})' + // hours capture
1460
+ ':(\\d{2})' + // minutes capture
1461
+ '(?:' + // optional :seconds.milliseconds
1462
+ ':(\\d{2})' + // seconds capture
1463
+ '(?:(\\.\\d{1,}))?' + // milliseconds capture
1464
+ ')?' +
1465
+ '(' + // capture UTC offset component
1466
+ 'Z|' + // UTC capture
1467
+ '(?:' + // offset specifier +/-hours:minutes
1468
+ '([-+])' + // sign capture
1469
+ '(\\d{2})' + // hours offset capture
1470
+ ':(\\d{2})' + // minutes offset capture
1471
+ ')' +
1472
+ ')?)?)?)?' +
1473
+ '$');
1474
+
1475
+ var months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
1476
+
1477
+ var dayFromMonth = function dayFromMonth(year, month) {
1478
+ var t = month > 1 ? 1 : 0;
1479
+ return (
1480
+ months[month] +
1481
+ Math.floor((year - 1969 + t) / 4) -
1482
+ Math.floor((year - 1901 + t) / 100) +
1483
+ Math.floor((year - 1601 + t) / 400) +
1484
+ 365 * (year - 1970)
1485
+ );
1486
+ };
1487
+
1488
+ var toUTC = function toUTC(t) {
1489
+ var s = 0;
1490
+ var ms = t;
1491
+ if (hasSafariSignedIntBug && ms > maxSafeUnsigned32Bit) {
1492
+ // work around a Safari 8/9 bug where it treats the seconds as signed
1493
+ var msToShift = Math.floor(ms / maxSafeUnsigned32Bit) * maxSafeUnsigned32Bit;
1494
+ var sToShift = Math.floor(msToShift / 1e3);
1495
+ s += sToShift;
1496
+ ms -= sToShift * 1e3;
1497
+ }
1498
+ return $Number(new NativeDate(1970, 0, 1, 0, 0, s, ms));
1499
+ };
1500
+
1501
+ // Copy any custom methods a 3rd party library may have added
1502
+ for (var key in NativeDate) {
1503
+ if (owns(NativeDate, key)) {
1504
+ DateShim[key] = NativeDate[key];
1505
+ }
1506
+ }
1507
+
1508
+ // Copy "native" methods explicitly; they may be non-enumerable
1509
+ defineProperties(DateShim, {
1510
+ now: NativeDate.now,
1511
+ UTC: NativeDate.UTC
1512
+ }, true);
1513
+ DateShim.prototype = NativeDate.prototype;
1514
+ defineProperties(DateShim.prototype, {
1515
+ constructor: DateShim
1516
+ }, true);
1517
+
1518
+ // Upgrade Date.parse to handle simplified ISO 8601 strings
1519
+ var parseShim = function parse(string) {
1520
+ var match = isoDateExpression.exec(string);
1521
+ if (match) {
1522
+ // parse months, days, hours, minutes, seconds, and milliseconds
1523
+ // provide default values if necessary
1524
+ // parse the UTC offset component
1525
+ var year = $Number(match[1]),
1526
+ month = $Number(match[2] || 1) - 1,
1527
+ day = $Number(match[3] || 1) - 1,
1528
+ hour = $Number(match[4] || 0),
1529
+ minute = $Number(match[5] || 0),
1530
+ second = $Number(match[6] || 0),
1531
+ millisecond = Math.floor($Number(match[7] || 0) * 1000),
1532
+ // When time zone is missed, local offset should be used
1533
+ // (ES 5.1 bug)
1534
+ // see https://bugs.ecmascript.org/show_bug.cgi?id=112
1535
+ isLocalTime = Boolean(match[4] && !match[8]),
1536
+ signOffset = match[9] === '-' ? 1 : -1,
1537
+ hourOffset = $Number(match[10] || 0),
1538
+ minuteOffset = $Number(match[11] || 0),
1539
+ result;
1540
+ var hasMinutesOrSecondsOrMilliseconds = minute > 0 || second > 0 || millisecond > 0;
1541
+ if (
1542
+ hour < (hasMinutesOrSecondsOrMilliseconds ? 24 : 25) &&
1543
+ minute < 60 && second < 60 && millisecond < 1000 &&
1544
+ month > -1 && month < 12 && hourOffset < 24 &&
1545
+ minuteOffset < 60 && // detect invalid offsets
1546
+ day > -1 &&
1547
+ day < (dayFromMonth(year, month + 1) - dayFromMonth(year, month))
1548
+ ) {
1549
+ result = (
1550
+ (dayFromMonth(year, month) + day) * 24 +
1551
+ hour +
1552
+ hourOffset * signOffset
1553
+ ) * 60;
1554
+ result = (
1555
+ (result + minute + minuteOffset * signOffset) * 60 +
1556
+ second
1557
+ ) * 1000 + millisecond;
1558
+ if (isLocalTime) {
1559
+ result = toUTC(result);
1560
+ }
1561
+ if (-8.64e15 <= result && result <= 8.64e15) {
1562
+ return result;
1563
+ }
1564
+ }
1565
+ return NaN;
1566
+ }
1567
+ return NativeDate.parse.apply(this, arguments);
1568
+ };
1569
+ defineProperties(DateShim, { parse: parseShim });
1570
+
1571
+ return DateShim;
1572
+ }(Date));
1573
+ /* global Date: false */
1574
+ }
1575
+
1576
+ // ES5 15.9.4.4
1577
+ // http://es5.github.com/#x15.9.4.4
1578
+ if (!Date.now) {
1579
+ Date.now = function now() {
1580
+ return new Date().getTime();
1581
+ };
1582
+ }
1583
+
1584
+ //
1585
+ // Number
1586
+ // ======
1587
+ //
1588
+
1589
+ // ES5.1 15.7.4.5
1590
+ // http://es5.github.com/#x15.7.4.5
1591
+ var hasToFixedBugs = NumberPrototype.toFixed && (
1592
+ (0.00008).toFixed(3) !== '0.000' ||
1593
+ (0.9).toFixed(0) !== '1' ||
1594
+ (1.255).toFixed(2) !== '1.25' ||
1595
+ (1000000000000000128).toFixed(0) !== '1000000000000000128'
1596
+ );
1597
+
1598
+ var toFixedHelpers = {
1599
+ base: 1e7,
1600
+ size: 6,
1601
+ data: [0, 0, 0, 0, 0, 0],
1602
+ multiply: function multiply(n, c) {
1603
+ var i = -1;
1604
+ var c2 = c;
1605
+ while (++i < toFixedHelpers.size) {
1606
+ c2 += n * toFixedHelpers.data[i];
1607
+ toFixedHelpers.data[i] = c2 % toFixedHelpers.base;
1608
+ c2 = Math.floor(c2 / toFixedHelpers.base);
1609
+ }
1610
+ },
1611
+ divide: function divide(n) {
1612
+ var i = toFixedHelpers.size;
1613
+ var c = 0;
1614
+ while (--i >= 0) {
1615
+ c += toFixedHelpers.data[i];
1616
+ toFixedHelpers.data[i] = Math.floor(c / n);
1617
+ c = (c % n) * toFixedHelpers.base;
1618
+ }
1619
+ },
1620
+ numToString: function numToString() {
1621
+ var i = toFixedHelpers.size;
1622
+ var s = '';
1623
+ while (--i >= 0) {
1624
+ if (s !== '' || i === 0 || toFixedHelpers.data[i] !== 0) {
1625
+ var t = $String(toFixedHelpers.data[i]);
1626
+ if (s === '') {
1627
+ s = t;
1628
+ } else {
1629
+ s += strSlice('0000000', 0, 7 - t.length) + t;
1630
+ }
1631
+ }
1632
+ }
1633
+ return s;
1634
+ },
1635
+ pow: function pow(x, n, acc) {
1636
+ return (n === 0 ? acc : (n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc)));
1637
+ },
1638
+ log: function log(x) {
1639
+ var n = 0;
1640
+ var x2 = x;
1641
+ while (x2 >= 4096) {
1642
+ n += 12;
1643
+ x2 /= 4096;
1644
+ }
1645
+ while (x2 >= 2) {
1646
+ n += 1;
1647
+ x2 /= 2;
1648
+ }
1649
+ return n;
1650
+ }
1651
+ };
1652
+
1653
+ var toFixedShim = function toFixed(fractionDigits) {
1654
+ var f, x, s, m, e, z, j, k;
1655
+
1656
+ // Test for NaN and round fractionDigits down
1657
+ f = $Number(fractionDigits);
1658
+ f = isActualNaN(f) ? 0 : Math.floor(f);
1659
+
1660
+ if (f < 0 || f > 20) {
1661
+ throw new RangeError('Number.toFixed called with invalid number of decimals');
1662
+ }
1663
+
1664
+ x = $Number(this);
1665
+
1666
+ if (isActualNaN(x)) {
1667
+ return 'NaN';
1668
+ }
1669
+
1670
+ // If it is too big or small, return the string value of the number
1671
+ if (x <= -1e21 || x >= 1e21) {
1672
+ return $String(x);
1673
+ }
1674
+
1675
+ s = '';
1676
+
1677
+ if (x < 0) {
1678
+ s = '-';
1679
+ x = -x;
1680
+ }
1681
+
1682
+ m = '0';
1683
+
1684
+ if (x > 1e-21) {
1685
+ // 1e-21 < x < 1e21
1686
+ // -70 < log2(x) < 70
1687
+ e = toFixedHelpers.log(x * toFixedHelpers.pow(2, 69, 1)) - 69;
1688
+ z = (e < 0 ? x * toFixedHelpers.pow(2, -e, 1) : x / toFixedHelpers.pow(2, e, 1));
1689
+ z *= 0x10000000000000; // Math.pow(2, 52);
1690
+ e = 52 - e;
1691
+
1692
+ // -18 < e < 122
1693
+ // x = z / 2 ^ e
1694
+ if (e > 0) {
1695
+ toFixedHelpers.multiply(0, z);
1696
+ j = f;
1697
+
1698
+ while (j >= 7) {
1699
+ toFixedHelpers.multiply(1e7, 0);
1700
+ j -= 7;
1701
+ }
1702
+
1703
+ toFixedHelpers.multiply(toFixedHelpers.pow(10, j, 1), 0);
1704
+ j = e - 1;
1705
+
1706
+ while (j >= 23) {
1707
+ toFixedHelpers.divide(1 << 23);
1708
+ j -= 23;
1709
+ }
1710
+
1711
+ toFixedHelpers.divide(1 << j);
1712
+ toFixedHelpers.multiply(1, 1);
1713
+ toFixedHelpers.divide(2);
1714
+ m = toFixedHelpers.numToString();
1715
+ } else {
1716
+ toFixedHelpers.multiply(0, z);
1717
+ toFixedHelpers.multiply(1 << (-e), 0);
1718
+ m = toFixedHelpers.numToString() + strSlice('0.00000000000000000000', 2, 2 + f);
1719
+ }
1720
+ }
1721
+
1722
+ if (f > 0) {
1723
+ k = m.length;
1724
+
1725
+ if (k <= f) {
1726
+ m = s + strSlice('0.0000000000000000000', 0, f - k + 2) + m;
1727
+ } else {
1728
+ m = s + strSlice(m, 0, k - f) + '.' + strSlice(m, k - f);
1729
+ }
1730
+ } else {
1731
+ m = s + m;
1732
+ }
1733
+
1734
+ return m;
1735
+ };
1736
+ defineProperties(NumberPrototype, { toFixed: toFixedShim }, hasToFixedBugs);
1737
+
1738
+ var hasToPrecisionUndefinedBug = (function () {
1739
+ try {
1740
+ return 1.0.toPrecision(undefined) === '1';
1741
+ } catch (e) {
1742
+ return true;
1743
+ }
1744
+ }());
1745
+ var originalToPrecision = NumberPrototype.toPrecision;
1746
+ defineProperties(NumberPrototype, {
1747
+ toPrecision: function toPrecision(precision) {
1748
+ return typeof precision === 'undefined' ? originalToPrecision.call(this) : originalToPrecision.call(this, precision);
1749
+ }
1750
+ }, hasToPrecisionUndefinedBug);
1751
+
1752
+ //
1753
+ // String
1754
+ // ======
1755
+ //
1756
+
1757
+ // ES5 15.5.4.14
1758
+ // http://es5.github.com/#x15.5.4.14
1759
+
1760
+ // [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
1761
+ // Many browsers do not split properly with regular expressions or they
1762
+ // do not perform the split correctly under obscure conditions.
1763
+ // See http://blog.stevenlevithan.com/archives/cross-browser-split
1764
+ // I've tested in many browsers and this seems to cover the deviant ones:
1765
+ // 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
1766
+ // '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
1767
+ // 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
1768
+ // [undefined, "t", undefined, "e", ...]
1769
+ // ''.split(/.?/) should be [], not [""]
1770
+ // '.'.split(/()()/) should be ["."], not ["", "", "."]
1771
+
1772
+ if (
1773
+ 'ab'.split(/(?:ab)*/).length !== 2 ||
1774
+ '.'.split(/(.?)(.?)/).length !== 4 ||
1775
+ 'tesst'.split(/(s)*/)[1] === 't' ||
1776
+ 'test'.split(/(?:)/, -1).length !== 4 ||
1777
+ ''.split(/.?/).length ||
1778
+ '.'.split(/()()/).length > 1
1779
+ ) {
1780
+ (function () {
1781
+ var compliantExecNpcg = typeof (/()??/).exec('')[1] === 'undefined'; // NPCG: nonparticipating capturing group
1782
+ var maxSafe32BitInt = Math.pow(2, 32) - 1;
1783
+
1784
+ StringPrototype.split = function (separator, limit) {
1785
+ var string = String(this);
1786
+ if (typeof separator === 'undefined' && limit === 0) {
1787
+ return [];
1788
+ }
1789
+
1790
+ // If `separator` is not a regex, use native split
1791
+ if (!isRegex(separator)) {
1792
+ return strSplit(this, separator, limit);
1793
+ }
1794
+
1795
+ var output = [];
1796
+ var flags = (separator.ignoreCase ? 'i' : '') +
1797
+ (separator.multiline ? 'm' : '') +
1798
+ (separator.unicode ? 'u' : '') + // in ES6
1799
+ (separator.sticky ? 'y' : ''), // Firefox 3+ and ES6
1800
+ lastLastIndex = 0,
1801
+ // Make `global` and avoid `lastIndex` issues by working with a copy
1802
+ separator2, match, lastIndex, lastLength;
1803
+ var separatorCopy = new RegExp(separator.source, flags + 'g');
1804
+ if (!compliantExecNpcg) {
1805
+ // Doesn't need flags gy, but they don't hurt
1806
+ separator2 = new RegExp('^' + separatorCopy.source + '$(?!\\s)', flags);
1807
+ }
1808
+ /* Values for `limit`, per the spec:
1809
+ * If undefined: 4294967295 // maxSafe32BitInt
1810
+ * If 0, Infinity, or NaN: 0
1811
+ * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
1812
+ * If negative number: 4294967296 - Math.floor(Math.abs(limit))
1813
+ * If other: Type-convert, then use the above rules
1814
+ */
1815
+ var splitLimit = typeof limit === 'undefined' ? maxSafe32BitInt : ES.ToUint32(limit);
1816
+ match = separatorCopy.exec(string);
1817
+ while (match) {
1818
+ // `separatorCopy.lastIndex` is not reliable cross-browser
1819
+ lastIndex = match.index + match[0].length;
1820
+ if (lastIndex > lastLastIndex) {
1821
+ pushCall(output, strSlice(string, lastLastIndex, match.index));
1822
+ // Fix browsers whose `exec` methods don't consistently return `undefined` for
1823
+ // nonparticipating capturing groups
1824
+ if (!compliantExecNpcg && match.length > 1) {
1825
+ /* eslint-disable no-loop-func */
1826
+ match[0].replace(separator2, function () {
1827
+ for (var i = 1; i < arguments.length - 2; i++) {
1828
+ if (typeof arguments[i] === 'undefined') {
1829
+ match[i] = void 0;
1830
+ }
1831
+ }
1832
+ });
1833
+ /* eslint-enable no-loop-func */
1834
+ }
1835
+ if (match.length > 1 && match.index < string.length) {
1836
+ array_push.apply(output, arraySlice(match, 1));
1837
+ }
1838
+ lastLength = match[0].length;
1839
+ lastLastIndex = lastIndex;
1840
+ if (output.length >= splitLimit) {
1841
+ break;
1842
+ }
1843
+ }
1844
+ if (separatorCopy.lastIndex === match.index) {
1845
+ separatorCopy.lastIndex++; // Avoid an infinite loop
1846
+ }
1847
+ match = separatorCopy.exec(string);
1848
+ }
1849
+ if (lastLastIndex === string.length) {
1850
+ if (lastLength || !separatorCopy.test('')) {
1851
+ pushCall(output, '');
1852
+ }
1853
+ } else {
1854
+ pushCall(output, strSlice(string, lastLastIndex));
1855
+ }
1856
+ return output.length > splitLimit ? arraySlice(output, 0, splitLimit) : output;
1857
+ };
1858
+ }());
1859
+
1860
+ // [bugfix, chrome]
1861
+ // If separator is undefined, then the result array contains just one String,
1862
+ // which is the this value (converted to a String). If limit is not undefined,
1863
+ // then the output array is truncated so that it contains no more than limit
1864
+ // elements.
1865
+ // "0".split(undefined, 0) -> []
1866
+ } else if ('0'.split(void 0, 0).length) {
1867
+ StringPrototype.split = function split(separator, limit) {
1868
+ if (typeof separator === 'undefined' && limit === 0) {
1869
+ return [];
1870
+ }
1871
+ return strSplit(this, separator, limit);
1872
+ };
1873
+ }
1874
+
1875
+ var str_replace = StringPrototype.replace;
1876
+ var replaceReportsGroupsCorrectly = (function () {
1877
+ var groups = [];
1878
+ 'x'.replace(/x(.)?/g, function (match, group) {
1879
+ pushCall(groups, group);
1880
+ });
1881
+ return groups.length === 1 && typeof groups[0] === 'undefined';
1882
+ }());
1883
+
1884
+ if (!replaceReportsGroupsCorrectly) {
1885
+ StringPrototype.replace = function replace(searchValue, replaceValue) {
1886
+ var isFn = isCallable(replaceValue);
1887
+ var hasCapturingGroups = isRegex(searchValue) && (/\)[*?]/).test(searchValue.source);
1888
+ if (!isFn || !hasCapturingGroups) {
1889
+ return str_replace.call(this, searchValue, replaceValue);
1890
+ } else {
1891
+ var wrappedReplaceValue = function (match) {
1892
+ var length = arguments.length;
1893
+ var originalLastIndex = searchValue.lastIndex;
1894
+ searchValue.lastIndex = 0;
1895
+ var args = searchValue.exec(match) || [];
1896
+ searchValue.lastIndex = originalLastIndex;
1897
+ pushCall(args, arguments[length - 2], arguments[length - 1]);
1898
+ return replaceValue.apply(this, args);
1899
+ };
1900
+ return str_replace.call(this, searchValue, wrappedReplaceValue);
1901
+ }
1902
+ };
1903
+ }
1904
+
1905
+ // ECMA-262, 3rd B.2.3
1906
+ // Not an ECMAScript standard, although ECMAScript 3rd Edition has a
1907
+ // non-normative section suggesting uniform semantics and it should be
1908
+ // normalized across all browsers
1909
+ // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
1910
+ var string_substr = StringPrototype.substr;
1911
+ var hasNegativeSubstrBug = ''.substr && '0b'.substr(-1) !== 'b';
1912
+ defineProperties(StringPrototype, {
1913
+ substr: function substr(start, length) {
1914
+ var normalizedStart = start;
1915
+ if (start < 0) {
1916
+ normalizedStart = max(this.length + start, 0);
1917
+ }
1918
+ return string_substr.call(this, normalizedStart, length);
1919
+ }
1920
+ }, hasNegativeSubstrBug);
1921
+
1922
+ // ES5 15.5.4.20
1923
+ // whitespace from: http://es5.github.io/#x15.5.4.20
1924
+ var ws = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003' +
1925
+ '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028' +
1926
+ '\u2029\uFEFF';
1927
+ var zeroWidth = '\u200b';
1928
+ var wsRegexChars = '[' + ws + ']';
1929
+ var trimBeginRegexp = new RegExp('^' + wsRegexChars + wsRegexChars + '*');
1930
+ var trimEndRegexp = new RegExp(wsRegexChars + wsRegexChars + '*$');
1931
+ var hasTrimWhitespaceBug = StringPrototype.trim && (ws.trim() || !zeroWidth.trim());
1932
+ defineProperties(StringPrototype, {
1933
+ // http://blog.stevenlevithan.com/archives/faster-trim-javascript
1934
+ // http://perfectionkills.com/whitespace-deviations/
1935
+ trim: function trim() {
1936
+ if (typeof this === 'undefined' || this === null) {
1937
+ throw new TypeError("can't convert " + this + ' to object');
1938
+ }
1939
+ return $String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, '');
1940
+ }
1941
+ }, hasTrimWhitespaceBug);
1942
+ var trim = call.bind(String.prototype.trim);
1943
+
1944
+ var hasLastIndexBug = StringPrototype.lastIndexOf && 'abcあい'.lastIndexOf('あい', 2) !== -1;
1945
+ defineProperties(StringPrototype, {
1946
+ lastIndexOf: function lastIndexOf(searchString) {
1947
+ if (typeof this === 'undefined' || this === null) {
1948
+ throw new TypeError("can't convert " + this + ' to object');
1949
+ }
1950
+ var S = $String(this);
1951
+ var searchStr = $String(searchString);
1952
+ var numPos = arguments.length > 1 ? $Number(arguments[1]) : NaN;
1953
+ var pos = isActualNaN(numPos) ? Infinity : ES.ToInteger(numPos);
1954
+ var start = min(max(pos, 0), S.length);
1955
+ var searchLen = searchStr.length;
1956
+ var k = start + searchLen;
1957
+ while (k > 0) {
1958
+ k = max(0, k - searchLen);
1959
+ var index = strIndexOf(strSlice(S, k, start + searchLen), searchStr);
1960
+ if (index !== -1) {
1961
+ return k + index;
1962
+ }
1963
+ }
1964
+ return -1;
1965
+ }
1966
+ }, hasLastIndexBug);
1967
+
1968
+ var originalLastIndexOf = StringPrototype.lastIndexOf;
1969
+ defineProperties(StringPrototype, {
1970
+ lastIndexOf: function lastIndexOf(searchString) {
1971
+ return originalLastIndexOf.apply(this, arguments);
1972
+ }
1973
+ }, StringPrototype.lastIndexOf.length !== 1);
1974
+
1975
+ // ES-5 15.1.2.2
1976
+ /* eslint-disable radix */
1977
+ if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
1978
+ /* eslint-enable radix */
1979
+ /* global parseInt: true */
1980
+ parseInt = (function (origParseInt) {
1981
+ var hexRegex = /^[\-+]?0[xX]/;
1982
+ return function parseInt(str, radix) {
1983
+ var string = trim(String(str));
1984
+ var defaultedRadix = $Number(radix) || (hexRegex.test(string) ? 16 : 10);
1985
+ return origParseInt(string, defaultedRadix);
1986
+ };
1987
+ }(parseInt));
1988
+ }
1989
+
1990
+ // https://es5.github.io/#x15.1.2.3
1991
+ if (1 / parseFloat('-0') !== -Infinity) {
1992
+ /* global parseFloat: true */
1993
+ parseFloat = (function (origParseFloat) {
1994
+ return function parseFloat(string) {
1995
+ var inputString = trim(String(string));
1996
+ var result = origParseFloat(inputString);
1997
+ return result === 0 && strSlice(inputString, 0, 1) === '-' ? -0 : result;
1998
+ };
1999
+ }(parseFloat));
2000
+ }
2001
+
2002
+ if (String(new RangeError('test')) !== 'RangeError: test') {
2003
+ var errorToStringShim = function toString() {
2004
+ if (typeof this === 'undefined' || this === null) {
2005
+ throw new TypeError("can't convert " + this + ' to object');
2006
+ }
2007
+ var name = this.name;
2008
+ if (typeof name === 'undefined') {
2009
+ name = 'Error';
2010
+ } else if (typeof name !== 'string') {
2011
+ name = $String(name);
2012
+ }
2013
+ var msg = this.message;
2014
+ if (typeof msg === 'undefined') {
2015
+ msg = '';
2016
+ } else if (typeof msg !== 'string') {
2017
+ msg = $String(msg);
2018
+ }
2019
+ if (!name) {
2020
+ return msg;
2021
+ }
2022
+ if (!msg) {
2023
+ return name;
2024
+ }
2025
+ return name + ': ' + msg;
2026
+ };
2027
+ // can't use defineProperties here because of toString enumeration issue in IE <= 8
2028
+ Error.prototype.toString = errorToStringShim;
2029
+ }
2030
+
2031
+ if (supportsDescriptors) {
2032
+ var ensureNonEnumerable = function (obj, prop) {
2033
+ if (isEnum(obj, prop)) {
2034
+ var desc = Object.getOwnPropertyDescriptor(obj, prop);
2035
+ if (desc.configurable) {
2036
+ desc.enumerable = false;
2037
+ Object.defineProperty(obj, prop, desc);
2038
+ }
2039
+ }
2040
+ };
2041
+ ensureNonEnumerable(Error.prototype, 'message');
2042
+ if (Error.prototype.message !== '') {
2043
+ Error.prototype.message = '';
2044
+ }
2045
+ ensureNonEnumerable(Error.prototype, 'name');
2046
+ }
2047
+
2048
+ if (String(/a/mig) !== '/a/gim') {
2049
+ var regexToString = function toString() {
2050
+ var str = '/' + this.source + '/';
2051
+ if (this.global) {
2052
+ str += 'g';
2053
+ }
2054
+ if (this.ignoreCase) {
2055
+ str += 'i';
2056
+ }
2057
+ if (this.multiline) {
2058
+ str += 'm';
2059
+ }
2060
+ return str;
2061
+ };
2062
+ // can't use defineProperties here because of toString enumeration issue in IE <= 8
2063
+ RegExp.prototype.toString = regexToString;
2064
+ }
2065
+ }));