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

Unified Diff: src/v8natives.js

Issue 12613007: Harden Function()'s parsing of function literals. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Andreas Rossberg. Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/new-function.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index f295c3a6de37d0f4fdc4d3aab65a854784d1e035..826ae43b64b1fd26dceafb082276c566cb7a9619 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -174,7 +174,7 @@ function GlobalEval(x) {
'be the global object from which eval originated');
}
- var f = %CompileString(x);
+ var f = %CompileString(x, false);
if (!IS_FUNCTION(f)) return f;
return %_CallFunction(global_receiver, f);
@@ -1704,14 +1704,18 @@ function NewFunction(arg1) { // length == 1
// character - it may make the combined function expression
// compile. We avoid this problem by checking for this early on.
if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]);
+ // If the formal parameters include an unbalanced block comment, the
+ // function must be rejected. Since JavaScript does not allow nested
+ // comments we can include a trailing block comment to catch this.
+ p += '\n/' + '**/';
}
var body = (n > 0) ? ToString(%_Arguments(n - 1)) : '';
- var source = '(function(' + p + ') {\n' + body + '\n})';
+ var source = '(function(\n' + p + '\n){\n' + body + '\n})';
// The call to SetNewFunctionAttributes will ensure the prototype
// property of the resulting function is enumerable (ECMA262, 15.3.5.2).
var global_receiver = %GlobalReceiver(global);
- var f = %_CallFunction(global_receiver, %CompileString(source));
+ var f = %_CallFunction(global_receiver, %CompileString(source, true));
%FunctionMarkNameShouldPrintAsAnonymous(f);
return %SetNewFunctionAttributes(f);
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/new-function.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698