github.com/bananabytelabs/wazero@v0.0.0-20240105073314-54b22a776da8/internal/gojs/builtin.go (about) 1 package gojs 2 3 import ( 4 "github.com/bananabytelabs/wazero/internal/gojs/config" 5 "github.com/bananabytelabs/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 proc := &processState{ 12 cwd: config.Workdir, 13 umask: config.Umask, 14 } 15 16 return newJsVal(goos.RefValueGlobal, "global"). 17 addProperties(map[string]interface{}{ 18 "Object": objectConstructor, 19 "Array": arrayConstructor, 20 "crypto": jsCrypto, 21 "Uint8Array": uint8ArrayConstructor, 22 "fetch": fetchProperty, 23 "process": newJsProcess(proc), 24 "fs": newJsFs(proc), 25 "Date": jsDateConstructor, 26 }) 27 } 28 29 var ( 30 // Values below are not built-in, but verifiable by looking at Go's source. 31 // When marked "XX.go init", these are eagerly referenced during syscall.init 32 33 // jsGo is not a constant 34 35 // objectConstructor is used by js.ValueOf to make `map[string]any`. 36 // Get("Object") // js.go init 37 objectConstructor = newJsVal(goos.RefObjectConstructor, "Object") 38 39 // arrayConstructor is used by js.ValueOf to make `[]any`. 40 // Get("Array") // js.go init 41 arrayConstructor = newJsVal(goos.RefArrayConstructor, "Array") 42 43 // uint8ArrayConstructor = js.Global().Get("Uint8Array") 44 // // fs_js.go, rand_js.go init 45 // 46 // It has only one invocation pattern: `buf := uint8Array.New(len(b))` 47 uint8ArrayConstructor = newJsVal(goos.RefUint8ArrayConstructor, "Uint8Array") 48 )