From b37e7b41ae4f085422eb60c152a90b655c403a37 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sat, 2 Jul 2011 03:54:53 +0000
Subject: [PATCH] Reverse Deuce's rev 1.86 change to create a separate contex
 for each JS module executed via exec_bin() - this had the side-effect of
 causing background loaded threads to terminate when the script terminated
 (rather than when the node context was destroyed) and also caused the node
 context to be unused (for mcmlxxix).

---
 src/sbbs3/exec.cpp | 27 +++------------------------
 1 file changed, 3 insertions(+), 24 deletions(-)

diff --git a/src/sbbs3/exec.cpp b/src/sbbs3/exec.cpp
index d6d03be58e..f8318762e4 100644
--- a/src/sbbs3/exec.cpp
+++ b/src/sbbs3/exec.cpp
@@ -575,7 +575,6 @@ static const char* js_ext(const char* fname)
 
 long sbbs_t::js_execfile(const char *cmd, const char* startup_dir)
 {
-	ulong		stack_frame;
 	char*		p;
 	char*		args=NULL;
 	char*		fname;
@@ -586,21 +585,11 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir)
 	JSScript*	js_script=NULL;
 	jsval		rval;
 	int32		result=0;
-	JSRuntime	*old_runtime=js_runtime;
-	JSContext	*old_context=js_cx;
-	JSObject	*old_glob=js_glob;
-	js_branch_t	old_branch;
-
-	memcpy(&old_branch, &js_branch, sizeof(old_branch));
-
-	js_init(&stack_frame);
-	js_create_user_objects();
 
 	if(js_cx==NULL) {
 		errormsg(WHERE,ERR_CHK,"JavaScript support",0);
 		errormsg(WHERE,ERR_EXEC,cmd,0);
-		result=-1;
-		goto reset_js;
+		return -1;
 	}
 
 	SAFECOPY(cmdline,cmd);
@@ -625,8 +614,7 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir)
 
 	if(!fexistcase(path)) {
 		errormsg(WHERE,ERR_OPEN,path,O_RDONLY);
-		result=-1;
-		goto reset_js;
+		return -1;
 	}
 
 	JS_BEGINREQUEST(js_cx);
@@ -670,8 +658,7 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir)
 		JS_ReportPendingException(js_cx);	/* Added Feb-2-2006, rswindell */
 		JS_ENDREQUEST(js_cx);
 		errormsg(WHERE,"compiling",path,0);
-		result=-1;
-		goto reset_js;
+		return -1;
 	}
 
 	js_branch.counter=0;	// Reset loop counter
@@ -701,14 +688,6 @@ long sbbs_t::js_execfile(const char *cmd, const char* startup_dir)
 
 	JS_ENDREQUEST(js_cx);
 
-reset_js:
-	js_cleanup(client_name);
-	js_runtime=old_runtime;
-	js_cx=old_context;
-	js_glob=old_glob;
-
-	memcpy(&js_branch, &old_branch, sizeof(old_branch));
-
 	return(result);
 }
 #endif
-- 
GitLab