jscall 1.2.0 → 1.3.0
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/README.md +16 -0
- data/Rakefile +5 -1
- data/lib/jscall/main.mjs +20 -7
- data/lib/jscall/version.rb +1 -1
- data/lib/jscall.rb +8 -6
- 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: 1df05fa2e6cee8575b7cdf9a95d35c264422d66c1c793f71e620462380a891bc
|
4
|
+
data.tar.gz: 4bae39ef37ec190d8c6b87fb4541c0ec4f074b7c5b09eeecc1d92a4a47dd570c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16c12783ff80fefb85e4453ca09b54faf4b614895157f4e57108379a51ef0ebbacc2fb38ddff7d87faef50a5c3880a6690cfeb03dc5e5d67be447e36236475af
|
7
|
+
data.tar.gz: a5b57ae8e5d7d891648d457ed32f481ea1b0d528d973e693e164f5053e39f6bfce235148fc22990a53e52e5d7ceaa5eb91dc3297b4b89b8a7af90aa47b88ff54
|
data/README.md
CHANGED
@@ -392,6 +392,22 @@ Jscall.config()
|
|
392
392
|
|
393
393
|
### Other configurations
|
394
394
|
|
395
|
+
To obtain more detailed error messages,
|
396
|
+
set a debugging level to 10.
|
397
|
+
In Ruby,
|
398
|
+
|
399
|
+
```
|
400
|
+
Jscall.debug = 10
|
401
|
+
```
|
402
|
+
|
403
|
+
In JavaScript,
|
404
|
+
|
405
|
+
```
|
406
|
+
Ruby.setDebugLevel(10)
|
407
|
+
```
|
408
|
+
|
409
|
+
The default debugging level is 0.
|
410
|
+
|
395
411
|
To change the name of the node command,
|
396
412
|
|
397
413
|
```
|
data/Rakefile
CHANGED
@@ -6,7 +6,11 @@ require "rake/testtask"
|
|
6
6
|
Rake::TestTask.new(:test) do |t|
|
7
7
|
t.libs << "test"
|
8
8
|
t.libs << "lib"
|
9
|
-
|
9
|
+
files = FileList["test/**/test_*.rb"]
|
10
|
+
unless /linux/ =~ RbConfig::CONFIG['host_os']
|
11
|
+
files.exclude "test/test_sync_io.rb"
|
12
|
+
end
|
13
|
+
t.test_files = files
|
10
14
|
end
|
11
15
|
|
12
16
|
task default: :test
|
data/lib/jscall/main.mjs
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
// Copyright (C) 2022- Shigeru Chiba. All rights reserved.
|
2
2
|
|
3
|
+
let debug_level = 0
|
4
|
+
|
5
|
+
// debug level is 0 (default) or 10.
|
6
|
+
export const setDebugLevel = d => {
|
7
|
+
debug_level = d
|
8
|
+
}
|
9
|
+
|
3
10
|
export const cmd_eval = 1
|
4
11
|
export const cmd_call = 2
|
5
12
|
export const cmd_reply = 3
|
@@ -199,6 +206,9 @@ export const funcall_from_ruby = cmd => {
|
|
199
206
|
const receiver = decode_obj(cmd[2])
|
200
207
|
const name = cmd[3]
|
201
208
|
const args = cmd[4].map(e => decode_obj(e))
|
209
|
+
if (debug_level >= 10)
|
210
|
+
console.error(`RubyToJS> ${name} ${cmd[1]}`)
|
211
|
+
|
202
212
|
if (name.endsWith('=')) {
|
203
213
|
const name2 = name.substring(0, name.length - 1)
|
204
214
|
if (receiver === null)
|
@@ -219,8 +229,8 @@ export const funcall_from_ruby = cmd => {
|
|
219
229
|
}
|
220
230
|
else {
|
221
231
|
const f = Reflect.get(receiver, name)
|
222
|
-
if (f)
|
223
|
-
if (typeof f === 'function')
|
232
|
+
if (f !== undefined)
|
233
|
+
if (typeof f === 'function' && !(f instanceof RemoteRef))
|
224
234
|
return Reflect.apply(f, receiver, args)
|
225
235
|
else if (args.length === 0)
|
226
236
|
return f // obtain a propety
|
@@ -252,8 +262,10 @@ export const reply = (message_id, value, sync_mode) => {
|
|
252
262
|
}
|
253
263
|
}
|
254
264
|
|
255
|
-
export const reply_error = (message_id,
|
256
|
-
const
|
265
|
+
export const reply_error = (message_id, error) => {
|
266
|
+
const msg = typeof error === 'string' ? error : error.toString() +
|
267
|
+
'\n ---\n' + error.stack
|
268
|
+
const cmd = reply_with_piggyback([cmd_reply, message_id, encode_error(msg)])
|
257
269
|
stdout_puts(JSON.stringify(cmd))
|
258
270
|
}
|
259
271
|
|
@@ -304,6 +316,9 @@ let funcall_to_ruby = (receiver_id, name, args) => {
|
|
304
316
|
const cmd = make_cmd_call(receiver_id, name, args)
|
305
317
|
const message_id = cmd[1]
|
306
318
|
callback_stack.push([message_id, resolve, reject])
|
319
|
+
if (debug_level >= 10)
|
320
|
+
console.error(`JStoRuby< ${name} ${message_id}`)
|
321
|
+
|
307
322
|
stdout_puts(JSON.stringify(cmd))
|
308
323
|
})
|
309
324
|
}
|
@@ -475,9 +490,7 @@ export const start = async (stdin, use_stdout) => {
|
|
475
490
|
else // cmd_retry and other unknown commands
|
476
491
|
reply_error(cmd[1], `invalid command ${cmd[0]}`)
|
477
492
|
} catch (error) {
|
478
|
-
|
479
|
-
'\n ---\n' + error.stack
|
480
|
-
reply_error(cmd[1], msg)
|
493
|
+
reply_error(cmd[1], error)
|
481
494
|
}
|
482
495
|
}
|
483
496
|
}
|
data/lib/jscall/version.rb
CHANGED
data/lib/jscall.rb
CHANGED
@@ -393,13 +393,15 @@ module Jscall
|
|
393
393
|
if reply[1] != message_id
|
394
394
|
send_reply(reply[1], nil, false, CMD_REJECT)
|
395
395
|
else
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
396
|
+
if @pending_replies.key?(message_id)
|
397
|
+
result = @pending_replies.delete(message_id)
|
398
|
+
if result.is_a?(JavaScriptError)
|
399
|
+
raise result
|
400
|
+
else
|
401
|
+
return result
|
402
|
+
end
|
401
403
|
else
|
402
|
-
|
404
|
+
raise RuntimeError.new("bad CMD_RETRY: #{reply}")
|
403
405
|
end
|
404
406
|
end
|
405
407
|
else
|
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.3.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-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: webrick
|