Documentation ¶
Index ¶
- Variables
- func Await(awaitable js.Value) (result []js.Value, err []js.Value)
- func Base64ToUint8Array(_ js.Value, args []js.Value) any
- func CopyBytesToGo(src js.Value) []byte
- func CopyBytesToJS(src []byte) js.Value
- func CreatePromise(f PromiseFn) any
- func JsError(err error) js.Value
- func JsErrorToJson(value js.Value) string
- func JsToJson(value js.Value) string
- func JsTrace(err error) js.Value
- func JsonToJS(inputJson []byte) (js.Value, error)
- func Throw(exception Exception, err error)
- func Uint8ArrayEquals(_ js.Value, args []js.Value) any
- func Uint8ArrayToBase64(_ js.Value, args []js.Value) any
- func WrapCB(parent js.Value, m string) func(args ...any) js.Value
- type Exception
- type PromiseFn
Constants ¶
This section is empty.
Variables ¶
var ( // Error is the Javascript Error type. It used to create new Javascript // errors. Error = js.Global().Get("Error") // JSON is the Javascript JSON type. It is used to perform JSON operations // on the Javascript layer. JSON = js.Global().Get("JSON") // Object is the Javascript Object type. It is used to perform Object // operations on the Javascript layer. Object = js.Global().Get("Object") // Promise is the Javascript Promise type. It is used to generate new // promises. Promise = js.Global().Get("Promise") // Uint8Array is the Javascript Uint8Array type. It is used to create new // Uint8Array. Uint8Array = js.Global().Get("Uint8Array") )
Functions ¶
func Await ¶
Await waits on a Javascript value. It blocks until the awaitable successfully resolves to the result or rejects to err.
If there is a result, err will be nil and vice versa.
func Base64ToUint8Array ¶
Base64ToUint8Array decodes a base 64 encoded string to a Uint8Array.
Parameters:
- args[0] - Base 64 encoded string (string).
Returns:
- Javascript 8-bit unsigned integer array (Uint8Array).
- Throws TypeError if decoding the string fails.
func CopyBytesToGo ¶
CopyBytesToGo copies the Uint8Array stored in the js.Value to []byte. This is a wrapper for js.CopyBytesToGo to make it more convenient.
func CopyBytesToJS ¶
CopyBytesToJS copies the []byte to a Uint8Array stored in a js.Value. This is a wrapper for js.CopyBytesToJS to make it more convenient.
func CreatePromise ¶
CreatePromise creates a Javascript promise to return the value of a blocking Go function to Javascript.
func JsErrorToJson ¶ added in v0.3.0
JsErrorToJson converts the Javascript error to JSON. This should be used for all Javascript error objects instead of JsonToJS.
func JsTrace ¶
JsTrace converts the error to a Javascript Error that includes the error's stack trace.
func Throw ¶
Throw function stub to throws Javascript exceptions. The exception must be one of the defined Exception below. Any other error types will result in an error.
func Uint8ArrayEquals ¶
Uint8ArrayEquals returns true if the two Uint8Array are equal and false otherwise.
Parameters:
- args[0] - Array A (Uint8Array).
- args[1] - Array B (Uint8Array).
Returns:
- If the two arrays are equal (boolean).
func Uint8ArrayToBase64 ¶
Uint8ArrayToBase64 encodes an uint8 array to a base 64 string.
Parameters:
- args[0] - Javascript 8-bit unsigned integer array (Uint8Array).
Returns:
- Base 64 encoded string (string).
Types ¶
type Exception ¶
type Exception string
Exception are the possible Javascript error types that can be thrown.
const ( // EvalError occurs when error has occurred in the eval() function. // // Deprecated: This exception is not thrown by JavaScript anymore, however // the EvalError object remains for compatibility. EvalError Exception = "EvalError" // RangeError occurs when a numeric variable or parameter is outside its // valid range. RangeError Exception = "RangeError" // ReferenceError occurs when a variable that does not exist (or hasn't yet // been initialized) in the current scope is referenced. ReferenceError Exception = "ReferenceError" // SyntaxError occurs when trying to interpret syntactically invalid code. SyntaxError Exception = "SyntaxError" // TypeError occurs when an operation could not be performed, typically (but // not exclusively) when a value is not of the expected type. // // A TypeError may be thrown when: // - an operand or argument passed to a function is incompatible with the // type expected by that operator or function; or // - when attempting to modify a value that cannot be changed; or // - when attempting to use a value in an inappropriate way. TypeError Exception = "TypeError" // URIError occurs when a global URI handling function was used in a wrong // way. URIError Exception = "URIError" )