go2hx

manual

github

Module: stdgo.syscall.js

(view library index)

Overview

Package js gives access to the WebAssembly host environment when using the js/wasm architecture. Its API is based on JavaScript semantics.

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.

Index

Constants

import stdgo.syscall.js.Js
final _nanHead:stdgo.GoUInt64 = ((0 : stdgo.GoUInt64))

nanHead are the upper 32 bits of a ref which are set if the value is not encoded as an IEEE 754 number (see above).

final _typeFlagFunction:Null<Dynamic> = @:invalid_type null
final _typeFlagNone:stdgo.GoUInt64 = ((0 : stdgo.GoUInt64))

the type flags need to be in sync with wasm_exec.js

final _typeFlagObject:Null<Dynamic> = @:invalid_type null
final _typeFlagString:Null<Dynamic> = @:invalid_type null
final _typeFlagSymbol:Null<Dynamic> = @:invalid_type null
final typeBoolean:stdgo.syscall.js.Type_ = ((((0 : stdgo.GoInt)) : stdgo.syscall.js.Js.Type_))
final typeFunction:stdgo.syscall.js.Type_ = ((((0 : stdgo.GoInt)) : stdgo.syscall.js.Js.Type_))
final typeNull:stdgo.syscall.js.Type_ = ((((0 : stdgo.GoInt)) : stdgo.syscall.js.Js.Type_))
final typeNumber:stdgo.syscall.js.Type_ = ((((0 : stdgo.GoInt)) : stdgo.syscall.js.Js.Type_))
final typeObject:stdgo.syscall.js.Type_ = ((((0 : stdgo.GoInt)) : stdgo.syscall.js.Js.Type_))
final typeString:stdgo.syscall.js.Type_ = ((((0 : stdgo.GoInt)) : stdgo.syscall.js.Js.Type_))
final typeSymbol:stdgo.syscall.js.Type_ = ((((0 : stdgo.GoInt)) : stdgo.syscall.js.Js.Type_))
final typeUndefined:stdgo.syscall.js.Type_ = ((((0 : stdgo.GoInt)) : stdgo.syscall.js.Js.Type_))

Variables

import stdgo.syscall.js.Js
var _arrayConstructor:stdgo.syscall.js.Value
var _funcs:stdgo.GoMap<stdgo.GoUInt32, (:stdgo.syscall.js.Value, :stdgo.Slice<stdgo.syscall.js.Value>):stdgo.AnyInterface>
var _funcsMu:stdgo.sync.Mutex
var _jsGo:stdgo.syscall.js.Value

instance of the Go class in JavaScript

var _nextFuncID:stdgo.GoUInt32
var _objectConstructor:stdgo.syscall.js.Value
var _valueFalse:stdgo.syscall.js.Value
var _valueGlobal:stdgo.syscall.js.Value
var _valueNaN:stdgo.syscall.js.Value
var _valueNull:stdgo.syscall.js.Value
var _valueTrue:stdgo.syscall.js.Value
var _valueUndefined:stdgo.syscall.js.Value
var _valueZero:stdgo.syscall.js.Value

Functions

import stdgo.syscall.js.Js

function _copyBytesToGo

function _copyBytesToGo(_dst:stdgo.Slice<stdgo.GoByte>, _src:stdgo.syscall.js.T_ref):{
	_1:Bool;
	_0:stdgo.GoInt;
}

go:wasmimport gojs syscall/js.copyBytesToGo

(view code)

function _copyBytesToJS

function _copyBytesToJS(_dst:stdgo.syscall.js.T_ref, _src:stdgo.Slice<stdgo.GoByte>):{
	_1:Bool;
	_0:stdgo.GoInt;
}

go:wasmimport gojs syscall/js.copyBytesToJS

(view code)

function _finalizeRef

function _finalizeRef(_r:stdgo.syscall.js.T_ref):Void

go:wasmimport gojs syscall/js.finalizeRef

(view code)

function _floatValue

function _floatValue(_f:stdgo.GoFloat64):stdgo.syscall.js.Value

(view code)

function _handleEvent

function _handleEvent():Bool

handleEvent retrieves the pending event (window._pendingEvent) and calls the js.Func on it. It returns true if an event was handled.

(view code)

function _jsString

