Skip to content

Commit

Permalink
minimal module
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinEberhardt committed Apr 10, 2019
0 parents commit 26db676
Show file tree
Hide file tree
Showing 8 changed files with 3,726 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
8 changes: 8 additions & 0 deletions __tests__/emitter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { emitter } from "../src/emitter";

describe("emitter", () => {
test("doesn't barf when loading the module", async () => {
const wasm = emitter();
await WebAssembly.instantiate(wasm);
});
});
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node"
};
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "chasm",
"version": "1.0.0",
"main": "index.js",
"author": "Colin Eberhardt <colin.eberhardt@gmail.com>",
"license": "MIT",
"devDependencies": {
"@types/jest": "^24.0.11",
"@types/node": "^11.13.4",
"@types/webassembly-js-api": "^0.0.3",
"jest": "^24.7.1",
"ts-jest": "^24.0.2",
"typescript": "^3.4.3"
},
"scripts": {
"test": "jest"
}
}
12 changes: 12 additions & 0 deletions src/emitter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

// https://webassembly.github.io/spec/core/binary/modules.html#binary-module
const magicModuleHeader = [0x00, 0x61, 0x73, 0x6d];
const moduleVersion = [0x01, 0x00, 0x00, 0x00];

export const emitter: Emitter = () => {
const buffer = [
...magicModuleHeader,
...moduleVersion,
];
return Uint8Array.from(buffer);
};
3 changes: 3 additions & 0 deletions src/types/emitter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Emitter {
(): Uint8Array;
}
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"outDir": "./built",
"allowJs": true,
"lib": ["es2017", "dom"],
"module": "commonjs",
"target": "es2017",
"noImplicitAny": true
},
"include": ["./src/**/*", "./__tests__/**/*"]
}
Loading

0 comments on commit 26db676

Please sign in to comment.