Skip to content

Commit afc7d23

Browse files
authored
Merge pull request #47 from x1unix/fix/update-wasm-bridge
Update wasm bridge
2 parents 4e87948 + 1b6e084 commit afc7d23

File tree

8 files changed

+329
-198
lines changed

8 files changed

+329
-198
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
# Better Go Playground
22

3+
[![Docker Hub](https://img.shields.io/docker/pulls/x1unix/go-playground.svg)](https://hub.docker.com/r/x1unix/go-playground)
4+
[![Docker Hub](https://img.shields.io/docker/v/x1unix/go-playground.svg?sort=date)](https://hub.docker.com/r/x1unix/go-playground)
35
[![Build Status](https://travis-ci.org/x1unix/go-playground.svg?branch=master)](https://travis-ci.org/x1unix/go-playground)
46
[![Coverage Status](https://coveralls.io/repos/github/x1unix/go-playground/badge.svg?branch=dev)](https://coveralls.io/github/x1unix/go-playground?branch=dev)
57
[![Goreportcard](https://goreportcard.com/badge/github.com/x1unix/go-playground)](https://goreportcard.com/report/github.com/x1unix/go-playground)
68

7-
Improved Go Playground powered by Monaco Editor and React
9+
Improved Go Playground powered by Monaco Editor and React - [https://goplay.tools/](https://goplay.tools)
810

9-
![alt text](./docs/demo.gif)
11+
![alt text](docs/demo.gif)
1012

1113
## Features
1214

15+
* 🌚 Dark theme
1316
* 💡 Code autocomplete
1417
* 💾 Load and save files
1518
* 📔 Snippets and tutorials
19+
* ⚙ Customization (fonts, ligatures, etc)
1620
* 🛠 [WebAssembly](https://github.com/golang/go/wiki/WebAssembly) support
17-
* 🌚 Dark theme
1821

1922

20-
And more
23+
And more !
24+
25+
## Installation
2126

22-
## Demo
27+
### Docker
2328

24-
[https://goplay.tools/](https://goplay.tools)
29+
Playground is available via [Docker Hub](https://hub.docker.com/r/x1unix/go-playground).
2530

26-
## Installation
31+
See [wiki](https://github.com/x1unix/go-playground/wiki/Docker) for usage info.
32+
33+
### Local instance
2734

28-
Playground is available via [Docker Hub](https://hub.docker.com/r/x1unix/go-playground) or can be built and run locally (**Go 1.12+** and **Node.js** required):
35+
Service can be built and run locally (**Go 1.12+** and **Node.js** required):
2936

3037
```
3138
$ git clone https://github.com/x1unix/go-playground.git

docs/demo.gif

8.34 MB
Loading

web/src/services/go/foundation.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,15 @@ export type bytes = Array<number>;
66
export type NodeCallback<T> = (Error, T) => void;
77

88
export const encoder = new TextEncoder();
9-
export const decoder = new TextDecoder('utf-8');
9+
export const decoder = new TextDecoder('utf-8');
10+
11+
12+
export class SyscallError extends Error {
13+
constructor(public code: string, message: string) {
14+
super(message);
15+
}
16+
}
17+
18+
export const enosys = () => {
19+
return new SyscallError('ENOSYS', 'not implemented')
20+
};

web/src/services/go/fs.ts

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NodeCallback } from './foundation';
1+
import { NodeCallback, enosys } from './foundation';
22

33
export type FileDescriptor = number;
44

@@ -10,6 +10,29 @@ export interface IFileSystem {
1010
write(fd: FileDescriptor, buf: Uint8Array, offset: number, length: number, position: number, callback: NodeCallback<number>)
1111
open(path: string, flags, mode, callback)
1212
fsync(fd, callback)
13+
chmod(path, mode, callback)
14+
chown(path, uid, gid, callback)
15+
close(fd, callback)
16+
fchmod(fd, mode, callback)
17+
fchown(fd, uid, gid, callback)
18+
fstat(fd, callback)
19+
fsync(fd, callback)
20+
ftruncate(fd, length, callback)
21+
lchown(path, uid, gid, callback)
22+
link(path, link, callback)
23+
lstat(path, callback)
24+
mkdir(path, perm, callback)
25+
open(path, flags, mode, callback)
26+
read(fd, buffer, offset, length, position, callback)
27+
readdir(path, callback)
28+
readlink(path, callback)
29+
rename(from, to, callback)
30+
rmdir(path, callback)
31+
stat(path, callback)
32+
symlink(path, link, callback)
33+
truncate(path, length, callback)
34+
unlink(path, callback)
35+
utimes(path, atime, mtime, callback)
1336
}
1437

1538
/**
@@ -21,7 +44,9 @@ export interface IWriter {
2144
}
2245

2346
/**
24-
* FileSystemWrapper is wrapper class for FS simulation
47+
* FileSystemWrapper is file system stub implementation for browser
48+
*
49+
* Source: wasm_exec.js:39 in Go 1.14
2550
*/
2651
export class FileSystemWrapper {
2752
descriptors = new Map<FileDescriptor, IWriter>();
@@ -42,32 +67,28 @@ export class FileSystemWrapper {
4267
writeSync(fd: FileDescriptor, buf: Uint8Array) {
4368
const writer = this.descriptors.get(fd);
4469
if (!writer) {
45-
const err = new Error('not implemented');
46-
err['code'] = 'ENOENT';
47-
throw err;
70+
throw enosys();
4871
}
4972

5073
return writer.write(buf);
5174
}
5275

5376
write(fd: FileDescriptor, buf: Uint8Array, offset: number, length: number, position: number, callback: NodeCallback<number>) {
5477
if (offset !== 0 || length !== buf.length || position !== null) {
55-
throw new Error("not implemented");
78+
callback(enosys(), null);
79+
return;
5680
}
5781
const n = this.writeSync(fd, buf);
5882
callback(null, n);
5983
}
6084

6185
open(path: string, flags, mode, callback) {
62-
const err = new Error("not implemented");
63-
err['code'] = "ENOSYS";
64-
callback(err, null);
86+
// TODO: implement file read-write
87+
callback(enosys(), null);
6588
}
6689

6790
read(fd: FileDescriptor, buffer, offset: number, length: number, position: number, callback: NodeCallback<any>) {
68-
const err = new Error("not implemented");
69-
err['code'] = "ENOSYS";
70-
callback(err, null);
91+
callback(enosys(), null);
7192
}
7293

7394
fsync(fd, callback) {

0 commit comments

Comments
 (0)