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

Side by Side Diff: src/v8natives.js

Issue 7830036: Optimize isFinite and isNaN. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Made the change general by moving putting it in the NUMBER_IS_FINITE macro. Created 9 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 | Annotate | Revision Log
« no previous file with comments | « src/uri.js ('k') | src/weakmap.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 23 matching lines...) Expand all
34 // const $Function = global.Function; 34 // const $Function = global.Function;
35 // const $Array = global.Array; 35 // const $Array = global.Array;
36 // const $NaN = 0/0; 36 // const $NaN = 0/0;
37 // 37 //
38 // in math.js: 38 // in math.js:
39 // const $floor = MathFloor 39 // const $floor = MathFloor
40 40
41 const $isNaN = GlobalIsNaN; 41 const $isNaN = GlobalIsNaN;
42 const $isFinite = GlobalIsFinite; 42 const $isFinite = GlobalIsFinite;
43 43
44
45 // ---------------------------------------------------------------------------- 44 // ----------------------------------------------------------------------------
46 45
47 46
48 // Helper function used to install functions on objects. 47 // Helper function used to install functions on objects.
49 function InstallFunctions(object, attributes, functions) { 48 function InstallFunctions(object, attributes, functions) {
50 if (functions.length >= 8) { 49 if (functions.length >= 8) {
51 %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); 50 %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1);
52 } 51 }
53 for (var i = 0; i < functions.length; i += 2) { 52 for (var i = 0; i < functions.length; i += 2) {
54 var key = functions[i]; 53 var key = functions[i];
(...skipping 13 matching lines...) Expand all
68 %SetNativeFlag(f); 67 %SetNativeFlag(f);
69 } 68 }
70 %ToFastProperties(object); 69 %ToFastProperties(object);
71 } 70 }
72 71
73 // Emulates JSC by installing functions on a hidden prototype that 72 // Emulates JSC by installing functions on a hidden prototype that
74 // lies above the current object/prototype. This lets you override 73 // lies above the current object/prototype. This lets you override
75 // functions on String.prototype etc. and then restore the old function 74 // functions on String.prototype etc. and then restore the old function
76 // with delete. See http://code.google.com/p/chromium/issues/detail?id=1717 75 // with delete. See http://code.google.com/p/chromium/issues/detail?id=1717
77 function InstallFunctionsOnHiddenPrototype(object, attributes, functions) { 76 function InstallFunctionsOnHiddenPrototype(object, attributes, functions) {
78 %CheckIsBootstrapping();
79 var hidden_prototype = new $Object(); 77 var hidden_prototype = new $Object();
80 %SetHiddenPrototype(object, hidden_prototype); 78 %SetHiddenPrototype(object, hidden_prototype);
81 InstallFunctions(hidden_prototype, attributes, functions); 79 InstallFunctions(hidden_prototype, attributes, functions);
82 } 80 }
83 81
84 82
85 // Prevents changes to the prototype of a built-infunction.
86 // The "prototype" property of the function object is made non-configurable,
87 // and the prototype object is made non-extensible. The latter prevents
88 // changing the __proto__ property.
89 function SetUpLockedPrototype(constructor, fields, methods) {
90 %CheckIsBootstrapping();
91 var prototype = constructor.prototype;
92 // Install functions first, because this function is used to initialize
93 // PropertyDescriptor itself.
94 var property_count = (methods.length >> 1) + (fields ? fields.length : 0);
95 if (property_count >= 4) {
96 %OptimizeObjectForAddingMultipleProperties(prototype, property_count);
97 }
98 if (fields) {
99 for (var i = 0; i < fields.length; i++) {
100 %SetProperty(prototype, fields[i], void 0, DONT_ENUM | DONT_DELETE);
101 }
102 }
103 for (var i = 0; i < methods.length; i += 2) {
104 var key = methods[i];
105 var f = methods[i + 1];
106 %SetProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY);
107 %SetNativeFlag(f);
108 }
109 prototype.__proto__ = null;
110 %PreventExtensions(prototype);
111 %ToFastProperties(prototype);
112
113 var desc = GetOwnProperty(constructor, "prototype");
114 desc.setWritable(false);
115 desc.setConfigurable(false);
116 DefineOwnProperty(constructor, "prototype", desc, false);
117 }
118
119
120 // ---------------------------------------------------------------------------- 83 // ----------------------------------------------------------------------------
121 84
122 85
123 // ECMA 262 - 15.1.4 86 // ECMA 262 - 15.1.4
124 function GlobalIsNaN(number) { 87 function GlobalIsNaN(number) {
125 var n = ToNumber(number); 88 if (!IS_NUMBER(number)) number = NonNumberToNumber(number);
126 return NUMBER_IS_NAN(n); 89 return NUMBER_IS_NAN(number);
127 } 90 }
128 91
129 92
130 // ECMA 262 - 15.1.5 93 // ECMA 262 - 15.1.5
131 function GlobalIsFinite(number) { 94 function GlobalIsFinite(number) {
132 if (!IS_NUMBER(number)) number = NonNumberToNumber(number); 95 if (!IS_NUMBER(number)) number = NonNumberToNumber(number);
133 96 return NUMBER_IS_FINITE(number);
134 // NaN - NaN == NaN, Infinity - Infinity == NaN, -Infinity - -Infinity == NaN.
135 return %_IsSmi(number) || number - number == 0;
136 } 97 }
137 98
138 99
139 // ECMA-262 - 15.1.2.2 100 // ECMA-262 - 15.1.2.2
140 function GlobalParseInt(string, radix) { 101 function GlobalParseInt(string, radix) {
141 if (IS_UNDEFINED(radix) || radix === 10 || radix === 0) { 102 if (IS_UNDEFINED(radix) || radix === 10 || radix === 0) {
142 // Some people use parseInt instead of Math.floor. This 103 // Some people use parseInt instead of Math.floor. This
143 // optimization makes parseInt on a Smi 12 times faster (60ns 104 // optimization makes parseInt on a Smi 12 times faster (60ns
144 // vs 800ns). The following optimization makes parseInt on a 105 // vs 800ns). The following optimization makes parseInt on a
145 // non-Smi number 9 times faster (230ns vs 2070ns). Together 106 // non-Smi number 9 times faster (230ns vs 2070ns). Together
146 // they make parseInt on a string 1.4% slower (274ns vs 270ns). 107 // they make parseInt on a string 1.4% slower (274ns vs 270ns).
147 if (%_IsSmi(string)) return string; 108 if (%_IsSmi(string)) return string;
148 if (IS_NUMBER(string) && 109 if (IS_NUMBER(string) &&
149 ((0.01 < string && string < 1e9) || 110 ((0.01 < string && string < 1e9) ||
150 (-1e9 < string && string < -0.01))) { 111 (-1e9 < string && string < -0.01))) {
151 // Truncate number. 112 // Truncate number.
152 return string | 0; 113 return string | 0;
153 } 114 }
154 string = TO_STRING_INLINE(string);
155 radix = radix | 0; 115 radix = radix | 0;
156 } else { 116 } else {
157 // The spec says ToString should be evaluated before ToInt32.
158 string = TO_STRING_INLINE(string);
159 radix = TO_INT32(radix); 117 radix = TO_INT32(radix);
160 if (!(radix == 0 || (2 <= radix && radix <= 36))) 118 if (!(radix == 0 || (2 <= radix && radix <= 36)))
161 return $NaN; 119 return $NaN;
162 } 120 }
163 121 string = TO_STRING_INLINE(string);
164 if (%_HasCachedArrayIndex(string) && 122 if (%_HasCachedArrayIndex(string) &&
165 (radix == 0 || radix == 10)) { 123 (radix == 0 || radix == 10)) {
166 return %_GetCachedArrayIndex(string); 124 return %_GetCachedArrayIndex(string);
167 } 125 }
168 return %StringParseInt(string, radix); 126 return %StringParseInt(string, radix);
169 } 127 }
170 128
171 129
172 // ECMA-262 - 15.1.2.3 130 // ECMA-262 - 15.1.2.3
173 function GlobalParseFloat(string) { 131 function GlobalParseFloat(string) {
(...skipping 26 matching lines...) Expand all
200 158
201 var f = %CompileString(x); 159 var f = %CompileString(x);
202 if (!IS_FUNCTION(f)) return f; 160 if (!IS_FUNCTION(f)) return f;
203 161
204 return %_CallFunction(receiver, f); 162 return %_CallFunction(receiver, f);
205 } 163 }
206 164
207 165
208 // ---------------------------------------------------------------------------- 166 // ----------------------------------------------------------------------------
209 167
210 // Set up global object. 168
211 function SetUpGlobal() { 169 function SetupGlobal() {
212 %CheckIsBootstrapping();
213 // ECMA 262 - 15.1.1.1. 170 // ECMA 262 - 15.1.1.1.
214 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); 171 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE);
215 172
216 // ECMA-262 - 15.1.1.2. 173 // ECMA-262 - 15.1.1.2.
217 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE); 174 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE);
218 175
219 // ECMA-262 - 15.1.1.3. 176 // ECMA-262 - 15.1.1.3.
220 %SetProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE); 177 %SetProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE);
221 178
222 // Set up non-enumerable function on the global object. 179 // Setup non-enumerable function on the global object.
223 InstallFunctions(global, DONT_ENUM, $Array( 180 InstallFunctions(global, DONT_ENUM, $Array(
224 "isNaN", GlobalIsNaN, 181 "isNaN", GlobalIsNaN,
225 "isFinite", GlobalIsFinite, 182 "isFinite", GlobalIsFinite,
226 "parseInt", GlobalParseInt, 183 "parseInt", GlobalParseInt,
227 "parseFloat", GlobalParseFloat, 184 "parseFloat", GlobalParseFloat,
228 "eval", GlobalEval 185 "eval", GlobalEval
229 )); 186 ));
230 } 187 }
231 188
232 SetUpGlobal(); 189 SetupGlobal();
190
233 191
234 // ---------------------------------------------------------------------------- 192 // ----------------------------------------------------------------------------
235 // Boolean (first part of definition) 193 // Boolean (first part of definition)
236 194
237 195
238 %SetCode($Boolean, function(x) { 196 %SetCode($Boolean, function(x) {
239 if (%_IsConstructCall()) { 197 if (%_IsConstructCall()) {
240 %_SetValueOf(this, ToBoolean(x)); 198 %_SetValueOf(this, ToBoolean(x));
241 } else { 199 } else {
242 return ToBoolean(x); 200 return ToBoolean(x);
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 this.enumerable_ = false; 477 this.enumerable_ = false;
520 this.hasEnumerable_ = false; 478 this.hasEnumerable_ = false;
521 this.configurable_ = false; 479 this.configurable_ = false;
522 this.hasConfigurable_ = false; 480 this.hasConfigurable_ = false;
523 this.get_ = void 0; 481 this.get_ = void 0;
524 this.hasGetter_ = false; 482 this.hasGetter_ = false;
525 this.set_ = void 0; 483 this.set_ = void 0;
526 this.hasSetter_ = false; 484 this.hasSetter_ = false;
527 } 485 }
528 486
529 SetUpLockedPrototype(PropertyDescriptor, $Array( 487 PropertyDescriptor.prototype.__proto__ = null;
530 "value_", 488
531 "hasValue_", 489 PropertyDescriptor.prototype.toString = function() {
532 "writable_", 490 return "[object PropertyDescriptor]";
533 "hasWritable_", 491 };
534 "enumerable_", 492
535 "hasEnumerable_", 493 PropertyDescriptor.prototype.setValue = function(value) {
536 "configurable_", 494 this.value_ = value;
537 "hasConfigurable_", 495 this.hasValue_ = true;
538 "get_", 496 }
539 "hasGetter_", 497
540 "set_", 498
541 "hasSetter_" 499 PropertyDescriptor.prototype.getValue = function() {
542 ), $Array( 500 return this.value_;
543 "toString", function() { 501 }
544 return "[object PropertyDescriptor]"; 502
545 }, 503
546 "setValue", function(value) { 504 PropertyDescriptor.prototype.hasValue = function() {
547 this.value_ = value; 505 return this.hasValue_;
548 this.hasValue_ = true; 506 }
549 }, 507
550 "getValue", function() { 508
551 return this.value_; 509 PropertyDescriptor.prototype.setEnumerable = function(enumerable) {
552 }, 510 this.enumerable_ = enumerable;
553 "hasValue", function() { 511 this.hasEnumerable_ = true;
554 return this.hasValue_; 512 }
555 }, 513
556 "setEnumerable", function(enumerable) { 514
557 this.enumerable_ = enumerable; 515 PropertyDescriptor.prototype.isEnumerable = function () {
558 this.hasEnumerable_ = true; 516 return this.enumerable_;
559 }, 517 }
560 "isEnumerable", function () { 518
561 return this.enumerable_; 519
562 }, 520 PropertyDescriptor.prototype.hasEnumerable = function() {
563 "hasEnumerable", function() { 521 return this.hasEnumerable_;
564 return this.hasEnumerable_; 522 }
565 }, 523
566 "setWritable", function(writable) { 524
567 this.writable_ = writable; 525 PropertyDescriptor.prototype.setWritable = function(writable) {
568 this.hasWritable_ = true; 526 this.writable_ = writable;
569 }, 527 this.hasWritable_ = true;
570 "isWritable", function() { 528 }
571 return this.writable_; 529
572 }, 530
573 "hasWritable", function() { 531 PropertyDescriptor.prototype.isWritable = function() {
574 return this.hasWritable_; 532 return this.writable_;
575 }, 533 }
576 "setConfigurable", function(configurable) { 534
577 this.configurable_ = configurable; 535
578 this.hasConfigurable_ = true; 536 PropertyDescriptor.prototype.hasWritable = function() {
579 }, 537 return this.hasWritable_;
580 "hasConfigurable", function() { 538 }
581 return this.hasConfigurable_; 539
582 }, 540
583 "isConfigurable", function() { 541 PropertyDescriptor.prototype.setConfigurable = function(configurable) {
584 return this.configurable_; 542 this.configurable_ = configurable;
585 }, 543 this.hasConfigurable_ = true;
586 "setGet", function(get) { 544 }
587 this.get_ = get; 545
588 this.hasGetter_ = true; 546
589 }, 547 PropertyDescriptor.prototype.hasConfigurable = function() {
590 "getGet", function() { 548 return this.hasConfigurable_;
591 return this.get_; 549 }
592 }, 550
593 "hasGetter", function() { 551
594 return this.hasGetter_; 552 PropertyDescriptor.prototype.isConfigurable = function() {
595 }, 553 return this.configurable_;
596 "setSet", function(set) { 554 }
597 this.set_ = set; 555
598 this.hasSetter_ = true; 556
599 }, 557 PropertyDescriptor.prototype.setGet = function(get) {
600 "getSet", function() { 558 this.get_ = get;
601 return this.set_; 559 this.hasGetter_ = true;
602 }, 560 }
603 "hasSetter", function() { 561
604 return this.hasSetter_; 562
605 })); 563 PropertyDescriptor.prototype.getGet = function() {
564 return this.get_;
565 }
566
567
568 PropertyDescriptor.prototype.hasGetter = function() {
569 return this.hasGetter_;
570 }
571
572
573 PropertyDescriptor.prototype.setSet = function(set) {
574 this.set_ = set;
575 this.hasSetter_ = true;
576 }
577
578
579 PropertyDescriptor.prototype.getSet = function() {
580 return this.set_;
581 }
582
583
584 PropertyDescriptor.prototype.hasSetter = function() {
585 return this.hasSetter_;
586 }
606 587
607 588
608 // Converts an array returned from Runtime_GetOwnProperty to an actual 589 // Converts an array returned from Runtime_GetOwnProperty to an actual
609 // property descriptor. For a description of the array layout please 590 // property descriptor. For a description of the array layout please
610 // see the runtime.cc file. 591 // see the runtime.cc file.
611 function ConvertDescriptorArrayToDescriptor(desc_array) { 592 function ConvertDescriptorArrayToDescriptor(desc_array) {
612 if (desc_array === false) { 593 if (desc_array === false) {
613 throw 'Internal error: invalid desc_array'; 594 throw 'Internal error: invalid desc_array';
614 } 595 }
615 596
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 return ToObject(x); 1164 return ToObject(x);
1184 } else { 1165 } else {
1185 if (x == null) return { }; 1166 if (x == null) return { };
1186 return ToObject(x); 1167 return ToObject(x);
1187 } 1168 }
1188 }); 1169 });
1189 1170
1190 %SetExpectedNumberOfProperties($Object, 4); 1171 %SetExpectedNumberOfProperties($Object, 4);
1191 1172
1192 // ---------------------------------------------------------------------------- 1173 // ----------------------------------------------------------------------------
1193 // Object
1194 1174
1195 function SetUpObject() { 1175
1196 %CheckIsBootstrapping(); 1176 function SetupObject() {
1197 // Set Up non-enumerable functions on the Object.prototype object. 1177 // Setup non-enumerable functions on the Object.prototype object.
1198 InstallFunctions($Object.prototype, DONT_ENUM, $Array( 1178 InstallFunctions($Object.prototype, DONT_ENUM, $Array(
1199 "toString", ObjectToString, 1179 "toString", ObjectToString,
1200 "toLocaleString", ObjectToLocaleString, 1180 "toLocaleString", ObjectToLocaleString,
1201 "valueOf", ObjectValueOf, 1181 "valueOf", ObjectValueOf,
1202 "hasOwnProperty", ObjectHasOwnProperty, 1182 "hasOwnProperty", ObjectHasOwnProperty,
1203 "isPrototypeOf", ObjectIsPrototypeOf, 1183 "isPrototypeOf", ObjectIsPrototypeOf,
1204 "propertyIsEnumerable", ObjectPropertyIsEnumerable, 1184 "propertyIsEnumerable", ObjectPropertyIsEnumerable,
1205 "__defineGetter__", ObjectDefineGetter, 1185 "__defineGetter__", ObjectDefineGetter,
1206 "__lookupGetter__", ObjectLookupGetter, 1186 "__lookupGetter__", ObjectLookupGetter,
1207 "__defineSetter__", ObjectDefineSetter, 1187 "__defineSetter__", ObjectDefineSetter,
1208 "__lookupSetter__", ObjectLookupSetter 1188 "__lookupSetter__", ObjectLookupSetter
1209 )); 1189 ));
1210 InstallFunctions($Object, DONT_ENUM, $Array( 1190 InstallFunctions($Object, DONT_ENUM, $Array(
1211 "keys", ObjectKeys, 1191 "keys", ObjectKeys,
1212 "create", ObjectCreate, 1192 "create", ObjectCreate,
1213 "defineProperty", ObjectDefineProperty, 1193 "defineProperty", ObjectDefineProperty,
1214 "defineProperties", ObjectDefineProperties, 1194 "defineProperties", ObjectDefineProperties,
1215 "freeze", ObjectFreeze, 1195 "freeze", ObjectFreeze,
1216 "getPrototypeOf", ObjectGetPrototypeOf, 1196 "getPrototypeOf", ObjectGetPrototypeOf,
1217 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, 1197 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
1218 "getOwnPropertyNames", ObjectGetOwnPropertyNames, 1198 "getOwnPropertyNames", ObjectGetOwnPropertyNames,
1219 "isExtensible", ObjectIsExtensible, 1199 "isExtensible", ObjectIsExtensible,
1220 "isFrozen", ObjectIsFrozen, 1200 "isFrozen", ObjectIsFrozen,
1221 "isSealed", ObjectIsSealed, 1201 "isSealed", ObjectIsSealed,
1222 "preventExtensions", ObjectPreventExtension, 1202 "preventExtensions", ObjectPreventExtension,
1223 "seal", ObjectSeal 1203 "seal", ObjectSeal
1224 )); 1204 ));
1225 } 1205 }
1226 1206
1227 SetUpObject(); 1207 SetupObject();
1208
1228 1209
1229 // ---------------------------------------------------------------------------- 1210 // ----------------------------------------------------------------------------
1230 // Boolean 1211 // Boolean
1231 1212
1232 function BooleanToString() { 1213 function BooleanToString() {
1233 // NOTE: Both Boolean objects and values can enter here as 1214 // NOTE: Both Boolean objects and values can enter here as
1234 // 'this'. This is not as dictated by ECMA-262. 1215 // 'this'. This is not as dictated by ECMA-262.
1235 var b = this; 1216 var b = this;
1236 if (!IS_BOOLEAN(b)) { 1217 if (!IS_BOOLEAN(b)) {
1237 if (!IS_BOOLEAN_WRAPPER(b)) { 1218 if (!IS_BOOLEAN_WRAPPER(b)) {
(...skipping 10 matching lines...) Expand all
1248 // 'this'. This is not as dictated by ECMA-262. 1229 // 'this'. This is not as dictated by ECMA-262.
1249 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) 1230 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this))
1250 throw new $TypeError('Boolean.prototype.valueOf is not generic'); 1231 throw new $TypeError('Boolean.prototype.valueOf is not generic');
1251 return %_ValueOf(this); 1232 return %_ValueOf(this);
1252 } 1233 }
1253 1234
1254 1235
1255 // ---------------------------------------------------------------------------- 1236 // ----------------------------------------------------------------------------
1256 1237
1257 1238
1258 function SetUpBoolean () { 1239 function SetupBoolean() {
1259 %CheckIsBootstrapping();
1260 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( 1240 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array(
1261 "toString", BooleanToString, 1241 "toString", BooleanToString,
1262 "valueOf", BooleanValueOf 1242 "valueOf", BooleanValueOf
1263 )); 1243 ));
1264 } 1244 }
1265 1245
1266 SetUpBoolean(); 1246 SetupBoolean();
1267
1268 1247
1269 // ---------------------------------------------------------------------------- 1248 // ----------------------------------------------------------------------------
1270 // Number 1249 // Number
1271 1250
1272 // Set the Number function and constructor. 1251 // Set the Number function and constructor.
1273 %SetCode($Number, function(x) { 1252 %SetCode($Number, function(x) {
1274 var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); 1253 var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x);
1275 if (%_IsConstructCall()) { 1254 if (%_IsConstructCall()) {
1276 %_SetValueOf(this, value); 1255 %_SetValueOf(this, value);
1277 } else { 1256 } else {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 if (p < 1 || p > 21) { 1350 if (p < 1 || p > 21) {
1372 throw new $RangeError("toPrecision() argument must be between 1 and 21"); 1351 throw new $RangeError("toPrecision() argument must be between 1 and 21");
1373 } 1352 }
1374 var x = ToNumber(this); 1353 var x = ToNumber(this);
1375 return %NumberToPrecision(x, p); 1354 return %NumberToPrecision(x, p);
1376 } 1355 }
1377 1356
1378 1357
1379 // ---------------------------------------------------------------------------- 1358 // ----------------------------------------------------------------------------
1380 1359
1381 function SetUpNumber() { 1360 function SetupNumber() {
1382 %CheckIsBootstrapping();
1383 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); 1361 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8);
1384 // Set up the constructor property on the Number prototype object. 1362 // Setup the constructor property on the Number prototype object.
1385 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); 1363 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM);
1386 1364
1387 %OptimizeObjectForAddingMultipleProperties($Number, 5); 1365 %OptimizeObjectForAddingMultipleProperties($Number, 5);
1388 // ECMA-262 section 15.7.3.1. 1366 // ECMA-262 section 15.7.3.1.
1389 %SetProperty($Number, 1367 %SetProperty($Number,
1390 "MAX_VALUE", 1368 "MAX_VALUE",
1391 1.7976931348623157e+308, 1369 1.7976931348623157e+308,
1392 DONT_ENUM | DONT_DELETE | READ_ONLY); 1370 DONT_ENUM | DONT_DELETE | READ_ONLY);
1393 1371
1394 // ECMA-262 section 15.7.3.2. 1372 // ECMA-262 section 15.7.3.2.
1395 %SetProperty($Number, "MIN_VALUE", 5e-324, DONT_ENUM | DONT_DELETE | READ_ONLY ); 1373 %SetProperty($Number, "MIN_VALUE", 5e-324, DONT_ENUM | DONT_DELETE | READ_ONLY );
1396 1374
1397 // ECMA-262 section 15.7.3.3. 1375 // ECMA-262 section 15.7.3.3.
1398 %SetProperty($Number, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); 1376 %SetProperty($Number, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY);
1399 1377
1400 // ECMA-262 section 15.7.3.4. 1378 // ECMA-262 section 15.7.3.4.
1401 %SetProperty($Number, 1379 %SetProperty($Number,
1402 "NEGATIVE_INFINITY", 1380 "NEGATIVE_INFINITY",
1403 -1/0, 1381 -1/0,
1404 DONT_ENUM | DONT_DELETE | READ_ONLY); 1382 DONT_ENUM | DONT_DELETE | READ_ONLY);
1405 1383
1406 // ECMA-262 section 15.7.3.5. 1384 // ECMA-262 section 15.7.3.5.
1407 %SetProperty($Number, 1385 %SetProperty($Number,
1408 "POSITIVE_INFINITY", 1386 "POSITIVE_INFINITY",
1409 1/0, 1387 1/0,
1410 DONT_ENUM | DONT_DELETE | READ_ONLY); 1388 DONT_ENUM | DONT_DELETE | READ_ONLY);
1411 %ToFastProperties($Number); 1389 %ToFastProperties($Number);
1412 1390
1413 // Set up non-enumerable functions on the Number prototype object. 1391 // Setup non-enumerable functions on the Number prototype object.
1414 InstallFunctions($Number.prototype, DONT_ENUM, $Array( 1392 InstallFunctions($Number.prototype, DONT_ENUM, $Array(
1415 "toString", NumberToString, 1393 "toString", NumberToString,
1416 "toLocaleString", NumberToLocaleString, 1394 "toLocaleString", NumberToLocaleString,
1417 "valueOf", NumberValueOf, 1395 "valueOf", NumberValueOf,
1418 "toFixed", NumberToFixed, 1396 "toFixed", NumberToFixed,
1419 "toExponential", NumberToExponential, 1397 "toExponential", NumberToExponential,
1420 "toPrecision", NumberToPrecision 1398 "toPrecision", NumberToPrecision
1421 )); 1399 ));
1422 } 1400 }
1423 1401
1424 SetUpNumber(); 1402 SetupNumber();
1425 1403
1426 1404
1427 // ---------------------------------------------------------------------------- 1405 // ----------------------------------------------------------------------------
1428 // Function 1406 // Function
1429 1407
1430 $Function.prototype.constructor = $Function; 1408 $Function.prototype.constructor = $Function;
1431 1409
1432 function FunctionSourceString(func) { 1410 function FunctionSourceString(func) {
1433 if (!IS_FUNCTION(func)) { 1411 if (!IS_FUNCTION(func)) {
1434 throw new $TypeError('Function.prototype.toString is not generic'); 1412 throw new $TypeError('Function.prototype.toString is not generic');
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). 1521 // property of the resulting function is enumerable (ECMA262, 15.3.5.2).
1544 var f = %CompileString(source)(); 1522 var f = %CompileString(source)();
1545 %FunctionMarkNameShouldPrintAsAnonymous(f); 1523 %FunctionMarkNameShouldPrintAsAnonymous(f);
1546 return %SetNewFunctionAttributes(f); 1524 return %SetNewFunctionAttributes(f);
1547 } 1525 }
1548 1526
1549 %SetCode($Function, NewFunction); 1527 %SetCode($Function, NewFunction);
1550 1528
1551 // ---------------------------------------------------------------------------- 1529 // ----------------------------------------------------------------------------
1552 1530
1553 function SetUpFunction() { 1531 function SetupFunction() {
1554 %CheckIsBootstrapping();
1555 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1532 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1556 "bind", FunctionBind, 1533 "bind", FunctionBind,
1557 "toString", FunctionToString 1534 "toString", FunctionToString
1558 )); 1535 ));
1559 } 1536 }
1560 1537
1561 SetUpFunction(); 1538 SetupFunction();
OLDNEW
« no previous file with comments | « src/uri.js ('k') | src/weakmap.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698