Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to add toString method to object #395

Open
JanGordon opened this issue Sep 16, 2023 · 0 comments
Open

unable to add toString method to object #395

JanGordon opened this issue Sep 16, 2023 · 0 comments

Comments

@JanGordon
Copy link

JanGordon commented Sep 16, 2023

I am creating an object and I want to add the toString method but whenever using that name it seg faults. I can use another name for the method and it works as expected.

Here's the code to reproduce:

package main

import (
	"fmt"

	"rogchap.com/v8go"
)

func failingExample() {
	fmt.Println("running failing example")

	iso := v8go.NewIsolate()
	global := v8go.NewObjectTemplate(iso)
	obj := v8go.NewObjectTemplate(iso)
	global.Set("obj", obj)
	obj.Set("toString", v8go.NewFunctionTemplate(iso, func(info *v8go.FunctionCallbackInfo) *v8go.Value {
		self := info.This()
		fmt.Println(self)
		return nil
	}))

	ctx := v8go.NewContext(iso, global)
	ctx.RunScript("var p = obj.toString('hello world')", "print.js")
}

func workingExample() {
	fmt.Println("running working example")

	iso := v8go.NewIsolate()
	global := v8go.NewObjectTemplate(iso)
	obj := v8go.NewObjectTemplate(iso)
	global.Set("obj", obj)
	obj.Set("toStrin", v8go.NewFunctionTemplate(iso, func(info *v8go.FunctionCallbackInfo) *v8go.Value {
		self := info.This()
		fmt.Println(self)
		return nil
	}))

	ctx := v8go.NewContext(iso, global)
	ctx.RunScript("var p = obj.toStrin('hello world')", "print.js")
}

func main() {
	workingExample()
	failingExample()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant