Browse Source

Update goja, peg js deps to specific version

Later versions start to degrade test performance quite a bit, and
latest versions flat out do not work. This seems to be due to some
weirdness in the require() logic where a circular import does not
work correctly. There is an existing circular import in regenerator-
transform (visit -> emit -> visit) so it works in that example but
not others.
pull/1/head
Tyler Sommer 11 months ago
parent
commit
3ccbcd3262
Signed by: tyler-sommer GPG Key ID: C09C010500DBD008
10 changed files with 74 additions and 35 deletions
  1. +3
    -1
      Dockerfile
  2. +6
    -3
      Makefile
  3. +1
    -2
      go.mod
  4. +18
    -2
      go.sum
  5. +11
    -8
      package.json
  6. +19
    -3
      plugins/babel/transformer/babel.go
  7. +12
    -9
      testdata/package.json
  8. +1
    -1
      vm/require.go
  9. +3
    -5
      vm/result.go
  10. +0
    -1
      vm/scheduler.go

+ 3
- 1
Dockerfile View File

@ -1,12 +1,14 @@
FROM golang:buster AS build
ARG race
WORKDIR /squircy
COPY . .
RUN go get -v ./...
RUN make clean all
RUN make clean all RACE=${race}
FROM debian:buster-slim


+ 6
- 3
Makefile View File

