execjs-xtrn 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +171 -0
- data/Rakefile +17 -0
- data/execjs-xtrn.gemspec +27 -0
- data/lib/execjs/node/index.js +71 -0
- data/lib/execjs/node/package.json +6 -0
- data/lib/execjs/wsh/json2.js +481 -0
- data/lib/execjs/wsh/repl.js +41 -0
- data/lib/execjs/xtrn.rb +9 -0
- data/lib/execjs/xtrn/child.rb +57 -0
- data/lib/execjs/xtrn/engine.rb +61 -0
- data/lib/execjs/xtrn/init.rb +25 -0
- data/lib/execjs/xtrn/node.rb +21 -0
- data/lib/execjs/xtrn/nvm.rb +43 -0
- data/lib/execjs/xtrn/version.rb +5 -0
- data/lib/execjs/xtrn/wsh.rb +12 -0
- data/test/child.rb +32 -0
- data/test/engine.rb +103 -0
- data/test/nvm.rb +36 -0
- data/test/shagi.rb +81 -0
- data/test/top.rb +80 -0
- metadata +145 -0
data/test/shagi.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
class Shagi < Minitest::Test
|
3
|
+
|
4
|
+
Spawn=5
|
5
|
+
M=ExecJS::Xtrn
|
6
|
+
|
7
|
+
def say(code)
|
8
|
+
raise NotImplementedError, self.class.name
|
9
|
+
end
|
10
|
+
|
11
|
+
def assert_ok(result, code)
|
12
|
+
r=say code
|
13
|
+
refute r.key? 'err'
|
14
|
+
assert_equal r, {'ok'=>result}
|
15
|
+
end
|
16
|
+
|
17
|
+
def assert_err(code)
|
18
|
+
assert say(code)['err']
|
19
|
+
end
|
20
|
+
|
21
|
+
def shag_math
|
22
|
+
assert_ok 42, 'return 6*7'
|
23
|
+
assert_ok 3, 'return Math.round(Math.PI)'
|
24
|
+
end
|
25
|
+
|
26
|
+
Chars='Япония, 中华, Russia'
|
27
|
+
Codes=[1071, 1087, 1086, 1085, 1080, 1103, 44, 32, 20013, 21326, 44, 32, 82, 117, 115, 115, 105, 97]
|
28
|
+
|
29
|
+
def shag_intl
|
30
|
+
assert_ok Codes, <<-EOJ
|
31
|
+
var s='#{Chars}'
|
32
|
+
var r=[]
|
33
|
+
for(var i=0; i<s.length; i++) r.push(s.charCodeAt(i))
|
34
|
+
return r
|
35
|
+
EOJ
|
36
|
+
|
37
|
+
assert_ok Chars, <<-EOJ
|
38
|
+
var c=#{Codes}
|
39
|
+
var s=''
|
40
|
+
for(var i=0; i<c.length; i++) s+=String.fromCharCode(c[i])
|
41
|
+
return s
|
42
|
+
EOJ
|
43
|
+
end
|
44
|
+
|
45
|
+
def shag_error
|
46
|
+
assert_err '#' # Syntax
|
47
|
+
assert_err 'none' # Runtime
|
48
|
+
assert_err false # Argument
|
49
|
+
assert_err key: 2 # the same
|
50
|
+
end
|
51
|
+
|
52
|
+
def shag_null
|
53
|
+
assert_equal say(''), {}
|
54
|
+
assert_ok nil, 'return null'
|
55
|
+
end
|
56
|
+
|
57
|
+
def shag_vars
|
58
|
+
assert_err 'localVar'
|
59
|
+
say 'var localVar=1'
|
60
|
+
assert_err 'localVar'
|
61
|
+
|
62
|
+
assert_err 'globalVar'
|
63
|
+
say "globalVar=#{v=rand 1000}"
|
64
|
+
assert_ok v, 'return globalVar'
|
65
|
+
end
|
66
|
+
|
67
|
+
def shag_stats
|
68
|
+
@child.stats r={}
|
69
|
+
say '//'
|
70
|
+
assert_equal r[:n], 1
|
71
|
+
ri=@child.stats
|
72
|
+
rc=@child.class.stats
|
73
|
+
say ''
|
74
|
+
assert_equal r[:n], 2
|
75
|
+
assert_equal ri[:n]+1, @child.stats[:n]
|
76
|
+
assert_equal rc[:n]+1, @child.class.stats[:n]
|
77
|
+
[r, ri, rc].each{|rec| %w(i o t).each{|sym| assert rec[sym.to_sym]}}
|
78
|
+
assert_operator rc[:c], :>, 0
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
data/test/top.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'coffee-script'
|
2
|
+
require 'uglifier'
|
3
|
+
ExecJS::Xtrn.init
|
4
|
+
|
5
|
+
class TestTop < Minitest::Test
|
6
|
+
|
7
|
+
def test_exec
|
8
|
+
assert_equal 42, ExecJS.exec('return 6*7')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_eval
|
12
|
+
assert_equal 42, ExecJS.eval('6*7')
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_compile
|
16
|
+
ctx=ExecJS.compile <<-EOJ
|
17
|
+
dec = function(i)
|
18
|
+
{
|
19
|
+
return i-1
|
20
|
+
}
|
21
|
+
EOJ
|
22
|
+
assert_equal 8, ctx.call('dec', 9)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_stats
|
26
|
+
ctx=ExecJS.compile <<-EOJ
|
27
|
+
summa = function(n)
|
28
|
+
{
|
29
|
+
var r=0
|
30
|
+
for(var i = 1; i<=n; i++)
|
31
|
+
{
|
32
|
+
r+=i
|
33
|
+
for(var t = ms() ; t>=ms(); );
|
34
|
+
}
|
35
|
+
return r
|
36
|
+
}
|
37
|
+
function ms()
|
38
|
+
{
|
39
|
+
return new Date().getTime()
|
40
|
+
}
|
41
|
+
EOJ
|
42
|
+
s=ctx.stats
|
43
|
+
%w(i o n t).each{|sym| assert s[sym.to_sym]}
|
44
|
+
ctx.exec ' '
|
45
|
+
assert_equal s, ctx.stats
|
46
|
+
assert_equal 5050, ctx.call('summa', 100)
|
47
|
+
assert_equal s[:n]+1, ctx.stats[:n]
|
48
|
+
%w(i o t).each{|sym| assert_operator s[sym.to_sym], :<, ctx.stats[sym.to_sym]}
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_coffee
|
52
|
+
assert CoffeeScript.compile('->', header: true)[CoffeeScript.version]
|
53
|
+
assert CoffeeScript.compile('a b c', bare: true)['a(b(c))']
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_uglify
|
57
|
+
u=Uglifier.new
|
58
|
+
assert u.compile('a( 1 + 2 * 3 )')['a(7)']
|
59
|
+
assert u.compile('b( 1 ? x : y )')['b(x)']
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_switch
|
63
|
+
assert_equal 42, ExecJS.eval('7*6')
|
64
|
+
e=ExecJS::Xtrn.engine
|
65
|
+
ExecJS::Xtrn.engine=FakeEngine
|
66
|
+
assert_equal 1, ExecJS.exec('A')
|
67
|
+
assert_equal 2, ExecJS.eval('B')
|
68
|
+
assert_equal 4, ExecJS.compile.eval('C')
|
69
|
+
ExecJS::Xtrn.engine=e
|
70
|
+
assert_equal 42, ExecJS.eval('21*2')
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
class FakeEngine < ExecJS::Xtrn::Engine
|
76
|
+
def exec(s='')
|
77
|
+
@@n||=0
|
78
|
+
@@n+=1
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: execjs-xtrn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stas Ukolov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coffee-script
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: uglifier
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Drop-in replacement for ExecJS with persistent external runtime
|
84
|
+
email:
|
85
|
+
- ukoloff@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .travis.yml
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- execjs-xtrn.gemspec
|
97
|
+
- lib/execjs/node/index.js
|
98
|
+
- lib/execjs/node/package.json
|
99
|
+
- lib/execjs/wsh/json2.js
|
100
|
+
- lib/execjs/wsh/repl.js
|
101
|
+
- lib/execjs/xtrn.rb
|
102
|
+
- lib/execjs/xtrn/child.rb
|
103
|
+
- lib/execjs/xtrn/engine.rb
|
104
|
+
- lib/execjs/xtrn/init.rb
|
105
|
+
- lib/execjs/xtrn/node.rb
|
106
|
+
- lib/execjs/xtrn/nvm.rb
|
107
|
+
- lib/execjs/xtrn/version.rb
|
108
|
+
- lib/execjs/xtrn/wsh.rb
|
109
|
+
- test/child.rb
|
110
|
+
- test/engine.rb
|
111
|
+
- test/nvm.rb
|
112
|
+
- test/shagi.rb
|
113
|
+
- test/top.rb
|
114
|
+
- lib/execjs/node/node_modules/split/index.js
|
115
|
+
- lib/execjs/node/node_modules/through/index.js
|
116
|
+
homepage: https://github.com/ukoloff/execjs-xtrn
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata: {}
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.0.3
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: 'Proof-of-concept: make ExecJS fast even without therubyracer'
|
140
|
+
test_files:
|
141
|
+
- test/child.rb
|
142
|
+
- test/engine.rb
|
143
|
+
- test/nvm.rb
|
144
|
+
- test/shagi.rb
|
145
|
+
- test/top.rb
|