Skip to content

Commit b9feebc

Browse files
Apply missed rake format
1 parent 2e76d4a commit b9feebc

File tree

6 files changed

+76
-70
lines changed

6 files changed

+76
-70
lines changed

ext/js/js-core.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ static VALUE _rb_js_obj_eql(VALUE obj, VALUE other) {
225225
* :nodoc: all
226226
*/
227227
static VALUE _rb_js_obj_hash(VALUE obj) {
228-
// TODO(katei): Track the JS object id in JS side as Pyodide and Swift JavaScriptKit do.
228+
// TODO(katei): Track the JS object id in JS side as Pyodide and Swift
229+
// JavaScriptKit do.
229230
return Qnil;
230231
}
231232

@@ -248,10 +249,11 @@ static VALUE _rb_js_obj_call(int argc, VALUE *argv, VALUE obj) {
248249

249250
rb_js_abi_host_list_js_abi_value_t abi_args;
250251
int function_arguments_count = argc;
251-
if(!rb_block_given_p())
252+
if (!rb_block_given_p())
252253
function_arguments_count -= 1;
253254

254-
abi_args.ptr = ALLOCA_N(rb_js_abi_host_js_abi_value_t, function_arguments_count);
255+
abi_args.ptr =
256+
ALLOCA_N(rb_js_abi_host_js_abi_value_t, function_arguments_count);
255257
abi_args.len = function_arguments_count;
256258
for (int i = 1; i < argc; i++) {
257259
VALUE arg = _rb_js_try_convert(rb_mJS, argv[i]);
@@ -262,9 +264,10 @@ static VALUE _rb_js_obj_call(int argc, VALUE *argv, VALUE obj) {
262264
abi_args.ptr[i - 1] = check_jsvalue(arg)->abi;
263265
}
264266

265-
if(rb_block_given_p()) {
267+
if (rb_block_given_p()) {
266268
VALUE proc = rb_block_proc();
267-
abi_args.ptr[function_arguments_count - 1] = check_jsvalue(_rb_js_try_convert(rb_mJS, proc))->abi;
269+
abi_args.ptr[function_arguments_count - 1] =
270+
check_jsvalue(_rb_js_try_convert(rb_mJS, proc))->abi;
268271
}
269272

270273
return jsvalue_s_new(
@@ -327,7 +330,8 @@ static VALUE _rb_js_import_from_js(VALUE obj) {
327330
*/
328331
static VALUE _rb_js_obj_wrap(VALUE obj, VALUE wrapping) {
329332
rb_abi_lend_object(wrapping);
330-
return jsvalue_s_new(rb_js_abi_host_rb_object_to_js_rb_value((uint32_t)wrapping));
333+
return jsvalue_s_new(
334+
rb_js_abi_host_rb_object_to_js_rb_value((uint32_t)wrapping));
331335
}
332336

333337
/*
@@ -384,7 +388,7 @@ static VALUE _rb_js_false_to_js(VALUE obj) {
384388
*/
385389
static VALUE _rb_js_proc_to_js(VALUE obj) {
386390
rb_abi_lend_object(obj);
387-
return jsvalue_s_new(rb_js_abi_host_proc_to_js_function((uint32_t) obj));
391+
return jsvalue_s_new(rb_js_abi_host_proc_to_js_function((uint32_t)obj));
388392
}
389393

390394
/*
@@ -409,7 +413,8 @@ void Init_js() {
409413
rb_define_method(rb_cJS_Object, "call", _rb_js_obj_call, -1);
410414
rb_define_method(rb_cJS_Object, "typeof", _rb_js_obj_typeof, 0);
411415
rb_define_method(rb_cJS_Object, "__export_to_js", _rb_js_export_to_js, 0);
412-
rb_define_singleton_method(rb_cJS_Object, "__import_from_js", _rb_js_import_from_js, 0);
416+
rb_define_singleton_method(rb_cJS_Object, "__import_from_js",
417+
_rb_js_import_from_js, 0);
413418
rb_define_method(rb_cJS_Object, "inspect", _rb_js_obj_inspect, 0);
414419
rb_define_method(rb_cJS_Object, "to_s", _rb_js_obj_inspect, 0);
415420
rb_define_singleton_method(rb_cJS_Object, "wrap", _rb_js_obj_wrap, 1);

packages/npm-packages/ruby-wasm-wasi/rollup.config.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typescript from "@rollup/plugin-typescript";
22
import { nodeResolve } from "@rollup/plugin-node-resolve";
33

4-
const typescriptOptions = { tsconfig: "./tsconfig.json", declaration: false }
4+
const typescriptOptions = { tsconfig: "./tsconfig.json", declaration: false };
55

66
function variant(basename) {
77
return {
@@ -23,10 +23,7 @@ function variant(basename) {
2323
exports: "named",
2424
},
2525
],
26-
plugins: [
27-
typescript(typescriptOptions),
28-
nodeResolve(),
29-
],
26+
plugins: [typescript(typescriptOptions), nodeResolve()],
3027
};
3128
}
3229

@@ -49,10 +46,7 @@ export default [
4946
exports: "named",
5047
},
5148
],
52-
plugins: [
53-
typescript(typescriptOptions),
54-
nodeResolve(),
55-
],
49+
plugins: [typescript(typescriptOptions), nodeResolve()],
5650
external: ["wasi"],
5751
},
5852
];
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
import { DefaultRubyVM } from "./browser";
22

3-
export const main = async (pkg: { name: string, version: string }) => {
4-
const response = await fetch(
5-
`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`
6-
);
7-
const buffer = await response.arrayBuffer();
8-
const module = await WebAssembly.compile(buffer);
9-
const { vm } = await DefaultRubyVM(module);
3+
export const main = async (pkg: { name: string; version: string }) => {
4+
const response = await fetch(
5+
`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`
6+
);
7+
const buffer = await response.arrayBuffer();
8+
const module = await WebAssembly.compile(buffer);
9+
const { vm } = await DefaultRubyVM(module);
1010

11-
vm.printVersion();
11+
vm.printVersion();
1212

13-
globalThis.rubyVM = vm;
13+
globalThis.rubyVM = vm;
1414

15-
runRubyScriptsInHtml(vm);
15+
runRubyScriptsInHtml(vm);
1616
};
1717

1818
const runRubyScriptsInHtml = async (vm) => {
19-
const tags = document.getElementsByTagName("script");
20-
for (var i = 0, len = tags.length; i < len; i++) {
21-
const tag = tags[i];
22-
if (tag.type === "text/ruby") {
23-
if (tag.hasAttribute('src')){
24-
const response = await fetch(
25-
tag.getAttribute('src')
26-
);
27-
const rubyScript = await response.text();
28-
vm.eval(rubyScript);
29-
} else if (tag.innerHTML) {
30-
vm.eval(tag.innerHTML);
31-
}
32-
}
19+
const tags = document.getElementsByTagName("script");
20+
for (var i = 0, len = tags.length; i < len; i++) {
21+
const tag = tags[i];
22+
if (tag.type === "text/ruby") {
23+
if (tag.hasAttribute("src")) {
24+
const response = await fetch(tag.getAttribute("src"));
25+
const rubyScript = await response.text();
26+
vm.eval(rubyScript);
27+
} else if (tag.innerHTML) {
28+
vm.eval(tag.innerHTML);
29+
}
3330
}
31+
}
3432
};

packages/npm-packages/ruby-wasm-wasi/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export class RubyVM {
9797
procToJsFunction: (rawRbAbiValue) => {
9898
const rbValue = this.rbValueofPointer(rawRbAbiValue);
9999
return (...args) => {
100-
rbValue.call('call', ...args.map(arg => this.wrap(arg)));
101-
}
100+
rbValue.call("call", ...args.map((arg) => this.wrap(arg)));
101+
};
102102
},
103103
rbObjectToJsRbValue: (rawRbAbiValue) => {
104104
return this.rbValueofPointer(rawRbAbiValue);

packages/npm-packages/ruby-wasm-wasi/test/init.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import path from "path";
33
import { DefaultRubyVM } from "../dist/node.cjs";
44

55
const rubyModule = (async () => {
6-
const binary = await fs.readFile(path.join(__dirname, "./../dist/ruby+stdlib.wasm"));
6+
const binary = await fs.readFile(
7+
path.join(__dirname, "./../dist/ruby+stdlib.wasm")
8+
);
79
return await WebAssembly.compile(binary.buffer);
810
})();
911

packages/npm-packages/ruby-wasm-wasi/test/js_from_rb.test.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ describe("Manipulation of JS from Ruby", () => {
6464
expect(vm.eval(result).toString()).toBe(String(props.result));
6565
});
6666

67-
test.each([
68-
`24`, `"hello"`, `null`, `undefined`,
69-
])("JS::Object#to_s (%s)", async (value) => {
70-
const vm = await initRubyVM();
71-
const to_s_result = `require "js"; JS.eval('return ${value}').to_s`;
72-
const inspect_result = `require "js"; JS.eval('return ${value}').inspect`;
73-
expect(vm.eval(to_s_result).toString()).toBe(String(eval(value)));
74-
expect(vm.eval(inspect_result).toString()).toBe(String(eval(value)));
75-
});
67+
test.each([`24`, `"hello"`, `null`, `undefined`])(
68+
"JS::Object#to_s (%s)",
69+
async (value) => {
70+
const vm = await initRubyVM();
71+
const to_s_result = `require "js"; JS.eval('return ${value}').to_s`;
72+
const inspect_result = `require "js"; JS.eval('return ${value}').inspect`;
73+
expect(vm.eval(to_s_result).toString()).toBe(String(eval(value)));
74+
expect(vm.eval(inspect_result).toString()).toBe(String(eval(value)));
75+
}
76+
);
7677

7778
test.each([
7879
{ self: `24`, calee: "toString", args: [], result: "24" },
@@ -97,12 +98,15 @@ describe("Manipulation of JS from Ruby", () => {
9798
end
9899
end
99100
`);
100-
proc.call("call", vm.wrap({
101-
take_block: (arg1: string, block: (_: any) => void) => {
102-
expect(arg1).toBe("x");
103-
block("y");
104-
}
105-
}))
101+
proc.call(
102+
"call",
103+
vm.wrap({
104+
take_block: (arg1: string, block: (_: any) => void) => {
105+
expect(arg1).toBe("x");
106+
block("y");
107+
},
108+
})
109+
);
106110
const y = vm.eval(`$y`);
107111
expect(y.toString()).toBe("y");
108112
});
@@ -174,7 +178,7 @@ describe("Manipulation of JS from Ruby", () => {
174178
function_to_call.call(:a, Proc.new { |a| b = a })
175179
b
176180
`,
177-
result: 1
181+
result: 1,
178182
},
179183
{
180184
expr: `
@@ -183,7 +187,7 @@ describe("Manipulation of JS from Ruby", () => {
183187
function_to_call.call(:a) { |a| b = a }
184188
b
185189
`,
186-
result: 1
190+
result: 1,
187191
},
188192
{
189193
expr: `
@@ -193,8 +197,8 @@ describe("Manipulation of JS from Ruby", () => {
193197
function_to_call.call(:b)
194198
b
195199
`,
196-
result: 1
197-
}
200+
result: 1,
201+
},
198202
])(`JS::Object#call (%s)`, async (props) => {
199203
const vm = await initRubyVM();
200204
const result = vm.eval(`
@@ -291,17 +295,20 @@ describe("Manipulation of JS from Ruby", () => {
291295
end
292296
`);
293297
const livingObjects = new Set<RbValue>();
294-
run.call("call", vm.wrap({
295-
mark_js_object_live: (object: RbValue) => {
296-
livingObjects.add(object);
297-
}
298-
}));
298+
run.call(
299+
"call",
300+
vm.wrap({
301+
mark_js_object_live: (object: RbValue) => {
302+
livingObjects.add(object);
303+
},
304+
})
305+
);
299306
vm.eval("GC.start");
300307
for (const object of livingObjects) {
301308
// Ensure that all objects are still alive
302-
object.call("itself")
309+
object.call("itself");
303310
}
304-
})
311+
});
305312

306313
test("Guard null", async () => {
307314
const vm = await initRubyVM();

0 commit comments

Comments
 (0)