mirror of https://github.com/golang/go.git
cmd/compile: allow wasmexport used without exportname
This commit is contained in:
parent
42f9ee904c
commit
9654c5ee71
|
|
@ -320,17 +320,19 @@ by ``importmodule'' and ``importname''. For example,
|
|||
|
||||
causes g to refer to the WebAssembly function f from module a_module.
|
||||
|
||||
//go:wasmexport exportname
|
||||
//go:wasmexport [exportname]
|
||||
|
||||
The //go:wasmexport directive is wasm-only and must be followed by a
|
||||
function definition.
|
||||
It specifies that the function is exported to the wasm host as ``exportname''.
|
||||
If exportname is omitted, the function's own name will be used as the export name.
|
||||
For example,
|
||||
|
||||
//go:wasmexport h
|
||||
func hWasm() { ... }
|
||||
|
||||
make Go function hWasm available outside this WebAssembly module as h.
|
||||
makes Go function hWasm available outside this WebAssembly module as h.
|
||||
//go:wasmexport
|
||||
func hWasm() { ... }
|
||||
makes Go function hWasm available outside this WebAssembly module as hWasm.
|
||||
|
||||
For both go:wasmimport and go:wasmexport,
|
||||
the types of parameters and return values to the Go function are translated to
|
||||
|
|
|
|||
|
|
@ -258,19 +258,23 @@ func (p *noder) pragma(pos syntax.Pos, blankLine bool, text string, old syntax.P
|
|||
}
|
||||
}
|
||||
|
||||
case strings.HasPrefix(text, "go:wasmexport "):
|
||||
case strings.HasPrefix(text, "go:wasmexport"):
|
||||
f := strings.Fields(text)
|
||||
if len(f) != 2 {
|
||||
// TODO: maybe make the name optional? It was once mentioned on proposal 65199.
|
||||
p.error(syntax.Error{Pos: pos, Msg: "usage: //go:wasmexport exportname"})
|
||||
if len(f) > 2 {
|
||||
p.error(syntax.Error{Pos: pos, Msg: "usage: //go:wasmexport [exportname]"})
|
||||
break
|
||||
}
|
||||
|
||||
var exportName string
|
||||
if len(f) == 2 {
|
||||
exportName = f[1]
|
||||
}
|
||||
|
||||
if buildcfg.GOARCH == "wasm" {
|
||||
// Only actually use them if we're compiling to WASM though.
|
||||
pragma.WasmExport = &WasmExport{
|
||||
Pos: pos,
|
||||
Name: f[1],
|
||||
Name: exportName,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1125,7 +1125,11 @@ func (w *writer) funcExt(obj *types2.Func) {
|
|||
w.String("")
|
||||
}
|
||||
if we != nil {
|
||||
w.String(we.Name)
|
||||
if we.Name != "" {
|
||||
w.String(we.Name)
|
||||
} else {
|
||||
w.String(decl.Name.Value)
|
||||
}
|
||||
} else {
|
||||
w.String("")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ package p
|
|||
//go:wasmexport F
|
||||
func F() {} // OK
|
||||
|
||||
//go:wasmexport
|
||||
func G() {} // OK
|
||||
|
||||
type S int32
|
||||
|
||||
//go:wasmexport M
|
||||
|
|
|
|||
Loading…
Reference in New Issue