nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.47k stars 282 forks source link

Fatal JavaScript invalid size error 169220804 #4178

Open jcubic opened 1 year ago

jcubic commented 1 year ago

Details

I've got this error when trying to optimize my code. The first thing was adding ^ in form of some regular expressions.

#
# Fatal error in , line 0
# Fatal JavaScript invalid size error 169220804
#
#
#
#FailureMessage Object: 0x7fffa0279820
 1: 0xbe67b1  [node]
 2: 0x1e4d4d4 V8_Fatal(char const*, ...) [node]
 3: 0xf00108  [node]
 4: 0x10afa92  [node]
 5: 0x10afd55  [node]
 6: 0x12beb3b v8::internal::Runtime_GrowArrayElements(int, unsigned long*, v8::internal::Isolate*) [node]
 7: 0x16fb6b9  [node]

Node.js version

v18.16.0

Example code

The only thing I do in my code that is big is this one:

var emoji_re = /BIG ES5 Emoji Regex from Mathias Bynens/;
var emoji_start_re = new RegExp('^' + emoji_re.source);

But I've replaced that with:

var emoji_start_re = new RegExp('^' + 'x');

and got the same error.

Operating system

Fedora 38

Scope

runtime

Module and version

jest: ^27.5.1
jquery.terminal @ devel

Additional Notes

I've pushed my changes to this branch:

https://github.com/jcubic/jquery.terminal/tree/perf

You can see the diff by comparing it with the devel branch.

This is the test that is failing:

https://github.com/jcubic/jquery.terminal/actions/runs/5205330154/jobs/9390658418#step:9:23

preveen-stack commented 1 year ago

@jcubic can you post the diff

jcubic commented 1 year ago

Sure:

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1faa58ff..82b8b5f7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
 ## 2.36.1
 ### Bugfix
 * fix CMD wrapping when prompt is empty [#882](https://github.com/jcubic/jquery.terminal/issues/882)
+* fix performance of long running typing animations [#820](https://github.com/jcubic/jquery.terminal/issues/820)

 ## 2.36.0
 ### Features
diff --git a/js/jquery.terminal-2.36.0.js b/js/jquery.terminal-2.36.0.js
index 824bcd88..f2301cd9 100644
Binary files a/js/jquery.terminal-2.36.0.js and b/js/jquery.terminal-2.36.0.js differ
diff --git a/js/jquery.terminal-2.36.0.min.js b/js/jquery.terminal-2.36.0.min.js
index 256c7d3d..b5ba398b 100644
Binary files a/js/jquery.terminal-2.36.0.min.js and b/js/jquery.terminal-2.36.0.min.js differ
diff --git a/js/jquery.terminal-src.js b/js/jquery.terminal-src.js
index 5dec6189..7681c23b 100644
--- a/js/jquery.terminal-src.js
+++ b/js/jquery.terminal-src.js
@@ -1177,14 +1177,19 @@
     // -------------------------------------------------------------------------
     /* eslint-disable */
     var entity_re = /(&(?:[a-z\d]+|#\d+|#x[a-f\d]+);)/i;
+    var entity_start_re = new RegExp('^' + entity_re.source);
     var space_re = /\s/;
     // regex that match single character at begining and folowing combine character
     // https://en.wikipedia.org/wiki/Combining_character
     var combine_chr_re = /(.(?:[\u0300-\u036F]|[\u1AB0-\u1abE]|[\u1DC0-\u1DF9]|[\u1DFB-\u1DFF]|[\u20D0-\u20F0]|[\uFE20-\uFE2F])+)/;
+    var combine_chr_start_re = new RegExp(combine_chr_re.source);
+    
     // source: https://mathiasbynens.be/notes/javascript-unicode
     var astral_symbols_re = /([\uD800-\uDBFF][\uDC00-\uDFFF])/;
+    var astral_symbols_start_re = new RegExp('^' + astral_symbols_re);
     // source: https://github.com/mathiasbynens/emoji-regex
     var emoji_re = /(\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC68(?:\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|[\u2695\u2696\u2708]\uFE0F|\uD83D[\uDC66\uDC67]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708])\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83E\uDDD1(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69])(?:\uD83C[\uDFFB-\uDFFE])|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69])(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69])(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69])(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69])(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83E\uDDD1(?:(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC3B\u200D\u2744|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F\u200D[\u2640\u2642]|(?:\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642])|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E-\uDC71\u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(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270A-\u270D]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDCAA\uDD74\uDD7A\uDD90\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2-\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F?|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD]))/;
