forked from denoland/deno
-
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
Showing
4 changed files
with
40 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules/ | |
dist/ | ||
deno | ||
assets.go | ||
msg.pb.go |
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,32 +1,46 @@ | ||
// To test: make && ./out/render test_input.js | ||
package main | ||
|
||
//go:generate protoc --go_out=. msg.proto | ||
//go:generate ./node_modules/.bin/parcel build --out-dir=dist/ --no-minify main.ts | ||
//go:generate go-bindata -pkg $GOPACKAGE -o assets.go dist/ | ||
|
||
import ( | ||
"github.com/golang/protobuf/proto" | ||
"github.com/ry/v8worker2" | ||
"os" | ||
) | ||
|
||
func recv(msg []byte) []byte { | ||
println("recv cb", string(msg)) | ||
return nil | ||
} | ||
|
||
func main() { | ||
indexFn := "dist/main.js" | ||
data, err := Asset(indexFn) | ||
func loadAsset(w *v8worker2.Worker, path string) { | ||
data, err := Asset(path) | ||
if err != nil { | ||
panic("asset not found") | ||
} | ||
code := string(data) | ||
err = w.Load(path, string(data)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
func main() { | ||
worker := v8worker2.New(recv) | ||
loadAsset(worker, "dist/main.js") | ||
|
||
// Load up index.js code. | ||
err = worker.Load(indexFn, code) | ||
loadMsg := &Msg{ | ||
Kind: Msg_LOAD, | ||
Argv: os.Args, | ||
} | ||
out, err := proto.Marshal(loadMsg) | ||
if err != nil { | ||
println("Problem executing Javascript.") | ||
panic(err) | ||
} | ||
err = worker.SendBytes(out) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
} |
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,4 +1,7 @@ | ||
import * as ts from "typescript"; | ||
|
||
V8Worker2.recv((ab: ArrayBuffer) { | ||
V8Worker2.print("Got array buffer", ab.byteLength); | ||
}); | ||
|
||
V8Worker2.print("Hello World"); | ||
V8Worker2.print("Hello"); |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
syntax = "proto3"; | ||
package main; | ||
|
||
|
||
message Msg { | ||
enum MsgKind { | ||
LOAD = 0; | ||
} | ||
MsgKind kind = 10; | ||
|
||
// LOAD | ||
repeated string argv = 11; | ||
} |