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

Side by Side Diff: src/js/v8natives.js

Issue 1573243009: [builtins] Migrate Number constructor similar to String constructor. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 (function(global, utils) { 5 (function(global, utils) {
6 6
7 %CheckIsBootstrapping(); 7 %CheckIsBootstrapping();
8 8
9 // ---------------------------------------------------------------------------- 9 // ----------------------------------------------------------------------------
10 // Imports 10 // Imports
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 945
946 utils.InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [ 946 utils.InstallFunctions(GlobalBoolean.prototype, DONT_ENUM, [
947 "toString", BooleanToString, 947 "toString", BooleanToString,
948 "valueOf", BooleanValueOf 948 "valueOf", BooleanValueOf
949 ]); 949 ]);
950 950
951 951
952 // ---------------------------------------------------------------------------- 952 // ----------------------------------------------------------------------------
953 // Number 953 // Number
954 954
955 function NumberConstructor(x) {
956 // TODO(bmeurer): Move this to toplevel.
957 "use strict";
958 var value = %_ArgumentsLength() == 0 ? 0 : TO_NUMBER(x);
959 if (IS_UNDEFINED(new.target)) return value;
960
961 var result = %NewObject(GlobalNumber, new.target);
962 %_SetValueOf(result, value);
963 return result;
964 }
965
966
967 // ES6 Number.prototype.toString([ radix ]) 955 // ES6 Number.prototype.toString([ radix ])
968 function NumberToStringJS(radix) { 956 function NumberToStringJS(radix) {
969 // NOTE: Both Number objects and values can enter here as 957 // NOTE: Both Number objects and values can enter here as
970 // 'this'. This is not as dictated by ECMA-262. 958 // 'this'. This is not as dictated by ECMA-262.
971 var number = this; 959 var number = this;
972 if (!IS_NUMBER(this)) { 960 if (!IS_NUMBER(this)) {
973 if (!IS_NUMBER_WRAPPER(this)) { 961 if (!IS_NUMBER_WRAPPER(this)) {
974 throw MakeTypeError(kNotGeneric, 'Number.prototype.toString'); 962 throw MakeTypeError(kNotGeneric, 'Number.prototype.toString');
975 } 963 }
976 // Get the value of this number in case it's an object. 964 // Get the value of this number in case it's an object.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 if (integral == number) { 1095 if (integral == number) {
1108 return MathAbs(integral) <= kMaxSafeInteger; 1096 return MathAbs(integral) <= kMaxSafeInteger;
1109 } 1097 }
1110 } 1098 }
1111 return false; 1099 return false;
1112 } 1100 }
1113 1101
1114 1102
1115 // ---------------------------------------------------------------------------- 1103 // ----------------------------------------------------------------------------
1116 1104
1117 %SetCode(GlobalNumber, NumberConstructor);
1118 %FunctionSetPrototype(GlobalNumber, new GlobalNumber(0)); 1105 %FunctionSetPrototype(GlobalNumber, new GlobalNumber(0));
1119 1106
1120 %OptimizeObjectForAddingMultipleProperties(GlobalNumber.prototype, 8); 1107 %OptimizeObjectForAddingMultipleProperties(GlobalNumber.prototype, 8);
1121 // Set up the constructor property on the Number prototype object. 1108 // Set up the constructor property on the Number prototype object.
1122 %AddNamedProperty(GlobalNumber.prototype, "constructor", GlobalNumber, 1109 %AddNamedProperty(GlobalNumber.prototype, "constructor", GlobalNumber,
1123 DONT_ENUM); 1110 DONT_ENUM);
1124 1111
1125 utils.InstallConstants(GlobalNumber, [ 1112 utils.InstallConstants(GlobalNumber, [
1126 // ECMA-262 section 15.7.3.1. 1113 // ECMA-262 section 15.7.3.1.
1127 "MAX_VALUE", 1.7976931348623157e+308, 1114 "MAX_VALUE", 1.7976931348623157e+308,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 to.ObjectDefineProperties = ObjectDefineProperties; 1181 to.ObjectDefineProperties = ObjectDefineProperties;
1195 to.ObjectDefineProperty = ObjectDefineProperty; 1182 to.ObjectDefineProperty = ObjectDefineProperty;
1196 to.ObjectHasOwnProperty = ObjectHasOwnProperty; 1183 to.ObjectHasOwnProperty = ObjectHasOwnProperty;
1197 }); 1184 });
1198 1185
1199 %InstallToContext([ 1186 %InstallToContext([
1200 "object_value_of", ObjectValueOf, 1187 "object_value_of", ObjectValueOf,
1201 ]); 1188 ]);
1202 1189
1203 }) 1190 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698