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

Side by Side Diff: src/harmony-string.js

Issue 990883002: Hide Math function implementations in a closure. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove printf and unnecessary test case change. Created 5 years, 9 months 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
« no previous file with comments | « src/date.js ('k') | src/json.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 "use strict"; 5 "use strict";
6 6
7 // This file relies on the fact that the following declaration has been made 7 // This file relies on the fact that the following declaration has been made
8 // in runtime.js: 8 // in runtime.js:
9 // var $String = global.String; 9 // var $String = global.String;
10 // var $Array = global.Array; 10 // var $Array = global.Array;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 var ss = TO_STRING_INLINE(searchString); 47 var ss = TO_STRING_INLINE(searchString);
48 var pos = 0; 48 var pos = 0;
49 if (%_ArgumentsLength() > 1) { 49 if (%_ArgumentsLength() > 1) {
50 pos = %_Arguments(1); // position 50 pos = %_Arguments(1); // position
51 pos = ToInteger(pos); 51 pos = ToInteger(pos);
52 } 52 }
53 53
54 var s_len = s.length; 54 var s_len = s.length;
55 var start = MathMin(MathMax(pos, 0), s_len); 55 var start = $min($max(pos, 0), s_len);
56 var ss_len = ss.length; 56 var ss_len = ss.length;
57 if (ss_len + start > s_len) { 57 if (ss_len + start > s_len) {
58 return false; 58 return false;
59 } 59 }
60 60
61 return %StringIndexOf(s, ss, start) === start; 61 return %StringIndexOf(s, ss, start) === start;
62 } 62 }
63 63
64 64
65 // ES6 draft 04-05-14, section 21.1.3.7 65 // ES6 draft 04-05-14, section 21.1.3.7
(...skipping 10 matching lines...) Expand all
76 var ss = TO_STRING_INLINE(searchString); 76 var ss = TO_STRING_INLINE(searchString);
77 var s_len = s.length; 77 var s_len = s.length;
78 var pos = s_len; 78 var pos = s_len;
79 if (%_ArgumentsLength() > 1) { 79 if (%_ArgumentsLength() > 1) {
80 var arg = %_Arguments(1); // position 80 var arg = %_Arguments(1); // position
81 if (!IS_UNDEFINED(arg)) { 81 if (!IS_UNDEFINED(arg)) {
82 pos = ToInteger(arg); 82 pos = ToInteger(arg);
83 } 83 }
84 } 84 }
85 85
86 var end = MathMin(MathMax(pos, 0), s_len); 86 var end = $min($max(pos, 0), s_len);
87 var ss_len = ss.length; 87 var ss_len = ss.length;
88 var start = end - ss_len; 88 var start = end - ss_len;
89 if (start < 0) { 89 if (start < 0) {
90 return false; 90 return false;
91 } 91 }
92 92
93 return %StringLastIndexOf(s, ss, start) === start; 93 return %StringLastIndexOf(s, ss, start) === start;
94 } 94 }
95 95
96 96
97 // ES6 draft 04-05-14, section 21.1.3.6 97 // ES6 draft 04-05-14, section 21.1.3.6
98 function StringIncludes(searchString /* position */) { // length == 1 98 function StringIncludes(searchString /* position */) { // length == 1
99 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes"); 99 CHECK_OBJECT_COERCIBLE(this, "String.prototype.includes");
100 100
101 var s = TO_STRING_INLINE(this); 101 var s = TO_STRING_INLINE(this);
102 102
103 if (IS_REGEXP(searchString)) { 103 if (IS_REGEXP(searchString)) {
104 throw MakeTypeError("first_argument_not_regexp", 104 throw MakeTypeError("first_argument_not_regexp",
105 ["String.prototype.includes"]); 105 ["String.prototype.includes"]);
106 } 106 }
107 107
108 var ss = TO_STRING_INLINE(searchString); 108 var ss = TO_STRING_INLINE(searchString);
109 var pos = 0; 109 var pos = 0;
110 if (%_ArgumentsLength() > 1) { 110 if (%_ArgumentsLength() > 1) {
111 pos = %_Arguments(1); // position 111 pos = %_Arguments(1); // position
112 pos = ToInteger(pos); 112 pos = ToInteger(pos);
113 } 113 }
114 114
115 var s_len = s.length; 115 var s_len = s.length;
116 var start = MathMin(MathMax(pos, 0), s_len); 116 var start = $min($max(pos, 0), s_len);
117 var ss_len = ss.length; 117 var ss_len = ss.length;
118 if (ss_len + start > s_len) { 118 if (ss_len + start > s_len) {
119 return false; 119 return false;
120 } 120 }
121 121
122 return %StringIndexOf(s, ss, start) !== -1; 122 return %StringIndexOf(s, ss, start) !== -1;
123 } 123 }
124 124
125 125
126 // ES6 Draft 05-22-2014, section 21.1.3.3 126 // ES6 Draft 05-22-2014, section 21.1.3.3
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 InstallFunctions($String.prototype, DONT_ENUM, $Array( 185 InstallFunctions($String.prototype, DONT_ENUM, $Array(
186 "codePointAt", StringCodePointAt, 186 "codePointAt", StringCodePointAt,
187 "includes", StringIncludes, 187 "includes", StringIncludes,
188 "endsWith", StringEndsWith, 188 "endsWith", StringEndsWith,
189 "repeat", StringRepeat, 189 "repeat", StringRepeat,
190 "startsWith", StringStartsWith 190 "startsWith", StringStartsWith
191 )); 191 ));
192 } 192 }
193 193
194 ExtendStringPrototype(); 194 ExtendStringPrototype();
OLDNEW
« no previous file with comments | « src/date.js ('k') | src/json.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698