diff options
author | Richard Musiol <mail@richard-musiol.de> | 2018-06-13 15:43:54 +0200 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-06-15 02:09:34 +0000 |
commit | 2809b339b5da46529f3f4529379391f8dd8e3525 (patch) | |
tree | 068a5a88db17937870056234a1377076ef3317d9 /misc | |
parent | f70d1e76cc0ed2550d83fbc04356f7d2308044c4 (diff) | |
download | go-git-2809b339b5da46529f3f4529379391f8dd8e3525.tar.gz |
syscall/js: improve import functions
1. Make import functions not use the js.Value type directly,
but only the ref field. This gives more flexibility on the Go side
for the js.Value type, which is a preparation for adding
garbage collection of js.Value.
2. Turn import functions which are methods of js.Value into
package-level functions. This is necessary to make vet happy.
Change-Id: I69959bf1fbea0a0b99a552a1112ffcd0c024e9b8
Reviewed-on: https://go-review.googlesource.com/118656
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'misc')
-rwxr-xr-x | misc/wasm/wasm_exec.js | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js index e0759a7ce1..1aa727ae4d 100755 --- a/misc/wasm/wasm_exec.js +++ b/misc/wasm/wasm_exec.js @@ -173,48 +173,48 @@ crypto.getRandomValues(loadSlice(sp + 8)); }, - // func boolVal(value bool) Value + // func boolVal(value bool) ref "syscall/js.boolVal": (sp) => { storeValue(sp + 16, mem().getUint8(sp + 8) !== 0); }, - // func intVal(value int) Value + // func intVal(value int) ref "syscall/js.intVal": (sp) => { storeValue(sp + 16, getInt64(sp + 8)); }, - // func floatVal(value float64) Value + // func floatVal(value float64) ref "syscall/js.floatVal": (sp) => { storeValue(sp + 16, mem().getFloat64(sp + 8, true)); }, - // func stringVal(value string) Value + // func stringVal(value string) ref "syscall/js.stringVal": (sp) => { storeValue(sp + 24, loadString(sp + 8)); }, - // func (v Value) Get(key string) Value - "syscall/js.Value.Get": (sp) => { + // func valueGet(v ref, p string) ref + "syscall/js.valueGet": (sp) => { storeValue(sp + 32, Reflect.get(loadValue(sp + 8), loadString(sp + 16))); }, - // func (v Value) set(key string, value Value) - "syscall/js.Value.set": (sp) => { + // func valueSet(v ref, p string, x ref) + "syscall/js.valueSet": (sp) => { Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32)); }, - // func (v Value) Index(i int) Value - "syscall/js.Value.Index": (sp) => { + // func valueIndex(v ref, i int) ref + "syscall/js.valueIndex": (sp) => { storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16))); }, - // func (v Value) setIndex(i int, value Value) - "syscall/js.Value.setIndex": (sp) => { + // valueSetIndex(v ref, i int, x ref) + "syscall/js.valueSetIndex": (sp) => { Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24)); }, - // func (v Value) call(name string, args []Value) (Value, bool) - "syscall/js.Value.call": (sp) => { + // func valueCall(v ref, m string, args []ref) (ref, bool) + "syscall/js.valueCall": (sp) => { try { const v = loadValue(sp + 8); const m = Reflect.get(v, loadString(sp + 16)); @@ -227,8 +227,8 @@ } }, - // func (v Value) invoke(args []Value) (Value, bool) - "syscall/js.Value.invoke": (sp) => { + // func valueInvoke(v ref, args []ref) (ref, bool) + "syscall/js.valueInvoke": (sp) => { try { const v = loadValue(sp + 8); const args = loadSliceOfValues(sp + 16); @@ -240,8 +240,8 @@ } }, - // func (v Value) new(args []Value) (Value, bool) - "syscall/js.Value.new": (sp) => { + // func valueNew(v ref, args []ref) (ref, bool) + "syscall/js.valueNew": (sp) => { try { const v = loadValue(sp + 8); const args = loadSliceOfValues(sp + 16); @@ -253,35 +253,35 @@ } }, - // func (v Value) Float() float64 - "syscall/js.Value.Float": (sp) => { + // func valueFloat(v ref) float64 + "syscall/js.valueFloat": (sp) => { mem().setFloat64(sp + 16, parseFloat(loadValue(sp + 8)), true); }, - // func (v Value) Int() int - "syscall/js.Value.Int": (sp) => { + // func valueInt(v ref) int + "syscall/js.valueInt": (sp) => { setInt64(sp + 16, parseInt(loadValue(sp + 8))); }, - // func (v Value) Bool() bool - "syscall/js.Value.Bool": (sp) => { + // func valueBool(v ref) bool + "syscall/js.valueBool": (sp) => { mem().setUint8(sp + 16, !!loadValue(sp + 8)); }, - // func (v Value) Length() int - "syscall/js.Value.Length": (sp) => { + // func valueLength(v ref) int + "syscall/js.valueLength": (sp) => { setInt64(sp + 16, parseInt(loadValue(sp + 8).length)); }, - // func (v Value) prepareString() (Value, int) - "syscall/js.Value.prepareString": (sp) => { + // valuePrepareString(v ref) (ref, int) + "syscall/js.valuePrepareString": (sp) => { const str = encoder.encode(String(loadValue(sp + 8))); storeValue(sp + 16, str); setInt64(sp + 24, str.length); }, - // func (v Value) loadString(b []byte) - "syscall/js.Value.loadString": (sp) => { + // valueLoadString(v ref, b []byte) + "syscall/js.valueLoadString": (sp) => { const str = loadValue(sp + 8); loadSlice(sp + 16).set(str); }, |