Skip to content

Commit 3174995

Browse files
Make js-core.c compatible with the new binding
1 parent 22f1e0a commit 3174995

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

packages/gems/js/ext/js/js-core.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static VALUE rb_cJS_Error;
2828
static ID i_to_js;
2929

3030
struct jsvalue {
31-
rb_js_abi_host_js_abi_value_t abi;
31+
rb_js_abi_host_own_js_abi_value_t abi;
3232
};
3333

3434
static void jsvalue_mark(void *p) {}
@@ -296,14 +296,14 @@ static VALUE _rb_js_obj_call(int argc, VALUE *argv, VALUE obj) {
296296
rb_raise(rb_eTypeError, "argument %d is not a JS::Object like object",
297297
1 + i);
298298
}
299-
abi_args.ptr[i - 1] = check_jsvalue(arg)->abi;
299+
abi_args.ptr[i - 1] = borrow_js_value(check_jsvalue(arg)->abi);
300300
rb_ary_push(rv_args, arg);
301301
}
302302

303303
if (rb_block_given_p()) {
304304
VALUE proc = rb_block_proc();
305305
VALUE rb_proc = _rb_js_try_convert(rb_mJS, proc);
306-
abi_args.ptr[function_arguments_count - 1] = check_jsvalue(rb_proc)->abi;
306+
abi_args.ptr[function_arguments_count - 1] = borrow_js_value(check_jsvalue(rb_proc)->abi);
307307
rb_ary_push(rv_args, rb_proc);
308308
}
309309

@@ -332,7 +332,7 @@ static VALUE _rb_js_obj_typeof(VALUE obj) {
332332
struct jsvalue *p = check_jsvalue(obj);
333333
rb_js_abi_host_string_t ret0;
334334
rb_js_abi_host_js_value_typeof(p->abi, &ret0);
335-
return rb_str_new(ret0.ptr, ret0.len);
335+
return rb_str_new((const char *)ret0.ptr, ret0.len);
336336
}
337337

