Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: src/string.js

Issue 8701006: Clean up JavaScript files to better follow coding standard. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 28 matching lines...) Expand all
39 %_SetValueOf(this, value); 39 %_SetValueOf(this, value);
40 } else { 40 } else {
41 return value; 41 return value;
42 } 42 }
43 }); 43 });
44 44
45 %FunctionSetPrototype($String, new $String()); 45 %FunctionSetPrototype($String, new $String());
46 46
47 // ECMA-262 section 15.5.4.2 47 // ECMA-262 section 15.5.4.2
48 function StringToString() { 48 function StringToString() {
49 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) 49 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
50 throw new $TypeError('String.prototype.toString is not generic'); 50 throw new $TypeError('String.prototype.toString is not generic');
51 }
51 return %_ValueOf(this); 52 return %_ValueOf(this);
52 } 53 }
53 54
54 55
55 // ECMA-262 section 15.5.4.3 56 // ECMA-262 section 15.5.4.3
56 function StringValueOf() { 57 function StringValueOf() {
57 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) 58 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
58 throw new $TypeError('String.prototype.valueOf is not generic'); 59 throw new $TypeError('String.prototype.valueOf is not generic');
60 }
59 return %_ValueOf(this); 61 return %_ValueOf(this);
60 } 62 }
61 63
62 64
63 // ECMA-262, section 15.5.4.4 65 // ECMA-262, section 15.5.4.4
64 function StringCharAt(pos) { 66 function StringCharAt(pos) {
65 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 67 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
66 throw MakeTypeError("called_on_null_or_undefined", 68 throw MakeTypeError("called_on_null_or_undefined",
67 ["String.prototype.charAt"]); 69 ["String.prototype.charAt"]);
68 } 70 }
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 // ECMA-262 section 15.5.4.13 526 // ECMA-262 section 15.5.4.13
525 function StringSlice(start, end) { 527 function StringSlice(start, end) {
526 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 528 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
527 throw MakeTypeError("called_on_null_or_undefined", 529 throw MakeTypeError("called_on_null_or_undefined",
528 ["String.prototype.slice"]); 530 ["String.prototype.slice"]);
529 } 531 }
530 var s = TO_STRING_INLINE(this); 532 var s = TO_STRING_INLINE(this);
531 var s_len = s.length; 533 var s_len = s.length;
532 var start_i = TO_INTEGER(start); 534 var start_i = TO_INTEGER(start);
533 var end_i = s_len; 535 var end_i = s_len;
534 if (end !== void 0) 536 if (end !== void 0) {
535 end_i = TO_INTEGER(end); 537 end_i = TO_INTEGER(end);
538 }
536 539
537 if (start_i < 0) { 540 if (start_i < 0) {
538 start_i += s_len; 541 start_i += s_len;
539 if (start_i < 0) 542 if (start_i < 0) {
540 start_i = 0; 543 start_i = 0;
544 }
541 } else { 545 } else {
542 if (start_i > s_len) 546 if (start_i > s_len) {
543 start_i = s_len; 547 start_i = s_len;
548 }
544 } 549 }
545 550
546 if (end_i < 0) { 551 if (end_i < 0) {
547 end_i += s_len; 552 end_i += s_len;
548 if (end_i < 0) 553 if (end_i < 0) {
549 end_i = 0; 554 end_i = 0;
555 }
550 } else { 556 } else {
551 if (end_i > s_len) 557 if (end_i > s_len) {
552 end_i = s_len; 558 end_i = s_len;
559 }
553 } 560 }
554 561
555 var num_c = end_i - start_i; 562 var num_c = end_i - start_i;
556 if (num_c < 0) 563 if (num_c < 0) {
557 num_c = 0; 564 num_c = 0;
565 }
558 566
559 return SubString(s, start_i, start_i + num_c); 567 return SubString(s, start_i, start_i + num_c);
560 } 568 }
561 569
562 570
563 // ECMA-262 section 15.5.4.14 571 // ECMA-262 section 15.5.4.14
564 function StringSplit(separator, limit) { 572 function StringSplit(separator, limit) {
565 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 573 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
566 throw MakeTypeError("called_on_null_or_undefined", 574 throw MakeTypeError("called_on_null_or_undefined",
567 ["String.prototype.split"]); 575 ["String.prototype.split"]);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 } else { 693 } else {
686 if (end_i < 0) end_i = 0; 694 if (end_i < 0) end_i = 0;
687 if (start_i > end_i) { 695 if (start_i > end_i) {
688 var tmp = end_i; 696 var tmp = end_i;
689 end_i = start_i; 697 end_i = start_i;
690 start_i = tmp; 698 start_i = tmp;
691 } 699 }
692 } 700 }
693 } 701 }
694 702
695 return (start_i + 1 == end_i 703 return ((start_i + 1 == end_i)
696 ? %_StringCharAt(s, start_i) 704 ? %_StringCharAt(s, start_i)
697 : %_SubString(s, start_i, end_i)); 705 : %_SubString(s, start_i, end_i));
698 } 706 }
699 707
700 708
701 // This is not a part of ECMA-262. 709 // This is not a part of ECMA-262.
702 function StringSubstr(start, n) { 710 function StringSubstr(start, n) {
703 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 711 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
704 throw MakeTypeError("called_on_null_or_undefined", 712 throw MakeTypeError("called_on_null_or_undefined",
705 ["String.prototype.substr"]); 713 ["String.prototype.substr"]);
(...skipping 23 matching lines...) Expand all
729 // use zero. 737 // use zero.
730 if (start < 0) { 738 if (start < 0) {
731 start += s.length; 739 start += s.length;
732 if (start < 0) start = 0; 740 if (start < 0) start = 0;
733 } 741 }
734 } 742 }
735 743
736 var end = start + len; 744 var end = start + len;
737 if (end > s.length) end = s.length; 745 if (end > s.length) end = s.length;
738 746
739 return (start + 1 == end 747 return ((start + 1 == end)
740 ? %_StringCharAt(s, start) 748 ? %_StringCharAt(s, start)
741 : %_SubString(s, start, end)); 749 : %_SubString(s, start, end));
742 } 750 }
743 751
744 752
745 // ECMA-262, 15.5.4.16 753 // ECMA-262, 15.5.4.16
746 function StringToLowerCase() { 754 function StringToLowerCase() {
747 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 755 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
748 throw MakeTypeError("called_on_null_or_undefined", 756 throw MakeTypeError("called_on_null_or_undefined",
749 ["String.prototype.toLowerCase"]); 757 ["String.prototype.toLowerCase"]);
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 "fixed", StringFixed, 998 "fixed", StringFixed,
991 "italics", StringItalics, 999 "italics", StringItalics,
992 "small", StringSmall, 1000 "small", StringSmall,
993 "strike", StringStrike, 1001 "strike", StringStrike,
994 "sub", StringSub, 1002 "sub", StringSub,
995 "sup", StringSup 1003 "sup", StringSup
996 )); 1004 ));
997 } 1005 }
998 1006
999 SetUpString(); 1007 SetUpString();
OLDNEW
« no previous file with comments | « src/mirror-debugger.js ('k') | src/v8natives.js » ('j') | src/v8natives.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698