Lgtm. Any idea why the function is called "anonymous"? Seems pointless (and self-contradictory since anonymous means "without name").
On Wed, Sep 24, 2008 at 10:31 AM, <[EMAIL PROTECTED]> wrote: > > Reviewers: plesner, > > Description: > Make sure that the body of the function created by calling Function is > on a line of its own. This allows the body to be terminated by a > single-line comment. > > This is a fix for http://code.google.com/p/v8/issues/detail?id=85 > > Please review this at http://codereview.chromium.org/4248 > > Affected files: > M src/v8natives.js > M test/mjsunit/function.js > > > Index: test/mjsunit/function.js > =================================================================== > --- test/mjsunit/function.js (revision 366) > +++ test/mjsunit/function.js (working copy) > @@ -27,23 +27,27 @@ > > var f = Function(); > assertTrue(typeof f() == 'undefined'); > -var f = new Function(); > +f = new Function(); > assertTrue(typeof f() == 'undefined'); > > -var f = Function('return 1'); > +f = Function('return 1'); > assertEquals(1, f()); > -var f = new Function('return 1'); > +f = new Function('return 1'); > assertEquals(1, f()); > > -var f = Function('return true'); > +f = Function('return true'); > assertTrue(f()); > -var f = new Function('return true'); > +f = new Function('return true'); > assertTrue(f()); > > -var f = Function('x', 'return x') > +f = Function('x', 'return x'); > assertEquals(1, f(1)); > assertEquals('bar', f('bar')); > assertTrue(typeof f() == 'undefined'); > + > +f = Function('x', 'return x // comment'); > +assertEquals(1, f(1)); > + > var x = {}; > assertTrue(x === f(x)); > var f = new Function('x', 'return x') > Index: src/v8natives.js > =================================================================== > --- src/v8natives.js (revision 366) > +++ src/v8natives.js (working copy) > @@ -406,7 +406,7 @@ > if (p.indexOf(')') != -1) throw MakeSyntaxError('unable_to_parse',[]); > } > var body = (n > 0) ? ToString(%_Arguments(n - 1)) : ''; > - var source = '(function anonymous(' + p + ') { ' + body + ' })'; > + var source = '(function anonymous(' + p + ') {\n ' + body + '\n})'; > > // The call to SetNewFunctionAttributes will ensure the prototype > // property of the resulting function is enumerable (ECMA262, 15.3.5.2). > > > > > > --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
