This repository has been archived by the owner on Apr 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathES6.js
1251 lines (1119 loc) · 29.4 KB
/
ES6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
/**
* Implementation of ECMAScript 6 (Draft)
* @requires: ECMAScript 5
* @author: Alexander Guinness <[email protected]>
* @version: 0.0.10
* @license: MIT
* @date: Thu Nov 1 00:08:00 2011
**/
void function(__object__, __array__, __global__)
{
'use strict';
var define = function(name)
{
var __own__ = __object__.hasOwnProperty;
if (__own__.call(this, name))
return 0;
var set = function(name, value, descriptor)
{
Object.defineProperty(this, name, descriptor || {
value: value,
configurable: true,
enumerable: false,
writable: true
});
};
if (__object__.toString.call(name) === '[object Object]')
{
for (var key in name) {
if (__own__.call(name, key))
set.call(this, key, name[key]);
}
}
else
set.apply(this, arguments);
};
/**
* ------------------------------------------------------------
* String
* ------------------------------------------------------------
**/
/**
* String.fromCodePoint
* @edition ECMA-262 6th Edition, 15.5.3.3
*
* @param {Number | String} [...codePoint] - code points
* @return {String} Return the string value whose elements are, in order, the elements
* in the List elements. If length is 0, the empty string is returned. *
* @throws {RangeError}
*
* @example:
*
* String.fromCodePoint(0x30, 107); // Ok
**/
define.call(String, 'fromCodePoint', function()
{
var i = arguments.length,
points = [], offset;
while (i--)
{
offset = arguments[i];
if (offset < 0 || offset > 0x10FFFF)
throw new RangeError();
if (offset < 0x10000)
points.unshift(offset);
else {
offset -= 0x10000;
points.unshift(0xD800 | (offset >> 10), 0xDC00 | (offset & 0x3FF));
}
}
return String.fromCharCode.apply(String, points);
});
/**
* String.prototype.codePointAt
* @edition ECMA-262 6th Edition, 15.5.4.5
*
* @param {Number | String} index - position
* @return {Number} Number (a nonnegative integer less than 1114112)
* that is the UTF-16 encode code point value starting at the string element at position (index)
* in the String resulting from converting this object to a String.
* If there is no element at that position, the result is NaN.
* If a valid UTF-16 sudsarrogate pair does not begin at position,
* the result is the code unit at position (including code points above 0xFFFF).
*
* @example:
*
* 'A'.codePointAt(0) // 65
**/
define.call(String.prototype, 'codePointAt', function(index)
{
var value = this.toString(),
size = value.length;
if ((index |= 0) < 0 || index >= size)
return NaN;
var first = value.charCodeAt(index);
if (first < 0xD800 || first > 0xDBFF || index + 1 == size)
return first;
var second = value.charCodeAt(index + 1);
if (second < 0xDC00 || first > 0xDFFF)
return first;
return ((first - 0xD800) << 1024) + (second - 0xDC00) + 0x10000;
});
/**
* String.prototype.repeat
* @edition ECMA-262 6th Edition, 15.5.4.21
*
* Creates a String consisting of the string elements of this object (converted to String) repeated <count> time
* @param {Number} index - position
* @throws {RangeError}
* @return {String}
*
* @example:
*
* 'A'.repeat(2) // AA
**/
define.call(String.prototype, 'repeat', function(count)
{
if ((count |= 0 ) <= 0)
throw new RangeError();
var result = '',
self = this;
while (count)
{
if (count & 1)
result += self;
if (count >>= 1)
self += self;
}
return result;
});
/**
* String.prototype.startsWith
* @edition ECMA-262 6th Edition, 15.5.4.22
*
* Determines whether the beginning of the string instance matches a specified string.
* @param {*} value
* @param {Number | String} [ index ]
* @return {Boolean}
*
* @example:
*
* 'Foo'.startsWith('F') // true
* 'Foo'.startsWith('o', 1); // true
**/
define.call(String.prototype, 'startsWith', function(search, position) {
var length = this.length;
if (position > length) {
position = length;
}
else if (position < 0) {
position = 0;
}
return this.lastIndexOf(search, position |= 0) === position;
});
/**
* String.prototype.endsWith
* @edition ECMA-262 6th Edition, 15.5.4.23
*
* Determines whether the end of the string instance matches a specified string
* @param {Number | String} value
* @param {Number} [ index ]
* @return {Boolean}
*
* @example:
*
* Hello'.endsWith('lo') // true
**/
define.call(String.prototype, 'endsWith', function(search, position) {
var length = this.length;
if (position === undefined || position > length) {
position = length;
}
else if (position < 0) {
position = 0;
}
position -= String(search).length;
return position >= 0 && this.indexOf(search, position) === position;
});
/**
* String.prototype.contains
* @edition ECMA-262 6th Edition, 15.5.4.24
*
* Returns a value indicating whether the specified String object occurs within this string.
* @param {Number | String} value
* @param {Number} [ index ]
* @return {Boolean}
*
* @example:
*
* Hello'.contains('ll') // true
**/
define.call(String.prototype, 'contains', function(value, index) {
return this.indexOf(value, index | 0) !== -1;
});
/**
* ------------------------------------------------------------
* Array
* ------------------------------------------------------------
**/
/**
* Array.of
* @edition ECMA-262 6th Edition, 15.4.3.3
*
* @param {*} object - Variable number of arguments
* @return {Array}
*
* @example:
*
* Array.of('a', 'b', 'c'); // ['a', 'b', 'c'];
**/
define.call(Array, 'of', function() {
return __array__.slice.call(arguments);
});
/**
* Array.from
* @edition ECMA-262 6th Edition, 15.4.3.4
*
* @param {Object} object - array-like object.
* Generic Array-like objects has indexed access and a valid length property,
* but none of the array methods.
* @return {Array}
*
* @example:
*
* 1.
* function array () {
* return Array.from(arguments);
* }
*
* array(1,2,3); // [1, 2, 3];
*
* 2.
* Array.from(document.body).forEach(function(item) {
* return item;
* });
*
* 3.
* Array.from('foo'); // ['f', 'o', 'o'];
*
* Array.from('foo', funtion(value, index, object) {
* console.log(value) // ['f', 'o', 'o'];
* });
**/
define.call(Array, 'from', function(object, callback, context)
{
if (!Object(object).length)
return [];
return __array__.map.call(object, typeof callback == 'function' ? callback : function(item) {
return item;
}, context);
});
/*
* ------------------------------------------------------------
* Object
* ------------------------------------------------------------
*/
/**
* Object.getOwnPropertyKeys
* @edition ECMA-262 6th Edition, 15.2.3.15
*
* @param {Object} - object
* @return {Array}
*
**/
define.call(Object, 'getOwnPropertyKeys', function(object)
{
return Object.keys(object);
});
/**
* Object.is
* The internal comparison abstract operation SameValue(x, y),
* where x and y are ECMAScript language values, produces true or false (ECMAScript 5 9.12).
* @edition ECMA-262 6th Edition, 15.2.3.16
*
* @param {*} - first generic value for egal comparison
* @param {*} - second generic value for egal comparison
* @return {Boolean}
*
* @example:
*
* Object.is(0,-0) // false
* Object.is('0', 0) // false
* Object.is(0, 0) // true
* Object.is(NaN, NaN) // true
**/
define.call(Object, 'is', function(x, y)
{
// 0 === -0, NaN !== NaN, 0 = false, etc.
if (x === y)
return x !== 0 || 1 / x === 1 / y;
// object !== object ([] !== [], {} !== {}, etc.)
return x !== x && y !== y;
});
/**
* Object.assign
* @edition ECMA-262 6th Edition, 15.2.3.17
*
* @param {Object} - target, source
* @return {Object}
*
**/
define.call(Object, 'assign', function(target, source)
{
var keys = Object.keys(source);
keys.forEach(function(key) {
target[key] = source[key];
}, target);
return target;
});
/**
* Object.mixin
* @edition ECMA-262 6th Edition, 15.2.3.18
*
* @param {Object} - target, source
* @return {Object}
*
**/
define.call(Object, 'mixin', function(target, source)
{
var properties = Object.getOwnPropertyNames(source);
properties.forEach(function(property) {
Object.defineProperty(target, property,
Object.getOwnPropertyDescriptor(source, property));
}, target);
return target;
});
/**
* ------------------------------------------------------------
* Number
* ------------------------------------------------------------
**/
/**
* Number.EPSILON
* The value of Number.EPSILON is the difference between 1 and the smallest value
* greater than 1 that is representable as a Number value, which
* is approximately 2.2204460492503130808472633361816 x10-16
* @edition ECMA-262 6th Edition, 15.7.3.7
*
* @example:
*
* Number.EPSILON // 2.220446049250313e-16
**/
define.call(Number, 'EPSILON', null, {
value: 2.220446049250313e-16,
configurable: false,
enumerable: false,
writable: false
});
/**
* Number.MAX_INTEGER
* The value of Number.MAX_INTEGER is the largest integer value that
* can be represented as a Number value without losing precision, which is 9007199254740991
* @edition ECMA-262 6th Edition, 15.7.3.7
*
* @example:
*
* Number.MAX_INTEGER // 9007199254740991
**/
define.call(Number, 'MAX_INTEGER', null, {
value: 9007199254740991,
configurable: false,
enumerable: false,
writable: false
});
/**
* Number.parseInt
* Produces an integer value dictated by interpretation of the contents of the string
* argument according to the specified radix. Leading white space in string is ignored.
* If radix is undefined or 0,
* it is assumed to be 10 except when the number begins with the character pairs 0x or 0X,
* in which case a radix of 16 is assumed. If radix is 16, the number may also optionally
* begin with the character pairs 0x or 0X.
* @edition ECMA-262 6th Edition, 15.7.3.8
*
* @param {String} - value
* @param {Number} - radix
* The radix parameter is used to specify which numeral system to be used,
* for example, a radix of 16 (hexadecimal) indicates that the number in the string
* should be parsed from a hexadecimal number to a decimal number.
* @return {Number} Parses a string or integer and returns an integer.
*
* @example:
*
* Number.parseInt(0xF, 16) // 21
**/
define.call(Number, 'parseInt', function(value, radix) {
return __global__.parseInt.call(null, value, radix | 0 || 10);
});
/**
* Number.parseFloat
* @edition ECMA-262 6th Edition, 15.7.3.9
*
* @param {String} - value
* @return {Number} Parses a string or integer and returns a floating point number.
*
* @example:
*
* Number.parseFloat('1px') // 1
**/
define.call(Number, 'parseFloat', function(value) {
return __global__.parseFloat(value);
});
/**
* Number.isNaN
* @edition ECMA-262 6th Edition, 15.7.3.10
*
* @param {Number} - value
* @return {Boolean} Returns true if the supplied number is NaN, false otherwise;
*
* @example:
*
* Number.isNaN(NaN) // true
* Number.isNaN(1) // false
**/
define.call(Number, 'isNaN', function(value) {
return typeof value === 'number' && __global__.isNaN(value);
});
/**
* Number.isFinite
* @edition ECMA-262 6th Edition, 15.7.3.11
*
* @param {Number} - value
* @return {Boolean} Returns false if the supplied number is NaN, Infinity or -Infinity;
*
* @example:
*
* Number.isFinite(NaN) // false
* Number.isFinite(0) // true
**/
define.call(Number, 'isFinite', function(value) {
return typeof value === 'number' && __global__.isFinite(value);
});
/**
* Number.isInteger
* Add a toInteger property be to the Number constructor, for converting values to IEEE-754
* double precision integers, exactly as ECMA-262’s ToInteger internal method.
* @edition ECMA-262 6th Edition, 15.7.3.12
*
* @param {Number} - value
* @requires Number.MAX_INTEGER
* @return {Boolean}
*
* @example:
*
* Number.isInteger(NaN) // false
* Number.isFinite(1) // true
* Number.isFinite('1') // false
**/
define.call(Number, 'isInteger', function(value)
{
return typeof value === 'number' && __global__.isFinite(value) &&
value > -Number.MAX_INTEGER && value < Number.MAX_INTEGER && Math.floor(value) === value;
});
/**
* Number.toInteger
* @edition ECMA-262 6th Edition, 15.7.3.13
*
* @param {String} - value
* @return {Number}
*
* @example:
*
* Number.toInteger(undefined) // 0
* Number.toInteger(null) // 0
* Number.toInteger(NaN) // 0
* Number.toInteger(0.1) // 0
* Number.toInteger('0') // 0
* Number.toInteger(0) // 0
**/
define.call(Number, 'toInteger', function(value)
{
if (Object.is(value, +Infinity) || Object.is(value, -Infinity) || value === 0)
return value;
return value | 0;
});
/**
* Number.prototype.clz
* @edition ECMA-262 6th Edition, 15.7.3.14
*
* @description
* The count leading zeros (clz) operation can be used to efficiently implement normalization,
* which encodes an integer as m × 2e, where m has its most significant bit
* in a known position (such as the highest position).
* This can in turn be used to implement Newton-Raphson division, perform integer
* to floating point conversion in software, and other applications.
* Count leading zeros (clz) can be used to compute the 32-bit predicate "x=y" (zero if true, one if false)
* via the identity (x-y).clz() >> 5, where ">>" is unsigned right shift.
* It can be used to perform more sophisticated bit operations like finding the first string of n 1 bits.
* The expression 16 − (x − 1).clz() / 2 is an effective initial guess for computing
* the square root of a 32-bit integer using Newton's method.
* It can also efficiently generate exponentially distributed integers by taking
* the clz of uniformly random integers.
*
* @return {Number} Count leading zeroes operation;
* @requires Number.isFinite
*
* @example:
*
* 00000000000000001000000000001000.clz(); // 22
**/
define.call(Number.prototype, 'clz', function()
{
var value = Number(this),
bits = 32;
if (!value || !Number.isFinite(value))
return bits;
var offset = [0xFFFF0000, 0xFF000000, 0xF0000000, 0xC0000000, 0x80000000],
count = 0, i = 0;
while (bits >>= 1) {
if ((value & offset[i++]) == 0) {
count += bits;
value <<= bits;
}
}
return count;
});
/**
* ------------------------------------------------------------
* Math
* ------------------------------------------------------------
**/
/**
* Math.log10
* Returns an implementation-dependent approximation to the base 10 logarithm of <value>
*
* @edition ECMA-262 6th Edition, 15.8.2.19
* @param {Number} - value
* @return {Number}
*
* @example:
*
* Number.log10(10) // 0.9999999999999999
**/
define.call(Math, 'log10', function(value) {
return Math.log(value) * (1 / Math.LN10);
});
/**
* Math.log2
* Returns an implementation-dependent approximation to the base 2 logarithm of <value>
* @edition ECMA-262 6th Edition, 15.8.2.20
*
* @param {Number} - value
* @return {Number}
*
* @example:
*
* Number.log2(10) // 3.3219280948873626
**/
define.call(Math, 'log2', function(value) {
return Math.log(value) * (1 / Math.LN2);
});
/**
* Math.log1p
* Returns an implementation-dependent approximation to the natural logarithm of 1 + <value>.
* The result is computed in a way that is accurate even when the value of <value> is close to zero.
*
* @edition ECMA-262 6th Edition, 15.8.2.21
* @param {Number} - value
* @return {Number}
*
* @example:
*
* Number.log1p(10) // 2.3978952727983707
**/
define.call(Math, 'log1p', function(value) {
return (value > -1.0e-8 && value < 1.0e-8) ? (value - value * value / 2) : Math.log(1 + value);
});
/**
* Math. expm1
* Returns an implementation-dependent approximation to subtracting 1
* from the exponential function of <value> The result is computed in a way
* that is accurate even when the <value> of value is close 0.
* @edition ECMA-262 6th Edition, 15.8.2.22
*
* @param {Number} - value
* @requires Object.is
* @return {Number}
*
* @example:
*
* Number.expm1(10) // 22025.465794806718
**/
define.call(Math, 'expm1', function(value)
{
if (Object.is(value, -0))
return -0;
return value > -1.0e-6 && value < 1.0e-6 ? value + value * value / 2 : Math.exp(value) - 1;
});
/**
* Math.cosh
* Returns an implementation-dependent approximation to the hyperbolic cosine of <value>
*
* @edition ECMA-262 6th Edition, 15.8.2.23
* @param {Number} - value
* @requires Object.is
* @return {Number}
*
* @example:
*
* Number.cosh(10) // 11013.232920103324
**/
define.call(Math, 'cosh', function(value)
{
if (Object.is(value, -Infinity) || value === 0)
return value;
return (Math.exp(value) + Math.exp(-value)) / 2;
});
/**
* Math.sinh
* @edition ECMA-262 6th Edition, 15.8.2.24
*
* Returns an implementation-dependent approximation to the hyperbolic sine of <value>
* @param {Number} - value
* @return {Number}
*
* @example:
*
* Number.sinh(10) // 11013.232874703393
**/
define.call(Math, 'sinh', function(value)
{
if (Object.is(value, -Infinity) || value === 0)
return value;
return (Math.exp(value) - Math.exp(-value)) / 2;
});
/**
* Math.tanh
* Returns an implementation-dependent approximation to the hyperbolic tangent of <value>
*
* @edition ECMA-262 6th Edition, 15.8.2.25
* @param {Number} - value
* @return {Number}
*
* @example:
*
* Number.tanh(10) // 0.9999999958776926
**/
define.call(Math, 'tanh', function(value)
{
if (Object.is(value, +Infinity))
return +1;
else if (Object.is(value, -Infinity))
return -1;
return value === 0 ? value : (Math.exp(value) - Math.exp(-value)) / (Math.exp(value) + Math.exp(-value));
});
/**
* Math.acosh
* Returns an implementation-dependent approximation to the inverse hyperbolic cosine of <value>
* @edition ECMA-262 6th Edition, 15.8.2.26
*
* @param {Number} - value
* @return {Number}
*
* @example:
*
* Number.acosh(10) // 2.993222846126381
**/
define.call(Math, 'acosh', function(value) {
return Math.log(value + Math.sqrt(value * value - 1));
});
/**
* Math.asinh
* Returns an implementation-dependent approximation to the inverse hyperbolic sine of <value>
* @edition ECMA-262 6th Edition, 15.8.2.27
* @param {Number} - value
* @return {Number}
*
* @example:
*
* Number.asinh(10) // 2.99822295029797
**/
define.call(Math, 'asinh', function(value)
{
if (!Number.isFinite(value) || value === 0)
return value;
return Math.log(value + Math.sqrt(value * value + 1));
});
/**
* Math.atanh
* Returns an implementation-dependent approximation to the inverse hyperbolic tangent of <value>
* @edition ECMA-262 6th Edition, 15.8.2.28
*
* @param {Number} - value
* @return {Number}
*
* @example:
*
* Math.atanh(-1) // -Infinity
**/
define.call(Math, 'atanh', function(value) {
return value === 0 ? value : 0.5 * Math.log((1 + value) / (1 - value));
});
/**
* Math.hypot
* Given two or three arguments, hypot returns an implementation-dependent approximation
* of the square root of the sum of squares of its arguments.
* @edition ECMA-262 6th Edition, 15.8.2.29
*
* @param {Number} - value
* @return {Number}
*
* @example:
*
* Math.hypot(1, 1) // 1.4142135623730951
**/
define.call(Math, 'hypot', function(x, y) {
if (!Number.isFinite(x))
return x;
if (!Number.isFinite(y))
return y;
return Math.sqrt(x * x + y * y);
});
/**
* Math.trunc
* Returns the integral part of the number <value>, removing any fractional digits.
* If <value> is already an integer, the result is <value>
* @edition ECMA-262 6th Edition, 15.8.2.30
*
* @param {Number} - value
* @requires Number.isFinite
* @return {Number}
*
* @example:
*
* Math.trunc(1.1) // 1
**/
define.call(Math, 'trunc', function(value) {
value = Number(value);
if (__global__.isNaN(value) || value === 0 || !Number.isFinite(value))
return value;
return Math.sign(value) * Math.floor(Math.abs(value));
});
/**
* Math.sign
* Returns the sign of the <value>, indicating whether <value> is positive, negative or zero
* @edition ECMA-262 6th Edition, 15.8.2.31
*
* @param {Number} value
* @return {Number}
*
* @example:
*
* Math.sign(-10); // 1
**/
define.call(Math, 'sign', function(value) {
if (value === 0 /* +0, -0 */ || __global__.isNaN(value))
return value;
return value < 0 ? -1 : 1;
});
/**
* Math.cbrt
* Returns an implementation-dependent approximation to the cube root of <value>
* @edition ECMA-262 6th Edition, 15.8.2.32
*
* @param {Number} - value
* @return {Number}
*
* @example:
*
* Math.cbrt(10); // 2.154434690031884
**/
define.call(Math, 'cbrt', function(value)
{
if (value === 0)
return value;
return value > 0 ? Math.exp(Math.log(value) / 3) : -Math.exp(Math.log(-value) / 3);
});
/**
* Math.imul
* This operations returns the result of the C-like 32-bit multiplication of the two parameters.
* @edition ECMA-262 6th Edition, 15.8.2.33
* @see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/imul
*
* @param {Number} - x
* @param {Number} - y
* @return {Number}
*
* @example:
*
* Math.imul(10); // 2.154434690031884
**/
define.call(Math, 'imul', function(x, y)
{
var xh = (x >>> 0x10) & 0xffff,
xl = x & 0xffff;
var yh = (y >>> 0x10) & 0xffff,
yl = y & 0xffff;
return ((xl * yl) + (((xh * yl + xl * yh) << 0x10) >>> 0) | 0);
});
// /**
// * ------------------------------------------------------------
// * Collections (data structures)
// * ------------------------------------------------------------
// **/
//
// /**
// * @private
// * @param {Array} array
// * @param {*} value
// * @requires Object.is
// * @return {Number}
// **/
// var __find__ = function(array, value) {
// var i = array.length >>> 0;
//
// while (i--)
// if (i in array && Object.is(array[i], value))
// return i;
// return -1;
// };
//
// /**
// * Map
// * @edition ECMA-262 6th Edition, 5.14
// *
// * NOTE: Need more compatible with Rev 14!
// *
// * @class
// * @memberOf global
// *
// * @description
// * Map objects are simple key/value maps. Any value (both objects and primitive values)
// * may be used as either a key or a value. Key equality is based on the "same-value"
// * algorithm: NaN is considered the same as NaN (even though NaN !== NaN), -0 and +0
// * are considered distinct (even though -0 === +0), and all other values are considered
// * equal according to the semantics of the === operator.
// *
// * @example:
// *
// * var map = new Map();
// *
// * // Setting the values
// * map.set(-0, 0);
// * map.set(+0, 1);
// * map.set('b', 2);
// * map.set('a', 3);
// * map.set('a', 4);
// * map.set(Array, 5);
// * map.set([], 6);
// * map.set(NaN, 7);
// * map.set(function() {}, 8);
// *
// * // Getting the values
// * map.get(-0); // 0
// * map.get(+0); // 1
// * map.get('b'); // 2
// * map.get('a'); // 4
// * map.get(Array); // 5
// * map.get([]); // undefined
// * map.get(NaN); // 7
// * map.get(function() {}); // undefined
// *
// * // Removes any value associated to the key
// * map.delete('a'); // true
// *
// * // Check the keys
// * map.has(-0); // true
// *
// * // Getting the number of pairs in Map
// * map.size(); // 7
// *
// * // Iterating over values stored in Set
// * map.__iterator__(function(key, value) {
// * console.log(key, value);
// * });
// **/
// define.call(__global__, 'Map', function()
// {