js 2.6.2 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/js/bindgen/ext.c +2 -49
- data/ext/js/bindgen/ext.h +1 -18
- data/ext/js/bindgen/ext_component_type.o +0 -0
- data/ext/js/bindgen/legacy/rb-abi-guest.c +3 -52
- data/ext/js/bindgen/legacy/rb-abi-guest.h +1 -15
- data/ext/js/bindgen/legacy/rb-abi-guest.wit +1 -5
- data/ext/js/extconf.rb +1 -1
- data/ext/js/js-core.c +17 -4
- data/ext/js/types.h +0 -1
- data/ext/js/witapi-core.c +8 -38
- data/lib/js/require_remote/url_resolver.rb +4 -0
- data/lib/js/require_remote.rb +16 -0
- data/lib/js/version.rb +1 -1
- data/lib/js.rb +53 -17
- data/wit/js-runtime.wit +2 -2
- data/wit/ruby-runtime.wit +1 -5
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f322c0e5d521f68cd2b3f105afecd8b93b7372a3320df538a7fed9c124e6c53
|
4
|
+
data.tar.gz: 8286d36e16bc367780fed3f12e9189b3cbaf79945e7768e0718bea3529fdc528
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cb9831474ab99228f8c38634ee6e3bfed2e6b1cc48e414267826cb37d5ba0b8d2a8d9d57b39b3075c4c96ecefaf28aa762cf332dcfd2a4992e872ed423593a5
|
7
|
+
data.tar.gz: 35b2224562bd4c50894419a454bfc165af4be9d63c2a636f2f311ad16b466b0e717d4e9004faa9d74ff9d6f0d17a2c2904452cf130a8e80cced40c806b47bc10
|
data/ext/js/bindgen/ext.c
CHANGED
@@ -78,9 +78,6 @@ extern void __wasm_import_ruby_js_js_runtime_throw_prohibit_rewind_exception(uin
|
|
78
78
|
|
79
79
|
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
81
|
__attribute__((__weak__, __export_name__("cabi_post_ruby:js/ruby-runtime#rstring-ptr")))
|
85
82
|
void __wasm_export_exports_ruby_js_ruby_runtime_rstring_ptr_post_return(uint8_t * arg0) {
|
86
83
|
if ((*((size_t*) (arg0 + 4))) > 0) {
|
@@ -150,32 +147,6 @@ void ruby_js_js_runtime_list_borrow_js_abi_value_free(ruby_js_js_runtime_list_bo
|
|
150
147
|
}
|
151
148
|
}
|
152
149
|
|
153
|
-
__attribute__((__import_module__("[export]ruby:js/ruby-runtime"), __import_name__("[resource-drop]rb-iseq")))
|
154
|
-
extern void __wasm_import_exports_ruby_js_ruby_runtime_rb_iseq_drop(int32_t handle);
|
155
|
-
|
156
|
-
void exports_ruby_js_ruby_runtime_rb_iseq_drop_own(exports_ruby_js_ruby_runtime_own_rb_iseq_t handle) {
|
157
|
-
__wasm_import_exports_ruby_js_ruby_runtime_rb_iseq_drop(handle.__handle);
|
158
|
-
}
|
159
|
-
|
160
|
-
__attribute__(( __import_module__("[export]ruby:js/ruby-runtime"), __import_name__("[resource-new]rb-iseq")))
|
161
|
-
extern int32_t __wasm_import_exports_ruby_js_ruby_runtime_rb_iseq_new(int32_t);
|
162
|
-
|
163
|
-
__attribute__((__import_module__("[export]ruby:js/ruby-runtime"), __import_name__("[resource-rep]rb-iseq")))
|
164
|
-
extern int32_t __wasm_import_exports_ruby_js_ruby_runtime_rb_iseq_rep(int32_t);
|
165
|
-
|
166
|
-
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) {
|
167
|
-
return (exports_ruby_js_ruby_runtime_own_rb_iseq_t) { __wasm_import_exports_ruby_js_ruby_runtime_rb_iseq_new((int32_t) rep) };
|
168
|
-
}
|
169
|
-
|
170
|
-
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) {
|
171
|
-
return (exports_ruby_js_ruby_runtime_rb_iseq_t*) __wasm_import_exports_ruby_js_ruby_runtime_rb_iseq_rep(handle.__handle);
|
172
|
-
}
|
173
|
-
|
174
|
-
__attribute__((__export_name__("ruby:js/ruby-runtime#[dtor]rb_iseq")))
|
175
|
-
void __wasm_export_exports_ruby_js_ruby_runtime_rb_iseq_dtor(exports_ruby_js_ruby_runtime_rb_iseq_t* arg) {
|
176
|
-
exports_ruby_js_ruby_runtime_rb_iseq_destructor(arg);
|
177
|
-
}
|
178
|
-
|
179
150
|
__attribute__((__import_module__("[export]ruby:js/ruby-runtime"), __import_name__("[resource-drop]rb-abi-value")))
|
180
151
|
extern void __wasm_import_exports_ruby_js_ruby_runtime_rb_abi_value_drop(int32_t handle);
|
181
152
|
|
@@ -437,27 +408,9 @@ void __wasm_export_exports_ruby_js_ruby_runtime_ruby_show_version(void) {
|
|
437
408
|
}
|
438
409
|
|
439
410
|
__attribute__((__export_name__("ruby:js/ruby-runtime#ruby-init")))
|
440
|
-
void __wasm_export_exports_ruby_js_ruby_runtime_ruby_init(
|
441
|
-
exports_ruby_js_ruby_runtime_ruby_init();
|
442
|
-
}
|
443
|
-
|
444
|
-
__attribute__((__export_name__("ruby:js/ruby-runtime#ruby-sysinit")))
|
445
|
-
void __wasm_export_exports_ruby_js_ruby_runtime_ruby_sysinit(uint8_t * arg, size_t arg0) {
|
411
|
+
void __wasm_export_exports_ruby_js_ruby_runtime_ruby_init(uint8_t * arg, size_t arg0) {
|
446
412
|
ext_list_string_t arg1 = (ext_list_string_t) { (ext_string_t*)(arg), (arg0) };
|
447
|
-
|
448
|
-
}
|
449
|
-
|
450
|
-
__attribute__((__export_name__("ruby:js/ruby-runtime#ruby-options")))
|
451
|
-
int32_t __wasm_export_exports_ruby_js_ruby_runtime_ruby_options(uint8_t * arg, size_t arg0) {
|
452
|
-
ext_list_string_t arg1 = (ext_list_string_t) { (ext_string_t*)(arg), (arg0) };
|
453
|
-
exports_ruby_js_ruby_runtime_own_rb_iseq_t ret = exports_ruby_js_ruby_runtime_ruby_options(&arg1);
|
454
|
-
return (ret).__handle;
|
455
|
-
}
|
456
|
-
|
457
|
-
__attribute__((__export_name__("ruby:js/ruby-runtime#ruby-script")))
|
458
|
-
void __wasm_export_exports_ruby_js_ruby_runtime_ruby_script(uint8_t * arg, size_t arg0) {
|
459
|
-
ext_string_t arg1 = (ext_string_t) { (uint8_t*)(arg), (arg0) };
|
460
|
-
exports_ruby_js_ruby_runtime_ruby_script(&arg1);
|
413
|
+
exports_ruby_js_ruby_runtime_ruby_init(&arg1);
|
461
414
|
}
|
462
415
|
|
463
416
|
__attribute__((__export_name__("ruby:js/ruby-runtime#ruby-init-loadpath")))
|
data/ext/js/bindgen/ext.h
CHANGED
@@ -48,14 +48,6 @@ typedef struct ruby_js_js_runtime_list_borrow_js_abi_value_t {
|
|
48
48
|
size_t len;
|
49
49
|
} ruby_js_js_runtime_list_borrow_js_abi_value_t;
|
50
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
51
|
typedef struct exports_ruby_js_ruby_runtime_own_rb_abi_value_t {
|
60
52
|
int32_t __handle;
|
61
53
|
} exports_ruby_js_ruby_runtime_own_rb_abi_value_t;
|
@@ -108,10 +100,7 @@ extern void ruby_js_js_runtime_throw_prohibit_rewind_exception(ext_string_t *mes
|
|
108
100
|
|
109
101
|
// Exported Functions from `ruby:js/ruby-runtime`
|
110
102
|
void exports_ruby_js_ruby_runtime_ruby_show_version(void);
|
111
|
-
void exports_ruby_js_ruby_runtime_ruby_init(
|
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);
|
103
|
+
void exports_ruby_js_ruby_runtime_ruby_init(ext_list_string_t *args);
|
115
104
|
void exports_ruby_js_ruby_runtime_ruby_init_loadpath(void);
|
116
105
|
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
106
|
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);
|
@@ -137,12 +126,6 @@ void ruby_js_js_runtime_raw_integer_free(ruby_js_js_runtime_raw_integer_t *ptr);
|
|
137
126
|
|
138
127
|
void ruby_js_js_runtime_list_borrow_js_abi_value_free(ruby_js_js_runtime_list_borrow_js_abi_value_t *ptr);
|
139
128
|
|
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
129
|
extern void exports_ruby_js_ruby_runtime_rb_abi_value_drop_own(exports_ruby_js_ruby_runtime_own_rb_abi_value_t handle);
|
147
130
|
|
148
131
|
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);
|
Binary file
|
@@ -14,40 +14,6 @@ size_t new_size
|
|
14
14
|
return ret;
|
15
15
|
}
|
16
16
|
|
17
|
-
__attribute__((import_module("canonical_abi"), import_name("resource_drop_rb-iseq")))
|
18
|
-
void __resource_rb_iseq_drop(uint32_t idx);
|
19
|
-
|
20
|
-
void rb_abi_guest_rb_iseq_free(rb_abi_guest_rb_iseq_t *ptr) {
|
21
|
-
__resource_rb_iseq_drop(ptr->idx);
|
22
|
-
}
|
23
|
-
|
24
|
-
__attribute__((import_module("canonical_abi"), import_name("resource_clone_rb-iseq")))
|
25
|
-
uint32_t __resource_rb_iseq_clone(uint32_t idx);
|
26
|
-
|
27
|
-
rb_abi_guest_rb_iseq_t rb_abi_guest_rb_iseq_clone(rb_abi_guest_rb_iseq_t *ptr) {
|
28
|
-
return (rb_abi_guest_rb_iseq_t){__resource_rb_iseq_clone(ptr->idx)};
|
29
|
-
}
|
30
|
-
|
31
|
-
__attribute__((import_module("canonical_abi"), import_name("resource_new_rb-iseq")))
|
32
|
-
uint32_t __resource_rb_iseq_new(uint32_t val);
|
33
|
-
|
34
|
-
rb_abi_guest_rb_iseq_t rb_abi_guest_rb_iseq_new(void *data) {
|
35
|
-
return (rb_abi_guest_rb_iseq_t){__resource_rb_iseq_new((uint32_t) data)};
|
36
|
-
}
|
37
|
-
|
38
|
-
__attribute__((import_module("canonical_abi"), import_name("resource_get_rb-iseq")))
|
39
|
-
uint32_t __resource_rb_iseq_get(uint32_t idx);
|
40
|
-
|
41
|
-
void* rb_abi_guest_rb_iseq_get(rb_abi_guest_rb_iseq_t *ptr) {
|
42
|
-
return (void*) __resource_rb_iseq_get(ptr->idx);
|
43
|
-
}
|
44
|
-
|
45
|
-
__attribute__((export_name("canonical_abi_drop_rb-iseq")))
|
46
|
-
void __resource_rb_iseq_dtor(uint32_t val) {
|
47
|
-
if (rb_abi_guest_rb_iseq_dtor)
|
48
|
-
rb_abi_guest_rb_iseq_dtor((void*) val);
|
49
|
-
}
|
50
|
-
|
51
17
|
__attribute__((import_module("canonical_abi"), import_name("resource_drop_rb-abi-value")))
|
52
18
|
void __resource_rb_abi_value_drop(uint32_t idx);
|
53
19
|
|
@@ -127,25 +93,10 @@ __attribute__((export_name("ruby-show-version: func() -> ()")))
|
|
127
93
|
void __wasm_export_rb_abi_guest_ruby_show_version(void) {
|
128
94
|
rb_abi_guest_ruby_show_version();
|
129
95
|
}
|
130
|
-
__attribute__((export_name("ruby-init: func() -> ()")))
|
131
|
-
void __wasm_export_rb_abi_guest_ruby_init(
|
132
|
-
rb_abi_guest_ruby_init();
|
133
|
-
}
|
134
|
-
__attribute__((export_name("ruby-sysinit: func(args: list<string>) -> ()")))
|
135
|
-
void __wasm_export_rb_abi_guest_ruby_sysinit(int32_t arg, int32_t arg0) {
|
96
|
+
__attribute__((export_name("ruby-init: func(args: list<string>) -> ()")))
|
97
|
+
void __wasm_export_rb_abi_guest_ruby_init(int32_t arg, int32_t arg0) {
|
136
98
|
rb_abi_guest_list_string_t arg1 = (rb_abi_guest_list_string_t) { (rb_abi_guest_string_t*)(arg), (size_t)(arg0) };
|
137
|
-
|
138
|
-
}
|
139
|
-
__attribute__((export_name("ruby-options: func(args: list<string>) -> handle<rb-iseq>")))
|
140
|
-
int32_t __wasm_export_rb_abi_guest_ruby_options(int32_t arg, int32_t arg0) {
|
141
|
-
rb_abi_guest_list_string_t arg1 = (rb_abi_guest_list_string_t) { (rb_abi_guest_string_t*)(arg), (size_t)(arg0) };
|
142
|
-
rb_abi_guest_rb_iseq_t ret = rb_abi_guest_ruby_options(&arg1);
|
143
|
-
return (ret).idx;
|
144
|
-
}
|
145
|
-
__attribute__((export_name("ruby-script: func(name: string) -> ()")))
|
146
|
-
void __wasm_export_rb_abi_guest_ruby_script(int32_t arg, int32_t arg0) {
|
147
|
-
rb_abi_guest_string_t arg1 = (rb_abi_guest_string_t) { (char*)(arg), (size_t)(arg0) };
|
148
|
-
rb_abi_guest_ruby_script(&arg1);
|
99
|
+
rb_abi_guest_ruby_init(&arg1);
|
149
100
|
}
|
150
101
|
__attribute__((export_name("ruby-init-loadpath: func() -> ()")))
|
151
102
|
void __wasm_export_rb_abi_guest_ruby_init_loadpath(void) {
|
@@ -8,17 +8,6 @@ extern "C"
|
|
8
8
|
#include <stdint.h>
|
9
9
|
#include <stdbool.h>
|
10
10
|
|
11
|
-
typedef struct {
|
12
|
-
uint32_t idx;
|
13
|
-
} rb_abi_guest_rb_iseq_t;
|
14
|
-
void rb_abi_guest_rb_iseq_free(rb_abi_guest_rb_iseq_t *ptr);
|
15
|
-
rb_abi_guest_rb_iseq_t rb_abi_guest_rb_iseq_clone(rb_abi_guest_rb_iseq_t *ptr);
|
16
|
-
rb_abi_guest_rb_iseq_t rb_abi_guest_rb_iseq_new(void *data);
|
17
|
-
void* rb_abi_guest_rb_iseq_get(rb_abi_guest_rb_iseq_t *ptr);
|
18
|
-
|
19
|
-
__attribute__((weak))
|
20
|
-
void rb_abi_guest_rb_iseq_dtor(void *data);
|
21
|
-
|
22
11
|
typedef struct {
|
23
12
|
uint32_t idx;
|
24
13
|
} rb_abi_guest_rb_abi_value_t;
|
@@ -56,10 +45,7 @@ extern "C"
|
|
56
45
|
} rb_abi_guest_list_rb_abi_value_t;
|
57
46
|
void rb_abi_guest_list_rb_abi_value_free(rb_abi_guest_list_rb_abi_value_t *ptr);
|
58
47
|
void rb_abi_guest_ruby_show_version(void);
|
59
|
-
void rb_abi_guest_ruby_init(
|
60
|
-
void rb_abi_guest_ruby_sysinit(rb_abi_guest_list_string_t *args);
|
61
|
-
rb_abi_guest_rb_iseq_t rb_abi_guest_ruby_options(rb_abi_guest_list_string_t *args);
|
62
|
-
void rb_abi_guest_ruby_script(rb_abi_guest_string_t *name);
|
48
|
+
void rb_abi_guest_ruby_init(rb_abi_guest_list_string_t *args);
|
63
49
|
void rb_abi_guest_ruby_init_loadpath(void);
|
64
50
|
void rb_abi_guest_rb_eval_string_protect(rb_abi_guest_string_t *str, rb_abi_guest_tuple2_rb_abi_value_s32_t *ret0);
|
65
51
|
void rb_abi_guest_rb_funcallv_protect(rb_abi_guest_rb_abi_value_t recv, rb_abi_guest_rb_id_t mid, rb_abi_guest_list_rb_abi_value_t *args, rb_abi_guest_tuple2_rb_abi_value_s32_t *ret0);
|
@@ -1,13 +1,9 @@
|
|
1
|
-
resource rb-iseq
|
2
1
|
resource rb-abi-value
|
3
2
|
type rb-errno = s32
|
4
3
|
type rb-id = u32
|
5
4
|
|
6
5
|
ruby-show-version: func()
|
7
|
-
ruby-init: func()
|
8
|
-
ruby-sysinit: func(args: list<string>)
|
9
|
-
ruby-options: func(args: list<string>) -> rb-iseq
|
10
|
-
ruby-script: func(name: string)
|
6
|
+
ruby-init: func(args: list<string>)
|
11
7
|
ruby-init-loadpath: func()
|
12
8
|
rb-eval-string-protect: func(str: string) -> tuple<rb-abi-value, s32>
|
13
9
|
rb-funcallv-protect: func(recv: rb-abi-value, mid: rb-id, args: list<rb-abi-value>) -> tuple<rb-abi-value, s32>
|
data/ext/js/extconf.rb
CHANGED
@@ -11,7 +11,7 @@ end
|
|
11
11
|
|
12
12
|
$objs = %w[js-core.o witapi-core.o]
|
13
13
|
|
14
|
-
use_component_model = enable_config("component-model",
|
14
|
+
use_component_model = enable_config("component-model", true)
|
15
15
|
$stderr.print "Building with component model: "
|
16
16
|
$stderr.puts use_component_model ? "\e[1;32myes\e[0m" : "\e[1;31mno\e[0m"
|
17
17
|
if use_component_model
|
data/ext/js/js-core.c
CHANGED
@@ -146,12 +146,25 @@ VALUE _rb_js_try_convert(VALUE klass, VALUE obj) {
|
|
146
146
|
* p JS.is_a?(JS.global, JS.global[:Object]) #=> true
|
147
147
|
* p JS.is_a?(JS.global, Object) #=> false
|
148
148
|
*/
|
149
|
-
static VALUE _rb_js_is_kind_of(
|
149
|
+
static VALUE _rb_js_is_kind_of(int argc, VALUE *argv, VALUE self) {
|
150
|
+
|
151
|
+
if (argc == 1) {
|
152
|
+
// If the second argument is not given, behaves as `Module#is_a?`.
|
153
|
+
return rb_obj_is_kind_of(self, argv[0]);
|
154
|
+
}
|
155
|
+
|
156
|
+
if (argc != 2) {
|
157
|
+
rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 2)",
|
158
|
+
argc);
|
159
|
+
}
|
160
|
+
|
161
|
+
VALUE obj = argv[0];
|
162
|
+
VALUE klass = argv[1];
|
150
163
|
if (!IS_JSVALUE(obj)) {
|
151
164
|
return Qfalse;
|
152
165
|
}
|
153
166
|
struct jsvalue *val = DATA_PTR(obj);
|
154
|
-
VALUE js_klass_v = _rb_js_try_convert(
|
167
|
+
VALUE js_klass_v = _rb_js_try_convert(self, klass);
|
155
168
|
struct jsvalue *js_klass = DATA_PTR(js_klass_v);
|
156
169
|
return RBOOL(rb_js_abi_host_instance_of(val->abi, js_klass->abi));
|
157
170
|
}
|
@@ -561,13 +574,13 @@ static VALUE _rb_js_proc_to_js(VALUE obj) {
|
|
561
574
|
*/
|
562
575
|
void Init_js() {
|
563
576
|
rb_mJS = rb_define_module("JS");
|
564
|
-
rb_define_module_function(rb_mJS, "is_a?", _rb_js_is_kind_of,
|
577
|
+
rb_define_module_function(rb_mJS, "is_a?", _rb_js_is_kind_of, -1);
|
565
578
|
rb_define_module_function(rb_mJS, "try_convert", _rb_js_try_convert, 1);
|
566
579
|
rb_define_module_function(rb_mJS, "eval", _rb_js_eval_js, 1);
|
567
580
|
rb_define_module_function(rb_mJS, "global", _rb_js_global_this, 0);
|
568
581
|
|
569
582
|
i_to_js = rb_intern("to_js");
|
570
|
-
rb_cJS_Object = rb_define_class_under(rb_mJS, "Object",
|
583
|
+
rb_cJS_Object = rb_define_class_under(rb_mJS, "Object", rb_cBasicObject);
|
571
584
|
VALUE rb_cJS_singleton = rb_singleton_class(rb_cJS_Object);
|
572
585
|
rb_define_alloc_func(rb_cJS_Object, jsvalue_s_allocate);
|
573
586
|
rb_define_method(rb_cJS_Object, "[]", _rb_js_obj_aref, 1);
|
data/ext/js/types.h
CHANGED
@@ -10,7 +10,6 @@ typedef exports_ruby_js_ruby_runtime_own_rb_abi_value_t
|
|
10
10
|
rb_abi_guest_own_rb_abi_value_t;
|
11
11
|
typedef exports_ruby_js_ruby_runtime_list_borrow_rb_abi_value_t
|
12
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
13
|
typedef exports_ruby_js_ruby_runtime_rb_id_t rb_abi_guest_rb_id_t;
|
15
14
|
typedef exports_ruby_js_ruby_runtime_tuple2_own_rb_abi_value_s32_t
|
16
15
|
rb_abi_guest_tuple2_rb_abi_value_s32_t;
|
data/ext/js/witapi-core.c
CHANGED
@@ -188,9 +188,6 @@ void rb_abi_guest_rb_abi_value_dtor(void *data) {
|
|
188
188
|
}
|
189
189
|
|
190
190
|
#ifdef JS_ENABLE_COMPONENT_MODEL
|
191
|
-
void exports_ruby_js_ruby_runtime_rb_iseq_destructor(
|
192
|
-
exports_ruby_js_ruby_runtime_rb_iseq_t *rep) {}
|
193
|
-
|
194
191
|
void exports_ruby_js_ruby_runtime_rb_abi_value_destructor(
|
195
192
|
exports_ruby_js_ruby_runtime_rb_abi_value_t *rep) {
|
196
193
|
rb_abi_guest_rb_abi_value_dtor((void *)rep);
|
@@ -203,36 +200,22 @@ void exports_ruby_js_ruby_runtime_rb_abi_value_destructor(
|
|
203
200
|
|
204
201
|
void rb_abi_guest_ruby_show_version(void) { ruby_show_version(); }
|
205
202
|
|
206
|
-
__attribute__((noinline)) static void
|
203
|
+
__attribute__((noinline)) static void
|
204
|
+
rb_abi_guest_ruby_init_thunk(int argc, char **c_args) {
|
207
205
|
ruby_init();
|
208
206
|
rb_abi_guest_arena_hash = rb_hash_new();
|
209
207
|
rb_abi_guest_refcount_hash = rb_hash_new();
|
210
208
|
|
211
209
|
rb_gc_register_mark_object(rb_abi_guest_arena_hash);
|
212
210
|
rb_gc_register_mark_object(rb_abi_guest_refcount_hash);
|
211
|
+
ruby_sysinit(&argc, &c_args);
|
212
|
+
ruby_options(argc, c_args);
|
213
213
|
}
|
214
|
-
void rb_abi_guest_ruby_init(
|
215
|
-
RB_WASM_LIB_RT(rb_abi_guest_ruby_init_thunk())
|
216
|
-
}
|
217
|
-
|
218
|
-
void rb_abi_guest_ruby_sysinit(rb_abi_guest_list_string_t *args) {
|
219
|
-
char **c_args;
|
214
|
+
void rb_abi_guest_ruby_init(rb_abi_guest_list_string_t *args) {
|
220
215
|
int argc = args->len;
|
221
|
-
c_strings_from_abi(args, c_args);
|
222
|
-
RB_WASM_LIB_RT(ruby_sysinit(&argc, &c_args))
|
223
|
-
}
|
224
|
-
|
225
|
-
rb_abi_guest_rb_iseq_t
|
226
|
-
rb_abi_guest_ruby_options(rb_abi_guest_list_string_t *args) {
|
227
|
-
void *result;
|
228
216
|
char **c_args;
|
229
217
|
c_strings_from_abi(args, c_args);
|
230
|
-
RB_WASM_LIB_RT(
|
231
|
-
return rb_abi_guest_rb_iseq_new(result);
|
232
|
-
}
|
233
|
-
|
234
|
-
void rb_abi_guest_ruby_script(rb_abi_guest_string_t *name) {
|
235
|
-
RB_WASM_LIB_RT(ruby_script((const char *)name->ptr))
|
218
|
+
RB_WASM_LIB_RT(rb_abi_guest_ruby_init_thunk(argc, c_args))
|
236
219
|
}
|
237
220
|
|
238
221
|
void rb_abi_guest_ruby_init_loadpath(void) {
|
@@ -398,22 +381,9 @@ void exports_ruby_js_ruby_runtime_ruby_show_version(void) {
|
|
398
381
|
__wasm_call_ctors_if_needed();
|
399
382
|
rb_abi_guest_ruby_show_version();
|
400
383
|
}
|
401
|
-
void exports_ruby_js_ruby_runtime_ruby_init(
|
402
|
-
__wasm_call_ctors_if_needed();
|
403
|
-
rb_abi_guest_ruby_init();
|
404
|
-
}
|
405
|
-
void exports_ruby_js_ruby_runtime_ruby_sysinit(ext_list_string_t *args) {
|
406
|
-
__wasm_call_ctors_if_needed();
|
407
|
-
rb_abi_guest_ruby_sysinit(args);
|
408
|
-
}
|
409
|
-
exports_ruby_js_ruby_runtime_own_rb_iseq_t
|
410
|
-
exports_ruby_js_ruby_runtime_ruby_options(ext_list_string_t *args) {
|
411
|
-
__wasm_call_ctors_if_needed();
|
412
|
-
return rb_abi_guest_ruby_options(args);
|
413
|
-
}
|
414
|
-
void exports_ruby_js_ruby_runtime_ruby_script(ext_string_t *name) {
|
384
|
+
void exports_ruby_js_ruby_runtime_ruby_init(ext_list_string_t *args) {
|
415
385
|
__wasm_call_ctors_if_needed();
|
416
|
-
|
386
|
+
rb_abi_guest_ruby_init(args);
|
417
387
|
}
|
418
388
|
void exports_ruby_js_ruby_runtime_ruby_init_loadpath(void) {
|
419
389
|
__wasm_call_ctors_if_needed();
|
data/lib/js/require_remote.rb
CHANGED
@@ -43,11 +43,27 @@ module JS
|
|
43
43
|
include Singleton
|
44
44
|
|
45
45
|
def initialize
|
46
|
+
# By default, the base_url is the URL of the HTML file that invoked ruby.wasm vm.
|
46
47
|
base_url = JS.global[:URL].new(JS.global[:location][:href])
|
47
48
|
@resolver = URLResolver.new(base_url)
|
48
49
|
@evaluator = Evaluator.new
|
49
50
|
end
|
50
51
|
|
52
|
+
# If you want to resolve relative paths to a starting point other than the HTML file that executes ruby.wasm,
|
53
|
+
# you can set the base_url property.
|
54
|
+
# For example, if you want to use the `lib` directory as the starting point, specify base_url as follows
|
55
|
+
#
|
56
|
+
# == Example
|
57
|
+
# require 'js/require_remote'
|
58
|
+
# JS::RequireRemote.instance.base_url = "lib"
|
59
|
+
# JS::RequireRemote.instance.load("foo") # => 'lib/foo.rb' will be loaded.
|
60
|
+
#
|
61
|
+
def base_url=(base_url)
|
62
|
+
base_url = base_url.end_with?("/") ? base_url : "#{base_url}/"
|
63
|
+
url = JS.global[:URL].new(base_url, JS.global[:location][:href])
|
64
|
+
@resolver = URLResolver.new(url)
|
65
|
+
end
|
66
|
+
|
51
67
|
# Load the given feature from remote.
|
52
68
|
def load(relative_feature)
|
53
69
|
location = @resolver.get_location(relative_feature)
|
data/lib/js/version.rb
CHANGED
data/lib/js.rb
CHANGED
@@ -125,7 +125,20 @@ module JS
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
|
128
|
+
# Inherit BasicObject to prevent define coventional menthods. #Override the `Object#send` to give priority to `send` method of JavaScript.
|
129
|
+
#
|
130
|
+
# This is to make it easier to use JavaScript Objects with `send` method such as `WebSocket` and `XMLHttpRequest`.
|
131
|
+
# The JavaScript method call short-hand in `JS::Object` is implemented using `method_missing`.
|
132
|
+
# If JS::Object inherits from Object, the `send` method defined in Ruby will take precedence over the JavaScript `send` method.
|
133
|
+
# If you want to call the JavaScript `send` method, you must use the `call` method as follows:
|
134
|
+
#
|
135
|
+
# ws = JS.global[:WebSocket].new("ws://example.com")
|
136
|
+
# ws.call(:send, ["Hello, world! from Ruby"])
|
137
|
+
#
|
138
|
+
# This inheritation allows you to call the JavaScript `send` method with the following syntax:
|
139
|
+
#
|
140
|
+
# ws.send("Hello, world! from Ruby")
|
141
|
+
class JS::Object < BasicObject
|
129
142
|
# Create a JavaScript object with the new method
|
130
143
|
#
|
131
144
|
# The below examples show typical usage in Ruby
|
@@ -141,7 +154,7 @@ class JS::Object
|
|
141
154
|
#
|
142
155
|
def new(*args, &block)
|
143
156
|
args = args + [block] if block
|
144
|
-
JS.global[:Reflect].construct(self, args.to_js)
|
157
|
+
::JS.global[:Reflect].construct(self, args.to_js)
|
145
158
|
end
|
146
159
|
|
147
160
|
# Converts +self+ to an Array:
|
@@ -149,8 +162,8 @@ class JS::Object
|
|
149
162
|
# JS.eval("return [1, 2, 3]").to_a.map(&:to_i) # => [1, 2, 3]
|
150
163
|
# JS.global[:document].querySelectorAll("p").to_a # => [[object HTMLParagraphElement], ...
|
151
164
|
def to_a
|
152
|
-
as_array = JS.global[:Array].from(self)
|
153
|
-
Array.new(as_array[:length].to_i) { as_array[_1] }
|
165
|
+
as_array = ::JS.global[:Array].from(self)
|
166
|
+
::Array.new(as_array[:length].to_i) { as_array[_1] }
|
154
167
|
end
|
155
168
|
|
156
169
|
# Provide a shorthand form for JS::Object#call
|
@@ -173,32 +186,28 @@ class JS::Object
|
|
173
186
|
if sym_str.end_with?("?")
|
174
187
|
# When a JS method is called with a ? suffix, it is treated as a predicate method,
|
175
188
|
# and the return value is converted to a Ruby boolean value automatically.
|
176
|
-
result =
|
177
|
-
|
189
|
+
result = invoke_js_method(sym_str[0..-2].to_sym, *args, &block)
|
178
190
|
# Type coerce the result to boolean type
|
179
191
|
# to match the true/false determination in JavaScript's if statement.
|
180
|
-
JS.global.Boolean(result) == JS::True
|
181
|
-
elsif self[sym].typeof == "function"
|
182
|
-
self.call(sym, *args, &block)
|
183
|
-
else
|
184
|
-
super
|
192
|
+
return ::JS.global.Boolean(result) == ::JS::True
|
185
193
|
end
|
194
|
+
|
195
|
+
invoke_js_method(sym, *args, &block)
|
186
196
|
end
|
187
197
|
|
188
198
|
# Check if a JavaScript method exists
|
189
199
|
#
|
190
200
|
# See JS::Object#method_missing for details.
|
191
201
|
def respond_to_missing?(sym, include_private)
|
192
|
-
return true if super
|
193
202
|
sym_str = sym.to_s
|
194
203
|
sym = sym_str[0..-2].to_sym if sym_str.end_with?("?")
|
195
204
|
self[sym].typeof == "function"
|
196
205
|
end
|
197
206
|
|
198
|
-
# Call the receiver (a JavaScript function) with `undefined` as its receiver context.
|
207
|
+
# Call the receiver (a JavaScript function) with `undefined` as its receiver context.
|
199
208
|
# This method is similar to JS::Object#call, but it is used to call a function that is not
|
200
209
|
# a method of an object.
|
201
|
-
#
|
210
|
+
#
|
202
211
|
# floor = JS.global[:Math][:floor]
|
203
212
|
# floor.apply(3.14) # => 3
|
204
213
|
# JS.global[:Promise].new do |resolve, reject|
|
@@ -206,7 +215,7 @@ class JS::Object
|
|
206
215
|
# end.await # => 42
|
207
216
|
def apply(*args, &block)
|
208
217
|
args = args + [block] if block
|
209
|
-
JS.global[:Reflect].call(:apply, self, JS::Undefined, args.to_js)
|
218
|
+
::JS.global[:Reflect].call(:apply, self, ::JS::Undefined, args.to_js)
|
210
219
|
end
|
211
220
|
|
212
221
|
# Await a JavaScript Promise like `await` in JavaScript.
|
@@ -236,8 +245,35 @@ class JS::Object
|
|
236
245
|
# JS.eval("return new Promise((ok, err) => err(new Error())").await # => raises JS::Error
|
237
246
|
def await
|
238
247
|
# Promise.resolve wrap a value or flattens promise-like object and its thenable chain
|
239
|
-
promise = JS.global[:Promise].resolve(self)
|
240
|
-
JS.promise_scheduler.await(promise)
|
248
|
+
promise = ::JS.global[:Promise].resolve(self)
|
249
|
+
::JS.promise_scheduler.await(promise)
|
250
|
+
end
|
251
|
+
|
252
|
+
# The `respond_to?` method is only used in unit tests.
|
253
|
+
# There is little need to define it here.
|
254
|
+
# However, methods suffixed with `?` do not conflict with JavaScript methods.
|
255
|
+
# As there are no disadvantages, we will define the `respond_to?` method here
|
256
|
+
# in the same way as the `nil?` and `is_a?` methods, prioritizing convenience.
|
257
|
+
[:nil?, :is_a?, :raise, :respond_to?].each do |method|
|
258
|
+
define_method(method, ::Object.instance_method(method))
|
259
|
+
end
|
260
|
+
|
261
|
+
private
|
262
|
+
|
263
|
+
# Invoke a JavaScript method
|
264
|
+
# If the property of JavaScritp object does not exist, raise a `NoMethodError`.
|
265
|
+
# If the property exists but is not a function, raise a `TypeError`.
|
266
|
+
def invoke_js_method(sym, *args, &block)
|
267
|
+
return self.call(sym, *args, &block) if self[sym].typeof == "function"
|
268
|
+
|
269
|
+
# Check to see if a non-functional property exists.
|
270
|
+
if ::JS.global[:Reflect].call(:has, self, sym.to_s) == ::JS::True
|
271
|
+
raise ::TypeError,
|
272
|
+
"`#{sym}` is not a function. To reference a property, use `[:#{sym}]` syntax instead."
|
273
|
+
end
|
274
|
+
|
275
|
+
raise ::NoMethodError,
|
276
|
+
"undefined method `#{sym}' for an instance of JS::Object"
|
241
277
|
end
|
242
278
|
end
|
243
279
|
|
data/wit/js-runtime.wit
CHANGED
@@ -14,7 +14,7 @@ interface js-runtime {
|
|
14
14
|
instance-of: func(value: borrow<js-abi-value>, klass: borrow<js-abi-value>) -> bool;
|
15
15
|
global-this: func() -> js-abi-value;
|
16
16
|
int-to-js-number: func(value: s32) -> js-abi-value;
|
17
|
-
float-to-js-number: func(value:
|
17
|
+
float-to-js-number: func(value: f64) -> js-abi-value;
|
18
18
|
string-to-js-string: func(value: string) -> js-abi-value;
|
19
19
|
bool-to-js-bool: func(value: bool) -> js-abi-value;
|
20
20
|
proc-to-js-function: func() -> js-abi-value;
|
@@ -23,7 +23,7 @@ interface js-runtime {
|
|
23
23
|
js-value-to-string: func(value: borrow<js-abi-value>) -> string;
|
24
24
|
|
25
25
|
variant raw-integer {
|
26
|
-
as-float(
|
26
|
+
as-float(f64),
|
27
27
|
bignum(string),
|
28
28
|
}
|
29
29
|
|
data/wit/ruby-runtime.wit
CHANGED
@@ -3,17 +3,13 @@ package ruby:js;
|
|
3
3
|
interface ruby-runtime {
|
4
4
|
use js-runtime.{js-abi-value};
|
5
5
|
|
6
|
-
resource rb-iseq {}
|
7
6
|
resource rb-abi-value {}
|
8
7
|
|
9
8
|
type rb-errno = s32;
|
10
9
|
type rb-id = u32;
|
11
10
|
|
12
11
|
ruby-show-version: func();
|
13
|
-
ruby-init: func();
|
14
|
-
ruby-sysinit: func(args: list<string>);
|
15
|
-
ruby-options: func(args: list<string>) -> rb-iseq;
|
16
|
-
ruby-script: func(name: string);
|
12
|
+
ruby-init: func(args: list<string>);
|
17
13
|
ruby-init-loadpath: func();
|
18
14
|
rb-eval-string-protect: func(str: string) -> tuple<rb-abi-value, s32>;
|
19
15
|
rb-funcallv-protect: func(recv: borrow<rb-abi-value>, mid: rb-id, args: list<borrow<rb-abi-value>>) -> tuple<rb-abi-value, s32>;
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuta Saito
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-23 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
12
|
description: JavaScript bindings for ruby.wasm. This gem provides a way to use JavaScript
|
14
13
|
functionalities from Ruby through WebAssembly.
|
@@ -52,7 +51,6 @@ licenses:
|
|
52
51
|
- MIT
|
53
52
|
metadata:
|
54
53
|
source_code_uri: https://github.com/ruby/ruby.wasm/tree/main/packages/gems/js
|
55
|
-
post_install_message:
|
56
54
|
rdoc_options: []
|
57
55
|
require_paths:
|
58
56
|
- lib
|
@@ -67,8 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
65
|
- !ruby/object:Gem::Version
|
68
66
|
version: '0'
|
69
67
|
requirements: []
|
70
|
-
rubygems_version: 3.
|
71
|
-
signing_key:
|
68
|
+
rubygems_version: 3.6.0.dev
|
72
69
|
specification_version: 4
|
73
70
|
summary: JavaScript bindings for ruby.wasm
|
74
71
|
test_files: []
|