Skip to content

Commit

Permalink
implement an optimized version of Context#close()
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Apr 27, 2024
1 parent 96d18d4 commit 3c1602e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/org/mozilla/javascript/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ public static void exit() {

@Override
public void close() {
exit();
if (enterCount < 1) Kit.codeBug();
if (--enterCount == 0) {
Object helper = VMBridge.instance.getThreadContextHelper();
VMBridge.instance.setContext(helper, null);
factory.onContextReleased(this);
}
}

/**
Expand Down Expand Up @@ -539,11 +544,8 @@ public static Object call(

/** The method implements {@link ContextFactory#call(ContextAction)} logic. */
static <T> T call(ContextFactory factory, ContextAction<T> action) {
Context cx = enter(null, factory);
try {
try (Context cx = enter(null, factory)) {
return action.run(cx);
} finally {
exit();
}
}

Expand Down

0 comments on commit 3c1602e

Please sign in to comment.