+    var emoji_start_re = new RegExp('^' + emoji_re);
     // https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser
     var mobile_re = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i;
     var tablet_re = /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i;
@@ -3542,10 +3547,12 @@
                            '</span>';
                 }).concat([last_line]).join('\n');
             }
-            function set(prompt) {
+            function set(prompt, options) {
                 if (prompt) {
-                    prompt = $.terminal.apply_formatters(prompt, {prompt: true});
-                    prompt = $.terminal.normalize(prompt);
+                    if (options.formatters) {
+                        prompt = $.terminal.apply_formatters(prompt, {prompt: true});
+                        prompt = $.terminal.normalize(prompt);
+                    }
                     prompt = crlf(prompt);
                 }
                 var formatted = format_prompt(prompt);
@@ -3575,7 +3582,10 @@
                     }
                 }
             }
-            return function() {
+            return function(options) {
+                var settings = $.extend({
+                    formatters: true
+                }, options);
                 // the data is used as cancelable reference because we have ref
                 // data object that is hold in closure and we remove `set` function
                 // so previous call to function prompt will be ignored
@@ -3588,7 +3598,7 @@
                     set: set
                 };
                 with_prompt(prompt, function(prompt) {
-                    data.set(prompt);
+                    data.set(prompt, settings);
                 }, self);
             };
         })();
@@ -3801,7 +3811,10 @@
                 prompt_offset = len;
                 prompt_len = just_prompt_len + prompt_offset;
             },