338338
/*
@@ -352,7 +352,7 @@ static VALUE _rb_js_obj_to_s(VALUE obj) {
352352
struct jsvalue *p = check_jsvalue(obj);
353353
rb_js_abi_host_string_t ret0;
354354
rb_js_abi_host_js_value_to_string(p->abi, &ret0);
355-
return rb_utf8_str_new(ret0.ptr, ret0.len);
355+
return rb_utf8_str_new((const char *)ret0.ptr, ret0.len);
356356
}
357357

358358
/*

packages/gems/js/ext/js/types.h

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,47 @@ typedef ext_string_t rb_abi_guest_string_t;
2121
typedef ext_string_t rb_js_abi_host_string_t;
2222
typedef ext_list_string_t rb_abi_guest_list_string_t;
2323

24+
# define borrow_js_value(v) ruby_js_js_runtime_borrow_js_abi_value(v)
25+
2426
# define rb_abi_guest_rb_abi_value_new(val) exports_ruby_js_ruby_runtime_rb_abi_value_new(val)
2527
# define rb_abi_guest_rb_abi_value_get(val) (*(val))
2628
# define rb_abi_guest_rb_iseq_new(val) exports_ruby_js_ruby_runtime_rb_iseq_new(val)
27-
# define rb_js_abi_host_js_value_equal(lhs, rhs) ruby_js_js_runtime_js_value_equal(lhs, rhs)
28-
# define rb_js_abi_host_reflect_apply(target, this, args, ret) ruby_js_js_runtime_reflect_apply(target, this, args, ret)
29-
# define rb_js_abi_host_js_value_to_integer(value, ret) ruby_js_js_runtime_js_value_to_integer(value, ret)
29+
# define rb_js_abi_host_js_value_equal(lhs, rhs) ruby_js_js_runtime_js_value_equal(borrow_js_value(lhs), borrow_js_value(rhs))
30+
# define rb_js_abi_host_reflect_apply(target, this, args, ret) ruby_js_js_runtime_reflect_apply(borrow_js_value(target), borrow_js_value(this), args, ret)
31+
# define rb_js_abi_host_js_value_to_integer(value, ret) ruby_js_js_runtime_js_value_to_integer(borrow_js_value(value), ret)
32+
# define rb_js_abi_host_export_js_value_to_host(value) ruby_js_js_runtime_export_js_value_to_host(borrow_js_value(value))
33+
# define rb_js_abi_host_raw_integer_free(ptr) ruby_js_js_runtime_raw_integer_free(ptr)
34+
# define rb_js_abi_host_rb_object_to_js_rb_value(val) ruby_js_js_runtime_rb_object_to_js_rb_value(val)
35+
# define rb_js_abi_host_int_to_js_number(val) ruby_js_js_runtime_int_to_js_number(val)
36+
# define rb_js_abi_host_float_to_js_number(val) ruby_js_js_runtime_float_to_js_number(val)
37+
# define rb_js_abi_host_string_to_js_string(val) ruby_js_js_runtime_string_to_js_string(val)
38+
# define rb_js_abi_host_bool_to_js_bool(val) ruby_js_js_runtime_bool_to_js_bool(val)
39+
# define rb_js_abi_host_proc_to_js_function(val) ruby_js_js_runtime_proc_to_js_function(val)
40+
# define rb_js_abi_host_import_js_value_from_host() ruby_js_js_runtime_import_js_value_from_host()
41+
# define rb_js_abi_host_js_value_to_string(value, ret) ruby_js_js_runtime_js_value_to_string(borrow_js_value(value), ret)
42+
# define rb_js_abi_host_js_value_typeof(value, ret) ruby_js_js_runtime_js_value_typeof(borrow_js_value(value), ret)
43+
# define rb_js_abi_host_js_value_strictly_equal(lhs, rhs) ruby_js_js_runtime_js_value_strictly_equal(borrow_js_value(lhs), borrow_js_value(rhs))
44+
# define rb_js_abi_host_reflect_get(target, key, ret) ruby_js_js_runtime_reflect_get(borrow_js_value(target), key, ret)
45+
# define rb_js_abi_host_reflect_set(target, key, value, ret) ruby_js_js_runtime_reflect_set(borrow_js_value(target), key, borrow_js_value(value), ret)
46+
# define rb_js_abi_host_global_this() ruby_js_js_runtime_global_this()
47+
# define rb_js_abi_host_instance_of(value, klass) ruby_js_js_runtime_instance_of(borrow_js_value(value), borrow_js_value(klass))
48+
# define rb_js_abi_host_is_js(value) ruby_js_js_runtime_is_js(borrow_js_value(value))
49+
# define rb_js_abi_host_eval_js(code, ret) ruby_js_js_runtime_eval_js(code, ret)
50+
51+
# define rb_js_abi_host_js_abi_value_free(ptr) ruby_js_js_runtime_js_abi_value_drop_own(*ptr)
52+
53+
# define RB_JS_ABI_HOST_RAW_INTEGER_AS_FLOAT RUBY_JS_JS_RUNTIME_RAW_INTEGER_AS_FLOAT
54+
# define RB_JS_ABI_HOST_JS_ABI_RESULT_FAILURE RUBY_JS_JS_RUNTIME_JS_ABI_RESULT_FAILURE
55+
3056
#else
3157
# include "bindgen/legacy/rb-abi-guest.h"
3258
# include "bindgen/legacy/rb-js-abi-host.h"
3359
typedef rb_abi_guest_rb_abi_value_t rb_abi_guest_own_rb_abi_value_t;
3460
typedef rb_js_abi_host_js_abi_value_t rb_js_abi_host_own_js_abi_value_t;
61+
62+
# define borrow_js_value(v) v
63+
64+
# define rb_js_abi_host_js_abi_value_free(ptr) rb_js_abi_host_js_abi_value_free(ptr)
3565
#endif
3666

3767
#endif // RUBY_WASM_JS_TYPES_H

0 commit comments

Comments
 (0)