Skip to content

Commit

Permalink
rake format with prettier 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Aug 1, 2023
1 parent c2a62ac commit d0e1445
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion packages/npm-packages/ruby-wasm-wasi/example/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DefaultRubyVM } from "ruby-head-wasm-wasi/dist/node.cjs.js";

const main = async () => {
const binary = await fs.readFile(
"./node_modules/ruby-head-wasm-wasi/dist/ruby.wasm"
"./node_modules/ruby-head-wasm-wasi/dist/ruby.wasm",
);
const module = await WebAssembly.compile(binary);
const { vm } = await DefaultRubyVM(module);
Expand Down
10 changes: 5 additions & 5 deletions packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DefaultRubyVM } from "./browser";

export const main = async (pkg: { name: string; version: string }) => {
const response = await fetch(
`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`
`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`,
);
const buffer = await response.arrayBuffer();
const module = await WebAssembly.compile(buffer);
Expand All @@ -17,7 +17,7 @@ export const main = async (pkg: { name: string; version: string }) => {
// and DOMContentLoaded has already been fired.
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", () =>
runRubyScriptsInHtml(vm)
runRubyScriptsInHtml(vm),
);
} else {
runRubyScriptsInHtml(vm);
Expand All @@ -29,7 +29,7 @@ const runRubyScriptsInHtml = async (vm) => {

// Get Ruby scripts in parallel.
const promisingRubyScripts = Array.from(tags).map((tag) =>
loadScriptAsync(tag)
loadScriptAsync(tag),
);

// Run Ruby scripts sequentially.
Expand All @@ -52,15 +52,15 @@ const deriveEvalStyle = (tag: Element): "async" | "sync" => {
const rawEvalStyle = tag.getAttribute("data-eval") || "sync";
if (rawEvalStyle !== "async" && rawEvalStyle !== "sync") {
console.warn(
`data-eval attribute of script tag must be "async" or "sync". ${rawEvalStyle} is ignored and "sync" is used instead.`
`data-eval attribute of script tag must be "async" or "sync". ${rawEvalStyle} is ignored and "sync" is used instead.`,
);
return "sync";
}
return rawEvalStyle;
};

const loadScriptAsync = async (
tag: Element
tag: Element,
): Promise<{ scriptContent: string; evalStyle: "async" | "sync" } | null> => {
const evalStyle = deriveEvalStyle(tag);
// Inline comments can be written with the src attribute of the script tag.
Expand Down
6 changes: 3 additions & 3 deletions packages/npm-packages/ruby-wasm-wasi/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const consolePrinter = () => {
fd: number,
iovs: number,
iovsLen: number,
nwritten: number
nwritten: number,
) => number;
imports.wasi_snapshot_preview1.fd_write = (
fd: number,
iovs: number,
iovsLen: number,
nwritten: number
nwritten: number,
): number => {
if (fd !== 1 && fd !== 2) {
return original(fd, iovs, iovsLen, nwritten);
Expand Down Expand Up @@ -62,7 +62,7 @@ const consolePrinter = () => {

export const DefaultRubyVM = async (
rubyModule: WebAssembly.Module,
options: { consolePrint: boolean } = { consolePrint: true }
options: { consolePrint: boolean } = { consolePrint: true },
): Promise<{
vm: RubyVM;
wasi: WASI;
Expand Down
38 changes: 19 additions & 19 deletions packages/npm-packages/ruby-wasm-wasi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class RubyVM {
const excluded = ["constructor"].concat(excludedMethods);
// wrap all methods in RbAbi.RbAbiGuest class
for (const key of Object.getOwnPropertyNames(
RbAbi.RbAbiGuest.prototype
RbAbi.RbAbiGuest.prototype,
)) {
if (excluded.includes(key)) {
continue;
Expand Down Expand Up @@ -86,7 +86,7 @@ export class RubyVM {
* an array of strings starting with the Ruby program name.
*/
initialize(
args: string[] = ["ruby.wasm", "--disable-gems", "-EUTF-8", "-e_=0"]
args: string[] = ["ruby.wasm", "--disable-gems", "-EUTF-8", "-e_=0"],
) {
const c_args = args.map((arg) => arg + "\0");
this.guest.rubyInit();
Expand Down Expand Up @@ -132,11 +132,11 @@ export class RubyVM {
imports["rb-js-abi-host"] = {
rb_wasm_throw_prohibit_rewind_exception: (
messagePtr: number,
messageLen: number
messageLen: number,
) => {
const memory = this.instance.exports.memory as WebAssembly.Memory;
const str = new TextDecoder().decode(
new Uint8Array(memory.buffer, messagePtr, messageLen)
new Uint8Array(memory.buffer, messagePtr, messageLen),
);
throw new RbFatalError(
"Ruby APIs that may rewind the VM stack are prohibited under nested VM operation " +
Expand All @@ -149,7 +149,7 @@ export class RubyVM {
" Note that `evalAsync` JS API switches fibers internally\n" +
" 2. Raising uncaught exceptions\n" +
" Please catch all exceptions inside the nested operation\n" +
" 3. Calling Continuation APIs\n"
" 3. Calling Continuation APIs\n",
);
},
};
Expand Down Expand Up @@ -268,7 +268,7 @@ export class RubyVM {
}),
reflectGetOwnPropertyDescriptor: function (
target,
propertyKey: string
propertyKey: string,
) {
throw new Error("Function not implemented.");
},
Expand Down Expand Up @@ -296,7 +296,7 @@ export class RubyVM {
}),
(name) => {
return this.instance.exports[name];
}
},
);
}

Expand Down Expand Up @@ -350,12 +350,12 @@ export class RubyVM {
this.exceptionFormatter.format(
error,
this,
this.privateObject()
)
)
this.privateObject(),
),
),
);
},
})
}),
);
});
}
Expand Down Expand Up @@ -445,7 +445,7 @@ export class RbValue {
constructor(
private inner: RbAbi.RbAbiValue,
private vm: RubyVM,
private privateObject: RubyVMPrivate
private privateObject: RubyVMPrivate,
) {}

/**
Expand All @@ -465,7 +465,7 @@ export class RbValue {
return new RbValue(
callRbMethod(this.vm, this.privateObject, this.inner, callee, innerArgs),
this.vm,
this.privateObject
this.privateObject,
);
}

Expand All @@ -491,7 +491,7 @@ export class RbValue {
this.privateObject,
this.inner,
"to_s",
[]
[],
);
return this.vm.guest.rstringPtr(rbString);
}
Expand Down Expand Up @@ -552,7 +552,7 @@ class RbExceptionFormatter {
if (backtrace.call("nil?").toString() === "true") {
return this.formatString(
error.call("class").toString(),
error.toString()
error.toString(),
);
}
const firstLine = backtrace.call("at", zeroLiteral);
Expand All @@ -568,7 +568,7 @@ class RbExceptionFormatter {
formatString(
klass: string,
message: string,
backtrace?: [string, string]
backtrace?: [string, string],
): string {
if (backtrace) {
return `${backtrace[0]}: ${message} (${klass})\n${backtrace[1]}`;
Expand All @@ -581,7 +581,7 @@ class RbExceptionFormatter {
const checkStatusTag = (
rawTag: number,
vm: RubyVM,
privateObject: RubyVMPrivate
privateObject: RubyVMPrivate,
) => {
switch (rawTag & ruby_tag_type.Mask) {
case ruby_tag_type.None:
Expand All @@ -607,7 +607,7 @@ const checkStatusTag = (
// clear errinfo if got exception due to no rb_jump_tag
vm.guest.rbClearErrinfo();
throw new RbError(
privateObject.exceptionFormatter.format(error, vm, privateObject)
privateObject.exceptionFormatter.format(error, vm, privateObject),
);
default:
throw new RbError(`unknown error tag: ${rawTag}`);
Expand Down Expand Up @@ -639,7 +639,7 @@ const callRbMethod = (
privateObject: RubyVMPrivate,
recv: RbAbi.RbAbiValue,
callee: string,
args: RbAbi.RbAbiValue[]
args: RbAbi.RbAbiValue[],
) => {
const mid = vm.guest.rbIntern(callee + "\0");
return wrapRbOperation(vm, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ test.beforeEach(async ({ context }) => {
const response = await new Promise<http.IncomingMessage>(
(resolve, reject) => {
https.get(url, resolve).on("error", reject);
}
},
);
if (response.statusCode == 404) {
console.log(
`ruby-head-wasm-wasi@${version} is not published yet, so skipping CDN tests`
`ruby-head-wasm-wasi@${version} is not published yet, so skipping CDN tests`,
);
test.skip();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (!process.env.RUBY_NPM_PACKAGE_ROOT) {
`);
const error = await page.waitForEvent("pageerror");
expect(error.message).toMatch(
/please ensure that you specify `data-eval="async"`/
/please ensure that you specify `data-eval="async"`/,
);
});

Expand Down
4 changes: 2 additions & 2 deletions packages/npm-packages/ruby-wasm-wasi/test-e2e/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export const waitForRubyVM = async (page: Page) => {
export const setupDebugLog = (context: BrowserContext) => {
if (process.env.DEBUG) {
context.on("request", (request) =>
console.log(">>", request.method(), request.url())
console.log(">>", request.method(), request.url()),
);
context.on("response", (response) =>
console.log("<<", response.status(), response.url())
console.log("<<", response.status(), response.url()),
);
context.on("console", (msg) => console.log("LOG:", msg.text()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("Async Ruby code evaluation", () => {
expect(() => {
vm.eval(`require "js"; JS.global[:Promise].resolve(42).await`);
}).toThrowError(
"JS::Object#await can be called only from RubyVM#evalAsync JS API"
"JS::Object#await can be called only from RubyVM#evalAsync JS API",
);
});
});
2 changes: 1 addition & 1 deletion packages/npm-packages/ruby-wasm-wasi/test/gc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("GC integration", () => {
mark_js_object_live: (object: RbValue) => {
livingObjects.add(object);
},
})
}),
);
vm.eval("GC.start");
for (const object of livingObjects) {
Expand Down
4 changes: 2 additions & 2 deletions packages/npm-packages/ruby-wasm-wasi/test/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const rubyModule = (async () => {
} else if (process.env.RUBY_NPM_PACKAGE_ROOT) {
binaryPath = path.join(
process.env.RUBY_NPM_PACKAGE_ROOT,
"./dist/ruby.debug+stdlib.wasm"
"./dist/ruby.debug+stdlib.wasm",
);
} else {
throw new Error("RUBY_ROOT or RUBY_NPM_PACKAGE_ROOT must be set");
Expand All @@ -20,7 +20,7 @@ const rubyModule = (async () => {
})();

export const initRubyVM = async (
{ suppressStderr } = { suppressStderr: false }
{ suppressStderr } = { suppressStderr: false },
) => {
let preopens = {};
if (process.env.RUBY_ROOT) {
Expand Down
2 changes: 1 addition & 1 deletion packages/npm-packages/ruby-wasm-wasi/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("Packaging validation", () => {
return moduleCache.get(file)!;
}
const binary = await fs.readFile(
path.join(process.env.RUBY_NPM_PACKAGE_ROOT, `./dist/${file}`)
path.join(process.env.RUBY_NPM_PACKAGE_ROOT, `./dist/${file}`),
);
const mod = await WebAssembly.compile(binary.buffer);
moduleCache.set(file, mod);
Expand Down
10 changes: 5 additions & 5 deletions packages/npm-packages/ruby-wasm-wasi/test/vm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ describe("RubyVM", () => {
`);
expect(X.call("identical", vm.eval("1")).toString()).toEqual("1");
expect(X.call("take_two", vm.eval("1"), vm.eval("1")).toString()).toEqual(
"2"
"2",
);
expect(
X.call("take_two", vm.eval(`"x"`), vm.eval(`"y"`)).toString()
X.call("take_two", vm.eval(`"x"`), vm.eval(`"y"`)).toString(),
).toEqual("xy");
});

Expand Down Expand Up @@ -170,9 +170,9 @@ eval:11:in \`<main>'`);
spy.mockReset();

expect(rejections[0].message).toMatch(
"Ruby APIs that may rewind the VM stack are prohibited"
"Ruby APIs that may rewind the VM stack are prohibited",
);
}
},
);

test("caught raise in nested eval is ok", async () => {
Expand All @@ -181,7 +181,7 @@ eval:11:in \`<main>'`);
setVM.call("call", vm.wrap(vm));
expect(() => {
vm.eval(
`JS::RubyVM.eval("begin; raise 'Exception from nested eval'; rescue; end")`
`JS::RubyVM.eval("begin; raise 'Exception from nested eval'; rescue; end")`,
);
}).not.toThrowError();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const shimContent = (target, pkg) => {
const dirname = path.dirname(new URL(import.meta.url).pathname);
const content = fs.readFileSync(
path.join(dirname, "..", "dist", target),
"utf-8"
"utf-8",
);
if (suffix === "d.ts") {
return content;
Expand Down

0 comments on commit d0e1445

Please sign in to comment.