Giter Club home page Giter Club logo

Comments (10)

buke avatar buke commented on May 30, 2024

欢迎提交PR,非常感谢~

from quickjs-go.

aoliaoaoaojiao avatar aoliaoaoaojiao commented on May 30, 2024

已提交,另外开发时遇到过将context中的集合对象调用js中合法的方法时,比如 map 对象调用keys方法,出现数组范围异常的提示,请问一下有思路吗?

from quickjs-go.

buke avatar buke commented on May 30, 2024

很棒的PR,我提一点优化建议,请到PR中查阅。

另外,关于“数组范围异常的提示”问题,能否给个重现的代码?

from quickjs-go.

aoliaoaoaojiao avatar aoliaoaoaojiao commented on May 30, 2024

很棒的PR,我提一点优化建议,请到PR中查阅。

另外,关于“数组范围异常的提示”问题,能否给个重现的代码?

quickjs_test.go文件内添加:
`
func TestMapGetArrayError(t *testing.T) {
rt := quickjs.NewRuntime()
defer rt.Close()

ctx := rt.NewContext()
defer ctx.Close()

test := ctx.Map()
defer test.Free()

for i := int64(0); i < 3; i++ {
	test.Put(ctx.Int64(i), ctx.String(fmt.Sprintf("test %d", i)))
	require.True(t, test.Has(ctx.Int64(i)))
	//testValue.Free()
}

value := test.ToValue().Call("keys")
fmt.Println(value.String())
value.Free()

}
`
执行测试代码可以复现,array、set、map里的其他部分方法调用都会出这个问题,目前看只要是涉及到获取新数组的,都是这样
image

至于PR中的意见,我没有看到,你也可以在这里提,然后我看着修改

from quickjs-go.

buke avatar buke commented on May 30, 2024

抱歉,应该是我的review 没有提交,可以试下能否看到。此外,修改建议我也贴在下方:

context.go 中
1、line 124
val := Value{ctx: ctx, ref: C.JS_NewArray(ctx.ref)}
建议改为:
val := Value{ctx: ctx, ref: C.JS_NewArray(ctx.ref)}

2、line 130
val := ctx.eval(new Map();)
建议改为:
ctor := ctx.Globals().Get("Map")
defer ctor.Free()
val := Value{ctx: ctx, ref: C.JS_CallConstructor(ctx.ref, ctor.ref, 0, nil)}

3、line 136
val := ctx.eval(new Set();)
建议改为:
ctor := ctx.Globals().Get("Set")
defer ctor.Free()
val := Value{ctx: ctx, ref: C.JS_CallConstructor(ctx.ref, ctor.ref, 0, nil)}

from quickjs-go.

aoliaoaoaojiao avatar aoliaoaoaojiao commented on May 30, 2024

非常感谢您的指正,PR已提交,您提供的代码让我对之后如何操作class有了一个大概的方向,感谢

from quickjs-go.

buke avatar buke commented on May 30, 2024

#39 已合并。

已重现关于“数组范围异常的提示”问题已重现,可能需要跟踪下quickjs c代码中是否实现了keys 方法,等我有时间研究下,所以此issue 仍然保持打开

from quickjs-go.

aoliaoaoaojiao avatar aoliaoaoaojiao commented on May 30, 2024

不只是map的keys方法有问题,array的unshift方法我记得也是有问题的,可能不单止是底层是否实现keys方法的问题

from quickjs-go.

buke avatar buke commented on May 30, 2024

确认为 js_call 调用的一个bug,当参数为0时,数组越界。
已修复于 f08c12b

请验证~

from quickjs-go.

aoliaoaoaojiao avatar aoliaoaoaojiao commented on May 30, 2024

确认为 js_call 调用的一个bug,当参数为0时,数组越界。 已修复于 f08c12b

请验证~

已经简单验证了,暂时没看到问题

from quickjs-go.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.