summaryrefslogtreecommitdiff
path: root/devdocs/go/syscall%2Fjs%2Findex.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/go/syscall%2Fjs%2Findex.html')
-rw-r--r--devdocs/go/syscall%2Fjs%2Findex.html159
1 files changed, 159 insertions, 0 deletions
diff --git a/devdocs/go/syscall%2Fjs%2Findex.html b/devdocs/go/syscall%2Fjs%2Findex.html
new file mode 100644
index 00000000..c82ff5a6
--- /dev/null
+++ b/devdocs/go/syscall%2Fjs%2Findex.html
@@ -0,0 +1,159 @@
+<h1> Package js </h1> <ul id="short-nav">
+<li><code>import "syscall/js"</code></li>
+<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
+<li><a href="#pkg-index" class="indexLink">Index</a></li>
+<li><a href="#pkg-examples" class="examplesLink">Examples</a></li>
+</ul> <h2 id="pkg-overview">Overview </h2> <p>Package js gives access to the WebAssembly host environment when using the js/wasm architecture. Its API is based on JavaScript semantics. </p>
+<p>This package is EXPERIMENTAL. Its current scope is only to allow tests to run, but not yet to provide a comprehensive API for users. It is exempt from the Go compatibility promise. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav">
+<li><a href="#CopyBytesToGo">func CopyBytesToGo(dst []byte, src Value) int</a></li>
+<li><a href="#CopyBytesToJS">func CopyBytesToJS(dst Value, src []byte) int</a></li>
+<li><a href="#Error">type Error</a></li>
+<li> <a href="#Error.Error">func (e Error) Error() string</a>
+</li>
+<li><a href="#Func">type Func</a></li>
+<li> <a href="#FuncOf">func FuncOf(fn func(this Value, args []Value) any) Func</a>
+</li>
+<li> <a href="#Func.Release">func (c Func) Release()</a>
+</li>
+<li><a href="#Type">type Type</a></li>
+<li> <a href="#Type.String">func (t Type) String() string</a>
+</li>
+<li><a href="#Value">type Value</a></li>
+<li> <a href="#Global">func Global() Value</a>
+</li>
+<li> <a href="#Null">func Null() Value</a>
+</li>
+<li> <a href="#Undefined">func Undefined() Value</a>
+</li>
+<li> <a href="#ValueOf">func ValueOf(x any) Value</a>
+</li>
+<li> <a href="#Value.Bool">func (v Value) Bool() bool</a>
+</li>
+<li> <a href="#Value.Call">func (v Value) Call(m string, args ...any) Value</a>
+</li>
+<li> <a href="#Value.Delete">func (v Value) Delete(p string)</a>
+</li>
+<li> <a href="#Value.Equal">func (v Value) Equal(w Value) bool</a>
+</li>
+<li> <a href="#Value.Float">func (v Value) Float() float64</a>
+</li>
+<li> <a href="#Value.Get">func (v Value) Get(p string) Value</a>
+</li>
+<li> <a href="#Value.Index">func (v Value) Index(i int) Value</a>
+</li>
+<li> <a href="#Value.InstanceOf">func (v Value) InstanceOf(t Value) bool</a>
+</li>
+<li> <a href="#Value.Int">func (v Value) Int() int</a>
+</li>
+<li> <a href="#Value.Invoke">func (v Value) Invoke(args ...any) Value</a>
+</li>
+<li> <a href="#Value.IsNaN">func (v Value) IsNaN() bool</a>
+</li>
+<li> <a href="#Value.IsNull">func (v Value) IsNull() bool</a>
+</li>
+<li> <a href="#Value.IsUndefined">func (v Value) IsUndefined() bool</a>
+</li>
+<li> <a href="#Value.Length">func (v Value) Length() int</a>
+</li>
+<li> <a href="#Value.New">func (v Value) New(args ...any) Value</a>
+</li>
+<li> <a href="#Value.Set">func (v Value) Set(p string, x any)</a>
+</li>
+<li> <a href="#Value.SetIndex">func (v Value) SetIndex(i int, x any)</a>
+</li>
+<li> <a href="#Value.String">func (v Value) String() string</a>
+</li>
+<li> <a href="#Value.Truthy">func (v Value) Truthy() bool</a>
+</li>
+<li> <a href="#Value.Type">func (v Value) Type() Type</a>
+</li>
+<li><a href="#ValueError">type ValueError</a></li>
+<li> <a href="#ValueError.Error">func (e *ValueError) Error() string</a>
+</li>
+</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_FuncOf">FuncOf</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>func.go</span> <span>js.go</span> </p> <h2 id="CopyBytesToGo">func <span>CopyBytesToGo</span> </h2> <pre data-language="go">func CopyBytesToGo(dst []byte, src Value) int</pre> <p>CopyBytesToGo copies bytes from src to dst. It panics if src is not a Uint8Array or Uint8ClampedArray. It returns the number of bytes copied, which will be the minimum of the lengths of src and dst. </p>
+<h2 id="CopyBytesToJS">func <span>CopyBytesToJS</span> </h2> <pre data-language="go">func CopyBytesToJS(dst Value, src []byte) int</pre> <p>CopyBytesToJS copies bytes from src to dst. It panics if dst is not a Uint8Array or Uint8ClampedArray. It returns the number of bytes copied, which will be the minimum of the lengths of src and dst. </p>
+<h2 id="Error">type <span>Error</span> </h2> <p>Error wraps a JavaScript error. </p>
+<pre data-language="go">type Error struct {
+ // Value is the underlying JavaScript error value.
+ Value
+}
+</pre> <h3 id="Error.Error">func (Error) <span>Error</span> </h3> <pre data-language="go">func (e Error) Error() string</pre> <p>Error implements the error interface. </p>
+<h2 id="Func">type <span>Func</span> </h2> <p>Func is a wrapped Go function to be called by JavaScript. </p>
+<pre data-language="go">type Func struct {
+ Value // the JavaScript function that invokes the Go function
+ // contains filtered or unexported fields
+}
+</pre> <h3 id="FuncOf">func <span>FuncOf</span> </h3> <pre data-language="go">func FuncOf(fn func(this Value, args []Value) any) Func</pre> <p>FuncOf returns a function to be used by JavaScript. </p>
+<p>The Go function fn is called with the value of JavaScript's "this" keyword and the arguments of the invocation. The return value of the invocation is the result of the Go function mapped back to JavaScript according to ValueOf. </p>
+<p>Invoking the wrapped Go function from JavaScript will pause the event loop and spawn a new goroutine. Other wrapped functions which are triggered during a call from Go to JavaScript get executed on the same goroutine. </p>
+<p>As a consequence, if one wrapped function blocks, JavaScript's event loop is blocked until that function returns. Hence, calling any async JavaScript API, which requires the event loop, like fetch (http.Client), will cause an immediate deadlock. Therefore a blocking function should explicitly start a new goroutine. </p>
+<p>Func.Release must be called to free up resources when the function will not be invoked any more. </p> <h4 id="example_FuncOf"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+var cb js.Func
+cb = js.FuncOf(func(this js.Value, args []js.Value) any {
+ fmt.Println("button clicked")
+ cb.Release() // release the function if the button will not be clicked again
+ return nil
+})
+js.Global().Get("document").Call("getElementById", "myButton").Call("addEventListener", "click", cb)
+</pre> <h3 id="Func.Release">func (Func) <span>Release</span> </h3> <pre data-language="go">func (c Func) Release()</pre> <p>Release frees up resources allocated for the function. The function must not be invoked after calling Release. It is allowed to call Release while the function is still running. </p>
+<h2 id="Type">type <span>Type</span> </h2> <p>Type represents the JavaScript type of a Value. </p>
+<pre data-language="go">type Type int</pre> <pre data-language="go">const (
+ TypeUndefined Type = iota
+ TypeNull
+ TypeBoolean
+ TypeNumber
+ TypeString
+ TypeSymbol
+ TypeObject
+ TypeFunction
+)</pre> <h3 id="Type.String">func (Type) <span>String</span> </h3> <pre data-language="go">func (t Type) String() string</pre> <h2 id="Value">type <span>Value</span> </h2> <p>Value represents a JavaScript value. The zero value is the JavaScript value "undefined". Values can be checked for equality with the Equal method. </p>
+<pre data-language="go">type Value struct {
+ // contains filtered or unexported fields
+}
+</pre> <h3 id="Global">func <span>Global</span> </h3> <pre data-language="go">func Global() Value</pre> <p>Global returns the JavaScript global object, usually "window" or "global". </p>
+<h3 id="Null">func <span>Null</span> </h3> <pre data-language="go">func Null() Value</pre> <p>Null returns the JavaScript value "null". </p>
+<h3 id="Undefined">func <span>Undefined</span> </h3> <pre data-language="go">func Undefined() Value</pre> <p>Undefined returns the JavaScript value "undefined". </p>
+<h3 id="ValueOf">func <span>ValueOf</span> </h3> <pre data-language="go">func ValueOf(x any) Value</pre> <p>ValueOf returns x as a JavaScript value: </p>
+<pre data-language="go">| Go | JavaScript |
+| ---------------------- | ---------------------- |
+| js.Value | [its value] |
+| js.Func | function |
+| nil | null |
+| bool | boolean |
+| integers and floats | number |
+| string | string |
+| []interface{} | new array |
+| map[string]interface{} | new object |
+</pre> <p>Panics if x is not one of the expected types. </p>
+<h3 id="Value.Bool">func (Value) <span>Bool</span> </h3> <pre data-language="go">func (v Value) Bool() bool</pre> <p>Bool returns the value v as a bool. It panics if v is not a JavaScript boolean. </p>
+<h3 id="Value.Call">func (Value) <span>Call</span> </h3> <pre data-language="go">func (v Value) Call(m string, args ...any) Value</pre> <p>Call does a JavaScript call to the method m of value v with the given arguments. It panics if v has no method m. The arguments get mapped to JavaScript values according to the ValueOf function. </p>
+<h3 id="Value.Delete">func (Value) <span>Delete</span> </h3> <pre data-language="go">func (v Value) Delete(p string)</pre> <p>Delete deletes the JavaScript property p of value v. It panics if v is not a JavaScript object. </p>
+<h3 id="Value.Equal">func (Value) <span>Equal</span> </h3> <pre data-language="go">func (v Value) Equal(w Value) bool</pre> <p>Equal reports whether v and w are equal according to JavaScript's === operator. </p>
+<h3 id="Value.Float">func (Value) <span>Float</span> </h3> <pre data-language="go">func (v Value) Float() float64</pre> <p>Float returns the value v as a float64. It panics if v is not a JavaScript number. </p>
+<h3 id="Value.Get">func (Value) <span>Get</span> </h3> <pre data-language="go">func (v Value) Get(p string) Value</pre> <p>Get returns the JavaScript property p of value v. It panics if v is not a JavaScript object. </p>
+<h3 id="Value.Index">func (Value) <span>Index</span> </h3> <pre data-language="go">func (v Value) Index(i int) Value</pre> <p>Index returns JavaScript index i of value v. It panics if v is not a JavaScript object. </p>
+<h3 id="Value.InstanceOf">func (Value) <span>InstanceOf</span> </h3> <pre data-language="go">func (v Value) InstanceOf(t Value) bool</pre> <p>InstanceOf reports whether v is an instance of type t according to JavaScript's instanceof operator. </p>
+<h3 id="Value.Int">func (Value) <span>Int</span> </h3> <pre data-language="go">func (v Value) Int() int</pre> <p>Int returns the value v truncated to an int. It panics if v is not a JavaScript number. </p>
+<h3 id="Value.Invoke">func (Value) <span>Invoke</span> </h3> <pre data-language="go">func (v Value) Invoke(args ...any) Value</pre> <p>Invoke does a JavaScript call of the value v with the given arguments. It panics if v is not a JavaScript function. The arguments get mapped to JavaScript values according to the ValueOf function. </p>
+<h3 id="Value.IsNaN">func (Value) <span>IsNaN</span> </h3> <pre data-language="go">func (v Value) IsNaN() bool</pre> <p>IsNaN reports whether v is the JavaScript value "NaN". </p>
+<h3 id="Value.IsNull">func (Value) <span>IsNull</span> </h3> <pre data-language="go">func (v Value) IsNull() bool</pre> <p>IsNull reports whether v is the JavaScript value "null". </p>
+<h3 id="Value.IsUndefined">func (Value) <span>IsUndefined</span> </h3> <pre data-language="go">func (v Value) IsUndefined() bool</pre> <p>IsUndefined reports whether v is the JavaScript value "undefined". </p>
+<h3 id="Value.Length">func (Value) <span>Length</span> </h3> <pre data-language="go">func (v Value) Length() int</pre> <p>Length returns the JavaScript property "length" of v. It panics if v is not a JavaScript object. </p>
+<h3 id="Value.New">func (Value) <span>New</span> </h3> <pre data-language="go">func (v Value) New(args ...any) Value</pre> <p>New uses JavaScript's "new" operator with value v as constructor and the given arguments. It panics if v is not a JavaScript function. The arguments get mapped to JavaScript values according to the ValueOf function. </p>
+<h3 id="Value.Set">func (Value) <span>Set</span> </h3> <pre data-language="go">func (v Value) Set(p string, x any)</pre> <p>Set sets the JavaScript property p of value v to ValueOf(x). It panics if v is not a JavaScript object. </p>
+<h3 id="Value.SetIndex">func (Value) <span>SetIndex</span> </h3> <pre data-language="go">func (v Value) SetIndex(i int, x any)</pre> <p>SetIndex sets the JavaScript index i of value v to ValueOf(x). It panics if v is not a JavaScript object. </p>
+<h3 id="Value.String">func (Value) <span>String</span> </h3> <pre data-language="go">func (v Value) String() string</pre> <p>String returns the value v as a string. String is a special case because of Go's String method convention. Unlike the other getters, it does not panic if v's Type is not TypeString. Instead, it returns a string of the form "&lt;T&gt;" or "&lt;T: V&gt;" where T is v's type and V is a string representation of v's value. </p>
+<h3 id="Value.Truthy">func (Value) <span>Truthy</span> </h3> <pre data-language="go">func (v Value) Truthy() bool</pre> <p>Truthy returns the JavaScript "truthiness" of the value v. In JavaScript, false, 0, "", null, undefined, and NaN are "falsy", and everything else is "truthy". See <a href="https://developer.mozilla.org/en-US/docs/Glossary/Truthy">https://developer.mozilla.org/en-US/docs/Glossary/Truthy</a>. </p>
+<h3 id="Value.Type">func (Value) <span>Type</span> </h3> <pre data-language="go">func (v Value) Type() Type</pre> <p>Type returns the JavaScript type of the value v. It is similar to JavaScript's typeof operator, except that it returns TypeNull instead of TypeObject for null. </p>
+<h2 id="ValueError">type <span>ValueError</span> </h2> <p>A ValueError occurs when a Value method is invoked on a Value that does not support it. Such cases are documented in the description of each method. </p>
+<pre data-language="go">type ValueError struct {
+ Method string
+ Type Type
+}
+</pre> <h3 id="ValueError.Error">func (*ValueError) <span>Error</span> </h3> <pre data-language="go">func (e *ValueError) Error() string</pre><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
+ <a href="http://golang.org/pkg/syscall/js/" class="_attribution-link">http://golang.org/pkg/syscall/js/</a>
+ </p>
+</div>