es6to5-rails 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5a13c617579a766b716899150c03b1efc2380f1f
4
+ data.tar.gz: 6261b6a3d0896837d647cdf426578bd9bb2cdac1
5
+ SHA512:
6
+ metadata.gz: d82837b85a54de7eccb5cec6decd4ae148461b275ac3b506852f9a2e50c4a3087a491a1e1518ba01e767d632371751e9b9a2b2b42c1dea0e5683151927e9a0dd
7
+ data.tar.gz: 908f6b51dd9ff41245c258813aea9bc84eb4e3b989e88ff681873f930f133bf4e2567388942e278b203118c1f5867c85c25aec562dd1da1ae828e6bf0595b387
@@ -0,0 +1,23 @@
1
+ .idea
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in es6to5-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Anatoly Lapshin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Es6to5::Rails
2
+
3
+ Simple gem to translate ECMAScript 6 scripts to ES5 ones using 6to5
4
+
5
+ TODO: Use cocaine to run 6to5
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'es6to5-rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install es6to5-rails
20
+
21
+ ## Usage
22
+
23
+ Just require `es6to5` in your `application.js`:
24
+
25
+ //= require es6to5
26
+
27
+ And name your scripts like: `my-script.js.es6`
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it ( https://github.com/holywarez/es6to5-rails/fork )
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'es6to5-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'es6to5-rails'
8
+ spec.version = Es6to5::VERSION
9
+ spec.authors = ['Anatoly Lapshin']
10
+ spec.email = ['holywarez@gmail.com']
11
+ spec.summary = %q{Simple gem to translate ECMAScript 6 scripts to ES5 ones using 6to5}
12
+ spec.description = %q{Simple gem to translate ECMAScript 6 scripts to ES5 ones using 6to5}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_runtime_dependency 'tilt', '>= 0'
24
+ spec.add_runtime_dependency 'sprockets', '>= 2.0.0'
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'es6to5-rails/rails'
2
+ require 'es6to5-rails/version'
3
+ require 'es6to5-rails/config'
4
+ require 'es6to5-rails/template'
5
+ require 'es6to5-rails/sprockets'
6
+
7
+ module Es6to5
8
+ module Rails
9
+ class Engine < ::Rails::Engine
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Es6to5
2
+ class Config
3
+ class << self
4
+ def bin_path
5
+ @path
6
+ end
7
+
8
+ def bin_path= path
9
+ @path = path
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ module Es6to5
2
+ end
@@ -0,0 +1,3 @@
1
+ require 'sprockets'
2
+
3
+ Sprockets.register_engine '.es6', Es6to5::Template
@@ -0,0 +1,14 @@
1
+ module Es6to5
2
+ class Template < ::Tilt::Template
3
+ self.default_mime_type = 'application/javascript'
4
+
5
+ def prepare
6
+ end
7
+
8
+ def evaluate(scope, locals, &block)
9
+ output = `#{Es6to5::Config.bin_path || '/usr/local/bin/6to5'} #{scope.pathname}`
10
+
11
+ %{(function(exports){\n#{output}\n})(exports || {});}
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Es6to5
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,1976 @@
1
+ /*!
2
+ * https://github.com/paulmillr/es6-shim
3
+ * @license es6-shim Copyright 2013-2014 by Paul Miller (http://paulmillr.com)
4
+ * and contributors, MIT License
5
+ * es6-shim: v0.19.1
6
+ * see https://github.com/paulmillr/es6-shim/blob/master/LICENSE
7
+ * Details and documentation:
8
+ * https://github.com/paulmillr/es6-shim/
9
+ */
10
+
11
+ (function (undefined) {
12
+ 'use strict';
13
+
14
+ var isCallableWithoutNew = function (func) {
15
+ try { func(); }
16
+ catch (e) { return false; }
17
+ return true;
18
+ };
19
+
20
+ var supportsSubclassing = function (C, f) {
21
+ /* jshint proto:true */
22
+ try {
23
+ var Sub = function () { C.apply(this, arguments); };
24
+ if (!Sub.__proto__) { return false; /* skip test on IE < 11 */ }
25
+ Object.setPrototypeOf(Sub, C);
26
+ Sub.prototype = Object.create(C.prototype, {
27
+ constructor: { value: C }
28
+ });
29
+ return f(Sub);
30
+ } catch (e) {
31
+ return false;
32
+ }
33
+ };
34
+
35
+ var arePropertyDescriptorsSupported = function () {
36
+ try {
37
+ Object.defineProperty({}, 'x', {});
38
+ return true;
39
+ } catch (e) { /* this is IE 8. */
40
+ return false;
41
+ }
42
+ };
43
+
44
+ var startsWithRejectsRegex = function () {
45
+ var rejectsRegex = false;
46
+ if (String.prototype.startsWith) {
47
+ try {
48
+ '/a/'.startsWith(/a/);
49
+ } catch (e) { /* this is spec compliant */
50
+ rejectsRegex = true;
51
+ }
52
+ }
53
+ return rejectsRegex;
54
+ };
55
+
56
+ /*jshint evil: true */
57
+ var getGlobal = new Function('return this;');
58
+ /*jshint evil: false */
59
+
60
+ var main = function () {
61
+ var globals = getGlobal();
62
+ var global_isFinite = globals.isFinite;
63
+ var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported();
64
+ var startsWithIsCompliant = startsWithRejectsRegex();
65
+ var _slice = Array.prototype.slice;
66
+ var _indexOf = String.prototype.indexOf;
67
+ var _toString = Object.prototype.toString;
68
+ var _hasOwnProperty = Object.prototype.hasOwnProperty;
69
+ var ArrayIterator; // make our implementation private
70
+
71
+ var defineProperty = function (object, name, value, force) {
72
+ if (!force && name in object) return;
73
+ if (supportsDescriptors) {
74
+ Object.defineProperty(object, name, {
75
+ configurable: true,
76
+ enumerable: false,
77
+ writable: true,
78
+ value: value
79
+ });
80
+ } else {
81
+ object[name] = value;
82
+ }
83
+ };
84
+
85
+ // Define configurable, writable and non-enumerable props
86
+ // if they don’t exist.
87
+ var defineProperties = function (object, map) {
88
+ Object.keys(map).forEach(function (name) {
89
+ var method = map[name];
90
+ defineProperty(object, name, method, false);
91
+ });
92
+ };
93
+
94
+ // Simple shim for Object.create on ES3 browsers
95
+ // (unlike real shim, no attempt to support `prototype === null`)
96
+ var create = Object.create || function (prototype, properties) {
97
+ function Type() {}
98
+ Type.prototype = prototype;
99
+ var object = new Type();
100
+ if (typeof properties !== "undefined") {
101
+ defineProperties(object, properties);
102
+ }
103
+ return object;
104
+ };
105
+
106
+ // This is a private name in the es6 spec, equal to '[Symbol.iterator]'
107
+ // we're going to use an arbitrary _-prefixed name to make our shims
108
+ // work properly with each other, even though we don't have full Iterator
109
+ // support. That is, `Array.from(map.keys())` will work, but we don't
110
+ // pretend to export a "real" Iterator interface.
111
+ var $iterator$ = (typeof Symbol === 'function' && Symbol.iterator) ||
112
+ '_es6shim_iterator_';
113
+ // Firefox ships a partial implementation using the name @@iterator.
114
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=907077#c14
115
+ // So use that name if we detect it.
116
+ if (globals.Set && typeof new globals.Set()['@@iterator'] === 'function') {
117
+ $iterator$ = '@@iterator';
118
+ }
119
+ var addIterator = function (prototype, impl) {
120
+ if (!impl) { impl = function iterator() { return this; }; }
121
+ var o = {};
122
+ o[$iterator$] = impl;
123
+ defineProperties(prototype, o);
124
+ /* jshint notypeof: true */
125
+ if (!prototype[$iterator$] && typeof $iterator$ === 'symbol') {
126
+ // implementations are buggy when $iterator$ is a Symbol
127
+ prototype[$iterator$] = impl;
128
+ }
129
+ };
130
+
131
+ // taken directly from https://github.com/ljharb/is-arguments/blob/master/index.js
132
+ // can be replaced with require('is-arguments') if we ever use a build process instead
133
+ var isArguments = function isArguments(value) {
134
+ var str = _toString.call(value);
135
+ var result = str === '[object Arguments]';
136
+ if (!result) {
137
+ result = str !== '[object Array]' &&
138
+ value !== null &&
139
+ typeof value === 'object' &&
140
+ typeof value.length === 'number' &&
141
+ value.length >= 0 &&
142
+ _toString.call(value.callee) === '[object Function]';
143
+ }
144
+ return result;
145
+ };
146
+
147
+ var emulateES6construct = function (o) {
148
+ if (!ES.TypeIsObject(o)) throw new TypeError('bad object');
149
+ // es5 approximation to es6 subclass semantics: in es6, 'new Foo'
150
+ // would invoke Foo.@@create to allocation/initialize the new object.
151
+ // In es5 we just get the plain object. So if we detect an
152
+ // uninitialized object, invoke o.constructor.@@create
153
+ if (!o._es6construct) {
154
+ if (o.constructor && ES.IsCallable(o.constructor['@@create'])) {
155
+ o = o.constructor['@@create'](o);
156
+ }
157
+ defineProperties(o, { _es6construct: true });
158
+ }
159
+ return o;
160
+ };
161
+
162
+ var ES = {
163
+ CheckObjectCoercible: function (x, optMessage) {
164
+ /* jshint eqnull:true */
165
+ if (x == null)
166
+ throw new TypeError(optMessage || ('Cannot call method on ' + x));
167
+ return x;
168
+ },
169
+
170
+ TypeIsObject: function (x) {
171
+ /* jshint eqnull:true */
172
+ // this is expensive when it returns false; use this function
173
+ // when you expect it to return true in the common case.
174
+ return x != null && Object(x) === x;
175
+ },
176
+
177
+ ToObject: function (o, optMessage) {
178
+ return Object(ES.CheckObjectCoercible(o, optMessage));
179
+ },
180
+
181
+ IsCallable: function (x) {
182
+ return typeof x === 'function' &&
183
+ // some versions of IE say that typeof /abc/ === 'function'
184
+ _toString.call(x) === '[object Function]';
185
+ },
186
+
187
+ ToInt32: function (x) {
188
+ return x >> 0;
189
+ },
190
+
191
+ ToUint32: function (x) {
192
+ return x >>> 0;
193
+ },
194
+
195
+ ToInteger: function (value) {
196
+ var number = +value;
197
+ if (Number.isNaN(number)) return 0;
198
+ if (number === 0 || !Number.isFinite(number)) return number;
199
+ return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
200
+ },
201
+
202
+ ToLength: function (value) {
203
+ var len = ES.ToInteger(value);
204
+ if (len <= 0) return 0; // includes converting -0 to +0
205
+ if (len > Number.MAX_SAFE_INTEGER) return Number.MAX_SAFE_INTEGER;
206
+ return len;
207
+ },
208
+
209
+ SameValue: function (a, b) {
210
+ if (a === b) {
211
+ // 0 === -0, but they are not identical.
212
+ if (a === 0) return 1 / a === 1 / b;
213
+ return true;
214
+ }
215
+ return Number.isNaN(a) && Number.isNaN(b);
216
+ },
217
+
218
+ SameValueZero: function (a, b) {
219
+ // same as SameValue except for SameValueZero(+0, -0) == true
220
+ return (a === b) || (Number.isNaN(a) && Number.isNaN(b));
221
+ },
222
+
223
+ IsIterable: function (o) {
224
+ return ES.TypeIsObject(o) &&
225
+ (o[$iterator$] !== undefined || isArguments(o));
226
+ },
227
+
228
+ GetIterator: function (o) {
229
+ if (isArguments(o)) {
230
+ // special case support for `arguments`
231
+ return new ArrayIterator(o, "value");
232
+ }
233
+ var it = o[$iterator$]();
234
+ if (!ES.TypeIsObject(it)) {
235
+ throw new TypeError('bad iterator');
236
+ }
237
+ return it;
238
+ },
239
+
240
+ IteratorNext: function (it) {
241
+ var result = arguments.length > 1 ? it.next(arguments[1]) : it.next();
242
+ if (!ES.TypeIsObject(result)) {
243
+ throw new TypeError('bad iterator');
244
+ }
245
+ return result;
246
+ },
247
+
248
+ Construct: function (C, args) {
249
+ // CreateFromConstructor
250
+ var obj;
251
+ if (ES.IsCallable(C['@@create'])) {
252
+ obj = C['@@create']();
253
+ } else {
254
+ // OrdinaryCreateFromConstructor
255
+ obj = create(C.prototype || null);
256
+ }
257
+ // Mark that we've used the es6 construct path
258
+ // (see emulateES6construct)
259
+ defineProperties(obj, { _es6construct: true });
260
+ // Call the constructor.
261
+ var result = C.apply(obj, args);
262
+ return ES.TypeIsObject(result) ? result : obj;
263
+ }
264
+ };
265
+
266
+ var numberConversion = (function () {
267
+ // from https://github.com/inexorabletash/polyfill/blob/master/typedarray.js#L176-L266
268
+ // with permission and license, per https://twitter.com/inexorabletash/status/372206509540659200
269
+
270
+ function roundToEven(n) {
271
+ var w = Math.floor(n), f = n - w;
272
+ if (f < 0.5) {
273
+ return w;
274
+ }
275
+ if (f > 0.5) {
276
+ return w + 1;
277
+ }
278
+ return w % 2 ? w + 1 : w;
279
+ }
280
+
281
+ function packIEEE754(v, ebits, fbits) {
282
+ var bias = (1 << (ebits - 1)) - 1,
283
+ s, e, f, ln,
284
+ i, bits, str, bytes;
285
+
286
+ // Compute sign, exponent, fraction
287
+ if (v !== v) {
288
+ // NaN
289
+ // http://dev.w3.org/2006/webapi/WebIDL/#es-type-mapping
290
+ e = (1 << ebits) - 1;
291
+ f = Math.pow(2, fbits - 1);
292
+ s = 0;
293
+ } else if (v === Infinity || v === -Infinity) {
294
+ e = (1 << ebits) - 1;
295
+ f = 0;
296
+ s = (v < 0) ? 1 : 0;
297
+ } else if (v === 0) {
298
+ e = 0;
299
+ f = 0;
300
+ s = (1 / v === -Infinity) ? 1 : 0;
301
+ } else {
302
+ s = v < 0;
303
+ v = Math.abs(v);
304
+
305
+ if (v >= Math.pow(2, 1 - bias)) {
306
+ e = Math.min(Math.floor(Math.log(v) / Math.LN2), 1023);
307
+ f = roundToEven(v / Math.pow(2, e) * Math.pow(2, fbits));
308
+ if (f / Math.pow(2, fbits) >= 2) {
309
+ e = e + 1;
310
+ f = 1;
311
+ }
312
+ if (e > bias) {
313
+ // Overflow
314
+ e = (1 << ebits) - 1;
315
+ f = 0;
316
+ } else {
317
+ // Normal
318
+ e = e + bias;
319
+ f = f - Math.pow(2, fbits);
320
+ }
321
+ } else {
322
+ // Subnormal
323
+ e = 0;
324
+ f = roundToEven(v / Math.pow(2, 1 - bias - fbits));
325
+ }
326
+ }
327
+
328
+ // Pack sign, exponent, fraction
329
+ bits = [];
330
+ for (i = fbits; i; i -= 1) {
331
+ bits.push(f % 2 ? 1 : 0);
332
+ f = Math.floor(f / 2);
333
+ }
334
+ for (i = ebits; i; i -= 1) {
335
+ bits.push(e % 2 ? 1 : 0);
336
+ e = Math.floor(e / 2);
337
+ }
338
+ bits.push(s ? 1 : 0);
339
+ bits.reverse();
340
+ str = bits.join('');
341
+
342
+ // Bits to bytes
343
+ bytes = [];
344
+ while (str.length) {
345
+ bytes.push(parseInt(str.slice(0, 8), 2));
346
+ str = str.slice(8);
347
+ }
348
+ return bytes;
349
+ }
350
+
351
+ function unpackIEEE754(bytes, ebits, fbits) {
352
+ // Bytes to bits
353
+ var bits = [], i, j, b, str,
354
+ bias, s, e, f;
355
+
356
+ for (i = bytes.length; i; i -= 1) {
357
+ b = bytes[i - 1];
358
+ for (j = 8; j; j -= 1) {
359
+ bits.push(b % 2 ? 1 : 0);
360
+ b = b >> 1;
361
+ }
362
+ }
363
+ bits.reverse();
364
+ str = bits.join('');
365
+
366
+ // Unpack sign, exponent, fraction
367
+ bias = (1 << (ebits - 1)) - 1;
368
+ s = parseInt(str.slice(0, 1), 2) ? -1 : 1;
369
+ e = parseInt(str.slice(1, 1 + ebits), 2);
370
+ f = parseInt(str.slice(1 + ebits), 2);
371
+
372
+ // Produce number
373
+ if (e === (1 << ebits) - 1) {
374
+ return f !== 0 ? NaN : s * Infinity;
375
+ } else if (e > 0) {
376
+ // Normalized
377
+ return s * Math.pow(2, e - bias) * (1 + f / Math.pow(2, fbits));
378
+ } else if (f !== 0) {
379
+ // Denormalized
380
+ return s * Math.pow(2, -(bias - 1)) * (f / Math.pow(2, fbits));
381
+ } else {
382
+ return s < 0 ? -0 : 0;
383
+ }
384
+ }
385
+
386
+ function unpackFloat64(b) { return unpackIEEE754(b, 11, 52); }
387
+ function packFloat64(v) { return packIEEE754(v, 11, 52); }
388
+ function unpackFloat32(b) { return unpackIEEE754(b, 8, 23); }
389
+ function packFloat32(v) { return packIEEE754(v, 8, 23); }
390
+
391
+ var conversions = {
392
+ toFloat32: function (num) { return unpackFloat32(packFloat32(num)); }
393
+ };
394
+ if (typeof Float32Array !== 'undefined') {
395
+ var float32array = new Float32Array(1);
396
+ conversions.toFloat32 = function (num) {
397
+ float32array[0] = num;
398
+ return float32array[0];
399
+ };
400
+ }
401
+ return conversions;
402
+ }());
403
+
404
+ defineProperties(String, {
405
+ fromCodePoint: function (_) { // length = 1
406
+ var points = _slice.call(arguments, 0, arguments.length);
407
+ var result = [];
408
+ var next;
409
+ for (var i = 0, length = points.length; i < length; i++) {
410
+ next = Number(points[i]);
411
+ if (!ES.SameValue(next, ES.ToInteger(next)) ||
412
+ next < 0 || next > 0x10FFFF) {
413
+ throw new RangeError('Invalid code point ' + next);
414
+ }
415
+
416
+ if (next < 0x10000) {
417
+ result.push(String.fromCharCode(next));
418
+ } else {
419
+ next -= 0x10000;
420
+ result.push(String.fromCharCode((next >> 10) + 0xD800));
421
+ result.push(String.fromCharCode((next % 0x400) + 0xDC00));
422
+ }
423
+ }
424
+ return result.join('');
425
+ },
426
+
427
+ raw: function (callSite) { // raw.length===1
428
+ var substitutions = _slice.call(arguments, 1, arguments.length);
429
+ var cooked = ES.ToObject(callSite, 'bad callSite');
430
+ var rawValue = cooked.raw;
431
+ var raw = ES.ToObject(rawValue, 'bad raw value');
432
+ var len = Object.keys(raw).length;
433
+ var literalsegments = ES.ToLength(len);
434
+ if (literalsegments === 0) {
435
+ return '';
436
+ }
437
+
438
+ var stringElements = [];
439
+ var nextIndex = 0;
440
+ var nextKey, next, nextSeg, nextSub;
441
+ while (nextIndex < literalsegments) {
442
+ nextKey = String(nextIndex);
443
+ next = raw[nextKey];
444
+ nextSeg = String(next);
445
+ stringElements.push(nextSeg);
446
+ if (nextIndex + 1 >= literalsegments) {
447
+ break;
448
+ }
449
+ next = substitutions[nextKey];
450
+ if (next === undefined) {
451
+ break;
452
+ }
453
+ nextSub = String(next);
454
+ stringElements.push(nextSub);
455
+ nextIndex++;
456
+ }
457
+ return stringElements.join('');
458
+ }
459
+ });
460
+
461
+ // Firefox 31 reports this function's length as 0
462
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1062484
463
+ if (String.fromCodePoint.length !== 1) {
464
+ var originalFromCodePoint = String.fromCodePoint;
465
+ defineProperty(String, 'fromCodePoint', function (_) { return originalFromCodePoint.apply(this, arguments); }, true);
466
+ }
467
+
468
+ var StringShims = {
469
+ // Fast repeat, uses the `Exponentiation by squaring` algorithm.
470
+ // Perf: http://jsperf.com/string-repeat2/2
471
+ repeat: (function () {
472
+ var repeat = function (s, times) {
473
+ if (times < 1) return '';
474
+ if (times % 2) return repeat(s, times - 1) + s;
475
+ var half = repeat(s, times / 2);
476
+ return half + half;
477
+ };
478
+
479
+ return function (times) {
480
+ var thisStr = String(ES.CheckObjectCoercible(this));
481
+ times = ES.ToInteger(times);
482
+ if (times < 0 || times === Infinity) {
483
+ throw new RangeError('Invalid String#repeat value');
484
+ }
485
+ return repeat(thisStr, times);
486
+ };
487
+ })(),
488
+
489
+ startsWith: function (searchStr) {
490
+ var thisStr = String(ES.CheckObjectCoercible(this));
491
+ if (_toString.call(searchStr) === '[object RegExp]') throw new TypeError('Cannot call method "startsWith" with a regex');
492
+ searchStr = String(searchStr);
493
+ var startArg = arguments.length > 1 ? arguments[1] : undefined;
494
+ var start = Math.max(ES.ToInteger(startArg), 0);
495
+ return thisStr.slice(start, start + searchStr.length) === searchStr;
496
+ },
497
+
498
+ endsWith: function (searchStr) {
499
+ var thisStr = String(ES.CheckObjectCoercible(this));
500
+ if (_toString.call(searchStr) === '[object RegExp]') throw new TypeError('Cannot call method "endsWith" with a regex');
501
+ searchStr = String(searchStr);
502
+ var thisLen = thisStr.length;
503
+ var posArg = arguments.length > 1 ? arguments[1] : undefined;
504
+ var pos = posArg === undefined ? thisLen : ES.ToInteger(posArg);
505
+ var end = Math.min(Math.max(pos, 0), thisLen);
506
+ return thisStr.slice(end - searchStr.length, end) === searchStr;
507
+ },
508
+
509
+ contains: function (searchString) {
510
+ var position = arguments.length > 1 ? arguments[1] : undefined;
511
+ // Somehow this trick makes method 100% compat with the spec.
512
+ return _indexOf.call(this, searchString, position) !== -1;
513
+ },
514
+
515
+ codePointAt: function (pos) {
516
+ var thisStr = String(ES.CheckObjectCoercible(this));
517
+ var position = ES.ToInteger(pos);
518
+ var length = thisStr.length;
519
+ if (position < 0 || position >= length) return undefined;
520
+ var first = thisStr.charCodeAt(position);
521
+ var isEnd = (position + 1 === length);
522
+ if (first < 0xD800 || first > 0xDBFF || isEnd) return first;
523
+ var second = thisStr.charCodeAt(position + 1);
524
+ if (second < 0xDC00 || second > 0xDFFF) return first;
525
+ return ((first - 0xD800) * 1024) + (second - 0xDC00) + 0x10000;
526
+ }
527
+ };
528
+ defineProperties(String.prototype, StringShims);
529
+
530
+ var hasStringTrimBug = '\u0085'.trim().length !== 1;
531
+ if (hasStringTrimBug) {
532
+ var originalStringTrim = String.prototype.trim;
533
+ delete String.prototype.trim;
534
+ // whitespace from: http://es5.github.io/#x15.5.4.20
535
+ // implementation from https://github.com/es-shims/es5-shim/blob/v3.4.0/es5-shim.js#L1304-L1324
536
+ var ws = [
537
+ '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003',
538
+ '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028',
539
+ '\u2029\uFEFF'
540
+ ].join('');
541
+ var trimRegexp = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g');
542
+ defineProperties(String.prototype, {
543
+ trim: function () {
544
+ if (this === undefined || this === null) {
545
+ throw new TypeError("can't convert " + this + " to object");
546
+ }
547
+ return String(this).replace(trimRegexp, "");
548
+ }
549
+ });
550
+ }
551
+
552
+ // see https://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype-@@iterator
553
+ var StringIterator = function (s) {
554
+ this._s = String(ES.CheckObjectCoercible(s));
555
+ this._i = 0;
556
+ };
557
+ StringIterator.prototype.next = function () {
558
+ var s = this._s, i = this._i;
559
+ if (s === undefined || i >= s.length) {
560
+ this._s = undefined;
561
+ return { value: undefined, done: true };
562
+ }
563
+ var first = s.charCodeAt(i), second, len;
564
+ if (first < 0xD800 || first > 0xDBFF || (i + 1) == s.length) {
565
+ len = 1;
566
+ } else {
567
+ second = s.charCodeAt(i + 1);
568
+ len = (second < 0xDC00 || second > 0xDFFF) ? 1 : 2;
569
+ }
570
+ this._i = i + len;
571
+ return { value: s.substr(i, len), done: false };
572
+ };
573
+ addIterator(StringIterator.prototype);
574
+ addIterator(String.prototype, function () {
575
+ return new StringIterator(this);
576
+ });
577
+
578
+ if (!startsWithIsCompliant) {
579
+ // Firefox has a noncompliant startsWith implementation
580
+ String.prototype.startsWith = StringShims.startsWith;
581
+ String.prototype.endsWith = StringShims.endsWith;
582
+ }
583
+
584
+ var ArrayShims = {
585
+ from: function (iterable) {
586
+ var mapFn = arguments.length > 1 ? arguments[1] : undefined;
587
+
588
+ var list = ES.ToObject(iterable, 'bad iterable');
589
+ if (mapFn !== undefined && !ES.IsCallable(mapFn)) {
590
+ throw new TypeError('Array.from: when provided, the second argument must be a function');
591
+ }
592
+
593
+ var hasThisArg = arguments.length > 2;
594
+ var thisArg = hasThisArg ? arguments[2] : undefined;
595
+
596
+ var usingIterator = ES.IsIterable(list);
597
+ // does the spec really mean that Arrays should use ArrayIterator?
598
+ // https://bugs.ecmascript.org/show_bug.cgi?id=2416
599
+ //if (Array.isArray(list)) { usingIterator=false; }
600
+
601
+ var length;
602
+ var result, i, value;
603
+ if (usingIterator) {
604
+ i = 0;
605
+ result = ES.IsCallable(this) ? Object(new this()) : [];
606
+ var it = usingIterator ? ES.GetIterator(list) : null;
607
+ var iterationValue;
608
+
609
+ do {
610
+ iterationValue = ES.IteratorNext(it);
611
+ if (!iterationValue.done) {
612
+ value = iterationValue.value;
613
+ if (mapFn) {
614
+ result[i] = hasThisArg ? mapFn.call(thisArg, value, i) : mapFn(value, i);
615
+ } else {
616
+ result[i] = value;
617
+ }
618
+ i += 1;
619
+ }
620
+ } while (!iterationValue.done);
621
+ length = i;
622
+ } else {
623
+ length = ES.ToLength(list.length);
624
+ result = ES.IsCallable(this) ? Object(new this(length)) : new Array(length);
625
+ for (i = 0; i < length; ++i) {
626
+ value = list[i];
627
+ if (mapFn) {
628
+ result[i] = hasThisArg ? mapFn.call(thisArg, value, i) : mapFn(value, i);
629
+ } else {
630
+ result[i] = value;
631
+ }
632
+ }
633
+ }
634
+
635
+ result.length = length;
636
+ return result;
637
+ },
638
+
639
+ of: function () {
640
+ return Array.from(arguments);
641
+ }
642
+ };
643
+ defineProperties(Array, ArrayShims);
644
+
645
+ var arrayFromSwallowsNegativeLengths = function () {
646
+ try {
647
+ return Array.from({ length: -1 }).length === 0;
648
+ } catch (e) {
649
+ return false;
650
+ }
651
+ };
652
+ // Fixes a Firefox bug in v32
653
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1063993
654
+ if (!arrayFromSwallowsNegativeLengths()) {
655
+ defineProperty(Array, 'from', ArrayShims.from, true);
656
+ }
657
+
658
+ // Our ArrayIterator is private; see
659
+ // https://github.com/paulmillr/es6-shim/issues/252
660
+ ArrayIterator = function (array, kind) {
661
+ this.i = 0;
662
+ this.array = array;
663
+ this.kind = kind;
664
+ };
665
+
666
+ defineProperties(ArrayIterator.prototype, {
667
+ next: function () {
668
+ var i = this.i, array = this.array;
669
+ if (!(this instanceof ArrayIterator)) {
670
+ throw new TypeError('Not an ArrayIterator');
671
+ }
672
+ if (array !== undefined) {
673
+ var len = ES.ToLength(array.length);
674
+ for (; i < len; i++) {
675
+ var kind = this.kind;
676
+ var retval;
677
+ if (kind === "key") {
678
+ retval = i;
679
+ } else if (kind === "value") {
680
+ retval = array[i];
681
+ } else if (kind === "entry") {
682
+ retval = [i, array[i]];
683
+ }
684
+ this.i = i + 1;
685
+ return { value: retval, done: false };
686
+ }
687
+ }
688
+ this.array = undefined;
689
+ return { value: undefined, done: true };
690
+ }
691
+ });
692
+ addIterator(ArrayIterator.prototype);
693
+
694
+ var ArrayPrototypeShims = {
695
+ copyWithin: function (target, start) {
696
+ var end = arguments[2]; // copyWithin.length must be 2
697
+ var o = ES.ToObject(this);
698
+ var len = ES.ToLength(o.length);
699
+ target = ES.ToInteger(target);
700
+ start = ES.ToInteger(start);
701
+ var to = target < 0 ? Math.max(len + target, 0) : Math.min(target, len);
702
+ var from = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
703
+ end = end === undefined ? len : ES.ToInteger(end);
704
+ var fin = end < 0 ? Math.max(len + end, 0) : Math.min(end, len);
705
+ var count = Math.min(fin - from, len - to);
706
+ var direction = 1;
707
+ if (from < to && to < (from + count)) {
708
+ direction = -1;
709
+ from += count - 1;
710
+ to += count - 1;
711
+ }
712
+ while (count > 0) {
713
+ if (_hasOwnProperty.call(o, from)) {
714
+ o[to] = o[from];
715
+ } else {
716
+ delete o[from];
717
+ }
718
+ from += direction;
719
+ to += direction;
720
+ count -= 1;
721
+ }
722
+ return o;
723
+ },
724
+
725
+ fill: function (value) {
726
+ var start = arguments.length > 1 ? arguments[1] : undefined;
727
+ var end = arguments.length > 2 ? arguments[2] : undefined;
728
+ var O = ES.ToObject(this);
729
+ var len = ES.ToLength(O.length);
730
+ start = ES.ToInteger(start === undefined ? 0 : start);
731
+ end = ES.ToInteger(end === undefined ? len : end);
732
+
733
+ var relativeStart = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
734
+ var relativeEnd = end < 0 ? len + end : end;
735
+
736
+ for (var i = relativeStart; i < len && i < relativeEnd; ++i) {
737
+ O[i] = value;
738
+ }
739
+ return O;
740
+ },
741
+
742
+ find: function find(predicate) {
743
+ var list = ES.ToObject(this);
744
+ var length = ES.ToLength(list.length);
745
+ if (!ES.IsCallable(predicate)) {
746
+ throw new TypeError('Array#find: predicate must be a function');
747
+ }
748
+ var thisArg = arguments[1];
749
+ for (var i = 0, value; i < length; i++) {
750
+ value = list[i];
751
+ if (predicate.call(thisArg, value, i, list)) { return value; }
752
+ }
753
+ return undefined;
754
+ },
755
+
756
+ findIndex: function findIndex(predicate) {
757
+ var list = ES.ToObject(this);
758
+ var length = ES.ToLength(list.length);
759
+ if (!ES.IsCallable(predicate)) {
760
+ throw new TypeError('Array#findIndex: predicate must be a function');
761
+ }
762
+ var thisArg = arguments[1];
763
+ for (var i = 0; i < length; i++) {
764
+ if (predicate.call(thisArg, list[i], i, list)) { return i; }
765
+ }
766
+ return -1;
767
+ },
768
+
769
+ keys: function () {
770
+ return new ArrayIterator(this, "key");
771
+ },
772
+
773
+ values: function () {
774
+ return new ArrayIterator(this, "value");
775
+ },
776
+
777
+ entries: function () {
778
+ return new ArrayIterator(this, "entry");
779
+ }
780
+ };
781
+ // Safari 7.1 defines Array#keys and Array#entries natively,
782
+ // but the resulting ArrayIterator objects don't have a "next" method.
783
+ if (Array.prototype.keys && !ES.IsCallable([1].keys().next)) {
784
+ delete Array.prototype.keys;
785
+ }
786
+ if (Array.prototype.entries && !ES.IsCallable([1].entries().next)) {
787
+ delete Array.prototype.entries;
788
+ }
789
+ defineProperties(Array.prototype, ArrayPrototypeShims);
790
+
791
+ addIterator(Array.prototype, function () { return this.values(); });
792
+ // Chrome defines keys/values/entries on Array, but doesn't give us
793
+ // any way to identify its iterator. So add our own shimmed field.
794
+ if (Object.getPrototypeOf) {
795
+ addIterator(Object.getPrototypeOf([].values()));
796
+ }
797
+
798
+ var maxSafeInteger = Math.pow(2, 53) - 1;
799
+ defineProperties(Number, {
800
+ MAX_SAFE_INTEGER: maxSafeInteger,
801
+ MIN_SAFE_INTEGER: -maxSafeInteger,
802
+ EPSILON: 2.220446049250313e-16,
803
+
804
+ parseInt: globals.parseInt,
805
+ parseFloat: globals.parseFloat,
806
+
807
+ isFinite: function (value) {
808
+ return typeof value === 'number' && global_isFinite(value);
809
+ },
810
+
811
+ isInteger: function (value) {
812
+ return Number.isFinite(value) &&
813
+ ES.ToInteger(value) === value;
814
+ },
815
+
816
+ isSafeInteger: function (value) {
817
+ return Number.isInteger(value) && Math.abs(value) <= Number.MAX_SAFE_INTEGER;
818
+ },
819
+
820
+ isNaN: function (value) {
821
+ // NaN !== NaN, but they are identical.
822
+ // NaNs are the only non-reflexive value, i.e., if x !== x,
823
+ // then x is NaN.
824
+ // isNaN is broken: it converts its argument to number, so
825
+ // isNaN('foo') => true
826
+ return value !== value;
827
+ }
828
+
829
+ });
830
+
831
+ // Work around bugs in Array#find and Array#findIndex -- early
832
+ // implementations skipped holes in sparse arrays. (Note that the
833
+ // implementations of find/findIndex indirectly use shimmed
834
+ // methods of Number, so this test has to happen down here.)
835
+ if (![, 1].find(function (item, idx) { return idx === 0; })) {
836
+ defineProperty(Array.prototype, 'find', ArrayPrototypeShims.find, true);
837
+ }
838
+ if ([, 1].findIndex(function (item, idx) { return idx === 0; }) !== 0) {
839
+ defineProperty(Array.prototype, 'findIndex', ArrayPrototypeShims.findIndex, true);
840
+ }
841
+
842
+ if (supportsDescriptors) {
843
+ defineProperties(Object, {
844
+ getPropertyDescriptor: function (subject, name) {
845
+ var pd = Object.getOwnPropertyDescriptor(subject, name);
846
+ var proto = Object.getPrototypeOf(subject);
847
+ while (pd === undefined && proto !== null) {
848
+ pd = Object.getOwnPropertyDescriptor(proto, name);
849
+ proto = Object.getPrototypeOf(proto);
850
+ }
851
+ return pd;
852
+ },
853
+
854
+ getPropertyNames: function (subject) {
855
+ var result = Object.getOwnPropertyNames(subject);
856
+ var proto = Object.getPrototypeOf(subject);
857
+
858
+ var addProperty = function (property) {
859
+ if (result.indexOf(property) === -1) {
860
+ result.push(property);
861
+ }
862
+ };
863
+
864
+ while (proto !== null) {
865
+ Object.getOwnPropertyNames(proto).forEach(addProperty);
866
+ proto = Object.getPrototypeOf(proto);
867
+ }
868
+ return result;
869
+ }
870
+ });
871
+
872
+ defineProperties(Object, {
873
+ // 19.1.3.1
874
+ assign: function (target, source) {
875
+ if (!ES.TypeIsObject(target)) {
876
+ throw new TypeError('target must be an object');
877
+ }
878
+ return Array.prototype.reduce.call(arguments, function (target, source) {
879
+ return Object.keys(Object(source)).reduce(function (target, key) {
880
+ target[key] = source[key];
881
+ return target;
882
+ }, target);
883
+ });
884
+ },
885
+
886
+ is: function (a, b) {
887
+ return ES.SameValue(a, b);
888
+ },
889
+
890
+ // 19.1.3.9
891
+ // shim from https://gist.github.com/WebReflection/5593554
892
+ setPrototypeOf: (function (Object, magic) {
893
+ var set;
894
+
895
+ var checkArgs = function (O, proto) {
896
+ if (!ES.TypeIsObject(O)) {
897
+ throw new TypeError('cannot set prototype on a non-object');
898
+ }
899
+ if (!(proto === null || ES.TypeIsObject(proto))) {
900
+ throw new TypeError('can only set prototype to an object or null' + proto);
901
+ }
902
+ };
903
+
904
+ var setPrototypeOf = function (O, proto) {
905
+ checkArgs(O, proto);
906
+ set.call(O, proto);
907
+ return O;
908
+ };
909
+
910
+ try {
911
+ // this works already in Firefox and Safari
912
+ set = Object.getOwnPropertyDescriptor(Object.prototype, magic).set;
913
+ set.call({}, null);
914
+ } catch (e) {
915
+ if (Object.prototype !== {}[magic]) {
916
+ // IE < 11 cannot be shimmed
917
+ return;
918
+ }
919
+ // probably Chrome or some old Mobile stock browser
920
+ set = function (proto) {
921
+ this[magic] = proto;
922
+ };
923
+ // please note that this will **not** work
924
+ // in those browsers that do not inherit
925
+ // __proto__ by mistake from Object.prototype
926
+ // in these cases we should probably throw an error
927
+ // or at least be informed about the issue
928
+ setPrototypeOf.polyfill = setPrototypeOf(
929
+ setPrototypeOf({}, null),
930
+ Object.prototype
931
+ ) instanceof Object;
932
+ // setPrototypeOf.polyfill === true means it works as meant
933
+ // setPrototypeOf.polyfill === false means it's not 100% reliable
934
+ // setPrototypeOf.polyfill === undefined
935
+ // or
936
+ // setPrototypeOf.polyfill == null means it's not a polyfill
937
+ // which means it works as expected
938
+ // we can even delete Object.prototype.__proto__;
939
+ }
940
+ return setPrototypeOf;
941
+ })(Object, '__proto__')
942
+ });
943
+ }
944
+
945
+ // Workaround bug in Opera 12 where setPrototypeOf(x, null) doesn't work,
946
+ // but Object.create(null) does.
947
+ if (Object.setPrototypeOf && Object.getPrototypeOf &&
948
+ Object.getPrototypeOf(Object.setPrototypeOf({}, null)) !== null &&
949
+ Object.getPrototypeOf(Object.create(null)) === null) {
950
+ (function () {
951
+ var FAKENULL = Object.create(null);
952
+ var gpo = Object.getPrototypeOf, spo = Object.setPrototypeOf;
953
+ Object.getPrototypeOf = function (o) {
954
+ var result = gpo(o);
955
+ return result === FAKENULL ? null : result;
956
+ };
957
+ Object.setPrototypeOf = function (o, p) {
958
+ if (p === null) { p = FAKENULL; }
959
+ return spo(o, p);
960
+ };
961
+ Object.setPrototypeOf.polyfill = false;
962
+ })();
963
+ }
964
+
965
+ try {
966
+ Object.keys('foo');
967
+ } catch (e) {
968
+ var originalObjectKeys = Object.keys;
969
+ Object.keys = function (obj) {
970
+ return originalObjectKeys(ES.ToObject(obj));
971
+ };
972
+ }
973
+
974
+ var MathShims = {
975
+ acosh: function (value) {
976
+ value = Number(value);
977
+ if (Number.isNaN(value) || value < 1) return NaN;
978
+ if (value === 1) return 0;
979
+ if (value === Infinity) return value;
980
+ return Math.log(value + Math.sqrt(value * value - 1));
981
+ },
982
+
983
+ asinh: function (value) {
984
+ value = Number(value);
985
+ if (value === 0 || !global_isFinite(value)) {
986
+ return value;
987
+ }
988
+ return value < 0 ? -Math.asinh(-value) : Math.log(value + Math.sqrt(value * value + 1));
989
+ },
990
+
991
+ atanh: function (value) {
992
+ value = Number(value);
993
+ if (Number.isNaN(value) || value < -1 || value > 1) {
994
+ return NaN;
995
+ }
996
+ if (value === -1) return -Infinity;
997
+ if (value === 1) return Infinity;
998
+ if (value === 0) return value;
999
+ return 0.5 * Math.log((1 + value) / (1 - value));
1000
+ },
1001
+
1002
+ cbrt: function (value) {
1003
+ value = Number(value);
1004
+ if (value === 0) return value;
1005
+ var negate = value < 0, result;
1006
+ if (negate) value = -value;
1007
+ result = Math.pow(value, 1 / 3);
1008
+ return negate ? -result : result;
1009
+ },
1010
+
1011
+ clz32: function (value) {
1012
+ // See https://bugs.ecmascript.org/show_bug.cgi?id=2465
1013
+ value = Number(value);
1014
+ var number = ES.ToUint32(value);
1015
+ if (number === 0) {
1016
+ return 32;
1017
+ }
1018
+ return 32 - (number).toString(2).length;
1019
+ },
1020
+
1021
+ cosh: function (value) {
1022
+ value = Number(value);
1023
+ if (value === 0) return 1; // +0 or -0
1024
+ if (Number.isNaN(value)) return NaN;
1025
+ if (!global_isFinite(value)) return Infinity;
1026
+ if (value < 0) value = -value;
1027
+ if (value > 21) return Math.exp(value) / 2;
1028
+ return (Math.exp(value) + Math.exp(-value)) / 2;
1029
+ },
1030
+
1031
+ expm1: function (value) {
1032
+ value = Number(value);
1033
+ if (value === -Infinity) return -1;
1034
+ if (!global_isFinite(value) || value === 0) return value;
1035
+ return Math.exp(value) - 1;
1036
+ },
1037
+
1038
+ hypot: function (x, y) {
1039
+ var anyNaN = false;
1040
+ var allZero = true;
1041
+ var anyInfinity = false;
1042
+ var numbers = [];
1043
+ Array.prototype.every.call(arguments, function (arg) {
1044
+ var num = Number(arg);
1045
+ if (Number.isNaN(num)) {
1046
+ anyNaN = true;
1047
+ } else if (num === Infinity || num === -Infinity) {
1048
+ anyInfinity = true;
1049
+ } else if (num !== 0) {
1050
+ allZero = false;
1051
+ }
1052
+ if (anyInfinity) {
1053
+ return false;
1054
+ } else if (!anyNaN) {
1055
+ numbers.push(Math.abs(num));
1056
+ }
1057
+ return true;
1058
+ });
1059
+ if (anyInfinity) return Infinity;
1060
+ if (anyNaN) return NaN;
1061
+ if (allZero) return 0;
1062
+
1063
+ numbers.sort(function (a, b) { return b - a; });
1064
+ var largest = numbers[0];
1065
+ var divided = numbers.map(function (number) { return number / largest; });
1066
+ var sum = divided.reduce(function (sum, number) { return sum += number * number; }, 0);
1067
+ return largest * Math.sqrt(sum);
1068
+ },
1069
+
1070
+ log2: function (value) {
1071
+ return Math.log(value) * Math.LOG2E;
1072
+ },
1073
+
1074
+ log10: function (value) {
1075
+ return Math.log(value) * Math.LOG10E;
1076
+ },
1077
+
1078
+ log1p: function (value) {
1079
+ value = Number(value);
1080
+ if (value < -1 || Number.isNaN(value)) return NaN;
1081
+ if (value === 0 || value === Infinity) return value;
1082
+ if (value === -1) return -Infinity;
1083
+ var result = 0;
1084
+ var n = 50;
1085
+
1086
+ if (value < 0 || value > 1) return Math.log(1 + value);
1087
+ for (var i = 1; i < n; i++) {
1088
+ if ((i % 2) === 0) {
1089
+ result -= Math.pow(value, i) / i;
1090
+ } else {
1091
+ result += Math.pow(value, i) / i;
1092
+ }
1093
+ }
1094
+
1095
+ return result;
1096
+ },
1097
+
1098
+ sign: function (value) {
1099
+ var number = +value;
1100
+ if (number === 0) return number;
1101
+ if (Number.isNaN(number)) return number;
1102
+ return number < 0 ? -1 : 1;
1103
+ },
1104
+
1105
+ sinh: function (value) {
1106
+ value = Number(value);
1107
+ if (!global_isFinite(value) || value === 0) return value;
1108
+ return (Math.exp(value) - Math.exp(-value)) / 2;
1109
+ },
1110
+
1111
+ tanh: function (value) {
1112
+ value = Number(value);
1113
+ if (Number.isNaN(value) || value === 0) return value;
1114
+ if (value === Infinity) return 1;
1115
+ if (value === -Infinity) return -1;
1116
+ return (Math.exp(value) - Math.exp(-value)) / (Math.exp(value) + Math.exp(-value));
1117
+ },
1118
+
1119
+ trunc: function (value) {
1120
+ var number = Number(value);
1121
+ return number < 0 ? -Math.floor(-number) : Math.floor(number);
1122
+ },
1123
+
1124
+ imul: function (x, y) {
1125
+ // taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
1126
+ x = ES.ToUint32(x);
1127
+ y = ES.ToUint32(y);
1128
+ var ah = (x >>> 16) & 0xffff;
1129
+ var al = x & 0xffff;
1130
+ var bh = (y >>> 16) & 0xffff;
1131
+ var bl = y & 0xffff;
1132
+ // the shift by 0 fixes the sign on the high part
1133
+ // the final |0 converts the unsigned value into a signed value
1134
+ return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0);
1135
+ },
1136
+
1137
+ fround: function (x) {
1138
+ if (x === 0 || x === Infinity || x === -Infinity || Number.isNaN(x)) {
1139
+ return x;
1140
+ }
1141
+ var num = Number(x);
1142
+ return numberConversion.toFloat32(num);
1143
+ }
1144
+ };
1145
+ defineProperties(Math, MathShims);
1146
+
1147
+ if (Math.imul(0xffffffff, 5) !== -5) {
1148
+ // Safari 6.1, at least, reports "0" for this value
1149
+ Math.imul = MathShims.imul;
1150
+ }
1151
+
1152
+ // Promises
1153
+ // Simplest possible implementation; use a 3rd-party library if you
1154
+ // want the best possible speed and/or long stack traces.
1155
+ var PromiseShim = (function () {
1156
+
1157
+ var Promise, Promise$prototype;
1158
+
1159
+ ES.IsPromise = function (promise) {
1160
+ if (!ES.TypeIsObject(promise)) {
1161
+ return false;
1162
+ }
1163
+ if (!promise._promiseConstructor) {
1164
+ // _promiseConstructor is a bit more unique than _status, so we'll
1165
+ // check that instead of the [[PromiseStatus]] internal field.
1166
+ return false;
1167
+ }
1168
+ if (promise._status === undefined) {
1169
+ return false; // uninitialized
1170
+ }
1171
+ return true;
1172
+ };
1173
+
1174
+ // "PromiseCapability" in the spec is what most promise implementations
1175
+ // call a "deferred".
1176
+ var PromiseCapability = function (C) {
1177
+ if (!ES.IsCallable(C)) {
1178
+ throw new TypeError('bad promise constructor');
1179
+ }
1180
+ var capability = this;
1181
+ var resolver = function (resolve, reject) {
1182
+ capability.resolve = resolve;
1183
+ capability.reject = reject;
1184
+ };
1185
+ capability.promise = ES.Construct(C, [resolver]);
1186
+ // see https://bugs.ecmascript.org/show_bug.cgi?id=2478
1187
+ if (!capability.promise._es6construct) {
1188
+ throw new TypeError('bad promise constructor');
1189
+ }
1190
+ if (!(ES.IsCallable(capability.resolve) &&
1191
+ ES.IsCallable(capability.reject))) {
1192
+ throw new TypeError('bad promise constructor');
1193
+ }
1194
+ };
1195
+
1196
+ // find an appropriate setImmediate-alike
1197
+ var setTimeout = globals.setTimeout;
1198
+ var makeZeroTimeout;
1199
+ if (typeof window !== 'undefined' && ES.IsCallable(window.postMessage)) {
1200
+ makeZeroTimeout = function () {
1201
+ // from http://dbaron.org/log/20100309-faster-timeouts
1202
+ var timeouts = [];
1203
+ var messageName = "zero-timeout-message";
1204
+ var setZeroTimeout = function (fn) {
1205
+ timeouts.push(fn);
1206
+ window.postMessage(messageName, "*");
1207
+ };
1208
+ var handleMessage = function (event) {
1209
+ if (event.source == window && event.data == messageName) {
1210
+ event.stopPropagation();
1211
+ if (timeouts.length === 0) { return; }
1212
+ var fn = timeouts.shift();
1213
+ fn();
1214
+ }
1215
+ };
1216
+ window.addEventListener("message", handleMessage, true);
1217
+ return setZeroTimeout;
1218
+ };
1219
+ }
1220
+ var makePromiseAsap = function () {
1221
+ // An efficient task-scheduler based on a pre-existing Promise
1222
+ // implementation, which we can use even if we override the
1223
+ // global Promise below (in order to workaround bugs)
1224
+ // https://github.com/Raynos/observ-hash/issues/2#issuecomment-35857671
1225
+ var P = globals.Promise;
1226
+ return P && P.resolve && function (task) {
1227
+ return P.resolve().then(task);
1228
+ };
1229
+ };
1230
+ var enqueue = ES.IsCallable(globals.setImmediate) ?
1231
+ globals.setImmediate.bind(globals) :
1232
+ typeof process === 'object' && process.nextTick ? process.nextTick :
1233
+ makePromiseAsap() ||
1234
+ (ES.IsCallable(makeZeroTimeout) ? makeZeroTimeout() :
1235
+ function (task) { setTimeout(task, 0); }); // fallback
1236
+
1237
+ var triggerPromiseReactions = function (reactions, x) {
1238
+ reactions.forEach(function (reaction) {
1239
+ enqueue(function () {
1240
+ // PromiseReactionTask
1241
+ var handler = reaction.handler;
1242
+ var capability = reaction.capability;
1243
+ var resolve = capability.resolve;
1244
+ var reject = capability.reject;
1245
+ try {
1246
+ var result = handler(x);
1247
+ if (result === capability.promise) {
1248
+ throw new TypeError('self resolution');
1249
+ }
1250
+ var updateResult =
1251
+ updatePromiseFromPotentialThenable(result, capability);
1252
+ if (!updateResult) {
1253
+ resolve(result);
1254
+ }
1255
+ } catch (e) {
1256
+ reject(e);
1257
+ }
1258
+ });
1259
+ });
1260
+ };
1261
+
1262
+ var updatePromiseFromPotentialThenable = function (x, capability) {
1263
+ if (!ES.TypeIsObject(x)) {
1264
+ return false;
1265
+ }
1266
+ var resolve = capability.resolve;
1267
+ var reject = capability.reject;
1268
+ try {
1269
+ var then = x.then; // only one invocation of accessor
1270
+ if (!ES.IsCallable(then)) { return false; }
1271
+ then.call(x, resolve, reject);
1272
+ } catch (e) {
1273
+ reject(e);
1274
+ }
1275
+ return true;
1276
+ };
1277
+
1278
+ var promiseResolutionHandler = function (promise, onFulfilled, onRejected) {
1279
+ return function (x) {
1280
+ if (x === promise) {
1281
+ return onRejected(new TypeError('self resolution'));
1282
+ }
1283
+ var C = promise._promiseConstructor;
1284
+ var capability = new PromiseCapability(C);
1285
+ var updateResult = updatePromiseFromPotentialThenable(x, capability);
1286
+ if (updateResult) {
1287
+ return capability.promise.then(onFulfilled, onRejected);
1288
+ } else {
1289
+ return onFulfilled(x);
1290
+ }
1291
+ };
1292
+ };
1293
+
1294
+ Promise = function (resolver) {
1295
+ var promise = this;
1296
+ promise = emulateES6construct(promise);
1297
+ if (!promise._promiseConstructor) {
1298
+ // we use _promiseConstructor as a stand-in for the internal
1299
+ // [[PromiseStatus]] field; it's a little more unique.
1300
+ throw new TypeError('bad promise');
1301
+ }
1302
+ if (promise._status !== undefined) {
1303
+ throw new TypeError('promise already initialized');
1304
+ }
1305
+ // see https://bugs.ecmascript.org/show_bug.cgi?id=2482
1306
+ if (!ES.IsCallable(resolver)) {
1307
+ throw new TypeError('not a valid resolver');
1308
+ }
1309
+ promise._status = 'unresolved';
1310
+ promise._resolveReactions = [];
1311
+ promise._rejectReactions = [];
1312
+
1313
+ var resolve = function (resolution) {
1314
+ if (promise._status !== 'unresolved') { return; }
1315
+ var reactions = promise._resolveReactions;
1316
+ promise._result = resolution;
1317
+ promise._resolveReactions = undefined;
1318
+ promise._rejectReactions = undefined;
1319
+ promise._status = 'has-resolution';
1320
+ triggerPromiseReactions(reactions, resolution);
1321
+ };
1322
+ var reject = function (reason) {
1323
+ if (promise._status !== 'unresolved') { return; }
1324
+ var reactions = promise._rejectReactions;
1325
+ promise._result = reason;
1326
+ promise._resolveReactions = undefined;
1327
+ promise._rejectReactions = undefined;
1328
+ promise._status = 'has-rejection';
1329
+ triggerPromiseReactions(reactions, reason);
1330
+ };
1331
+ try {
1332
+ resolver(resolve, reject);
1333
+ } catch (e) {
1334
+ reject(e);
1335
+ }
1336
+ return promise;
1337
+ };
1338
+ Promise$prototype = Promise.prototype;
1339
+ defineProperties(Promise, {
1340
+ '@@create': function (obj) {
1341
+ var constructor = this;
1342
+ // AllocatePromise
1343
+ // The `obj` parameter is a hack we use for es5
1344
+ // compatibility.
1345
+ var prototype = constructor.prototype || Promise$prototype;
1346
+ obj = obj || create(prototype);
1347
+ defineProperties(obj, {
1348
+ _status: undefined,
1349
+ _result: undefined,
1350
+ _resolveReactions: undefined,
1351
+ _rejectReactions: undefined,
1352
+ _promiseConstructor: undefined
1353
+ });
1354
+ obj._promiseConstructor = constructor;
1355
+ return obj;
1356
+ }
1357
+ });
1358
+
1359
+ var _promiseAllResolver = function (index, values, capability, remaining) {
1360
+ var done = false;
1361
+ return function (x) {
1362
+ if (done) { return; } // protect against being called multiple times
1363
+ done = true;
1364
+ values[index] = x;
1365
+ if ((--remaining.count) === 0) {
1366
+ var resolve = capability.resolve;
1367
+ resolve(values); // call w/ this===undefined
1368
+ }
1369
+ };
1370
+ };
1371
+
1372
+ Promise.all = function (iterable) {
1373
+ var C = this;
1374
+ var capability = new PromiseCapability(C);
1375
+ var resolve = capability.resolve;
1376
+ var reject = capability.reject;
1377
+ try {
1378
+ if (!ES.IsIterable(iterable)) {
1379
+ throw new TypeError('bad iterable');
1380
+ }
1381
+ var it = ES.GetIterator(iterable);
1382
+ var values = [], remaining = { count: 1 };
1383
+ for (var index = 0; ; index++) {
1384
+ var next = ES.IteratorNext(it);
1385
+ if (next.done) {
1386
+ break;
1387
+ }
1388
+ var nextPromise = C.resolve(next.value);
1389
+ var resolveElement = _promiseAllResolver(
1390
+ index, values, capability, remaining
1391
+ );
1392
+ remaining.count++;
1393
+ nextPromise.then(resolveElement, capability.reject);
1394
+ }
1395
+ if ((--remaining.count) === 0) {
1396
+ resolve(values); // call w/ this===undefined
1397
+ }
1398
+ } catch (e) {
1399
+ reject(e);
1400
+ }
1401
+ return capability.promise;
1402
+ };
1403
+
1404
+ Promise.race = function (iterable) {
1405
+ var C = this;
1406
+ var capability = new PromiseCapability(C);
1407
+ var resolve = capability.resolve;
1408
+ var reject = capability.reject;
1409
+ try {
1410
+ if (!ES.IsIterable(iterable)) {
1411
+ throw new TypeError('bad iterable');
1412
+ }
1413
+ var it = ES.GetIterator(iterable);
1414
+ while (true) {
1415
+ var next = ES.IteratorNext(it);
1416
+ if (next.done) {
1417
+ // If iterable has no items, resulting promise will never
1418
+ // resolve; see:
1419
+ // https://github.com/domenic/promises-unwrapping/issues/75
1420
+ // https://bugs.ecmascript.org/show_bug.cgi?id=2515
1421
+ break;
1422
+ }
1423
+ var nextPromise = C.resolve(next.value);
1424
+ nextPromise.then(resolve, reject);
1425
+ }
1426
+ } catch (e) {
1427
+ reject(e);
1428
+ }
1429
+ return capability.promise;
1430
+ };
1431
+
1432
+ Promise.reject = function (reason) {
1433
+ var C = this;
1434
+ var capability = new PromiseCapability(C);
1435
+ var reject = capability.reject;
1436
+ reject(reason); // call with this===undefined
1437
+ return capability.promise;
1438
+ };
1439
+
1440
+ Promise.resolve = function (v) {
1441
+ var C = this;
1442
+ if (ES.IsPromise(v)) {
1443
+ var constructor = v._promiseConstructor;
1444
+ if (constructor === C) { return v; }
1445
+ }
1446
+ var capability = new PromiseCapability(C);
1447
+ var resolve = capability.resolve;
1448
+ resolve(v); // call with this===undefined
1449
+ return capability.promise;
1450
+ };
1451
+
1452
+ Promise.prototype['catch'] = function (onRejected) {
1453
+ return this.then(undefined, onRejected);
1454
+ };
1455
+
1456
+ Promise.prototype.then = function (onFulfilled, onRejected) {
1457
+ var promise = this;
1458
+ if (!ES.IsPromise(promise)) { throw new TypeError('not a promise'); }
1459
+ // this.constructor not this._promiseConstructor; see
1460
+ // https://bugs.ecmascript.org/show_bug.cgi?id=2513
1461
+ var C = this.constructor;
1462
+ var capability = new PromiseCapability(C);
1463
+ if (!ES.IsCallable(onRejected)) {
1464
+ onRejected = function (e) { throw e; };
1465
+ }
1466
+ if (!ES.IsCallable(onFulfilled)) {
1467
+ onFulfilled = function (x) { return x; };
1468
+ }
1469
+ var resolutionHandler =
1470
+ promiseResolutionHandler(promise, onFulfilled, onRejected);
1471
+ var resolveReaction =
1472
+ { capability: capability, handler: resolutionHandler };
1473
+ var rejectReaction =
1474
+ { capability: capability, handler: onRejected };
1475
+ switch (promise._status) {
1476
+ case 'unresolved':
1477
+ promise._resolveReactions.push(resolveReaction);
1478
+ promise._rejectReactions.push(rejectReaction);
1479
+ break;
1480
+ case 'has-resolution':
1481
+ triggerPromiseReactions([resolveReaction], promise._result);
1482
+ break;
1483
+ case 'has-rejection':
1484
+ triggerPromiseReactions([rejectReaction], promise._result);
1485
+ break;
1486
+ default:
1487
+ throw new TypeError('unexpected');
1488
+ }
1489
+ return capability.promise;
1490
+ };
1491
+
1492
+ return Promise;
1493
+ })();
1494
+ // export the Promise constructor.
1495
+ defineProperties(globals, { Promise: PromiseShim });
1496
+ // In Chrome 33 (and thereabouts) Promise is defined, but the
1497
+ // implementation is buggy in a number of ways. Let's check subclassing
1498
+ // support to see if we have a buggy implementation.
1499
+ var promiseSupportsSubclassing = supportsSubclassing(globals.Promise, function (S) {
1500
+ return S.resolve(42) instanceof S;
1501
+ });
1502
+ var promiseIgnoresNonFunctionThenCallbacks = (function () {
1503
+ try {
1504
+ globals.Promise.reject(42).then(null, 5).then(null, function () {});
1505
+ return true;
1506
+ } catch (ex) {
1507
+ return false;
1508
+ }
1509
+ }());
1510
+ var promiseRequiresObjectContext = (function () {
1511
+ try { Promise.call(3, function () {}); } catch (e) { return true; }
1512
+ return false;
1513
+ }());
1514
+ if (!promiseSupportsSubclassing || !promiseIgnoresNonFunctionThenCallbacks || !promiseRequiresObjectContext) {
1515
+ globals.Promise = PromiseShim;
1516
+ }
1517
+
1518
+ // Map and Set require a true ES5 environment
1519
+ // Their fast path also requires that the environment preserve
1520
+ // property insertion order, which is not guaranteed by the spec.
1521
+ var testOrder = function(a) {
1522
+ var b = Object.keys(a.reduce(function (o, k) {
1523
+ o[k] = true;
1524
+ return o;
1525
+ }, {}));
1526
+ return a.join(':') === b.join(':');
1527
+ };
1528
+ var preservesInsertionOrder = testOrder(['z', 'a', 'bb']);
1529
+ // some engines (eg, Chrome) only preserve insertion order for string keys
1530
+ var preservesNumericInsertionOrder = testOrder(['z', 1, 'a', '3', 2]);
1531
+
1532
+ if (supportsDescriptors) {
1533
+
1534
+ var fastkey = function fastkey(key) {
1535
+ if (!preservesInsertionOrder) {
1536
+ return null;
1537
+ }
1538
+ var type = typeof key;
1539
+ if (type === 'string') {
1540
+ return '$' + key;
1541
+ } else if (type === 'number') {
1542
+ // note that -0 will get coerced to "0" when used as a property key
1543
+ if (!preservesNumericInsertionOrder) {
1544
+ return 'n' + key;
1545
+ }
1546
+ return key;
1547
+ }
1548
+ return null;
1549
+ };
1550
+
1551
+ var emptyObject = function emptyObject() {
1552
+ // accomodate some older not-quite-ES5 browsers
1553
+ return Object.create ? Object.create(null) : {};
1554
+ };
1555
+
1556
+ var collectionShims = {
1557
+ Map: (function () {
1558
+
1559
+ var empty = {};
1560
+
1561
+ function MapEntry(key, value) {
1562
+ this.key = key;
1563
+ this.value = value;
1564
+ this.next = null;
1565
+ this.prev = null;
1566
+ }
1567
+
1568
+ MapEntry.prototype.isRemoved = function () {
1569
+ return this.key === empty;
1570
+ };
1571
+
1572
+ function MapIterator(map, kind) {
1573
+ this.head = map._head;
1574
+ this.i = this.head;
1575
+ this.kind = kind;
1576
+ }
1577
+
1578
+ MapIterator.prototype = {
1579
+ next: function () {
1580
+ var i = this.i, kind = this.kind, head = this.head, result;
1581
+ if (this.i === undefined) {
1582
+ return { value: undefined, done: true };
1583
+ }
1584
+ while (i.isRemoved() && i !== head) {
1585
+ // back up off of removed entries
1586
+ i = i.prev;
1587
+ }
1588
+ // advance to next unreturned element.
1589
+ while (i.next !== head) {
1590
+ i = i.next;
1591
+ if (!i.isRemoved()) {
1592
+ if (kind === "key") {
1593
+ result = i.key;
1594
+ } else if (kind === "value") {
1595
+ result = i.value;
1596
+ } else {
1597
+ result = [i.key, i.value];
1598
+ }
1599
+ this.i = i;
1600
+ return { value: result, done: false };
1601
+ }
1602
+ }
1603
+ // once the iterator is done, it is done forever.
1604
+ this.i = undefined;
1605
+ return { value: undefined, done: true };
1606
+ }
1607
+ };
1608
+ addIterator(MapIterator.prototype);
1609
+
1610
+ function Map(iterable) {
1611
+ var map = this;
1612
+ map = emulateES6construct(map);
1613
+ if (!map._es6map) {
1614
+ throw new TypeError('bad map');
1615
+ }
1616
+
1617
+ var head = new MapEntry(null, null);
1618
+ // circular doubly-linked list.
1619
+ head.next = head.prev = head;
1620
+
1621
+ defineProperties(map, {
1622
+ _head: head,
1623
+ _storage: emptyObject(),
1624
+ _size: 0
1625
+ });
1626
+
1627
+ // Optionally initialize map from iterable
1628
+ if (iterable !== undefined && iterable !== null) {
1629
+ var it = ES.GetIterator(iterable);
1630
+ var adder = map.set;
1631
+ if (!ES.IsCallable(adder)) { throw new TypeError('bad map'); }
1632
+ while (true) {
1633
+ var next = ES.IteratorNext(it);
1634
+ if (next.done) { break; }
1635
+ var nextItem = next.value;
1636
+ if (!ES.TypeIsObject(nextItem)) {
1637
+ throw new TypeError('expected iterable of pairs');
1638
+ }
1639
+ adder.call(map, nextItem[0], nextItem[1]);
1640
+ }
1641
+ }
1642
+ return map;
1643
+ }
1644
+ var Map$prototype = Map.prototype;
1645
+ defineProperties(Map, {
1646
+ '@@create': function (obj) {
1647
+ var constructor = this;
1648
+ var prototype = constructor.prototype || Map$prototype;
1649
+ obj = obj || create(prototype);
1650
+ defineProperties(obj, { _es6map: true });
1651
+ return obj;
1652
+ }
1653
+ });
1654
+
1655
+ Object.defineProperty(Map.prototype, 'size', {
1656
+ configurable: true,
1657
+ enumerable: false,
1658
+ get: function () {
1659
+ if (typeof this._size === 'undefined') {
1660
+ throw new TypeError('size method called on incompatible Map');
1661
+ }
1662
+ return this._size;
1663
+ }
1664
+ });
1665
+
1666
+ defineProperties(Map.prototype, {
1667
+ get: function (key) {
1668
+ var fkey = fastkey(key);
1669
+ if (fkey !== null) {
1670
+ // fast O(1) path
1671
+ var entry = this._storage[fkey];
1672
+ return entry ? entry.value : undefined;
1673
+ }
1674
+ var head = this._head, i = head;
1675
+ while ((i = i.next) !== head) {
1676
+ if (ES.SameValueZero(i.key, key)) {
1677
+ return i.value;
1678
+ }
1679
+ }
1680
+ return undefined;
1681
+ },
1682
+
1683
+ has: function (key) {
1684
+ var fkey = fastkey(key);
1685
+ if (fkey !== null) {
1686
+ // fast O(1) path
1687
+ return typeof this._storage[fkey] !== 'undefined';
1688
+ }
1689
+ var head = this._head, i = head;
1690
+ while ((i = i.next) !== head) {
1691
+ if (ES.SameValueZero(i.key, key)) {
1692
+ return true;
1693
+ }
1694
+ }
1695
+ return false;
1696
+ },
1697
+
1698
+ set: function (key, value) {
1699
+ var head = this._head, i = head, entry;
1700
+ var fkey = fastkey(key);
1701
+ if (fkey !== null) {
1702
+ // fast O(1) path
1703
+ if (typeof this._storage[fkey] !== 'undefined') {
1704
+ this._storage[fkey].value = value;
1705
+ return;
1706
+ } else {
1707
+ entry = this._storage[fkey] = new MapEntry(key, value);
1708
+ i = head.prev;
1709
+ // fall through
1710
+ }
1711
+ }
1712
+ while ((i = i.next) !== head) {
1713
+ if (ES.SameValueZero(i.key, key)) {
1714
+ i.value = value;
1715
+ return;
1716
+ }
1717
+ }
1718
+ entry = entry || new MapEntry(key, value);
1719
+ if (ES.SameValue(-0, key)) {
1720
+ entry.key = +0; // coerce -0 to +0 in entry
1721
+ }
1722
+ entry.next = this._head;
1723
+ entry.prev = this._head.prev;
1724
+ entry.prev.next = entry;
1725
+ entry.next.prev = entry;
1726
+ this._size += 1;
1727
+ return this;
1728
+ },
1729
+
1730
+ 'delete': function (key) {
1731
+ var head = this._head, i = head;
1732
+ var fkey = fastkey(key);
1733
+ if (fkey !== null) {
1734
+ // fast O(1) path
1735
+ if (typeof this._storage[fkey] === 'undefined') {
1736
+ return false;
1737
+ }
1738
+ i = this._storage[fkey].prev;
1739
+ delete this._storage[fkey];
1740
+ // fall through
1741
+ }
1742
+ while ((i = i.next) !== head) {
1743
+ if (ES.SameValueZero(i.key, key)) {
1744
+ i.key = i.value = empty;
1745
+ i.prev.next = i.next;
1746
+ i.next.prev = i.prev;
1747
+ this._size -= 1;
1748
+ return true;
1749
+ }
1750
+ }
1751
+ return false;
1752
+ },
1753
+
1754
+ clear: function () {
1755
+ this._size = 0;
1756
+ this._storage = emptyObject();
1757
+ var head = this._head, i = head, p = i.next;
1758
+ while ((i = p) !== head) {
1759
+ i.key = i.value = empty;
1760
+ p = i.next;
1761
+ i.next = i.prev = head;
1762
+ }
1763
+ head.next = head.prev = head;
1764
+ },
1765
+
1766
+ keys: function () {
1767
+ return new MapIterator(this, "key");
1768
+ },
1769
+
1770
+ values: function () {
1771
+ return new MapIterator(this, "value");
1772
+ },
1773
+
1774
+ entries: function () {
1775
+ return new MapIterator(this, "key+value");
1776
+ },
1777
+
1778
+ forEach: function (callback) {
1779
+ var context = arguments.length > 1 ? arguments[1] : null;
1780
+ var it = this.entries();
1781
+ for (var entry = it.next(); !entry.done; entry = it.next()) {
1782
+ callback.call(context, entry.value[1], entry.value[0], this);
1783
+ }
1784
+ }
1785
+ });
1786
+ addIterator(Map.prototype, function () { return this.entries(); });
1787
+
1788
+ return Map;
1789
+ })(),
1790
+
1791
+ Set: (function () {
1792
+ // Creating a Map is expensive. To speed up the common case of
1793
+ // Sets containing only string or numeric keys, we use an object
1794
+ // as backing storage and lazily create a full Map only when
1795
+ // required.
1796
+ var SetShim = function Set(iterable) {
1797
+ var set = this;
1798
+ set = emulateES6construct(set);
1799
+ if (!set._es6set) {
1800
+ throw new TypeError('bad set');
1801
+ }
1802
+
1803
+ defineProperties(set, {
1804
+ '[[SetData]]': null,
1805
+ _storage: emptyObject()
1806
+ });
1807
+
1808
+ // Optionally initialize map from iterable
1809
+ if (iterable !== undefined && iterable !== null) {
1810
+ var it = ES.GetIterator(iterable);
1811
+ var adder = set.add;
1812
+ if (!ES.IsCallable(adder)) { throw new TypeError('bad set'); }
1813
+ while (true) {
1814
+ var next = ES.IteratorNext(it);
1815
+ if (next.done) { break; }
1816
+ var nextItem = next.value;
1817
+ adder.call(set, nextItem);
1818
+ }
1819
+ }
1820
+ return set;
1821
+ };
1822
+ var Set$prototype = SetShim.prototype;
1823
+ defineProperties(SetShim, {
1824
+ '@@create': function (obj) {
1825
+ var constructor = this;
1826
+ var prototype = constructor.prototype || Set$prototype;
1827
+ obj = obj || create(prototype);
1828
+ defineProperties(obj, { _es6set: true });
1829
+ return obj;
1830
+ }
1831
+ });
1832
+
1833
+ // Switch from the object backing storage to a full Map.
1834
+ var ensureMap = function ensureMap(set) {
1835
+ if (!set['[[SetData]]']) {
1836
+ var m = set['[[SetData]]'] = new collectionShims.Map();
1837
+ Object.keys(set._storage).forEach(function (k) {
1838
+ // fast check for leading '$'
1839
+ if (k.charCodeAt(0) === 36) {
1840
+ k = k.slice(1);
1841
+ } else if (k.charAt(0) === 'n') {
1842
+ k = +k.slice(1);
1843
+ } else {
1844
+ k = +k;
1845
+ }
1846
+ m.set(k, k);
1847
+ });
1848
+ set._storage = null; // free old backing storage
1849
+ }
1850
+ };
1851
+
1852
+ Object.defineProperty(SetShim.prototype, 'size', {
1853
+ configurable: true,
1854
+ enumerable: false,
1855
+ get: function () {
1856
+ if (typeof this._storage === 'undefined') {
1857
+ // https://github.com/paulmillr/es6-shim/issues/176
1858
+ throw new TypeError('size method called on incompatible Set');
1859
+ }
1860
+ ensureMap(this);
1861
+ return this['[[SetData]]'].size;
1862
+ }
1863
+ });
1864
+
1865
+ defineProperties(SetShim.prototype, {
1866
+ has: function (key) {
1867
+ var fkey;
1868
+ if (this._storage && (fkey = fastkey(key)) !== null) {
1869
+ return !!this._storage[fkey];
1870
+ }
1871
+ ensureMap(this);
1872
+ return this['[[SetData]]'].has(key);
1873
+ },
1874
+
1875
+ add: function (key) {
1876
+ var fkey;
1877
+ if (this._storage && (fkey = fastkey(key)) !== null) {
1878
+ this._storage[fkey] = true;
1879
+ return;
1880
+ }
1881
+ ensureMap(this);
1882
+ this['[[SetData]]'].set(key, key);
1883
+ return this;
1884
+ },
1885
+
1886
+ 'delete': function (key) {
1887
+ var fkey;
1888
+ if (this._storage && (fkey = fastkey(key)) !== null) {
1889
+ delete this._storage[fkey];
1890
+ return;
1891
+ }
1892
+ ensureMap(this);
1893
+ return this['[[SetData]]']['delete'](key);
1894
+ },
1895
+
1896
+ clear: function () {
1897
+ if (this._storage) {
1898
+ this._storage = emptyObject();
1899
+ return;
1900
+ }
1901
+ return this['[[SetData]]'].clear();
1902
+ },
1903
+
1904
+ keys: function () {
1905
+ ensureMap(this);
1906
+ return this['[[SetData]]'].keys();
1907
+ },
1908
+
1909
+ values: function () {
1910
+ ensureMap(this);
1911
+ return this['[[SetData]]'].values();
1912
+ },
1913
+
1914
+ entries: function () {
1915
+ ensureMap(this);
1916
+ return this['[[SetData]]'].entries();
1917
+ },
1918
+
1919
+ forEach: function (callback) {
1920
+ var context = arguments.length > 1 ? arguments[1] : null;
1921
+ var entireSet = this;
1922
+ ensureMap(this);
1923
+ this['[[SetData]]'].forEach(function (value, key) {
1924
+ callback.call(context, key, key, entireSet);
1925
+ });
1926
+ }
1927
+ });
1928
+ addIterator(SetShim.prototype, function () { return this.values(); });
1929
+
1930
+ return SetShim;
1931
+ })()
1932
+ };
1933
+ defineProperties(globals, collectionShims);
1934
+
1935
+ if (globals.Map || globals.Set) {
1936
+ /*
1937
+ - In Firefox < 23, Map#size is a function.
1938
+ - In all current Firefox, Set#entries/keys/values & Map#clear do not exist
1939
+ - https://bugzilla.mozilla.org/show_bug.cgi?id=869996
1940
+ - In Firefox 24, Map and Set do not implement forEach
1941
+ - In Firefox 25 at least, Map and Set are callable without "new"
1942
+ */
1943
+ if (
1944
+ typeof globals.Map.prototype.clear !== 'function' ||
1945
+ new globals.Set().size !== 0 ||
1946
+ new globals.Map().size !== 0 ||
1947
+ typeof globals.Map.prototype.keys !== 'function' ||
1948
+ typeof globals.Set.prototype.keys !== 'function' ||
1949
+ typeof globals.Map.prototype.forEach !== 'function' ||
1950
+ typeof globals.Set.prototype.forEach !== 'function' ||
1951
+ isCallableWithoutNew(globals.Map) ||
1952
+ isCallableWithoutNew(globals.Set) ||
1953
+ !supportsSubclassing(globals.Map, function (M) {
1954
+ var m = new M([]);
1955
+ // Firefox 32 is ok with the instantiating the subclass but will
1956
+ // throw when the map is used.
1957
+ m.set(42, 42);
1958
+ return m instanceof M;
1959
+ })
1960
+ ) {
1961
+ globals.Map = collectionShims.Map;
1962
+ globals.Set = collectionShims.Set;
1963
+ }
1964
+ }
1965
+ // Shim incomplete iterator implementations.
1966
+ addIterator(Object.getPrototypeOf((new globals.Map()).keys()));
1967
+ addIterator(Object.getPrototypeOf((new globals.Set()).keys()));
1968
+ }
1969
+ };
1970
+
1971
+ if (typeof define === 'function' && define.amd) {
1972
+ define(main); // RequireJS
1973
+ } else {
1974
+ main(); // CommonJS and <script>
1975
+ }
1976
+ })();