isomorfeus-speednode 0.2.3 → 0.2.4
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/lib/isomorfeus/speednode/runner.js +25 -23
- data/lib/isomorfeus/speednode/runtime.rb +5 -1
- data/lib/isomorfeus/speednode/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: 31ef61f35fb553a911c8a0438028e1f30a42a39f67f6eac785009b9bca24ca16
|
4
|
+
data.tar.gz: 184188cc475fe8cc293857f5090a36f6df100f9592385f3b84ee5af52308991b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a40508924ae7c642f72bfe8db638c3b57d36ac15e9d7c35f1db8976cd57f1a5d4b415e69c93a3e316425a993095610355cb7bd8d907ccce9d0f11f93c32c7c43
|
7
|
+
data.tar.gz: 66d5c937dc96c5bc69f1ad59ea1e67b65e77a22c308635da78d4ea7ff9e1577077820466152d079dc3cbdce9baad561ad23c304317a9b7d08af3b83487e6c285
|
@@ -1,7 +1,9 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
1
3
|
const vm = require('vm');
|
2
4
|
const net = require('net');
|
3
|
-
|
4
|
-
|
5
|
+
let contexts = {};
|
6
|
+
let process_exit = false;
|
5
7
|
|
6
8
|
/*** circular-json, originally taken from https://raw.githubusercontent.com/WebReflection/circular-json/
|
7
9
|
Copyright (C) 2013-2017 by Andrea Giammarchi - @WebReflection
|
@@ -37,12 +39,12 @@ CircularJSON.safeSpecialChar = '\\x' + ('0' + CircularJSON.specialChar.charCode
|
|
37
39
|
CircularJSON.escapedSafeSpecialChar = '\\' + CircularJSON.safeSpecialChar;
|
38
40
|
CircularJSON.specialCharRG = new RegExp(CircularJSON.safeSpecialChar, 'g');
|
39
41
|
CircularJSON.indexOf = [].indexOf || function(v){
|
40
|
-
for(
|
42
|
+
for(let i=this.length;i--&&this[i]!==v;);
|
41
43
|
return i;
|
42
44
|
};
|
43
45
|
|
44
46
|
CircularJSON.generateReplacer = function (value, replacer, resolve) {
|
45
|
-
|
47
|
+
let
|
46
48
|
doNotIgnore = false,
|
47
49
|
inspect = !!replacer,
|
48
50
|
path = [],
|
@@ -142,7 +144,7 @@ function massageStackTrace(stack) {
|
|
142
144
|
}
|
143
145
|
|
144
146
|
function createCompatibleContext() {
|
145
|
-
|
147
|
+
let c = vm.createContext();
|
146
148
|
vm.runInContext('delete this.console', c, "(execjs)");
|
147
149
|
return c;
|
148
150
|
}
|
@@ -154,11 +156,12 @@ function createPermissiveContext() {
|
|
154
156
|
function getCompatibleContext(uuid) {
|
155
157
|
return contexts[uuid] || (contexts[uuid] = createCompatibleContext());
|
156
158
|
}
|
159
|
+
|
157
160
|
function getPermissiveContext(uuid) {
|
158
161
|
return contexts[uuid] || (contexts[uuid] = createPermissiveContext());
|
159
162
|
}
|
160
163
|
|
161
|
-
|
164
|
+
let commands = {
|
162
165
|
deleteContext: function(uuid) {
|
163
166
|
delete contexts[uuid];
|
164
167
|
return [1];
|
@@ -168,10 +171,10 @@ var commands = {
|
|
168
171
|
return ['ok'];
|
169
172
|
},
|
170
173
|
execp: function execJS(input) {
|
171
|
-
|
174
|
+
let context = getPermissiveContext(input.context);
|
172
175
|
try {
|
173
|
-
|
174
|
-
|
176
|
+
let program = function(){ return vm.runInContext(input.source, context, "(execjs)"); };
|
177
|
+
let result = program();
|
175
178
|
if (typeof result == 'undefined' && result !== null) { return ['ok']; }
|
176
179
|
else {
|
177
180
|
try { return ['ok', result]; }
|
@@ -180,10 +183,10 @@ var commands = {
|
|
180
183
|
} catch (err) { return ['err', '' + err, massageStackTrace(err.stack)]; }
|
181
184
|
},
|
182
185
|
exec: function execJS(input) {
|
183
|
-
|
186
|
+
let context = getCompatibleContext(input.context);
|
184
187
|
try {
|
185
|
-
|
186
|
-
|
188
|
+
let program = function(){ return vm.runInContext(input.source, context, "(execjs)"); };
|
189
|
+
let result = program();
|
187
190
|
if (typeof result == 'undefined' && result !== null) { return ['ok']; }
|
188
191
|
else {
|
189
192
|
try { return ['ok', result]; }
|
@@ -193,19 +196,18 @@ var commands = {
|
|
193
196
|
}
|
194
197
|
};
|
195
198
|
|
196
|
-
|
197
|
-
|
199
|
+
let server = net.createServer(function(s) {
|
200
|
+
let received_data = Buffer.alloc(0);
|
198
201
|
|
199
202
|
s.on('data', function (data) {
|
200
|
-
received_data
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
received_data = '';
|
203
|
+
received_data = Buffer.concat([received_data, data]);
|
204
|
+
if (received_data[received_data.length - 1] !== 4) { return; }
|
205
|
+
let request = received_data.slice(0, received_data.length - 1).toString('utf8');
|
206
|
+
received_data = Buffer.alloc(0);
|
205
207
|
|
206
|
-
|
207
|
-
|
208
|
-
|
208
|
+
let input = JSON.parse(request);
|
209
|
+
let result = commands[input.cmd].apply(null, input.args);
|
210
|
+
let outputJSON = '';
|
209
211
|
|
210
212
|
try { outputJSON = JSON.stringify(result); }
|
211
213
|
catch(err) {
|
@@ -218,6 +220,6 @@ var server = net.createServer(function(s) {
|
|
218
220
|
});
|
219
221
|
});
|
220
222
|
|
221
|
-
|
223
|
+
let socket_path = process.env.SOCKET_PATH;
|
222
224
|
if (!socket_path) { throw 'No SOCKET_PATH given!'; };
|
223
225
|
server.listen(socket_path);
|
@@ -97,7 +97,11 @@ module Isomorfeus
|
|
97
97
|
|
98
98
|
ObjectSpace.define_finalizer(self, self.class.finalize(@runtime, @uuid))
|
99
99
|
|
100
|
-
|
100
|
+
begin
|
101
|
+
source = encode(source)
|
102
|
+
rescue
|
103
|
+
source = source.force_encoding('UTF-8')
|
104
|
+
end
|
101
105
|
|
102
106
|
@permissive ? raw_execp(source) : raw_exec(source)
|
103
107
|
end
|
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.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|