jscall 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/lib/jscall/main.mjs +16 -13
- data/lib/jscall/synch.mjs +2 -2
- data/lib/jscall/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccebaf9700a3adef5c0bba832014a8f29ecfecee4d2e6fd1303c77a986bd6e5a
|
4
|
+
data.tar.gz: ea718525489e87dd340200008540c269b33e5b3432a8b6eb6ddd6103ca53329e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6852583f9276d903886d9f3ff1dbcf3ca16569844567f43751bee97917715d0014c8bf598e84aae7a2ba4db6145398b397c1b21e59d921755a6c8d3b0f6bee9
|
7
|
+
data.tar.gz: 3fe7e88204d5971a3a425ca3a2329f560a547204e06e009f791017036ef75e2054da4716b2ddc948b8d170d3eaa05845c30551a88e700cda03eee814530f4857
|
data/README.md
CHANGED
@@ -110,6 +110,11 @@ created in Ruby.
|
|
110
110
|
Note that you must `await` every call to Ruby object since it is
|
111
111
|
asynchronous call.
|
112
112
|
|
113
|
+
A shorthand for `obj.to_a()` is `obj.to_a` in Ruby. However,
|
114
|
+
this shorthand is not available in JavaScript.
|
115
|
+
You must explicitly write `obj.to_a()`
|
116
|
+
in JavaScript when `obj` is a Ruby object.
|
117
|
+
|
113
118
|
In JavaScript, `Ruby.exec` is available to run a program in Ruby.
|
114
119
|
For example,
|
115
120
|
|
data/lib/jscall/main.mjs
CHANGED
@@ -43,8 +43,8 @@ const exported = new class {
|
|
43
43
|
}
|
44
44
|
}
|
45
45
|
|
46
|
-
export_remoteref(
|
47
|
-
return
|
46
|
+
export_remoteref(rref) { // proxy for remote reference
|
47
|
+
return rref.id
|
48
48
|
}
|
49
49
|
|
50
50
|
next_element() {
|
@@ -61,6 +61,8 @@ const exported = new class {
|
|
61
61
|
const obj = this.objects[idx]
|
62
62
|
if (typeof obj === 'number')
|
63
63
|
throw `unknown index is given to find(): ${idx}`
|
64
|
+
else if (obj === null)
|
65
|
+
throw `null is exported? ${idx}`
|
64
66
|
else
|
65
67
|
return obj
|
66
68
|
}
|
@@ -95,12 +97,12 @@ const remoteRefHandler = new class {
|
|
95
97
|
else
|
96
98
|
return (...args) => {
|
97
99
|
// this returns Promise
|
98
|
-
return funcall_to_ruby(obj
|
100
|
+
return funcall_to_ruby(obj, name, args)
|
99
101
|
}
|
100
102
|
}
|
101
103
|
apply(obj, self, args) {
|
102
104
|
// this returns Promise
|
103
|
-
return funcall_to_ruby(obj
|
105
|
+
return funcall_to_ruby(obj, 'call', args)
|
104
106
|
}
|
105
107
|
}
|
106
108
|
|
@@ -154,11 +156,11 @@ const encode_obj = obj => {
|
|
154
156
|
else if (obj instanceof Map) {
|
155
157
|
const hash = {}
|
156
158
|
for (const [key, value] of obj.entries())
|
157
|
-
hash[key] = value
|
159
|
+
hash[key] = encode_obj(value)
|
158
160
|
return [param_hash, hash]
|
159
161
|
}
|
160
162
|
else if (obj instanceof RemoteRef)
|
161
|
-
return [param_local_object, exported.export_remoteref(obj)]
|
163
|
+
return [param_local_object, exported.export_remoteref(obj.__self__)]
|
162
164
|
else
|
163
165
|
return [param_object, exported.export(obj)]
|
164
166
|
}
|
@@ -203,12 +205,12 @@ export const decode_obj_or_error = obj => {
|
|
203
205
|
const js_eval = eval
|
204
206
|
|
205
207
|
export const funcall_from_ruby = cmd => {
|
208
|
+
if (debug_level >= 10)
|
209
|
+
console.error(`RubyToJS> ${cmd[3]} ${cmd[1]} ${cmd[2]}`)
|
210
|
+
|
206
211
|
const receiver = decode_obj(cmd[2])
|
207
212
|
const name = cmd[3]
|
208
213
|
const args = cmd[4].map(e => decode_obj(e))
|
209
|
-
if (debug_level >= 10)
|
210
|
-
console.error(`RubyToJS> ${name} ${cmd[1]}`)
|
211
|
-
|
212
214
|
if (name.endsWith('=')) {
|
213
215
|
const name2 = name.substring(0, name.length - 1)
|
214
216
|
if (receiver === null)
|
@@ -311,13 +313,13 @@ export const make_cmd_eval = src => {
|
|
311
313
|
return reply_with_piggyback([cmd_eval, message_id, src])
|
312
314
|
}
|
313
315
|
|
314
|
-
let funcall_to_ruby = (
|
316
|
+
let funcall_to_ruby = (receiver, name, args) => {
|
315
317
|
return new Promise((resolve, reject) => {
|
316
|
-
const cmd = make_cmd_call(
|
318
|
+
const cmd = make_cmd_call(receiver, name, args)
|
317
319
|
const message_id = cmd[1]
|
318
320
|
callback_stack.push([message_id, resolve, reject])
|
319
321
|
if (debug_level >= 10)
|
320
|
-
console.error(`JStoRuby< ${name} ${message_id}`)
|
322
|
+
console.error(`JStoRuby< ${name} ${message_id} ${cmd[2][1]}`)
|
321
323
|
|
322
324
|
stdout_puts(JSON.stringify(cmd))
|
323
325
|
})
|
@@ -325,7 +327,8 @@ let funcall_to_ruby = (receiver_id, name, args) => {
|
|
325
327
|
|
326
328
|
export const set_funcall_to_ruby = f => { funcall_to_ruby = f }
|
327
329
|
|
328
|
-
export const make_cmd_call = (
|
330
|
+
export const make_cmd_call = (obj, name, args) => {
|
331
|
+
const receiver_id = exported.export_remoteref(obj)
|
329
332
|
const message_id = fresh_id()
|
330
333
|
const receiver = [param_local_object, receiver_id]
|
331
334
|
const encoded_args = args.map(e => encode_obj(e))
|
data/lib/jscall/synch.mjs
CHANGED
@@ -171,8 +171,8 @@ export const exec = src => {
|
|
171
171
|
return event_loop()
|
172
172
|
}
|
173
173
|
|
174
|
-
main.set_funcall_to_ruby((
|
175
|
-
const cmd = main.make_cmd_call(
|
174
|
+
main.set_funcall_to_ruby((receiver, name, args) => {
|
175
|
+
const cmd = main.make_cmd_call(receiver, name, args)
|
176
176
|
main.stdout_puts(JSON.stringify(cmd))
|
177
177
|
return event_loop()
|
178
178
|
})
|
data/lib/jscall/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jscall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shigeru Chiba
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webrick
|