-
I'm building a headless browser in Go, and not knowing about this, started using the v8 engine (have basic HTMX app with a bit of interactivity supported). However, upon discovering this project, I immediately started looking into using goja instead of v8; having a native Go implementation (now I'm glad I decided to keep the DOM decoupled from the script engine) But exposing native Go objects to JS is not enough. They must adhere to the DOM standard, e.g. an And I'm a little puzzled how I setup this correctly. Already just at setting up the globals scope, I ran into issues, just having constructors have the right name. E.g.,
Checking with gomega reveals a different name. Expect(window.Eval("Window.name")).To(Equal("Window"), "Window.name") This fails with
Next attempt was to get the get a function object for the function, and explicitly set the Window := vm.ToValue(WindowConstructor).(*goja.Object)
Window.Set("name", "Window")
globalThis.Set("Window", Window) But this produces the same result. In JS, How do I make sure that the function objects have the right |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The |
Beta Was this translation helpful? Give feedback.
The
name
property in a function is defined as non-writable, however it is configurable which means you can redefine it withWindow.DefineDataProperty("name", vm.ToValue("Window"), FLAG_NOT_SET, FLAG_NOT_SET, FLAG_NOT_SET)