-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c251cbe
commit 54905c5
Showing
3 changed files
with
116 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,23 @@ | ||
package main | ||
|
||
import "go/format" | ||
import ( | ||
"go/format" | ||
"syscall/js" | ||
) | ||
|
||
const buf_len = 8192 | ||
func Format(this js.Value, args []js.Value) any { | ||
input := ([]byte)(args[0].String()) | ||
|
||
var buf [buf_len]byte | ||
|
||
//go:export getBuffer | ||
func GetBuffer() *byte { | ||
return &buf[0] | ||
} | ||
|
||
//go:export format | ||
func Format(input_len uint) int { | ||
input := buf[:input_len] | ||
output, err := format.Source(input) | ||
if err != nil { | ||
return -copy(buf[:], []byte(err.Error())) | ||
return []interface{}{true, err.Error()} | ||
} | ||
result := len(output) | ||
|
||
if result > buf_len { | ||
return -copy(buf[:], []byte("Buffer out of memory")) | ||
} | ||
|
||
copy(buf[:], output) | ||
return result | ||
return []interface{}{false, string(output)} | ||
} | ||
|
||
func main() {} | ||
func main() { | ||
done := make(chan bool) | ||
js.Global().Set("format", js.FuncOf(Format)) | ||
<-done | ||
} |