function _jsString(_v:stdgo.syscall.js.Value):stdgo.GoString

(view code)

function _makeArgs

function _makeArgs(_args:stdgo.Slice<stdgo.AnyInterface>):{
	_1:stdgo.Slice<stdgo.syscall.js.T_ref>;
	_0:stdgo.Slice<stdgo.syscall.js.Value>;
}

(view code)

function _makeValue

function _makeValue(_r:stdgo.syscall.js.T_ref):stdgo.syscall.js.Value

(view code)

function _predefValue

function _predefValue(_id:stdgo.GoUInt32, _typeFlag:stdgo.GoByte):stdgo.syscall.js.Value

(view code)

function _setEventHandler

function _setEventHandler(_fn:():Bool):Void

setEventHandler is defined in the runtime package.

(view code)

function _stringVal

function _stringVal(_x:stdgo.GoString):stdgo.syscall.js.T_ref

go:wasmimport gojs syscall/js.stringVal

(view code)

function _valueCall

function _valueCall(_v:stdgo.syscall.js.T_ref, _m:stdgo.GoString, _args:stdgo.Slice<stdgo.syscall.js.T_ref>):{
	_1:Bool;
	_0:stdgo.syscall.js.T_ref;
}

go:wasmimport gojs syscall/js.valueCall go:nosplit

(view code)

function _valueDelete

function _valueDelete(_v:stdgo.syscall.js.T_ref, _p:stdgo.GoString):Void

go:wasmimport gojs syscall/js.valueDelete

(view code)

function _valueGet

function _valueGet(_v:stdgo.syscall.js.T_ref, _p:stdgo.GoString):stdgo.syscall.js.T_ref

go:wasmimport gojs syscall/js.valueGet

(view code)

function _valueIndex

function _valueIndex(_v:stdgo.syscall.js.T_ref, _i:stdgo.GoInt):stdgo.syscall.js.T_ref

go:wasmimport gojs syscall/js.valueIndex

(view code)

function _valueInstanceOf

function _valueInstanceOf(_v:stdgo.syscall.js.T_ref, _t:stdgo.syscall.js.T_ref):Bool

go:wasmimport gojs syscall/js.valueInstanceOf

(view code)

function _valueInvoke

function _valueInvoke(_v:stdgo.syscall.js.T_ref, _args:stdgo.Slice<stdgo.syscall.js.T_ref>):{
	_1:Bool;
	_0:stdgo.syscall.js.T_ref;
}

go:wasmimport gojs syscall/js.valueInvoke

(view code)

function _valueLength

function _valueLength(_v:stdgo.syscall.js.T_ref):stdgo.GoInt

go:wasmimport gojs syscall/js.valueLength

(view code)

function _valueLoadString

function _valueLoadString(_v:stdgo.syscall.js.T_ref, _b:stdgo.Slice<stdgo.GoByte>):Void

go:wasmimport gojs syscall/js.valueLoadString

(view code)

function _valueNew

function _valueNew(_v:stdgo.syscall.js.T_ref, _args:stdgo.Slice<stdgo.syscall.js.T_ref>):{
	_1:Bool;
	_0:stdgo.syscall.js.T_ref;
}

go:wasmimport gojs syscall/js.valueNew

(view code)

function _valuePrepareString

function _valuePrepareString(_v:stdgo.syscall.js.T_ref):{
	_1:stdgo.GoInt;
	_0:stdgo.syscall.js.T_ref;
}

go:wasmimport gojs syscall/js.valuePrepareString

(view code)

function _valueSet

function _valueSet(_v:stdgo.syscall.js.T_ref, _p:stdgo.GoString, _x:stdgo.syscall.js.T_ref):Void

go:wasmimport gojs syscall/js.valueSet

(view code)

function _valueSetIndex

function _valueSetIndex(_v:stdgo.syscall.js.T_ref, _i:stdgo.GoInt, _x:stdgo.syscall.js.T_ref):Void

go:wasmimport gojs syscall/js.valueSetIndex

(view code)

function copyBytesToGo

function copyBytesToGo(_dst:stdgo.Slice<stdgo.GoByte>, _src:stdgo.syscall.js.Value):stdgo.GoInt

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.

(view code)

function copyBytesToJS

