js 2.5.0 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/js/bindgen/ext.c +552 -0
- data/ext/js/bindgen/ext.h +170 -0
- data/ext/js/bindgen/ext_component_type.o +0 -0
- data/ext/js/bindgen/{rb-js-abi-host.c → legacy/rb-js-abi-host.c} +2 -2
- data/ext/js/bindgen/{rb-js-abi-host.h → legacy/rb-js-abi-host.h} +2 -2
- data/ext/js/bindgen/{rb-js-abi-host.wit → legacy/rb-js-abi-host.wit} +1 -1
- data/ext/js/depend +10 -3
- data/ext/js/extconf.rb +16 -2
- data/ext/js/js-core.c +35 -13
- data/ext/js/types.h +103 -0
- data/ext/{witapi → js}/witapi-core.c +138 -6
- data/js.gemspec +1 -1
- data/lib/js/version.rb +1 -1
- data/lib/js.rb +19 -3
- data/wit/js-runtime.wit +45 -0
- data/wit/ruby-runtime.wit +43 -0
- data/wit/world.wit +6 -0
- metadata +17 -17
- data/ext/witapi/bindgen/.clang-format +0 -2
- data/ext/witapi/depend +0 -11
- data/ext/witapi/extconf.rb +0 -3
- /data/ext/{witapi/bindgen → js/bindgen/legacy}/rb-abi-guest.c +0 -0
- /data/ext/{witapi/bindgen → js/bindgen/legacy}/rb-abi-guest.h +0 -0
- /data/ext/{witapi/bindgen → js/bindgen/legacy}/rb-abi-guest.wit +0 -0
|
@@ -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 {
|
|
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.
|
|
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
|
|
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
|
|
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 {
|
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
|
|
3
|
-
|
|
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 "
|
|
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
|
-
|
|
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(
|
|
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);
|
|
@@ -200,6 +200,11 @@ static VALUE _rb_js_obj_aref(VALUE obj, VALUE key) {
|
|
|
200
200
|
static VALUE _rb_js_obj_aset(VALUE obj, VALUE key, VALUE val) {
|
|
201
201
|
struct jsvalue *p = check_jsvalue(obj);
|
|
202
202
|
VALUE rv = _rb_js_try_convert(rb_mJS, val);
|
|
203
|
+
if (rv == Qnil) {
|
|
204
|
+
rb_raise(rb_eTypeError,
|
|
205
|
+
"wrong argument type %s (expected JS::Object like object)",
|
|
206
|
+
rb_class2name(rb_obj_class(val)));
|
|
207
|
+
}
|
|
203
208
|
struct jsvalue *v = check_jsvalue(rv);
|
|
204
209
|
rb_js_abi_host_string_t key_abi_str;
|
|
205
210
|
key = rb_obj_as_string(key);
|
|
@@ -235,8 +240,14 @@ static VALUE _rb_js_obj_strictly_eql(VALUE obj, VALUE other) {
|
|
|
235
240
|
* Performs "==" comparison, a.k.a the "Abstract Equality Comparison"
|
|
236
241
|
* algorithm defined in the ECMAScript.
|
|
237
242
|
* https://262.ecma-international.org/11.0/#sec-abstract-equality-comparison
|
|
243
|
+
* If the given other object is not a JS::Object, try to convert it to a
|
|
244
|
+
* JS::Object using JS.try_convert. If the conversion fails, returns false.
|
|
238
245
|
*/
|
|
239
246
|
static VALUE _rb_js_obj_eql(VALUE obj, VALUE other) {
|
|
247
|
+
other = _rb_js_try_convert(rb_mJS, other);
|
|
248
|
+
if (other == Qnil) {
|
|
249
|
+
return Qfalse;
|
|
250
|
+
}
|
|
240
251
|
struct jsvalue *lhs = check_jsvalue(obj);
|
|
241
252
|
struct jsvalue *rhs = check_jsvalue(other);
|
|
242
253
|
bool result = rb_js_abi_host_js_value_equal(lhs->abi, rhs->abi);
|
|
@@ -285,14 +296,15 @@ static VALUE _rb_js_obj_call(int argc, VALUE *argv, VALUE obj) {
|
|
|
285
296
|
rb_raise(rb_eTypeError, "argument %d is not a JS::Object like object",
|
|
286
297
|
1 + i);
|
|
287
298
|
}
|
|
288
|
-
abi_args.ptr[i - 1] = check_jsvalue(arg)->abi;
|
|
299
|
+
abi_args.ptr[i - 1] = borrow_js_value(check_jsvalue(arg)->abi);
|
|
289
300
|
rb_ary_push(rv_args, arg);
|
|
290
301
|
}
|
|
291
302
|
|
|
292
303
|
if (rb_block_given_p()) {
|
|
293
304
|
VALUE proc = rb_block_proc();
|
|
294
305
|
VALUE rb_proc = _rb_js_try_convert(rb_mJS, proc);
|
|
295
|
-
abi_args.ptr[function_arguments_count - 1] =
|
|
306
|
+
abi_args.ptr[function_arguments_count - 1] =
|
|
307
|
+
borrow_js_value(check_jsvalue(rb_proc)->abi);
|
|
296
308
|
rb_ary_push(rv_args, rb_proc);
|
|
297
309
|
}
|
|
298
310
|
|
|
@@ -321,7 +333,7 @@ static VALUE _rb_js_obj_typeof(VALUE obj) {
|
|
|
321
333
|
struct jsvalue *p = check_jsvalue(obj);
|
|
322
334
|
rb_js_abi_host_string_t ret0;
|
|
323
335
|
rb_js_abi_host_js_value_typeof(p->abi, &ret0);
|
|
324
|
-
return rb_str_new(ret0.ptr, ret0.len);
|
|
336
|
+
return rb_str_new((const char *)ret0.ptr, ret0.len);
|
|
325
337
|
}
|
|
326
338
|
|
|
327
339
|
/*
|
|
@@ -341,7 +353,7 @@ static VALUE _rb_js_obj_to_s(VALUE obj) {
|
|
|
341
353
|
struct jsvalue *p = check_jsvalue(obj);
|
|
342
354
|
rb_js_abi_host_string_t ret0;
|
|
343
355
|
rb_js_abi_host_js_value_to_string(p->abi, &ret0);
|
|
344
|
-
return rb_utf8_str_new(ret0.ptr, ret0.len);
|
|
356
|
+
return rb_utf8_str_new((const char *)ret0.ptr, ret0.len);
|
|
345
357
|
}
|
|
346
358
|
|
|
347
359
|
/*
|
|
@@ -365,10 +377,10 @@ static VALUE _rb_js_obj_to_i(VALUE obj) {
|
|
|
365
377
|
rb_js_abi_host_raw_integer_t ret;
|
|
366
378
|
rb_js_abi_host_js_value_to_integer(p->abi, &ret);
|
|
367
379
|
VALUE result;
|
|
368
|
-
if (ret.tag ==
|
|
369
|
-
result = rb_dbl2big(ret.val.
|
|
380
|
+
if (ret.tag == RB_JS_ABI_HOST_RAW_INTEGER_AS_FLOAT) {
|
|
381
|
+
result = rb_dbl2big(ret.val.as_float);
|
|
370
382
|
} else {
|
|
371
|
-
result = rb_cstr2inum(ret.val.bignum.ptr, 10);
|
|
383
|
+
result = rb_cstr2inum((const char *)ret.val.bignum.ptr, 10);
|
|
372
384
|
}
|
|
373
385
|
rb_js_abi_host_raw_integer_free(&ret);
|
|
374
386
|
return result;
|
|
@@ -395,10 +407,10 @@ static VALUE _rb_js_obj_to_f(VALUE obj) {
|
|
|
395
407
|
rb_js_abi_host_raw_integer_t ret;
|
|
396
408
|
VALUE result;
|
|
397
409
|
rb_js_abi_host_js_value_to_integer(p->abi, &ret);
|
|
398
|
-
if (ret.tag ==
|
|
399
|
-
result = rb_float_new(ret.val.
|
|
410
|
+
if (ret.tag == RB_JS_ABI_HOST_RAW_INTEGER_AS_FLOAT) {
|
|
411
|
+
result = rb_float_new(ret.val.as_float);
|
|
400
412
|
} else {
|
|
401
|
-
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));
|
|
402
414
|
}
|
|
403
415
|
rb_js_abi_host_raw_integer_free(&ret);
|
|
404
416
|
return result;
|
|
@@ -426,9 +438,14 @@ static VALUE _rb_js_import_from_js(VALUE obj) {
|
|
|
426
438
|
* Returns +obj+ wrapped by JS class RbValue.
|
|
427
439
|
*/
|
|
428
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
|
|
429
445
|
rb_abi_lend_object(wrapping);
|
|
430
446
|
return jsvalue_s_new(
|
|
431
447
|
rb_js_abi_host_rb_object_to_js_rb_value((uint32_t)wrapping));
|
|
448
|
+
#endif
|
|
432
449
|
}
|
|
433
450
|
|
|
434
451
|
/*
|
|
@@ -494,8 +511,13 @@ static VALUE _rb_js_false_to_js(VALUE obj) {
|
|
|
494
511
|
* Returns +self+ as a JS::Object.
|
|
495
512
|
*/
|
|
496
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
|
|
497
518
|
rb_abi_lend_object(obj);
|
|
498
519
|
return jsvalue_s_new(rb_js_abi_host_proc_to_js_function((uint32_t)obj));
|
|
520
|
+
#endif
|
|
499
521
|
}
|
|
500
522
|
|
|
501
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
|