isomorfeus-speednode 0.4.10 → 0.5.0

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: ca0207c7ed85d1fb9f3fd4bbefcd101f2fd07f8b12b9708cd090e0fef4f76880
4
- data.tar.gz: cebac939d6b699bb9e2afab4a4eefb1880cab09ea6e64ddf23d231e36d64fbd4
3
+ metadata.gz: fc7add59924aa8a26faab4104731a2a2a5370f1a019417105206cb0dc38fd533
4
+ data.tar.gz: 239f6c6e4f2cf18caffca1b755c41d78c76e8d4fdcefdb319d18d6acdf9c8963
5
5
  SHA512:
6
- metadata.gz: 909f2eafee666a73675fe313aed7dcf34674d8b0563649fffae41271131196b6fc333c61fdd6c2253fd86f2365b41efd788e51f1560fc27fbe5ec5fa4ba3549b
7
- data.tar.gz: 2829dfa3c69ee7a402a325ca6cd1d7b6e1231f6fd8002f589c699c9b94a178bb7972da445a888d115c09c19fd5cf1d9c878a4c5ff983661cf93c2e2669627416
6
+ metadata.gz: 77e34c80ccf9ad930f74e57efdc2529c7f91cde1b5b1b91a1ffe3cae33c7f4033c489cb19b788e50d13236a64dba994e55f842825e0ed63cf71f7b3046d91481
7
+ data.tar.gz: d2cef10f4eab5e96fbffd7c8f7b3c3cef3b7a351467dcd76485d779812a514d944d32a0a0b44fb8fe083fe457a54bd94cd4808f3b9a782ce394e30ed117c9111
data/README.md CHANGED
@@ -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:
@@ -10,6 +10,7 @@ try {
10
10
  } catch (err) {}
11
11
  const crypto = crypto_var;
12
12
  let contexts = {};
13
+ let scripts = {};
13
14
  let process_exit = false;
14
15
 
15
16
  /*** circular-json, originally taken from https://raw.githubusercontent.com/WebReflection/circular-json/
@@ -280,6 +281,17 @@ let commands = {
280
281
  let result = vm.runInContext(input.source, getContext(input.context), getContextOptions(input.context));
281
282
  return formatResult(result);
282
283
  },
284
+ scsc: function (input) {
285
+ if (input.source.match(/^\s*{/)) { input.source = "(" + input.source + ")"; }
286
+ else if (input.source.match(/^\s*function\s*\(/)) { input.source = "(" + input.source + ")"; }
287
+ scripts[input.context] = {};
288
+ scripts[input.context][input.key] = new vm.Script(input.source);
289
+ return formatResult(true);
290
+ },
291
+ evsc: function(input) {
292
+ let result = scripts[input.context][input.key].runInContext(getContext(input.context));
293
+ return formatResult(result);
294
+ },
283
295
  // ctxo: function (input) {
284
296
  // return formatResult(getContextOptions(input.context));
285
297
  // },
@@ -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("eval", {'context' => context, 'source' => source})
91
+ command('eval', {'context' => context, 'source' => source})
84
92
  end
85
93
 
86
94
  def exec(context, source)
87
- command("exec", {'context' => context, 'source' => source})
95
+ command('exec', {'context' => context, 'source' => source})
88
96
  end
89
97
 
90
98
  def create(context, source, options)
91
- command("create", {'context' => context, 'source' => source, 'options' => options})
99
+ command('create', {'context' => context, 'source' => source, 'options' => options})
92
100
  end
93
101
 
94
102
  def createp(context, source, options)
95
- command("createp", {'context' => context, 'source' => source, 'options' => options})
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("attach", {'context' => context, 'func' => func })
108
+ command('attach', {'context' => context, 'func' => func })
101
109
  end
102
110
 
103
111
  def delete_context(context)
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Speednode
3
- VERSION = '0.4.10'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-speednode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann