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

Side by Side Diff: src/v8natives.js

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

Powered by Google App Engine
This is Rietveld 408576698