gojs

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClearTimeoutEvent = stubFunction(functionClearTimeoutEvent)

ClearTimeoutEvent implements runtime.clearTimeoutEvent which supports runtime.notetsleepg used by runtime.signal_recv.

See https://github.com/golang/go/blob/go1.19/src/runtime/sys_wasm.s#L196

View Source
var CopyBytesToGo = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionCopyBytesToGo},
	Name:        functionCopyBytesToGo,
	ParamTypes:  []api.ValueType{i32, i32, i32, i64},
	ParamNames:  []string{"dstAddr", "dstLen", "_", "src"},
	ResultTypes: []api.ValueType{i32, i32},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(copyBytesToGo),
	},
})

CopyBytesToGo copies a JavaScript managed byte array to linear memory. For example, this is used to read an HTTP response body.

Results

  • n is the count of bytes written.
  • ok is false if the src was not a uint8Array.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L569 and https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L424-L433

View Source
var CopyBytesToJS = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionCopyBytesToJS},
	Name:        functionCopyBytesToJS,
	ParamTypes:  []api.ValueType{i64, i32, i32, i32},
	ParamNames:  []string{"dst", "srcAddr", "srcLen", "_"},
	ResultTypes: []api.ValueType{i32, i32},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(copyBytesToJS),
	},
})

CopyBytesToJS copies linear memory to a JavaScript managed byte array. For example, this is used to read an HTTP request body.

Results

  • n is the count of bytes written.
  • ok is false if the dst was not a uint8Array.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L583

https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L438-L448
View Source
var Debug = stubFunction(functionDebug)

Debug has unknown use, so stubbed.

See https://github.com/golang/go/blob/go1.19/src/cmd/link/internal/wasm/asm.go#L133-L138

View Source
var FinalizeRef = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionFinalizeRef},
	Name:        functionFinalizeRef,
	ParamTypes:  []api.ValueType{i32},
	ParamNames:  []string{"r"},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoFunc(finalizeRef),
	},
})

FinalizeRef implements js.finalizeRef, which is used as a runtime.SetFinalizer on the given reference.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L61

View Source
var GetRandomData = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionGetRandomData},
	Name:        functionGetRandomData,
	ParamTypes:  []api.ValueType{i32, i32},
	ParamNames:  []string{"buf", "bufLen"},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(getRandomData),
	},
})

GetRandomData implements runtime.getRandomData, which initializes the seed for runtime.fastrand.

See https://github.com/golang/go/blob/go1.19/src/runtime/sys_wasm.s#L200

View Source
var (
	NaN = math.NaN()
)
View Source
var Nanotime1 = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionNanotime1},
	Name:        functionNanotime1,
	ResultTypes: []api.ValueType{i64},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(nanotime1),
	},
})

Nanotime1 implements runtime.nanotime which supports time.Since.

See https://github.com/golang/go/blob/go1.19/src/runtime/sys_wasm.s#L184

View Source
var ResetMemoryDataView = &wasm.HostFunc{
	ExportNames: []string{functionResetMemoryDataView},
	Name:        functionResetMemoryDataView,
	ParamTypes:  []wasm.ValueType{wasm.ValueTypeI32},
	ParamNames:  []string{parameterSp},

	Code: &wasm.Code{IsHostFunction: true, Body: []byte{wasm.OpcodeEnd}},
}

ResetMemoryDataView signals wasm.OpcodeMemoryGrow happened, indicating any cached view of memory should be reset.

See https://github.com/golang/go/blob/go1.19/src/runtime/mem_js.go#L82

View Source
var ScheduleTimeoutEvent = stubFunction(functionScheduleTimeoutEvent)

ScheduleTimeoutEvent implements runtime.scheduleTimeoutEvent which supports runtime.notetsleepg used by runtime.signal_recv.

Unlike other most functions prefixed by "runtime.", this both launches a goroutine and invokes code compiled into wasm "resume".

See https://github.com/golang/go/blob/go1.19/src/runtime/sys_wasm.s#L192

View Source
var StringVal = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionStringVal},
	Name:        functionStringVal,
	ParamTypes:  []api.ValueType{i32, i32},
	ParamNames:  []string{"xAddr", "xLen"},
	ResultTypes: []api.ValueType{i64},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(stringVal),
	},
})

StringVal implements js.stringVal, which is used to load the string for `js.ValueOf(x)`. For example, this is used when setting HTTP headers.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L212 and https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L305-L308

View Source
var ValueCall = spfunc.MustCallFromSP(true, &wasm.HostFunc{
	ExportNames: []string{functionValueCall},
	Name:        functionValueCall,
	ParamTypes:  []api.ValueType{i64, i32, i32, i32, i32},
	ParamNames:  []string{"v", "mAddr", "mLen", "argsArray", "argsLen"},
	ResultTypes: []api.ValueType{i64, i32, i32},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(valueCall),
	},
})

ValueCall implements js.valueCall, which is used to call a js.Value function by name, e.g. `document.Call("createElement", "div")`.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L394

https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L343-L358
View Source
var ValueDelete = stubFunction(functionValueDelete)

ValueDelete is stubbed as it isn't used in Go's main source tree.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L321

View Source
var ValueGet = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionValueGet},
	Name:        functionValueGet,
	ParamTypes:  []api.ValueType{i64, i32, i32},
	ParamNames:  []string{"v", "pAddr", "pLen"},
	ResultTypes: []api.ValueType{i64},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(valueGet),
	},
})

