You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "paul iannazzo (Created) (JIRA)" <ji...@apache.org> on 2011/10/01 19:36:34 UTC

[jira] [Created] (COUCHDB-1300) Array.prototype isn't getting set.

Array.prototype isn't getting set.
----------------------------------

                 Key: COUCHDB-1300
                 URL: https://issues.apache.org/jira/browse/COUCHDB-1300
             Project: CouchDB
          Issue Type: Bug
          Components: JavaScript View Server
    Affects Versions: 1.1
         Environment: Ubuntu 11.04, node.couchapp, commonJS
            Reporter: paul iannazzo


##file helpers.js in views/lib/common
const _ = require("views/lib/underscore");
Array.prototype.compact = function(){return _.compact(this);};
Array.prototype.flatten = function(){return _.flatten(this);};

//this function is called from views.someName.map
function commonProperties(doc){
    arr = [];
    arr = arr.compact();
    log(arr);
    log("is array?");
    log(toString.call(doc.store.taxes));
    log(doc.store.taxes);
    //log(doc.store.taxes.compact());
    log("is safe array?");
    log(toString.call(safe.array(doc.store.taxes)));
    log(safe.array(doc.store.taxes));
   //log(safe.array(doc.store.taxes).compact());
    log("array?");
    log(toString.call(Array(safe.array(doc.store.taxes))));
    log(Array(doc.store.taxes));
    log(Array(doc.store.taxes).compact());
...


::LOG

[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is safe array?
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: array?
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [[{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]]


the .compact() lines that are commented out cause errors:
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
[info] [<0.3429.0>] OS Process #Port<0.5316> Log :: function raised exception (new TypeError("doc.store.taxes.compact is not a function", "", 29)) with doc._id RT7-RT7-31-20

the first logs show that doc.store.taxes is an array, why do i need to use Array() on it in order to use the prototype functions?


--
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

        

[jira] [Updated] (COUCHDB-1300) Array.prototype isn't working properly

Posted by "paul iannazzo (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COUCHDB-1300?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

paul iannazzo updated COUCHDB-1300:
-----------------------------------

    Summary: Array.prototype isn't working properly  (was: Array.prototype isn't getting set.)
    
> Array.prototype isn't working properly
> --------------------------------------
>
>                 Key: COUCHDB-1300
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1300
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>    Affects Versions: 1.1
>         Environment: Ubuntu 11.04, node.couchapp, commonJS
>            Reporter: paul iannazzo
>              Labels: javascript, patch
>
> ##file helpers.js in views/lib/common
> const _ = require("views/lib/underscore");
> Array.prototype.compact = function(){return _.compact(this);};
> Array.prototype.flatten = function(){return _.flatten(this);};
> //this function is called from views.someName.map
> function commonProperties(doc){
>     arr = [];
>     arr = arr.compact();
>     log(arr);
>     log("is array?");
>     log(toString.call(doc.store.taxes));
>     log(doc.store.taxes);
>     //log(doc.store.taxes.compact());
>     log("is safe array?");
>     log(toString.call(safe.array(doc.store.taxes)));
>     log(safe.array(doc.store.taxes));
>    //log(safe.array(doc.store.taxes).compact());
>     log("array?");
>     log(toString.call(Array(safe.array(doc.store.taxes))));
>     log(Array(doc.store.taxes));
>     log(Array(doc.store.taxes).compact());
> ...
> ::LOG
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is safe array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [[{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]]
> the .compact() lines that are commented out cause errors:
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: function raised exception (new TypeError("doc.store.taxes.compact is not a function", "", 29)) with doc._id RT7-RT7-31-20
> the first logs show that doc.store.taxes is an array, why do i need to use Array() on it in order to use the prototype functions?

--
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

        

[jira] [Commented] (COUCHDB-1300) Array.prototype isn't working properly

Posted by "paul iannazzo (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COUCHDB-1300?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13118941#comment-13118941 ] 

paul iannazzo commented on COUCHDB-1300:
----------------------------------------

I found a workaround (i guess solution in this case) to my problem.
instead of using array prototypes i can get the same functionality via monads (specifically the underscore library).

anyway, i found this issue very confusing.

thank you for your quick response.
                
> Array.prototype isn't working properly
> --------------------------------------
>
>                 Key: COUCHDB-1300
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1300
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>    Affects Versions: 1.1
>         Environment: Ubuntu 11.04, node.couchapp, commonJS
>            Reporter: paul iannazzo
>              Labels: javascript, patch
>
> ##file helpers.js in views/lib/common
> const _ = require("views/lib/underscore");
> Array.prototype.compact = function(){return _.compact(this);};
> Array.prototype.flatten = function(){return _.flatten(this);};
> //this function is called from views.someName.map
> function commonProperties(doc){
>     arr = [];
>     arr = arr.compact();
>     log(arr);
>     log("is array?");
>     log(toString.call(doc.store.taxes));
>     log(doc.store.taxes);
>     //log(doc.store.taxes.compact());
>     log("is safe array?");
>     log(toString.call(safe.array(doc.store.taxes)));
>     log(safe.array(doc.store.taxes));
>    //log(safe.array(doc.store.taxes).compact());
>     log("array?");
>     log(toString.call(Array(safe.array(doc.store.taxes))));
>     log(Array(doc.store.taxes));
>     log(Array(doc.store.taxes).compact());
> ...
> ::LOG
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is safe array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [[{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]]
> the .compact() lines that are commented out cause errors:
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: function raised exception (new TypeError("doc.store.taxes.compact is not a function", "", 29)) with doc._id RT7-RT7-31-20
> the first logs show that doc.store.taxes is an array, why do i need to use Array() on it in order to use the prototype functions?

--
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

        

[jira] [Resolved] (COUCHDB-1300) Array.prototype isn't working properly

Posted by "Paul Joseph Davis (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COUCHDB-1300?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul Joseph Davis resolved COUCHDB-1300.
----------------------------------------

    Resolution: Not A Problem
    
> Array.prototype isn't working properly
> --------------------------------------
>
>                 Key: COUCHDB-1300
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1300
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>    Affects Versions: 1.1
>         Environment: Ubuntu 11.04, node.couchapp, commonJS
>            Reporter: paul iannazzo
>              Labels: javascript, patch
>
> ##file helpers.js in views/lib/common
> const _ = require("views/lib/underscore");
> Array.prototype.compact = function(){return _.compact(this);};
> Array.prototype.flatten = function(){return _.flatten(this);};
> //this function is called from views.someName.map
> function commonProperties(doc){
>     arr = [];
>     arr = arr.compact();
>     log(arr);
>     log("is array?");
>     log(toString.call(doc.store.taxes));
>     log(doc.store.taxes);
>     //log(doc.store.taxes.compact());
>     log("is safe array?");
>     log(toString.call(safe.array(doc.store.taxes)));
>     log(safe.array(doc.store.taxes));
>    //log(safe.array(doc.store.taxes).compact());
>     log("array?");
>     log(toString.call(Array(safe.array(doc.store.taxes))));
>     log(Array(doc.store.taxes));
>     log(Array(doc.store.taxes).compact());
> ...
> ::LOG
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is safe array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [[{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]]
> the .compact() lines that are commented out cause errors:
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: function raised exception (new TypeError("doc.store.taxes.compact is not a function", "", 29)) with doc._id RT7-RT7-31-20
> the first logs show that doc.store.taxes is an array, why do i need to use Array() on it in order to use the prototype functions?

--
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

        

[jira] [Commented] (COUCHDB-1300) Array.prototype isn't working properly

Posted by "Filipe Manana (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COUCHDB-1300?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13118937#comment-13118937 ] 

Filipe Manana commented on COUCHDB-1300:
----------------------------------------

Hi, there's a reason for that, and it's exactly the same reason why "foo instanceof Array" fails when foo is created in a browser iframe and the previous expression evaluated in another iframe which is accessing that array.

For couch, the user document is json decoded in one javascript context and the map function ran against the document is executed in another context (a sandbox). Each context has its own Array constructor.

                
> Array.prototype isn't working properly
> --------------------------------------
>
>                 Key: COUCHDB-1300
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1300
>             Project: CouchDB
>          Issue Type: Bug
>          Components: JavaScript View Server
>    Affects Versions: 1.1
>         Environment: Ubuntu 11.04, node.couchapp, commonJS
>            Reporter: paul iannazzo
>              Labels: javascript, patch
>
> ##file helpers.js in views/lib/common
> const _ = require("views/lib/underscore");
> Array.prototype.compact = function(){return _.compact(this);};
> Array.prototype.flatten = function(){return _.flatten(this);};
> //this function is called from views.someName.map
> function commonProperties(doc){
>     arr = [];
>     arr = arr.compact();
>     log(arr);
>     log("is array?");
>     log(toString.call(doc.store.taxes));
>     log(doc.store.taxes);
>     //log(doc.store.taxes.compact());
>     log("is safe array?");
>     log(toString.call(safe.array(doc.store.taxes)));
>     log(safe.array(doc.store.taxes));
>    //log(safe.array(doc.store.taxes).compact());
>     log("array?");
>     log(toString.call(Array(safe.array(doc.store.taxes))));
>     log(Array(doc.store.taxes));
>     log(Array(doc.store.taxes).compact());
> ...
> ::LOG
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is safe array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [[{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]]
> the .compact() lines that are commented out cause errors:
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: []
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: is array?
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [object Array]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: [{"taxId":0,"number":"000000","percent":8},{"taxId":1,"number":"","percent":5},{"taxId":2,"number":"","percent":1}]
> [info] [<0.3429.0>] OS Process #Port<0.5316> Log :: function raised exception (new TypeError("doc.store.taxes.compact is not a function", "", 29)) with doc._id RT7-RT7-31-20
> the first logs show that doc.store.taxes is an array, why do i need to use Array() on it in order to use the prototype functions?

--
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