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

Side by Side Diff: src/v8natives.js

Issue 27491002: Cosmetic: Add macros for NaN, undefined and Infinity to native js code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/string.js ('k') | no next file » | 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 // 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 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // This file relies on the fact that the following declarations have been made 28 // This file relies on the fact that the following declarations have been made
29 // in runtime.js: 29 // in runtime.js:
30 // var $Object = global.Object; 30 // var $Object = global.Object;
31 // var $Boolean = global.Boolean; 31 // var $Boolean = global.Boolean;
32 // var $Number = global.Number; 32 // var $Number = global.Number;
33 // var $Function = global.Function; 33 // var $Function = global.Function;
34 // var $Array = global.Array; 34 // var $Array = global.Array;
35 // var $NaN = 0/0;
36 // 35 //
37 // in math.js: 36 // in math.js:
38 // var $floor = MathFloor 37 // var $floor = MathFloor
39 38
40 var $isNaN = GlobalIsNaN; 39 var $isNaN = GlobalIsNaN;
41 var $isFinite = GlobalIsFinite; 40 var $isFinite = GlobalIsFinite;
42 41
43 // ---------------------------------------------------------------------------- 42 // ----------------------------------------------------------------------------
44 43
45 // Helper function used to install functions on objects. 44 // Helper function used to install functions on objects.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 %CheckIsBootstrapping(); 87 %CheckIsBootstrapping();
89 var prototype = constructor.prototype; 88 var prototype = constructor.prototype;
90 // Install functions first, because this function is used to initialize 89 // Install functions first, because this function is used to initialize
91 // PropertyDescriptor itself. 90 // PropertyDescriptor itself.
92 var property_count = (methods.length >> 1) + (fields ? fields.length : 0); 91 var property_count = (methods.length >> 1) + (fields ? fields.length : 0);
93 if (property_count >= 4) { 92 if (property_count >= 4) {
94 %OptimizeObjectForAddingMultipleProperties(prototype, property_count); 93 %OptimizeObjectForAddingMultipleProperties(prototype, property_count);
95 } 94 }
96 if (fields) { 95 if (fields) {
97 for (var i = 0; i < fields.length; i++) { 96 for (var i = 0; i < fields.length; i++) {
98 %SetProperty(prototype, fields[i], void 0, DONT_ENUM | DONT_DELETE); 97 %SetProperty(prototype, fields[i], UNDEFINED, DONT_ENUM | DONT_DELETE);
99 } 98 }
100 } 99 }
101 for (var i = 0; i < methods.length; i += 2) { 100 for (var i = 0; i < methods.length; i += 2) {
102 var key = methods[i]; 101 var key = methods[i];
103 var f = methods[i + 1]; 102 var f = methods[i + 1];
104 %SetProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY); 103 %SetProperty(prototype, key, f, DONT_ENUM | DONT_DELETE | READ_ONLY);
105 %SetNativeFlag(f); 104 %SetNativeFlag(f);
106 } 105 }
107 %SetPrototype(prototype, null); 106 %SetPrototype(prototype, null);
108 %ToFastProperties(prototype); 107 %ToFastProperties(prototype);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Truncate number. 140 // Truncate number.
142 return string | 0; 141 return string | 0;
143 } 142 }
144 string = TO_STRING_INLINE(string); 143 string = TO_STRING_INLINE(string);
145 radix = radix | 0; 144 radix = radix | 0;
146 } else { 145 } else {
147 // The spec says ToString should be evaluated before ToInt32. 146 // The spec says ToString should be evaluated before ToInt32.
148 string = TO_STRING_INLINE(string); 147 string = TO_STRING_INLINE(string);
149 radix = TO_INT32(radix); 148 radix = TO_INT32(radix);
150 if (!(radix == 0 || (2 <= radix && radix <= 36))) { 149 if (!(radix == 0 || (2 <= radix && radix <= 36))) {
151 return $NaN; 150 return NAN;
152 } 151 }
153 } 152 }
154 153
155 if (%_HasCachedArrayIndex(string) && 154 if (%_HasCachedArrayIndex(string) &&
156 (radix == 0 || radix == 10)) { 155 (radix == 0 || radix == 10)) {
157 return %_GetCachedArrayIndex(string); 156 return %_GetCachedArrayIndex(string);
158 } 157 }
159 return %StringParseInt(string, radix); 158 return %StringParseInt(string, radix);
160 } 159 }
161 160
(...skipping 28 matching lines...) Expand all
190 return %_CallFunction(global_receiver, f); 189 return %_CallFunction(global_receiver, f);
191 } 190 }
192 191
193 192
194 // ---------------------------------------------------------------------------- 193 // ----------------------------------------------------------------------------
195 194
196 // Set up global object. 195 // Set up global object.
197 function SetUpGlobal() { 196 function SetUpGlobal() {
198 %CheckIsBootstrapping(); 197 %CheckIsBootstrapping();
199 198
199 var attributes = DONT_ENUM | DONT_DELETE | READ_ONLY;
200
200 // ECMA 262 - 15.1.1.1. 201 // ECMA 262 - 15.1.1.1.
201 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); 202 %SetProperty(global, "NaN", NAN, attributes);
202 203
203 // ECMA-262 - 15.1.1.2. 204 // ECMA-262 - 15.1.1.2.
204 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE | READ_ONLY); 205 %SetProperty(global, "Infinity", INFINITY, attributes);
205 206
206 // ECMA-262 - 15.1.1.3. 207 // ECMA-262 - 15.1.1.3.
207 %SetProperty(global, "undefined", void 0, 208 %SetProperty(global, "undefined", UNDEFINED, attributes);
208 DONT_ENUM | DONT_DELETE | READ_ONLY);
209 209
210 // Set up non-enumerable function on the global object. 210 // Set up non-enumerable function on the global object.
211 InstallFunctions(global, DONT_ENUM, $Array( 211 InstallFunctions(global, DONT_ENUM, $Array(
212 "isNaN", GlobalIsNaN, 212 "isNaN", GlobalIsNaN,
213 "isFinite", GlobalIsFinite, 213 "isFinite", GlobalIsFinite,
214 "parseInt", GlobalParseInt, 214 "parseInt", GlobalParseInt,
215 "parseFloat", GlobalParseFloat, 215 "parseFloat", GlobalParseFloat,
216 "eval", GlobalEval 216 "eval", GlobalEval
217 )); 217 ));
218 } 218 }
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 throw MakeTypeError("value_and_accessor", [obj]); 468 throw MakeTypeError("value_and_accessor", [obj]);
469 } 469 }
470 return desc; 470 return desc;
471 } 471 }
472 472
473 473
474 // For Harmony proxies. 474 // For Harmony proxies.
475 function ToCompletePropertyDescriptor(obj) { 475 function ToCompletePropertyDescriptor(obj) {
476 var desc = ToPropertyDescriptor(obj); 476 var desc = ToPropertyDescriptor(obj);
477 if (IsGenericDescriptor(desc) || IsDataDescriptor(desc)) { 477 if (IsGenericDescriptor(desc) || IsDataDescriptor(desc)) {
478 if (!desc.hasValue()) desc.setValue(void 0); 478 if (!desc.hasValue()) desc.setValue(UNDEFINED);
479 if (!desc.hasWritable()) desc.setWritable(false); 479 if (!desc.hasWritable()) desc.setWritable(false);
480 } else { 480 } else {
481 // Is accessor descriptor. 481 // Is accessor descriptor.
482 if (!desc.hasGetter()) desc.setGet(void 0); 482 if (!desc.hasGetter()) desc.setGet(UNDEFINED);
483 if (!desc.hasSetter()) desc.setSet(void 0); 483 if (!desc.hasSetter()) desc.setSet(UNDEFINED);
484 } 484 }
485 if (!desc.hasEnumerable()) desc.setEnumerable(false); 485 if (!desc.hasEnumerable()) desc.setEnumerable(false);
486 if (!desc.hasConfigurable()) desc.setConfigurable(false); 486 if (!desc.hasConfigurable()) desc.setConfigurable(false);
487 return desc; 487 return desc;
488 } 488 }
489 489
490 490
491 function PropertyDescriptor() { 491 function PropertyDescriptor() {
492 // Initialize here so they are all in-object and have the same map. 492 // Initialize here so they are all in-object and have the same map.
493 // Default values from ES5 8.6.1. 493 // Default values from ES5 8.6.1.
494 this.value_ = void 0; 494 this.value_ = UNDEFINED;
495 this.hasValue_ = false; 495 this.hasValue_ = false;
496 this.writable_ = false; 496 this.writable_ = false;
497 this.hasWritable_ = false; 497 this.hasWritable_ = false;
498 this.enumerable_ = false; 498 this.enumerable_ = false;
499 this.hasEnumerable_ = false; 499 this.hasEnumerable_ = false;
500 this.configurable_ = false; 500 this.configurable_ = false;
501 this.hasConfigurable_ = false; 501 this.hasConfigurable_ = false;
502 this.get_ = void 0; 502 this.get_ = UNDEFINED;
503 this.hasGetter_ = false; 503 this.hasGetter_ = false;
504 this.set_ = void 0; 504 this.set_ = UNDEFINED;
505 this.hasSetter_ = false; 505 this.hasSetter_ = false;
506 } 506 }
507 507
508 SetUpLockedPrototype(PropertyDescriptor, $Array( 508 SetUpLockedPrototype(PropertyDescriptor, $Array(
509 "value_", 509 "value_",
510 "hasValue_", 510 "hasValue_",
511 "writable_", 511 "writable_",
512 "hasWritable_", 512 "hasWritable_",
513 "enumerable_", 513 "enumerable_",
514 "hasEnumerable_", 514 "hasEnumerable_",
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 586
587 // Converts an array returned from Runtime_GetOwnProperty to an actual 587 // Converts an array returned from Runtime_GetOwnProperty to an actual
588 // property descriptor. For a description of the array layout please 588 // property descriptor. For a description of the array layout please
589 // see the runtime.cc file. 589 // see the runtime.cc file.
590 function ConvertDescriptorArrayToDescriptor(desc_array) { 590 function ConvertDescriptorArrayToDescriptor(desc_array) {
591 if (desc_array === false) { 591 if (desc_array === false) {
592 throw 'Internal error: invalid desc_array'; 592 throw 'Internal error: invalid desc_array';
593 } 593 }
594 594
595 if (IS_UNDEFINED(desc_array)) { 595 if (IS_UNDEFINED(desc_array)) {
596 return void 0; 596 return UNDEFINED;
597 } 597 }
598 598
599 var desc = new PropertyDescriptor(); 599 var desc = new PropertyDescriptor();
600 // This is an accessor. 600 // This is an accessor.
601 if (desc_array[IS_ACCESSOR_INDEX]) { 601 if (desc_array[IS_ACCESSOR_INDEX]) {
602 desc.setGet(desc_array[GETTER_INDEX]); 602 desc.setGet(desc_array[GETTER_INDEX]);
603 desc.setSet(desc_array[SETTER_INDEX]); 603 desc.setSet(desc_array[SETTER_INDEX]);
604 } else { 604 } else {
605 desc.setValue(desc_array[VALUE_INDEX]); 605 desc.setValue(desc_array[VALUE_INDEX]);
606 desc.setWritable(desc_array[WRITABLE_INDEX]); 606 desc.setWritable(desc_array[WRITABLE_INDEX]);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 function CallTrap2(handler, name, defaultTrap, x, y) { 640 function CallTrap2(handler, name, defaultTrap, x, y) {
641 return %_CallFunction(handler, x, y, GetTrap(handler, name, defaultTrap)); 641 return %_CallFunction(handler, x, y, GetTrap(handler, name, defaultTrap));
642 } 642 }
643 643
644 644
645 // ES5 section 8.12.1. 645 // ES5 section 8.12.1.
646 function GetOwnProperty(obj, v) { 646 function GetOwnProperty(obj, v) {
647 var p = ToName(v); 647 var p = ToName(v);
648 if (%IsJSProxy(obj)) { 648 if (%IsJSProxy(obj)) {
649 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 649 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
650 if (IS_SYMBOL(v)) return void 0; 650 if (IS_SYMBOL(v)) return UNDEFINED;
651 651
652 var handler = %GetHandler(obj); 652 var handler = %GetHandler(obj);
653 var descriptor = CallTrap1(handler, "getOwnPropertyDescriptor", void 0, p); 653 var descriptor = CallTrap1(
654 handler, "getOwnPropertyDescriptor", UNDEFINED, p);
654 if (IS_UNDEFINED(descriptor)) return descriptor; 655 if (IS_UNDEFINED(descriptor)) return descriptor;
655 var desc = ToCompletePropertyDescriptor(descriptor); 656 var desc = ToCompletePropertyDescriptor(descriptor);
656 if (!desc.isConfigurable()) { 657 if (!desc.isConfigurable()) {
657 throw MakeTypeError("proxy_prop_not_configurable", 658 throw MakeTypeError("proxy_prop_not_configurable",
658 [handler, "getOwnPropertyDescriptor", p, descriptor]); 659 [handler, "getOwnPropertyDescriptor", p, descriptor]);
659 } 660 }
660 return desc; 661 return desc;
661 } 662 }
662 663
663 // GetOwnProperty returns an array indexed by the constants 664 // GetOwnProperty returns an array indexed by the constants
664 // defined in macros.py. 665 // defined in macros.py.
665 // If p is not a property on obj undefined is returned. 666 // If p is not a property on obj undefined is returned.
666 var props = %GetOwnProperty(ToObject(obj), p); 667 var props = %GetOwnProperty(ToObject(obj), p);
667 668
668 // A false value here means that access checks failed. 669 // A false value here means that access checks failed.
669 if (props === false) return void 0; 670 if (props === false) return UNDEFINED;
670 671
671 return ConvertDescriptorArrayToDescriptor(props); 672 return ConvertDescriptorArrayToDescriptor(props);
672 } 673 }
673 674
674 675
675 // ES5 section 8.12.7. 676 // ES5 section 8.12.7.
676 function Delete(obj, p, should_throw) { 677 function Delete(obj, p, should_throw) {
677 var desc = GetOwnProperty(obj, p); 678 var desc = GetOwnProperty(obj, p);
678 if (IS_UNDEFINED(desc)) return true; 679 if (IS_UNDEFINED(desc)) return true;
679 if (desc.isConfigurable()) { 680 if (desc.isConfigurable()) {
680 %DeleteProperty(obj, p, 0); 681 %DeleteProperty(obj, p, 0);
681 return true; 682 return true;
682 } else if (should_throw) { 683 } else if (should_throw) {
683 throw MakeTypeError("define_disallowed", [p]); 684 throw MakeTypeError("define_disallowed", [p]);
684 } else { 685 } else {
685 return; 686 return;
686 } 687 }
687 } 688 }
688 689
689 690
690 // Harmony proxies. 691 // Harmony proxies.
691 function DefineProxyProperty(obj, p, attributes, should_throw) { 692 function DefineProxyProperty(obj, p, attributes, should_throw) {
692 // TODO(rossberg): adjust once there is a story for symbols vs proxies. 693 // TODO(rossberg): adjust once there is a story for symbols vs proxies.
693 if (IS_SYMBOL(p)) return false; 694 if (IS_SYMBOL(p)) return false;
694 695
695 var handler = %GetHandler(obj); 696 var handler = %GetHandler(obj);
696 var result = CallTrap2(handler, "defineProperty", void 0, p, attributes); 697 var result = CallTrap2(handler, "defineProperty", UNDEFINED, p, attributes);
697 if (!ToBoolean(result)) { 698 if (!ToBoolean(result)) {
698 if (should_throw) { 699 if (should_throw) {
699 throw MakeTypeError("handler_returned_false", 700 throw MakeTypeError("handler_returned_false",
700 [handler, "defineProperty"]); 701 [handler, "defineProperty"]);
701 } else { 702 } else {
702 return false; 703 return false;
703 } 704 }
704 } 705 }
705 return true; 706 return true;
706 } 707 }
707 708
708 709
709 // ES5 8.12.9. 710 // ES5 8.12.9.
710 function DefineObjectProperty(obj, p, desc, should_throw) { 711 function DefineObjectProperty(obj, p, desc, should_throw) {
711 var current_or_access = %GetOwnProperty(ToObject(obj), ToName(p)); 712 var current_or_access = %GetOwnProperty(ToObject(obj), ToName(p));
712 // A false value here means that access checks failed. 713 // A false value here means that access checks failed.
713 if (current_or_access === false) return void 0; 714 if (current_or_access === false) return UNDEFINED;
714 715
715 var current = ConvertDescriptorArrayToDescriptor(current_or_access); 716 var current = ConvertDescriptorArrayToDescriptor(current_or_access);
716 var extensible = %IsExtensible(ToObject(obj)); 717 var extensible = %IsExtensible(ToObject(obj));
717 718
718 // Error handling according to spec. 719 // Error handling according to spec.
719 // Step 3 720 // Step 3
720 if (IS_UNDEFINED(current) && !extensible) { 721 if (IS_UNDEFINED(current) && !extensible) {
721 if (should_throw) { 722 if (should_throw) {
722 throw MakeTypeError("define_disallowed", [p]); 723 throw MakeTypeError("define_disallowed", [p]);
723 } else { 724 } else {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 // descriptor. 835 // descriptor.
835 836
836 if (desc.hasWritable()) { 837 if (desc.hasWritable()) {
837 flag |= desc.isWritable() ? 0 : READ_ONLY; 838 flag |= desc.isWritable() ? 0 : READ_ONLY;
838 } else if (!IS_UNDEFINED(current)) { 839 } else if (!IS_UNDEFINED(current)) {
839 flag |= current.isWritable() ? 0 : READ_ONLY; 840 flag |= current.isWritable() ? 0 : READ_ONLY;
840 } else { 841 } else {
841 flag |= READ_ONLY; 842 flag |= READ_ONLY;
842 } 843 }
843 844
844 var value = void 0; // Default value is undefined. 845 var value = UNDEFINED; // Default value is undefined.
845 if (desc.hasValue()) { 846 if (desc.hasValue()) {
846 value = desc.getValue(); 847 value = desc.getValue();
847 } else if (!IS_UNDEFINED(current) && IsDataDescriptor(current)) { 848 } else if (!IS_UNDEFINED(current) && IsDataDescriptor(current)) {
848 value = current.getValue(); 849 value = current.getValue();
849 } 850 }
850 851
851 %DefineOrRedefineDataProperty(obj, p, value, flag); 852 %DefineOrRedefineDataProperty(obj, p, value, flag);
852 } else { 853 } else {
853 // There are 3 cases that lead here: 854 // There are 3 cases that lead here:
854 // Step 4b - defining a new accessor property. 855 // Step 4b - defining a new accessor property.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 break; 914 break;
914 } 915 }
915 } 916 }
916 // Make sure the below call to DefineObjectProperty() doesn't overwrite 917 // Make sure the below call to DefineObjectProperty() doesn't overwrite
917 // any magic "length" property by removing the value. 918 // any magic "length" property by removing the value.
918 // TODO(mstarzinger): This hack should be removed once we have addressed the 919 // TODO(mstarzinger): This hack should be removed once we have addressed the
919 // respective TODO in Runtime_DefineOrRedefineDataProperty. 920 // respective TODO in Runtime_DefineOrRedefineDataProperty.
920 // For the time being, we need a hack to prevent Object.observe from 921 // For the time being, we need a hack to prevent Object.observe from
921 // generating two change records. 922 // generating two change records.
922 obj.length = new_length; 923 obj.length = new_length;
923 desc.value_ = void 0; 924 desc.value_ = UNDEFINED;
924 desc.hasValue_ = false; 925 desc.hasValue_ = false;
925 threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw; 926 threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw;
926 if (emit_splice) { 927 if (emit_splice) {
927 EndPerformSplice(obj); 928 EndPerformSplice(obj);
928 EnqueueSpliceRecord(obj, 929 EnqueueSpliceRecord(obj,
929 new_length < old_length ? new_length : old_length, 930 new_length < old_length ? new_length : old_length,
930 removed, 931 removed,
931 new_length > old_length ? new_length - old_length : 0); 932 new_length > old_length ? new_length - old_length : 0);
932 } 933 }
933 if (threw) { 934 if (threw) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 1039
1039 1040
1040 // ES5 section 15.2.3.4. 1041 // ES5 section 15.2.3.4.
1041 function ObjectGetOwnPropertyNames(obj) { 1042 function ObjectGetOwnPropertyNames(obj) {
1042 if (!IS_SPEC_OBJECT(obj)) { 1043 if (!IS_SPEC_OBJECT(obj)) {
1043 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); 1044 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]);
1044 } 1045 }
1045 // Special handling for proxies. 1046 // Special handling for proxies.
1046 if (%IsJSProxy(obj)) { 1047 if (%IsJSProxy(obj)) {
1047 var handler = %GetHandler(obj); 1048 var handler = %GetHandler(obj);
1048 var names = CallTrap0(handler, "getOwnPropertyNames", void 0); 1049 var names = CallTrap0(handler, "getOwnPropertyNames", UNDEFINED);
1049 return ToNameArray(names, "getOwnPropertyNames", false); 1050 return ToNameArray(names, "getOwnPropertyNames", false);
1050 } 1051 }
1051 1052
1052 var nameArrays = new InternalArray(); 1053 var nameArrays = new InternalArray();
1053 1054
1054 // Find all the indexed properties. 1055 // Find all the indexed properties.
1055 1056
1056 // Get the local element names. 1057 // Get the local element names.
1057 var localElementNames = %GetLocalElementNames(obj); 1058 var localElementNames = %GetLocalElementNames(obj);
1058 for (var i = 0; i < localElementNames.length; ++i) { 1059 for (var i = 0; i < localElementNames.length; ++i) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 for (var i = 0; i < names.length; i++) { 1188 for (var i = 0; i < names.length; i++) {
1188 DefineOwnProperty(obj, names[i], descriptors[i], true); 1189 DefineOwnProperty(obj, names[i], descriptors[i], true);
1189 } 1190 }
1190 return obj; 1191 return obj;
1191 } 1192 }
1192 1193
1193 1194
1194 // Harmony proxies. 1195 // Harmony proxies.
1195 function ProxyFix(obj) { 1196 function ProxyFix(obj) {
1196 var handler = %GetHandler(obj); 1197 var handler = %GetHandler(obj);
1197 var props = CallTrap0(handler, "fix", void 0); 1198 var props = CallTrap0(handler, "fix", UNDEFINED);
1198 if (IS_UNDEFINED(props)) { 1199 if (IS_UNDEFINED(props)) {
1199 throw MakeTypeError("handler_returned_undefined", [handler, "fix"]); 1200 throw MakeTypeError("handler_returned_undefined", [handler, "fix"]);
1200 } 1201 }
1201 1202
1202 if (%IsJSFunctionProxy(obj)) { 1203 if (%IsJSFunctionProxy(obj)) {
1203 var callTrap = %GetCallTrap(obj); 1204 var callTrap = %GetCallTrap(obj);
1204 var constructTrap = %GetConstructTrap(obj); 1205 var constructTrap = %GetConstructTrap(obj);
1205 var code = DelegateCallAndConstruct(callTrap, constructTrap); 1206 var code = DelegateCallAndConstruct(callTrap, constructTrap);
1206 %Fix(obj); // becomes a regular function 1207 %Fix(obj); // becomes a regular function
1207 %SetCode(obj, code); 1208 %SetCode(obj, code);
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 // Get the value of this number in case it's an object. 1554 // Get the value of this number in case it's an object.
1554 x = %_ValueOf(this); 1555 x = %_ValueOf(this);
1555 } 1556 }
1556 var f = TO_INTEGER(fractionDigits); 1557 var f = TO_INTEGER(fractionDigits);
1557 1558
1558 if (f < 0 || f > 20) { 1559 if (f < 0 || f > 20) {
1559 throw new $RangeError("toFixed() digits argument must be between 0 and 20"); 1560 throw new $RangeError("toFixed() digits argument must be between 0 and 20");
1560 } 1561 }
1561 1562
1562 if (NUMBER_IS_NAN(x)) return "NaN"; 1563 if (NUMBER_IS_NAN(x)) return "NaN";
1563 if (x == 1/0) return "Infinity"; 1564 if (x == INFINITY) return "Infinity";
1564 if (x == -1/0) return "-Infinity"; 1565 if (x == -INFINITY) return "-Infinity";
1565 1566
1566 return %NumberToFixed(x, f); 1567 return %NumberToFixed(x, f);
1567 } 1568 }
1568 1569
1569 1570
1570 // ECMA-262 section 15.7.4.6 1571 // ECMA-262 section 15.7.4.6
1571 function NumberToExponential(fractionDigits) { 1572 function NumberToExponential(fractionDigits) {
1572 var x = this; 1573 var x = this;
1573 if (!IS_NUMBER(this)) { 1574 if (!IS_NUMBER(this)) {
1574 if (!IS_NUMBER_WRAPPER(this)) { 1575 if (!IS_NUMBER_WRAPPER(this)) {
1575 throw MakeTypeError("incompatible_method_receiver", 1576 throw MakeTypeError("incompatible_method_receiver",
1576 ["Number.prototype.toExponential", this]); 1577 ["Number.prototype.toExponential", this]);
1577 } 1578 }
1578 // Get the value of this number in case it's an object. 1579 // Get the value of this number in case it's an object.
1579 x = %_ValueOf(this); 1580 x = %_ValueOf(this);
1580 } 1581 }
1581 var f = IS_UNDEFINED(fractionDigits) ? void 0 : TO_INTEGER(fractionDigits); 1582 var f = IS_UNDEFINED(fractionDigits) ? UNDEFINED : TO_INTEGER(fractionDigits);
1582 1583
1583 if (NUMBER_IS_NAN(x)) return "NaN"; 1584 if (NUMBER_IS_NAN(x)) return "NaN";
1584 if (x == 1/0) return "Infinity"; 1585 if (x == INFINITY) return "Infinity";
1585 if (x == -1/0) return "-Infinity"; 1586 if (x == -INFINITY) return "-Infinity";
1586 1587
1587 if (IS_UNDEFINED(f)) { 1588 if (IS_UNDEFINED(f)) {
1588 f = -1; // Signal for runtime function that f is not defined. 1589 f = -1; // Signal for runtime function that f is not defined.
1589 } else if (f < 0 || f > 20) { 1590 } else if (f < 0 || f > 20) {
1590 throw new $RangeError("toExponential() argument must be between 0 and 20"); 1591 throw new $RangeError("toExponential() argument must be between 0 and 20");
1591 } 1592 }
1592 return %NumberToExponential(x, f); 1593 return %NumberToExponential(x, f);
1593 } 1594 }
1594 1595
1595 1596
1596 // ECMA-262 section 15.7.4.7 1597 // ECMA-262 section 15.7.4.7
1597 function NumberToPrecision(precision) { 1598 function NumberToPrecision(precision) {
1598 var x = this; 1599 var x = this;
1599 if (!IS_NUMBER(this)) { 1600 if (!IS_NUMBER(this)) {
1600 if (!IS_NUMBER_WRAPPER(this)) { 1601 if (!IS_NUMBER_WRAPPER(this)) {
1601 throw MakeTypeError("incompatible_method_receiver", 1602 throw MakeTypeError("incompatible_method_receiver",
1602 ["Number.prototype.toPrecision", this]); 1603 ["Number.prototype.toPrecision", this]);
1603 } 1604 }
1604 // Get the value of this number in case it's an object. 1605 // Get the value of this number in case it's an object.
1605 x = %_ValueOf(this); 1606 x = %_ValueOf(this);
1606 } 1607 }
1607 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); 1608 if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this));
1608 var p = TO_INTEGER(precision); 1609 var p = TO_INTEGER(precision);
1609 1610
1610 if (NUMBER_IS_NAN(x)) return "NaN"; 1611 if (NUMBER_IS_NAN(x)) return "NaN";
1611 if (x == 1/0) return "Infinity"; 1612 if (x == INFINITY) return "Infinity";
1612 if (x == -1/0) return "-Infinity"; 1613 if (x == -INFINITY) return "-Infinity";
1613 1614
1614 if (p < 1 || p > 21) { 1615 if (p < 1 || p > 21) {
1615 throw new $RangeError("toPrecision() argument must be between 1 and 21"); 1616 throw new $RangeError("toPrecision() argument must be between 1 and 21");
1616 } 1617 }
1617 return %NumberToPrecision(x, p); 1618 return %NumberToPrecision(x, p);
1618 } 1619 }
1619 1620
1620 1621
1621 // Harmony isFinite. 1622 // Harmony isFinite.
1622 function NumberIsFinite(number) { 1623 function NumberIsFinite(number) {
(...skipping 24 matching lines...) Expand all
1647 %SetProperty($Number, 1648 %SetProperty($Number,
1648 "MAX_VALUE", 1649 "MAX_VALUE",
1649 1.7976931348623157e+308, 1650 1.7976931348623157e+308,
1650 DONT_ENUM | DONT_DELETE | READ_ONLY); 1651 DONT_ENUM | DONT_DELETE | READ_ONLY);
1651 1652
1652 // ECMA-262 section 15.7.3.2. 1653 // ECMA-262 section 15.7.3.2.
1653 %SetProperty($Number, "MIN_VALUE", 5e-324, 1654 %SetProperty($Number, "MIN_VALUE", 5e-324,
1654 DONT_ENUM | DONT_DELETE | READ_ONLY); 1655 DONT_ENUM | DONT_DELETE | READ_ONLY);
1655 1656
1656 // ECMA-262 section 15.7.3.3. 1657 // ECMA-262 section 15.7.3.3.
1657 %SetProperty($Number, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); 1658 %SetProperty($Number, "NaN", NAN, DONT_ENUM | DONT_DELETE | READ_ONLY);
1658 1659
1659 // ECMA-262 section 15.7.3.4. 1660 // ECMA-262 section 15.7.3.4.
1660 %SetProperty($Number, 1661 %SetProperty($Number,
1661 "NEGATIVE_INFINITY", 1662 "NEGATIVE_INFINITY",
1662 -1/0, 1663 -INFINITY,
1663 DONT_ENUM | DONT_DELETE | READ_ONLY); 1664 DONT_ENUM | DONT_DELETE | READ_ONLY);
1664 1665
1665 // ECMA-262 section 15.7.3.5. 1666 // ECMA-262 section 15.7.3.5.
1666 %SetProperty($Number, 1667 %SetProperty($Number,
1667 "POSITIVE_INFINITY", 1668 "POSITIVE_INFINITY",
1668 1/0, 1669 INFINITY,
1669 DONT_ENUM | DONT_DELETE | READ_ONLY); 1670 DONT_ENUM | DONT_DELETE | READ_ONLY);
1670 %ToFastProperties($Number); 1671 %ToFastProperties($Number);
1671 1672
1672 // Set up non-enumerable functions on the Number prototype object. 1673 // Set up non-enumerable functions on the Number prototype object.
1673 InstallFunctions($Number.prototype, DONT_ENUM, $Array( 1674 InstallFunctions($Number.prototype, DONT_ENUM, $Array(
1674 "toString", NumberToString, 1675 "toString", NumberToString,
1675 "toLocaleString", NumberToLocaleString, 1676 "toLocaleString", NumberToLocaleString,
1676 "valueOf", NumberValueOf, 1677 "valueOf", NumberValueOf,
1677 "toFixed", NumberToFixed, 1678 "toFixed", NumberToFixed,
1678 "toExponential", NumberToExponential, 1679 "toExponential", NumberToExponential,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 %SetCode($Function, FunctionConstructor); 1830 %SetCode($Function, FunctionConstructor);
1830 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); 1831 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM);
1831 1832
1832 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1833 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1833 "bind", FunctionBind, 1834 "bind", FunctionBind,
1834 "toString", FunctionToString 1835 "toString", FunctionToString
1835 )); 1836 ));
1836 } 1837 }
1837 1838
1838 SetUpFunction(); 1839 SetUpFunction();
OLDNEW
« no previous file with comments | « src/string.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698