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

Side by Side Diff: src/v8natives.js

Issue 14668013: Function constructor should avoid String.prototype methods (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix nit Created 7 years, 7 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 | « no previous file | test/mjsunit/regress/regress-2686.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
(...skipping 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 function NewFunction(arg1) { // length == 1 1760 function NewFunction(arg1) { // length == 1
1761 var n = %_ArgumentsLength(); 1761 var n = %_ArgumentsLength();
1762 var p = ''; 1762 var p = '';
1763 if (n > 1) { 1763 if (n > 1) {
1764 p = new InternalArray(n - 1); 1764 p = new InternalArray(n - 1);
1765 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i); 1765 for (var i = 0; i < n - 1; i++) p[i] = %_Arguments(i);
1766 p = Join(p, n - 1, ',', NonStringToString); 1766 p = Join(p, n - 1, ',', NonStringToString);
1767 // If the formal parameters string include ) - an illegal 1767 // If the formal parameters string include ) - an illegal
1768 // character - it may make the combined function expression 1768 // character - it may make the combined function expression
1769 // compile. We avoid this problem by checking for this early on. 1769 // compile. We avoid this problem by checking for this early on.
1770 if (p.indexOf(')') != -1) throw MakeSyntaxError('paren_in_arg_string',[]); 1770 if (%_CallFunction(p, ')', StringIndexOf) != -1) {
1771 throw MakeSyntaxError('paren_in_arg_string',[]);
1772 }
1771 // If the formal parameters include an unbalanced block comment, the 1773 // If the formal parameters include an unbalanced block comment, the
1772 // function must be rejected. Since JavaScript does not allow nested 1774 // function must be rejected. Since JavaScript does not allow nested
1773 // comments we can include a trailing block comment to catch this. 1775 // comments we can include a trailing block comment to catch this.
1774 p += '\n/' + '**/'; 1776 p += '\n/' + '**/';
1775 } 1777 }
1776 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; 1778 var body = (n > 0) ? ToString(%_Arguments(n - 1)) : '';
1777 var source = '(function(' + p + ') {\n' + body + '\n})'; 1779 var source = '(function(' + p + ') {\n' + body + '\n})';
1778 1780
1779 var global_receiver = %GlobalReceiver(global); 1781 var global_receiver = %GlobalReceiver(global);
1780 var f = %_CallFunction(global_receiver, %CompileString(source, true)); 1782 var f = %_CallFunction(global_receiver, %CompileString(source, true));
(...skipping 11 matching lines...) Expand all
1792 %SetCode($Function, NewFunction); 1794 %SetCode($Function, NewFunction);
1793 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); 1795 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM);
1794 1796
1795 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1797 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1796 "bind", FunctionBind, 1798 "bind", FunctionBind,
1797 "toString", FunctionToString 1799 "toString", FunctionToString
1798 )); 1800 ));
1799 } 1801 }
1800 1802
1801 SetUpFunction(); 1803 SetUpFunction();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-2686.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698