Skip to content

Improve error message on assignment <non-js-like> to JS #373

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

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/gems/js/ext/js/js-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ static VALUE _rb_js_obj_aref(VALUE obj, VALUE key) {
static VALUE _rb_js_obj_aset(VALUE obj, VALUE key, VALUE val) {
struct jsvalue *p = check_jsvalue(obj);
VALUE rv = _rb_js_try_convert(rb_mJS, val);
if (rv == Qnil) {
rb_raise(rb_eTypeError, "value is not a JS::Object like object");
}
struct jsvalue *v = check_jsvalue(rv);
rb_js_abi_host_string_t key_abi_str;
key = rb_obj_as_string(key);
Expand Down
6 changes: 6 additions & 0 deletions packages/npm-packages/ruby-wasm-wasi/test/unit/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ def test_member_set
assert_equal 41.to_s, object["bar"].to_s
end

def test_member_set_with_non_js_object
assert_raise_message("value is not a JS::Object like object") do
JS.global[:tmp] = Object.new
end
end

def test_member_set_with_stress_gc
GC.stress = true
JS.global[:tmp] = "1"
Expand Down