| OLD | NEW | 
|---|
| 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 23 matching lines...) Expand all  Loading... | 
| 34 // const $Number = global.Number; | 34 // const $Number = global.Number; | 
| 35 // const $Function = global.Function; | 35 // const $Function = global.Function; | 
| 36 // const $Array = global.Array; | 36 // const $Array = global.Array; | 
| 37 // const $NaN = 0/0; | 37 // const $NaN = 0/0; | 
| 38 // | 38 // | 
| 39 // in math.js: | 39 // in math.js: | 
| 40 // const $floor = MathFloor | 40 // const $floor = MathFloor | 
| 41 | 41 | 
| 42 | 42 | 
| 43 // ECMA 262 - 15.1.1.1. | 43 // ECMA 262 - 15.1.1.1. | 
| 44 %AddProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); | 44 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); | 
| 45 | 45 | 
| 46 | 46 | 
| 47 // ECMA-262 - 15.1.1.2. | 47 // ECMA-262 - 15.1.1.2. | 
| 48 %AddProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE); | 48 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE); | 
| 49 | 49 | 
| 50 | 50 | 
| 51 // ECMA-262 - 15.1.1.3. | 51 // ECMA-262 - 15.1.1.3. | 
| 52 %AddProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE); | 52 %SetProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE); | 
| 53 | 53 | 
| 54 | 54 | 
| 55 // ECMA 262 - 15.1.4 | 55 // ECMA 262 - 15.1.4 | 
| 56 function $isNaN(number) { | 56 function $isNaN(number) { | 
| 57   var n = ToNumber(number); | 57   var n = ToNumber(number); | 
| 58   return NUMBER_IS_NAN(n); | 58   return NUMBER_IS_NAN(n); | 
| 59 } | 59 } | 
| 60 %AddProperty(global, "isNaN", $isNaN, DONT_ENUM); | 60 %SetProperty(global, "isNaN", $isNaN, DONT_ENUM); | 
| 61 | 61 | 
| 62 | 62 | 
| 63 // ECMA 262 - 15.1.5 | 63 // ECMA 262 - 15.1.5 | 
| 64 function $isFinite(number) { | 64 function $isFinite(number) { | 
| 65   return %NumberIsFinite(ToNumber(number)); | 65   return %NumberIsFinite(ToNumber(number)); | 
| 66 } | 66 } | 
| 67 %AddProperty(global, "isFinite", $isFinite, DONT_ENUM); | 67 %SetProperty(global, "isFinite", $isFinite, DONT_ENUM); | 
| 68 | 68 | 
| 69 | 69 | 
| 70 // ECMA-262 - 15.1.2.2 | 70 // ECMA-262 - 15.1.2.2 | 
| 71 %AddProperty(global, "parseInt", function(string, radix) { | 71 %SetProperty(global, "parseInt", function(string, radix) { | 
| 72   if (radix === void 0) { | 72   if (radix === void 0) { | 
| 73     radix = 0; | 73     radix = 0; | 
| 74     // Some people use parseInt instead of Math.floor.  This | 74     // Some people use parseInt instead of Math.floor.  This | 
| 75     // optimization makes parseInt on a Smi 12 times faster (60ns | 75     // optimization makes parseInt on a Smi 12 times faster (60ns | 
| 76     // vs 800ns).  The following optimization makes parseInt on a | 76     // vs 800ns).  The following optimization makes parseInt on a | 
| 77     // non-Smi number 9 times faster (230ns vs 2070ns).  Together | 77     // non-Smi number 9 times faster (230ns vs 2070ns).  Together | 
| 78     // they make parseInt on a string 1.4% slower (274ns vs 270ns). | 78     // they make parseInt on a string 1.4% slower (274ns vs 270ns). | 
| 79     if (%_IsSmi(string)) return string; | 79     if (%_IsSmi(string)) return string; | 
| 80     if (IS_NUMBER(string)) { | 80     if (IS_NUMBER(string)) { | 
| 81       if (string >= 0.01 && string < 1e9) | 81       if (string >= 0.01 && string < 1e9) | 
| 82         return $floor(string); | 82         return $floor(string); | 
| 83       if (string <= -0.01 && string > -1e9) | 83       if (string <= -0.01 && string > -1e9) | 
| 84         return - $floor(-string); | 84         return - $floor(-string); | 
| 85     } | 85     } | 
| 86   } else { | 86   } else { | 
| 87     radix = TO_INT32(radix); | 87     radix = TO_INT32(radix); | 
| 88     if (!(radix == 0 || (2 <= radix && radix <= 36))) | 88     if (!(radix == 0 || (2 <= radix && radix <= 36))) | 
| 89       return $NaN; | 89       return $NaN; | 
| 90   } | 90   } | 
| 91   return %StringParseInt(ToString(string), radix); | 91   return %StringParseInt(ToString(string), radix); | 
| 92 }, DONT_ENUM); | 92 }, DONT_ENUM); | 
| 93 | 93 | 
| 94 | 94 | 
| 95 // ECMA-262 - 15.1.2.3 | 95 // ECMA-262 - 15.1.2.3 | 
| 96 %AddProperty(global, "parseFloat", function(string) { | 96 %SetProperty(global, "parseFloat", function(string) { | 
| 97   return %StringParseFloat(ToString(string)); | 97   return %StringParseFloat(ToString(string)); | 
| 98 }, DONT_ENUM); | 98 }, DONT_ENUM); | 
| 99 | 99 | 
| 100 | 100 | 
| 101 // ---------------------------------------------------------------------------- | 101 // ---------------------------------------------------------------------------- | 
| 102 // Boolean (first part of definition) | 102 // Boolean (first part of definition) | 
| 103 | 103 | 
| 104 | 104 | 
| 105 %SetCode($Boolean, function(x) { | 105 %SetCode($Boolean, function(x) { | 
| 106   if (%IsConstructCall()) { | 106   if (%IsConstructCall()) { | 
| 107     %_SetValueOf(this, ToBoolean(x)); | 107     %_SetValueOf(this, ToBoolean(x)); | 
| 108   } else { | 108   } else { | 
| 109     return ToBoolean(x); | 109     return ToBoolean(x); | 
| 110   } | 110   } | 
| 111 }); | 111 }); | 
| 112 | 112 | 
| 113 %FunctionSetPrototype($Boolean, new $Boolean(false)); | 113 %FunctionSetPrototype($Boolean, new $Boolean(false)); | 
| 114 | 114 | 
| 115 %AddProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); | 115 %SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); | 
| 116 | 116 | 
| 117 // ---------------------------------------------------------------------------- | 117 // ---------------------------------------------------------------------------- | 
| 118 // Object | 118 // Object | 
| 119 | 119 | 
| 120 $Object.prototype.constructor = $Object; | 120 $Object.prototype.constructor = $Object; | 
| 121 | 121 | 
| 122 %AddProperty($Object.prototype, "toString", function() { | 122 %SetProperty($Object.prototype, "toString", function() { | 
| 123   var c = %ClassOf(this); | 123   var c = %ClassOf(this); | 
| 124   // Hide Arguments from the outside. | 124   // Hide Arguments from the outside. | 
| 125   if (c === 'Arguments') c  = 'Object'; | 125   if (c === 'Arguments') c  = 'Object'; | 
| 126   return "[object " + c + "]"; | 126   return "[object " + c + "]"; | 
| 127 }, DONT_ENUM); | 127 }, DONT_ENUM); | 
| 128 | 128 | 
| 129 | 129 | 
| 130 // ECMA-262, section 15.2.4.3, page 84. | 130 // ECMA-262, section 15.2.4.3, page 84. | 
| 131 %AddProperty($Object.prototype, "toLocaleString", function() { | 131 %SetProperty($Object.prototype, "toLocaleString", function() { | 
| 132   return this.toString(); | 132   return this.toString(); | 
| 133 }, DONT_ENUM); | 133 }, DONT_ENUM); | 
| 134 | 134 | 
| 135 | 135 | 
| 136 // ECMA-262, section 15.2.4.4, page 85. | 136 // ECMA-262, section 15.2.4.4, page 85. | 
| 137 %AddProperty($Object.prototype, "valueOf", function() { | 137 %SetProperty($Object.prototype, "valueOf", function() { | 
| 138   return this; | 138   return this; | 
| 139 }, DONT_ENUM); | 139 }, DONT_ENUM); | 
| 140 | 140 | 
| 141 | 141 | 
| 142 // ECMA-262, section 15.2.4.5, page 85. | 142 // ECMA-262, section 15.2.4.5, page 85. | 
| 143 %AddProperty($Object.prototype, "hasOwnProperty", function(V) { | 143 %SetProperty($Object.prototype, "hasOwnProperty", function(V) { | 
| 144   return %HasLocalProperty(ToObject(this), ToString(V)); | 144   return %HasLocalProperty(ToObject(this), ToString(V)); | 
| 145 }, DONT_ENUM); | 145 }, DONT_ENUM); | 
| 146 | 146 | 
| 147 | 147 | 
| 148 // ECMA-262, section 15.2.4.6, page 85. | 148 // ECMA-262, section 15.2.4.6, page 85. | 
| 149 %AddProperty($Object.prototype, "isPrototypeOf", function(V) { | 149 %SetProperty($Object.prototype, "isPrototypeOf", function(V) { | 
| 150   if (!IS_OBJECT(V) && !IS_FUNCTION(V)) return false; | 150   if (!IS_OBJECT(V) && !IS_FUNCTION(V)) return false; | 
| 151   return %IsInPrototypeChain(this, V); | 151   return %IsInPrototypeChain(this, V); | 
| 152 }, DONT_ENUM); | 152 }, DONT_ENUM); | 
| 153 | 153 | 
| 154 | 154 | 
| 155 // ECMA-262, section 15.2.4.6, page 85. | 155 // ECMA-262, section 15.2.4.6, page 85. | 
| 156 %AddProperty($Object.prototype, "propertyIsEnumerable", function(V) { | 156 %SetProperty($Object.prototype, "propertyIsEnumerable", function(V) { | 
| 157   if (this == null) return false; | 157   if (this == null) return false; | 
| 158   if (!IS_OBJECT(this) && !IS_FUNCTION(this)) return false; | 158   if (!IS_OBJECT(this) && !IS_FUNCTION(this)) return false; | 
| 159   return %IsPropertyEnumerable(this, ToString(V)); | 159   return %IsPropertyEnumerable(this, ToString(V)); | 
| 160 }, DONT_ENUM); | 160 }, DONT_ENUM); | 
| 161 | 161 | 
| 162 | 162 | 
| 163 // Extensions for providing property getters and setters. | 163 // Extensions for providing property getters and setters. | 
| 164 %AddProperty($Object.prototype, "__defineGetter__", function(name, fun) { | 164 %SetProperty($Object.prototype, "__defineGetter__", function(name, fun) { | 
| 165   if (this == null) throw new $TypeError('Object.prototype.__defineGetter__: thi
     s is Null'); | 165   if (this == null) { | 
| 166   if (!IS_FUNCTION(fun)) throw new $TypeError('Object.prototype.__defineGetter__
     : Expecting function'); | 166     throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); | 
|  | 167   } | 
|  | 168   if (!IS_FUNCTION(fun)) { | 
|  | 169     throw new $TypeError( | 
|  | 170 »       'Object.prototype.__defineGetter__: Expecting function'); | 
|  | 171   } | 
| 167   return %DefineAccessor(ToObject(this), ToString(name), GETTER, fun); | 172   return %DefineAccessor(ToObject(this), ToString(name), GETTER, fun); | 
| 168 }, DONT_ENUM); | 173 }, DONT_ENUM); | 
| 169 | 174 | 
| 170 | 175 | 
| 171 | 176 | 
| 172 %AddProperty($Object.prototype, "__lookupGetter__", function(name) { | 177 %SetProperty($Object.prototype, "__lookupGetter__", function(name) { | 
| 173   if (this == null) throw new $TypeError('Object.prototype.__lookupGetter__: thi
     s is Null'); | 178   if (this == null) { | 
|  | 179     throw new $TypeError('Object.prototype.__lookupGetter__: this is Null'); | 
|  | 180   } | 
| 174   return %LookupAccessor(ToObject(this), ToString(name), GETTER); | 181   return %LookupAccessor(ToObject(this), ToString(name), GETTER); | 
| 175 }, DONT_ENUM); | 182 }, DONT_ENUM); | 
| 176 | 183 | 
| 177 | 184 | 
| 178 %AddProperty($Object.prototype, "__defineSetter__", function(name, fun) { | 185 %SetProperty($Object.prototype, "__defineSetter__", function(name, fun) { | 
| 179   if (this == null) throw new $TypeError('Object.prototype.__defineSetter__: thi
     s is Null'); | 186   if (this == null) { | 
| 180   if (!IS_FUNCTION(fun)) throw new $TypeError('Object.prototype.__defineSetter__
     : Expecting function'); | 187     throw new $TypeError('Object.prototype.__defineSetter__: this is Null'); | 
|  | 188   } | 
|  | 189   if (!IS_FUNCTION(fun)) { | 
|  | 190     throw new $TypeError( | 
|  | 191         'Object.prototype.__defineSetter__: Expecting function'); | 
|  | 192   } | 
| 181   return %DefineAccessor(ToObject(this), ToString(name), SETTER, fun); | 193   return %DefineAccessor(ToObject(this), ToString(name), SETTER, fun); | 
| 182 }, DONT_ENUM); | 194 }, DONT_ENUM); | 
| 183 | 195 | 
| 184 | 196 | 
| 185 %AddProperty($Object.prototype, "__lookupSetter__", function(name) { | 197 %SetProperty($Object.prototype, "__lookupSetter__", function(name) { | 
| 186   if (this == null) throw new $TypeError('Object.prototype.__lookupSetter__: thi
     s is Null'); | 198   if (this == null) { | 
|  | 199     throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); | 
|  | 200   } | 
| 187   return %LookupAccessor(ToObject(this), ToString(name), SETTER); | 201   return %LookupAccessor(ToObject(this), ToString(name), SETTER); | 
| 188 }, DONT_ENUM); | 202 }, DONT_ENUM); | 
| 189 | 203 | 
| 190 | 204 | 
| 191 %SetCode($Object, function(x) { | 205 %SetCode($Object, function(x) { | 
| 192   if (%IsConstructCall()) { | 206   if (%IsConstructCall()) { | 
| 193     if (x == null) return this; | 207     if (x == null) return this; | 
| 194     return ToObject(x); | 208     return ToObject(x); | 
| 195   } else { | 209   } else { | 
| 196     if (x == null) return { }; | 210     if (x == null) return { }; | 
| 197     return ToObject(x); | 211     return ToObject(x); | 
| 198   } | 212   } | 
| 199 }); | 213 }); | 
| 200 | 214 | 
| 201 | 215 | 
| 202 // ---------------------------------------------------------------------------- | 216 // ---------------------------------------------------------------------------- | 
| 203 // Global stuff... | 217 // Global stuff... | 
| 204 | 218 | 
| 205 %AddProperty(global, "eval", function(x) { | 219 %SetProperty(global, "eval", function(x) { | 
| 206   if (!IS_STRING(x)) return x; | 220   if (!IS_STRING(x)) return x; | 
| 207 | 221 | 
| 208   var f = %CompileString(x, 0, true); | 222   var f = %CompileString(x, 0, true); | 
| 209   if (!IS_FUNCTION(f)) return f; | 223   if (!IS_FUNCTION(f)) return f; | 
| 210 | 224 | 
| 211   return f.call(%EvalReceiver(this)); | 225   return f.call(%EvalReceiver(this)); | 
| 212 }, DONT_ENUM); | 226 }, DONT_ENUM); | 
| 213 | 227 | 
| 214 | 228 | 
| 215 // execScript for IE compatibility. | 229 // execScript for IE compatibility. | 
| 216 %AddProperty(global, "execScript", function(expr, lang) { | 230 %SetProperty(global, "execScript", function(expr, lang) { | 
| 217   // NOTE: We don't care about the character casing. | 231   // NOTE: We don't care about the character casing. | 
| 218   if (!lang || /javascript/i.test(lang)) { | 232   if (!lang || /javascript/i.test(lang)) { | 
| 219     var f = %CompileString(ToString(expr), 0, false); | 233     var f = %CompileString(ToString(expr), 0, false); | 
| 220     f.call(global); | 234     f.call(global); | 
| 221   } | 235   } | 
| 222   return null; | 236   return null; | 
| 223 }, DONT_ENUM); | 237 }, DONT_ENUM); | 
| 224 | 238 | 
| 225 | 239 | 
| 226 // ---------------------------------------------------------------------------- | 240 // ---------------------------------------------------------------------------- | 
| 227 // Boolean | 241 // Boolean | 
| 228 | 242 | 
| 229 %AddProperty($Boolean.prototype, "toString", function() { | 243 %SetProperty($Boolean.prototype, "toString", function() { | 
| 230   // NOTE: Both Boolean objects and values can enter here as | 244   // NOTE: Both Boolean objects and values can enter here as | 
| 231   // 'this'. This is not as dictated by ECMA-262. | 245   // 'this'. This is not as dictated by ECMA-262. | 
| 232   if (!IS_BOOLEAN(this) && %ClassOf(this) !== 'Boolean') | 246   if (!IS_BOOLEAN(this) && %ClassOf(this) !== 'Boolean') | 
| 233     throw new $TypeError('Boolean.prototype.toString is not generic'); | 247     throw new $TypeError('Boolean.prototype.toString is not generic'); | 
| 234   return ToString(%_ValueOf(this)); | 248   return ToString(%_ValueOf(this)); | 
| 235 }, DONT_ENUM); | 249 }, DONT_ENUM); | 
| 236 | 250 | 
| 237 | 251 | 
| 238 %AddProperty($Boolean.prototype, "valueOf", function() { | 252 %SetProperty($Boolean.prototype, "valueOf", function() { | 
| 239   // NOTE: Both Boolean objects and values can enter here as | 253   // NOTE: Both Boolean objects and values can enter here as | 
| 240   // 'this'. This is not as dictated by ECMA-262. | 254   // 'this'. This is not as dictated by ECMA-262. | 
| 241   if (!IS_BOOLEAN(this) && %ClassOf(this) !== 'Boolean') | 255   if (!IS_BOOLEAN(this) && %ClassOf(this) !== 'Boolean') | 
| 242     throw new $TypeError('Boolean.prototype.valueOf is not generic'); | 256     throw new $TypeError('Boolean.prototype.valueOf is not generic'); | 
| 243   return %_ValueOf(this); | 257   return %_ValueOf(this); | 
| 244 }, DONT_ENUM); | 258 }, DONT_ENUM); | 
| 245 | 259 | 
| 246 | 260 | 
| 247 // ---------------------------------------------------------------------------- | 261 // ---------------------------------------------------------------------------- | 
| 248 // Number | 262 // Number | 
| 249 | 263 | 
| 250 // Set the Number function and constructor. | 264 // Set the Number function and constructor. | 
| 251 %SetCode($Number, function(x) { | 265 %SetCode($Number, function(x) { | 
| 252   var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); | 266   var value = %_ArgumentsLength() == 0 ? 0 : ToNumber(x); | 
| 253   if (%IsConstructCall()) { | 267   if (%IsConstructCall()) { | 
| 254     %_SetValueOf(this, value); | 268     %_SetValueOf(this, value); | 
| 255   } else { | 269   } else { | 
| 256     return value; | 270     return value; | 
| 257   } | 271   } | 
| 258 }); | 272 }); | 
| 259 | 273 | 
| 260 %FunctionSetPrototype($Number, new $Number(0)); | 274 %FunctionSetPrototype($Number, new $Number(0)); | 
| 261 | 275 | 
| 262 %AddProperty($Number.prototype, "constructor", $Number, DONT_ENUM); | 276 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); | 
| 263 | 277 | 
| 264 // ECMA-262 section 15.7.3.1. | 278 // ECMA-262 section 15.7.3.1. | 
| 265 %AddProperty($Number, "MAX_VALUE", 1.7976931348623157e+308, DONT_ENUM | DONT_DEL
     ETE | READ_ONLY); | 279 %SetProperty($Number, | 
|  | 280              "MAX_VALUE", | 
|  | 281              1.7976931348623157e+308, | 
|  | 282              DONT_ENUM | DONT_DELETE | READ_ONLY); | 
| 266 | 283 | 
| 267 // ECMA-262 section 15.7.3.2. | 284 // ECMA-262 section 15.7.3.2. | 
| 268 %AddProperty($Number, "MIN_VALUE", 5e-324, DONT_ENUM | DONT_DELETE | READ_ONLY); | 285 %SetProperty($Number, "MIN_VALUE", 5e-324, DONT_ENUM | DONT_DELETE | READ_ONLY); | 
| 269 | 286 | 
| 270 // ECMA-262 section 15.7.3.3. | 287 // ECMA-262 section 15.7.3.3. | 
| 271 %AddProperty($Number, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); | 288 %SetProperty($Number, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); | 
| 272 | 289 | 
| 273 // ECMA-262 section 15.7.3.4. | 290 // ECMA-262 section 15.7.3.4. | 
| 274 %AddProperty($Number, "NEGATIVE_INFINITY", -1/0,  DONT_ENUM | DONT_DELETE | READ
     _ONLY); | 291 %SetProperty($Number, | 
|  | 292              "NEGATIVE_INFINITY", | 
|  | 293              -1/0, | 
|  | 294              DONT_ENUM | DONT_DELETE | READ_ONLY); | 
| 275 | 295 | 
| 276 // ECMA-262 section 15.7.3.5. | 296 // ECMA-262 section 15.7.3.5. | 
| 277 %AddProperty($Number, "POSITIVE_INFINITY", 1/0,  DONT_ENUM | DONT_DELETE | READ_
     ONLY); | 297 %SetProperty($Number, | 
|  | 298              "POSITIVE_INFINITY", | 
|  | 299              1/0, | 
|  | 300              DONT_ENUM | DONT_DELETE | READ_ONLY); | 
| 278 | 301 | 
| 279 // ECMA-262 section 15.7.4.2. | 302 // ECMA-262 section 15.7.4.2. | 
| 280 %AddProperty($Number.prototype, "toString", function(radix) { | 303 %SetProperty($Number.prototype, "toString", function(radix) { | 
| 281   // NOTE: Both Number objects and values can enter here as | 304   // NOTE: Both Number objects and values can enter here as | 
| 282   // 'this'. This is not as dictated by ECMA-262. | 305   // 'this'. This is not as dictated by ECMA-262. | 
| 283   var number = this; | 306   var number = this; | 
| 284   if (!IS_NUMBER(this)) { | 307   if (!IS_NUMBER(this)) { | 
| 285     if (%ClassOf(this) !== 'Number') | 308     if (%ClassOf(this) !== 'Number') | 
| 286       throw new $TypeError('Number.prototype.toString is not generic'); | 309       throw new $TypeError('Number.prototype.toString is not generic'); | 
| 287     // Get the value of this number in case it's an object. | 310     // Get the value of this number in case it's an object. | 
| 288     number = %_ValueOf(this); | 311     number = %_ValueOf(this); | 
| 289   } | 312   } | 
| 290   // Fast case: Convert number in radix 10. | 313   // Fast case: Convert number in radix 10. | 
| 291   if (IS_UNDEFINED(radix) || radix === 10) { | 314   if (IS_UNDEFINED(radix) || radix === 10) { | 
| 292     return ToString(number); | 315     return ToString(number); | 
| 293   } | 316   } | 
| 294 | 317 | 
| 295   // Convert the radix to an integer and check the range. | 318   // Convert the radix to an integer and check the range. | 
| 296   radix = TO_INTEGER(radix); | 319   radix = TO_INTEGER(radix); | 
| 297   if (radix < 2 || radix > 36) { | 320   if (radix < 2 || radix > 36) { | 
| 298     throw new $RangeError('toString() radix argument must be between 2 and 36'); | 321     throw new $RangeError('toString() radix argument must be between 2 and 36'); | 
| 299   } | 322   } | 
| 300   // Convert the number to a string in the given radix. | 323   // Convert the number to a string in the given radix. | 
| 301   return %NumberToRadixString(number, radix); | 324   return %NumberToRadixString(number, radix); | 
| 302 }, DONT_ENUM); | 325 }, DONT_ENUM); | 
| 303 | 326 | 
| 304 | 327 | 
| 305 // ECMA-262 section 15.7.4.3 | 328 // ECMA-262 section 15.7.4.3 | 
| 306 %AddProperty($Number.prototype, "toLocaleString", function() { | 329 %SetProperty($Number.prototype, "toLocaleString", function() { | 
| 307   return this.toString(); | 330   return this.toString(); | 
| 308 }, DONT_ENUM); | 331 }, DONT_ENUM); | 
| 309 | 332 | 
| 310 | 333 | 
| 311 // ECMA-262 section 15.7.4.4 | 334 // ECMA-262 section 15.7.4.4 | 
| 312 %AddProperty($Number.prototype, "valueOf", function() { | 335 %SetProperty($Number.prototype, "valueOf", function() { | 
| 313   // NOTE: Both Number objects and values can enter here as | 336   // NOTE: Both Number objects and values can enter here as | 
| 314   // 'this'. This is not as dictated by ECMA-262. | 337   // 'this'. This is not as dictated by ECMA-262. | 
| 315   if (!IS_NUMBER(this) && %ClassOf(this) !== 'Number') | 338   if (!IS_NUMBER(this) && %ClassOf(this) !== 'Number') | 
| 316     throw new $TypeError('Number.prototype.valueOf is not generic'); | 339     throw new $TypeError('Number.prototype.valueOf is not generic'); | 
| 317   return %_ValueOf(this); | 340   return %_ValueOf(this); | 
| 318 }, DONT_ENUM); | 341 }, DONT_ENUM); | 
| 319 | 342 | 
| 320 | 343 | 
| 321 // ECMA-262 section 15.7.4.5 | 344 // ECMA-262 section 15.7.4.5 | 
| 322 %AddProperty($Number.prototype, "toFixed", function(fractionDigits) { | 345 %SetProperty($Number.prototype, "toFixed", function(fractionDigits) { | 
| 323   var f = TO_INTEGER(fractionDigits); | 346   var f = TO_INTEGER(fractionDigits); | 
| 324   if (f < 0 || f > 20) { | 347   if (f < 0 || f > 20) { | 
| 325     throw new $RangeError("toFixed() digits argument must be between 0 and 20"); | 348     throw new $RangeError("toFixed() digits argument must be between 0 and 20"); | 
| 326   } | 349   } | 
| 327   var x = ToNumber(this); | 350   var x = ToNumber(this); | 
| 328   return %NumberToFixed(x, f); | 351   return %NumberToFixed(x, f); | 
| 329 }, DONT_ENUM); | 352 }, DONT_ENUM); | 
| 330 | 353 | 
| 331 | 354 | 
| 332 // ECMA-262 section 15.7.4.6 | 355 // ECMA-262 section 15.7.4.6 | 
| 333 %AddProperty($Number.prototype, "toExponential", function(fractionDigits) { | 356 %SetProperty($Number.prototype, "toExponential", function(fractionDigits) { | 
| 334   var f = -1; | 357   var f = -1; | 
| 335   if (!IS_UNDEFINED(fractionDigits)) { | 358   if (!IS_UNDEFINED(fractionDigits)) { | 
| 336     f = TO_INTEGER(fractionDigits); | 359     f = TO_INTEGER(fractionDigits); | 
| 337     if (f < 0 || f > 20) { | 360     if (f < 0 || f > 20) { | 
| 338       throw new $RangeError("toExponential() argument must be between 0 and 20")
     ; | 361       throw new $RangeError("toExponential() argument must be between 0 and 20")
     ; | 
| 339     } | 362     } | 
| 340   } | 363   } | 
| 341   var x = ToNumber(this); | 364   var x = ToNumber(this); | 
| 342   return %NumberToExponential(x, f); | 365   return %NumberToExponential(x, f); | 
| 343 }, DONT_ENUM); | 366 }, DONT_ENUM); | 
| 344 | 367 | 
| 345 | 368 | 
| 346 // ECMA-262 section 15.7.4.7 | 369 // ECMA-262 section 15.7.4.7 | 
| 347 %AddProperty($Number.prototype, "toPrecision", function(precision) { | 370 %SetProperty($Number.prototype, "toPrecision", function(precision) { | 
| 348   if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); | 371   if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); | 
| 349   var p = TO_INTEGER(precision); | 372   var p = TO_INTEGER(precision); | 
| 350   if (p < 1 || p > 21) { | 373   if (p < 1 || p > 21) { | 
| 351     throw new $RangeError("toPrecision() argument must be between 1 and 21"); | 374     throw new $RangeError("toPrecision() argument must be between 1 and 21"); | 
| 352   } | 375   } | 
| 353   var x = ToNumber(this); | 376   var x = ToNumber(this); | 
| 354   return %NumberToPrecision(x, p); | 377   return %NumberToPrecision(x, p); | 
| 355 }, DONT_ENUM); | 378 }, DONT_ENUM); | 
| 356 | 379 | 
| 357 | 380 | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 382   // functions and don't cache under the assumption that people rarly | 405   // functions and don't cache under the assumption that people rarly | 
| 383   // convert functions to strings.  Note that we (apparently) can't | 406   // convert functions to strings.  Note that we (apparently) can't | 
| 384   // use regular expression literals in natives files. | 407   // use regular expression literals in natives files. | 
| 385   var regexp = ORIGINAL_REGEXP("%(\\w+\\()", "gm"); | 408   var regexp = ORIGINAL_REGEXP("%(\\w+\\()", "gm"); | 
| 386   if (source.match(regexp)) source = source.replace(regexp, "$1"); | 409   if (source.match(regexp)) source = source.replace(regexp, "$1"); | 
| 387   var name = %FunctionGetName(func); | 410   var name = %FunctionGetName(func); | 
| 388   return 'function ' + name + source; | 411   return 'function ' + name + source; | 
| 389 } | 412 } | 
| 390 | 413 | 
| 391 | 414 | 
| 392 %AddProperty($Function.prototype, "toString", function() { | 415 %SetProperty($Function.prototype, "toString", function() { | 
| 393   return FunctionSourceString(this); | 416   return FunctionSourceString(this); | 
| 394 }, DONT_ENUM); | 417 }, DONT_ENUM); | 
| 395 | 418 | 
| 396 | 419 | 
| 397 function NewFunction(arg1) {  // length == 1 | 420 function NewFunction(arg1) {  // length == 1 | 
| 398   var n = %_ArgumentsLength(); | 421   var n = %_ArgumentsLength(); | 
| 399   var p = ''; | 422   var p = ''; | 
| 400   if (n > 1) { | 423   if (n > 1) { | 
| 401     p = new $Array(n - 1); | 424     p = new $Array(n - 1); | 
| 402     // Explicitly convert all parameters to strings. | 425     // Explicitly convert all parameters to strings. | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 413   var source = '(function(' + p + ') {\n' + body + '\n})'; | 436   var source = '(function(' + p + ') {\n' + body + '\n})'; | 
| 414 | 437 | 
| 415   // The call to SetNewFunctionAttributes will ensure the prototype | 438   // The call to SetNewFunctionAttributes will ensure the prototype | 
| 416   // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 439   // property of the resulting function is enumerable (ECMA262, 15.3.5.2). | 
| 417   var f = %CompileString(source, -1, false)(); | 440   var f = %CompileString(source, -1, false)(); | 
| 418   %FunctionSetName(f, "anonymous"); | 441   %FunctionSetName(f, "anonymous"); | 
| 419   return %SetNewFunctionAttributes(f); | 442   return %SetNewFunctionAttributes(f); | 
| 420 } | 443 } | 
| 421 | 444 | 
| 422 %SetCode($Function, NewFunction); | 445 %SetCode($Function, NewFunction); | 
| OLD | NEW | 
|---|