ref: 2c9435dbbc2e084a8b7c62d2c6efb82d1cb0c5c6
parent: d5977e3393e6486566ac307f40d8c3492ed8338f
author: Philip Silva <philip.silva@protonmail.com>
date: Sun Jul 3 08:53:27 EDT 2022
use sparklefs
--- a/README.md
+++ b/README.md
@@ -25,7 +25,7 @@
hget https://curl.haxx.se/ca/cacert.pem > /sys/lib/tls/ca.pem
# Create mountpoints (needed on 9legacy)
mkdir /mnt/opossum
- mkdir /mnt/goja
+ mkdir /mnt/sparkle
### Binary
@@ -69,24 +69,22 @@
Use on your own Risk!
-Mostly based on goja (ECMAScript 5.1) and https://github.com/fgnass/domino
-(fork of DOM implementation from Mozilla in JS). Some sort of DOM diffing
-is needed, also AJAX functions, `getComputedStyle` etc. are either missing or stubs.
-Very simple jQuery based code works though, e.g. jQuery UI Tab view
-https://jqueryui.com/resources/demos/tabs/default.html or the toggle buttons on
-https://golang.org/dl There is also highly experimental ES6 support with Babel.
-(Needs also https://github.com/psilva261/6to5)
+JS implementation forked from goja (and thus otto). Since the implementation
+is very limited anyway, DOM changes are only computed initially and during
+click events. A handful of jQuery UI widgets work though, e.g. jQuery UI Tab
+view https://jqueryui.com/resources/demos/tabs/default.html. There is also
+highly experimental ES6 support with Babel. (https://github.com/psilva261/6to5)
Install the js engine:
```
cd ..
-git/clone https://github.com/psilva261/gojafs
-cd gojafs
-go install ./cmd/gojafs
+git/clone https://github.com/psilva261/sparklefs
+cd sparklefs
+go install ./cmd/sparklefs
```
-On 9legacy also the folders `/mnt/opossum` and `/mnt/goja` need to exist.
+On 9legacy also the folders `/mnt/opossum` and `/mnt/sparkle` need to exist.
Then it can be tested with:
--- a/browser/browser.go
+++ b/browser/browser.go
@@ -33,6 +33,8 @@
const (
EnterKey = 10
+
+ UserAgent = "opossum"
)
var debugPrintHtml = false
@@ -1734,7 +1736,7 @@
if err != nil {
return
}
- req.Header.Add("User-Agent", "opossum")
+ req.Header.Add("User-Agent", UserAgent)
resp, err := b.client.Do(req)
if err != nil {
return nil, opossum.ContentType{}, fmt.Errorf("error loading %v: %w", uri, err)
@@ -1764,7 +1766,7 @@
if err != nil {
return
}
- req.Header.Add("User-Agent", "opossum")
+ req.Header.Add("User-Agent", UserAgent)
req.Header.Set("Content-Type", fmt.Sprintf("application/x-www-form-urlencoded; charset=%v", b.Website.Charset()))
resp, err := b.client.Do(req)
if err != nil {
--- a/browser/website.go
+++ b/browser/website.go
@@ -77,7 +77,7 @@
csss := cssSrcs(f, doc)
doc, nodeMap := pass(htm, csss...)
- // 3rd pass is only needed initially to load the scripts and set the goja VM
+ // 3rd pass is only needed initially to load the scripts and set the js VM
// state. During subsequent calls from click handlers that state is kept.
var scripts []string
if ExperimentalJsInsecure && layouting != ClickRelayout {
--- a/cmd/opossum/main.go
+++ b/cmd/opossum/main.go
@@ -241,6 +241,7 @@
case err, ok := <-dui.Error:
//log.Infof("err=%v", err)
if !ok {
+ finalize()
return nil
}
log.Printf("main: duit: %s\n", err)
@@ -323,11 +324,15 @@
go func() {
<-done
- js.Stop()
- os.Exit(1)
+ finalize()
}()
if err := Main(); err != nil {
log.Fatalf("Main: %v", err)
}
+}
+
+func finalize() {
+ js.Stop()
+ os.Exit(1)
}
--- a/js/js.go
+++ b/js/js.go
@@ -18,16 +18,11 @@
var timeout = 60 * time.Second
-type ReadWriteCloser struct {
- io.Reader
- io.Writer
- io.Closer
-}
-
var (
fetcher opossum.Fetcher
service string
+ cmd *exec.Cmd
cancel context.CancelFunc
)
@@ -36,9 +31,16 @@
}
func call(fn, cmd string, args ...string) (resp string, err error) {
- rwc, err := callGojaCtl()
+ var rwc io.ReadWriteCloser
+ for t := 100*time.Millisecond; t < 5*time.Second; t *= 2 {
+ rwc, err = callSparkleCtl()
+ if err == nil {
+ break
+ }
+ <-time.After(t)
+ }
if err != nil {
- return "", fmt.Errorf("call goja ctl: %v", err)
+ return "", fmt.Errorf("call sparkle ctl: %v", err)
}
defer rwc.Close()
rwc.Write([]byte(cmd + "\n"))
@@ -56,14 +58,14 @@
// Start with pre-defined scripts
func Start(scripts ...string) (resHtm string, changed bool, err error) {
- service = fmt.Sprintf("goja.%d", os.Getpid())
+ service = fmt.Sprintf("sparkle.%d", os.Getpid())
args := make([]string, 0, len(scripts)+2)
args = append(args, "-s", service)
- log.Infof("Start gojafs")
+ log.Infof("Start sparklefs")
var ctx context.Context
ctx, cancel = context.WithCancel(fetcher.Ctx())
- cmd := exec.CommandContext(ctx, "gojafs", args...)
+ cmd = exec.CommandContext(ctx, "sparklefs", args...)
cmd.Stderr = os.Stderr
log.Infof("cmd.Start...")
@@ -70,11 +72,7 @@
if err = cmd.Start(); err != nil {
return "", false, fmt.Errorf("cmd start: %w", err)
}
- // Prevent Zombie processes after stopping
- go cmd.Wait()
- <-time.After(5 * time.Second)
-
resp, err := call("ctl", "start")
if err != nil {
return "", false, fmt.Errorf("call start: %v", err)
@@ -89,10 +87,17 @@
}
func Stop() {
- log.Infof("Stop gojafs")
+ log.Infof("Stop sparklefs")
hangup()
if cancel != nil {
+ log.Infof("cancel()")
cancel()
+ cancel = nil
+ if cmd != nil {
+ // Prevent Zombie processes after stopping
+ cmd.Wait()
+ cmd = nil
+ }
}
}
@@ -190,12 +195,3 @@
return
}
-
-// AJAX:
-// https://stackoverflow.com/questions/7086858/loading-ajax-app-with-jsdom
-
-// Babel on Goja:
-// https://github.com/dop251/goja/issues/5#issuecomment-259996573
-
-// Goja supports ES5.1 which is essentially JS assembly:
-// https://github.com/dop251/goja/issues/76#issuecomment-399253779
--- a/js/js_plan9.go
+++ b/js/js_plan9.go
@@ -7,6 +7,6 @@
func hangup() {}
-func callGojaCtl() (rwc io.ReadWriteCloser, err error) {
- return os.OpenFile("/mnt/goja/ctl", os.O_RDWR, 0600)
+func callSparkleCtl() (rwc io.ReadWriteCloser, err error) {
+ return os.OpenFile("/mnt/sparkle/ctl", os.O_RDWR, 0600)
}
--- a/js/js_unix.go
+++ b/js/js_unix.go
@@ -44,7 +44,7 @@
}
}
-func callGojaCtl() (rwc io.ReadWriteCloser, err error) {
+func callSparkleCtl() (rwc io.ReadWriteCloser, err error) {
if fsys == nil {
if err := dial(); err != nil {
return nil, fmt.Errorf("dial: %v", err)