Module: Quickjs
- Defined in:
- lib/quickjs.rb,
lib/quickjs/version.rb,
lib/quickjs/function.rb,
lib/quickjs/crypto_key.rb,
lib/quickjs/subtle_crypto.rb,
ext/quickjsrb/quickjsrb.c
Defined Under Namespace
Modules: SubtleCrypto
Classes: Blob, CryptoKey, File, Function, VM
Constant Summary
collapse
- VERSION =
"0.15.0"
Class Method Summary
collapse
Class Method Details
._build_import(imported) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/quickjs.rb', line 37
def _build_import(imported)
code_define_global = ->(name) { "globalThis['#{name}'] = #{name};" }
case imported
in String if matched = imported.match(/\* as (.+)/)
[imported, code_define_global.call(matched[1])]
in String
[imported, code_define_global.call(imported)]
in [*all] if all.all? {|e| e.is_a? String }
[
imported.join(', ').yield_self{|s| '{ %s }' % s },
imported.map(&code_define_global).join("\n")
]
in { ** }
imports, aliases = imported.to_a.map do |imp|
["#{imp[0]} as #{imp[1]}", imp[1].to_s]
end.transpose
[
imports.join(', ').yield_self{|s| '{ %s }' % s },
aliases.map(&code_define_global).join("\n")
]
else
raise 'Unsupported importing style'
end
end
|
._with_timeout(msec, proc, args) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/quickjs.rb', line 28
def _with_timeout(msec, proc, args)
Timeout.timeout(msec / 1_000.0) { proc.call(*args) }
rescue Timeout::Error
raise Quickjs::InterruptedError.new('Ruby runtime got timeout', nil)
rescue
raise
end
|
.eval_code(code, overwrite_opts = {}) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/quickjs.rb', line 20
def eval_code(code, overwrite_opts = {})
vm = Quickjs::VM.new(**overwrite_opts)
res = vm.eval_code(code)
vm = nil
res
end
|