Skip to content

Add Prettier, reformat JS code #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Documentation

on:
on:
push:
branches: [master]

Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.build
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"overrides": [
{
"files": ["tsconfig.json", "*.js", "*.ts"],
"options": {
"tabWidth": 4
}
}
]
}
3 changes: 1 addition & 2 deletions Example/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Example project of JavaScriptKit


## Bootstrap

```sh
$ make build
$ npm run start
$ # Open http://localhost:8080 on your browser
$ # Open http://localhost:8080 on your browser
```
2 changes: 1 addition & 1 deletion Example/public/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html>
<head>
<title>Getting Started</title>
Expand Down
65 changes: 32 additions & 33 deletions Example/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,53 @@ import { SwiftRuntime } from "javascript-kit-swift";
import { WASI } from "@wasmer/wasi";
import { WasmFs } from "@wasmer/wasmfs";


const swift = new SwiftRuntime();
// Instantiate a new WASI Instance
const wasmFs = new WasmFs();

// Output stdout and stderr to console
const originalWriteSync = wasmFs.fs.writeSync;
wasmFs.fs.writeSync = (fd, buffer, offset, length, position) => {
const text = new TextDecoder("utf-8").decode(buffer);

// Filter out standalone "\n" added by every `print`, `console.log`
// always adds its own "\n" on top.
if (text !== "\n") {
switch (fd) {
case 1:
console.log(text);
break;
case 2:
console.error(text);
break;
const text = new TextDecoder("utf-8").decode(buffer);

// Filter out standalone "\n" added by every `print`, `console.log`
// always adds its own "\n" on top.
if (text !== "\n") {
switch (fd) {
case 1:
console.log(text);
break;
case 2:
console.error(text);
break;
}
}
}
return originalWriteSync(fd, buffer, offset, length, position);
return originalWriteSync(fd, buffer, offset, length, position);
};

let wasi = new WASI({
args: [],
env: {},
bindings: {
...WASI.defaultBindings,
fs: wasmFs.fs
}
args: [],
env: {},
bindings: {
...WASI.defaultBindings,
fs: wasmFs.fs,
},
});

const startWasiTask = async () => {
// Fetch our Wasm File
const response = await fetch("JavaScriptKitExample.wasm");
const responseArrayBuffer = await response.arrayBuffer();
// Fetch our Wasm File
const response = await fetch("JavaScriptKitExample.wasm");
const responseArrayBuffer = await response.arrayBuffer();

// Instantiate the WebAssembly file
const wasm_bytes = new Uint8Array(responseArrayBuffer).buffer;
let { instance } = await WebAssembly.instantiate(wasm_bytes, {
wasi_snapshot_preview1: wasi.wasiImport,
javascript_kit: swift.importObjects(),
});
// Instantiate the WebAssembly file
const wasm_bytes = new Uint8Array(responseArrayBuffer).buffer;
let { instance } = await WebAssembly.instantiate(wasm_bytes, {
wasi_snapshot_preview1: wasi.wasiImport,
javascript_kit: swift.importObjects(),
});

swift.setInstance(instance);
// Start the WebAssembly WASI instance!
wasi.start(instance);
swift.setInstance(instance);
// Start the WebAssembly WASI instance!
wasi.start(instance);
};
startWasiTask();
32 changes: 16 additions & 16 deletions Example/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const path = require('path');
const outputPath = path.resolve(__dirname, 'dist');
const path = require("path");
const outputPath = path.resolve(__dirname, "dist");

module.exports = {
entry: './src/index.js',
mode: 'development',
output: {
filename: 'main.js',
path: outputPath,
},
devServer: {
inline: true,
watchContentBase: true,
contentBase: [
path.join(__dirname, 'public'),
path.join(__dirname, 'dist'),
],
},
entry: "./src/index.js",
mode: "development",
output: {
filename: "main.js",
path: outputPath,
},
devServer: {
inline: true,
watchContentBase: true,
contentBase: [
path.join(__dirname, "public"),
path.join(__dirname, "dist"),
],
},
};
2 changes: 1 addition & 1 deletion IntegrationTests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ node_modules: package-lock.json

.PHONY: build_rt
build_rt: node_modules
cd ../Runtime && npm run build
cd .. && npm run build

.PHONY: benchmark
benchmark: build_rt dist/BenchmarkTests.wasm
Expand Down
48 changes: 25 additions & 23 deletions IntegrationTests/bin/benchmark-tests.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
const { startWasiTask } = require("../lib")
const { startWasiTask } = require("../lib");
const { performance } = require("perf_hooks");

global.benchmarkRunner = function(name, body) {
console.log(`Running '${name}' ...`)
const startTime = performance.now();
body(5000)
const endTime = performance.now();
console.log("done " + (endTime - startTime) + " ms");
}
global.benchmarkRunner = function (name, body) {
console.log(`Running '${name}' ...`);
const startTime = performance.now();
body(5000);
const endTime = performance.now();
console.log("done " + (endTime - startTime) + " ms");
};

class JSBenchmark {
constructor(title) { this.title = title }
constructor(title) {
this.title = title;
}
testSuite(name, body) {
benchmarkRunner(`${this.title}/${name}`, (iteration) => {
for (let idx = 0; idx < iteration; idx++) {
body()
body();
}
})
});
}
}

