isomorfeus-speednode 0.4.8 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74eb2f47432b1bc39363b023df1f181ca1ca6721080e1a5a49f6b082b7cdee16
|
4
|
+
data.tar.gz: '09d180b35d456a84bd1be8d52efd601f3bae95d6f1a9723b1e877b044e1c8401'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f145d915f4588687fb8d77c5ea5c5545b414d354993320540df2156b284a11adb75320e31c43dbf04d4d1560d1fc355b7a0804c973d84412c518e60124b4fdf6
|
7
|
+
data.tar.gz: 9dd42852a0492916cd634c32621f4cb184f52f597b763263ecb9d075a12bd6f5b634619b9cf553c596d4ad4ed0c5f13eca9066d489826cfe9f8c82dbab6d559e
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ A fast runtime for execjs using node js. Works on Linux, BSDs, MacOS and Windows
|
|
7
7
|
Inspired by [execjs-fastnode](https://github.com/jhawthorn/execjs-fastnode).
|
8
8
|
|
9
9
|
### Community and Support
|
10
|
-
At the [Isomorfeus Framework Project](
|
10
|
+
At the [Isomorfeus Framework Project](https://isomorfeus.com)
|
11
11
|
|
12
12
|
### Installation
|
13
13
|
|
@@ -53,6 +53,15 @@ Evaluation in a permissive context:
|
|
53
53
|
ExecJS.permissive_eval('1+1')
|
54
54
|
```
|
55
55
|
|
56
|
+
### Storing scripts for repeated execution
|
57
|
+
|
58
|
+
Scripts can be precompiled and stored for repeated execution, which leads to a significant performance improvement, especially for larger scripts:
|
59
|
+
```ruby
|
60
|
+
context = ExecJS.compile('Test = "test"')
|
61
|
+
context.add_script(key: 'super', source: some_large_javascript) # will compile and store the script
|
62
|
+
context.eval_script(:key: 'super') # will run the precompiled script in the context
|
63
|
+
```
|
64
|
+
|
56
65
|
### Async function support
|
57
66
|
|
58
67
|
Its possible to call async functions synchronously from ruby using Context#await:
|
@@ -4,7 +4,13 @@ const vm = require('vm');
|
|
4
4
|
const net = require('net');
|
5
5
|
const os = require('os');
|
6
6
|
const fs = require('fs');
|
7
|
+
let crypto_var = null;
|
8
|
+
try {
|
9
|
+
crypto_var = require('crypto');
|
10
|
+
} catch (err) {}
|
11
|
+
const crypto = crypto_var;
|
7
12
|
let contexts = {};
|
13
|
+
let scripts = {};
|
8
14
|
let process_exit = false;
|
9
15
|
|
10
16
|
/*** circular-json, originally taken from https://raw.githubusercontent.com/WebReflection/circular-json/
|
@@ -200,7 +206,7 @@ function createCompatibleContext(uuid, options) {
|
|
200
206
|
}
|
201
207
|
|
202
208
|
function createPermissiveContext(uuid, options) {
|
203
|
-
let c = vm.createContext({ __responder_socket: false, process: { release: { name: "node" }, env: process.env }, Buffer, clearTimeout, fs, net, os, require, setTimeout });
|
209
|
+
let c = vm.createContext({ __responder_socket: false, process: { release: { name: "node" }, env: process.env }, Buffer, clearTimeout, crypto, fs, net, os, require, setTimeout });
|
204
210
|
vm.runInContext('global = globalThis;', c);
|
205
211
|
contexts[uuid] = { context: c, options: options };
|
206
212
|
return c;
|
@@ -259,6 +265,7 @@ let commands = {
|
|
259
265
|
},
|
260
266
|
deleteContext: function(uuid) {
|
261
267
|
delete contexts[uuid];
|
268
|
+
delete scripts[uuid]
|
262
269
|
return [1];
|
263
270
|
},
|
264
271
|
exit: function(code) {
|
@@ -275,6 +282,17 @@ let commands = {
|
|
275
282
|
let result = vm.runInContext(input.source, getContext(input.context), getContextOptions(input.context));
|
276
283
|
return formatResult(result);
|
277
284
|
},
|
285
|
+
scsc: function (input) {
|
286
|
+
if (input.source.match(/^\s*{/)) { input.source = "(" + input.source + ")"; }
|
287
|
+
else if (input.source.match(/^\s*function\s*\(/)) { input.source = "(" + input.source + ")"; }
|
288
|
+
if (!scripts[input.context]) { scripts[input.context] = {}; }
|
289
|
+
scripts[input.context][input.key] = new vm.Script(input.source);
|
290
|
+
return formatResult(true);
|
291
|
+
},
|
292
|
+
evsc: function(input) {
|
293
|
+
let result = scripts[input.context][input.key].runInContext(getContext(input.context));
|
294
|
+
return formatResult(result);
|
295
|
+
},
|
278
296
|
// ctxo: function (input) {
|
279
297
|
// return formatResult(getContextOptions(input.context));
|
280
298
|
// },
|
@@ -7,7 +7,6 @@ module Isomorfeus
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def initialize(runtime, source = "", options = {})
|
10
|
-
|
11
10
|
@runtime = runtime
|
12
11
|
@uuid = SecureRandom.uuid
|
13
12
|
@permissive = !!options.delete(:permissive)
|
@@ -69,6 +68,14 @@ module Isomorfeus
|
|
69
68
|
raw_exec("(function(){#{source}})()")
|
70
69
|
end
|
71
70
|
|
71
|
+
def eval_script(key:)
|
72
|
+
extract_result(@vm.evsc(@uuid, key))
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_script(key:, source:)
|
76
|
+
extract_result(@vm.scsc(@uuid, key, encode(source)))
|
77
|
+
end
|
78
|
+
|
72
79
|
def permissive?
|
73
80
|
@permissive
|
74
81
|
end
|
@@ -89,7 +96,6 @@ module Isomorfeus
|
|
89
96
|
extract_result(@vm.eval(@uuid, encode(source)))
|
90
97
|
end
|
91
98
|
|
92
|
-
|
93
99
|
def raw_exec(source)
|
94
100
|
extract_result(@vm.exec(@uuid, encode(source)))
|
95
101
|
end
|
@@ -79,25 +79,33 @@ module Isomorfeus
|
|
79
79
|
nil
|
80
80
|
end
|
81
81
|
|
82
|
+
def evsc(context, key)
|
83
|
+
command('evsc', { 'context' => context, 'key' => key })
|
84
|
+
end
|
85
|
+
|
86
|
+
def scsc(context, key, source)
|
87
|
+
command('scsc', { 'context' => context, 'key' => key, 'source' => source })
|
88
|
+
end
|
89
|
+
|
82
90
|
def eval(context, source)
|
83
|
-
command(
|
91
|
+
command('eval', {'context' => context, 'source' => source})
|
84
92
|
end
|
85
93
|
|
86
94
|
def exec(context, source)
|
87
|
-
command(
|
95
|
+
command('exec', {'context' => context, 'source' => source})
|
88
96
|
end
|
89
97
|
|
90
98
|
def create(context, source, options)
|
91
|
-
command(
|
99
|
+
command('create', {'context' => context, 'source' => source, 'options' => options})
|
92
100
|
end
|
93
101
|
|
94
102
|
def createp(context, source, options)
|
95
|
-
command(
|
103
|
+
command('createp', {'context' => context, 'source' => source, 'options' => options})
|
96
104
|
end
|
97
105
|
|
98
106
|
def attach(context, func)
|
99
107
|
create_responder(context) unless responder
|
100
|
-
command(
|
108
|
+
command('attach', {'context' => context, 'func' => func })
|
101
109
|
end
|
102
110
|
|
103
111
|
def delete_context(context)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-speednode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.13.
|
33
|
+
version: 3.13.11
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.13.
|
40
|
+
version: 3.13.11
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: win32-pipe
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 5.
|
75
|
+
version: 5.15.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 5.
|
82
|
+
version: 5.15.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,11 +130,12 @@ files:
|
|
130
130
|
- lib/isomorfeus/speednode/runtime/vm.rb
|
131
131
|
- lib/isomorfeus/speednode/runtime/vm_command.rb
|
132
132
|
- lib/isomorfeus/speednode/version.rb
|
133
|
-
homepage:
|
133
|
+
homepage: https://isomorfeus.com
|
134
134
|
licenses:
|
135
135
|
- MIT
|
136
136
|
metadata:
|
137
137
|
github_repo: ssh://github.com/isomorfeus/gems
|
138
|
+
source_code_uri: https://github.com/isomorfeus/isomorfeus-speednode
|
138
139
|
post_install_message:
|
139
140
|
rdoc_options: []
|
140
141
|
require_paths:
|