function copyBytesToJS(_dst:stdgo.syscall.js.Value, _src:stdgo.Slice<stdgo.GoByte>):stdgo.GoInt

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.

(view code)

function funcOf

function funcOf(_fn:(_this:stdgo.syscall.js.Value, _args:stdgo.Slice<stdgo.syscall.js.Value>):stdgo.AnyInterface):stdgo.syscall.js.Func

FuncOf returns a function to be used by JavaScript.

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.

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.

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.

Func.Release must be called to free up resources when the function will not be invoked any more.

(view code)

function global

function global():stdgo.syscall.js.Value

Global returns the JavaScript global object, usually "window" or "global".

(view code)

function null_

function null_():stdgo.syscall.js.Value

Null returns the JavaScript value "null".

(view code)

function undefined

function undefined():stdgo.syscall.js.Value

Undefined returns the JavaScript value "undefined".

(view code)

function valueOf

function valueOf(_x:stdgo.AnyInterface):stdgo.syscall.js.Value

ValueOf returns x as a JavaScript value:

	| 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             |

Panics if x is not one of the expected types.

(view code)

Classes

import stdgo.syscall.js.*

class Func

Func is a wrapped Go function to be called by JavaScript.

var _id:stdgo.GoUInt32
var value:stdgo.syscall.js.Value

Func function _float

function _float(_p:stdgo.GoString):stdgo.GoFloat64

(view code)

Func function _isNumber

function _isNumber():Bool

(view code)

Func function bool_

function bool_():Bool

(view code)

Func function call

