Skip to content

Commit dce6769

Browse files
committed
Document another spidermonkey vs spidermonkey discrepancy
`String.substring("abcd", 1, 2)` stopped working at some point between 1.8.5 and 91. My 52 and 78 installs broke, so can only test those two. Also noticed some of the discrepances had been indented while others were not, so made them all non-indented as that looked better and saved some horizontal space.
1 parent 1bf0389 commit dce6769

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

src/docs/src/best-practices/jsdevel.rst

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ known regression or discrepancies between versions:
7878

7979
1. ``for each (var x in ...)``
8080

81-
Version ``1.8.5`` supports the ``for each (var x in ...)`` looping
82-
expression. That's not a standard JavaScript syntax and is not supported in
83-
later versions:
81+
Version ``1.8.5`` supports the ``for each (var x in ...)`` looping
82+
expression. That's not a standard JavaScript syntax and is not supported in
83+
later versions:
8484

8585
.. code-block:: bash
8686
@@ -97,10 +97,10 @@ known regression or discrepancies between versions:
9797
9898
2. E4X (ECMAScript for XML)
9999
100-
This is not supported in versions greater than ``1.8.5``. This feature may
101-
be inadvertently triggered when inserting a ``.`` character between a
102-
variable and ``(``. That would compile on ``1.8.5`` and throw a
103-
``SyntaxError`` on other versions:
100+
This is not supported in versions greater than ``1.8.5``. This feature may be
101+
inadvertently triggered when inserting a ``.`` character between a variable and
102+
``(``. That would compile on ``1.8.5`` and throw a ``SyntaxError`` on other
103+
versions:
104104
105105
.. code-block:: bash
106106
@@ -119,7 +119,7 @@ known regression or discrepancies between versions:
119119
120120
3. ``toLocaleFormat(...)`` function.
121121
122-
This ``Date`` function is not present in versions greater than ``1.8.5``:
122+
This ``Date`` function is not present in versions greater than ``1.8.5``:
123123
124124
.. code-block:: bash
125125
@@ -137,8 +137,8 @@ known regression or discrepancies between versions:
137137
138138
4. ``toLocaleString(...)`` function.
139139
140-
SpiderMonkey 1.8.5 ignored locale strings. Later versions started to
141-
return the correct format:
140+
SpiderMonkey 1.8.5 ignored locale strings. Later versions started to return the
141+
correct format:
142142
143143
.. code-block:: bash
144144
@@ -155,9 +155,8 @@ Spidermonkey 91 output also match QuickJS and v8.
155155
5. Invalid expressions following ``function(){...}`` are not ignored any longer
156156
and will throw an error.
157157
158-
Previously, in versions less than or equal to ``1.8.5`` it was possible add
159-
any expression following the main function definition and they were mostly
160-
ignored:
158+
Previously, in versions less than or equal to ``1.8.5`` it was possible add any
159+
expression following the main function definition and they were mostly ignored:
161160
162161
.. code-block:: bash
163162
@@ -183,7 +182,7 @@ Spidermonkey 91 output also match QuickJS and v8.
183182
"total_rows": 1
184183
}
185184
186-
With higher versions of SpiderMonkey, that would throw a compilation error:
185+
With higher versions of SpiderMonkey, that would throw a compilation error:
187186
188187
.. code-block:: bash
189188
@@ -196,8 +195,8 @@ Spidermonkey 91 output also match QuickJS and v8.
196195
197196
6. Object key order.
198197
199-
Object key order may change between versions, so any views which rely on
200-
that order may emit different results depending on the engine version:
198+
Object key order may change between versions, so any views which rely on that
199+
order may emit different results depending on the engine version:
201200
202201
.. code-block:: bash
203202
@@ -211,8 +210,8 @@ Spidermonkey 91 output also match QuickJS and v8.
211210
212211
7. String ``match(undefined)``
213212
214-
Spidermonkey 1.8.5 returns ``null`` for ``match(undefined)`` while versions
215-
starting with at least ``78`` return ``[""]``.
213+
Spidermonkey 1.8.5 returns ``null`` for ``match(undefined)`` while versions
214+
starting with at least ``78`` return ``[""]``.
216215
217216
.. code-block:: bash
218217
@@ -224,7 +223,32 @@ Spidermonkey 91 output also match QuickJS and v8.
224223
js> "abc".match(undefined)
225224
[""]
226225
227-
8. The ``toISOString()`` throws an error on invalid ``Date`` objects.
226+
8. String ``substring(val, start, end)``
227+
228+
Spidermonkey ``1.8.5`` has a ``String.substring(val, start, end)`` function. That
229+
function is not present in at least Spidermonkey ``91`` and higher:
230+
231+
.. code-block:: bash
232+
233+
% js
234+
js> String.substring("abcd", 1, 2)
235+
"b"
236+
237+
% js91
238+
js> String.substring("abcd", 1, 2)
239+
typein:1:8 TypeError: String.substring is not a function
240+
Stack:
241+
@typein:1:
242+
243+
Use ``String.prototype.substring(start, end)`` instead:
244+
245+
.. code-block:: bash
246+
247+
% js91
248+
js> "abcd".substring(1, 2)
249+
"b"
250+
251+
9. The ``toISOString()`` throws an error on invalid ``Date`` objects.
228252
229253
SpiderMonkey version ``1.8.5`` does not throw an error when calling
230254
``toISOString()`` on invalid ``Date`` objects, but SpiderMonkey versions at
@@ -247,7 +271,7 @@ might have emitted the "Invalid Date" string, while in later SpiderMonkey
247271
engines all the emit results from that document will be skipped, since view
248272
functions skip view results if an exception is thrown.
249273
250-
9. Invalid JavaScript before function definition
274+
10. Invalid JavaScript before function definition
251275
252276
SpiderMoneky version ``1.8.5`` allowed the invalid ``term : function(...)``
253277
syntax. So a view function like the following worked and produced successfull

0 commit comments

Comments
 (0)