Skip to content

Commit

Permalink
🐛 Close polyglot Context objects
Browse files Browse the repository at this point in the history
  • Loading branch information
ujibang committed Sep 27, 2024
1 parent 4779b8a commit 930cb41
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static void addBindings(Context ctx,

/**
*
* @return the Context associated with this thread. If not existing, it instanitates it.
* @return the Context
*/
protected Context ctx() {
var ret = context(engine, contextOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,14 @@ export function handle(request, response) {
*/
@Override
public void handle(StringRequest request, StringResponse response) {
ctx().eval(this.handleSource).executeVoid(request, response);
try (final var ctx = ctx()) {
ctx.eval(this.handleSource).executeVoid(request, response);
}
}

/**
*
* @return the Context associated with this thread. If not existing, it instanitates it.
* @return the Context
*/
@Override
protected Context ctx() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ public class AbstractJSInterceptor<R extends Request<?>, S extends Response<?>>
* @param pluginClass
* @param description
* @param interceptPoint
* @param handleSource
* @param mclient
* @param modulesReplacements
* @param resolveSource
* @param contextOptions
* @param config
*/
public AbstractJSInterceptor(String name,
String pluginClass,
Expand All @@ -73,7 +76,9 @@ public AbstractJSInterceptor(String name,
* @param response */
@Override
public void handle(R request, S response) {
ctx().eval(this.handleSource).executeVoid(request, response);
try (final var ctx = ctx()) {
ctx.eval(this.handleSource).executeVoid(request, response);
}
}

@Override
Expand Down

0 comments on commit 930cb41

Please sign in to comment.