Open
Description
Hi, I'm trying to use defaccessor to set a getter and setter, any idea if I'm doing something obviously wrong here?
#[test]
fn defaccessor_with_closure() {
let state = ::State::new(::JS_STRICT);
state.newobject();
state.newfunction(|js| {
js.pushnumber(42.0);
}, "getter", 0);
state.newfunction(|js| {
js.pushundefined();
}, "setter", 1);
state.defaccessor(-3, "test", ::PropertyAttributes::empty());
state.getproperty(-1, "test");
}
backtrace
thread 'tests::defaccessor_with_closure' panicked at '"TypeError: not a __RustClosure__"', src/lib.rs:243:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace
0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::_print
at /checkout/src/libstd/sys_common/backtrace.rs:71
2: std::panicking::default_hook::{{closure}}
at /checkout/src/libstd/sys_common/backtrace.rs:60
at /checkout/src/libstd/panicking.rs:381
3: std::panicking::default_hook
at /checkout/src/libstd/panicking.rs:391
4: std::panicking::rust_panic_with_hook
at /checkout/src/libstd/panicking.rs:577
5: std::panicking::begin_panic
at /checkout/src/libstd/panicking.rs:538
6: std::panicking::begin_panic_fmt
at /checkout/src/libstd/panicking.rs:522
7: mujs::State::_panic
at src/lib.rs:243
8: js_throw
at mujs/jsrun.c:1221
9: js_typeerror
at mujs/jserror.c:102
10: js_touserdata
at mujs/jsrun.c:310
11: mujs::State::_newcfunction_trampoline
at src/lib.rs:837
12: jsR_callcfunction
at mujs/jsrun.c:1031
13: js_call
at mujs/jsrun.c:1073
14: jsR_hasproperty
at mujs/jsrun.c:522
15: jsR_getproperty
at mujs/jsrun.c:534
16: js_getproperty
at mujs/jsrun.c:791
17: mujs::State::getproperty
at src/lib.rs:726
18: mujs::tests::defaccessor_with_closure
at src/lib.rs:2041
19: <F as test::FnBox<T>>::call_box
at /checkout/src/libtest/lib.rs:1480
at /checkout/src/libcore/ops/function.rs:223
at /checkout/src/libtest/lib.rs:141
20: __rust_maybe_catch_panic
at /checkout/src/libpanic_unwind/lib.rs:99
I''m still digging through it but in the call to js_touserdata the object at the top of the stack has a tag of "\001" and the type is userdata.
(gdb) break rust_panic
(...)
(gdb) frame
#7 0x00005555555a2071 in js_touserdata (J=0x7ffff64107c0, idx=-1, tag=0x7ffff640f030 "__RustClosure__")
at mujs/jsrun.c:310
310 js_typeerror(J, "not a %s(%s)", tag);
(gdb) print v.u.object.type
$30 = JS_CUSERDATA
$34 = {boolean = -163516384, number = 6.9533477290522177e-310, s = {string = 0x7ffff640f020 "\001", length = -163516400},
a = {length = -163516384}, f = {function = 0x7ffff640f020, scope = 0x7ffff640f010}, c = {name = 0x7ffff640f020 "\001",
function = 0x7ffff640f010, constructor = 0x0, length = 0}, r = {prog = 0x7ffff640f020, source = 0x7ffff640f010 "\001",
flags = 0, last = 0}, iter = {target = 0x7ffff640f020, head = 0x7ffff640f010}, user = {tag = 0x7ffff640f020 "\001",
data = 0x7ffff640f010, has = 0x0, put = 0x0, delete = 0x0, finalize = 0x555555571550 <mujs::State::_finalize>}}
(gdb) print v.u.object.u.user.tag
$35 = 0x7ffff640f020 "\001"
Metadata
Assignees
Labels
No labels