Skip to content

How to set the prototype of DynamicObject correctly? #488

Answered by dop251
zllovesuki asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, I was just writing to suggest that your DynamicObject implementation that either returns a primitive or a function that returns an object when asked for the toString property.

The following works as expected for me:

func TestDynamicObjectProtoSymbol1(t *testing.T) {
	vm := New()
	_, err := vm.RunString(`
class FetchEvent {
    get [Symbol.toStringTag]() {
        return 'FetchEvent'
    }
}

const instance = new FetchEvent()
	`)
	if err != nil {
		t.Fatal(err)
	}
	m := make(map[string]Value)
	//m["toString"] = vm.ToValue("")
	dynObj := &testDynObject{
		r: vm,
		m: m,
	}
	o := vm.NewDynamicObject(dynObj)
	class := vm.Get("FetchEvent")
	instance := vm.Get("instance")
	o.SetPrototype(c…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@zllovesuki
Comment options

@dop251
Comment options

Answer selected by zllovesuki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants