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

Side by Side Diff: src/v8natives.js

Issue 6928007: Reapply 7763, including arm and x64 variants. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 7 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/string.js ('k') | src/x64/builtins-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-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); 202 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM);
203 203
204 // ---------------------------------------------------------------------------- 204 // ----------------------------------------------------------------------------
205 // Object 205 // Object
206 206
207 $Object.prototype.constructor = $Object; 207 $Object.prototype.constructor = $Object;
208 208
209 // ECMA-262 - 15.2.4.2 209 // ECMA-262 - 15.2.4.2
210 function ObjectToString() { 210 function ObjectToString() {
211 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
212 return '[object Undefined]';
213 }
214 if (IS_NULL(this)) return '[object Null]';
211 return "[object " + %_ClassOf(ToObject(this)) + "]"; 215 return "[object " + %_ClassOf(ToObject(this)) + "]";
212 } 216 }
213 217
214 218
215 // ECMA-262 - 15.2.4.3 219 // ECMA-262 - 15.2.4.3
216 function ObjectToLocaleString() { 220 function ObjectToLocaleString() {
221 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
222 throw MakeTypeError("called_on_null_or_undefined",
223 ["Object.prototype.toLocaleString"]);
224 }
217 return this.toString(); 225 return this.toString();
218 } 226 }
219 227
220 228
221 // ECMA-262 - 15.2.4.4 229 // ECMA-262 - 15.2.4.4
222 function ObjectValueOf() { 230 function ObjectValueOf() {
223 return ToObject(this); 231 return ToObject(this);
224 } 232 }
225 233
226 234
227 // ECMA-262 - 15.2.4.5 235 // ECMA-262 - 15.2.4.5
228 function ObjectHasOwnProperty(V) { 236 function ObjectHasOwnProperty(V) {
229 return %HasLocalProperty(ToObject(this), ToString(V)); 237 return %HasLocalProperty(ToObject(this), ToString(V));
230 } 238 }
231 239
232 240
233 // ECMA-262 - 15.2.4.6 241 // ECMA-262 - 15.2.4.6
234 function ObjectIsPrototypeOf(V) { 242 function ObjectIsPrototypeOf(V) {
243 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
244 throw MakeTypeError("called_on_null_or_undefined",
245 ["Object.prototype.isPrototypeOf"]);
246 }
235 if (!IS_SPEC_OBJECT(V)) return false; 247 if (!IS_SPEC_OBJECT(V)) return false;
236 return %IsInPrototypeChain(this, V); 248 return %IsInPrototypeChain(this, V);
237 } 249 }
238 250
239 251
240 // ECMA-262 - 15.2.4.6 252 // ECMA-262 - 15.2.4.6
241 function ObjectPropertyIsEnumerable(V) { 253 function ObjectPropertyIsEnumerable(V) {
242 return %IsPropertyEnumerable(ToObject(this), ToString(V)); 254 return %IsPropertyEnumerable(ToObject(this), ToString(V));
243 } 255 }
244 256
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 if (radix < 2 || radix > 36) { 1067 if (radix < 2 || radix > 36) {
1056 throw new $RangeError('toString() radix argument must be between 2 and 36'); 1068 throw new $RangeError('toString() radix argument must be between 2 and 36');
1057 } 1069 }
1058 // Convert the number to a string in the given radix. 1070 // Convert the number to a string in the given radix.
1059 return %NumberToRadixString(number, radix); 1071 return %NumberToRadixString(number, radix);
1060 } 1072 }
1061 1073
1062 1074
1063 // ECMA-262 section 15.7.4.3 1075 // ECMA-262 section 15.7.4.3
1064 function NumberToLocaleString() { 1076 function NumberToLocaleString() {
1077 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1078 throw MakeTypeError("called_on_null_or_undefined",
1079 ["Number.prototype.toLocaleString"]);
1080 }
1065 return this.toString(); 1081 return this.toString();
1066 } 1082 }
1067 1083
1068 1084
1069 // ECMA-262 section 15.7.4.4 1085 // ECMA-262 section 15.7.4.4
1070 function NumberValueOf() { 1086 function NumberValueOf() {
1071 // NOTE: Both Number objects and values can enter here as 1087 // NOTE: Both Number objects and values can enter here as
1072 // 'this'. This is not as dictated by ECMA-262. 1088 // 'this'. This is not as dictated by ECMA-262.
1073 if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this)) 1089 if (!IS_NUMBER(this) && !IS_NUMBER_WRAPPER(this))
1074 throw new $TypeError('Number.prototype.valueOf is not generic'); 1090 throw new $TypeError('Number.prototype.valueOf is not generic');
1075 return %_ValueOf(this); 1091 return %_ValueOf(this);
1076 } 1092 }
1077 1093
1078 1094
1079 // ECMA-262 section 15.7.4.5 1095 // ECMA-262 section 15.7.4.5
1080 function NumberToFixed(fractionDigits) { 1096 function NumberToFixed(fractionDigits) {
1081 var f = TO_INTEGER(fractionDigits); 1097 var f = TO_INTEGER(fractionDigits);
1082 if (f < 0 || f > 20) { 1098 if (f < 0 || f > 20) {
1083 throw new $RangeError("toFixed() digits argument must be between 0 and 20"); 1099 throw new $RangeError("toFixed() digits argument must be between 0 and 20");
1084 } 1100 }
1101 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1102 throw MakeTypeError("called_on_null_or_undefined",
1103 ["Number.prototype.toFixed"]);
1104 }
1085 var x = ToNumber(this); 1105 var x = ToNumber(this);
1086 return %NumberToFixed(x, f); 1106 return %NumberToFixed(x, f);
1087 } 1107 }
1088 1108
1089 1109
1090 // ECMA-262 section 15.7.4.6 1110 // ECMA-262 section 15.7.4.6
1091 function NumberToExponential(fractionDigits) { 1111 function NumberToExponential(fractionDigits) {
1092 var f = -1; 1112 var f = -1;
1093 if (!IS_UNDEFINED(fractionDigits)) { 1113 if (!IS_UNDEFINED(fractionDigits)) {
1094 f = TO_INTEGER(fractionDigits); 1114 f = TO_INTEGER(fractionDigits);
1095 if (f < 0 || f > 20) { 1115 if (f < 0 || f > 20) {
1096 throw new $RangeError("toExponential() argument must be between 0 and 20") ; 1116 throw new $RangeError("toExponential() argument must be between 0 and 20") ;
1097 } 1117 }
1098 } 1118 }
1119 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1120 throw MakeTypeError("called_on_null_or_undefined",
1121 ["Number.prototype.toExponential"]);
1122 }
1099 var x = ToNumber(this); 1123 var x = ToNumber(this);
1100 return %NumberToExponential(x, f); 1124 return %NumberToExponential(x, f);
1101 } 1125 }
1102 1126
1103 1127
1104 // ECMA-262 section 15.7.4.7 1128 // ECMA-262 section 15.7.4.7
1105 function NumberToPrecision(precision) { 1129 function NumberToPrecision(precision) {
1130 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
1131 throw MakeTypeError("called_on_null_or_undefined",
1132 ["Number.prototype.toPrecision"]);
1133 }
1106 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); 1134 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this));
1107 var p = TO_INTEGER(precision); 1135 var p = TO_INTEGER(precision);
1108 if (p < 1 || p > 21) { 1136 if (p < 1 || p > 21) {
1109 throw new $RangeError("toPrecision() argument must be between 1 and 21"); 1137 throw new $RangeError("toPrecision() argument must be between 1 and 21");
1110 } 1138 }
1111 var x = ToNumber(this); 1139 var x = ToNumber(this);
1112 return %NumberToPrecision(x, p); 1140 return %NumberToPrecision(x, p);
1113 } 1141 }
1114 1142
1115 1143
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 // Function 1192 // Function
1165 1193
1166 $Function.prototype.constructor = $Function; 1194 $Function.prototype.constructor = $Function;
1167 1195
1168 function FunctionSourceString(func) { 1196 function FunctionSourceString(func) {
1169 if (!IS_FUNCTION(func)) { 1197 if (!IS_FUNCTION(func)) {
1170 throw new $TypeError('Function.prototype.toString is not generic'); 1198 throw new $TypeError('Function.prototype.toString is not generic');
1171 } 1199 }
1172 1200
1173 var source = %FunctionGetSourceCode(func); 1201 var source = %FunctionGetSourceCode(func);
1202 if (!IS_STRING(source)) return "NOT A string";
1174 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) { 1203 if (!IS_STRING(source) || %FunctionIsBuiltin(func)) {
1175 var name = %FunctionGetName(func); 1204 var name = %FunctionGetName(func);
1176 if (name) { 1205 if (name) {
1177 // Mimic what KJS does. 1206 // Mimic what KJS does.
1178 return 'function ' + name + '() { [native code] }'; 1207 return 'function ' + name + '() { [native code] }';
1179 } else { 1208 } else {
1180 return 'function () { [native code] }'; 1209 return 'function () { [native code] }';
1181 } 1210 }
1182 } 1211 }
1183 1212
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 // ---------------------------------------------------------------------------- 1313 // ----------------------------------------------------------------------------
1285 1314
1286 function SetupFunction() { 1315 function SetupFunction() {
1287 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1316 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1288 "bind", FunctionBind, 1317 "bind", FunctionBind,
1289 "toString", FunctionToString 1318 "toString", FunctionToString
1290 )); 1319 ));
1291 } 1320 }
1292 1321
1293 SetupFunction(); 1322 SetupFunction();
OLDNEW
« no previous file with comments | « src/string.js ('k') | src/x64/builtins-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698