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

Side by Side Diff: src/string.js

Issue 1344893002: [builtins] Unify the String constructor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/runtime/runtime-symbol.cc ('k') | src/symbol.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 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 ArrayIndexOf; 12 var ArrayIndexOf;
13 var ArrayJoin; 13 var ArrayJoin;
14 var GlobalRegExp = global.RegExp; 14 var GlobalRegExp = global.RegExp;
15 var GlobalString = global.String; 15 var GlobalString = global.String;
16 var InternalArray = utils.InternalArray; 16 var InternalArray = utils.InternalArray;
17 var InternalPackedArray = utils.InternalPackedArray; 17 var InternalPackedArray = utils.InternalPackedArray;
18 var RegExpExec; 18 var RegExpExec;
19 var RegExpExecNoTests; 19 var RegExpExecNoTests;
20 var RegExpLastMatchInfo; 20 var RegExpLastMatchInfo;
21 var SymbolToString;
22 var ToNumber; 21 var ToNumber;
23 var ToString; 22 var ToString;
24 23
25 utils.Import(function(from) { 24 utils.Import(function(from) {
26 ArrayIndexOf = from.ArrayIndexOf; 25 ArrayIndexOf = from.ArrayIndexOf;
27 ArrayJoin = from.ArrayJoin; 26 ArrayJoin = from.ArrayJoin;
28 RegExpExec = from.RegExpExec; 27 RegExpExec = from.RegExpExec;
29 RegExpExecNoTests = from.RegExpExecNoTests; 28 RegExpExecNoTests = from.RegExpExecNoTests;
30 RegExpLastMatchInfo = from.RegExpLastMatchInfo; 29 RegExpLastMatchInfo = from.RegExpLastMatchInfo;
31 SymbolToString = from.SymbolToString;
32 ToNumber = from.ToNumber; 30 ToNumber = from.ToNumber;
33 ToString = from.ToString; 31 ToString = from.ToString;
34 }); 32 });
35 33
36 //------------------------------------------------------------------- 34 //-------------------------------------------------------------------
37 35
38 function StringConstructor(x) {
39 // TODO(bmeurer): Move this to toplevel.
40 "use strict";
41 if (%_ArgumentsLength() == 0) x = '';
42 if (%_IsConstructCall()) {
43 %_SetValueOf(this, TO_STRING_INLINE(x));
44 } else {
45 return IS_SYMBOL(x) ?
46 %_CallFunction(x, SymbolToString) : TO_STRING_INLINE(x);
47 }
48 }
49
50
51 // ECMA-262 section 15.5.4.2 36 // ECMA-262 section 15.5.4.2
52 function StringToString() { 37 function StringToString() {
53 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) { 38 if (!IS_STRING(this) && !IS_STRING_WRAPPER(this)) {
54 throw MakeTypeError(kNotGeneric, 'String.prototype.toString'); 39 throw MakeTypeError(kNotGeneric, 'String.prototype.toString');
55 } 40 }
56 return %_ValueOf(this); 41 return %_ValueOf(this);
57 } 42 }
58 43
59 44
60 // ECMA-262 section 15.5.4.3 45 // ECMA-262 section 15.5.4.3
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 } 1129 }
1145 result += ToString(raw[i]); 1130 result += ToString(raw[i]);
1146 } 1131 }
1147 1132
1148 return result; 1133 return result;
1149 } 1134 }
1150 1135
1151 // ------------------------------------------------------------------- 1136 // -------------------------------------------------------------------
1152 1137
1153 // Set the String function and constructor. 1138 // Set the String function and constructor.
1154 %SetCode(GlobalString, StringConstructor);
1155 %FunctionSetPrototype(GlobalString, new GlobalString()); 1139 %FunctionSetPrototype(GlobalString, new GlobalString());
1156 1140
1157 // Set up the constructor property on the String prototype object. 1141 // Set up the constructor property on the String prototype object.
1158 %AddNamedProperty( 1142 %AddNamedProperty(
1159 GlobalString.prototype, "constructor", GlobalString, DONT_ENUM); 1143 GlobalString.prototype, "constructor", GlobalString, DONT_ENUM);
1160 1144
1161 // Set up the non-enumerable functions on the String object. 1145 // Set up the non-enumerable functions on the String object.
1162 utils.InstallFunctions(GlobalString, DONT_ENUM, [ 1146 utils.InstallFunctions(GlobalString, DONT_ENUM, [
1163 "fromCharCode", StringFromCharCode, 1147 "fromCharCode", StringFromCharCode,
1164 "fromCodePoint", StringFromCodePoint, 1148 "fromCodePoint", StringFromCodePoint,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 to.StringLastIndexOf = StringLastIndexOfJS; 1204 to.StringLastIndexOf = StringLastIndexOfJS;
1221 to.StringMatch = StringMatchJS; 1205 to.StringMatch = StringMatchJS;
1222 to.StringReplace = StringReplace; 1206 to.StringReplace = StringReplace;
1223 to.StringSlice = StringSlice; 1207 to.StringSlice = StringSlice;
1224 to.StringSplit = StringSplitJS; 1208 to.StringSplit = StringSplitJS;
1225 to.StringSubstr = StringSubstr; 1209 to.StringSubstr = StringSubstr;
1226 to.StringSubstring = StringSubstring; 1210 to.StringSubstring = StringSubstring;
1227 }); 1211 });
1228 1212
1229 }) 1213 })
OLDNEW
« no previous file with comments | « src/runtime/runtime-symbol.cc ('k') | src/symbol.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698