Skip to content

Commit

Permalink
Release v0.5.0 (#75)
Browse files Browse the repository at this point in the history
* add more examples to the README

* typos

* v0.5.0

* add release workflow to actions
  • Loading branch information
rogchap committed Feb 8, 2021
1 parent 6305aab commit 3605835
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,27 @@
name: Release

on:
push:
tags:
- v*

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Get version tag
id: version
run: echo "::set-output name=tag::${GITHUB_REF/refs\/tags\//}"
- name: Get changelog url
id: changelog
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}'
- name: Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.tag }}
release_name: ${{ steps.version.outputs.tag }}
body: Full changelog ⇒ [${{ steps.version.outputs.tag }}](${{ steps.changelog.outputs.url }})
draft: true
prerelease: false
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,14 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.5.0] - 2021-02-08

### Added
- Support for the BigInt value to the big.Int Go type
- Create Object Templates with primitive values, including other Object Templates
- Configure Object Template as the global object of any new Context
- Function Templates with callbacks to Go
- Value to Object type, including Get/Set/Has/Delete methods
- Get Global Object from the Context
- Convert a Object Template to an instance of an Object
- Convert an Object Template to an instance of an Object

### Changed
- NewContext() API has been improved to handle optional global object, as well as optional Isolate
Expand Down
40 changes: 34 additions & 6 deletions README.md
Expand Up @@ -20,7 +20,7 @@ import "rogchap.com/v8go"
### Running a script

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

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

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

### JavaScript function with Go callback

```go
iso, _ := v8go.NewIsolate() // create a new VM
// a template that represents a JS function
printfn, _ := v8go.NewFunctionTemplate(iso, func(info *v8go.FunctionCallbackInfo) *v8go.Value {
fmt.Printf("%v", info.Args()) // when the JS function is called this Go callback will execute
return nil // you can return a value back to the JS caller if required
})
global, _ := v8go.NewObjectTemplate(iso) // a template that represents a JS Object
global.Set("print", printfn) // sets the "print" property of the Object to our function
ctx, _ := v8go.NewContext(iso, global) // new Context with the global Object set to our object template
ctx.RunScript("print('foo')", "print.js") // will execute the Go callback with a single argunent 'foo'
```

### Update a JavaScript object from Go

```go
ctx, _ := v8go.NewContext() // new context with a default VM
obj := ctx.Global() // get the global object from the context
obj.Set("version", "v1.0.0") // set the property "version" on the object
val, _ := ctx.RunScript("version", "version.js") // global object will have the property set within the JS VM
fmt.Printf("version: %s", val)

if obj.Has("version") { // check if a property exists on the object
obj.Delete("version") // remove the property from the object
}
```

### JavaScript errors

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

```go

vals := make(chan *v8go.Value, 1)
errs := make(chan error, 1)

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

## Documentation

Go Reference: https://pkg.go.dev/rogchap.com/v8go
Go Reference & more examples: https://pkg.go.dev/rogchap.com/v8go

### Support

Expand Down

0 comments on commit 3605835

Please sign in to comment.