Skip to content

Commit 1ecbbdf

Browse files
committed
Use private variables in Application. NFC
As far as I recall these were always intended to be private, but I was not aware of how widespread support for private variables was. (In any case, this package is intended to always used with a bundler, so this isn't a breaking change even if the fields were read.)
1 parent aaa8362 commit 1ecbbdf

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

lib/api.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,41 @@ function fetchResources({ modules, filesystem }) {
4747
}
4848

4949
export class Application {
50+
#resources;
51+
#resourceData;
52+
#instantiate;
53+
#argv0;
54+
5055
constructor(resources, instantiate, argv0) {
51-
this.resources = resources;
52-
this.resourceData = null;
53-
this.instantiate = instantiate;
54-
this.argv0 = argv0;
56+
this.#resources = resources;
57+
this.#resourceData = null;
58+
this.#instantiate = instantiate;
59+
this.#argv0 = argv0;
5560
}
5661

5762
// The `printLine` option is deprecated and not documented but still accepted for compatibility.
5863
run(args = null, files = {}, options = {}) {
59-
if (this.resourceData === null) {
64+
if (this.#resourceData === null) {
6065
if (options.synchronously)
6166
throw new Error("Cannot run application synchronously unless resources are " +
6267
"prefetched first; use `await run()` to do so");
6368

64-
return this.resources().then(fetchResources).then((resourceData) => {
65-
this.resourceData = resourceData;
66-
return this.run(args, files, options);
67-
});
69+
return this.#resources()
70+
.then((resourceObject) => fetchResources(resourceObject))
71+
.then((resourceData) => {
72+
this.#resourceData = resourceData;
73+
return this.run(args, files, options);
74+
});
6875
}
6976

7077
if (args === null)
7178
return; // prefetch resources, but do not actually run
7279

7380
// meow. :3
7481
const environment = new Environment();
75-
environment.args = [this.argv0].concat(args);
82+
environment.args = [this.#argv0].concat(args);
7683
environment.root = directoryFromTree(files);
77-
for (const [dirName, dirContents] of Object.entries(this.resourceData.filesystem))
84+
for (const [dirName, dirContents] of Object.entries(this.#resourceData.filesystem))
7885
environment.root.files[dirName] = directoryFromTree(dirContents);
7986
const lineBufferedConsole = lineBuffered(options.printLine ?? console.log);
8087
environment.stdin = options.stdin === undefined ? null : options.stdin;
@@ -92,7 +99,7 @@ export class Application {
9299
error = e;
93100
}
94101

95-
for (const dirName of Object.keys(this.resourceData.filesystem))
102+
for (const dirName of Object.keys(this.#resourceData.filesystem))
96103
delete environment.root.files[dirName];
97104
files = directoryIntoTree(environment.root, { decodeASCII: options.decodeASCII ?? true });
98105
if (error !== null) {
@@ -103,13 +110,13 @@ export class Application {
103110
}
104111
};
105112

106-
const getCoreModule = (filename) => this.resourceData.modules[filename];
113+
const getCoreModule = (filename) => this.#resourceData.modules[filename];
107114
const imports = { runtime: environment.exports };
108115
if (options.synchronously) {
109116
const instantiateCore = (module, imports) => new WebAssembly.Instance(module, imports);
110-
return runCommand(this.instantiate(getCoreModule, imports, instantiateCore));
117+
return runCommand(this.#instantiate(getCoreModule, imports, instantiateCore));
111118
} else {
112-
return this.instantiate(getCoreModule, imports).then(runCommand);
119+
return this.#instantiate(getCoreModule, imports).then(runCommand);
113120
}
114121
}
115122
}

0 commit comments

Comments
 (0)