[SERVER-7892] JS (v8) doesn't indent Created: 10/Dec/12  Updated: 11/Jul/16  Resolved: 18/Mar/13

Status: Closed
Project: Core Server
Component/s: JavaScript, Shell
Affects Version/s: 2.3.1
Fix Version/s: 2.4.4, 2.5.0

Type: Bug Priority: Critical - P2
Reporter: Scott Hernandez (Inactive) Assignee: Tad Marshall
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

If you do

> db.runCommand
function ( obj ){
if ( typeof( obj ) == "string" ){
var n = {};
n[obj] = 1;
obj = n;
}
return this.getCollection( "$cmd" ).findOne( obj );
}

The output is not indented.

This worked with spidermonkey



 Comments   
Comment by auto [ 30/Apr/13 ]

Author:

{u'date': u'2013-03-18T17:14:06Z', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-7892 Do not strip indentation in JavaScript source code

V8 displays source code "as-is", so if we remove indentation then it
won't be there when users display "built-in" shell helper source code.
Branch: v2.4
https://github.com/mongodb/mongo/commit/dc3b3a8fd707e2a3ff4243f4c6a648b8fa12667c

Comment by auto [ 18/Mar/13 ]

Author:

{u'date': u'2013-03-18T17:14:06Z', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}

Message: SERVER-7892 Do not strip indentation in JavaScript source code

V8 displays source code "as-is", so if we remove indentation then it
won't be there when users display "built-in" shell helper source code.
Branch: master
https://github.com/mongodb/mongo/commit/2d2a2ce570c402dcdc445fde3842818b1ea6c89c

Comment by Tad Marshall [ 23/Dec/12 ]

What is happening here is that V8 just prints the JavaScript exactly as it was provided to it, and our jsToH Python script strips leading spaces and tabs from the JavaScript code we supply. We could either stop stripping spaces and tabs or add code to do pretty-printing of JavaScript.

Code that is supplied that includes indentation will be displayed as-is with its indentation.

Generated at Thu Feb 08 03:15:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.