@ -13,6 +13,9 @@ OUTPUT_BASE := out
PLUGIN_TARGETS := $(patsubst %,$(OUTPUT_BASE)/%.so,$(PLUGINS))
SQUIRCY_TARGET := $(OUTPUT_BASE)/squircy
RACE ?= -race
TEST_ARGS ?= -count 1
TESTDATA_NODEMODS_TARGET := testdata/node_modules
.PHONY: all build generate run squircy plugins clean
@ -34,7 +37,7 @@ run: build
$(SQUIRCY_TARGET)
test: $(TESTDATA_NODEMODS_TARGET)
go test --tags netgo -race ./...
go test -tags netgo $(RACE) $(TEST_ARGS) ./...
$(TESTDATA_NODEMODS_TARGET):
cd testdata && \
@ -42,10 +45,10 @@ $(TESTDATA_NODEMODS_TARGET):
.SECONDEXPANSION:
$(PLUGIN_TARGETS): $(OUTPUT_BASE)/%.so: $$(wildcard plugins/%/*) $(SOURCES)
go build -tags netgo -race -o $@ -buildmode=plugin plugins/$*/*.go
go build -tags netgo $(RACE) -o $@ -buildmode=plugin plugins/$*/*.go
$(SQUIRCY_TARGET): $(SOURCES)
go build -tags netgo -race -o $@ cmd/squircy/*.go
go build -tags netgo $(RACE) -o $@ cmd/squircy/*.go
$(OUTPUT_BASE)/.generated: $(GENERATOR_SOURCES)
go generate


+ 1
- 2
go.mod View File

@ -5,8 +5,7 @@ go 1.12
require (
github.com/BurntSushi/toml v0.3.1
github.com/dlclark/regexp2 v1.2.0 // indirect
github.com/dop251/goja v0.0.0-20190912223329-aa89e6a4c733
github.com/dop251/goja_nodejs v0.0.0-20200128125109-2d688c7e0ac4 // indirect
github.com/dop251/goja v0.0.0-20200526165454-f1752421c432
github.com/fatih/structtag v1.0.0
github.com/go-sourcemap/sourcemap v2.1.2+incompatible // indirect
github.com/kr/pretty v0.1.0 // indirect


+ 18
- 2
go.sum View File

@ -7,8 +7,24 @@ github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/dop251/goja v0.0.0-20190912223329-aa89e6a4c733 h1:cyNc40Dx5YNEO94idePU8rhVd3dn+sd04Arh0kDBAaw=
github.com/dop251/goja v0.0.0-20190912223329-aa89e6a4c733/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja_nodejs v0.0.0-20200128125109-2d688c7e0ac4 h1:L3xoE2+R67n8YEoNBB9K5h9CYJd3QbD8iYAjnuqFNK8=
github.com/dop251/goja_nodejs v0.0.0-20200128125109-2d688c7e0ac4/go.mod h1:hn7BA7c8pLvoGndExHudxTDKZ84Pyvv+90pbBjbTz0Y=
github.com/dop251/goja v0.0.0-20191203121440-007eef3bc40f h1:vtCDQseO/Sbu5IZSoc2uzZ7CkSoai7OtpcwGFK5FlyE=
github.com/dop251/goja v0.0.0-20191203121440-007eef3bc40f/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20200106141417-aaec0e7bde29 h1:Ewd9K+mC725sITA12QQHRqWj78NU4t7EhlFVVgdlzJg=
github.com/dop251/goja v0.0.0-20200106141417-aaec0e7bde29/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20200110130636-0a0a0d8cb944 h1:HUK5qC9rASk/LJfCUCsHV+hGb9siLAHGsLLwOguJzdQ=
github.com/dop251/goja v0.0.0-20200110130636-0a0a0d8cb944/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20200126140343-a7d7d4827263 h1:ADKe3tPOEUfIfucUE2zIBWORnpCADIhs5qd2gK/ooh4=
github.com/dop251/goja v0.0.0-20200126140343-a7d7d4827263/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20200219165308-d1232e640a87 h1:OMbqMXf9OAXzH1dDH82mQMrddBE8LIIwDtxeK4wE1/A=
github.com/dop251/goja v0.0.0-20200219165308-d1232e640a87/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20200221192958-32d9f07ba84c h1:RitFEwjX3S2dz0kCm2QtVU0uAzIzpwQtQCdg9VKfmpg=
github.com/dop251/goja v0.0.0-20200221192958-32d9f07ba84c/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20200223111000-2a7d122434f4 h1:9MPoNbIK8uyTpntY3CsHE68NZE7HgvBQq8nbHrhsQgI=
github.com/dop251/goja v0.0.0-20200223111000-2a7d122434f4/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20200229111354-281a94b35950 h1:D3jcUWgmR0sX6x6wa86oAIjb+IFu3/xkYDaNwRAWgbw=
github.com/dop251/goja v0.0.0-20200229111354-281a94b35950/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/dop251/goja v0.0.0-20200526165454-f1752421c432 h1:EIY1hqp9O08saJ41t7aQy0o1hhq3ByOy61AACthST5M=
github.com/dop251/goja v0.0.0-20200526165454-f1752421c432/go.mod h1:Mw6PkjjMXWbTj+nnj4s3QPXq1jaT0s5pC0iFD4+BOAA=
github.com/fatih/structtag v1.0.0 h1:pTHj65+u3RKWYPSGaU290FpI/dXxTaHdVwVwbcPKmEc=
github.com/fatih/structtag v1.0.0/go.mod h1:IKitwq45uXL/yqi5mYghiD3w9H6eTOvI9vnk8tXMphA=
github.com/go-sourcemap/sourcemap v2.1.2+incompatible h1:0b/xya7BKGhXuqFESKM4oIiRo9WOt2ebz7KxfreD6ug=


+ 11
- 8
package.json View File

@ -4,13 +4,16 @@
"license": "MIT",
"private": true,
"dependencies": {
"@babel/standalone": "^7.5.5",
"assert": "^2.0.0",
"assert-polyfill": "^0.0.0",
"buffer": "^5.2.1",
"core-js-bundle": "^3.1.4",
"process": "^0.11.10",
"regenerator-runtime": "^0.13.3",
"regenerator-transform": "^0.14.1"
"@babel/standalone": "7.5.5",
"assert": "2.0.0",
"assert-polyfill": "0.0.0",
"buffer": "5.2.1",
"core-js-bundle": "3.1.4",
"process": "0.11.10",
"regenerator-runtime": "0.13.3",
"regenerator-transform": "0.14.1"
},
"resolutions": {
"util": "0.12.1"
}
}

+ 19
- 3
plugins/babel/transformer/babel.go View File

@ -16,14 +16,30 @@ func New(r *goja.Runtime) (*Babel, error) {
v, err := b.runtime.RunString(`
this.global = this.global || this;
this.process = this.process || require('process/browser');
// core-js does not set this up correctly, so we do it explicitly here
Object.setPrototypeOf = function(O, proto) {
if(! (O instanceof Object)) {
throw new TypeError("Expected object");
}
if(proto !== null && ! (proto instanceof Object)) {
throw new TypeError("Expected prototype to be object or null");
}
O.__proto__ = proto;
return O;
};
Object.getPrototypeOf = function(O) {
if(! (O instanceof Object)) {
throw new TypeError("Expected object");
}
return O.__proto__;
}
require('core-js-bundle');
this.Babel = require('@babel/standalone');
var plugin = require('regenerator-transform');
var transform = function(src) {
(function(src) {
var res = Babel.transform(src, {presets: ['es2015'], plugins: [plugin]});
return res.code;
};
transform`)
})`)
if err != nil {
return nil, err
}


+ 12
- 9
testdata/package.json View File

@ -1,15 +1,18 @@
{
"private": true,
"dependencies": {
"@babel/standalone": "^7.5.5",
"assert": "^2.0.0",
"@babel/standalone": "7.5.5",
"assert": "2.0.0",
"assert-polyfill": "^0.0.0",
"buffer": "^5.2.1",
"core-js-bundle": "^3.1.4",
"error-polyfill": "^0.1.2",
"process": "^0.11.10",
"readable-stream": "^3.6.0",
"regenerator-runtime": "^0.13.3",
"regenerator-transform": "^0.14.1"
"buffer": "5.2.1",
"core-js-bundle": "3.1.4",
"error-polyfill": "0.1.2",
"process": "0.11.10",
"readable-stream": "3.6.0",
"regenerator-runtime": "0.13.3",
"regenerator-transform": "0.14.1"
},
"resolutions": {
"util": "0.12.1"
}
}

+ 1
- 1
vm/require.go View File

@ -92,7 +92,7 @@ func require(runtime *goja.Runtime, parent *Module, stack []string) func(goja.Fu
return true
}
parse := func(body string) (*ast.Program, error) {
return parser.ParseFile(nil, module.FullPath(), "var res = (function(require, module, exports) {\n"+body+"\n}); res", parser.Mode(0))
return parser.ParseFile(nil, module.FullPath(), "(function(require, module, exports) {\n"+body+"\n})", parser.Mode(0))
}
if !equal(module.etag, etag) {
body := module.Body


+ 3
- 5
vm/result.go View File

@ -214,7 +214,7 @@ func (r *AsyncResult) Cancel() {
}
func getOrCreateResultHandler(gr *goja.Runtime) goja.Callable {
if v := gr.Get("_squircy_handle_result"); v != nil {
if v := gr.Get("____squircy3_handle_result"); v != nil {
fn, _ := goja.AssertFunction(v)
return fn
}
@ -222,7 +222,7 @@ func getOrCreateResultHandler(gr *goja.Runtime) goja.Callable {
// Promise, sets the error if the value is an Error, or sets the result
// as the value for anything else.
v, err := gr.RunString(`
var handler = function(state) {
(function(state) {
if(typeof Promise !== 'undefined' && state.value instanceof Promise) {
state.value
.then(function(result) { state.result = result; })
@ -235,8 +235,7 @@ var handler = function(state) {
state.result = state.value;
state.done = true;
}
}
handler;`)
})`)
if err != nil {
logrus.Warnln("unable to set async result handler:", err.Error())
return nil
@ -297,7 +296,6 @@ func (r *AsyncResult) loop() {
}
select {
case <-r.cancel:
r.Error = errors.New("cancelled")
return
case <-r.vmdone:
// VM shutdown without resolving, cancel execution


+ 0
- 1
vm/scheduler.go View File

@ -144,7 +144,6 @@ func (s *scheduler) start() error {
}
s.done = make(chan struct{})
s.runtime = &runtime{inner: goja.New()}
// s.runtime.inner.SetFieldNameMapper(goja.UncapField())
s.running = true
s.run(func(r *goja.Runtime) {
err := s.initRuntime()


Loading…
Cancel
Save