const serialization = new JSBenchmark("Serialization")
const serialization = new JSBenchmark("Serialization");
serialization.testSuite("Write JavaScript number directly", () => {
const jsNumber = 42
const object = global
const jsNumber = 42;
const object = global;
for (let idx = 0; idx < 100; idx++) {
object["numberValue" + idx] = jsNumber
object["numberValue" + idx] = jsNumber;
}
})
});

serialization.testSuite("Write JavaScript string directly", () => {
const jsString = "Hello, world"
const object = global
const jsString = "Hello, world";
const object = global;
for (let idx = 0; idx < 100; idx++) {
object["stringValue" + idx] = jsString
object["stringValue" + idx] = jsString;
}
})
});

startWasiTask("./dist/BenchmarkTests.wasm").catch(err => {
console.log(err)
});
startWasiTask("./dist/BenchmarkTests.wasm").catch((err) => {
console.log(err);
});
92 changes: 52 additions & 40 deletions IntegrationTests/bin/primary-tests.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
global.globalObject1 = {
"prop_1": {
"nested_prop": 1,
},
"prop_2": 2,
"prop_3": true,
"prop_4": [
3, 4, "str_elm_1", null, undefined, 5,
],
"prop_5": {
"func1": function () { return },
"func2": function () { return 1 },
"func3": function (n) { return n * 2},
"func4": function (a, b, c) { return a + b + c },
"func5": function (x) { return "Hello, " + x },
"func6": function (c, a, b) {
if (c) { return a } else { return b }
prop_1: {
nested_prop: 1,
},
},
"prop_6": {
"call_host_1": () => {
return global.globalObject1.prop_6.host_func_1()
}
},
"prop_7": 3.14,
"prop_8": [0, , 2, 3, , , 6],
}
prop_2: 2,
prop_3: true,
prop_4: [3, 4, "str_elm_1", null, undefined, 5],
prop_5: {
func1: function () {
return;
},
func2: function () {
return 1;
},
func3: function (n) {
return n * 2;
},
func4: function (a, b, c) {
return a + b + c;
},
func5: function (x) {
return "Hello, " + x;
},
func6: function (c, a, b) {
if (c) {
return a;
} else {
return b;
}
},
},
prop_6: {
call_host_1: () => {
return global.globalObject1.prop_6.host_func_1();
},
},
prop_7: 3.14,
prop_8: [0, , 2, 3, , , 6],
};

global.Animal = function(name, age, isCat) {
this.name = name
this.age = age
this.bark = () => {
return isCat ? "nyan" : "wan"
}
this.isCat = isCat
this.getIsCat = function() {
return this.isCat
}
}
global.Animal = function (name, age, isCat) {
this.name = name;
this.age = age;
this.bark = () => {
return isCat ? "nyan" : "wan";
};
this.isCat = isCat;
this.getIsCat = function () {
return this.isCat;
};
};

const { startWasiTask } = require("../lib")
const { startWasiTask } = require("../lib");

startWasiTask("./dist/PrimaryTests.wasm").catch(err => {
console.log(err)
process.exit(1)
startWasiTask("./dist/PrimaryTests.wasm").catch((err) => {
console.log(err);
process.exit(1);
});
Loading