function call(_m:stdgo.GoString, _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

Func function delete

function delete(_p:stdgo.GoString):Void

(view code)

Func function equal

function equal(__0:stdgo.syscall.js.Value):Bool

(view code)

Func function float_

function float_():stdgo.GoFloat64

(view code)

Func function get

function get(_p:stdgo.GoString):stdgo.syscall.js.Value

(view code)

Func function index

function index(_i:stdgo.GoInt):stdgo.syscall.js.Value

(view code)

Func function instanceOf

function instanceOf(__0:stdgo.syscall.js.Value):Bool

(view code)

Func function int_

function int_():stdgo.GoInt

(view code)

Func function invoke

function invoke(_args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

Func function isNaN

function isNaN():Bool

(view code)

Func function isNull

function isNull():Bool

(view code)

Func function isUndefined

function isUndefined():Bool

(view code)

Func function length_

function length_():stdgo.GoInt

(view code)

Func function new

function new(?value:stdgo.syscall.js.Value, ?_id:stdgo.GoUInt32):Void

(view code)

Func function new_

function new_(_args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

Func function set

function set(_p:stdgo.GoString, _x:stdgo.AnyInterface):Void

(view code)

Func function setIndex

function setIndex(_i:stdgo.GoInt, _x:stdgo.AnyInterface):Void

(view code)

Func function string

function string():stdgo.GoString

(view code)

Func function truthy

function truthy():Bool

(view code)

Func function type

function type():stdgo.syscall.js.Type_

(view code)

Func function _float

function _float( _p:stdgo.GoString):stdgo.GoFloat64

(view code)

Func function _isNumber

function _isNumber():Bool

(view code)

Func function bool_

function bool_():Bool

(view code)

Func function call

function call( _m:stdgo.GoString, _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

Func function delete

function delete( _p:stdgo.GoString):Void

(view code)

Func function equal

function equal( __0:stdgo.syscall.js.Value):Bool

(view code)

Func function float_

function float_():stdgo.GoFloat64

(view code)

Func function get

function get( _p:stdgo.GoString):stdgo.syscall.js.Value

(view code)

Func function index

function index( _i:stdgo.GoInt):stdgo.syscall.js.Value

(view code)

Func function instanceOf

function instanceOf( __0:stdgo.syscall.js.Value):Bool

(view code)

Func function int_

function int_():stdgo.GoInt

(view code)

Func function invoke

function invoke( _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

Func function isNaN

function isNaN():Bool

(view code)

Func function isNull

function isNull():Bool

(view code)

Func function isUndefined

function isUndefined():Bool

(view code)

Func function length_

function length_():stdgo.GoInt

(view code)

Func function new_

function new_( _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

Func function release

function release():Void

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.

(view code)

Func function set

function set( _p:stdgo.GoString, _x:stdgo.AnyInterface):Void

(view code)

Func function setIndex

function setIndex( _i:stdgo.GoInt, _x:stdgo.AnyInterface):Void

(view code)

Func function string

function string():stdgo.GoString

(view code)

Func function truthy

function truthy():Bool

(view code)

Func function type

function type():stdgo.syscall.js.Type_

(view code)

class T_error

Error wraps a JavaScript error.

var value:stdgo.syscall.js.Value

Value is the underlying JavaScript error value.

T_error function _float

function _float(_p:stdgo.GoString):stdgo.GoFloat64

(view code)

T_error function _isNumber

function _isNumber():Bool

(view code)

T\error function bool\

function bool_():Bool

(view code)

T_error function call

function call(_m:stdgo.GoString, _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

T_error function delete

function delete(_p:stdgo.GoString):Void

(view code)

T_error function equal

function equal(__0:stdgo.syscall.js.Value):Bool

(view code)

T\error function float\

function float_():stdgo.GoFloat64

(view code)

T_error function get

function get(_p:stdgo.GoString):stdgo.syscall.js.Value

(view code)

T_error function index

function index(_i:stdgo.GoInt):stdgo.syscall.js.Value

(view code)

T_error function instanceOf

function instanceOf(__0:stdgo.syscall.js.Value):Bool

(view code)

T\error function int\

function int_():stdgo.GoInt

(view code)

T_error function invoke

function invoke(_args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

T_error function isNaN

function isNaN():Bool

(view code)

T_error function isNull

function isNull():Bool

(view code)

T_error function isUndefined

function isUndefined():Bool

(view code)

T\error function length\

function length_():stdgo.GoInt

(view code)

T_error function new

function new(?value:stdgo.syscall.js.Value):Void

(view code)

T\error function new\

function new_(_args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

T_error function set

function set(_p:stdgo.GoString, _x:stdgo.AnyInterface):Void

(view code)

T_error function setIndex

function setIndex(_i:stdgo.GoInt, _x:stdgo.AnyInterface):Void

(view code)

T_error function string

function string():stdgo.GoString

(view code)

T_error function truthy

function truthy():Bool

(view code)

T_error function type

function type():stdgo.syscall.js.Type_

(view code)

T_error function _float

function _float( _p:stdgo.GoString):stdgo.GoFloat64

(view code)

T_error function _isNumber

function _isNumber():Bool

(view code)

T\error function bool\

function bool_():Bool

(view code)

T_error function call

function call( _m:stdgo.GoString, _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

T_error function delete

function delete( _p:stdgo.GoString):Void

(view code)

T_error function equal

function equal( __0:stdgo.syscall.js.Value):Bool

(view code)

T_error function error

function error():stdgo.GoString

Error implements the error interface.

(view code)

T\error function float\

function float_():stdgo.GoFloat64

(view code)

T_error function get

function get( _p:stdgo.GoString):stdgo.syscall.js.Value

(view code)

T_error function index

function index( _i:stdgo.GoInt):stdgo.syscall.js.Value

(view code)

T_error function instanceOf

function instanceOf( __0:stdgo.syscall.js.Value):Bool

(view code)

T\error function int\

function int_():stdgo.GoInt

(view code)

T_error function invoke

function invoke( _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

T_error function isNaN

function isNaN():Bool

(view code)

T_error function isNull

function isNull():Bool

(view code)

T_error function isUndefined

function isUndefined():Bool

(view code)

T\error function length\

function length_():stdgo.GoInt

(view code)

T\error function new\

function new_( _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

(view code)

T_error function set

function set( _p:stdgo.GoString, _x:stdgo.AnyInterface):Void

(view code)

T_error function setIndex

function setIndex( _i:stdgo.GoInt, _x:stdgo.AnyInterface):Void

(view code)

T_error function string

function string():stdgo.GoString

(view code)

T_error function truthy

function truthy():Bool

(view code)

T_error function type

function type():stdgo.syscall.js.Type_

(view code)

class Value

Value represents a JavaScript value. The zero value is the JavaScript value "undefined". Values can be checked for equality with the Equal method.

var __26:stdgo.GoArray<():Void>
var _gcPtr:stdgo.Pointer<stdgo.syscall.js.T_ref>
var _ref:stdgo.syscall.js.T_ref

Value function new

function new(?__26:stdgo.GoArray<():Void>, ?_ref:Null<stdgo.syscall.js.T_ref>, ?_gcPtr:stdgo.Pointer<stdgo.syscall.js.T_ref>):Void

(view code)

Value function _float

function _float( _method:stdgo.GoString):stdgo.GoFloat64

(view code)

Value function _isNumber

function _isNumber():Bool

(view code)

Value function bool_

function bool_():Bool

Bool returns the value v as a bool. It panics if v is not a JavaScript boolean.

(view code)

Value function call

function call( _m:stdgo.GoString, _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

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.

(view code)

Value function delete

function delete( _p:stdgo.GoString):Void

Delete deletes the JavaScript property p of value v. It panics if v is not a JavaScript object.

(view code)

Value function equal

function equal( _w:stdgo.syscall.js.Value):Bool

Equal reports whether v and w are equal according to JavaScript's === operator.

(view code)

Value function float_

function float_():stdgo.GoFloat64

Float returns the value v as a float64. It panics if v is not a JavaScript number.

(view code)

Value function get

function get( _p:stdgo.GoString):stdgo.syscall.js.Value

Get returns the JavaScript property p of value v. It panics if v is not a JavaScript object.

(view code)

Value function index

function index( _i:stdgo.GoInt):stdgo.syscall.js.Value

Index returns JavaScript index i of value v. It panics if v is not a JavaScript object.

(view code)

Value function instanceOf

function instanceOf( _t:stdgo.syscall.js.Value):Bool

InstanceOf reports whether v is an instance of type t according to JavaScript's instanceof operator.

(view code)

Value function int_

function int_():stdgo.GoInt

Int returns the value v truncated to an int. It panics if v is not a JavaScript number.

(view code)

Value function invoke

function invoke( _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

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.

(view code)

Value function isNaN

function isNaN():Bool

IsNaN reports whether v is the JavaScript value "NaN".

(view code)

Value function isNull

function isNull():Bool

IsNull reports whether v is the JavaScript value "null".

(view code)

Value function isUndefined

function isUndefined():Bool

IsUndefined reports whether v is the JavaScript value "undefined".

(view code)

Value function length_

function length_():stdgo.GoInt

Length returns the JavaScript property "length" of v. It panics if v is not a JavaScript object.

(view code)

Value function new_

function new_( _args:haxe.Rest<stdgo.AnyInterface>):stdgo.syscall.js.Value

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.

(view code)

Value function set

function set( _p:stdgo.GoString, _x:stdgo.AnyInterface):Void

Set sets the JavaScript property p of value v to ValueOf(x). It panics if v is not a JavaScript object.

(view code)

Value function setIndex

function setIndex( _i:stdgo.GoInt, _x:stdgo.AnyInterface):Void

SetIndex sets the JavaScript index i of value v to ValueOf(x). It panics if v is not a JavaScript object.

(view code)

Value function string

function string():stdgo.GoString

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 "\" or "\" where T is v's type and V is a string representation of v's value.

(view code)

Value function truthy

function truthy():Bool

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 https://developer.mozilla.org/en-US/docs/Glossary/Truthy.

(view code)

Value function type

function type():stdgo.syscall.js.Type_

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.

(view code)

class ValueError

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.

var method:stdgo.GoString
var type:stdgo.syscall.js.Type_

ValueError function new

function new(?method:stdgo.GoString, ?type:Null<stdgo.syscall.js.Type_>):Void

(view code)

ValueError function error

function error():stdgo.GoString

(view code)

Typedefs

import stdgo.syscall.js.*

typedef T_ref

typedef T_ref = stdgo.GoUInt64;

ref is used to identify a JavaScript value, since the value itself can not be passed to WebAssembly.

The JavaScript value "undefined" is represented by the value 0. A JavaScript number (64-bit float, except 0 and NaN) is represented by its IEEE 754 binary representation. All other values are represented as an IEEE 754 binary representation of NaN with bits 0-31 used as an ID and bits 32-34 used to differentiate between string, symbol, function and object.

typedef Type_

typedef Type_ = stdgo.GoInt;

Type represents the JavaScript type of a Value.