nickva commented on code in PR #5221: URL: https://github.com/apache/couchdb/pull/5221#discussion_r1747242973
########## src/docs/src/best-practices/jsdevel.rst: ########## @@ -46,3 +46,254 @@ tips and tricks that will ease the difficulty. - Be sure to guard all document accesses to avoid exceptions when fields or subfields are missing: ``if (doc && doc.myarray && doc.myarray.length)...`` + +=========================== +JavaScript engine versions +=========================== + +Until version 3.4 Apache CouchDB used only Spidermonkey as the it's +underlying JavaScript engine. With version 3.4, it's possible to configure +CouchDB to use QuickJS. + +Recent versions of CouchDB may use the node-local ``_versions`` API endpoint to +get the current engine type and version: + +.. code-block:: bash + + % http http://adm:pass@localhost:5984/_node/_local/_versions | jq '.javascript_engine' + { + "version": "1.8.5", + "name": "spidermonkey" + } + +Spidermonkey version compatibility +================================== + +Depending on the CouchDB version and what's available on supported operating +systems, the Spidermonkey version may be any one of these: 1.8.5, 60, 68, 78, +86 or 91. Sometimes there are differences in supported features between +versions. Usually later versions only add features, so views will work on +version upgrades. However, there are a few exceptions to this. These are a few +known regression or discrepancies between versions: + +1. ``for each (var x in ...)`` + + Version ``1.8.5`` supports the ``for each (var x in ...)`` looping + expression. That's not a standard JavaScript syntax and is not supported in + later versions: + +.. code-block:: bash + + % js + js> for each (var x in [1,2]) {print(x)} + 1 + 2 + + % js91 + js> for each (var x in [1,2]) {print(x)} + typein:1:4 SyntaxError: missing ( after for: + typein:1:4 for each (var x in [1,2]) {print(x)} + typein:1:4 ....^ + +2. E4X (ECMAScript for XML) + + This is not supported in versions greater than ``1.8.5``. This feature may + be inadvertently triggered when inserting a ``.`` character between a + variable and ``(``. That would compile on ``1.8.5`` and throw a + ``SyntaxError`` on other versions: + +.. code-block:: bash + + % js + js> var xml = <root><x></x></root> + js> xml.(x) + <root> + <x/> + </root> + + % js91 + js> var xml = <root><x></x></root> + typein:1:11 SyntaxError: expected expression, got '<': + typein:1:11 var xml = <root><x></x></root> + typein:1:11 ...........^ + +3. ``toLocaleFormat(...)`` function. + + This ``Date`` function is not present in versions greater than ``1.8.5``: Review Comment: I just used `Date` since that's the class/object and the function name is already mentioned in the section title. The full name should be something like `Date.prototype.toLocaleFormat()` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
