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

Side by Side Diff: src/js/regexp.js

Issue 2415103002: [regexp] Turn last match info into a simple FixedArray (Closed)
Patch Set: Don't check instance type before map check Created 4 years, 2 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/js/macros.py ('k') | src/mips/code-stubs-mips.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 (function(global, utils) { 5 (function(global, utils) {
6 6
7 'use strict'; 7 'use strict';
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 12
13 // Property of the builtins object for recording the result of the last
14 // regexp match. The property RegExpLastMatchInfo includes the matchIndices
15 // array of the last successful regexp match (an array of start/end index
16 // pairs for the match and all the captured substrings), the invariant is
17 // that there are at least two capture indices. The array also contains
18 // the subject string for the last successful match.
19 // We use a JSObject rather than a JSArray so we don't have to manually update
20 // its length.
21 var RegExpLastMatchInfo = {
22 REGEXP_NUMBER_OF_CAPTURES: 2,
23 REGEXP_LAST_SUBJECT: "",
24 REGEXP_LAST_INPUT: UNDEFINED, // Settable with RegExpSetInput.
25 CAPTURE0: 0,
26 CAPTURE1: 0
27 };
28
29 // ES#sec-getsubstitution 13 // ES#sec-getsubstitution
30 // GetSubstitution(matched, str, position, captures, replacement) 14 // GetSubstitution(matched, str, position, captures, replacement)
31 // Expand the $-expressions in the string and return a new string with 15 // Expand the $-expressions in the string and return a new string with
32 // the result. 16 // the result.
33 function GetSubstitution(matched, string, position, captures, replacement) { 17 function GetSubstitution(matched, string, position, captures, replacement) {
34 var matchLength = matched.length; 18 var matchLength = matched.length;
35 var stringLength = string.length; 19 var stringLength = string.length;
36 var capturesLength = captures.length; 20 var capturesLength = captures.length;
37 var tailPos = position + matchLength; 21 var tailPos = position + matchLength;
38 var result = ""; 22 var result = "";
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 89
106 // Append substring between the previous and the next $ character. 90 // Append substring between the previous and the next $ character.
107 if (next > pos) { 91 if (next > pos) {
108 result += %_SubString(replacement, pos, next); 92 result += %_SubString(replacement, pos, next);
109 } 93 }
110 } 94 }
111 return result; 95 return result;
112 } 96 }
113 97
114 // ------------------------------------------------------------------- 98 // -------------------------------------------------------------------
115
116 %InstallToContext(["regexp_last_match_info", RegExpLastMatchInfo]);
117
118 // -------------------------------------------------------------------
119 // Exports 99 // Exports
120 100
121 utils.Export(function(to) { 101 utils.Export(function(to) {
122 to.GetSubstitution = GetSubstitution; 102 to.GetSubstitution = GetSubstitution;
123 }); 103 });
124 104
125 }) 105 })
OLDNEW
« no previous file with comments | « src/js/macros.py ('k') | src/mips/code-stubs-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698