ValueGet implements js.valueGet, which is used to load a js.Value property by name, e.g. `v.Get("address")`. Notably, this is used by js.handleEvent to get the pending event.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L295 and https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L311-L316

View Source
var ValueIndex = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionValueIndex},
	Name:        functionValueIndex,
	ParamTypes:  []api.ValueType{i64, i32},
	ParamNames:  []string{"v", "i"},
	ResultTypes: []api.ValueType{i64},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoFunc(valueIndex),
	},
})

ValueIndex implements js.valueIndex, which is used to load a js.Value property by index, e.g. `v.Index(0)`. Notably, this is used by js.handleEvent to read event arguments

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L334 and https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L331-L334

View Source
var ValueInstanceOf = stubFunction(functionValueInstanceOf)

ValueInstanceOf is stubbed as it isn't used in Go's main source tree.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L543

View Source
var ValueInvoke = stubFunction(functionValueInvoke)

ValueInvoke is stubbed as it isn't used in Go's main source tree.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L413

View Source
var ValueLength = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionValueLength},
	Name:        functionValueLength,
	ParamTypes:  []api.ValueType{i64},
	ParamNames:  []string{"v"},
	ResultTypes: []api.ValueType{i32},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoFunc(valueLength),
	},
})

ValueLength implements js.valueLength, which is used to load the length property of a value, e.g. `array.length`.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L372 and https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L396-L397

View Source
var ValueLoadString = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionValueLoadString},
	Name:        functionValueLoadString,
	ParamTypes:  []api.ValueType{i64, i32, i32},
	ParamNames:  []string{"v", "bAddr", "bLen"},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(valueLoadString),
	},
})

ValueLoadString implements js.valueLoadString, which is used copy a string value for `o.String()`.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L533

https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L410-L412
View Source
var ValueNew = spfunc.MustCallFromSP(true, &wasm.HostFunc{
	ExportNames: []string{functionValueNew},
	Name:        functionValueNew,
	ParamTypes:  []api.ValueType{i64, i32, i32},
	ParamNames:  []string{"v", "argsArray", "argsLen"},
	ResultTypes: []api.ValueType{i64, i32, i32},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(valueNew),
	},
})

ValueNew implements js.valueNew, which is used to call a js.Value, e.g. `array.New(2)`.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L432 and https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L380-L391

View Source
var ValuePrepareString = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionValuePrepareString},
	Name:        functionValuePrepareString,
	ParamTypes:  []api.ValueType{i64},
	ParamNames:  []string{"v"},
	ResultTypes: []api.ValueType{i64, i32},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoFunc(valuePrepareString),
	},
})

ValuePrepareString implements js.valuePrepareString, which is used to load the string for `o.String()` (via js.jsString) for string, boolean and number types. Notably, http.Transport uses this in RoundTrip to coerce the URL to a string.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L531 and https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L402-L405

View Source
var ValueSet = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionValueSet},
	Name:        functionValueSet,
	ParamTypes:  []api.ValueType{i64, i32, i32, i64},
	ParamNames:  []string{"v", "pAddr", "pLen", "x"},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(valueSet),
	},
})

ValueSet implements js.valueSet, which is used to store a js.Value property by name, e.g. `v.Set("address", a)`. Notably, this is used by js.handleEvent set the event result.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L309 and https://github.com/golang/go/blob/go1.19/misc/wasm/wasm_exec.js#L318-L322

View Source
var ValueSetIndex = stubFunction(functionValueSetIndex)

ValueSetIndex is stubbed as it is only used for js.ValueOf when the input is []interface{}, which doesn't appear to occur in Go's source tree.

See https://github.com/golang/go/blob/go1.19/src/syscall/js/js.go#L348

View Source
var Walltime = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionWalltime},
	Name:        functionWalltime,
	ResultTypes: []api.ValueType{i64, i32},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(walltime),
	},
})

Walltime implements runtime.walltime which supports time.Now.

See https://github.com/golang/go/blob/go1.19/src/runtime/sys_wasm.s#L188

View Source
var WasmExit = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionWasmExit},
	Name:        functionWasmExit,
	ParamTypes:  []api.ValueType{i32},
	ParamNames:  []string{"code"},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(wasmExit),
	},
})

WasmExit implements runtime.wasmExit which supports runtime.exit.

See https://github.com/golang/go/blob/go1.19/src/runtime/sys_wasm.go#L28

View Source
var WasmWrite = spfunc.MustCallFromSP(false, &wasm.HostFunc{
	ExportNames: []string{functionWasmWrite},
	Name:        functionWasmWrite,
	ParamTypes:  []api.ValueType{i32, i32, i32},
	ParamNames:  []string{"fd", "p", "n"},
	Code: &wasm.Code{
		IsHostFunction: true,
		GoFunc:         api.GoModuleFunc(wasmWrite),
	},
})

WasmWrite implements runtime.wasmWrite which supports runtime.write and runtime.writeErr. This implements `println`.

See https://github.com/golang/go/blob/go1.19/src/runtime/os_js.go#L29

Functions

func WithState

func WithState(ctx context.Context) context.Context

func WriteArgsAndEnviron

func WriteArgsAndEnviron(ctx context.Context, mod api.Module) (argc, argv uint32, err error)

WriteArgsAndEnviron writes arguments and environment variables to memory, so they can be read by main, Go compiles as the function export "run".

Types

type RoundTripperKey

type RoundTripperKey struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL