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

Side by Side Diff: src/v8natives.js

Issue 6223: Make sure that the name accessor on functions return the expected... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 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/uri.js ('k') | test/cctest/test-api.cc » ('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 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
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 28
29 // This file relies on the fact that the following declarations have been made 29 // This file relies on the fact that the following declarations have been made
30 //
30 // in runtime.js: 31 // in runtime.js:
31 // const $Object = global.Object; 32 // const $Object = global.Object;
32 // const $Boolean = global.Boolean; 33 // const $Boolean = global.Boolean;
33 // const $Number = global.Number; 34 // const $Number = global.Number;
34 // const $Function = global.Function; 35 // const $Function = global.Function;
35 // const $Array = global.Array; 36 // const $Array = global.Array;
36 // const $NaN = 0/0; 37 // const $NaN = 0/0;
38 //
39 // in math.js:
40 // const $floor = MathFloor
37 41
38 42
39 // ECMA 262 - 15.1.1.1. 43 // ECMA 262 - 15.1.1.1.
40 %AddProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); 44 %AddProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE);
41 45
42 46
43 // ECMA-262 - 15.1.1.2. 47 // ECMA-262 - 15.1.1.2.
44 %AddProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE); 48 %AddProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE);
45 49
46 50
47 // ECMA-262 - 15.1.1.3. 51 // ECMA-262 - 15.1.1.3.
48 %AddProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE); 52 %AddProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE);
49 53
50 54
51 // ECMA 262 - 15.1.4 55 // ECMA 262 - 15.1.4
52 function $isNaN(number) { 56 function $isNaN(number) {
53 var n = ToNumber(number); 57 var n = ToNumber(number);
54 return NUMBER_IS_NAN(n); 58 return NUMBER_IS_NAN(n);
55 }; 59 }
56 %AddProperty(global, "isNaN", $isNaN, DONT_ENUM); 60 %AddProperty(global, "isNaN", $isNaN, DONT_ENUM);
57 61
58 62
59 // ECMA 262 - 15.1.5 63 // ECMA 262 - 15.1.5
60 function $isFinite(number) { 64 function $isFinite(number) {
61 return %NumberIsFinite(ToNumber(number)); 65 return %NumberIsFinite(ToNumber(number));
62 }; 66 }
63 %AddProperty(global, "isFinite", $isFinite, DONT_ENUM); 67 %AddProperty(global, "isFinite", $isFinite, DONT_ENUM);
64 68
65 69
66 // ECMA-262 - 15.1.2.2 70 // ECMA-262 - 15.1.2.2
67 %AddProperty(global, "parseInt", function(string, radix) { 71 %AddProperty(global, "parseInt", function(string, radix) {
68 if (radix === void 0) { 72 if (radix === void 0) {
69 radix = 0; 73 radix = 0;
70 // Some people use parseInt instead of Math.floor. This 74 // Some people use parseInt instead of Math.floor. This
71 // optimization makes parseInt on a Smi 12 times faster (60ns 75 // optimization makes parseInt on a Smi 12 times faster (60ns
72 // vs 800ns). The following optimization makes parseInt on a 76 // vs 800ns). The following optimization makes parseInt on a
73 // non-Smi number 9 times faster (230ns vs 2070ns). Together 77 // non-Smi number 9 times faster (230ns vs 2070ns). Together
74 // 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).
75 if (%_IsSmi(string)) return string; 79 if (%_IsSmi(string)) return string;
76 if (IS_NUMBER(string)) { 80 if (IS_NUMBER(string)) {
77 if (string >= 0.01 && string < 1e9) 81 if (string >= 0.01 && string < 1e9)
78 return $Math_floor(string); 82 return $floor(string);
79 if (string <= -0.01 && string > -1e9) 83 if (string <= -0.01 && string > -1e9)
80 return - $Math_floor(-string); 84 return - $floor(-string);
81 } 85 }
82 } else { 86 } else {
83 radix = TO_INT32(radix); 87 radix = TO_INT32(radix);
84 if (!(radix == 0 || (2 <= radix && radix <= 36))) 88 if (!(radix == 0 || (2 <= radix && radix <= 36)))
85 return $NaN; 89 return $NaN;
86 } 90 }
87 return %StringParseInt(ToString(string), radix); 91 return %StringParseInt(ToString(string), radix);
88 }, DONT_ENUM); 92 }, DONT_ENUM);
89 93
90 94
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 379 }
376 380
377 // Censor occurrences of internal calls. We do that for all 381 // Censor occurrences of internal calls. We do that for all
378 // functions and don't cache under the assumption that people rarly 382 // functions and don't cache under the assumption that people rarly
379 // convert functions to strings. Note that we (apparently) can't 383 // convert functions to strings. Note that we (apparently) can't
380 // use regular expression literals in natives files. 384 // use regular expression literals in natives files.
381 var regexp = ORIGINAL_REGEXP("%(\\w+\\()", "gm"); 385 var regexp = ORIGINAL_REGEXP("%(\\w+\\()", "gm");
382 if (source.match(regexp)) source = source.replace(regexp, "$1"); 386 if (source.match(regexp)) source = source.replace(regexp, "$1");
383 var name = %FunctionGetName(func); 387 var name = %FunctionGetName(func);
384 return 'function ' + name + source; 388 return 'function ' + name + source;
385 }; 389 }
386 390
387 391
388 %AddProperty($Function.prototype, "toString", function() { 392 %AddProperty($Function.prototype, "toString", function() {
389 return FunctionSourceString(this); 393 return FunctionSourceString(this);
390 }, DONT_ENUM); 394 }, DONT_ENUM);
391 395
392 396
393 function NewFunction(arg1) { // length == 1 397 function NewFunction(arg1) { // length == 1
394 var n = %_ArgumentsLength(); 398 var n = %_ArgumentsLength();
395 var p = ''; 399 var p = '';
(...skipping 10 matching lines...) Expand all
406 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); 410 if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]);
407 } 411 }
408 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; 412 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : '';
409 var source = '(function(' + p + ') {\n' + body + '\n})'; 413 var source = '(function(' + p + ') {\n' + body + '\n})';
410 414
411 // The call to SetNewFunctionAttributes will ensure the prototype 415 // The call to SetNewFunctionAttributes will ensure the prototype
412 // property of the resulting function is enumerable (ECMA262, 15.3.5.2). 416 // property of the resulting function is enumerable (ECMA262, 15.3.5.2).
413 var f = %CompileString(source, -1, false)(); 417 var f = %CompileString(source, -1, false)();
414 %FunctionSetName(f, "anonymous"); 418 %FunctionSetName(f, "anonymous");
415 return %SetNewFunctionAttributes(f); 419 return %SetNewFunctionAttributes(f);
416 }; 420 }
417 421
418 %SetCode($Function, NewFunction); 422 %SetCode($Function, NewFunction);
OLDNEW
« no previous file with comments | « src/uri.js ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698