incubator-couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Smith <...@iriscouch.com>
Subject Re: [jira] [Commented] (COUCHDB-1302) Fix couchjs
Date Fri, 07 Oct 2011 06:57:56 GMT
Randall asked that I note for posterity that uglify.js may help.

It seems to be 100% Javascript, CommonJS (not just a Node), BSD
license. It gives you the Javascript abstract syntax tree. I was
thinking of using it for input validation.

Perhaps, instead of all sorts of new ideas, just make the breaking
change that you *must* stick to the normal CouchDB way, one function
in a string.

Here is how you can confirm a standard map function. That could be in
the view server, just before you eval() it.

http://friendpaste.com/7LdkWzEfGgrLTKYdo7JENm

// Confirm a valid old-school CouchDB map function.

var uglify = require('uglify-js')
  , assert = require('assert');

var old_map = "function(doc) { emit(doc._id, 1) }"

var code, ast;
code = old_map;

try {
  ast = uglify.parser.parse('(' + code + ')');
  assert.equal(ast[0], 'toplevel');

  var statements = ast[1];
  assert.equal(statements.length, 1);

  var func_expr = statements[0];
  assert.equal(func_expr.length, 2);
  assert.equal(func_expr[0], 'stat');

  var func_def = func_expr[1];
  assert.equal(func_def[0], 'function');

  if(process.env.require_name)
    assert.equal(func_def[1], 'map');

  var formals = func_def[2];
  assert.ok(formals.length <= 1);

  console.log('Good code:\n' + code);
} catch(e) {
  console.log('Bad code:\n' + code);
  if(ast)
    console.log('\nAST:\n' + JSON.stringify(ast));
}

On Fri, Oct 7, 2011 at 10:58 AM, Paul Joseph Davis (Commented) (JIRA)
<jira@apache.org> wrote:
>
>    [ https://issues.apache.org/jira/browse/COUCHDB-1302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13122519#comment-13122519
]
>
> Paul Joseph Davis commented on COUCHDB-1302:
> --------------------------------------------
>
> I agree with Randall. I think we have a plan for 1.1.1 that's sane. The 1.2 can of worms
is going to be a big one so we should make sure and separate the issues there.
>
>> Fix couchjs
>> -----------
>>
>>                 Key: COUCHDB-1302
>>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1302
>>             Project: CouchDB
>>          Issue Type: Improvement
>>          Components: JavaScript View Server
>>    Affects Versions: 1.1.1, 1.2, 1.3
>>            Reporter: Paul Joseph Davis
>>            Priority: Blocker
>>
>> Figure out why some spidermonkeys have an error when doing: eval("function(){}")
>
> --
> This message is automatically generated by JIRA.
> If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>
>
>



-- 
Iris Couch

Mime
View raw message