@@ -277,7 +277,8 @@ hjs_script_getproperty (JSContext* context, string property, string fallback)
277277 char * cstr;
278278 string str;
279279
280- if (JS_HasProperty (context, globals, property.c_str (), &found))
280+ if (context != nullptr
281+ && JS_HasProperty (context, globals, property.c_str (), &found))
281282 {
282283 if (found)
283284 {
@@ -1427,23 +1428,25 @@ js_init (JSContext **cx, JSRuntime **rt, JSObject **globals, bool fake)
14271428static void
14281429js_deinit (JSContext *cx, JSRuntime *rt)
14291430{
1430- JS_DestroyContext (cx);
1431- JS_DestroyRuntime (rt);
1431+ if (cx != nullptr )
1432+ JS_DestroyContext (cx);
1433+ if (rt != nullptr )
1434+ JS_DestroyRuntime (rt);
14321435}
14331436
14341437js_script::js_script (string file, string src)
14351438{
1436- JSObject* fake_globals;
1437- JSContext* fake_context;
1438- JSRuntime* fake_runtime;
1439+ JSObject* fake_globals = nullptr ;
1440+ JSContext* fake_context = nullptr ;
1441+ JSRuntime* fake_runtime = nullptr ;
14391442
14401443 js_script_list.push_back (this );
14411444
14421445 filename = file;
14431446
14441447 // create a fake runtime to get the scripts name without actually running it, is there an easier way?
1445- js_init (&fake_context, &fake_runtime, &fake_globals, true );
1446- JS_EvaluateScript (fake_context, fake_globals, src.c_str (), src.length (), file.c_str (), 0 , nullptr );
1448+ if ( js_init (&fake_context, &fake_runtime, &fake_globals, true ))
1449+ JS_EvaluateScript (fake_context, fake_globals, src.c_str (), src.length (), file.c_str (), 0 , nullptr );
14471450
14481451 name = hjs_script_getproperty (fake_context, " SCRIPT_NAME" , hjs_util_shrinkfile (file));
14491452 desc = hjs_script_getproperty (fake_context, " SCRIPT_DESC" , file);
@@ -1453,8 +1456,10 @@ js_script::js_script (string file, string src)
14531456 js_deinit (fake_context, fake_runtime);
14541457
14551458 // now the real thing..
1456- js_init (&context, &runtime, &globals, false );
1457- JS_EvaluateScript (context, globals, src.c_str (), src.length (), file.c_str (), 0 , nullptr );
1459+ if (js_init (&context, &runtime, &globals, false ))
1460+ JS_EvaluateScript (context, globals, src.c_str (), src.length (), file.c_str (), 0 , nullptr );
1461+ else
1462+ hexchat_printf (ph, " \003 20JavaScript Error:\017 : Failed to initialize %s" , name.c_str ());
14581463}
14591464
14601465void
0 commit comments