-            prompt: function(user_prompt) {
+            prompt: function(user_prompt, options) {
+                var settings = $.extend({
+                    formatters: true
+                }, options);
                 if (user_prompt === true) {
                     return last_rendered_prompt;
                 } else if (user_prompt === undefined) {
@@ -3815,7 +3828,7 @@
                         throw new Error('prompt must be a function or string');
                     }
                     if (should_redraw) {
-                        draw_prompt();
+                        draw_prompt(settings);
                         // we could check if command is longer then numchars-new
                         // prompt
                         redraw();
@@ -4732,16 +4745,12 @@
     function make_re_fn(re) {
         return function test_re(string) {
             var m = string.match(re);
-            if (starts_with(m)) {
+            if (m) {
                 return m[1];
             }
         };
     }
     // -------------------------------------------------------------------------
-    function starts_with(match) {
-        return match && match.index === 0;
-    }
-    // -------------------------------------------------------------------------
     function is_simple_text(string) {
         var re = [
             entity_re,
@@ -4766,9 +4775,9 @@
     function make_next_char_fun(string) {
         var tests = [];
         [
-            entity_re,
-            emoji_re,
-            combine_chr_re
+            entity_start_re,
+            emoji_start_re,
+            combine_chr_start_re
         ].forEach(function(re) {
             if (re.test(string)) {
                 tests.push(make_re_fn(re));
@@ -4776,8 +4785,8 @@
         });
         if (astral_symbols_re.test(string)) {
             tests.push(function test_astral(string) {
-                var m1 = string.match(astral_symbols_re);
-                if (starts_with(m1)) {
+                var m1 = string.match(astral_symbols_start_re);
+                if (m1) {
                     var m2 = string.match(combine_chr_re);
                     if (m2 && m2.index === 1) {
                         return string.slice(0, 3);
@@ -4802,22 +4811,22 @@
     // :: counting emoji, suroggate pairs and combine characters
     // -------------------------------------------------------------------------
     function get_next_character(string) {
-        var match_entity = string.match(entity_re);
-        if (starts_with(match_entity)) {
+        var match_entity = string.match(entity_start_re);
+        if (match_entity) {
             return match_entity[1];
         }
-        var match_combo = string.match(combine_chr_re);
-        if (starts_with(match_combo)) {
+        var match_combo = string.match(combine_chr_start_re);
+        if (match_combo) {
             return match_combo[1];
         }
-        var match_emoji = string.match(emoji_re);
-        if (starts_with(match_emoji)) {
+        var match_emoji = string.match(emoji_start_re);
+        if (match_emoji) {
             return match_emoji[1];
         } else if (string.charCodeAt(0) < 255) {
             return string[0];
         } else {
-            var astral_match = string.match(astral_symbols_re);
-            if (starts_with(astral_match)) {
+            var astral_match = string.match(astral_symbols_start_re);
+            if (astral_match) {
                 match_combo = string.match(combine_chr_re);
                 if (match_combo && match_combo.index === 1) {
                     return string.slice(0, 3);
@@ -9103,6 +9112,7 @@
                 var formattted = $.terminal.apply_formatters(message, {
                     animation: true
                 });
+                formattted = $.terminal.normalize(formattted);
                 animating = true;
                 var prompt = self.get_prompt();
                 var char_i = 0;
@@ -9128,7 +9138,7 @@
                                 }
                             }
                             new_prompt += chr;
-                            self.set_prompt(new_prompt);
+                            command_line.prompt(new_prompt, {formatters: false});
                             if (bottom && (chr === '\n' || !self.is_bottom())) {
                                 self.scroll_to_bottom();
                             }
@@ -9137,7 +9147,7 @@
                             self.skip_stop();
                             var chrRest = $.terminal.substring(formattted, char_i, len);
                             new_prompt += chrRest;
-                            self.set_prompt(new_prompt);
+                            command_line.prompt(new_prompt, {formatters: false});
                             char_i = len;
                         }
                         if (char_i === len) {
@@ -12153,7 +12163,7 @@
                 }, options);
             }
             function bottom_detect(intersections) {
-                is_bottom_detected = intersections[0].intersectionRatio === 1;
+                is_bottom_detected = intersections[0].intersectionRatio >= 0.9;
             }
             function create_bottom_detect() {
                 if (window.IntersectionObserver) {
diff --git a/js/jquery.terminal.js b/js/jquery.terminal.js
index 824bcd88..f2301cd9 100644
Binary files a/js/jquery.terminal.js and b/js/jquery.terminal.js differ
diff --git a/js/jquery.terminal.min.js b/js/jquery.terminal.min.js
index 256c7d3d..b5ba398b 100644
Binary files a/js/jquery.terminal.min.js and b/js/jquery.terminal.min.js differ
diff --git a/js/jquery.terminal.min.js.map b/js/jquery.terminal.min.js.map
index 3e0173ba..090a3773 100644
Binary files a/js/jquery.terminal.min.js.map and b/js/jquery.terminal.min.js.map differ

When animation runs the set function from the prompt is executed on every character. I was thinking maybe I allocate too many objects for options => settings.

jcubic commented 1 year ago

Any idea what is happening?

preveen-stack commented 1 year ago

can you check options in this link https://support.circleci.com/hc/en-us/articles/360009208393-How-can-I-increase-the-max-memory-for-Node-

jcubic commented 1 year ago

@preveen-stack What size do I need to use, what is the default size in Node 16 that I use? Does Node 18 have a bigger memory size?

jcubic commented 1 year ago

It doesn't work. I've found this StackOverflow question it seems that this option is no longer available in Node Change in max-old-space-size between nodejs 16 and nodejs 14?

jcubic commented 1 year ago

I've run this code:

export NODE_OPTIONS='--max-old-space-size=8192 --max-semi-space-size=4096'

(found that other variable in Node source code) but it doesn't work.

To be sure that the NODE_OPTIONS are passed from Makefile I've added

console.log(process.env['NODE_OPTIONS']);

To my script and I've got the value.

jcubic commented 1 year ago

Another issue is the tests are really slow, I have fdescribe to run only test related to changes, it should run really fast but it takes 4 minutes, longer than all the tests combined.

preveen-stack commented 1 year ago

Can you test on another system and see

On Fri, 16 Jun, 2023, 3:24 pm Jakub T. Jankiewicz, @.***> wrote:

Another issue is the tests are really slow, I have fdescribe to run only test related to changes, it should run really fast but it takes 4 minutes, longer than all the tests combined.

— Reply to this email directly, view it on GitHub https://github.com/nodejs/help/issues/4178#issuecomment-1594424984, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHQB3TZGMGQBW7NGWXZ35SLXLQUNBANCNFSM6AAAAAAY6PA2HQ . You are receiving this because you were mentioned.Message ID: @.***>

jcubic commented 1 year ago

I can test in CI/CD in the GitHub action

jcubic commented 1 year ago

GitHub action throw same error after adding option to increase the memory:

https://github.com/jcubic/jquery.terminal/actions/runs/5290584143/jobs/9574926459

But in the article that was linked in the article you've posted:

Node.js — Increase the Memory Limit for Your Process

The problem was:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

My error is different.

preveen-stack commented 1 year ago

Guess this code is from where the error is getting triggered, though exactly I am not able to pin point

https://github.com/nodejs/node/blob/43d167a262d0772a73ec1e21316e722bad71e4f8/deps/v8/src/runtime/runtime-array.cc#L166-L200

jcubic commented 1 year ago

When this code is executed in JavaScript? array::push()? Or something else?

preveen-stack commented 1 year ago

https://github.com/nodejs/node/issues/47928 https://bugs.chromium.org/p/chromium/issues/detail?id=1201626

jcubic commented 1 year ago

These are completely different scenarios I don't do such things as create an array in a loop or change the length of the array. Also in my case when I did manual tests in Chrome the animation works fine, only unit tests are failing.

Unfortunately, I can't create the issue (in the NodeJS repo) because I don't have a way to reproduce it, there is way too much code.

Muhangi2 commented 1 year ago

I moved "react-scripts": "5.0.1" from dependencies to devDependencies in package.json , this saved me.

jcubic commented 1 year ago

@Muhangi2 I don't use React in this project

ovflowd commented 1 year ago

I doubt the error is in those lines. Could you share a gist with more of the code?

I've found a few StackOverflow's https://stackoverflow.com/questions/71541488/why-its-giving-me-this-error-fatal-error-in-line-0-fatal-javascript-invali

jcubic commented 1 year ago

@ovflowd Sorry I can't create simple reproduction of the issue it would take me years to debug my code and extract what is the root cause. But you can see the regular expression that is causing the issue in my code. I have no idea why the regex is causing an issue. Running this regex is isolation work fine:

https://github.com/nodejs/node/issues/48546

preveen-stack commented 1 year ago

cc @nodejs/v8 PTAL

yanickrochon commented 8 months ago

For me, it was a cyclical dependency between two workspace projects (using pnpm); fixing the dependencies solved my issue.

andiamvinay commented 5 months ago

I ran into the same issue today. My production service was stopped all of a sudden with this error.

May 03 11:16:28 node2 bash[224655]: # May 03 11:16:28 node2 bash[224655]: # Fatal error in , line 0 May 03 11:16:28 node2 bash[224655]: # Fatal JavaScript invalid size error 169220804 (see crbug.com/1201626) May 03 11:16:28 node2 bash[224655]: # May 03 11:16:28 node2 bash[224655]: # May 03 11:16:28 node2 bash[224655]: # May 03 11:16:28 node2 bash[224655]: #FailureMessage Object: 0x7fff1a9b59a0 May 03 11:16:28 node2 bash[224655]: ----- Native stack trace ----- May 03 11:16:29 node2 bash[224655]: 1: 0xd491b1 [node] May 03 11:16:29 node2 bash[224655]: 2: 0x2169281 V8_Fatal(char const, ...) [node] May 03 11:16:29 node2 bash[224655]: 3: 0x10cda98 [node] May 03 11:16:29 node2 bash[224655]: 4: 0x12ac77f [node] May 03 11:16:29 node2 bash[224655]: 5: 0x12ac907 [node] May 03 11:16:29 node2 bash[224655]: 6: 0x1526286 v8::internal::Runtime_GrowArrayElements(int, unsigned long, v8::internal::Isolate*) [node] May 03 11:16:29 node2 bash[224655]: 7: 0x1971ef6 [node] May 03 11:16:29 node2 bash[224647]: Trace/breakpoint trap