mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +00:00
parent
5bfe3eb8f4
commit
260084ccbf
2 changed files with 26 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { openPlugin as openPluginOp } from "./ops/plugins.ts";
|
import { openPlugin as openPluginOp } from "./ops/plugins.ts";
|
||||||
import { core } from "./core.ts";
|
import { core } from "./core.ts";
|
||||||
|
import { close } from "./ops/resources.ts";
|
||||||
|
|
||||||
export interface AsyncHandler {
|
export interface AsyncHandler {
|
||||||
(msg: Uint8Array): void;
|
(msg: Uint8Array): void;
|
||||||
|
@ -32,18 +33,17 @@ class PluginOpImpl implements PluginOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(afinch7): add close method.
|
|
||||||
|
|
||||||
interface Plugin {
|
interface Plugin {
|
||||||
ops: {
|
ops: {
|
||||||
[name: string]: PluginOp;
|
[name: string]: PluginOp;
|
||||||
};
|
};
|
||||||
|
close(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PluginImpl implements Plugin {
|
class PluginImpl implements Plugin {
|
||||||
#ops: { [name: string]: PluginOp } = {};
|
#ops: { [name: string]: PluginOp } = {};
|
||||||
|
|
||||||
constructor(_rid: number, ops: { [name: string]: number }) {
|
constructor(readonly rid: number, ops: { [name: string]: number }) {
|
||||||
for (const op in ops) {
|
for (const op in ops) {
|
||||||
this.#ops[op] = new PluginOpImpl(ops[op]);
|
this.#ops[op] = new PluginOpImpl(ops[op]);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,10 @@ class PluginImpl implements Plugin {
|
||||||
get ops(): { [name: string]: PluginOp } {
|
get ops(): { [name: string]: PluginOp } {
|
||||||
return Object.assign({}, this.#ops);
|
return Object.assign({}, this.#ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(): void {
|
||||||
|
close(this.rid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openPlugin(filename: string): Plugin {
|
export function openPlugin(filename: string): Plugin {
|
||||||
|
|
|
@ -13,6 +13,10 @@ if (Deno.build.os === "mac") {
|
||||||
|
|
||||||
const filename = `../target/${Deno.args[0]}/${filenamePrefix}${filenameBase}${filenameSuffix}`;
|
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 plugin = Deno.openPlugin(filename);
|
||||||
|
|
||||||
const { testSync, testAsync } = plugin.ops;
|
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();
|
runTestSync();
|
||||||
runTestAsync();
|
runTestAsync();
|
||||||
|
|
||||||
runTestOpCount();
|
runTestOpCount();
|
||||||
|
runTestPluginClose();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue