github.com/tetratelabs/wazero@v1.2.1/internal/gojs/builtin.go (about) 1 package gojs 2 3 import ( 4 "github.com/tetratelabs/wazero/internal/gojs/config" 5 "github.com/tetratelabs/wazero/internal/gojs/goos" 6 ) 7 8 // newJsGlobal = js.Global() // js.go init 9 func newJsGlobal(config *config.Config) *jsVal { 10 var fetchProperty interface{} = goos.Undefined 11 uid, gid, euid := config.Uid, config.Gid, config.Euid 12 groups := config.Groups 13 proc := &processState{ 14 cwd: config.Workdir, 15 umask: config.Umask, 16 } 17 rt := config.Rt 18 19 if config.Rt != nil { 20 fetchProperty = goos.RefHttpFetch 21 } 22 23 return newJsVal(goos.RefValueGlobal, "global"). 24 addProperties(map[string]interface{}{ 25 "Object": objectConstructor, 26 "Array": arrayConstructor, 27 "crypto": jsCrypto, 28 "Uint8Array": uint8ArrayConstructor, 29 "fetch": fetchProperty, 30 "AbortController": goos.Undefined, 31 "Headers": headersConstructor, 32 "process": newJsProcess(uid, gid, euid, groups, proc), 33 "fs": newJsFs(proc), 34 "Date": jsDateConstructor, 35 }). 36 addFunction("fetch", &httpFetch{rt}) 37 } 38 39 var ( 40 // Values below are not built-in, but verifiable by looking at Go's source. 41 // When marked "XX.go init", these are eagerly referenced during syscall.init 42 43 // jsGo is not a constant 44 45 // objectConstructor is used by js.ValueOf to make `map[string]any`. 46 // Get("Object") // js.go init 47 objectConstructor = newJsVal(goos.RefObjectConstructor, "Object") 48 49 // arrayConstructor is used by js.ValueOf to make `[]any`. 50 // Get("Array") // js.go init 51 arrayConstructor = newJsVal(goos.RefArrayConstructor, "Array") 52 53 // uint8ArrayConstructor = js.Global().Get("Uint8Array") 54 // // fs_js.go, rand_js.go, roundtrip_js.go init 55 // 56 // It has only one invocation pattern: `buf := uint8Array.New(len(b))` 57 uint8ArrayConstructor = newJsVal(goos.RefUint8ArrayConstructor, "Uint8Array") 58 )