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

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

Issue 2409513003: [regexp] Port remaining JS functions in regexp.js (Closed)
Patch Set: Rebaseline bytecode expectations 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/regexp.js ('k') | src/runtime/runtime.h » ('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 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ------------------------------------------------------------------- 9 // -------------------------------------------------------------------
10 // Imports 10 // Imports
11 11
12 var ArrayJoin; 12 var ArrayJoin;
13 var GetSubstitution; 13 var GetSubstitution;
14 var GlobalRegExp = global.RegExp; 14 var GlobalRegExp = global.RegExp;
15 var GlobalString = global.String; 15 var GlobalString = global.String;
16 var IsRegExp;
17 var MaxSimple; 16 var MaxSimple;
18 var MinSimple; 17 var MinSimple;
19 var RegExpInitialize;
20 var matchSymbol = utils.ImportNow("match_symbol"); 18 var matchSymbol = utils.ImportNow("match_symbol");
21 var replaceSymbol = utils.ImportNow("replace_symbol"); 19 var replaceSymbol = utils.ImportNow("replace_symbol");
22 var searchSymbol = utils.ImportNow("search_symbol"); 20 var searchSymbol = utils.ImportNow("search_symbol");
23 var splitSymbol = utils.ImportNow("split_symbol"); 21 var splitSymbol = utils.ImportNow("split_symbol");
24 22
25 utils.Import(function(from) { 23 utils.Import(function(from) {
26 ArrayJoin = from.ArrayJoin; 24 ArrayJoin = from.ArrayJoin;
27 GetSubstitution = from.GetSubstitution; 25 GetSubstitution = from.GetSubstitution;
28 IsRegExp = from.IsRegExp;
29 MaxSimple = from.MaxSimple; 26 MaxSimple = from.MaxSimple;
30 MinSimple = from.MinSimple; 27 MinSimple = from.MinSimple;
31 RegExpInitialize = from.RegExpInitialize;
32 }); 28 });
33 29
34 //------------------------------------------------------------------- 30 //-------------------------------------------------------------------
35 31
36 // ECMA-262, section 15.5.4.6 32 // ECMA-262, section 15.5.4.6
37 function StringConcat(other /* and more */) { // length == 1 33 function StringConcat(other /* and more */) { // length == 1
38 "use strict"; 34 "use strict";
39 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat"); 35 CHECK_OBJECT_COERCIBLE(this, "String.prototype.concat");
40 var s = TO_STRING(this); 36 var s = TO_STRING(this);
41 var len = arguments.length; 37 var len = arguments.length;
(...skipping 11 matching lines...) Expand all
53 if (!IS_NULL_OR_UNDEFINED(pattern)) { 49 if (!IS_NULL_OR_UNDEFINED(pattern)) {
54 var matcher = pattern[matchSymbol]; 50 var matcher = pattern[matchSymbol];
55 if (!IS_UNDEFINED(matcher)) { 51 if (!IS_UNDEFINED(matcher)) {
56 return %_Call(matcher, pattern, this); 52 return %_Call(matcher, pattern, this);
57 } 53 }
58 } 54 }
59 55
60 var subject = TO_STRING(this); 56 var subject = TO_STRING(this);
61 57
62 // Equivalent to RegExpCreate (ES#sec-regexpcreate) 58 // Equivalent to RegExpCreate (ES#sec-regexpcreate)
63 var regexp = %_NewObject(GlobalRegExp, GlobalRegExp); 59 var regexp = %RegExpCreate(pattern);
64 RegExpInitialize(regexp, pattern);
65 return regexp[matchSymbol](subject); 60 return regexp[matchSymbol](subject);
66 } 61 }
67 62
68 63
69 // ES6, section 21.1.3.14 64 // ES6, section 21.1.3.14
70 function StringReplace(search, replace) { 65 function StringReplace(search, replace) {
71 CHECK_OBJECT_COERCIBLE(this, "String.prototype.replace"); 66 CHECK_OBJECT_COERCIBLE(this, "String.prototype.replace");
72 67
73 // Decision tree for dispatch 68 // Decision tree for dispatch
74 // .. regexp search (in src/js/regexp.js, RegExpReplace) 69 // .. regexp search (in src/js/regexp.js, RegExpReplace)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 if (!IS_NULL_OR_UNDEFINED(pattern)) { 131 if (!IS_NULL_OR_UNDEFINED(pattern)) {
137 var searcher = pattern[searchSymbol]; 132 var searcher = pattern[searchSymbol];
138 if (!IS_UNDEFINED(searcher)) { 133 if (!IS_UNDEFINED(searcher)) {
139 return %_Call(searcher, pattern, this); 134 return %_Call(searcher, pattern, this);
140 } 135 }
141 } 136 }
142 137
143 var subject = TO_STRING(this); 138 var subject = TO_STRING(this);
144 139
145 // Equivalent to RegExpCreate (ES#sec-regexpcreate) 140 // Equivalent to RegExpCreate (ES#sec-regexpcreate)
146 var regexp = %_NewObject(GlobalRegExp, GlobalRegExp); 141 var regexp = %RegExpCreate(pattern);
147 RegExpInitialize(regexp, pattern);
148 return %_Call(regexp[searchSymbol], regexp, subject); 142 return %_Call(regexp[searchSymbol], regexp, subject);
149 } 143 }
150 144
151 145
152 // ECMA-262 section 15.5.4.13 146 // ECMA-262 section 15.5.4.13
153 function StringSlice(start, end) { 147 function StringSlice(start, end) {
154 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice"); 148 CHECK_OBJECT_COERCIBLE(this, "String.prototype.slice");
155 149
156 var s = TO_STRING(this); 150 var s = TO_STRING(this);
157 var s_len = s.length; 151 var s_len = s.length;
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // Exports 461 // Exports
468 462
469 utils.Export(function(to) { 463 utils.Export(function(to) {
470 to.StringMatch = StringMatchJS; 464 to.StringMatch = StringMatchJS;
471 to.StringReplace = StringReplace; 465 to.StringReplace = StringReplace;
472 to.StringSlice = StringSlice; 466 to.StringSlice = StringSlice;
473 to.StringSplit = StringSplitJS; 467 to.StringSplit = StringSplitJS;
474 }); 468 });
475 469
476 }) 470 })
OLDNEW
« no previous file with comments | « src/js/regexp.js ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698