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

Side by Side Diff: src/math.js

Issue 14125004: Move global code for builtins into setup functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Andreas Rossberg. Created 7 years, 8 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/json.js ('k') | src/proxy.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
29 // in runtime.js:
30 // var $Object = global.Object;
28 31
29 // Keep reference to original values of some global properties. This 32 // Keep reference to original values of some global properties. This
30 // has the added benefit that the code in this file is isolated from 33 // has the added benefit that the code in this file is isolated from
31 // changes to these properties. 34 // changes to these properties.
32 var $floor = MathFloor; 35 var $floor = MathFloor;
33 var $abs = MathAbs; 36 var $abs = MathAbs;
34 37
35 // Instance class name can only be set on functions. That is the only 38 // Instance class name can only be set on functions. That is the only
36 // purpose for MathConstructor. 39 // purpose for MathConstructor.
37 function MathConstructor() {} 40 function MathConstructor() {}
38 %FunctionSetInstanceClassName(MathConstructor, 'Math');
39 var $Math = new MathConstructor(); 41 var $Math = new MathConstructor();
40 %SetPrototype($Math, $Object.prototype); 42
41 %SetProperty(global, "Math", $Math, DONT_ENUM); 43 // -------------------------------------------------------------------
42 44
43 // ECMA 262 - 15.8.2.1 45 // ECMA 262 - 15.8.2.1
44 function MathAbs(x) { 46 function MathAbs(x) {
45 if (%_IsSmi(x)) return x >= 0 ? x : -x; 47 if (%_IsSmi(x)) return x >= 0 ? x : -x;
46 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); 48 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
47 if (x === 0) return 0; // To handle -0. 49 if (x === 0) return 0; // To handle -0.
48 return x > 0 ? x : -x; 50 return x > 0 ? x : -x;
49 } 51 }
50 52
51 // ECMA 262 - 15.8.2.2 53 // ECMA 262 - 15.8.2.2
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 function MathTan(x) { 211 function MathTan(x) {
210 if (!IS_NUMBER(x)) x = NonNumberToNumber(x); 212 if (!IS_NUMBER(x)) x = NonNumberToNumber(x);
211 return %_MathTan(x); 213 return %_MathTan(x);
212 } 214 }
213 215
214 216
215 // ------------------------------------------------------------------- 217 // -------------------------------------------------------------------
216 218
217 function SetUpMath() { 219 function SetUpMath() {
218 %CheckIsBootstrapping(); 220 %CheckIsBootstrapping();
221
222 %SetPrototype($Math, $Object.prototype);
223 %SetProperty(global, "Math", $Math, DONT_ENUM);
224 %FunctionSetInstanceClassName(MathConstructor, 'Math');
225
219 // Set up math constants. 226 // Set up math constants.
220 // ECMA-262, section 15.8.1.1. 227 // ECMA-262, section 15.8.1.1.
221 %OptimizeObjectForAddingMultipleProperties($Math, 8); 228 %OptimizeObjectForAddingMultipleProperties($Math, 8);
222 %SetProperty($Math, 229 %SetProperty($Math,
223 "E", 230 "E",
224 2.7182818284590452354, 231 2.7182818284590452354,
225 DONT_ENUM | DONT_DELETE | READ_ONLY); 232 DONT_ENUM | DONT_DELETE | READ_ONLY);
226 // ECMA-262, section 15.8.1.2. 233 // ECMA-262, section 15.8.1.2.
227 %SetProperty($Math, 234 %SetProperty($Math,
228 "LN10", 235 "LN10",
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 "sqrt", MathSqrt, 281 "sqrt", MathSqrt,
275 "tan", MathTan, 282 "tan", MathTan,
276 "atan2", MathAtan2, 283 "atan2", MathAtan2,
277 "pow", MathPow, 284 "pow", MathPow,
278 "max", MathMax, 285 "max", MathMax,
279 "min", MathMin 286 "min", MathMin
280 )); 287 ));
281 } 288 }
282 289
283 SetUpMath(); 290 SetUpMath();
OLDNEW
« no previous file with comments | « src/json.js ('k') | src/proxy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698