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

Side by Side Diff: src/string.js

Issue 7623011: Implement function proxies (except for their use as constructors). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed second round of comments. Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.js ('k') | src/v8natives.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 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 function StringReplace(search, replace) { 216 function StringReplace(search, replace) {
217 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 217 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
218 throw MakeTypeError("called_on_null_or_undefined", 218 throw MakeTypeError("called_on_null_or_undefined",
219 ["String.prototype.replace"]); 219 ["String.prototype.replace"]);
220 } 220 }
221 var subject = TO_STRING_INLINE(this); 221 var subject = TO_STRING_INLINE(this);
222 222
223 // Delegate to one of the regular expression variants if necessary. 223 // Delegate to one of the regular expression variants if necessary.
224 if (IS_REGEXP(search)) { 224 if (IS_REGEXP(search)) {
225 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); 225 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]);
226 if (IS_FUNCTION(replace)) { 226 if (IS_SPEC_FUNCTION(replace)) {
227 if (search.global) { 227 if (search.global) {
228 return StringReplaceGlobalRegExpWithFunction(subject, search, replace); 228 return StringReplaceGlobalRegExpWithFunction(subject, search, replace);
229 } else { 229 } else {
230 return StringReplaceNonGlobalRegExpWithFunction(subject, 230 return StringReplaceNonGlobalRegExpWithFunction(subject,
231 search, 231 search,
232 replace); 232 replace);
233 } 233 }
234 } else { 234 } else {
235 return %StringReplaceRegExpWithString(subject, 235 return %StringReplaceRegExpWithString(subject,
236 search, 236 search,
237 TO_STRING_INLINE(replace), 237 TO_STRING_INLINE(replace),
238 lastMatchInfo); 238 lastMatchInfo);
239 } 239 }
240 } 240 }
241 241
242 // Convert the search argument to a string and search for it. 242 // Convert the search argument to a string and search for it.
243 search = TO_STRING_INLINE(search); 243 search = TO_STRING_INLINE(search);
244 var start = %StringIndexOf(subject, search, 0); 244 var start = %StringIndexOf(subject, search, 0);
245 if (start < 0) return subject; 245 if (start < 0) return subject;
246 var end = start + search.length; 246 var end = start + search.length;
247 247
248 var builder = new ReplaceResultBuilder(subject); 248 var builder = new ReplaceResultBuilder(subject);
249 // prefix 249 // prefix
250 builder.addSpecialSlice(0, start); 250 builder.addSpecialSlice(0, start);
251 251
252 // Compute the string to replace with. 252 // Compute the string to replace with.
253 if (IS_FUNCTION(replace)) { 253 if (IS_SPEC_FUNCTION(replace)) {
254 var receiver = 254 var receiver =
255 %_IsNativeOrStrictMode(replace) ? void 0 : %GetGlobalReceiver(); 255 %_IsNativeOrStrictMode(replace) ? void 0 : %GetGlobalReceiver();
256 builder.add(%_CallFunction(receiver, 256 builder.add(%_CallFunction(receiver,
257 search, 257 search,
258 start, 258 start,
259 subject, 259 subject,
260 replace)); 260 replace));
261 } else { 261 } else {
262 reusableMatchInfo[CAPTURE0] = start; 262 reusableMatchInfo[CAPTURE0] = start;
263 reusableMatchInfo[CAPTURE1] = end; 263 reusableMatchInfo[CAPTURE1] = end;
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 "italics", StringItalics, 990 "italics", StringItalics,
991 "small", StringSmall, 991 "small", StringSmall,
992 "strike", StringStrike, 992 "strike", StringStrike,
993 "sub", StringSub, 993 "sub", StringSub,
994 "sup", StringSup 994 "sup", StringSup
995 )); 995 ));
996 } 996 }
997 997
998 998
999 SetupString(); 999 SetupString();
OLDNEW
« no previous file with comments | « src/runtime.js ('k') | src/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698