summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGudmund Vatn <gudmund.vatn@gmail.com>2020-04-17 12:51:10 +0200
committerGitHub <noreply@github.com>2020-04-17 12:51:10 +0200
commit260084ccbf053485d00d5b6ebc804252c409be49 (patch)
tree472ef5342b0cd1fa749d35430bdb4917b3f5d793
parent5bfe3eb8f49f5d6eed2e6d4436b8c75dd4b4ad26 (diff)
Add close method to Plugin (#4670) (#4785)
-rw-r--r--cli/js/plugins.ts10
-rw-r--r--test_plugin/tests/test.js19
2 files changed, 26 insertions, 3 deletions
diff --git a/cli/js/plugins.ts b/cli/js/plugins.ts
index 3fe0574ca..498da8e16 100644
--- a/cli/js/plugins.ts
+++ b/cli/js/plugins.ts
@@ -1,5 +1,6 @@
import { openPlugin as openPluginOp } from "./ops/plugins.ts";
import { core } from "./core.ts";
+import { close } from "./ops/resources.ts";
export interface AsyncHandler {
(msg: Uint8Array): void;
@@ -32,18 +33,17 @@ class PluginOpImpl implements PluginOp {
}
}
-// TODO(afinch7): add close method.
-
interface Plugin {
ops: {
[name: string]: PluginOp;
};
+ close(): void;
}
class PluginImpl implements Plugin {
#ops: { [name: string]: PluginOp } = {};
- constructor(_rid: number, ops: { [name: string]: number }) {
+ constructor(readonly rid: number, ops: { [name: string]: number }) {
for (const op in ops) {
this.#ops[op] = new PluginOpImpl(ops[op]);
}
@@ -52,6 +52,10 @@ class PluginImpl implements Plugin {
get ops(): { [name: string]: PluginOp } {
return Object.assign({}, this.#ops);
}
+
+ close(): void {
+ close(this.rid);
+ }
}
export function openPlugin(filename: string): Plugin {
diff --git a/test_plugin/tests/test.js b/test_plugin/tests/test.js
index d6d531f14..d34624f09 100644
--- a/test_plugin/tests/test.js
+++ b/test_plugin/tests/test.js
@@ -13,6 +13,10 @@ if (Deno.build.os === "mac") {
const filename = `../target/${Deno.args[0]}/${filenamePrefix}${filenameBase}${filenameSuffix}`;
+// This will be checked against open resources after Plugin.close()
+// in runTestClose() below.
+const resourcesPre = Deno.resources();
+
const plugin = Deno.openPlugin(filename);
const { testSync, testAsync } = plugin.ops;
@@ -60,7 +64,22 @@ function runTestOpCount() {
}
}
+function runTestPluginClose() {
+ plugin.close();
+
+ const resourcesPost = Deno.resources();
+
+ const preStr = JSON.stringify(resourcesPre, null, 2);
+ const postStr = JSON.stringify(resourcesPost, null, 2);
+ if (preStr !== postStr) {
+ throw new Error(`Difference in open resources before openPlugin and after Plugin.close():
+Before: ${preStr}
+After: ${postStr}`);
+ }
+}
+
runTestSync();
runTestAsync();
runTestOpCount();
+runTestPluginClose();