Skip to content

Commit 3605835

Browse files
authored
Release v0.5.0 (#75)
* add more examples to the README * typos * v0.5.0 * add release workflow to actions
1 parent 6305aab commit 3605835

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

.github/workflows/release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Get version tag
13+
id: version
14+
run: echo "::set-output name=tag::${GITHUB_REF/refs\/tags\//}"
15+
- name: Get changelog url
16+
id: changelog
17+
run: echo "${{ steps.version.outputs.tag }}---$(date +'%Y-%m-%d')" | sed -e 's/\.//g' | awk '{print "::set-output name=url::https://github.com/rogchap/v8go/blob/master/CHANGELOG.md#" $1}'
18+
- name: Create release
19+
uses: actions/create-release@v1
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
with:
23+
tag_name: ${{ steps.version.outputs.tag }}
24+
release_name: ${{ steps.version.outputs.tag }}
25+
body: Full changelog ⇒ [${{ steps.version.outputs.tag }}](${{ steps.changelog.outputs.url }})
26+
draft: true
27+
prerelease: false

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [v0.5.0] - 2021-02-08
10+
911
### Added
1012
- Support for the BigInt value to the big.Int Go type
1113
- Create Object Templates with primitive values, including other Object Templates
1214
- Configure Object Template as the global object of any new Context
1315
- Function Templates with callbacks to Go
1416
- Value to Object type, including Get/Set/Has/Delete methods
1517
- Get Global Object from the Context
16-
- Convert a Object Template to an instance of an Object
18+
- Convert an Object Template to an instance of an Object
1719

1820
### Changed
1921
- NewContext() API has been improved to handle optional global object, as well as optional Isolate

README.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import "rogchap.com/v8go"
2020
### Running a script
2121

2222
```go
23-
ctx, _ := v8go.NewContext(nil) // creates a new V8 context with a new Isolate aka VM
23+
ctx, _ := v8go.NewContext() // creates a new V8 context with a new Isolate aka VM
2424
ctx.RunScript("const add = (a, b) => a + b", "math.js") // executes a script on the global context
2525
ctx.RunScript("const result = add(3, 4)", "main.js") // any functions previously added to the context can be called
2626
val, _ := ctx.RunScript("result", "value.js") // return a value in JavaScript back to Go
@@ -30,16 +30,45 @@ fmt.Printf("addition result: %s", val)
3030
### One VM, many contexts
3131

3232
```go
33-
vm, _ := v8go.NewIsolate() // creates a new JavaScript VM
34-
ctx1, _ := v8go.NewContext(vm) // new context within the VM
33+
iso, _ := v8go.NewIsolate() // creates a new JavaScript VM
34+
ctx1, _ := v8go.NewContext(iso) // new context within the VM
3535
ctx1.RunScript("const multiply = (a, b) => a * b", "math.js")
3636

37-
ctx2, _ := v8go.NewContext(vm) // another context on the same VM
37+
ctx2, _ := v8go.NewContext(iso) // another context on the same VM
3838
if _, err := ctx2.RunScript("multiply(3, 4)", "main.js"); err != nil {
3939
// this will error as multiply is not defined in this context
4040
}
4141
```
4242

43+
### JavaScript function with Go callback
44+
45+
```go
46+
iso, _ := v8go.NewIsolate() // create a new VM
47+
// a template that represents a JS function
48+
printfn, _ := v8go.NewFunctionTemplate(iso, func(info *v8go.FunctionCallbackInfo) *v8go.Value {
49+
fmt.Printf("%v", info.Args()) // when the JS function is called this Go callback will execute
50+
return nil // you can return a value back to the JS caller if required
51+
})
52+
global, _ := v8go.NewObjectTemplate(iso) // a template that represents a JS Object
53+
global.Set("print", printfn) // sets the "print" property of the Object to our function
54+
ctx, _ := v8go.NewContext(iso, global) // new Context with the global Object set to our object template
55+
ctx.RunScript("print('foo')", "print.js") // will execute the Go callback with a single argunent 'foo'
56+
```
57+
58+
### Update a JavaScript object from Go
59+
60+
```go
61+
ctx, _ := v8go.NewContext() // new context with a default VM
62+
obj := ctx.Global() // get the global object from the context
63+
obj.Set("version", "v1.0.0") // set the property "version" on the object
64+
val, _ := ctx.RunScript("version", "version.js") // global object will have the property set within the JS VM
65+
fmt.Printf("version: %s", val)
66+
67+
if obj.Has("version") { // check if a property exists on the object
68+
obj.Delete("version") // remove the property from the object
69+
}
70+
```
71+
4372
### JavaScript errors
4473

4574
```go
@@ -58,7 +87,6 @@ if err != nil {
5887
### Terminate long running scripts
5988

6089
```go
61-
6290
vals := make(chan *v8go.Value, 1)
6391
errs := make(chan error, 1)
6492

@@ -85,7 +113,7 @@ case <- time.After(200 * time.Milliseconds):
85113

86114
## Documentation
87115

88-
Go Reference: https://pkg.go.dev/rogchap.com/v8go
116+
Go Reference & more examples: https://pkg.go.dev/rogchap.com/v8go
89117

90118
### Support
91119

0 commit comments

Comments
 (0)