While you haven't posted the stack trace, I'm pretty sure it's not V8 that's crashing, but your code, specifically:
v8::Local<v8::Value> v = (...).ToLocalChecked(); > if (v.IsEmpty()) { A v8::Local is never empty (unless it's uninitialized). The v8::MaybeLocal that you get back from script->Run() can be empty (hence its name), but by calling .ToLocalChecked you're saying "I know this can't be empty, please crash if it is". So the fix is to perform the isEmpty check on the MaybeLocal, e.g. by using a (non-"Checked") ToLocal conversion, and handle the exception when that fails. On Wed, Jul 17, 2019 at 2:23 PM Tsvetan Stefanovski < tsvetan.stefanov...@gmail.com> wrote: > Hello, > > Why could V8 be crashing trying to run a script containing errors? Below > is how I run the compilation and the script itself > > *// const char* src comes as argument * > *v8::Isolate* isolate = v8::Isolate::GetCurrent();* > *v8::HandleScope hScope(isolate);* > > *v8::Local<v8::Context> context = context_.Get(isolate);* > *v8::Context::Scope ctxScope(context);* > > *v8::Local<v8::String> source = v8::String::NewFromUtf8(isolate, src);* > *v8::Local<v8::Script> script = > v8::Script::Compile(isolate->GetCurrentContext(), source).ToLocalChecked();* > *v8::TryCatch trycatch(isolate);* > *v8::Local<v8::Value> v = > script->Run(isolate->GetCurrentContext()).ToLocalChecked();* > *if (v.IsEmpty()) {* > * v8::Local<v8::Value> exception = trycatch.Exception();* > * v8::String::Utf8Value exceptionStr(isolate, exception);* > *}* > > Javascript: > > *log("first line");* > *log("second line");* > *var a = 2;* > *var b = 5;* > *var c = a + b;* > *log("" + c); // My C++ callback assumes arguments is String :-) * > *var d = new Something(); // crash here* > > I've also tried with these start-up options: > *--stack-size=4096 --abort_on_uncaught_exception=false --hard-abort=false* > > This is the crash code: > > *2019-07-17 15:19:51.919 23748-23748/?: Instance.cpp:16: Log callback: > first line 2019-07-17 15:19:51.919 23748-23748/?: Instance.cpp:16: Log > callback: second line 2019-07-17 15:19:51.919 23748-23748/?: > Instance.cpp:16: Log callback: 7* > *2019-07-17 15:19:51.988 23785-23785/? A/DEBUG: signal 5 (SIGTRAP), code 1 > (TRAP_BRKPT), fault addr 0x7f2da5f4ac 2019-07-17 15:19:51.988 23785-23785/? > A/DEBUG: x0 000000000000003e x1 0000000000000000 x2 3a64889416988361 x3 > 0000000000000001 2019-07-17 15:19:51.988 23785-23785/? A/DEBUG: x4 > 0000007f2e082ea3 x5 0000007fda9767ce x6 0000000000000008 x7 > 000000000a0a230a 2019-07-17 15:19:51.988 23785-23785/? A/DEBUG: x8 > 0000000000000001 x9 3a64889416988361 x10 3a64889416988361 x11 > 0000007f4f206a48 2019-07-17 15:19:51.988 23785-23785/? A/DEBUG: x12 > 0000000000000000 x13 2e6c61636f4c6562 x14 0000007f4f206a48 x15 > 0000000000005cc4 2019-07-17 15:19:51.988 23785-23785/? A/DEBUG: x16 > 0000007f2e6a2000 x17 0000007f2da5f494 x18 0000000000000000 x19 > 0000007f2e08316c 2019-07-17 15:19:51.988 23785-23785/? A/DEBUG: x20 > 0000007f2e083159 x21 0000007f392e7840 x22 0000007fda977f2c x23 > 0000007f4af7fd75 2019-07-17 15:19:51.988 23785-23785/? A/DEBUG: x24 > 000000000000000c x25 0000007f49ea7aa0 x26 0000000000000000 x27 > 0000000000000000 2019-07-17 15:19:51.988 23785-23785/? A/DEBUG: x28 > 0000007fda977c70 x29 0000007fda976ea0 x30 0000007f2cd066c8 2019-07-17 > 15:19:51.988 23785-23785/? A/DEBUG: sp 0000007fda976e80 pc 0000007f2da5f4ac > pstate 0000000060000000* > > The backtrace's last two entries are my function which calls the script > execution followed by v8::base::Abort() > If I remove the last line from the javascript, everything works fine. > > -- > -- > v8-users mailing list > v8-users@googlegroups.com > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to the Google Groups > "v8-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to v8-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/v8-users/413223cf-e528-482d-bd40-0f5c468608ca%40googlegroups.com > <https://groups.google.com/d/msgid/v8-users/413223cf-e528-482d-bd40-0f5c468608ca%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/CAKSzg3TBSQTQ82DLnHS%2BqmvCckbc4EkOn1OCMC1wyZfJcMODzg%40mail.gmail.com.