├── .gitignore ├── .npmignore ├── ES6.js ├── HISTORY.md ├── MIT_LICENSE.txt ├── README.md ├── TODO.md ├── package.json ├── proposal.js └── tests ├── Array.js ├── Collection.js ├── Math.js ├── Number.js ├── Object.js ├── Proposal.js ├── String.js └── suitest.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git/ 2 | .gitignore 3 | .idea/ 4 | .DS_Store 5 | TODO.md 6 | -------------------------------------------------------------------------------- /ES6.js: -------------------------------------------------------------------------------- 1 | // -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- 2 | 3 | /** 4 | * Implementation of ECMAScript 6 (Draft) 5 | * @requires: ECMAScript 5 6 | * @author: Alexander Guinness 7 | * @version: 0.0.10 8 | * @license: MIT 9 | * @date: Thu Nov 1 00:08:00 2011 10 | **/ 11 | 12 | void function(__object__, __array__, __global__) 13 | { 14 | 'use strict'; 15 | 16 | var define = function(name) 17 | { 18 | var __own__ = __object__.hasOwnProperty; 19 | 20 | if (__own__.call(this, name)) 21 | return 0; 22 | 23 | var set = function(name, value, descriptor) 24 | { 25 | Object.defineProperty(this, name, descriptor || { 26 | value: value, 27 | configurable: true, 28 | enumerable: false, 29 | writable: true 30 | }); 31 | }; 32 | 33 | if (__object__.toString.call(name) === '[object Object]') 34 | { 35 | for (var key in name) { 36 | if (__own__.call(name, key)) 37 | set.call(this, key, name[key]); 38 | } 39 | } 40 | else 41 | set.apply(this, arguments); 42 | }; 43 | 44 | 45 | /** 46 | * ------------------------------------------------------------ 47 | * String 48 | * ------------------------------------------------------------ 49 | **/ 50 | 51 | 52 | /** 53 | * String.fromCodePoint 54 | * @edition ECMA-262 6th Edition, 15.5.3.3 55 | * 56 | * @param {Number | String} [...codePoint] - code points 57 | * @return {String} Return the string value whose elements are, in order, the elements 58 | * in the List elements. If length is 0, the empty string is returned. * 59 | * @throws {RangeError} 60 | * 61 | * @example: 62 | * 63 | * String.fromCodePoint(0x30, 107); // Ok 64 | **/ 65 | define.call(String, 'fromCodePoint', function() 66 | { 67 | var i = arguments.length, 68 | points = [], offset; 69 | 70 | while (i--) 71 | { 72 | offset = arguments[i]; 73 | 74 | if (offset < 0 || offset > 0x10FFFF) 75 | throw new RangeError(); 76 | 77 | if (offset < 0x10000) 78 | points.unshift(offset); 79 | 80 | else { 81 | offset -= 0x10000; 82 | points.unshift(0xD800 | (offset >> 10), 0xDC00 | (offset & 0x3FF)); 83 | } 84 | } 85 | 86 | return String.fromCharCode.apply(String, points); 87 | }); 88 | 89 | 90 | /** 91 | * String.prototype.codePointAt 92 | * @edition ECMA-262 6th Edition, 15.5.4.5 93 | * 94 | * @param {Number | String} index - position 95 | * @return {Number} Number (a nonnegative integer less than 1114112) 96 | * that is the UTF-16 encode code point value starting at the string element at position (index) 97 | * in the String resulting from converting this object to a String. 98 | * If there is no element at that position, the result is NaN. 99 | * If a valid UTF-16 sudsarrogate pair does not begin at position, 100 | * the result is the code unit at position (including code points above 0xFFFF). 101 | * 102 | * @example: 103 | * 104 | * 'A'.codePointAt(0) // 65 105 | **/ 106 | define.call(String.prototype, 'codePointAt', function(index) 107 | { 108 | var value = this.toString(), 109 | size = value.length; 110 | 111 | if ((index |= 0) < 0 || index >= size) 112 | return NaN; 113 | 114 | var first = value.charCodeAt(index); 115 | 116 | if (first < 0xD800 || first > 0xDBFF || index + 1 == size) 117 | return first; 118 | 119 | var second = value.charCodeAt(index + 1); 120 | 121 | if (second < 0xDC00 || first > 0xDFFF) 122 | return first; 123 | 124 | return ((first - 0xD800) << 1024) + (second - 0xDC00) + 0x10000; 125 | }); 126 | 127 | 128 | /** 129 | * String.prototype.repeat 130 | * @edition ECMA-262 6th Edition, 15.5.4.21 131 | * 132 | * Creates a String consisting of the string elements of this object (converted to String) repeated time 133 | * @param {Number} index - position 134 | * @throws {RangeError} 135 | * @return {String} 136 | * 137 | * @example: 138 | * 139 | * 'A'.repeat(2) // AA 140 | **/ 141 | define.call(String.prototype, 'repeat', function(count) 142 | { 143 | if ((count |= 0 ) <= 0) 144 | throw new RangeError(); 145 | 146 | var result = '', 147 | self = this; 148 | 149 | while (count) 150 | { 151 | if (count & 1) 152 | result += self; 153 | 154 | if (count >>= 1) 155 | self += self; 156 | } 157 | 158 | return result; 159 | }); 160 | 161 | 162 | /** 163 | * String.prototype.startsWith 164 | * @edition ECMA-262 6th Edition, 15.5.4.22 165 | * 166 | * Determines whether the beginning of the string instance matches a specified string. 167 | * @param {*} value 168 | * @param {Number | String} [ index ] 169 | * @return {Boolean} 170 | * 171 | * @example: 172 | * 173 | * 'Foo'.startsWith('F') // true 174 | * 'Foo'.startsWith('o', 1); // true 175 | **/ 176 | define.call(String.prototype, 'startsWith', function(search, position) { 177 | var length = this.length; 178 | 179 | if (position > length) { 180 | position = length; 181 | } 182 | else if (position < 0) { 183 | position = 0; 184 | } 185 | 186 | return this.lastIndexOf(search, position |= 0) === position; 187 | }); 188 | 189 | 190 | /** 191 | * String.prototype.endsWith 192 | * @edition ECMA-262 6th Edition, 15.5.4.23 193 | * 194 | * Determines whether the end of the string instance matches a specified string 195 | * @param {Number | String} value 196 | * @param {Number} [ index ] 197 | * @return {Boolean} 198 | * 199 | * @example: 200 | * 201 | * Hello'.endsWith('lo') // true 202 | **/ 203 | define.call(String.prototype, 'endsWith', function(search, position) { 204 | var length = this.length; 205 | 206 | if (position === undefined || position > length) { 207 | position = length; 208 | } 209 | else if (position < 0) { 210 | position = 0; 211 | } 212 | 213 | position -= String(search).length; 214 | 215 | return position >= 0 && this.indexOf(search, position) === position; 216 | }); 217 | 218 | 219 | /** 220 | * String.prototype.contains 221 | * @edition ECMA-262 6th Edition, 15.5.4.24 222 | * 223 | * Returns a value indicating whether the specified String object occurs within this string. 224 | * @param {Number | String} value 225 | * @param {Number} [ index ] 226 | * @return {Boolean} 227 | * 228 | * @example: 229 | * 230 | * Hello'.contains('ll') // true 231 | **/ 232 | define.call(String.prototype, 'contains', function(value, index) { 233 | return this.indexOf(value, index | 0) !== -1; 234 | }); 235 | 236 | 237 | /** 238 | * ------------------------------------------------------------ 239 | * Array 240 | * ------------------------------------------------------------ 241 | **/ 242 | 243 | /** 244 | * Array.of 245 | * @edition ECMA-262 6th Edition, 15.4.3.3 246 | * 247 | * @param {*} object - Variable number of arguments 248 | * @return {Array} 249 | * 250 | * @example: 251 | * 252 | * Array.of('a', 'b', 'c'); // ['a', 'b', 'c']; 253 | **/ 254 | define.call(Array, 'of', function() { 255 | return __array__.slice.call(arguments); 256 | }); 257 | 258 | /** 259 | * Array.from 260 | * @edition ECMA-262 6th Edition, 15.4.3.4 261 | * 262 | * @param {Object} object - array-like object. 263 | * Generic Array-like objects has indexed access and a valid length property, 264 | * but none of the array methods. 265 | * @return {Array} 266 | * 267 | * @example: 268 | * 269 | * 1. 270 | * function array () { 271 | * return Array.from(arguments); 272 | * } 273 | * 274 | * array(1,2,3); // [1, 2, 3]; 275 | * 276 | * 2. 277 | * Array.from(document.body).forEach(function(item) { 278 | * return item; 279 | * }); 280 | * 281 | * 3. 282 | * Array.from('foo'); // ['f', 'o', 'o']; 283 | * 284 | * Array.from('foo', funtion(value, index, object) { 285 | * console.log(value) // ['f', 'o', 'o']; 286 | * }); 287 | **/ 288 | define.call(Array, 'from', function(object, callback, context) 289 | { 290 | if (!Object(object).length) 291 | return []; 292 | 293 | return __array__.map.call(object, typeof callback == 'function' ? callback : function(item) { 294 | return item; 295 | }, context); 296 | }); 297 | 298 | 299 | /* 300 | * ------------------------------------------------------------ 301 | * Object 302 | * ------------------------------------------------------------ 303 | */ 304 | 305 | 306 | /** 307 | * Object.getOwnPropertyKeys 308 | * @edition ECMA-262 6th Edition, 15.2.3.15 309 | * 310 | * @param {Object} - object 311 | * @return {Array} 312 | * 313 | **/ 314 | define.call(Object, 'getOwnPropertyKeys', function(object) 315 | { 316 | return Object.keys(object); 317 | }); 318 | 319 | /** 320 | * Object.is 321 | * The internal comparison abstract operation SameValue(x, y), 322 | * where x and y are ECMAScript language values, produces true or false (ECMAScript 5 9.12). 323 | * @edition ECMA-262 6th Edition, 15.2.3.16 324 | * 325 | * @param {*} - first generic value for egal comparison 326 | * @param {*} - second generic value for egal comparison 327 | * @return {Boolean} 328 | * 329 | * @example: 330 | * 331 | * Object.is(0,-0) // false 332 | * Object.is('0', 0) // false 333 | * Object.is(0, 0) // true 334 | * Object.is(NaN, NaN) // true 335 | **/ 336 | define.call(Object, 'is', function(x, y) 337 | { 338 | // 0 === -0, NaN !== NaN, 0 = false, etc. 339 | if (x === y) 340 | return x !== 0 || 1 / x === 1 / y; 341 | 342 | // object !== object ([] !== [], {} !== {}, etc.) 343 | return x !== x && y !== y; 344 | }); 345 | 346 | /** 347 | * Object.assign 348 | * @edition ECMA-262 6th Edition, 15.2.3.17 349 | * 350 | * @param {Object} - target, source 351 | * @return {Object} 352 | * 353 | **/ 354 | define.call(Object, 'assign', function(target, source) 355 | { 356 | var keys = Object.keys(source); 357 | 358 | keys.forEach(function(key) { 359 | target[key] = source[key]; 360 | }, target); 361 | 362 | return target; 363 | }); 364 | 365 | /** 366 | * Object.mixin 367 | * @edition ECMA-262 6th Edition, 15.2.3.18 368 | * 369 | * @param {Object} - target, source 370 | * @return {Object} 371 | * 372 | **/ 373 | define.call(Object, 'mixin', function(target, source) 374 | { 375 | var properties = Object.getOwnPropertyNames(source); 376 | 377 | properties.forEach(function(property) { 378 | Object.defineProperty(target, property, 379 | Object.getOwnPropertyDescriptor(source, property)); 380 | }, target); 381 | 382 | return target; 383 | }); 384 | 385 | 386 | /** 387 | * ------------------------------------------------------------ 388 | * Number 389 | * ------------------------------------------------------------ 390 | **/ 391 | 392 | 393 | /** 394 | * Number.EPSILON 395 | * The value of Number.EPSILON is the difference between 1 and the smallest value 396 | * greater than 1 that is representable as a Number value, which 397 | * is approximately 2.2204460492503130808472633361816 x10-16 398 | * @edition ECMA-262 6th Edition, 15.7.3.7 399 | * 400 | * @example: 401 | * 402 | * Number.EPSILON // 2.220446049250313e-16 403 | **/ 404 | define.call(Number, 'EPSILON', null, { 405 | value: 2.220446049250313e-16, 406 | configurable: false, 407 | enumerable: false, 408 | writable: false 409 | }); 410 | 411 | 412 | /** 413 | * Number.MAX_INTEGER 414 | * The value of Number.MAX_INTEGER is the largest integer value that 415 | * can be represented as a Number value without losing precision, which is 9007199254740991 416 | * @edition ECMA-262 6th Edition, 15.7.3.7 417 | * 418 | * @example: 419 | * 420 | * Number.MAX_INTEGER // 9007199254740991 421 | **/ 422 | define.call(Number, 'MAX_INTEGER', null, { 423 | value: 9007199254740991, 424 | configurable: false, 425 | enumerable: false, 426 | writable: false 427 | }); 428 | 429 | 430 | /** 431 | * Number.parseInt 432 | * Produces an integer value dictated by interpretation of the contents of the string 433 | * argument according to the specified radix. Leading white space in string is ignored. 434 | * If radix is undefined or 0, 435 | * it is assumed to be 10 except when the number begins with the character pairs 0x or 0X, 436 | * in which case a radix of 16 is assumed. If radix is 16, the number may also optionally 437 | * begin with the character pairs 0x or 0X. 438 | * @edition ECMA-262 6th Edition, 15.7.3.8 439 | * 440 | * @param {String} - value 441 | * @param {Number} - radix 442 | * The radix parameter is used to specify which numeral system to be used, 443 | * for example, a radix of 16 (hexadecimal) indicates that the number in the string 444 | * should be parsed from a hexadecimal number to a decimal number. 445 | * @return {Number} Parses a string or integer and returns an integer. 446 | * 447 | * @example: 448 | * 449 | * Number.parseInt(0xF, 16) // 21 450 | **/ 451 | define.call(Number, 'parseInt', function(value, radix) { 452 | return __global__.parseInt.call(null, value, radix | 0 || 10); 453 | }); 454 | 455 | 456 | /** 457 | * Number.parseFloat 458 | * @edition ECMA-262 6th Edition, 15.7.3.9 459 | * 460 | * @param {String} - value 461 | * @return {Number} Parses a string or integer and returns a floating point number. 462 | * 463 | * @example: 464 | * 465 | * Number.parseFloat('1px') // 1 466 | **/ 467 | define.call(Number, 'parseFloat', function(value) { 468 | return __global__.parseFloat(value); 469 | }); 470 | 471 | /** 472 | * Number.isNaN 473 | * @edition ECMA-262 6th Edition, 15.7.3.10 474 | * 475 | * @param {Number} - value 476 | * @return {Boolean} Returns true if the supplied number is NaN, false otherwise; 477 | * 478 | * @example: 479 | * 480 | * Number.isNaN(NaN) // true 481 | * Number.isNaN(1) // false 482 | **/ 483 | define.call(Number, 'isNaN', function(value) { 484 | return typeof value === 'number' && __global__.isNaN(value); 485 | }); 486 | 487 | 488 | /** 489 | * Number.isFinite 490 | * @edition ECMA-262 6th Edition, 15.7.3.11 491 | * 492 | * @param {Number} - value 493 | * @return {Boolean} Returns false if the supplied number is NaN, Infinity or -Infinity; 494 | * 495 | * @example: 496 | * 497 | * Number.isFinite(NaN) // false 498 | * Number.isFinite(0) // true 499 | **/ 500 | define.call(Number, 'isFinite', function(value) { 501 | return typeof value === 'number' && __global__.isFinite(value); 502 | }); 503 | 504 | 505 | /** 506 | * Number.isInteger 507 | * Add a toInteger property be to the Number constructor, for converting values to IEEE-754 508 | * double precision integers, exactly as ECMA-262’s ToInteger internal method. 509 | * @edition ECMA-262 6th Edition, 15.7.3.12 510 | * 511 | * @param {Number} - value 512 | * @requires Number.MAX_INTEGER 513 | * @return {Boolean} 514 | * 515 | * @example: 516 | * 517 | * Number.isInteger(NaN) // false 518 | * Number.isFinite(1) // true 519 | * Number.isFinite('1') // false 520 | 521 | **/ 522 | define.call(Number, 'isInteger', function(value) 523 | { 524 | return typeof value === 'number' && __global__.isFinite(value) && 525 | value > -Number.MAX_INTEGER && value < Number.MAX_INTEGER && Math.floor(value) === value; 526 | }); 527 | 528 | 529 | /** 530 | * Number.toInteger 531 | * @edition ECMA-262 6th Edition, 15.7.3.13 532 | * 533 | * @param {String} - value 534 | * @return {Number} 535 | * 536 | * @example: 537 | * 538 | * Number.toInteger(undefined) // 0 539 | * Number.toInteger(null) // 0 540 | * Number.toInteger(NaN) // 0 541 | * Number.toInteger(0.1) // 0 542 | * Number.toInteger('0') // 0 543 | * Number.toInteger(0) // 0 544 | **/ 545 | define.call(Number, 'toInteger', function(value) 546 | { 547 | if (Object.is(value, +Infinity) || Object.is(value, -Infinity) || value === 0) 548 | return value; 549 | 550 | return value | 0; 551 | }); 552 | 553 | 554 | /** 555 | * Number.prototype.clz 556 | * @edition ECMA-262 6th Edition, 15.7.3.14 557 | * 558 | * @description 559 | * The count leading zeros (clz) operation can be used to efficiently implement normalization, 560 | * which encodes an integer as m × 2e, where m has its most significant bit 561 | * in a known position (such as the highest position). 562 | * This can in turn be used to implement Newton-Raphson division, perform integer 563 | * to floating point conversion in software, and other applications. 564 | * Count leading zeros (clz) can be used to compute the 32-bit predicate "x=y" (zero if true, one if false) 565 | * via the identity (x-y).clz() >> 5, where ">>" is unsigned right shift. 566 | * It can be used to perform more sophisticated bit operations like finding the first string of n 1 bits. 567 | * The expression 16 − (x − 1).clz() / 2 is an effective initial guess for computing 568 | * the square root of a 32-bit integer using Newton's method. 569 | * It can also efficiently generate exponentially distributed integers by taking 570 | * the clz of uniformly random integers. 571 | * 572 | * @return {Number} Count leading zeroes operation; 573 | * @requires Number.isFinite 574 | * 575 | * @example: 576 | * 577 | * 00000000000000001000000000001000.clz(); // 22 578 | **/ 579 | define.call(Number.prototype, 'clz', function() 580 | { 581 | var value = Number(this), 582 | bits = 32; 583 | 584 | if (!value || !Number.isFinite(value)) 585 | return bits; 586 | 587 | var offset = [0xFFFF0000, 0xFF000000, 0xF0000000, 0xC0000000, 0x80000000], 588 | count = 0, i = 0; 589 | 590 | while (bits >>= 1) { 591 | if ((value & offset[i++]) == 0) { 592 | count += bits; 593 | value <<= bits; 594 | } 595 | } 596 | 597 | return count; 598 | }); 599 | 600 | 601 | /** 602 | * ------------------------------------------------------------ 603 | * Math 604 | * ------------------------------------------------------------ 605 | **/ 606 | 607 | 608 | /** 609 | * Math.log10 610 | * Returns an implementation-dependent approximation to the base 10 logarithm of 611 | * 612 | * @edition ECMA-262 6th Edition, 15.8.2.19 613 | * @param {Number} - value 614 | * @return {Number} 615 | * 616 | * @example: 617 | * 618 | * Number.log10(10) // 0.9999999999999999 619 | **/ 620 | define.call(Math, 'log10', function(value) { 621 | return Math.log(value) * (1 / Math.LN10); 622 | }); 623 | 624 | 625 | /** 626 | * Math.log2 627 | * Returns an implementation-dependent approximation to the base 2 logarithm of 628 | * @edition ECMA-262 6th Edition, 15.8.2.20 629 | * 630 | * @param {Number} - value 631 | * @return {Number} 632 | * 633 | * @example: 634 | * 635 | * Number.log2(10) // 3.3219280948873626 636 | **/ 637 | define.call(Math, 'log2', function(value) { 638 | return Math.log(value) * (1 / Math.LN2); 639 | }); 640 | 641 | 642 | /** 643 | * Math.log1p 644 | * Returns an implementation-dependent approximation to the natural logarithm of 1 + . 645 | * The result is computed in a way that is accurate even when the value of is close to zero. 646 | * 647 | * @edition ECMA-262 6th Edition, 15.8.2.21 648 | * @param {Number} - value 649 | * @return {Number} 650 | * 651 | * @example: 652 | * 653 | * Number.log1p(10) // 2.3978952727983707 654 | **/ 655 | define.call(Math, 'log1p', function(value) { 656 | return (value > -1.0e-8 && value < 1.0e-8) ? (value - value * value / 2) : Math.log(1 + value); 657 | }); 658 | 659 | 660 | /** 661 | * Math. expm1 662 | * Returns an implementation-dependent approximation to subtracting 1 663 | * from the exponential function of The result is computed in a way 664 | * that is accurate even when the of value is close 0. 665 | * @edition ECMA-262 6th Edition, 15.8.2.22 666 | * 667 | * @param {Number} - value 668 | * @requires Object.is 669 | * @return {Number} 670 | * 671 | * @example: 672 | * 673 | * Number.expm1(10) // 22025.465794806718 674 | **/ 675 | define.call(Math, 'expm1', function(value) 676 | { 677 | if (Object.is(value, -0)) 678 | return -0; 679 | 680 | return value > -1.0e-6 && value < 1.0e-6 ? value + value * value / 2 : Math.exp(value) - 1; 681 | }); 682 | 683 | 684 | /** 685 | * Math.cosh 686 | * Returns an implementation-dependent approximation to the hyperbolic cosine of 687 | * 688 | * @edition ECMA-262 6th Edition, 15.8.2.23 689 | * @param {Number} - value 690 | * @requires Object.is 691 | * @return {Number} 692 | * 693 | * @example: 694 | * 695 | * Number.cosh(10) // 11013.232920103324 696 | **/ 697 | define.call(Math, 'cosh', function(value) 698 | { 699 | if (Object.is(value, -Infinity) || value === 0) 700 | return value; 701 | 702 | return (Math.exp(value) + Math.exp(-value)) / 2; 703 | }); 704 | 705 | 706 | /** 707 | * Math.sinh 708 | * @edition ECMA-262 6th Edition, 15.8.2.24 709 | * 710 | * Returns an implementation-dependent approximation to the hyperbolic sine of 711 | * @param {Number} - value 712 | * @return {Number} 713 | * 714 | * @example: 715 | * 716 | * Number.sinh(10) // 11013.232874703393 717 | **/ 718 | define.call(Math, 'sinh', function(value) 719 | { 720 | if (Object.is(value, -Infinity) || value === 0) 721 | return value; 722 | 723 | return (Math.exp(value) - Math.exp(-value)) / 2; 724 | }); 725 | 726 | 727 | /** 728 | * Math.tanh 729 | * Returns an implementation-dependent approximation to the hyperbolic tangent of 730 | * 731 | * @edition ECMA-262 6th Edition, 15.8.2.25 732 | * @param {Number} - value 733 | * @return {Number} 734 | * 735 | * @example: 736 | * 737 | * Number.tanh(10) // 0.9999999958776926 738 | **/ 739 | define.call(Math, 'tanh', function(value) 740 | { 741 | if (Object.is(value, +Infinity)) 742 | return +1; 743 | 744 | else if (Object.is(value, -Infinity)) 745 | return -1; 746 | 747 | return value === 0 ? value : (Math.exp(value) - Math.exp(-value)) / (Math.exp(value) + Math.exp(-value)); 748 | }); 749 | 750 | 751 | /** 752 | * Math.acosh 753 | * Returns an implementation-dependent approximation to the inverse hyperbolic cosine of 754 | * @edition ECMA-262 6th Edition, 15.8.2.26 755 | * 756 | * @param {Number} - value 757 | * @return {Number} 758 | * 759 | * @example: 760 | * 761 | * Number.acosh(10) // 2.993222846126381 762 | **/ 763 | define.call(Math, 'acosh', function(value) { 764 | return Math.log(value + Math.sqrt(value * value - 1)); 765 | }); 766 | 767 | 768 | /** 769 | * Math.asinh 770 | * Returns an implementation-dependent approximation to the inverse hyperbolic sine of 771 | * @edition ECMA-262 6th Edition, 15.8.2.27 772 | 773 | * @param {Number} - value 774 | * @return {Number} 775 | * 776 | * @example: 777 | * 778 | * Number.asinh(10) // 2.99822295029797 779 | **/ 780 | define.call(Math, 'asinh', function(value) 781 | { 782 | if (!Number.isFinite(value) || value === 0) 783 | return value; 784 | 785 | return Math.log(value + Math.sqrt(value * value + 1)); 786 | }); 787 | 788 | 789 | /** 790 | * Math.atanh 791 | * Returns an implementation-dependent approximation to the inverse hyperbolic tangent of 792 | * @edition ECMA-262 6th Edition, 15.8.2.28 793 | * 794 | * @param {Number} - value 795 | * @return {Number} 796 | * 797 | * @example: 798 | * 799 | * Math.atanh(-1) // -Infinity 800 | **/ 801 | define.call(Math, 'atanh', function(value) { 802 | return value === 0 ? value : 0.5 * Math.log((1 + value) / (1 - value)); 803 | }); 804 | 805 | 806 | /** 807 | * Math.hypot 808 | * Given two or three arguments, hypot returns an implementation-dependent approximation 809 | * of the square root of the sum of squares of its arguments. 810 | * @edition ECMA-262 6th Edition, 15.8.2.29 811 | * 812 | * @param {Number} - value 813 | * @return {Number} 814 | * 815 | * @example: 816 | * 817 | * Math.hypot(1, 1) // 1.4142135623730951 818 | **/ 819 | define.call(Math, 'hypot', function(x, y) { 820 | 821 | if (!Number.isFinite(x)) 822 | return x; 823 | 824 | if (!Number.isFinite(y)) 825 | return y; 826 | 827 | return Math.sqrt(x * x + y * y); 828 | }); 829 | 830 | 831 | /** 832 | * Math.trunc 833 | * Returns the integral part of the number , removing any fractional digits. 834 | * If is already an integer, the result is 835 | * @edition ECMA-262 6th Edition, 15.8.2.30 836 | * 837 | * @param {Number} - value 838 | * @requires Number.isFinite 839 | * @return {Number} 840 | * 841 | * @example: 842 | * 843 | * Math.trunc(1.1) // 1 844 | **/ 845 | define.call(Math, 'trunc', function(value) { 846 | value = Number(value); 847 | 848 | if (__global__.isNaN(value) || value === 0 || !Number.isFinite(value)) 849 | return value; 850 | 851 | return Math.sign(value) * Math.floor(Math.abs(value)); 852 | }); 853 | 854 | 855 | /** 856 | * Math.sign 857 | * Returns the sign of the , indicating whether is positive, negative or zero 858 | * @edition ECMA-262 6th Edition, 15.8.2.31 859 | * 860 | * @param {Number} value 861 | * @return {Number} 862 | * 863 | * @example: 864 | * 865 | * Math.sign(-10); // 1 866 | **/ 867 | define.call(Math, 'sign', function(value) { 868 | if (value === 0 /* +0, -0 */ || __global__.isNaN(value)) 869 | return value; 870 | 871 | return value < 0 ? -1 : 1; 872 | }); 873 | 874 | 875 | /** 876 | * Math.cbrt 877 | * Returns an implementation-dependent approximation to the cube root of 878 | * @edition ECMA-262 6th Edition, 15.8.2.32 879 | * 880 | * @param {Number} - value 881 | * @return {Number} 882 | * 883 | * @example: 884 | * 885 | * Math.cbrt(10); // 2.154434690031884 886 | **/ 887 | define.call(Math, 'cbrt', function(value) 888 | { 889 | if (value === 0) 890 | return value; 891 | 892 | return value > 0 ? Math.exp(Math.log(value) / 3) : -Math.exp(Math.log(-value) / 3); 893 | }); 894 | 895 | 896 | /** 897 | * Math.imul 898 | * This operations returns the result of the C-like 32-bit multiplication of the two parameters. 899 | * @edition ECMA-262 6th Edition, 15.8.2.33 900 | * @see https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/imul 901 | * 902 | * @param {Number} - x 903 | * @param {Number} - y 904 | * @return {Number} 905 | * 906 | * @example: 907 | * 908 | * Math.imul(10); // 2.154434690031884 909 | **/ 910 | define.call(Math, 'imul', function(x, y) 911 | { 912 | var xh = (x >>> 0x10) & 0xffff, 913 | xl = x & 0xffff; 914 | 915 | var yh = (y >>> 0x10) & 0xffff, 916 | yl = y & 0xffff; 917 | 918 | return ((xl * yl) + (((xh * yl + xl * yh) << 0x10) >>> 0) | 0); 919 | }); 920 | 921 | 922 | // /** 923 | // * ------------------------------------------------------------ 924 | // * Collections (data structures) 925 | // * ------------------------------------------------------------ 926 | // **/ 927 | // 928 | // /** 929 | // * @private 930 | // * @param {Array} array 931 | // * @param {*} value 932 | // * @requires Object.is 933 | // * @return {Number} 934 | // **/ 935 | // var __find__ = function(array, value) { 936 | // var i = array.length >>> 0; 937 | // 938 | // while (i--) 939 | // if (i in array && Object.is(array[i], value)) 940 | // return i; 941 | // return -1; 942 | // }; 943 | // 944 | // /** 945 | // * Map 946 | // * @edition ECMA-262 6th Edition, 5.14 947 | // * 948 | // * NOTE: Need more compatible with Rev 14! 949 | // * 950 | // * @class 951 | // * @memberOf global 952 | // * 953 | // * @description 954 | // * Map objects are simple key/value maps. Any value (both objects and primitive values) 955 | // * may be used as either a key or a value. Key equality is based on the "same-value" 956 | // * algorithm: NaN is considered the same as NaN (even though NaN !== NaN), -0 and +0 957 | // * are considered distinct (even though -0 === +0), and all other values are considered 958 | // * equal according to the semantics of the === operator. 959 | // * 960 | // * @example: 961 | // * 962 | // * var map = new Map(); 963 | // * 964 | // * // Setting the values 965 | // * map.set(-0, 0); 966 | // * map.set(+0, 1); 967 | // * map.set('b', 2); 968 | // * map.set('a', 3); 969 | // * map.set('a', 4); 970 | // * map.set(Array, 5); 971 | // * map.set([], 6); 972 | // * map.set(NaN, 7); 973 | // * map.set(function() {}, 8); 974 | // * 975 | // * // Getting the values 976 | // * map.get(-0); // 0 977 | // * map.get(+0); // 1 978 | // * map.get('b'); // 2 979 | // * map.get('a'); // 4 980 | // * map.get(Array); // 5 981 | // * map.get([]); // undefined 982 | // * map.get(NaN); // 7 983 | // * map.get(function() {}); // undefined 984 | // * 985 | // * // Removes any value associated to the key 986 | // * map.delete('a'); // true 987 | // * 988 | // * // Check the keys 989 | // * map.has(-0); // true 990 | // * 991 | // * // Getting the number of pairs in Map 992 | // * map.size(); // 7 993 | // * 994 | // * // Iterating over values stored in Set 995 | // * map.__iterator__(function(key, value) { 996 | // * console.log(key, value); 997 | // * }); 998 | // **/ 999 | // define.call(__global__, 'Map', function() 1000 | // { 1001 | // if (!(this instanceof Map)) 1002 | // return new Map; 1003 | // 1004 | // var index = 0; 1005 | // 1006 | // /** @static */ 1007 | // define.call(this, { 1008 | // keys: [], 1009 | // values: [] 1010 | // }); 1011 | // 1012 | // /** 1013 | // * @lends Map.prototype 1014 | // * @constructs 1015 | // **/ 1016 | // define.call(Map.prototype, { 1017 | // /** 1018 | // * Map.get 1019 | // * Returns the value associated to the key, or undefined if there is none. 1020 | // * @param {*} 1021 | // * @return {*} 1022 | // */ 1023 | // get: function(key) 1024 | // { 1025 | // if ((index = __find__(this.keys, key)) !== -1) 1026 | // return this.values[index]; 1027 | // }, 1028 | // 1029 | // /** 1030 | // * Map.set 1031 | // * Sets the value for the key in Map. Returns undefined. 1032 | // * @param {*} key 1033 | // * @param {*} value 1034 | // * @return {void} 1035 | // */ 1036 | // set: function(key, value) 1037 | // { 1038 | // if ((index = __find__(this.keys, key)) === -1) { 1039 | // this.keys.push(key); 1040 | // this.values.push(value); 1041 | // } 1042 | // else 1043 | // this.values[index] = value; 1044 | // }, 1045 | // 1046 | // /** 1047 | // * Map.has 1048 | // * Returns a boolean asserting whether a value has been associated to the key in Map or not 1049 | // * @param {*} key 1050 | // * @return {Boolean} 1051 | // */ 1052 | // has: function(key) { 1053 | // return __find__(this.keys, key) !== -1; 1054 | // }, 1055 | // 1056 | // /** 1057 | // * Map.clear 1058 | // * @return {void} 1059 | // */ 1060 | // clear: function() { 1061 | // this.values.length = 0; 1062 | // this.keys.length = 0; 1063 | // }, 1064 | // 1065 | // /** 1066 | // * Map.delete 1067 | // * Removes any value associated to the key. After such a call, myMap.has(key) will return false. 1068 | // * @param {*} key 1069 | // * @return {Boolean} 1070 | // */ 1071 | // 'delete': function(key) 1072 | // { 1073 | // if ((index = __find__(this.keys, key)) === -1) 1074 | // return false; 1075 | // 1076 | // this.keys.splice(index, 1); 1077 | // this.values.splice(index, 1); 1078 | // 1079 | // return true; 1080 | // }, 1081 | // 1082 | // /** 1083 | // * Map.size 1084 | // * Returns the number of key/value pairs in Map. 1085 | // * @return {Number} 1086 | // */ 1087 | // size: function() { 1088 | // return this.keys.length >>> 0; 1089 | // }, 1090 | // 1091 | // /** 1092 | // * Map.__iterator__ ( Undocumented feature ) 1093 | // * Allow for iterating over Maps and enumerating their keys 1094 | // * @param {Function} callback - is invoked with two arguments (the element key and value) 1095 | // * @param {Object} [ context ] - Object to use as when executing callback 1096 | // * @return {void} 1097 | // */ 1098 | // __iterator__: function(callback, context) 1099 | // { 1100 | // for (var i = 0, length = this.size(); i < length; i++) { 1101 | // if (i in this.keys && i in this.values) 1102 | // if (callback.call(context, this.keys[i], this.values[i]) === false) 1103 | // break; 1104 | // } 1105 | // } 1106 | // }); 1107 | // }); 1108 | // 1109 | // 1110 | // /** 1111 | // * Set 1112 | // * @edition ECMA-262 6th Edition, 5.16 1113 | // * NOTE: Need more compatible with Rev 14! 1114 | // * 1115 | // * @class 1116 | // * @memberOf global 1117 | // * 1118 | // * @description 1119 | // * Set objects let you store unique values of any type, whether primitive values or object references. 1120 | // * Values equality is not based on the same algorithm as the one used in the === operator. 1121 | // * Specifically, for Sets, +0 (which is strictly equal to -0) and -0 are different values. 1122 | // * NaN can also be stored in a Set. 1123 | // * 1124 | // * @example: 1125 | // * 1126 | // * var set = new Set(); 1127 | // * 1128 | // * // Setting the values 1129 | // * 1130 | // * set.add(-0); 1131 | // * set.add(+0); 1132 | // * set.add('b'); 1133 | // * set.add('a'); 1134 | // * set.add('a'); 1135 | // * set.add(Array); 1136 | // * set.add([]); 1137 | // * set.add(function() {}); 1138 | // * set.add(NaN); 1139 | // * 1140 | // * // Check the values 1141 | // * set.has(-0); // true 1142 | // * set.has(+0); // true 1143 | // * set.has('b'); // true 1144 | // * set.has('a'); // true 1145 | // * set.has(Array); // true 1146 | // * set.has([]); // false 1147 | // * set.has(NaN); // true 1148 | // * set.has(function() {}); // false 1149 | // * 1150 | // * // Removes the value 1151 | // * map.delete(-0); // true 1152 | // * 1153 | // * // Getting the number of values in Set 1154 | // * set.size(); // 7 1155 | // * 1156 | // * // Iterating over values stored in Set 1157 | // * set.__iterator__(function(value) { 1158 | // * console.log(value); 1159 | // * }); 1160 | // **/ 1161 | // define.call(__global__, 'Set', function() 1162 | // { 1163 | // if (!(this instanceof Set)) 1164 | // return new Set; 1165 | // 1166 | // var index = 0; 1167 | // 1168 | // /** @static */ 1169 | // define.call(this, { 1170 | // values: [] 1171 | // }); 1172 | // 1173 | // /** 1174 | // * @lends Set.prototype 1175 | // * @constructs 1176 | // **/ 1177 | // define.call(Set.prototype, { 1178 | // /** 1179 | // * Set.add 1180 | // * Adds the value to mySet. Returns undefined. 1181 | // * @param {*} value 1182 | // * @return {void} 1183 | // */ 1184 | // add: function(value) { 1185 | // if ((index = __find__(this.values, value)) === -1) 1186 | // this.values.push(value); 1187 | // else 1188 | // this.values[index] = value; 1189 | // }, 1190 | // 1191 | // /** 1192 | // * Set.has 1193 | // * Returns a boolean asserting whether the value has been added to Set or not 1194 | // * @param {*} value 1195 | // * @return {Boolean} 1196 | // */ 1197 | // has: function(value) { 1198 | // return __find__(this.values, value) !== -1; 1199 | // }, 1200 | // 1201 | // /** 1202 | // * Set.clear 1203 | // * @return {void} 1204 | // */ 1205 | // clear: function() { 1206 | // this.values.length = 0; 1207 | // }, 1208 | // 1209 | // /** 1210 | // * Set.delete 1211 | // * Sets the value for the key in mySet. Returns undefined. 1212 | // * @param {*} key 1213 | // * @return {void} 1214 | // */ 1215 | // 'delete': function(value) { 1216 | // if ((index = __find__(this.values, value)) === -1) 1217 | // return false; 1218 | // 1219 | // this.values.splice(index, 1); 1220 | // 1221 | // return true; 1222 | // }, 1223 | // 1224 | // /** 1225 | // * Set.size() 1226 | // * Returns the number of values in Set. 1227 | // * @return {Number} 1228 | // */ 1229 | // size: function() { 1230 | // return this.values.length >>> 0; 1231 | // }, 1232 | // 1233 | // /** 1234 | // * Set.__iterator__ ( Undocumented feature ) 1235 | // * Allow for iterating over values stored in Set 1236 | // * @param {Function} callback - is invoked with one argument (the element value) 1237 | // * @param {Object} [ context ] - Object to use as when executing callback 1238 | // * @return {void} 1239 | // */ 1240 | // __iterator__: function(callback, context) { 1241 | // for (var i = 0, length = this.size(); i < length; i++) { 1242 | // if (i in this.values) 1243 | // callback.call(context, this.values[i]); 1244 | // } 1245 | // } 1246 | // }); 1247 | // }); 1248 | } 1249 | (Object.prototype, Array.prototype, function() { 1250 | return this; 1251 | }()); 1252 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | # 0.0.10 / 2013-06-03 2 | * [Critical] Removed String.prototype.toArray, Object.isObject.
3 | ES6 Rev 9 (July 8, 2012 Draft)
4 | 5 | * [Critical] Fixed tests for Number.parseInt, Number.parseFloat.
6 | 7 | # 0.0.9 / 2013-06-02 8 | * [Enhancement] Math.imul.
9 | 10 | # 0.0.8 / 2013-06-02 11 | * [Critical] fixed String.prototype.startsWith, String.prototype.endsWith.
12 | 13 | # 0.0.7 / 2013-05-19 14 | * [Enhancement] added proposals.
15 | 16 | # 0.0.6 / 2013-05-16 17 | * [Enhancement] added Object.getOwnPropertyKeys, Object.mixin, Object.assign.
18 | ES6 Rev 14 (March 8, 2013 Draft) 19 | 20 | * [Fix] remove Object.isnt.
21 | ES6 Rev 14 (March 8, 2013 Draft) 22 | 23 | # 0.0.5 / 2013-05-16 24 | * [Enhancement] Array.from now takes an optional map function.
25 | ES6 Rev 14 (March 8, 2013 Draft) 26 | 27 | # 0.0.4 / 2012-09-20 28 | * [Critical] Fixed String.prototype.startsWith, String.prototype.endsWith 29 | 30 | # 0.0.3 / 2012-09-20 31 | * [Critical] Fixed initialization 32 | 33 | # 0.0.2 / 2012-08-26 34 | * Added tests 35 | * Fixed Math, Number, Map 36 | -------------------------------------------------------------------------------- /MIT_LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2012, Alexander Guinness 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ECMAScript 6 Harmony 2 | 3 | ECMAScript 6 Harmony polyfil 4 | 5 | ## Please use https://github.com/paulmillr/es6-shim/ insted! 6 | 7 | 8 | ## Array 9 | 10 | * **Array.of**
11 | *ECMA-262 6th Edition, 15.4.3.3*
12 | 13 | * **Array.from**
14 | *ECMA-262 6th Edition, 15.4.3.4*
15 | 16 | ## String 17 | 18 | * **String.fromCodePoint**
19 | *ECMA-262 6th Edition, 15.5.3.3*
20 | 21 | * **String.prototype.codePointAt**
22 | *ECMA-262 6th Edition, 15.5.4.5*
23 | 24 | * **String.prototype.repeat**
25 | *ECMA-262 6th Edition, 15.5.4.21*
26 | 27 | * **String.prototype.startsWith**
28 | *ECMA-262 6th Edition, 15.5.4.22*
29 | 30 | * **String.prototype.endsWith**
31 | *ECMA-262 6th Edition, 15.5.4.23*
32 | 33 | * **String.prototype.contains**
34 | *ECMA-262 6th Edition, 15.5.4.24*
35 | 36 | * **~~String.prototype.toArray~~**
37 | *~~ECMA-262 6th Edition, 15.5.4.25~~*
38 | 39 | 40 | ## Object 41 | 42 | * **~~Object.isObject~~**
43 | *~~ECMA-262 6th Edition, 15.2.3.15~~*
44 | 45 | * **Object.getOwnPropertyKeys**
46 | *ECMA-262 6th Edition, 15.2.3.15*
47 | 48 | * **Object.is**
49 | *ECMA-262 6th Edition, 15.2.3.16*
50 | 51 | * **Object.assign**
52 | *ECMA-262 6th Edition, 15.2.3.17*
53 | 54 | * **Object.mixin**
55 | *ECMA-262 6th Edition, 15.2.3.18*
56 | 57 | 58 | ## Number 59 | 60 | * **Number.EPSILON**
61 | *ECMA-262 6th Edition, 15.7.3.7*
62 | 63 | * **Number.MAX_INTEGER**
64 | *ECMA-262 6th Edition, 15.7.3.7*
65 | 66 | * **Number.parseInt**
67 | *ECMA-262 6th Edition, 15.7.3.8*
68 | 69 | * **Number.parseFloat**
70 | *ECMA-262 6th Edition, 15.7.3.9*
71 | 72 | * **Number.isNaN**
73 | *ECMA-262 6th Edition, 15.7.3.10*
74 | 75 | * **Number.isFinite**
76 | *ECMA-262 6th Edition, 15.7.3.11*
77 | 78 | * **Number.isInteger**
79 | *ECMA-262 6th Edition, 15.7.3.12*
80 | 81 | * **Number.toInteger**
82 | *ECMA-262 6th Edition, 15.7.3.13*
83 | 84 | * **Number.prototype.clz**
85 | *ECMA-262 6th Edition, 15.7.3.13*
86 | 87 | 88 | ## Math 89 | 90 | * **Math.log10**
91 | *ECMA-262 6th Edition, 15.8.2.19*
92 | 93 | * **Math.log2**
94 | *ECMA-262 6th Edition, 15.8.2.20*
95 | 96 | * **Math.log1p**
97 | *ECMA-262 6th Edition, 15.8.2.21*
98 | 99 | * **Math.expm1**
100 | *ECMA-262 6th Edition, 15.8.2.22*
101 | 102 | * **Math.cosh**
103 | *ECMA-262 6th Edition, 15.8.2.23*
104 | 105 | * **Math.sinh**
106 | *ECMA-262 6th Edition, 15.8.2.24*
107 | 108 | * **Math.tanh**
109 | *ECMA-262 6th Edition, 15.8.2.25*
110 | 111 | * **Math.acosh**
112 | *ECMA-262 6th Edition, 15.8.2.26*
113 | 114 | * **Math.asinh**
115 | *ECMA-262 6th Edition, 15.8.2.27*
116 | 117 | * **Math.atanh**
118 | *ECMA-262 6th Edition, 15.8.2.28*
119 | 120 | * **Math.hypot**
121 | *ECMA-262 6th Edition, 15.8.2.29*
122 | 123 | * **Math.trunc**
124 | *ECMA-262 6th Edition, 15.8.2.30*
125 | 126 | * **Math.sign**
127 | *ECMA-262 6th Edition, 15.8.2.31*
128 | 129 | * **Math.cbrt**
130 | *ECMA-262 6th Edition, 15.8.2.32*
131 | 132 | * **Math.imul**
133 | *ECMA-262 6th Edition, 15.8.2.33*
134 | 135 | 136 | ## Proposals 137 | 138 | * **Object.getOwnPropertyDescriptors**
139 | 140 | * **Object.getPropertyDescriptor**
141 | 142 | * **Object.getPropertyNames**
143 | 144 | * **Object.isnt**
145 | 146 | * **Object.isObject**
147 | 148 | * **String.prototype.toArray**
149 | 150 | 151 | ## TODO 152 | 153 | * *String.prototype.normalize*
154 | * *MapIterator.prototype*
155 | * *RegeExp.prototype...*
156 | 157 | 158 | #### Server-side including 159 | 160 | ```javascript 161 | require('./ES6.js'); 162 | ``` 163 | 164 | #### Client-side including 165 | 166 | ```html 167 | 168 | ``` 169 | 170 | 171 | ## Information 172 | 173 | NOTE: requires ECMAScript 5!
174 |
175 | [ECMAScript 6 compatibility table] (http://kangax.github.com/es5-compat-table/es6/)
176 | [Historical records of working draft of the ECMA-262 6th specification] (http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts)
177 | [Proposals of ECMA-262 6th specification] (http://wiki.ecmascript.org/doku.php?id=harmony:proposals)
178 | 179 | 180 | ##. 181 | 182 | * ECMAScript 6 Harmony polyfil is licensed under the MIT (MIT_LICENSE.txt) license 183 | 184 | * Copyright (c) 2011 [Alexander Guinness] (https://github.com/monolithed) 185 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | - 1.2. WeakMap container 2 | + 1.1. Map/Set containers 3 | + 1.0. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "Alexander Guinness (https://github.com/monolithed)", 3 | "name": "es6", 4 | "title": "ECMAScript 6 polyfill", 5 | "version": "0.0.10", 6 | "description": "Shim to provide ECMAScript 6 Harmony implementation", 7 | "keywords": ["ecmascript", "harmony", "shim", "polyfill", "collections", "data structures", "array", "string", "object", "number"], 8 | 9 | "homepage": "https://github.com/monolithed/ECMAScript-6", 10 | "repository": { 11 | "type": "git", 12 | "url": "git@github.com:monolithed/ECMAScript-6.git" 13 | }, 14 | "bugs": { 15 | "url": "https://github.com/monolithed/ECMAScript-6/issues" 16 | }, 17 | "license": { 18 | "name": "MIT", 19 | "url": "http://www.opensource.org/licenses/mit-license.php" 20 | }, 21 | "main": "./ES6.js", 22 | "engines": { 23 | "node": ">=0.4.9" 24 | }, 25 | "dependencies": {}, 26 | "devDependencies": {} 27 | } 28 | -------------------------------------------------------------------------------- /proposal.js: -------------------------------------------------------------------------------- 1 | // -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- 2 | 3 | /** 4 | * Implementation of ECMAScript 6 (Draft) 5 | * @requires: ECMAScript 5 6 | * @author: Alexander Guinness 7 | * @version: 0.0.1 8 | * @license: MIT 9 | * @date: Thu Nov 1 00:08:00 2011 10 | **/ 11 | 12 | 13 | void function(__object__, __array__, __global__) 14 | { 15 | 'use strict'; 16 | 17 | var define = function(name) 18 | { 19 | var __own__ = __object__.hasOwnProperty; 20 | 21 | if (__own__.call(this, name)) 22 | return 0; 23 | 24 | var set = function(name, value, descriptor) 25 | { 26 | Object.defineProperty(this, name, descriptor || { 27 | value: value, 28 | configurable: true, 29 | enumerable: false, 30 | writable: true 31 | }); 32 | }; 33 | 34 | if (__object__.toString.call(name) === '[object Object]') 35 | { 36 | for (var key in name) { 37 | if (__own__.call(name, key)) 38 | set.call(this, key, name[key]); 39 | } 40 | } 41 | else 42 | set.apply(this, arguments); 43 | }; 44 | 45 | /* 46 | * ------------------------------------------------------------ 47 | * Object 48 | * ------------------------------------------------------------ 49 | */ 50 | 51 | /** 52 | * Object.isObject 53 | * @edition ECMA-262 6th Edition, 15.2.3.15 54 | * Removed in Rev 9 July 8, 2012 ECMA-262 6 Draft 55 | * 56 | * @param {Object} 57 | * @return {Boolean} 58 | * 59 | * @example: 60 | * 61 | * Object.isObject({}); // true 62 | **/ 63 | define.call(Object, 'isObject', function(object) { 64 | return object && __object__.toString.call(object) === '[object Object]'; 65 | }); 66 | 67 | 68 | /** 69 | * Object.getOwnPropertyDescriptors 70 | * @edition proposal 71 | * 72 | * Returns a property descriptor of the specified object, including object’s prototype chain 73 | * @param {Object} object 74 | * Object.getOwnPropertyDescriptor, Array.prototype.forEach 75 | * @throws {TypeError} 76 | * @return {Object} 77 | * 78 | * @example: 79 | * 80 | * var object = {}; 81 | * 82 | * Object.defineProperty(object, 'a', { 83 | * value: 1, 84 | * configurable: false, 85 | * enumerable: false, 86 | * writable: false 87 | * }); 88 | * 89 | * Object.defineProperty(object, 'b', { 90 | * value:2, 91 | * configurable: true, 92 | * enumerable: true, 93 | * writable: true 94 | * }); 95 | * 96 | * Object.getOwnPropertyDescriptors(object); 97 | * 98 | * a: { 99 | * value: 1, 100 | * configurable: false, 101 | * enumerable: false, 102 | * writable: false 103 | * }, 104 | * 105 | * b: { 106 | * value: 2, 107 | * configurable: true, 108 | * enumerable: true, 109 | * writable: true 110 | * } 111 | **/ 112 | define.call(Object, 'getOwnPropertyDescriptors', function(object) 113 | { 114 | if (__object__.toString.call(object) !== '[object Object]') 115 | throw new TypeError('Object.getOwnPropertyDescriptors: ' + object + ' is not an Object!'); 116 | 117 | var descriptors = {}; 118 | 119 | __array__.forEach.call(Object.getOwnPropertyNames(object), function (property) 120 | { 121 | Object.defineProperty(descriptors, property, { 122 | value: Object.getOwnPropertyDescriptor(object, property), 123 | configurable: false, 124 | enumerable: true, 125 | writable: false 126 | }); 127 | }); 128 | 129 | return descriptors; 130 | }); 131 | 132 | 133 | /** 134 | * Object.getPropertyDescriptor 135 | * @edition proposal 136 | * 137 | * Returns a property descriptor of the specified object, including object’s prototype chain 138 | * @param {Object} object 139 | * @param {String} name - The name of the property 140 | * @throws {TypeError} 141 | * @return {Object} 142 | * 143 | * @example: 144 | * 145 | * Object.getPropertyDescriptor({}, 'toString'); 146 | * 147 | * { 148 | * value: [Function: toString], 149 | * writable: true, 150 | * enumerable: false, 151 | * configurable: true 152 | * } 153 | **/ 154 | define.call(Object, 'getPropertyDescriptor', function(object, name) 155 | { 156 | if (__object__.toString.call(object) !== '[object Object]') 157 | throw new TypeError('Object.getPropertyDescriptor: ' + object + ' is not an Object!'); 158 | 159 | var descriptor = Object.getOwnPropertyDescriptor(object, name), 160 | __proto__ = Object.getPrototypeOf(object); 161 | 162 | while (descriptor === undefined && __proto__ !== null) { 163 | descriptor = Object.getOwnPropertyDescriptor(__proto__, name); 164 | __proto__ = Object.getPrototypeOf(__proto__); 165 | } 166 | 167 | return descriptor; 168 | }); 169 | 170 | 171 | /** 172 | * Object.getPropertyNames 173 | * Returns an array of all the names of the properties 174 | * 175 | * @param {Object} object 176 | * @throws {TypeError} 177 | * @edition proposal 178 | * @return {Array} 179 | * 180 | * @example: 181 | * 182 | * Object.getPropertyNames({}); 183 | * 184 | * [ 185 | * 'toString', 186 | * 'toLocaleString', 187 | * 'hasOwnProperty', 188 | * 'valueOf', 189 | * 'constructor', 190 | * 'propertyIsEnumerable', 191 | * 'isPrototypeOf', 192 | * ] 193 | **/ 194 | define.call(Object, 'getPropertyNames', function(object) 195 | { 196 | if (__object__.toString.call(object) !== '[object Object]') 197 | throw new TypeError('Object.getPropertyNames: ' + object + ' is not an Object!'); 198 | 199 | var properies = Object.getOwnPropertyNames(object), 200 | __proto__ = Object.getPrototypeOf(object); 201 | 202 | while (__proto__ !== null) 203 | { 204 | __array__.forEach.call(Object.getOwnPropertyNames(__proto__), function(property) { 205 | if (properies.indexOf(property) === -1) 206 | properies.push(property); 207 | }); 208 | 209 | __proto__ = Object.getPrototypeOf(__proto__); 210 | } 211 | 212 | return properies; 213 | }); 214 | 215 | 216 | /** 217 | * Object.isnt 218 | * Opposed to the Object.isnt 219 | * 220 | * @param {*} - first generic value for egal comparison 221 | * @param {*} - second generic value for egal comparison 222 | * @requires Object.is 223 | * @return {Boolean} 224 | * 225 | * @example: 226 | * 227 | * Object.isnt(0, 0) // false 228 | **/ 229 | define.call(Object, 'isnt', function(x, y) { 230 | return !Object.is(x, y); 231 | }); 232 | 233 | 234 | /** 235 | * String.prototype.toArray 236 | * @edition ECMA-262 6th Edition, 15.5.4.25 237 | * Removed in Rev 9 July 8, 2012 ECMA-262 6 Draft 238 | * 239 | * Creates an array from the specified String object 240 | * @return {Array} Returns an Array object with elements corresponding to 241 | * the characters of this object (converted to a String). 242 | * 243 | * @example: 244 | * 245 | * Hello'.toArray() // ['H', 'e', 'l', 'l', 'o']; 246 | **/ 247 | define.call(String.prototype, 'toArray', function() { 248 | return this.split(''); 249 | }); 250 | 251 | } 252 | (Object.prototype, Array.prototype, function() { 253 | return this; 254 | }()); 255 | -------------------------------------------------------------------------------- /tests/Array.js: -------------------------------------------------------------------------------- 1 | require('../ES6.js'); 2 | require('./suitest.js'); 3 | 4 | /** 5 | * ------------------------------------------------------------ 6 | * Array 7 | * ------------------------------------------------------------ 8 | **/ 9 | 10 | void function(__is__) 11 | { 12 | /* 13 | Array.of 14 | */ 15 | 16 | var isEmptyArray = function(array) { 17 | return Object.prototype.toString.call(array) == '[object Array]' && !array.length; 18 | }; 19 | 20 | new Suitest('Array.of') 21 | 22 | .test('Array.of: returns Array', function() 23 | { 24 | this 25 | .describe("type of Array.of(0, 1) is '[object Array]'") 26 | .exec(__is__.call(Array.of(0, 1)), '[object Array]') 27 | .done(); 28 | }) 29 | 30 | .test('Array.of: converting a variable number of argument to array', function() 31 | { 32 | this 33 | .describe("Array.of(0, 1) are equal [0, 1]'") 34 | .exec((Array.of(0, 1).toString()), [0, 1].toString()).done(); 35 | }); 36 | 37 | /* 38 | Array.from 39 | */ 40 | 41 | new Suitest('Array.from') 42 | 43 | .test('Array.from: returns Array', function() 44 | { 45 | this 46 | .describe("type of Array.from('01') is [object Array]'") 47 | .exec(__is__.call(Array.from('01')), '[object Array]').done(); 48 | }) 49 | 50 | .test('Array.from: converting a string to array', function() 51 | { 52 | this 53 | .describe("Array.from('01') is [0, 1]'") 54 | .exec(Array.from('01').toString(), [0, 1].toString()).done(); 55 | }) 56 | 57 | .test('Array.from: array from arguments', function() 58 | { 59 | this 60 | .describe("Array.from(arguments) converted to [0, 1]") 61 | .exec(function() { 62 | return Array.from(arguments); 63 | }(0, 1), [0, 1].toString()).done(); 64 | }) 65 | 66 | .test('Array.from: [ callback [ value ] ]', function() 67 | { 68 | this 69 | .exec(Array.from('12', function(value) { 70 | return value; 71 | }), '1,2').done(); 72 | }) 73 | 74 | .test('Array.from: [ callback [ index ] ]', function() 75 | { 76 | this 77 | .exec(Array.from('12', function(value, index) { 78 | return index; 79 | }), '0,1').done(); 80 | }) 81 | 82 | .test('Array.from: [ callback [ object ] ]', function() 83 | { 84 | this 85 | .exec(Array.from('12', function(value, index, object) { 86 | return object; 87 | }), '12,12').done(); 88 | }) 89 | 90 | .test('Array.from: [ callback [ value, index ] ]', function() 91 | { 92 | this 93 | .exec(Array.from('12', function(value, index) { 94 | return value + index; 95 | }), '10,21').done(); 96 | }) 97 | 98 | .test('Array.from: [ callback [ value, index, object ] ]', function() 99 | { 100 | this 101 | .exec(Array.from('12', function(value, index, object) { 102 | return value + index + object; 103 | }), '1012,2112').done(); 104 | }) 105 | 106 | .test('Array.from: [callback, context ]', function() 107 | { 108 | var object = {0: 1, 1: 2}; 109 | 110 | this 111 | .exec(Array.from('01', function(value) { 112 | return this[value]; 113 | }, object), '1,2').done(); 114 | }) 115 | 116 | .test('Array.from: [callback, context ]', function() 117 | { 118 | var object = {0: 1, 1: 2}; 119 | 120 | this 121 | .exec(Array.from('01', function(value) { 122 | return this[value]; 123 | }, object), '1,2').done(); 124 | }) 125 | 126 | .test('Array.from: empty string value', function() 127 | { 128 | this 129 | .exec(isEmptyArray(Array.from(''))).done(); 130 | }) 131 | 132 | .test('Array.from: Boolean', function() 133 | { 134 | this 135 | .exec(isEmptyArray(Array.from(true))).done(); 136 | }) 137 | 138 | .test('Array.from: Object', function() 139 | { 140 | this 141 | .exec(isEmptyArray(Array.from({}))).done(); 142 | }) 143 | 144 | .test('Array.from: Array-like object', function() 145 | { 146 | this 147 | .exec(Array.from({0: 1, 1: 2, length: 2}).toString(), '1,2').done(); 148 | }) 149 | 150 | }(Object.prototype.toString); 151 | -------------------------------------------------------------------------------- /tests/Collection.js: -------------------------------------------------------------------------------- 1 | //require('../ES6.js'); 2 | //require('./suitest.js'); 3 | // 4 | ///** 5 | // * ------------------------------------------------------------ 6 | // * Map 7 | // * ------------------------------------------------------------ 8 | //**/ 9 | // 10 | //var map = new Map(); 11 | // 12 | //new Suitest('Map') 13 | // 14 | //.test('Map.set: -0', function() 15 | //{ 16 | // map.set(-0, 0); 17 | // 18 | // this 19 | // .exec(map.get(-0), -0) 20 | // .done(); 21 | //}) 22 | // 23 | //.test('Map.set: +0', function() 24 | //{ 25 | // map.set(+0, 1); 26 | // 27 | // this 28 | // .exec(map.get(+0), 1) 29 | // .done(); 30 | //}) 31 | // 32 | //.test('Map.set: string', function() 33 | //{ 34 | // map.set('b', 2); 35 | // 36 | // this 37 | // .describe("map.get('b'), 2") 38 | // .exec(map.get('b'), 2) 39 | // .done(); 40 | //}) 41 | // 42 | //.test('Map.set: override key', function() 43 | //{ 44 | // map.set('a', 3); 45 | // map.set('a', 4); 46 | // 47 | // this 48 | // .describe("map.set('a', 4)") 49 | // .exec(map.get('a'), 4) 50 | // .done(); 51 | //}) 52 | // 53 | //.test('Map.set: Array', function() 54 | //{ 55 | // map.set(Array, 5); 56 | // 57 | // this 58 | // .describe("map.set(Array, 5)") 59 | // .exec(map.get(Array), 5) 60 | // .done(); 61 | //}) 62 | // 63 | //.test('Map.set: []', function() 64 | //{ 65 | // map.set([], 6); 66 | // 67 | // this 68 | // .describe("map.get([]), undefined") 69 | // .exec(map.get([]), undefined) 70 | // .done(); 71 | //}) 72 | // 73 | //.test('Map.set: NaN', function() 74 | //{ 75 | // map.set(NaN, 7); 76 | // 77 | // this 78 | // .describe("map.set(NaN, 7)") 79 | // .exec(map.get(NaN), 7) 80 | // .done(); 81 | //}) 82 | // 83 | //.test('Map.set: function', function() 84 | //{ 85 | // map.set(function() {}, 8); 86 | // 87 | // this 88 | // .describe("map.set(function() {}, 8)") 89 | // .exec(map.get(function() {}), undefined) 90 | // .done(); 91 | //}) 92 | // 93 | //.test('Map.set: .delete()', function() 94 | //{ 95 | // map.delete('a'); 96 | // 97 | // this 98 | // .describe("map.delete('a')") 99 | // .exec(map.get('a'), undefined) 100 | // .done(); 101 | //}) 102 | // 103 | //.test('Map.set: .has()', function() 104 | //{ 105 | // map.has(-0); 106 | // 107 | // this 108 | // .describe("map.has(-0)") 109 | // .exec(map.has(-0)) 110 | // .done(); 111 | //}) 112 | // 113 | //.test('Map.set: .size()', function() 114 | //{ 115 | // map.size(); 116 | // 117 | // this 118 | // .exec(map.size(), 7) 119 | // .done(); 120 | //}) 121 | // 122 | // 123 | //.test('Map.set: __iterator__', function() 124 | //{ 125 | // var count = 0; 126 | // 127 | // map.__iterator__(function(key, value) { 128 | // count++; 129 | // }); 130 | // 131 | // this 132 | // .describe("map.size()") 133 | // .exec(map.size(), count) 134 | // .done(); 135 | //}) 136 | // 137 | // 138 | //.test('Map.set: .clear()', function() 139 | //{ 140 | // map.clear(); 141 | // 142 | // this 143 | // .exec(map.size(), 0) 144 | // .done(); 145 | //}) 146 | // 147 | // 148 | ///** 149 | // * ------------------------------------------------------------ 150 | // * Set 151 | // * ------------------------------------------------------------ 152 | //**/ 153 | //var set = new Set(); 154 | // 155 | //new Suitest('Set') 156 | // 157 | //.test('Map.set: -0', function() 158 | //{ 159 | // set.add(-0); 160 | // 161 | // this 162 | // .describe("map.add(-0)") 163 | // .exec(set.has(-0)) 164 | // .done(); 165 | //}) 166 | // 167 | //.test('Map.set: +0', function() 168 | //{ 169 | // set.add(+0); 170 | // 171 | // this 172 | // .describe("map.add(+0)") 173 | // .exec(set.has(+0)) 174 | // .done(); 175 | //}) 176 | // 177 | // 178 | //.test('Map.set: string', function() 179 | //{ 180 | // set.add('a'); 181 | // 182 | // this 183 | // .describe("map.add('a')") 184 | // .exec(set.has('a')) 185 | // .done(); 186 | //}) 187 | // 188 | //.test('Map.set: Array', function() 189 | //{ 190 | // set.add(Array); 191 | // 192 | // this 193 | // .describe("map.add(Array)") 194 | // .exec(set.has(Array)) 195 | // .done(); 196 | //}) 197 | // 198 | //.test('Map.set: []', function() 199 | //{ 200 | // set.add([]); 201 | // 202 | // this 203 | // .describe("map.add([])") 204 | // .exec(!set.has([])) 205 | // .done(); 206 | //}) 207 | // 208 | //.test('Map.set: NaN', function() 209 | //{ 210 | // set.add(NaN); 211 | // 212 | // this 213 | // .describe("map.add(NaN)") 214 | // .exec(set.has(NaN)) 215 | // .done(); 216 | //}) 217 | // 218 | //.test('Map.set: function', function() 219 | //{ 220 | // set.add(function() {}); 221 | // 222 | // this 223 | // .describe("map.add(function() {})") 224 | // .exec(!set.has(function() {})) 225 | // .done(); 226 | //}) 227 | // 228 | //.test('Map.set: .delete()', function() 229 | //{ 230 | // set.delete(-0); 231 | // 232 | // this 233 | // .describe("map.delete(-0)") 234 | // .exec(!set.has(-0)) 235 | // .done(); 236 | //}) 237 | // 238 | //.test('Map.set: .size()', function() 239 | //{ 240 | // set.size(); 241 | // 242 | // this 243 | // .describe("map.size()") 244 | // .exec(set.size(), 6) 245 | // .done(); 246 | //}) 247 | // 248 | //.test('Map.set: __iterator__', function() 249 | //{ 250 | // var count = 0; 251 | // 252 | // set.__iterator__(function(value) { 253 | // count++; 254 | // }); 255 | // 256 | // this 257 | // .describe("set.size()") 258 | // .exec(set.size(), count) 259 | // .done(); 260 | //}) 261 | -------------------------------------------------------------------------------- /tests/Math.js: -------------------------------------------------------------------------------- 1 | require('../ES6.js'); 2 | require('./suitest.js'); 3 | 4 | /** 5 | * ------------------------------------------------------------ 6 | * Math 7 | * ------------------------------------------------------------ 8 | **/ 9 | 10 | 11 | /* 12 | Math.log10 13 | */ 14 | 15 | new Suitest('Math.log10') 16 | 17 | .test('Math.log10: > 0', function() 18 | { 19 | this 20 | .exec(Math.ceil(Math.log10(10)), 1) 21 | .done(); 22 | }) 23 | 24 | .test('Math.log10: < 0', function() 25 | { 26 | this 27 | .exec(Math.log10(-10), NaN, 'eg') 28 | .done(); 29 | }) 30 | 31 | .test('Math.log10: NaN', function() 32 | { 33 | this 34 | .exec(Math.log10(NaN), NaN, 'eg') 35 | .done(); 36 | }) 37 | 38 | .test('Math.log10: +0', function() 39 | { 40 | this 41 | .exec(Math.log10(0), -Infinity) 42 | .done(); 43 | }) 44 | 45 | .test('Math.log10: -0', function() 46 | { 47 | this 48 | .exec(Math.log10(-0), -Infinity) 49 | .done(); 50 | }) 51 | 52 | .test('Math.log10: 1', function() 53 | { 54 | this 55 | .exec(Math.log10(1), 0) 56 | .done(); 57 | }) 58 | 59 | .test('Math.log10: +Infinity', function() 60 | { 61 | this 62 | .exec(Math.log10(Infinity), Infinity) 63 | .done(); 64 | }); 65 | 66 | 67 | /* 68 | Math.log2 69 | */ 70 | 71 | new Suitest('Math.log2') 72 | 73 | .test('Math.log2: > 0', function() 74 | { 75 | this 76 | .exec(Math.ceil(Math.log2(10)), 4) 77 | .done(); 78 | }) 79 | 80 | .test('Math.log2: < 0', function() 81 | { 82 | this 83 | .exec(Math.log2(-10), NaN, 'eg') 84 | .done(); 85 | }) 86 | 87 | .test('Math.log2: NaN', function() 88 | { 89 | this 90 | .exec(Math.log2(NaN), NaN, 'eg') 91 | .done(); 92 | }) 93 | 94 | .test('Math.log2: +0', function() 95 | { 96 | this 97 | .exec(Math.log2(0), -Infinity) 98 | .done(); 99 | }) 100 | 101 | .test('Math.log2: -0', function() 102 | { 103 | this 104 | .exec(Math.log2(-0), -Infinity) 105 | .done(); 106 | }) 107 | 108 | .test('Math.log2: 1', function() 109 | { 110 | this 111 | .exec(Math.log2(1), 0) 112 | .done(); 113 | }) 114 | 115 | .test('Math.log2: +Infinity', function() 116 | { 117 | this 118 | .exec(Math.log2(Infinity), Infinity) 119 | .done(); 120 | }); 121 | 122 | 123 | /* 124 | Math.log1p 125 | */ 126 | 127 | new Suitest('Math.log1p') 128 | 129 | .test('Math.log1p: > 0', function() 130 | { 131 | this 132 | .exec(Math.ceil(Math.log1p(10)), 3) 133 | .done(); 134 | }) 135 | 136 | .test('Math.log1p: < -1', function() 137 | { 138 | this 139 | .exec(Math.log1p(-10), NaN, 'eg') 140 | .done(); 141 | }) 142 | 143 | .test('Math.log1p: NaN', function() 144 | { 145 | this 146 | .exec(Math.log1p(NaN), NaN, 'eg') 147 | .done(); 148 | }) 149 | 150 | .test('Math.log1p: +0', function() 151 | { 152 | this 153 | .exec(Math.log1p(0), 0, 'eg') 154 | .done(); 155 | }) 156 | 157 | .test('Math.log1p: -0', function() 158 | { 159 | this 160 | .exec(Math.log1p(-0), -0, 'eg') 161 | .done(); 162 | }) 163 | 164 | .test('Math.log1p: +Infinity', function() 165 | { 166 | this 167 | .exec(Math.log1p(Infinity), Infinity) 168 | .done(); 169 | }); 170 | 171 | 172 | /* 173 | Math.expm1 174 | */ 175 | 176 | new Suitest('Math.expm1') 177 | 178 | .test('Math.expm1: NaN', function() 179 | { 180 | this 181 | .exec(Math.expm1(NaN), NaN, 'eg') 182 | .done(); 183 | }) 184 | 185 | .test('Math.expm1: +0', function() 186 | { 187 | this 188 | .exec(Math.expm1(0), 0, 'eg') 189 | .done(); 190 | }) 191 | 192 | .test('Math.expm1: -0', function() 193 | { 194 | this 195 | .exec(Math.expm1(-0), -0, 'eg') 196 | .done(); 197 | }) 198 | 199 | .test('Math.expm1: +Infinity', function() 200 | { 201 | this 202 | .exec(Math.expm1(Infinity), Infinity) 203 | .done(); 204 | }) 205 | 206 | .test('Math.expm1: -Infinity', function() 207 | { 208 | this 209 | .exec(Math.expm1(-Infinity), -1) 210 | .done(); 211 | }); 212 | 213 | 214 | /* 215 | Math.cosh 216 | */ 217 | 218 | new Suitest('Math.cosh') 219 | 220 | .test('Math.cosh: NaN', function() 221 | { 222 | this 223 | .exec(Math.cosh(NaN), NaN, 'eg') 224 | .done(); 225 | }) 226 | 227 | .test('Math.cosh: +0', function() 228 | { 229 | this 230 | .exec(Math.expm1(0), 0, 'eg') 231 | .done(); 232 | }) 233 | 234 | .test('Math.cosh: -0', function() 235 | { 236 | this 237 | .exec(Math.cosh(-0), -0, 'eg') 238 | .done(); 239 | }) 240 | 241 | .test('Math.cosh: +Infinity', function() 242 | { 243 | this 244 | .exec(Math.cosh(Infinity), Infinity) 245 | .done(); 246 | }) 247 | 248 | .test('Math.cosh: -Infinity', function() 249 | { 250 | this 251 | .exec(Math.cosh(-Infinity), -Infinity) 252 | .done(); 253 | }); 254 | 255 | 256 | /* 257 | Math.sinh 258 | */ 259 | 260 | new Suitest('Math.sinh') 261 | 262 | .test('Math.sinh: NaN', function() 263 | { 264 | this 265 | .exec(Math.sinh(NaN), NaN, 'eg') 266 | .done(); 267 | }) 268 | 269 | .test('Math.sinh: +0', function() 270 | { 271 | this 272 | .exec(Math.sinh(0), 0, 'eg') 273 | .done(); 274 | }) 275 | 276 | .test('Math.sinh: -0', function() 277 | { 278 | this 279 | .exec(Math.sinh(-0), -0, 'eg') 280 | .done(); 281 | }) 282 | 283 | .test('Math.sinh: +Infinity', function() 284 | { 285 | this 286 | .exec(Math.sinh(Infinity), Infinity) 287 | .done(); 288 | }) 289 | 290 | .test('Math.sinh: -Infinity', function() 291 | { 292 | this 293 | .exec(Math.sinh(-Infinity), -Infinity) 294 | .done(); 295 | }); 296 | 297 | 298 | /* 299 | Math.tanh 300 | */ 301 | 302 | new Suitest('Math.tanh') 303 | 304 | .test('Math.tanh: NaN', function() 305 | { 306 | this 307 | .exec(Math.tanh(NaN), NaN, 'eg') 308 | .done(); 309 | }) 310 | 311 | .test('Math.tanh: +0', function() 312 | { 313 | this 314 | .exec(Math.tanh(0), 0, 'eg') 315 | .done(); 316 | }) 317 | 318 | .test('Math.tanh: -0', function() 319 | { 320 | this 321 | .exec(Math.tanh(-0), -0, 'eg') 322 | .done(); 323 | }) 324 | 325 | .test('Math.tanh: +Infinity', function() 326 | { 327 | this 328 | .exec(Math.tanh(+Infinity), 1, 'eg') 329 | .done(); 330 | }) 331 | 332 | .test('Math.tanh: -Infinity', function() 333 | { 334 | this 335 | .exec(Math.tanh(-Infinity), -1, 'eg') 336 | .done(); 337 | }) 338 | 339 | .test('Math.tanh: > 0', function() 340 | { 341 | this 342 | .exec(Math.ceil(Math.tanh(10)), 1) 343 | .done(); 344 | }) 345 | 346 | .test('Math.tanh: < 0', function() 347 | { 348 | this 349 | .exec(Math.ceil(Math.tanh(-10)), 0) 350 | .done(); 351 | }); 352 | 353 | 354 | /* 355 | Math.acosh 356 | */ 357 | 358 | new Suitest('Math.acosh') 359 | 360 | .test('Math.acosh: NaN', function() 361 | { 362 | this 363 | .exec(Math.acosh(NaN), NaN, 'eg') 364 | .done(); 365 | }) 366 | 367 | .test('Math.acosh: < 1', function() 368 | { 369 | this 370 | .exec(Math.acosh(0), NaN, 'eg') 371 | .done(); 372 | }) 373 | 374 | .test('Math.tanh: 1', function() 375 | { 376 | this 377 | .exec(Math.acosh(1), +0, 'eg') 378 | .done(); 379 | }) 380 | 381 | .test('Math.acosh: +Infinity', function() 382 | { 383 | this 384 | .exec(Math.acosh(+Infinity), +Infinity, 'eg') 385 | .done(); 386 | }) 387 | 388 | .test('Math.acosh: > 0', function() 389 | { 390 | this 391 | .exec(Math.ceil(Math.acosh(10)), 3) 392 | .done(); 393 | }); 394 | 395 | 396 | /* 397 | Math.asinh 398 | */ 399 | 400 | new Suitest('Math.asinh') 401 | 402 | .test('Math.asinh: NaN', function() 403 | { 404 | this 405 | .exec(Math.asinh(NaN), NaN, 'eg') 406 | .done(); 407 | }) 408 | 409 | .test('Math.asinh: +0', function() 410 | { 411 | this 412 | .exec(Math.asinh(0), 0, 'eg') 413 | .done(); 414 | }) 415 | 416 | .test('Math.asinh: -0', function() 417 | { 418 | this 419 | .exec(Math.asinh(-0), -0, 'eg') 420 | .done(); 421 | }) 422 | 423 | .test('Math.asinh: +Infinity', function() 424 | { 425 | this 426 | .exec(Math.asinh(+Infinity), +Infinity, 'eg') 427 | .done(); 428 | }) 429 | 430 | .test('Math.asinh: -Infinity', function() 431 | { 432 | this 433 | .exec(Math.asinh(-Infinity), -Infinity, 'eg') 434 | .done(); 435 | }) 436 | 437 | .test('Math.asinh: > 0', function() 438 | { 439 | this 440 | .exec(Math.ceil(Math.asinh(10)), 3) 441 | .done(); 442 | }) 443 | 444 | .test('Math.asinh: < 0', function() 445 | { 446 | this 447 | .exec(Math.ceil(Math.asinh(-10)), -2) 448 | .done(); 449 | }); 450 | 451 | 452 | /* 453 | Math.atanh 454 | */ 455 | 456 | new Suitest('Math.atanh') 457 | 458 | .test('Math.atanh: NaN', function() 459 | { 460 | this 461 | .exec(Math.atanh(NaN), NaN, 'eg') 462 | .done(); 463 | }) 464 | 465 | .test('Math.atanh: < -1', function() 466 | { 467 | this 468 | .exec(Math.atanh(-10), NaN, 'eg') 469 | .done(); 470 | }) 471 | 472 | .test('Math.atanh: > 1', function() 473 | { 474 | this 475 | .exec(Math.atanh(10), NaN, 'eg') 476 | .done(); 477 | }) 478 | 479 | .test('Math.atanh: -1', function() 480 | { 481 | this 482 | .exec(Math.atanh(-1), -Infinity, 'eg') 483 | .done(); 484 | }) 485 | 486 | .test('Math.atanh: +1', function() 487 | { 488 | this 489 | .exec(Math.atanh(+1), +Infinity, 'eg') 490 | .done(); 491 | }) 492 | 493 | .test('Math.atanh: +0', function() 494 | { 495 | this 496 | .exec(Math.atanh(0), 0, 'eg') 497 | .done(); 498 | }) 499 | 500 | .test('Math.atanh: -0', function() 501 | { 502 | this 503 | .exec(Math.atanh(-0), -0, 'eg') 504 | .done(); 505 | }); 506 | 507 | 508 | /* 509 | Math.hypot 510 | */ 511 | 512 | new Suitest('Math.hypot') 513 | 514 | .test('Math.hypot: +Infinity', function() 515 | { 516 | this 517 | .exec(Math.hypot(+Infinity, 1), +Infinity, 'eg') 518 | .done(); 519 | }) 520 | 521 | .test('Math.hypot: -Infinity', function() 522 | { 523 | this 524 | .exec(Math.hypot(-Infinity, 1), -Infinity, 'eg') 525 | .done(); 526 | }) 527 | 528 | .test('Math.hypot: NaN', function() 529 | { 530 | this 531 | .exec(Math.hypot(NaN, 1), NaN, 'eg') 532 | .done(); 533 | }) 534 | 535 | .test('Math.hypot: +0', function() 536 | { 537 | this 538 | .exec(Math.hypot(0, 0), 0, 'eg') 539 | .done(); 540 | }) 541 | 542 | .test('Math.hypot: -0', function() 543 | { 544 | this 545 | .exec(Math.hypot(-0, -0), 0, 'eg') 546 | .done(); 547 | }); 548 | 549 | 550 | /* 551 | Math.trunc 552 | */ 553 | 554 | new Suitest('Math.trunc') 555 | 556 | .test('Math.trunc: NaN', function() 557 | { 558 | this 559 | .exec(Math.trunc(NaN), NaN, 'eg') 560 | .done(); 561 | }) 562 | 563 | .test('Math.trunc: +0', function() 564 | { 565 | this 566 | .exec(Math.trunc(+0), +0, 'eg') 567 | .done(); 568 | }) 569 | 570 | .test('Math.trunc: -0', function() 571 | { 572 | this 573 | .exec(Math.trunc(-0), -0, 'eg') 574 | .done(); 575 | }) 576 | 577 | .test('Math.trunc: +Infinity', function() 578 | { 579 | this 580 | .exec(Math.trunc(+Infinity), +Infinity, 'eg') 581 | .done(); 582 | }) 583 | 584 | .test('Math.trunc: -Infinity', function() 585 | { 586 | this 587 | .exec(Math.trunc(-Infinity), -Infinity, 'eg') 588 | .done(); 589 | }) 590 | 591 | .test('Math.trunc: float', function() 592 | { 593 | this 594 | .exec(Math.trunc(0.1), 0, 'eg') 595 | .done(); 596 | }) 597 | 598 | 599 | .test('Math.trunc: 1e+211', function() 600 | { 601 | this 602 | .exec(Math.trunc(1e+21), 1e+21, 'eg') 603 | .done(); 604 | }) 605 | 606 | .test('Math.trunc: -1e+211', function() 607 | { 608 | this 609 | .exec(Math.trunc(-1e+21), -1e+21, 'eg') 610 | .done(); 611 | }); 612 | 613 | 614 | /* 615 | Math.sign 616 | */ 617 | 618 | new Suitest('Math.sign') 619 | 620 | .test('Math.sign: NaN', function() 621 | { 622 | this 623 | .exec(Math.sign(NaN), NaN, 'eg') 624 | .done(); 625 | }) 626 | 627 | .test('Math.sign: +0', function() 628 | { 629 | this 630 | .exec(Math.sign(+0), +0, 'eg') 631 | .done(); 632 | }) 633 | 634 | .test('Math.trunc: -0', function() 635 | { 636 | this 637 | .exec(Math.sign(-0), -0, 'eg') 638 | .done(); 639 | }) 640 | 641 | .test('Math.sign: +1', function() 642 | { 643 | this 644 | .exec(Math.sign(+1), +1, 'eg') 645 | .done(); 646 | }) 647 | 648 | .test('Math.sign: -1', function() 649 | { 650 | this 651 | .exec(Math.sign(-1), -1, 'eg') 652 | .done(); 653 | }); 654 | 655 | 656 | /* 657 | Math.cbrt 658 | */ 659 | 660 | new Suitest('Math.cbrt') 661 | 662 | .test('Math.cbrt: NaN', function() 663 | { 664 | this 665 | .exec(Math.cbrt(NaN), NaN, 'eg') 666 | .done(); 667 | }) 668 | 669 | .test('Math.cbrt: +0', function() 670 | { 671 | this 672 | .exec(Math.cbrt(+0), +0, 'eg') 673 | .done(); 674 | }) 675 | 676 | .test('Math.cbrt: -0', function() 677 | { 678 | this 679 | .exec(Math.cbrt(-0), -0, 'eg') 680 | .done(); 681 | }) 682 | 683 | .test('Math.cbrt: +Infinity', function() 684 | { 685 | this 686 | .exec(Math.cbrt(+Infinity), +Infinity, 'eg') 687 | .done(); 688 | }) 689 | 690 | .test('Math.cbrt: -Infinity', function() 691 | { 692 | this 693 | .exec(Math.cbrt(-Infinity), -Infinity, 'eg') 694 | .done(); 695 | }); 696 | 697 | 698 | /* 699 | * Math.imul 700 | * @see https://bugs.webkit.org/show_bug.cgi?id=115143 701 | */ 702 | 703 | new Suitest('Math.imul') 704 | 705 | .test('Math.imul: Math.imul(1, 0.5)', function() 706 | { 707 | this 708 | .exec(Math.imul(1, 0.5), 0) 709 | .done(); 710 | }) 711 | 712 | .test('Math.imul: Math.imul(1, -0.5)', function() 713 | { 714 | this 715 | .exec(Math.imul(1, -0.5), 0) 716 | .done(); 717 | }) 718 | 719 | .test('Math.imul: Math.imul(2, 1 << 30)', function() 720 | { 721 | this 722 | .exec(Math.imul(2, 1 << 30), -2147483648) 723 | .done(); 724 | }) 725 | 726 | .test('Math.imul: Math.imul(4, 1 << 30)', function() 727 | { 728 | this 729 | .exec(Math.imul(4, 1 << 30), 0) 730 | .done(); 731 | }) 732 | 733 | .test('Math.imul: Math.imul(1, NaN)', function() 734 | { 735 | this 736 | .exec(Math.imul(1, NaN), 0) 737 | .done(); 738 | }) 739 | 740 | .test('Math.imul: Math.imul(1, Infinity)', function() 741 | { 742 | this 743 | .exec(Math.imul(1, Infinity), 0) 744 | .done(); 745 | }) 746 | 747 | .test('Math.imul: Math.imul(0.5, 1)', function() 748 | { 749 | this 750 | .exec(Math.imul(0.5, 1), 0) 751 | .done(); 752 | }) 753 | 754 | .test('Math.imul: Math.imul(-0.5, 1)', function() 755 | { 756 | this 757 | .exec(Math.imul(-0.5, 1), 0) 758 | .done(); 759 | }) 760 | 761 | .test('Math.imul: Math.imul(1 << 30, 2)', function() 762 | { 763 | this 764 | .exec(Math.imul(1 << 30, 2), -2147483648) 765 | .done(); 766 | }) 767 | 768 | .test('Math.imul: Math.imul(1 << 30, 4)', function() 769 | { 770 | this 771 | .exec(Math.imul(1 << 30, 4), 0) 772 | .done(); 773 | }) 774 | 775 | .test('Math.imul: Math.imul(NaN, 1)', function() 776 | { 777 | this 778 | .exec(Math.imul(NaN, 1), 0) 779 | .done(); 780 | }) 781 | 782 | .test('Math.imul: Math.imul(Infinity, 1)', function() 783 | { 784 | this 785 | .exec(Math.imul(Infinity, 1), 0) 786 | .done(); 787 | }) 788 | 789 | .test('Math.imul: Math.imul(NaN, NaN, 2)', function() 790 | { 791 | this 792 | .exec(Math.imul(NaN, NaN, 2), 0) 793 | .done(); 794 | }) 795 | 796 | .test('Math.imul: Math.imul(Infinity, Infinity, 2)', function() 797 | { 798 | this 799 | .exec(Math.imul(Infinity, Infinity, 2), 0) 800 | .done(); 801 | }) 802 | 803 | .test('Math.imul: Math.imul(Infinity, -Infinity)', function() 804 | { 805 | this 806 | .exec(Math.imul(Infinity, -Infinity), 0) 807 | .done(); 808 | }) 809 | 810 | .test('Math.imul: Math.imul(-Infinity, Infinity)', function() 811 | { 812 | this 813 | .exec(Math.imul(-Infinity, Infinity), 0) 814 | .done(); 815 | }) 816 | 817 | .test('Math.imul: Math.imul(-Infinity, -Infinity)', function() 818 | { 819 | this 820 | .exec(Math.imul(-Infinity, -Infinity), 0) 821 | .done(); 822 | }) 823 | 824 | .test('Math.imul: Math.imul(2, 2)', function() 825 | { 826 | this 827 | .exec(Math.imul(2, 2), 4) 828 | .done(); 829 | }) 830 | 831 | .test('Math.imul: Math.imul(2.5, 2)', function() 832 | { 833 | this 834 | .exec(Math.imul(2.5, 2), 4) 835 | .done(); 836 | }) 837 | 838 | .test('Math.imul: Math.imul(2.5, 2)', function() 839 | { 840 | this 841 | .exec(Math.imul(2.5, 2), 4) 842 | .done(); 843 | }) 844 | 845 | .test('Math.imul: Math.imul(2, 2.5)', function() 846 | { 847 | this 848 | .exec(Math.imul(2, 2.5), 4) 849 | .done(); 850 | }) 851 | 852 | .test('Math.imul: Math.imul(2.5, 2)', function() 853 | { 854 | this 855 | .exec(Math.imul(2.5, 2), 4) 856 | .done(); 857 | }) 858 | 859 | .test('Math.imul: Math.imul(2.5, 2.5)', function() 860 | { 861 | this 862 | .exec(Math.imul(2.5, 2.5), 4) 863 | .done(); 864 | }) 865 | 866 | .test('Math.imul: Math.imul(-2, -2)', function() 867 | { 868 | this 869 | .exec(Math.imul(-2, -2), 4) 870 | .done(); 871 | }) 872 | 873 | .test('Math.imul: Math.imul(-2.5, -2)', function() 874 | { 875 | this 876 | .exec(Math.imul(-2.5, -2), 4) 877 | .done(); 878 | }) 879 | 880 | .test('Math.imul: Math.imul(-2.5, -2)', function() 881 | { 882 | this 883 | .exec(Math.imul(-2.5, -2), 4) 884 | .done(); 885 | }) 886 | 887 | .test('Math.imul: Math.imul(-2, -2.5)', function() 888 | { 889 | this 890 | .exec(Math.imul(-2, -2.5), 4) 891 | .done(); 892 | }) 893 | 894 | .test('Math.imul: Math.imul(-2.5, -2)', function() 895 | { 896 | this 897 | .exec(Math.imul(-2.5, -2), 4) 898 | .done(); 899 | }) 900 | 901 | .test('Math.imul: Math.imul(-2.5, -2.5)', function() 902 | { 903 | this 904 | .exec(Math.imul(-2.5, -2.5), 4) 905 | .done(); 906 | }) 907 | 908 | .test('Math.imul: Math.imul(-2, 2)', function() 909 | { 910 | this 911 | .exec(Math.imul(-2, 2), -4) 912 | .done(); 913 | }) 914 | 915 | .test('Math.imul: Math.imul(-2.5, 2)', function() 916 | { 917 | this 918 | .exec(Math.imul(-2.5, 2), -4) 919 | .done(); 920 | }) 921 | 922 | .test('Math.imul: Math.imul(-2.5, 2)', function() 923 | { 924 | this 925 | .exec(Math.imul(-2.5, 2), -4) 926 | .done(); 927 | }) 928 | 929 | .test('Math.imul: Math.imul(-2, 2.5)', function() 930 | { 931 | this 932 | .exec(Math.imul(-2, 2.5), -4) 933 | .done(); 934 | }) 935 | 936 | .test('Math.imul: Math.imul(-2.5, 2)', function() 937 | { 938 | this 939 | .exec(Math.imul(-2.5, 2), -4) 940 | .done(); 941 | }) 942 | 943 | .test('Math.imul: Math.imul(-2.5, 2.5)', function() 944 | { 945 | this 946 | .exec(Math.imul(-2.5, 2.5), -4) 947 | .done(); 948 | }) 949 | 950 | .test('Math.imul: Math.imul(2, -2)', function() 951 | { 952 | this 953 | .exec(Math.imul(2, -2), -4) 954 | .done(); 955 | }) 956 | 957 | .test('Math.imul: Math.imul(2.5, -2)', function() 958 | { 959 | this 960 | .exec(Math.imul(2.5, -2), -4) 961 | .done(); 962 | }) 963 | 964 | .test('Math.imul: Math.imul(2.5, -2)', function() 965 | { 966 | this 967 | .exec(Math.imul(2.5, -2), -4) 968 | .done(); 969 | }) 970 | 971 | .test('Math.imul: Math.imul(2, -2.5)', function() 972 | { 973 | this 974 | .exec(Math.imul(2, -2.5), -4) 975 | .done(); 976 | }) 977 | 978 | .test('Math.imul: Math.imul(2.5, -2)', function() 979 | { 980 | this 981 | .exec(Math.imul(2.5, -2), -4) 982 | .done(); 983 | }) 984 | 985 | .test('Math.imul: Math.imul(2.5, -2.5)', function() 986 | { 987 | this 988 | .exec(Math.imul(2.5, -2.5), -4) 989 | .done(); 990 | }) 991 | 992 | .test('Math.imul: Math.imul(NaN, 1)', function() 993 | { 994 | this 995 | .exec(Math.imul(NaN, 1), 0) 996 | .done(); 997 | }) 998 | 999 | .test('Math.imul: Math.imul(Infinity, 1)', function() 1000 | { 1001 | this 1002 | .exec(Math.imul(Infinity, 1), 0) 1003 | .done(); 1004 | }) 1005 | 1006 | .test('Math.imul: Math.imul(1e40, 1)', function() 1007 | { 1008 | this 1009 | .exec(Math.imul(1e40, 1), 0) 1010 | .done(); 1011 | }) 1012 | 1013 | .test('Math.imul: Math.imul(0xffffffff, 5)', function() 1014 | { 1015 | this 1016 | .exec(Math.imul(0xffffffff, 5), -5) 1017 | .done(); 1018 | }) 1019 | 1020 | .test('Math.imul: Math.imul(0xfffffffe, 5)', function() 1021 | { 1022 | this 1023 | .exec(Math.imul(0xfffffffe, 5), -10) 1024 | .done(); 1025 | }) 1026 | 1027 | .test('Math.imul: Math.imul(1, NaN)', function() 1028 | { 1029 | this 1030 | .exec(Math.imul(1, NaN), 0) 1031 | .done(); 1032 | }) 1033 | 1034 | .test('Math.imul: Math.imul(1, Infinity)', function() 1035 | { 1036 | this 1037 | .exec(Math.imul(1, Infinity), 0) 1038 | .done(); 1039 | }) 1040 | 1041 | .test('Math.imul: Math.imul(1, 1e40)', function() 1042 | { 1043 | this 1044 | .exec(Math.imul(1, 1e40), 0) 1045 | .done(); 1046 | }) 1047 | -------------------------------------------------------------------------------- /tests/Number.js: -------------------------------------------------------------------------------- 1 | require('../ES6.js'); 2 | require('./suitest.js'); 3 | 4 | /** 5 | * ------------------------------------------------------------ 6 | * Number 7 | * ------------------------------------------------------------ 8 | **/ 9 | 10 | /* 11 | Number.EPSILON 12 | */ 13 | 14 | new Suitest('Number.EPSILON') 15 | 16 | .test('Number.EPSILON', function() 17 | { 18 | this 19 | .exec(Number.EPSILON, 2.220446049250313e-16) 20 | .done(); 21 | }); 22 | 23 | /* 24 | Number.MAX_INTEGER 25 | */ 26 | new Suitest('Number.MAX_INTEGER') 27 | 28 | .test('Number.EPSILON', function() 29 | { 30 | this 31 | .exec(Number.MAX_INTEGER, 9007199254740991) 32 | .done(); 33 | }); 34 | 35 | /* 36 | Number.parseInt 37 | */ 38 | 39 | new Suitest('Number.parseInt') 40 | 41 | .test('Number.parseInt: E+2*', function() 42 | { 43 | this 44 | .describe("Number.parseInt(1000000000000000000000) is 1") 45 | .exec(Number.parseInt(1000000000000000000000), 1) 46 | .done(); 47 | }) 48 | 49 | .test('Number.parseInt: 32 radix', function() 50 | { 51 | this 52 | .describe("Number.parseInt((10).toString(32), 32) is 10") 53 | .exec(Number.parseInt((10).toString(32), 32), 10) 54 | .done(); 55 | }) 56 | 57 | .test('Number.parseInt: 16 radix', function() 58 | { 59 | this 60 | .describe("Number.parseInt((10).toString(16), 16) is 10") 61 | .exec(Number.parseInt((10).toString(16), 16), 10) 62 | .done(); 63 | }) 64 | 65 | .test('Number.parseInt: 10', function() 66 | { 67 | this 68 | .describe("Number.parseInt(10) is 10") 69 | .exec(Number.parseInt(10), 10) 70 | .done(); 71 | }) 72 | 73 | .test('Number.parseInt: 8 radix', function() 74 | { 75 | this 76 | .describe("Number.parseInt((10).toString(8), 8) is 10") 77 | .exec(Number.parseInt((10).toString(8), 8), 10) 78 | .done(); 79 | }) 80 | 81 | .test('Number.parseInt: 2 radix', function() 82 | { 83 | this 84 | .describe("Number.parseInt((10).toString(2) is 10") 85 | .exec(Number.parseInt((10).toString(2), 2), 10) 86 | .done(); 87 | }) 88 | 89 | .test('Number.parseInt: int', function() 90 | { 91 | this 92 | .describe("Number.parseInt('10px') is 10") 93 | .exec(Number.parseInt('10px'), 10) 94 | .done(); 95 | }) 96 | 97 | .test('Number.parseInt: float', function() 98 | { 99 | this 100 | .describe("Number.parseInt(10.1) is 10") 101 | .exec(Number.parseInt(10.1), 10) 102 | .done(); 103 | }) 104 | 105 | .test('Number.parseInt: E+', function() 106 | { 107 | this 108 | .describe("Number.parseInt(0.100E+2) is 10") 109 | .exec(Number.parseInt(0.100E+2), 10) 110 | .done(); 111 | }) 112 | 113 | .test('Number.parseInt: E-', function() 114 | { 115 | this 116 | .describe("Number.parseInt(10.1) is 10") 117 | .exec(Number.parseInt(1000E-2), 10) 118 | .done(); 119 | }) 120 | 121 | .test('Number.parseInt: NaN', function() 122 | { 123 | this 124 | .describe("Number.parseInt('i10') is NaN") 125 | .exec(Number.parseInt('i10'), NaN, 'eg') 126 | .done(); 127 | }); 128 | 129 | /* 130 | Number.parseFloat 131 | */ 132 | 133 | new Suitest('Number.parseFloat') 134 | 135 | .test('Number.parseInt: E+2*', function() 136 | { 137 | this 138 | .describe("Number.parseFloat(1000000000000000000000) is 1e+21") 139 | .exec(Number.parseFloat(1000000000000000000000), 1e+21) 140 | .done(); 141 | }) 142 | 143 | .test('Number.parseFloat: 10', function() 144 | { 145 | this 146 | .describe("Number.parseFloat(10) is 10") 147 | .exec(Number.parseFloat(10), 10) 148 | .done(); 149 | }) 150 | 151 | .test('Number.parseFloat: int', function() 152 | { 153 | this 154 | .describe("Number.parseFloat('10px') is 10") 155 | .exec(Number.parseFloat('10px'), 10) 156 | .done(); 157 | }) 158 | 159 | .test('Number.parseFloat: float', function() 160 | { 161 | this 162 | .describe("Number.parseFloat(10.1) is 10") 163 | .exec(Number.parseFloat(10.1), 10.1) 164 | .done(); 165 | }) 166 | 167 | .test('Number.parseInt: E+', function() 168 | { 169 | this 170 | .describe("Number.parseFloat(0.100E+2) is 10") 171 | .exec(Number.parseInt(0.100E+2), 10) 172 | .done(); 173 | }) 174 | 175 | .test('Number.parseFloat: E-', function() 176 | { 177 | this 178 | .describe("Number.parseFloat(10.1) is 10") 179 | .exec(Number.parseFloat(1000E-2), 10) 180 | .done(); 181 | }); 182 | 183 | /* 184 | Number.isNaN 185 | */ 186 | 187 | new Suitest('Number.isNaN') 188 | 189 | .test('Number.isNaN: int', function() 190 | { 191 | this 192 | .describe("Number.isNaN(10) is not a number") 193 | .exec(!Number.isNaN(10)) 194 | .done(); 195 | }) 196 | 197 | .test('Number.isNaN: NaN', function() 198 | { 199 | this 200 | .describe("Number.isNaN(NaN) is a number") 201 | .exec(Number.isNaN(NaN)) 202 | .done(); 203 | }) 204 | 205 | .test('Number.isNaN: []', function() 206 | { 207 | this 208 | .describe("Number.isNaN([]) is a number") 209 | .exec(!Number.isNaN([])) 210 | .done(); 211 | }); 212 | 213 | /* 214 | Number.isFinite 215 | */ 216 | 217 | new Suitest('Number.isFinite') 218 | 219 | .test('Number.isFinite: int', function() 220 | { 221 | this 222 | .describe("Number.isFinite(10) is a finite number") 223 | .exec(Number.isFinite(10)) 224 | .done(); 225 | }) 226 | 227 | .test('Number.isFinite: float', function() 228 | { 229 | this 230 | .describe("Number.isFinite(10.1) is a finite number") 231 | .exec(Number.isFinite(10.1)) 232 | .done(); 233 | }) 234 | 235 | .test('Number.isFinite: string', function() 236 | { 237 | this 238 | .describe("Number.isFinite('10') is not a finite number") 239 | .exec(!Number.isFinite('10')) 240 | .done(); 241 | }) 242 | 243 | .test('Number.isFinite: NaN', function() 244 | { 245 | this 246 | .describe("Number.isFinite(+Infinity) is not a finite number") 247 | .exec(!Number.isFinite(+Infinity)) 248 | .done(); 249 | }) 250 | 251 | .test('Number.isFinite: -Infinity', function() 252 | { 253 | this 254 | .describe("Number.isFinite(-Infinity) is not a finite number") 255 | .exec(!Number.isFinite(-Infinity)) 256 | .done(); 257 | }) 258 | 259 | .test('Number.isFinite: NaN', function() 260 | { 261 | this 262 | .describe("Number.isFinite(NaN) is not a finite number") 263 | .exec(!Number.isFinite(NaN)) 264 | .done(); 265 | }) 266 | 267 | /* 268 | Number.isInteger 269 | */ 270 | 271 | new Suitest('Number.isInteger') 272 | 273 | .test('Number.isInteger: int', function() 274 | { 275 | this 276 | .describe("Number.isInteger(10) is integer") 277 | .exec(Number.isInteger(10)) 278 | .done(); 279 | }) 280 | 281 | .test('Number.isInteger: float', function() 282 | { 283 | this 284 | .describe("Number.isInteger(10.1) is integer") 285 | .exec(Number.isFinite(10.1)) 286 | .done(); 287 | }) 288 | 289 | .test('Number.isInteger: string', function() 290 | { 291 | this 292 | .describe("Number.isInteger('10') is not integer") 293 | .exec(!Number.isInteger('10')) 294 | .done(); 295 | }) 296 | 297 | .test('Number.isInteger: NaN', function() 298 | { 299 | this 300 | .describe("Number.isInteger(NaN) is not integer") 301 | .exec(!Number.isInteger(NaN)) 302 | .done(); 303 | }) 304 | 305 | .test('Number.isInteger: {}', function() 306 | { 307 | this 308 | .describe("Number.isInteger({}) is not integer") 309 | .exec(!Number.isInteger({})) 310 | .done(); 311 | }); 312 | 313 | /* 314 | Number.toInteger 315 | */ 316 | 317 | new Suitest('Number.toInteger') 318 | 319 | .test('Number.toInteger: int', function() 320 | { 321 | this 322 | .describe("Number.toInteger(10) is 10") 323 | .exec(Number.toInteger(10)) 324 | .done(); 325 | }) 326 | 327 | .test('Number.toInteger: float', function() 328 | { 329 | this 330 | .describe("Number.toInteger(10.1) is 10.1") 331 | .exec(Number.toInteger(10.1)) 332 | .done(); 333 | }) 334 | 335 | .test('Number.toInteger: string', function() 336 | { 337 | this 338 | .describe("Number.toInteger('10') is 10") 339 | .exec(Number.toInteger('10')) 340 | .done(); 341 | }) 342 | 343 | .test('Number.toInteger: NaN', function() 344 | { 345 | this 346 | .describe("Number.toInteger(NaN) is 0") 347 | .exec(Number.toInteger(NaN), 0) 348 | .done(); 349 | }) 350 | 351 | .test('Number.toInteger: undefined', function() 352 | { 353 | this 354 | .describe("Number.toInteger(undefined) is 0") 355 | .exec(Number.toInteger(undefined), 0) 356 | .done(); 357 | }) 358 | 359 | .test('Number.toInteger: null', function() 360 | { 361 | this 362 | .describe("Number.toInteger(null) is 0") 363 | .exec(Number.toInteger(null), 0) 364 | .done(); 365 | }) 366 | 367 | .test('Number.toInteger: {}', function() 368 | { 369 | this 370 | .describe("Number.toInteger({}) is 0") 371 | .exec(Number.toInteger({}), 0) 372 | .done(); 373 | }) 374 | 375 | .test('Number.toInteger: function', function() 376 | { 377 | this 378 | .describe("Number.toInteger({}) is 0") 379 | .exec(Number.toInteger(function(){}), 0) 380 | .done(); 381 | }) 382 | 383 | .test('Number.toInteger: +0', function() 384 | { 385 | this 386 | .describe("Number.toInteger(+0) is int") 387 | .exec(Number.toInteger(0), 0) 388 | .done(); 389 | }) 390 | 391 | .test('Number.toInteger: -0', function() 392 | { 393 | this 394 | .describe("Number.toInteger(-0) is int") 395 | .exec(Number.toInteger(-0), -0) 396 | .done(); 397 | }) 398 | 399 | .test('Number.toInteger: -Infinity', function() 400 | { 401 | this 402 | .describe("Number.toInteger(+Infinity) is int") 403 | .exec(Number.toInteger(+Infinity), +Infinity) 404 | .done(); 405 | }) 406 | 407 | .test('Number.toInteger: -Infinity', function() 408 | { 409 | this 410 | .describe("Number.toInteger(-Infinity) is int") 411 | .exec(Number.toInteger(-Infinity), -Infinity) 412 | .done(); 413 | }); 414 | 415 | /* 416 | Number.prototype.clz 417 | */ 418 | 419 | new Suitest('Number.prototype.clz') 420 | 421 | .test('Number.prototype.clz: +int', function() 422 | { 423 | this 424 | .describe("000010000000.clz() is 10") 425 | .exec(000010000000.clz(), 10) 426 | .done(); 427 | }) 428 | 429 | .test('Number.prototype.clz: -int', function() 430 | { 431 | this 432 | .describe("-000010000000.clz() is -10") 433 | .exec(-000010000000.clz(), -10) 434 | .done(); 435 | }) 436 | 437 | .test('Number.prototype.clz: +float', function() 438 | { 439 | this 440 | .describe("0.1.clz() is 31") 441 | .exec(0.1.clz(), 31) 442 | .done(); 443 | }) 444 | 445 | .test('Number.prototype.clz: -float', function() 446 | { 447 | this 448 | .describe("0.1.clz() is 31") 449 | .exec(-0.1.clz(), -31) 450 | .done(); 451 | }); -------------------------------------------------------------------------------- /tests/Object.js: -------------------------------------------------------------------------------- 1 | require('../ES6.js'); 2 | require('./suitest.js'); 3 | 4 | /** 5 | * ------------------------------------------------------------ 6 | * Object 7 | * ------------------------------------------------------------ 8 | **/ 9 | 10 | void function(__is__, object) 11 | { 12 | /* 13 | Object.is 14 | */ 15 | 16 | new Suitest('Object.is') 17 | 18 | .test('Object.is: negative zero', function() 19 | { 20 | this 21 | .describe('0 is not -0') 22 | .exec(!Object.is(0, -0)) 23 | .done(); 24 | }) 25 | 26 | .test('Object.is: numbers and strings', function() 27 | { 28 | this 29 | .describe('"0" is not 0') 30 | .exec(!Object.is('0', 0)) 31 | .done(); 32 | }) 33 | 34 | .test('Object.is: equivalent numbers', function() 35 | { 36 | this 37 | .describe('0 is 0') 38 | .exec(Object.is(0, 0)) 39 | .done(); 40 | }) 41 | 42 | .test('Object.is: NaN', function() 43 | { 44 | this 45 | .describe('NaN is NaN') 46 | .exec(Object.is(NaN, NaN)) 47 | .done(); 48 | }); 49 | 50 | // TODO: Object.getOwnPropertyKeys, Object.mixin, Object.assign 51 | 52 | }(Object.prototype.toString, {}); 53 | -------------------------------------------------------------------------------- /tests/Proposal.js: -------------------------------------------------------------------------------- 1 | // -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- 2 | 3 | require('../proposal.js'); 4 | require('./suitest.js'); 5 | 6 | /** 7 | * ------------------------------------------------------------ 8 | * Object 9 | * ------------------------------------------------------------ 10 | **/ 11 | 12 | void function(__is__, object) 13 | { 14 | /* 15 | Object.isObject 16 | */ 17 | 18 | new Suitest('Object.isObject') 19 | 20 | .test('Object.isObject: null', function() 21 | { 22 | this 23 | .describe('null is not object') 24 | .exec(!Object.isObject(null)) 25 | .done(); 26 | }) 27 | 28 | .test('Object.isObject: object', function() 29 | { 30 | this 31 | .describe('{} is object') 32 | .exec(Object.isObject({})) 33 | .done(); 34 | }) 35 | 36 | .test('Object.isObject: array', function() 37 | { 38 | this 39 | .describe('[] is object') 40 | .exec(!Object.isObject([])) 41 | .done(); 42 | }); 43 | 44 | /* 45 | Object.getOwnPropertyDescriptors 46 | */ 47 | 48 | Object.defineProperty(object, 'a', { 49 | value: 0, 50 | configurable: false, 51 | enumerable: false, 52 | writable: false 53 | }); 54 | 55 | Object.defineProperty(object, 'b', { 56 | value: 1, 57 | configurable: true, 58 | enumerable: true, 59 | writable: true 60 | }); 61 | 62 | new Suitest('Object.getOwnPropertyDescriptors') 63 | 64 | .test('Object.getOwnPropertyDescriptors: returns Object', function() 65 | { 66 | this 67 | .describe("type of Object.getOwnPropertyDescriptors({}) is '[object Object]'") 68 | .exec(__is__.call(Object.getOwnPropertyDescriptors({})), '[object Object]') 69 | .done(); 70 | }) 71 | 72 | .test('Object.getOwnPropertyDescriptors: check the object keys', function() 73 | { 74 | this 75 | .describe("Object.keys(Object.getOwnPropertyDescriptors({ a:1, b:1 })) is 'b,a'") 76 | .exec(Object.keys(Object.getOwnPropertyDescriptors(object)).toString().replace(/\s/g, ''), 'b,a') 77 | .done(); 78 | }) 79 | 80 | .test('Object.getOwnPropertyDescriptors: get a property descriptor values of the specified object', function() 81 | { 82 | var value_1 = [], 83 | value_2 = []; 84 | 85 | Object.getOwnPropertyNames(object).forEach(function(key) 86 | { 87 | Object.keys(Object.getOwnPropertyDescriptor(object, key)).forEach(function(descriptor) 88 | { 89 | value_1.push(Object.getOwnPropertyDescriptor(object, key)[descriptor]); 90 | value_2.push(Object.getOwnPropertyDescriptors(object)[key][descriptor]); 91 | }); 92 | }); 93 | 94 | this 95 | .describe("Object.getOwnPropertyDescriptor(object, key)[descriptor] is Object.getOwnPropertyDescriptors(object)[key][descriptor]") 96 | .exec(value_1.toString(), value_2.toString()) 97 | .done(); 98 | }); 99 | 100 | /* 101 | Object.getPropertyNames 102 | */ 103 | 104 | new Suitest('Object.getPropertyNames') 105 | 106 | .test('Object.getPropertyNames: returns Object', function() 107 | { 108 | this 109 | .describe("type of Object.getPropertyNames({}) is '[object Array]'") 110 | .exec(__is__.call(Object.getPropertyNames({})), '[object Array]') 111 | .done(); 112 | }) 113 | 114 | .test('Object.getPropertyNames: get all the names of the properties', function() 115 | { 116 | this 117 | .describe('Object.getPropertyNames(object) in object') 118 | .exec(Object.getPropertyNames(object).every(function(a) { 119 | return a in object; 120 | })) 121 | .done(); 122 | }); 123 | 124 | /* 125 | Object.isnt 126 | */ 127 | 128 | new Suitest('Object.isnt') 129 | 130 | .test('Object.isnt: negative zero', function() 131 | { 132 | this 133 | .describe('0 is not -0') 134 | .exec(Object.isnt(0, -0)) 135 | .done(); 136 | }) 137 | 138 | .test('Object.isnt: numbers and strings', function() 139 | { 140 | this 141 | .describe('"0" is not 0') 142 | .exec(Object.isnt('0', 0)) 143 | .done(); 144 | }) 145 | 146 | .test('Object.isnt: equivalent numbers', function() 147 | { 148 | this 149 | .describe('0 is 0') 150 | .exec(!Object.isnt(0, 0)) 151 | .done(); 152 | }) 153 | 154 | .test('Object.isnt: NaN', function() 155 | { 156 | this 157 | .describe('NaN is NaN') 158 | .exec(!Object.isnt(NaN, NaN)) 159 | .done(); 160 | }); 161 | 162 | 163 | /* 164 | String.prototype.toArray 165 | */ 166 | 167 | new Suitest('String.prototype.toArray') 168 | 169 | .test('String.prototype.toArray: returns array', function() 170 | { 171 | this 172 | .describe("'type of Hello'.toArray() is [object Array]") 173 | .exec(Object.prototype.toString.call('Hello'.toArray()), '[object Array]') 174 | .done(); 175 | }) 176 | 177 | .test('String.prototype.toArray', function() 178 | { 179 | this 180 | .describe("'Hello'.toArray() is ['H', 'e', 'l', 'l', 'o']") 181 | .exec('Hello'.toArray().toString(), ['H', 'e', 'l', 'l', 'o'].toString()) 182 | .done(); 183 | }); 184 | 185 | }(Object.prototype.toString, {}); 186 | -------------------------------------------------------------------------------- /tests/String.js: -------------------------------------------------------------------------------- 1 | require('../ES6.js'); 2 | require('./suitest.js'); 3 | 4 | /** 5 | * ------------------------------------------------------------ 6 | * String 7 | * ------------------------------------------------------------ 8 | **/ 9 | 10 | 11 | /* 12 | String.fromCodePoint 13 | */ 14 | 15 | new Suitest('String.fromCodePoint') 16 | 17 | .test('String.fromCodePoint: 0x', function() 18 | { 19 | this 20 | .describe("0x21 is '!'") 21 | .exec(String.fromCodePoint(0x21), '!') 22 | .done(); 23 | }) 24 | 25 | .test('String.fromCodePoint: unicode values', function() 26 | { 27 | this 28 | .describe("107 is 'k'") 29 | .exec(String.fromCodePoint(107), 'k') 30 | .done(); 31 | }) 32 | 33 | .test('String.fromCodePoint: 0', function() 34 | { 35 | this 36 | .describe("0 is empty string") 37 | .exec(String.fromCodePoint(0), String.fromCharCode(0)) 38 | .done(); 39 | }); 40 | 41 | /* 42 | String.codePointAt 43 | */ 44 | 45 | new Suitest('codePointAt') 46 | 47 | .test('String.codePointAt', function() 48 | { 49 | this 50 | .describe("'A'.codePointAt(0) is 65") 51 | .exec('A'.codePointAt(0), 65) 52 | .done(); 53 | }) 54 | 55 | .test('String.codePointAt', function() 56 | { 57 | this 58 | .describe("String.fromCodePoint(65).codePointAt(0) is 'A'.codePointAt(0)") 59 | .exec(String.fromCodePoint(65).codePointAt(0), 'A'.codePointAt(0)) 60 | .done(); 61 | }); 62 | 63 | 64 | /* 65 | String.prototype.repeat 66 | */ 67 | 68 | new Suitest('String.prototype.repeat') 69 | 70 | .test('String.prototype.repeat', function() 71 | { 72 | this 73 | .describe("'A'.repeat(2) is 'AA'") 74 | .exec('A'.repeat(2), 'AA') 75 | .done(); 76 | }); 77 | 78 | 79 | /* 80 | String.prototype.startsWith 81 | */ 82 | 83 | new Suitest('String.prototype.startsWith') 84 | 85 | .test("String.prototype.startsWith: 'test'.startsWith('t')", function() 86 | { 87 | this 88 | .exec('test'.startsWith('t')) 89 | .done(); 90 | }) 91 | 92 | .test("String.prototype.startsWith: 'test me'.startsWith('t')", function() 93 | { 94 | this 95 | .exec('test me'.startsWith('t')) 96 | .done(); 97 | }) 98 | 99 | .test("String.prototype.startsWith: 'test'.startsWith('test')", function() 100 | { 101 | this 102 | .exec('test'.startsWith('test')) 103 | .done(); 104 | }) 105 | 106 | .test("String.prototype.startsWith: !'test'.startsWith('TEST')", function() 107 | { 108 | this 109 | .exec(!'test'.startsWith('ЕУЫЕ')) 110 | .done(); 111 | }) 112 | 113 | .test("String.prototype.startsWith: 'test me'.startsWith('test me')", function() 114 | { 115 | this 116 | .exec('test me'.startsWith('test me')) 117 | .done(); 118 | }) 119 | 120 | .test("String.prototype.startsWith: !'test me'.startsWith(' me')", function() 121 | { 122 | this 123 | .exec(!'test me'.startsWith(' me')) 124 | .done(); 125 | }) 126 | 127 | .test("String.prototype.startsWith: !'test me'.startsWith('me')", function() 128 | { 129 | this 130 | .exec(!'test me'.startsWith('me')) 131 | .done(); 132 | }) 133 | 134 | .test("String.prototype.startsWith: !''.startsWith('a')", function() 135 | { 136 | this 137 | .exec(!''.startsWith('a')) 138 | .done(); 139 | }) 140 | 141 | .test("String.prototype.startsWith: ''.startsWith('')", function() 142 | { 143 | this 144 | .exec(''.startsWith('')) 145 | .done(); 146 | }) 147 | 148 | .test("String.prototype.startsWith: 'test me me'.startsWith('test')", function() 149 | { 150 | this 151 | .exec('test me me'.startsWith('test')) 152 | .done(); 153 | }) 154 | 155 | .test("String.prototype.startsWith: 'test me me'.startsWith('test ')", function() 156 | { 157 | this 158 | .exec('test me me'.startsWith('test ')) 159 | .done(); 160 | }) 161 | 162 | .test("String.prototype.startsWith: !'test me me'.startsWith(' test')", function() 163 | { 164 | this 165 | .exec(!'test me me'.startsWith(' test')) 166 | .done(); 167 | }) 168 | 169 | .test("String.prototype.startsWith: !'m'.startsWith('me')", function() 170 | { 171 | this 172 | .exec(!'m'.startsWith('me')) 173 | .done(); 174 | }) 175 | 176 | .test("String.prototype.startsWith: !'me'.startsWith('me ')", function() 177 | { 178 | this 179 | .exec(!'me'.startsWith('me ')) 180 | .done(); 181 | }) 182 | 183 | .test("String.prototype.startsWith: 'test me'.startsWith('me', 2)", function() 184 | { 185 | this 186 | .exec(!'test me'.startsWith('me', 2)) 187 | .done(); 188 | }) 189 | 190 | .test("String.prototype.startsWith: 'test me'.startsWith('me', '5')", function() 191 | { 192 | this 193 | .exec('test me'.startsWith('me', '5')) 194 | .done(); 195 | }) 196 | 197 | .test("String.prototype.startsWith: !'test'.startsWith('test', 0)", function() 198 | { 199 | this 200 | .exec('test'.startsWith('test', 0)) 201 | .done(); 202 | }) 203 | 204 | .test("String.prototype.startsWith: 'test'.startsWith('t', 0)", function() 205 | { 206 | this 207 | .exec('test'.startsWith('t', 0)) 208 | .done(); 209 | }) 210 | 211 | .test("String.prototype.startsWith: 'test'.startsWith('e', 1)", function() 212 | { 213 | this 214 | .exec('test'.startsWith('e', 1)) 215 | .done(); 216 | }) 217 | 218 | .test("String.prototype.startsWith: 'test'.startsWith('es', 1)", function() 219 | { 220 | this 221 | .exec('test'.startsWith('es', 1)) 222 | .done(); 223 | }) 224 | 225 | .test("String.prototype.startsWith: 'test'.startsWith('tes', 0)", function() 226 | { 227 | this 228 | .exec('test'.startsWith('tes', 0)) 229 | .done(); 230 | }) 231 | 232 | .test("String.prototype.startsWith: !'test'.startsWith('tes', 1)", function() 233 | { 234 | this 235 | .exec(!'test'.startsWith('tes', 1)) 236 | .done(); 237 | }) 238 | 239 | .test("String.prototype.startsWith: '!test'.startsWith('t', 4)", function() 240 | { 241 | this 242 | .exec(!'test'.startsWith('t', 4)) 243 | .done(); 244 | }) 245 | 246 | .test("String.prototype.startsWith: 'a'.startsWith('a', 0)", function() 247 | { 248 | this 249 | .exec('a'.startsWith('a', 0)) 250 | .done(); 251 | }) 252 | 253 | .test("String.prototype.startsWith: !'a'.startsWith('a', 1)", function() 254 | { 255 | this 256 | .exec(!'a'.startsWith('a', 1)) 257 | .done(); 258 | }) 259 | 260 | .test("String.prototype.startsWith: !'test me'.startsWith('me', 0)", function() 261 | { 262 | this 263 | .exec(!'test me'.startsWith('me', 0)) 264 | .done(); 265 | }) 266 | 267 | .test("String.prototype.startsWith: !'123'.startsWith('3')", function() 268 | { 269 | this 270 | .exec(!'123'.startsWith('3')) 271 | .done(); 272 | }) 273 | 274 | .test("String.prototype.startsWith: !'123'.startsWith('3')", function() 275 | { 276 | this 277 | .exec(!'123'.startsWith(3)) 278 | .done(); 279 | }) 280 | 281 | .test("String.prototype.startsWith: !'123'.startsWith('3', 0)", function() 282 | { 283 | this 284 | .exec(!'123'.startsWith('3', 0)) 285 | .done(); 286 | }) 287 | 288 | .test("String.prototype.startsWith: !'123'.startsWith('3', 0)", function() 289 | { 290 | this 291 | .exec(!'123'.startsWith(3, 0)) 292 | .done(); 293 | }) 294 | 295 | .test("String.prototype.startsWith: !'123'.startsWith('3', 1)", function() 296 | { 297 | this 298 | .exec(!'123'.startsWith('3', 1)) 299 | .done(); 300 | }) 301 | 302 | .test("String.prototype.startsWith: !'123'.startsWith('3', 1)", function() 303 | { 304 | this 305 | .exec(!'123'.startsWith(3, 1)) 306 | .done(); 307 | }) 308 | 309 | .test("String.prototype.startsWith: '123'.startsWith('3', 2)", function() 310 | { 311 | this 312 | .exec('123'.startsWith('3', 2)) 313 | .done(); 314 | }) 315 | 316 | .test("String.prototype.startsWith: '123'.startsWith('3', 2)", function() 317 | { 318 | this 319 | .exec('123'.startsWith(3, 2)) 320 | .done(); 321 | }) 322 | 323 | .test("String.prototype.startsWith: !'123'.startsWith('3', 3)", function() 324 | { 325 | this 326 | .exec(!'123'.startsWith('3', 3)) 327 | .done(); 328 | }) 329 | 330 | .test("String.prototype.startsWith: !'123'.startsWith('3', 3)", function() 331 | { 332 | this 333 | .exec(!'123'.startsWith(3, 3)) 334 | .done(); 335 | }) 336 | 337 | .test("String.prototype.startsWith: !'123'.startsWith('3', 4)", function() 338 | { 339 | this 340 | .exec(!'123'.startsWith('3', 4)) 341 | .done(); 342 | }) 343 | 344 | .test("String.prototype.startsWith: !'123'.startsWith('3', 4)", function() 345 | { 346 | this 347 | .exec(!'123'.startsWith(3, 4)) 348 | .done(); 349 | }) 350 | 351 | .test("String.prototype.startsWith: !'123'.startsWith('1', '1')", function() 352 | { 353 | this 354 | .exec(!'123'.startsWith('1', 1)) 355 | .done(); 356 | }) 357 | 358 | .test("String.prototype.startsWith: !'123'.startsWith('1', '1')", function() 359 | { 360 | this 361 | .exec(!'123'.startsWith(1, 1)) 362 | .done(); 363 | }) 364 | 365 | .test("String.prototype.startsWith: !'123'.startsWith('1', null)", function() 366 | { 367 | this 368 | .exec('123'.startsWith('1', null)) 369 | .done(); 370 | }) 371 | 372 | .test("String.prototype.startsWith: !'123'.startsWith('1', null)", function() 373 | { 374 | this 375 | .exec('123'.startsWith(1, null)) 376 | .done(); 377 | }) 378 | 379 | .test("String.prototype.startsWith: !'123'.startsWith('3', null)", function() 380 | { 381 | this 382 | .exec(!'123'.startsWith('3', null)) 383 | .done(); 384 | }) 385 | 386 | .test("String.prototype.startsWith: !'123'.startsWith('3', null)", function() 387 | { 388 | this 389 | .exec(!'123'.startsWith(3, null)) 390 | .done(); 391 | }) 392 | 393 | .test("String.prototype.startsWith: '123'.startsWith('1', -1)", function() 394 | { 395 | this 396 | .exec('123'.startsWith('1', -1)) 397 | .done(); 398 | }) 399 | 400 | .test("String.prototype.startsWith: '123'.startsWith('1', -1)", function() 401 | { 402 | this 403 | .exec('123'.startsWith(1, -1)) 404 | .done(); 405 | }) 406 | 407 | .test("String.prototype.startsWith: !'123'.startsWith('3', -1)", function() 408 | { 409 | this 410 | .exec(!'123'.startsWith('3', -1)) 411 | .done(); 412 | }) 413 | 414 | .test("String.prototype.startsWith: !'123'.startsWith('3', -1)", function() 415 | { 416 | this 417 | .exec(!'123'.startsWith(3, -1)) 418 | .done(); 419 | }) 420 | 421 | .test("String.prototype.startsWith: !'123'.startsWith('3', -3)", function() 422 | { 423 | this 424 | .exec(!'123'.startsWith('3', -3)) 425 | .done(); 426 | }) 427 | 428 | .test("String.prototype.startsWith: !'123'.startsWith('3', -3)", function() 429 | { 430 | this 431 | .exec(!'123'.startsWith(3, -3)) 432 | .done(); 433 | }) 434 | 435 | .test("String.prototype.startsWith: '123'.startsWith('')", function() 436 | { 437 | this 438 | .exec('123'.startsWith('')) 439 | .done(); 440 | }) 441 | 442 | .test("String.prototype.startsWith: '123'.startsWith('', 0)", function() 443 | { 444 | this 445 | .exec('123'.startsWith('', 0)) 446 | .done(); 447 | }) 448 | 449 | .test("String.prototype.startsWith: '123'.startsWith('', -1)", function() 450 | { 451 | this 452 | .exec('123'.startsWith('', -1)) 453 | .done(); 454 | }) 455 | 456 | .test("String.prototype.startsWith: '123'.startsWith('', 10)", function() 457 | { 458 | this 459 | .exec('123'.startsWith('', 10)) 460 | .done(); 461 | }) 462 | 463 | .test("String.prototype.startsWith: ''.startsWith('', 0)", function() 464 | { 465 | this 466 | .exec(''.startsWith('', 0)) 467 | .done(); 468 | }) 469 | 470 | .test("String.prototype.startsWith: !''.startsWith(null, 0)", function() 471 | { 472 | this 473 | .exec(!''.startsWith(null, 0)) 474 | .done(); 475 | }) 476 | 477 | .test("String.prototype.startsWith: !''.startsWith(undefined, 0)", function() 478 | { 479 | this 480 | .exec(!''.startsWith(undefined, 0)) 481 | .done(); 482 | }) 483 | 484 | .test("String.prototype.startsWith: !''.startsWith(0, 0)", function() 485 | { 486 | this 487 | .exec(!''.startsWith(0, 0)) 488 | .done(); 489 | }) 490 | 491 | .test("String.prototype.startsWith: !''.startsWith(0, -1)", function() 492 | { 493 | this 494 | .exec(!''.startsWith(0, -1)) 495 | .done(); 496 | }) 497 | 498 | .test("String.prototype.startsWith: '-1'.startsWith(-1, -1)", function() 499 | { 500 | this 501 | .exec('-1'.startsWith(-1, -1)) 502 | .done(); 503 | }) 504 | 505 | .test("String.prototype.startsWith: '[object Object]'.startsWith({})", function() 506 | { 507 | this 508 | .exec('[object Object]'.startsWith({})) 509 | .done(); 510 | }) 511 | 512 | .test("String.prototype.startsWith: '[object Object]'.startsWith({})", function() 513 | { 514 | this 515 | .exec('[object Object]'.startsWith({})) 516 | .done(); 517 | }) 518 | 519 | // 62 tests 520 | 521 | 522 | /* 523 | String.prototype.endsWith 524 | */ 525 | 526 | new Suitest('String.prototype.endsWith') 527 | 528 | .test("String.prototype.endsWith: 'test'.endsWith('t')", function() 529 | { 530 | this 531 | .exec('test'.endsWith('t')) 532 | .done(); 533 | }) 534 | 535 | .test("String.prototype.endsWith: 'test me'.endsWith('e')", function() 536 | { 537 | this 538 | .exec('test me'.endsWith('e')) 539 | .done(); 540 | }) 541 | 542 | .test("String.prototype.endsWith: 'test me'.endsWith('me')", function() 543 | { 544 | this 545 | .exec('test me'.endsWith('me')) 546 | .done(); 547 | }) 548 | 549 | .test("String.prototype.endsWith: 'test me'.endsWith('test me')", function() 550 | { 551 | this 552 | .exec('test me'.endsWith('test me')) 553 | .done(); 554 | }) 555 | 556 | .test("String.prototype.endsWith: !'test'.endsWith('TEST')", function() 557 | { 558 | this 559 | .exec(!'test'.endsWith('TEST')) 560 | .done(); 561 | }) 562 | 563 | .test("String.prototype.endsWith: 'test me'.endsWith(' me')", function() 564 | { 565 | this 566 | .exec('test me'.endsWith(' me')) 567 | .done(); 568 | }) 569 | 570 | .test("String.prototype.endsWith: !'test me'.endsWith('t')", function() 571 | { 572 | this 573 | .exec(!'test me'.endsWith('t')) 574 | .done(); 575 | }) 576 | 577 | .test("String.prototype.endsWith: !''.endsWith('a')", function() 578 | { 579 | this 580 | .exec(!''.endsWith('a')) 581 | .done(); 582 | }) 583 | 584 | .test("String.prototype.endsWith: ''.endsWith('')", function() 585 | { 586 | this 587 | .exec(''.endsWith('')) 588 | .done(); 589 | }) 590 | 591 | .test("String.prototype.endsWith: 'test me me'.endsWith('me')", function() 592 | { 593 | this 594 | .exec('test me me'.endsWith('me')) 595 | .done(); 596 | }) 597 | 598 | .test("String.prototype.endsWith: 'test me me'.endsWith(' me')", function() 599 | { 600 | this 601 | .exec('test me me'.endsWith(' me')) 602 | .done(); 603 | }) 604 | 605 | .test("String.prototype.endsWith: !'m'.endsWith('me')", function() 606 | { 607 | this 608 | .exec(!'m'.endsWith('me')) 609 | .done(); 610 | }) 611 | 612 | .test("String.prototype.endsWith: !'me'.endsWith('me ')", function() 613 | { 614 | this 615 | .exec(!'me'.endsWith('me ')) 616 | .done(); 617 | }) 618 | 619 | .test("String.prototype.endsWith: 'test me'.endsWith('me', 2)", function() 620 | { 621 | this 622 | .exec(!'test me'.endsWith('me', 2)) 623 | .done(); 624 | }) 625 | 626 | .test("String.prototype.endsWith: !'test me'.endsWith('me', '2')", function() 627 | { 628 | this 629 | .exec(!'test me'.endsWith('me', '2')) 630 | .done(); 631 | }) 632 | 633 | .test("String.prototype.endsWith: !'test'.endsWith('test', 4)", function() 634 | { 635 | this 636 | .exec('test'.endsWith('test', 4)) 637 | .done(); 638 | }) 639 | 640 | .test("String.prototype.endsWith: 'test'.endsWith('t', 1)", function() 641 | { 642 | this 643 | .exec('test'.endsWith('t', 1)) 644 | .done(); 645 | }) 646 | 647 | .test("String.prototype.endsWith: 'test'.endsWith('e', 2)", function() 648 | { 649 | this 650 | .exec('test'.endsWith('e', 2)) 651 | .done(); 652 | }) 653 | 654 | .test("String.prototype.endsWith: 'test'.endsWith('es', 3)", function() 655 | { 656 | this 657 | .exec('test'.endsWith('es', 3)) 658 | .done(); 659 | }) 660 | 661 | .test("String.prototype.endsWith: !'test'.endsWith('tes', 4)", function() 662 | { 663 | this 664 | .exec(!'test'.endsWith('tes', 4)) 665 | .done(); 666 | }) 667 | 668 | .test("String.prototype.endsWith: 'test'.endsWith('tes', 4)", function() 669 | { 670 | this 671 | .exec('test'.endsWith('tes', 3)) 672 | .done(); 673 | }) 674 | 675 | .test("String.prototype.endsWith: 'test'.endsWith('t', 4)", function() 676 | { 677 | this 678 | .exec('test'.endsWith('t', 4)) 679 | .done(); 680 | }) 681 | 682 | .test("String.prototype.endsWith: !'a'.endsWith('a', 0)", function() 683 | { 684 | this 685 | .exec(!'a'.endsWith('a', 0)) 686 | .done(); 687 | }) 688 | 689 | .test("String.prototype.endsWith: 'a'.startsWith('a', 1)", function() 690 | { 691 | this 692 | .exec('a'.endsWith('a', 1)) 693 | .done(); 694 | }) 695 | 696 | .test("String.prototype.endsWith: !'test me'.endsWith('me', 0)", function() 697 | { 698 | this 699 | .exec(!'test me'.endsWith('me', 0)) 700 | .done(); 701 | }) 702 | 703 | .test("String.prototype.endsWith: '123'.endsWith('3')", function() 704 | { 705 | this 706 | .exec('123'.endsWith('3')) 707 | .done(); 708 | }) 709 | 710 | .test("String.prototype.endsWith: '123'.endsWith('3')", function() 711 | { 712 | this 713 | .exec('123'.endsWith(3)) 714 | .done(); 715 | }) 716 | 717 | .test("String.prototype.endsWith: !'123'.endsWith('3', 0)", function() 718 | { 719 | this 720 | .exec(!'123'.endsWith('3', 0)) 721 | .done(); 722 | }) 723 | 724 | .test("String.prototype.endsWith: !'123'.endsWith('3', 0)", function() 725 | { 726 | this 727 | .exec(!'123'.endsWith(3, 0)) 728 | .done(); 729 | }) 730 | 731 | .test("String.prototype.endsWith: !'123'.endsWith('3', 1)", function() 732 | { 733 | this 734 | .exec(!'123'.endsWith('3', 1)) 735 | .done(); 736 | }) 737 | 738 | .test("String.prototype.endsWith: !'123'.endsWith('3', 1)", function() 739 | { 740 | this 741 | .exec(!'123'.endsWith(3, 1)) 742 | .done(); 743 | }) 744 | 745 | .test("String.prototype.endsWith: !'123'.endsWith('3', 2)", function() 746 | { 747 | this 748 | .exec(!'123'.endsWith('3', 2)) 749 | .done(); 750 | }) 751 | 752 | .test("String.prototype.endsWith: !'123'.endsWith('3', 2)", function() 753 | { 754 | this 755 | .exec(!'123'.endsWith(3, 2)) 756 | .done(); 757 | }) 758 | 759 | .test("String.prototype.endsWith: '123'.endsWith('3', 3)", function() 760 | { 761 | this 762 | .exec('123'.endsWith('3', 3)) 763 | .done(); 764 | }) 765 | 766 | .test("String.prototype.endsWith: '123'.endsWith('3', 3)", function() 767 | { 768 | this 769 | .exec('123'.endsWith(3, 3)) 770 | .done(); 771 | }) 772 | 773 | .test("String.prototype.endsWith: '123'.endsWith('3', 4)", function() 774 | { 775 | this 776 | .exec('123'.endsWith('3', 4)) 777 | .done(); 778 | }) 779 | 780 | .test("String.prototype.endsWith: '123'.endsWith('3', 4)", function() 781 | { 782 | this 783 | .exec('123'.endsWith(3, 4)) 784 | .done(); 785 | }) 786 | 787 | .test("String.prototype.endsWith: '123'.endsWith('1', '1')", function() 788 | { 789 | this 790 | .exec('123'.endsWith('1', 1)) 791 | .done(); 792 | }) 793 | 794 | .test("String.prototype.endsWith: '123'.endsWith('1', '1')", function() 795 | { 796 | this 797 | .exec('123'.endsWith(1, 1)) 798 | .done(); 799 | }) 800 | 801 | .test("String.prototype.endsWith: !'123'.endsWith('1', null)", function() 802 | { 803 | this 804 | .exec(!'123'.endsWith('1', null)) 805 | .done(); 806 | }) 807 | 808 | .test("String.prototype.endsWith: !'123'.endsWith('1', null)", function() 809 | { 810 | this 811 | .exec(!'123'.endsWith(1, null)) 812 | .done(); 813 | }) 814 | 815 | .test("String.prototype.endsWith: !'123'.endsWith('3', null)", function() 816 | { 817 | this 818 | .exec(!'123'.endsWith('3', null)) 819 | .done(); 820 | }) 821 | 822 | .test("String.prototype.endsWith: !'123'.endsWith('3', null)", function() 823 | { 824 | this 825 | .exec(!'123'.endsWith(3, null)) 826 | .done(); 827 | }) 828 | 829 | .test("String.prototype.endsWith: !'123'.endsWith('1', -1)", function() 830 | { 831 | this 832 | .exec(!'123'.endsWith('1', -1)) 833 | .done(); 834 | }) 835 | 836 | .test("String.prototype.endsWith: !'123'.endsWith('1', -1)", function() 837 | { 838 | this 839 | .exec(!'123'.endsWith(1, -1)) 840 | .done(); 841 | }) 842 | 843 | .test("String.prototype.endsWith: !'123'.endsWith('3', -1)", function() 844 | { 845 | this 846 | .exec(!'123'.endsWith('3', -1)) 847 | .done(); 848 | }) 849 | 850 | .test("String.prototype.endsWith: !'123'.endsWith('3', -1)", function() 851 | { 852 | this 853 | .exec(!'123'.endsWith(3, -1)) 854 | .done(); 855 | }) 856 | 857 | .test("String.prototype.endsWith: !'123'.endsWith('3', -3)", function() 858 | { 859 | this 860 | .exec(!'123'.endsWith('3', -3)) 861 | .done(); 862 | }) 863 | 864 | .test("String.prototype.endsWith: !'123'.endsWith('3', -3)", function() 865 | { 866 | this 867 | .exec(!'123'.endsWith(3, -3)) 868 | .done(); 869 | }) 870 | 871 | .test("String.prototype.endsWith: '123'.endsWith('')", function() 872 | { 873 | this 874 | .exec('123'.endsWith('')) 875 | .done(); 876 | }) 877 | 878 | .test("String.prototype.endsWith: '123'.endsWith('', 0)", function() 879 | { 880 | this 881 | .exec('123'.endsWith('', 0)) 882 | .done(); 883 | }) 884 | 885 | .test("String.prototype.endsWith: '123'.endsWith('', -1)", function() 886 | { 887 | this 888 | .exec('123'.endsWith('', -1)) 889 | .done(); 890 | }) 891 | 892 | .test("String.prototype.endsWith: '123'.endsWith('', 10)", function() 893 | { 894 | this 895 | .exec('123'.endsWith('', 10)) 896 | .done(); 897 | }) 898 | 899 | .test("String.prototype.endsWith: ''.endsWith('', 0)", function() 900 | { 901 | this 902 | .exec(''.endsWith('', 0)) 903 | .done(); 904 | }) 905 | 906 | .test("String.prototype.endsWith: !''.endsWith(null, 0)", function() 907 | { 908 | this 909 | .exec(!''.endsWith(null, 0)) 910 | .done(); 911 | }) 912 | 913 | .test("String.prototype.endsWith: !''.endsWith(undefined, 0)", function() 914 | { 915 | this 916 | .exec(!''.endsWith(undefined, 0)) 917 | .done(); 918 | }) 919 | 920 | .test("String.prototype.endsWith: !''.endsWith(0, 0)", function() 921 | { 922 | this 923 | .exec(!''.endsWith(0, 0)) 924 | .done(); 925 | }) 926 | 927 | .test("String.prototype.endsWith: !''.endsWith(0, -1)", function() 928 | { 929 | this 930 | .exec(!''.endsWith(0, -1)) 931 | .done(); 932 | }) 933 | 934 | .test("String.prototype.endsWith: '-1'.endsWith(-1)", function() 935 | { 936 | this 937 | .exec('-1'.endsWith(-1)) 938 | .done(); 939 | }) 940 | 941 | .test("String.prototype.endsWith: '[object Object]'.endsWith({})", function() 942 | { 943 | this 944 | .exec('[object Object]'.endsWith({})) 945 | .done(); 946 | }) 947 | 948 | .test("String.prototype.endsWith: '[object Array]'.endsWith([])", function() 949 | { 950 | this 951 | .exec('[object Object]'.endsWith([])) 952 | .done(); 953 | }) 954 | 955 | // 60 tests 956 | 957 | 958 | /* 959 | String.prototype.contains 960 | */ 961 | 962 | new Suitest('String.prototype.contains') 963 | 964 | .test('String.prototype.contains', function() 965 | { 966 | this 967 | .describe("'Hello'.contains('He') is true") 968 | .exec('Hello'.contains('He')) 969 | .done(); 970 | }) 971 | 972 | .test('String.prototype.contains', function() 973 | { 974 | this 975 | .describe("'Hello'.contains('HE') is false") 976 | .exec(!'Hello'.contains('HE')) 977 | .done(); 978 | }); 979 | -------------------------------------------------------------------------------- /tests/suitest.js: -------------------------------------------------------------------------------- 1 | // -*- coding: utf-8; indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*- 2 | 3 | /** 4 | * Suitest is a powerful and easy-to-use JavaScript test suite 5 | * @author: Alexander Guinness 6 | * @version: 0.1.1 7 | * license: MIT 8 | * @date: ‎Sun Aug 12 03:30:00 2012 9 | **/ 10 | 11 | void function(__object__, __define__) 12 | { 13 | var __global__ = this, 14 | __own__ = __object__.hasOwnProperty; 15 | 16 | 'use strict'; 17 | 18 | var __private__ = { 19 | info: { 20 | title: 'Suitest', 21 | author: 'Alexander Guinnes', 22 | email: '', 23 | version: '0.1.0', 24 | license: 'MIT', 25 | year: 2012 26 | }, 27 | 28 | header: function() { 29 | var info = this.info; 30 | 31 | this.write 32 | ( 33 | '\n', this.color('gray'), this.line, '\n ', 34 | 35 | // Title 36 | info.title, 37 | 38 | // Version 39 | ' version: ', info.version, 40 | 41 | // Copyright 42 | '\n Copyright (c): ', info.author, ', ', 43 | 44 | // Author's e-mail 45 | info.email, ', ', 46 | 47 | // Release year 48 | info.year, '\n', 49 | 50 | this.line, this.color('reset') 51 | ); 52 | }, 53 | 54 | /** 55 | * __private__.define 56 | * It is used to add an own properties and set the descriptors: 57 | * { 58 | * __config__urable: false, 59 | * enumerable: false, 60 | * writable: false 61 | * } 62 | * @param {Object} object 63 | * @return {void} 64 | **/ 65 | define: function(object) 66 | { 67 | var __set__ = function(name, value) { 68 | if (__define__) 69 | __define__(this, name, { 70 | value: value, 71 | writable: true 72 | }); 73 | else 74 | this[name] = value; 75 | } 76 | 77 | for (var key in object) { 78 | if (__own__.call(object, key)) 79 | __set__.call(this, key, object[key]); 80 | } 81 | }, 82 | 83 | /** 84 | * __private__.color 85 | * Getting ASCII codes for coloring output text 86 | * @param {String} color - color name 87 | * @return {String} Unicode unit 88 | **/ 89 | color: function(color) 90 | { 91 | if (__global__.toString() === '[object Window]') 92 | return ''; 93 | 94 | return '\u001b[' + { 95 | red : '31m', 96 | green : '32m', 97 | yellow : '33m', 98 | blue : '36m', 99 | gray : '37m', 100 | reset : '0m' 101 | }[color]; 102 | }, 103 | 104 | /** 105 | * __private__.extend 106 | * @param {Object} x 107 | * @param {Object} y 108 | * @return {void} 109 | **/ 110 | extend: function(x, y) { 111 | for (var key in y) 112 | __own__.call(y, key) && (x[key] = y[key]); 113 | }, 114 | 115 | /** 116 | * __private__.init 117 | * Holds the fist initialization status 118 | **/ 119 | init: 0, 120 | 121 | /** 122 | * __private__.is 123 | * Determine the internal ECMAScript [[Class]] of an object. 124 | * @param {Object} object 125 | * @param {String} name 126 | * @return {Boolean} 127 | **/ 128 | is: function(object, name) { 129 | return __object__.toString.call(object) === '[object ' + name + ']'; 130 | }, 131 | 132 | /** 133 | * __private__.line 134 | * Dashed lines generator 135 | * @return {void} 136 | **/ 137 | line: Array(64).join('-'), 138 | 139 | /** 140 | * __private__.time 141 | * Getting total elapsed time 142 | * @param {Array} array 143 | * @return {Number} elapsed time in seconds 144 | **/ 145 | time: function(array) 146 | { 147 | var result = 0, 148 | i = array.length >>> 0; 149 | 150 | while (i--) 151 | result += array[i]; 152 | 153 | return result + 'ms'; 154 | }, 155 | 156 | /** 157 | * __private__.write 158 | * Output stream function 159 | * @return {void} 160 | **/ 161 | write: function() 162 | { 163 | /* 164 | * Object console is not part of ECMAScript standard, 165 | * so we'd check the one. 166 | * But there're some stupid problems in the engines: 167 | * 168 | * Object.prototype.toString.call(console): 169 | * [object Console] // Chrome 170 | * [object Object] // NodeJS, Opera, IE 171 | */ 172 | var console = __global__.console; 173 | 174 | if (console && typeof console === 'object') 175 | console.log(Array.prototype.join.call(arguments, '')); 176 | } 177 | }; 178 | 179 | /** @public */ 180 | var __config__ = { 181 | indent: ' ', // Set indentation 182 | describe: 58, // Max width for description section 183 | timeout: 25 // Timeout for the