js 2.5.1 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,170 @@
1
+ // Generated by `wit-bindgen` 0.24.0. DO NOT EDIT!
2
+ #ifndef __BINDINGS_EXT_H
3
+ #define __BINDINGS_EXT_H
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #include <stdint.h>
9
+ #include <stdbool.h>
10
+
11
+ typedef struct ext_string_t {
12
+ uint8_t*ptr;
13
+ size_t len;
14
+ } ext_string_t;
15
+
16
+ typedef struct ruby_js_js_runtime_own_js_abi_value_t {
17
+ int32_t __handle;
18
+ } ruby_js_js_runtime_own_js_abi_value_t;
19
+
20
+ typedef struct ruby_js_js_runtime_borrow_js_abi_value_t {
21
+ int32_t __handle;
22
+ } ruby_js_js_runtime_borrow_js_abi_value_t;
23
+
24
+ typedef struct ruby_js_js_runtime_js_abi_result_t {
25
+ uint8_t tag;
26
+ union {
27
+ ruby_js_js_runtime_own_js_abi_value_t success;
28
+ ruby_js_js_runtime_own_js_abi_value_t failure;
29
+ } val;
30
+ } ruby_js_js_runtime_js_abi_result_t;
31
+
32
+ #define RUBY_JS_JS_RUNTIME_JS_ABI_RESULT_SUCCESS 0
33
+ #define RUBY_JS_JS_RUNTIME_JS_ABI_RESULT_FAILURE 1
34
+
35
+ typedef struct ruby_js_js_runtime_raw_integer_t {
36
+ uint8_t tag;
37
+ union {
38
+ double as_float;
39
+ ext_string_t bignum;
40
+ } val;
41
+ } ruby_js_js_runtime_raw_integer_t;
42
+
43
+ #define RUBY_JS_JS_RUNTIME_RAW_INTEGER_AS_FLOAT 0
44
+ #define RUBY_JS_JS_RUNTIME_RAW_INTEGER_BIGNUM 1
45
+
46
+ typedef struct ruby_js_js_runtime_list_borrow_js_abi_value_t {
47
+ ruby_js_js_runtime_borrow_js_abi_value_t *ptr;
48
+ size_t len;
49
+ } ruby_js_js_runtime_list_borrow_js_abi_value_t;
50
+
51
+ typedef struct exports_ruby_js_ruby_runtime_own_rb_iseq_t {
52
+ int32_t __handle;
53
+ } exports_ruby_js_ruby_runtime_own_rb_iseq_t;
54
+
55
+ typedef struct exports_ruby_js_ruby_runtime_rb_iseq_t exports_ruby_js_ruby_runtime_rb_iseq_t;
56
+
57
+ typedef exports_ruby_js_ruby_runtime_rb_iseq_t* exports_ruby_js_ruby_runtime_borrow_rb_iseq_t;
58
+
59
+ typedef struct exports_ruby_js_ruby_runtime_own_rb_abi_value_t {
60
+ int32_t __handle;
61
+ } exports_ruby_js_ruby_runtime_own_rb_abi_value_t;
62
+
63
+ typedef struct exports_ruby_js_ruby_runtime_rb_abi_value_t exports_ruby_js_ruby_runtime_rb_abi_value_t;
64
+
65
+ typedef exports_ruby_js_ruby_runtime_rb_abi_value_t* exports_ruby_js_ruby_runtime_borrow_rb_abi_value_t;
66
+
67
+ typedef int32_t exports_ruby_js_ruby_runtime_rb_errno_t;
68
+
69
+ typedef uint32_t exports_ruby_js_ruby_runtime_rb_id_t;
70
+
71
+ typedef struct ext_list_string_t {
72
+ ext_string_t *ptr;
73
+ size_t len;
74
+ } ext_list_string_t;
75
+
76
+ typedef struct exports_ruby_js_ruby_runtime_tuple2_own_rb_abi_value_s32_t {
77
+ exports_ruby_js_ruby_runtime_own_rb_abi_value_t f0;
78
+ int32_t f1;
79
+ } exports_ruby_js_ruby_runtime_tuple2_own_rb_abi_value_s32_t;
80
+
81
+ typedef struct exports_ruby_js_ruby_runtime_list_borrow_rb_abi_value_t {
82
+ exports_ruby_js_ruby_runtime_borrow_rb_abi_value_t *ptr;
83
+ size_t len;
84
+ } exports_ruby_js_ruby_runtime_list_borrow_rb_abi_value_t;
85
+
86
+ // Imported Functions from `ruby:js/js-runtime`
87
+ extern void ruby_js_js_runtime_eval_js(ext_string_t *code, ruby_js_js_runtime_js_abi_result_t *ret);
88
+ extern bool ruby_js_js_runtime_is_js(ruby_js_js_runtime_borrow_js_abi_value_t value);
89
+ extern bool ruby_js_js_runtime_instance_of(ruby_js_js_runtime_borrow_js_abi_value_t value, ruby_js_js_runtime_borrow_js_abi_value_t klass);
90
+ extern ruby_js_js_runtime_own_js_abi_value_t ruby_js_js_runtime_global_this(void);
91
+ extern ruby_js_js_runtime_own_js_abi_value_t ruby_js_js_runtime_int_to_js_number(int32_t value);
92
+ extern ruby_js_js_runtime_own_js_abi_value_t ruby_js_js_runtime_float_to_js_number(double value);
93
+ extern ruby_js_js_runtime_own_js_abi_value_t ruby_js_js_runtime_string_to_js_string(ext_string_t *value);
94
+ extern ruby_js_js_runtime_own_js_abi_value_t ruby_js_js_runtime_bool_to_js_bool(bool value);
95
+ extern ruby_js_js_runtime_own_js_abi_value_t ruby_js_js_runtime_proc_to_js_function(void);
96
+ extern ruby_js_js_runtime_own_js_abi_value_t ruby_js_js_runtime_rb_object_to_js_rb_value(void);
97
+ extern void ruby_js_js_runtime_js_value_to_string(ruby_js_js_runtime_borrow_js_abi_value_t value, ext_string_t *ret);
98
+ extern void ruby_js_js_runtime_js_value_to_integer(ruby_js_js_runtime_borrow_js_abi_value_t value, ruby_js_js_runtime_raw_integer_t *ret);
99
+ extern void ruby_js_js_runtime_export_js_value_to_host(ruby_js_js_runtime_borrow_js_abi_value_t value);
100
+ extern ruby_js_js_runtime_own_js_abi_value_t ruby_js_js_runtime_import_js_value_from_host(void);
101
+ extern void ruby_js_js_runtime_js_value_typeof(ruby_js_js_runtime_borrow_js_abi_value_t value, ext_string_t *ret);
102
+ extern bool ruby_js_js_runtime_js_value_equal(ruby_js_js_runtime_borrow_js_abi_value_t lhs, ruby_js_js_runtime_borrow_js_abi_value_t rhs);
103
+ extern bool ruby_js_js_runtime_js_value_strictly_equal(ruby_js_js_runtime_borrow_js_abi_value_t lhs, ruby_js_js_runtime_borrow_js_abi_value_t rhs);
104
+ extern void ruby_js_js_runtime_reflect_apply(ruby_js_js_runtime_borrow_js_abi_value_t target, ruby_js_js_runtime_borrow_js_abi_value_t this_argument, ruby_js_js_runtime_list_borrow_js_abi_value_t *arguments, ruby_js_js_runtime_js_abi_result_t *ret);
105
+ extern void ruby_js_js_runtime_reflect_get(ruby_js_js_runtime_borrow_js_abi_value_t target, ext_string_t *property_key, ruby_js_js_runtime_js_abi_result_t *ret);
106
+ extern void ruby_js_js_runtime_reflect_set(ruby_js_js_runtime_borrow_js_abi_value_t target, ext_string_t *property_key, ruby_js_js_runtime_borrow_js_abi_value_t value, ruby_js_js_runtime_js_abi_result_t *ret);
107
+ extern void ruby_js_js_runtime_throw_prohibit_rewind_exception(ext_string_t *message);
108
+
109
+ // Exported Functions from `ruby:js/ruby-runtime`
110
+ void exports_ruby_js_ruby_runtime_ruby_show_version(void);
111
+ void exports_ruby_js_ruby_runtime_ruby_init(void);
112
+ void exports_ruby_js_ruby_runtime_ruby_sysinit(ext_list_string_t *args);
113
+ exports_ruby_js_ruby_runtime_own_rb_iseq_t exports_ruby_js_ruby_runtime_ruby_options(ext_list_string_t *args);
114
+ void exports_ruby_js_ruby_runtime_ruby_script(ext_string_t *name);
115
+ void exports_ruby_js_ruby_runtime_ruby_init_loadpath(void);
116
+ void exports_ruby_js_ruby_runtime_rb_eval_string_protect(ext_string_t *str, exports_ruby_js_ruby_runtime_tuple2_own_rb_abi_value_s32_t *ret);
117
+ void exports_ruby_js_ruby_runtime_rb_funcallv_protect(exports_ruby_js_ruby_runtime_borrow_rb_abi_value_t recv, exports_ruby_js_ruby_runtime_rb_id_t mid, exports_ruby_js_ruby_runtime_list_borrow_rb_abi_value_t *args, exports_ruby_js_ruby_runtime_tuple2_own_rb_abi_value_s32_t *ret);
118
+ exports_ruby_js_ruby_runtime_rb_id_t exports_ruby_js_ruby_runtime_rb_intern(ext_string_t *name);
119
+ exports_ruby_js_ruby_runtime_own_rb_abi_value_t exports_ruby_js_ruby_runtime_rb_errinfo(void);
120
+ void exports_ruby_js_ruby_runtime_rb_clear_errinfo(void);
121
+ void exports_ruby_js_ruby_runtime_rstring_ptr(exports_ruby_js_ruby_runtime_borrow_rb_abi_value_t value, ext_string_t *ret);
122
+ void exports_ruby_js_ruby_runtime_rb_vm_bugreport(void);
123
+ bool exports_ruby_js_ruby_runtime_rb_gc_enable(void);
124
+ bool exports_ruby_js_ruby_runtime_rb_gc_disable(void);
125
+ bool exports_ruby_js_ruby_runtime_rb_set_should_prohibit_rewind(bool new_value);
126
+ exports_ruby_js_ruby_runtime_own_rb_abi_value_t exports_ruby_js_ruby_runtime_export_rb_value_to_js(void);
127
+
128
+ // Helper Functions
129
+
130
+ extern void ruby_js_js_runtime_js_abi_value_drop_own(ruby_js_js_runtime_own_js_abi_value_t handle);
131
+
132
+ extern ruby_js_js_runtime_borrow_js_abi_value_t ruby_js_js_runtime_borrow_js_abi_value(ruby_js_js_runtime_own_js_abi_value_t handle);
133
+
134
+ void ruby_js_js_runtime_js_abi_result_free(ruby_js_js_runtime_js_abi_result_t *ptr);
135
+
136
+ void ruby_js_js_runtime_raw_integer_free(ruby_js_js_runtime_raw_integer_t *ptr);
137
+
138
+ void ruby_js_js_runtime_list_borrow_js_abi_value_free(ruby_js_js_runtime_list_borrow_js_abi_value_t *ptr);
139
+
140
+ extern void exports_ruby_js_ruby_runtime_rb_iseq_drop_own(exports_ruby_js_ruby_runtime_own_rb_iseq_t handle);
141
+
142
+ extern exports_ruby_js_ruby_runtime_own_rb_iseq_t exports_ruby_js_ruby_runtime_rb_iseq_new(exports_ruby_js_ruby_runtime_rb_iseq_t *rep);
143
+ extern exports_ruby_js_ruby_runtime_rb_iseq_t* exports_ruby_js_ruby_runtime_rb_iseq_rep(exports_ruby_js_ruby_runtime_own_rb_iseq_t handle);
144
+ void exports_ruby_js_ruby_runtime_rb_iseq_destructor(exports_ruby_js_ruby_runtime_rb_iseq_t *rep);
145
+
146
+ extern void exports_ruby_js_ruby_runtime_rb_abi_value_drop_own(exports_ruby_js_ruby_runtime_own_rb_abi_value_t handle);
147
+
148
+ extern exports_ruby_js_ruby_runtime_own_rb_abi_value_t exports_ruby_js_ruby_runtime_rb_abi_value_new(exports_ruby_js_ruby_runtime_rb_abi_value_t *rep);
149
+ extern exports_ruby_js_ruby_runtime_rb_abi_value_t* exports_ruby_js_ruby_runtime_rb_abi_value_rep(exports_ruby_js_ruby_runtime_own_rb_abi_value_t handle);
150
+ void exports_ruby_js_ruby_runtime_rb_abi_value_destructor(exports_ruby_js_ruby_runtime_rb_abi_value_t *rep);
151
+
152
+ void ext_list_string_free(ext_list_string_t *ptr);
153
+
154
+ void exports_ruby_js_ruby_runtime_list_borrow_rb_abi_value_free(exports_ruby_js_ruby_runtime_list_borrow_rb_abi_value_t *ptr);
155
+
156
+ // Transfers ownership of `s` into the string `ret`
157
+ void ext_string_set(ext_string_t *ret, const char*s);
158
+
159
+ // Creates a copy of the input nul-terminate string `s` and
160
+ // stores it into the component model string `ret`.
161
+ void ext_string_dup(ext_string_t *ret, const char*s);
162
+
163
+ // Deallocates the string pointed to by `ret`, deallocating
164
+ // the memory behind the string.
165
+ void ext_string_free(ext_string_t *ret);
166
+
167
+ #ifdef __cplusplus
168
+ }
169
+ #endif
170
+ #endif
Binary file
@@ -161,7 +161,7 @@ void rb_js_abi_host_js_value_to_string(rb_js_abi_host_js_abi_value_t value, rb_j
161
161
  __wasm_import_rb_js_abi_host_js_value_to_string((value).idx, ptr);
162
162
  *ret0 = (rb_js_abi_host_string_t) { (char*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) };
163
163
  }
