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

Side by Side Diff: src/string.js

Issue 7741042: Make (some) functions called from builtin functions use the callback's global as receiver. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 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.cc ('k') | src/x64/full-codegen-x64.cc » ('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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_FUNCTION(replace)) {
254 var receiver = 254 var receiver = %GetDefaultReceiver(replace);
255 %_IsNativeOrStrictMode(replace) ? void 0 : %GetGlobalReceiver();
256 builder.add(%_CallFunction(receiver, 255 builder.add(%_CallFunction(receiver,
257 search, 256 search,
258 start, 257 start,
259 subject, 258 subject,
260 replace)); 259 replace));
261 } else { 260 } else {
262 reusableMatchInfo[CAPTURE0] = start; 261 reusableMatchInfo[CAPTURE0] = start;
263 reusableMatchInfo[CAPTURE1] = end; 262 reusableMatchInfo[CAPTURE1] = end;
264 replace = TO_STRING_INLINE(replace); 263 replace = TO_STRING_INLINE(replace);
265 ExpandReplacement(replace, subject, reusableMatchInfo, builder); 264 ExpandReplacement(replace, subject, reusableMatchInfo, builder);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 if (IS_NULL(res)) { 412 if (IS_NULL(res)) {
414 // No matches at all. 413 // No matches at all.
415 reusableReplaceArray = resultArray; 414 reusableReplaceArray = resultArray;
416 return subject; 415 return subject;
417 } 416 }
418 var len = res.length; 417 var len = res.length;
419 var i = 0; 418 var i = 0;
420 if (NUMBER_OF_CAPTURES(lastMatchInfo) == 2) { 419 if (NUMBER_OF_CAPTURES(lastMatchInfo) == 2) {
421 var match_start = 0; 420 var match_start = 0;
422 var override = new InternalArray(null, 0, subject); 421 var override = new InternalArray(null, 0, subject);
423 var receiver = 422 var receiver = %GetDefaultReceiver(replace);
424 %_IsNativeOrStrictMode(replace) ? void 0 : %GetGlobalReceiver();
425 while (i < len) { 423 while (i < len) {
426 var elem = res[i]; 424 var elem = res[i];
427 if (%_IsSmi(elem)) { 425 if (%_IsSmi(elem)) {
428 if (elem > 0) { 426 if (elem > 0) {
429 match_start = (elem >> 11) + (elem & 0x7ff); 427 match_start = (elem >> 11) + (elem & 0x7ff);
430 } else { 428 } else {
431 match_start = res[++i] - elem; 429 match_start = res[++i] - elem;
432 } 430 }
433 } else { 431 } else {
434 override[0] = elem; 432 override[0] = elem;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 var endOfMatch = matchInfo[CAPTURE1]; 469 var endOfMatch = matchInfo[CAPTURE1];
472 // Compute the parameter list consisting of the match, captures, index, 470 // Compute the parameter list consisting of the match, captures, index,
473 // and subject for the replace function invocation. 471 // and subject for the replace function invocation.
474 // The number of captures plus one for the match. 472 // The number of captures plus one for the match.
475 var m = NUMBER_OF_CAPTURES(matchInfo) >> 1; 473 var m = NUMBER_OF_CAPTURES(matchInfo) >> 1;
476 var replacement; 474 var replacement;
477 if (m == 1) { 475 if (m == 1) {
478 // No captures, only the match, which is always valid. 476 // No captures, only the match, which is always valid.
479 var s = SubString(subject, index, endOfMatch); 477 var s = SubString(subject, index, endOfMatch);
480 // Don't call directly to avoid exposing the built-in global object. 478 // Don't call directly to avoid exposing the built-in global object.
481 var receiver = 479 var receiver = %GetDefaultReceiver(replace);
482 %_IsNativeOrStrictMode(replace) ? void 0 : %GetGlobalReceiver();
483 replacement = 480 replacement =
484 %_CallFunction(receiver, s, index, subject, replace); 481 %_CallFunction(receiver, s, index, subject, replace);
485 } else { 482 } else {
486 var parameters = new InternalArray(m + 2); 483 var parameters = new InternalArray(m + 2);
487 for (var j = 0; j < m; j++) { 484 for (var j = 0; j < m; j++) {
488 parameters[j] = CaptureString(subject, matchInfo, j); 485 parameters[j] = CaptureString(subject, matchInfo, j);
489 } 486 }
490 parameters[j] = index; 487 parameters[j] = index;
491 parameters[j + 1] = subject; 488 parameters[j + 1] = subject;
492 489
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 "italics", StringItalics, 989 "italics", StringItalics,
993 "small", StringSmall, 990 "small", StringSmall,
994 "strike", StringStrike, 991 "strike", StringStrike,
995 "sub", StringSub, 992 "sub", StringSub,
996 "sup", StringSup 993 "sup", StringSup
997 )); 994 ));
998 } 995 }
999 996
1000 997
1001 SetupString(); 998 SetupString();
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698