164
- __attribute__((import_module("rb-js-abi-host"), import_name("js-value-to-integer: func(value: handle<js-abi-value>) -> variant { f64(float64), bignum(string) }")))
164
+ __attribute__((import_module("rb-js-abi-host"), import_name("js-value-to-integer: func(value: handle<js-abi-value>) -> variant { as-float(float64), bignum(string) }")))
165
165
  void __wasm_import_rb_js_abi_host_js_value_to_integer(int32_t, int32_t);
166
166
  void rb_js_abi_host_js_value_to_integer(rb_js_abi_host_js_abi_value_t value, rb_js_abi_host_raw_integer_t *ret0) {
167
167
 
@@ -173,7 +173,7 @@ void rb_js_abi_host_js_value_to_integer(rb_js_abi_host_js_abi_value_t value, rb_
173
173
  variant.tag = (int32_t) (*((uint8_t*) (ptr + 0)));
174
174
  switch ((int32_t) variant.tag) {
175
175
  case 0: {
176
- variant.val.f64 = *((double*) (ptr + 8));
176
+ variant.val.as_float = *((double*) (ptr + 8));
177
177
  break;
178
178
  }
179
179
  case 1: {
@@ -35,11 +35,11 @@ extern "C"
35
35
  typedef struct {
36
36
  uint8_t tag;
37
37
  union {
38
- double f64;
38
+ double as_float;
39
39
  rb_js_abi_host_string_t bignum;
40
40
  } val;
41
41
  } rb_js_abi_host_raw_integer_t;
42
- #define RB_JS_ABI_HOST_RAW_INTEGER_F64 0
42
+ #define RB_JS_ABI_HOST_RAW_INTEGER_AS_FLOAT 0
43
43
  #define RB_JS_ABI_HOST_RAW_INTEGER_BIGNUM 1
44
44
  void rb_js_abi_host_raw_integer_free(rb_js_abi_host_raw_integer_t *ptr);
45
45
  typedef struct {
@@ -19,7 +19,7 @@ rb-object-to-js-rb-value: func(raw-rb-abi-value: u32) -> js-abi-value
19
19
  js-value-to-string: func(value: js-abi-value) -> string
20
20
 
21
21
  variant raw-integer {
22
- f64(float64),
22
+ as-float(float64),
23
23
  bignum(string),
24
24
  }
25
25
 
data/ext/js/depend CHANGED
@@ -1,10 +1,17 @@
1
+ CLEANFILES += link.filelist
1
2
  link.filelist:
2
3
  echo $(foreach obj,$(OBJS),$(abspath $(obj))) > $@
4
+ echo $(EXTRA_OBJS) >> $@
5
+ echo -mexec-model=reactor >> $@
3
6
 
4
7
  js.a: link.filelist
5
8
 
6
- js-core.o: $(srcdir)/bindgen/rb-js-abi-host.h
9
+ js-core.o: $(srcdir)/bindgen/legacy/rb-js-abi-host.h
7
10
 
8
- bindgen/%.o: $(srcdir)/bindgen/%.c
11
+ bindgen/legacy/%.o: $(srcdir)/bindgen/legacy/%.c
9
12
  @mkdir -p "$(@D)"
10
- $(CC) -c -I$(srcdir)/bindgen -o $@ $<
13
+ $(CC) -c -I$(srcdir)/bindgen/legacy -o $@ $<
14
+
15
+ bindgen/ext.o: $(srcdir)/bindgen/ext.c
16
+ @mkdir -p "$(@D)"
17
+ $(CC) -c -o $@ $<
data/ext/js/extconf.rb CHANGED
@@ -1,3 +1,17 @@
1
1
  require "mkmf"
2
- $objs = %w[js-core.o bindgen/rb-js-abi-host.o]
3
- create_makefile("js")
2
+ $objs = %w[js-core.o witapi-core.o]
3
+
4
+ use_component_model = enable_config("component-model", false)
5
+ $stderr.print "Building with component model: "
6
+ $stderr.puts use_component_model ? "\e[1;32myes\e[0m" : "\e[1;31mno\e[0m"
7
+ if use_component_model
8
+ $defs << "-DJS_ENABLE_COMPONENT_MODEL=1"
9
+ $objs << "bindgen/ext.o"
10
+ else
11
+ $objs << "bindgen/legacy/rb-js-abi-host.o"
12
+ $objs << "bindgen/legacy/rb-abi-guest.o"
13
+ end
14
+ create_makefile("js") do |mk|
15
+ mk << "EXTRA_OBJS = $(srcdir)/bindgen/ext_component_type.o\n" if use_component_model
16
+ mk
17
+ end
data/ext/js/js-core.c CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  #include "ruby.h"
4
4
 
5
- #include "bindgen/rb-js-abi-host.h"
5
+ #include "types.h"
6
6
 
7
7
  // MARK: - Ruby extension
8
8
 
@@ -28,7 +28,7 @@ static VALUE rb_cJS_Error;
28
28
  static ID i_to_js;
29
29
 
30
30
  struct jsvalue {
31
- rb_js_abi_host_js_abi_value_t abi;
31
+ rb_js_abi_host_own_js_abi_value_t abi;
32
32
  };
33
33
 
34
34
  static void jsvalue_mark(void *p) {}
@@ -57,7 +57,7 @@ static VALUE jsvalue_s_allocate(VALUE klass) {
57
57
  return obj;
58
58
  }
59
59
 
60
- static VALUE jsvalue_s_new(rb_js_abi_host_js_abi_value_t abi) {
60
+ static VALUE jsvalue_s_new(rb_js_abi_host_own_js_abi_value_t abi) {
61
61
  struct jsvalue *p;
62
62
  VALUE obj = TypedData_Make_Struct(rb_cJS_Object, struct jsvalue,
63
63
  &jsvalue_data_type, p);
@@ -296,14 +296,15 @@ static VALUE _rb_js_obj_call(int argc, VALUE *argv, VALUE obj) {
296
296
  rb_raise(rb_eTypeError, "argument %d is not a JS::Object like object",
297
297
  1 + i);
298
298
  }
299
- abi_args.ptr[i - 1] = check_jsvalue(arg)->abi;
299
+ abi_args.ptr[i - 1] = borrow_js_value(check_jsvalue(arg)->abi);
300
300
  rb_ary_push(rv_args, arg);
301
301
  }
302
302
 
303
303
  if (rb_block_given_p()) {
304
304
  VALUE proc = rb_block_proc();
305
305
  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] =
307
+ borrow_js_value(check_jsvalue(rb_proc)->abi);
307
308
  rb_ary_push(rv_args, rb_proc);
308
309
  }
309
310
 
@@ -332,7 +333,7 @@ static VALUE _rb_js_obj_typeof(VALUE obj) {
332
333
  struct jsvalue *p = check_jsvalue(obj);
333
334
  rb_js_abi_host_string_t ret0;
334
335
  rb_js_abi_host_js_value_typeof(p->abi, &ret0);
335
- return rb_str_new(ret0.ptr, ret0.len);
336
+ return rb_str_new((const char *)ret0.ptr, ret0.len);
336
337
  }
337
338
 
338
339
  /*
@@ -352,7 +353,7 @@ static VALUE _rb_js_obj_to_s(VALUE obj) {
352
353
  struct jsvalue *p = check_jsvalue(obj);
353
354
  rb_js_abi_host_string_t ret0;
354
355
  rb_js_abi_host_js_value_to_string(p->abi, &ret0);
355
- return rb_utf8_str_new(ret0.ptr, ret0.len);
356
+ return rb_utf8_str_new((const char *)ret0.ptr, ret0.len);
356
357
  }
357
358
 
358
359
  /*
@@ -376,10 +377,10 @@ static VALUE _rb_js_obj_to_i(VALUE obj) {
376
377
  rb_js_abi_host_raw_integer_t ret;
377
378
  rb_js_abi_host_js_value_to_integer(p->abi, &ret);
378
379
  VALUE result;
379
- if (ret.tag == RB_JS_ABI_HOST_RAW_INTEGER_F64) {
380
- result = rb_dbl2big(ret.val.f64);
380
+ if (ret.tag == RB_JS_ABI_HOST_RAW_INTEGER_AS_FLOAT) {
381
+ result = rb_dbl2big(ret.val.as_float);
381
382
  } else {
382
- result = rb_cstr2inum(ret.val.bignum.ptr, 10);
383
+ result = rb_cstr2inum((const char *)ret.val.bignum.ptr, 10);
383
384
  }
384
385
  rb_js_abi_host_raw_integer_free(&ret);
385
386
  return result;
@@ -406,10 +407,10 @@ static VALUE _rb_js_obj_to_f(VALUE obj) {
406
407
  rb_js_abi_host_raw_integer_t ret;
407
408
  VALUE result;
408
409
  rb_js_abi_host_js_value_to_integer(p->abi, &ret);
409
- if (ret.tag == RB_JS_ABI_HOST_RAW_INTEGER_F64) {
410
- result = rb_float_new(ret.val.f64);
410
+ if (ret.tag == RB_JS_ABI_HOST_RAW_INTEGER_AS_FLOAT) {
411
+ result = rb_float_new(ret.val.as_float);
411
412
  } else {
412
- result = DBL2NUM(rb_cstr_to_dbl(ret.val.bignum.ptr, FALSE));
413
+ result = DBL2NUM(rb_cstr_to_dbl((const char *)ret.val.bignum.ptr, FALSE));
413
414
  }
414
415
  rb_js_abi_host_raw_integer_free(&ret);
415
416
  return result;
@@ -437,9 +438,14 @@ static VALUE _rb_js_import_from_js(VALUE obj) {
437
438
  * Returns +obj+ wrapped by JS class RbValue.
438
439
  */
439
440
  static VALUE _rb_js_obj_wrap(VALUE obj, VALUE wrapping) {
441
+ #if JS_ENABLE_COMPONENT_MODEL
442
+ rb_abi_stage_rb_value_to_js(wrapping);
443
+ return jsvalue_s_new(rb_js_abi_host_rb_object_to_js_rb_value());
444
+ #else
440
445
  rb_abi_lend_object(wrapping);
441
446
  return jsvalue_s_new(
442
447
  rb_js_abi_host_rb_object_to_js_rb_value((uint32_t)wrapping));
448
+ #endif
443
449
  }
444
450
 
445
451
  /*
@@ -505,8 +511,13 @@ static VALUE _rb_js_false_to_js(VALUE obj) {
505
511
  * Returns +self+ as a JS::Object.
506
512
  */
507
513
  static VALUE _rb_js_proc_to_js(VALUE obj) {
514
+ #if JS_ENABLE_COMPONENT_MODEL
515
+ rb_abi_stage_rb_value_to_js(obj);
516
+ return jsvalue_s_new(ruby_js_js_runtime_proc_to_js_function());
517
+ #else
508
518
  rb_abi_lend_object(obj);
509
519
  return jsvalue_s_new(rb_js_abi_host_proc_to_js_function((uint32_t)obj));
520
+ #endif
510
521
  }
511
522
 
512
523
  /*
data/ext/js/types.h ADDED
@@ -0,0 +1,103 @@
1
+ #ifndef RUBY_WASM_JS_TYPES_H
2
+ #define RUBY_WASM_JS_TYPES_H
3
+
4
+ #ifdef JS_ENABLE_COMPONENT_MODEL
5
+ # include "bindgen/ext.h"
6
+
7
+ typedef exports_ruby_js_ruby_runtime_borrow_rb_abi_value_t
8
+ rb_abi_guest_rb_abi_value_t;
9
+ typedef exports_ruby_js_ruby_runtime_own_rb_abi_value_t
10
+ rb_abi_guest_own_rb_abi_value_t;
11
+ typedef exports_ruby_js_ruby_runtime_list_borrow_rb_abi_value_t
12
+ rb_abi_guest_list_rb_abi_value_t;
13
+ typedef exports_ruby_js_ruby_runtime_own_rb_iseq_t rb_abi_guest_rb_iseq_t;
14
+ typedef exports_ruby_js_ruby_runtime_rb_id_t rb_abi_guest_rb_id_t;
15
+ typedef exports_ruby_js_ruby_runtime_tuple2_own_rb_abi_value_s32_t
16
+ rb_abi_guest_tuple2_rb_abi_value_s32_t;
17
+
18
+ typedef ruby_js_js_runtime_borrow_js_abi_value_t rb_js_abi_host_js_abi_value_t;
19
+ typedef ruby_js_js_runtime_own_js_abi_value_t rb_js_abi_host_own_js_abi_value_t;
20
+ typedef ruby_js_js_runtime_js_abi_result_t rb_js_abi_host_js_abi_result_t;
21
+ typedef ruby_js_js_runtime_list_borrow_js_abi_value_t
22
+ rb_js_abi_host_list_js_abi_value_t;
23
+ typedef ruby_js_js_runtime_raw_integer_t rb_js_abi_host_raw_integer_t;
24
+
25
+ typedef ext_string_t rb_abi_guest_string_t;
26
+ typedef ext_string_t rb_js_abi_host_string_t;
27
+ typedef ext_list_string_t rb_abi_guest_list_string_t;
28
+
29
+ # define borrow_js_value(v) ruby_js_js_runtime_borrow_js_abi_value(v)
30
+
31
+ # define rb_abi_guest_rb_abi_value_new(val) \
32
+ exports_ruby_js_ruby_runtime_rb_abi_value_new(val)
33
+ # define rb_abi_guest_rb_abi_value_get(val) (*(val))
34
+ # define rb_abi_guest_rb_iseq_new(val) \
35
+ exports_ruby_js_ruby_runtime_rb_iseq_new(val)
36
+ # define rb_js_abi_host_js_value_equal(lhs, rhs) \
37
+ ruby_js_js_runtime_js_value_equal(borrow_js_value(lhs), \
38
+ borrow_js_value(rhs))
39
+ # define rb_js_abi_host_reflect_apply(target, this, args, ret) \
40
+ ruby_js_js_runtime_reflect_apply(borrow_js_value(target), \
41
+ borrow_js_value(this), args, ret)
42
+ # define rb_js_abi_host_js_value_to_integer(value, ret) \
43
+ ruby_js_js_runtime_js_value_to_integer(borrow_js_value(value), ret)
44
+ # define rb_js_abi_host_export_js_value_to_host(value) \
45
+ ruby_js_js_runtime_export_js_value_to_host(borrow_js_value(value))
46
+ # define rb_js_abi_host_raw_integer_free(ptr) \
47
+ ruby_js_js_runtime_raw_integer_free(ptr)
48
+ # define rb_js_abi_host_rb_object_to_js_rb_value(val) \
49
+ ruby_js_js_runtime_rb_object_to_js_rb_value(val)
50
+ # define rb_js_abi_host_int_to_js_number(val) \
51
+ ruby_js_js_runtime_int_to_js_number(val)
52
+ # define rb_js_abi_host_float_to_js_number(val) \
53
+ ruby_js_js_runtime_float_to_js_number(val)
54
+ # define rb_js_abi_host_string_to_js_string(val) \
55
+ ruby_js_js_runtime_string_to_js_string(val)
56
+ # define rb_js_abi_host_bool_to_js_bool(val) \
57
+ ruby_js_js_runtime_bool_to_js_bool(val)
58
+ # define rb_js_abi_host_import_js_value_from_host() \
59
+ ruby_js_js_runtime_import_js_value_from_host()
60
+ # define rb_js_abi_host_js_value_to_string(value, ret) \
61
+ ruby_js_js_runtime_js_value_to_string(borrow_js_value(value), ret)
62
+ # define rb_js_abi_host_js_value_typeof(value, ret) \
63
+ ruby_js_js_runtime_js_value_typeof(borrow_js_value(value), ret)
64
+ # define rb_js_abi_host_js_value_strictly_equal(lhs, rhs) \
65
+ ruby_js_js_runtime_js_value_strictly_equal(borrow_js_value(lhs), \
66
+ borrow_js_value(rhs))
67
+ # define rb_js_abi_host_reflect_get(target, key, ret) \
68
+ ruby_js_js_runtime_reflect_get(borrow_js_value(target), key, ret)
69
+ # define rb_js_abi_host_reflect_set(target, key, value, ret) \
70
+ ruby_js_js_runtime_reflect_set(borrow_js_value(target), key, \
71
+ borrow_js_value(value), ret)
72
+ # define rb_js_abi_host_global_this() ruby_js_js_runtime_global_this()
73
+ # define rb_js_abi_host_instance_of(value, klass) \
74
+ ruby_js_js_runtime_instance_of(borrow_js_value(value), \
75
+ borrow_js_value(klass))
76
+ # define rb_js_abi_host_is_js(value) \
77
+ ruby_js_js_runtime_is_js(borrow_js_value(value))
78
+ # define rb_js_abi_host_eval_js(code, ret) \
79
+ ruby_js_js_runtime_eval_js(code, ret)
80
+
81
+ # define rb_js_abi_host_js_abi_value_free(ptr) \
82
+ ruby_js_js_runtime_js_abi_value_drop_own(*ptr)
83
+
84
+ # define RB_JS_ABI_HOST_RAW_INTEGER_AS_FLOAT \
85
+ RUBY_JS_JS_RUNTIME_RAW_INTEGER_AS_FLOAT
86
+ # define RB_JS_ABI_HOST_JS_ABI_RESULT_FAILURE \
87
+ RUBY_JS_JS_RUNTIME_JS_ABI_RESULT_FAILURE
88
+
89
+ void rb_abi_stage_rb_value_to_js(VALUE value);
90
+
91
+ #else
92
+ # include "bindgen/legacy/rb-abi-guest.h"
93
+ # include "bindgen/legacy/rb-js-abi-host.h"
94
+ typedef rb_abi_guest_rb_abi_value_t rb_abi_guest_own_rb_abi_value_t;
95
+ typedef rb_js_abi_host_js_abi_value_t rb_js_abi_host_own_js_abi_value_t;
96
+
97
+ # define borrow_js_value(v) v
98
+
99
+ # define rb_js_abi_host_js_abi_value_free(ptr) \
100
+ rb_js_abi_host_js_abi_value_free(ptr)
101
+ #endif
102
+
103
+ #endif // RUBY_WASM_JS_TYPES_H
@@ -17,7 +17,7 @@ static VALUE rb_eval_string_value_protect(VALUE str, int *pstate) {
17
17
 
18
18
  #define TAG_NONE 0
19
19
 
20
- #include "bindgen/rb-abi-guest.h"
20
+ #include "types.h"
21
21
 
22
22
  __attribute__((import_module("asyncify"), import_name("start_unwind"))) void
23
23
  asyncify_start_unwind(void *buf);
@@ -55,10 +55,18 @@ void *rb_wasm_handle_fiber_unwind(void (**new_fiber_entry)(void *, void *),
55
55
 
56
56
  static bool rb_should_prohibit_rewind = false;
57
57
 
58
+ #ifdef JS_ENABLE_COMPONENT_MODEL
59
+ void rb_wasm_throw_prohibit_rewind_exception(const char *c_msg,
60
+ size_t msg_len) {
61
+ ext_string_t message = {.ptr = (uint8_t *)c_msg, .len = msg_len};
62
+ ruby_js_js_runtime_throw_prohibit_rewind_exception(&message);
63
+ }
64
+ #else
58
65
  __attribute__((import_module("rb-js-abi-host"),
59
66
  import_name("rb_wasm_throw_prohibit_rewind_exception")))
60
67
  __attribute__((noreturn)) void
61
68
  rb_wasm_throw_prohibit_rewind_exception(const char *c_msg, size_t msg_len);
69
+ #endif
62
70
 
63
71
  #define RB_WASM_CHECK_REWIND_PROHIBITED(msg) \
64
72
  /* \
@@ -122,7 +130,7 @@ rb_wasm_throw_prohibit_rewind_exception(const char *c_msg, size_t msg_len);
122
130
  { \
123
131
  new_args = alloca(sizeof(char *) * ((list)->len + 1)); \
124
132
  for (size_t i = 0; i < (list)->len; i++) { \
125
- new_args[i] = (list)->ptr[i].ptr; \
133
+ new_args[i] = (char *)((list)->ptr[i].ptr); \
126
134
  } \
127
135
  }
128
136
 
@@ -176,6 +184,16 @@ void rb_abi_guest_rb_abi_value_dtor(void *data) {
176
184
  assert(state == TAG_NONE && "rb_abi_guest_rb_abi_value_dtor_internal failed");
177
185
  }
178
186
 
187
+ #ifdef JS_ENABLE_COMPONENT_MODEL
188
+ void exports_ruby_js_ruby_runtime_rb_iseq_destructor(
189
+ exports_ruby_js_ruby_runtime_rb_iseq_t *rep) {}
190
+
191
+ void exports_ruby_js_ruby_runtime_rb_abi_value_destructor(
192
+ exports_ruby_js_ruby_runtime_rb_abi_value_t *rep) {
193
+ rb_abi_guest_rb_abi_value_dtor((void *)rep);
194
+ }
195
+ #endif
196
+
179
197
  // MARK: - Exported functions
180
198
  // NOTE: Assume that callers always pass null terminated string by
181
199
  // rb_abi_guest_string_t
@@ -209,7 +227,7 @@ rb_abi_guest_ruby_options(rb_abi_guest_list_string_t *args) {
209
227
  }
210
228
 
211
229
  void rb_abi_guest_ruby_script(rb_abi_guest_string_t *name) {
212
- RB_WASM_LIB_RT(ruby_script(name->ptr))
230
+ RB_WASM_LIB_RT(ruby_script((const char *)name->ptr))
213
231
  }
214
232
 
215
233
  void rb_abi_guest_ruby_init_loadpath(void) {
@@ -220,7 +238,7 @@ void rb_abi_guest_rb_eval_string_protect(
220
238
  rb_abi_guest_string_t *str, rb_abi_guest_tuple2_rb_abi_value_s32_t *ret0) {
221
239
  VALUE retval;
222
240
  RB_WASM_DEBUG_LOG("rb_eval_string_protect: str = %s\n", str->ptr);
223
- VALUE utf8_str = rb_utf8_str_new(str->ptr, str->len);
241
+ VALUE utf8_str = rb_utf8_str_new((const char *)str->ptr, str->len);
224
242
  RB_WASM_LIB_RT(retval = rb_eval_string_value_protect(utf8_str, &ret0->f1));
225
243
  RB_WASM_DEBUG_LOG("rb_eval_string_protect: retval = %p, state = %d\n",
226
244
  (void *)retval, ret0->f1);
@@ -266,10 +284,10 @@ void rb_abi_guest_rb_funcallv_protect(
266
284
  }
267
285
 
268
286
  rb_abi_guest_rb_id_t rb_abi_guest_rb_intern(rb_abi_guest_string_t *name) {
269
- return rb_intern(name->ptr);
287
+ return rb_intern((const char *)name->ptr);
270
288
  }
271
289
 
272
- rb_abi_guest_rb_abi_value_t rb_abi_guest_rb_errinfo(void) {
290
+ rb_abi_guest_own_rb_abi_value_t rb_abi_guest_rb_errinfo(void) {
273
291
  VALUE retval;
274
292
  RB_WASM_LIB_RT(retval = rb_errinfo());
275
293
  rb_abi_lend_object(retval);
@@ -322,4 +340,118 @@ bool rb_abi_guest_rb_set_should_prohibit_rewind(bool value) {
322
340
  return old;
323
341
  }
324
342
 
343
+ static VALUE rb_abi_export_stage = Qnil;
344
+ static rb_abi_guest_own_rb_abi_value_t rb_abi_export_rb_value_to_js(void) {
345
+ VALUE staged = rb_abi_export_stage;
346
+ rb_abi_export_stage = Qnil;
347
+ rb_abi_lend_object(staged);
348
+ return rb_abi_guest_rb_abi_value_new((void *)staged);
349
+ }
350
+
351
+ void rb_abi_stage_rb_value_to_js(VALUE value) {
352
+ assert(rb_abi_export_stage == Qnil &&
353
+ "rb_abi_stage_rb_value_to_js: stage is not empty!?");
354
+ rb_abi_export_stage = value;
355
+ }
356
+
357
+ #ifdef JS_ENABLE_COMPONENT_MODEL
358
+
359
+ extern void __wasm_call_ctors(void);
360
+ static inline void __wasm_call_ctors_if_needed(void) {
361
+ static bool __wasm_call_ctors_done = false;
362
+ if (!__wasm_call_ctors_done) {
363
+ __wasm_call_ctors_done = true;
364
+ __wasm_call_ctors();
365
+
366
+ __attribute__((weak)) extern void __wasi_vfs_rt_init(void);
367
+ if (__wasi_vfs_rt_init) {
368
+ __wasi_vfs_rt_init();
369
+ }
370
+ }
371
+ }
372
+
373
+ // Exported Functions from `ruby:js/ruby-runtime`
374
+ void exports_ruby_js_ruby_runtime_ruby_show_version(void) {
375
+ __wasm_call_ctors_if_needed();
376
+ rb_abi_guest_ruby_show_version();
377
+ }
378
+ void exports_ruby_js_ruby_runtime_ruby_init(void) {
379
+ __wasm_call_ctors_if_needed();
380
+ rb_abi_guest_ruby_init();
381
+ }
382
+ void exports_ruby_js_ruby_runtime_ruby_sysinit(ext_list_string_t *args) {
383
+ __wasm_call_ctors_if_needed();
384
+ rb_abi_guest_ruby_sysinit(args);
385
+ }
386
+ exports_ruby_js_ruby_runtime_own_rb_iseq_t
387
+ exports_ruby_js_ruby_runtime_ruby_options(ext_list_string_t *args) {
388
+ __wasm_call_ctors_if_needed();
389
+ return rb_abi_guest_ruby_options(args);
390
+ }
391
+ void exports_ruby_js_ruby_runtime_ruby_script(ext_string_t *name) {
392
+ __wasm_call_ctors_if_needed();
393
+ rb_abi_guest_ruby_script(name);
394
+ }
395
+ void exports_ruby_js_ruby_runtime_ruby_init_loadpath(void) {
396
+ __wasm_call_ctors_if_needed();
397
+ rb_abi_guest_ruby_init_loadpath();
398
+ }
399
+ void exports_ruby_js_ruby_runtime_rb_eval_string_protect(
400
+ ext_string_t *str,
401
+ exports_ruby_js_ruby_runtime_tuple2_own_rb_abi_value_s32_t *ret) {
402
+ __wasm_call_ctors_if_needed();
403
+ rb_abi_guest_rb_eval_string_protect(str, ret);
404
+ }
405
+ void exports_ruby_js_ruby_runtime_rb_funcallv_protect(
406
+ exports_ruby_js_ruby_runtime_borrow_rb_abi_value_t recv,
407
+ exports_ruby_js_ruby_runtime_rb_id_t mid,
408
+ exports_ruby_js_ruby_runtime_list_borrow_rb_abi_value_t *args,
409
+ exports_ruby_js_ruby_runtime_tuple2_own_rb_abi_value_s32_t *ret) {
410
+ __wasm_call_ctors_if_needed();
411
+ rb_abi_guest_rb_funcallv_protect(recv, mid, args, ret);
412
+ }
413
+ exports_ruby_js_ruby_runtime_rb_id_t
414
+ exports_ruby_js_ruby_runtime_rb_intern(ext_string_t *name) {
415
+ __wasm_call_ctors_if_needed();
416
+ return rb_abi_guest_rb_intern(name);
417
+ }
418
+ exports_ruby_js_ruby_runtime_own_rb_abi_value_t
419
+ exports_ruby_js_ruby_runtime_rb_errinfo(void) {
420
+ __wasm_call_ctors_if_needed();
421
+ return rb_abi_guest_rb_errinfo();
422
+ }
423
+ void exports_ruby_js_ruby_runtime_rb_clear_errinfo(void) {
424
+ __wasm_call_ctors_if_needed();
425
+ rb_abi_guest_rb_clear_errinfo();
426
+ }
427
+ void exports_ruby_js_ruby_runtime_rstring_ptr(
428
+ exports_ruby_js_ruby_runtime_borrow_rb_abi_value_t value,
429
+ ext_string_t *ret) {
430
+ __wasm_call_ctors_if_needed();
431
+ rb_abi_guest_rstring_ptr(value, ret);
432
+ }
433
+ void exports_ruby_js_ruby_runtime_rb_vm_bugreport(void) {
434
+ __wasm_call_ctors_if_needed();
435
+ rb_abi_guest_rb_vm_bugreport();
436
+ }
437
+ bool exports_ruby_js_ruby_runtime_rb_gc_enable(void) {
438
+ __wasm_call_ctors_if_needed();
439
+ return rb_abi_guest_rb_gc_enable();
440
+ }
441
+ bool exports_ruby_js_ruby_runtime_rb_gc_disable(void) {
442
+ __wasm_call_ctors_if_needed();
443
+ return rb_abi_guest_rb_gc_disable();
444
+ }
445
+ bool exports_ruby_js_ruby_runtime_rb_set_should_prohibit_rewind(
446
+ bool new_value) {
447
+ __wasm_call_ctors_if_needed();
448
+ return rb_abi_guest_rb_set_should_prohibit_rewind(new_value);
449
+ }
450
+ exports_ruby_js_ruby_runtime_own_rb_abi_value_t
451
+ exports_ruby_js_ruby_runtime_export_rb_value_to_js(void) {
452
+ __wasm_call_ctors_if_needed();
453
+ return rb_abi_export_rb_value_to_js();
454
+ }
455
+ #endif
456
+
325
457
  void Init_witapi(void) {}