opal 0.6.3 → 0.7.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.spectator +2 -0
- data/.spectator-mspec +3 -0
- data/.travis.yml +8 -11
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTING.md +8 -43
- data/Gemfile +15 -4
- data/Guardfile +77 -0
- data/README.md +15 -9
- data/Rakefile +36 -12
- data/benchmarks/operators.rb +11 -0
- data/bin/opal +10 -13
- data/bin/opal-build +4 -4
- data/bin/opal-mspec +10 -0
- data/bin/opal-repl +4 -3
- data/examples/sinatra/Gemfile +1 -1
- data/examples/sinatra/config.ru +3 -3
- data/lib/mspec/opal/main.rb.erb +2 -2
- data/lib/mspec/opal/rake_task.rb +31 -24
- data/lib/mspec/opal/runner.rb +18 -1
- data/lib/mspec/opal/sprockets.js +17 -0
- data/lib/opal.rb +1 -34
- data/lib/opal/builder.rb +92 -58
- data/lib/opal/builder_processors.rb +165 -0
- data/lib/opal/cli.rb +85 -144
- data/lib/opal/cli_options.rb +136 -90
- data/lib/opal/cli_runners.rb +10 -0
- data/lib/opal/cli_runners/nodejs.rb +56 -0
- data/lib/opal/cli_runners/phantom.js +35 -0
- data/lib/opal/cli_runners/phantomjs.rb +28 -0
- data/lib/opal/cli_runners/server.rb +54 -0
- data/lib/opal/compiler.rb +35 -16
- data/lib/opal/erb.rb +29 -15
- data/lib/opal/hike_path_finder.rb +18 -0
- data/lib/opal/nodes.rb +1 -0
- data/lib/opal/nodes/call.rb +107 -26
- data/lib/opal/nodes/call_special.rb +31 -6
- data/lib/opal/nodes/class.rb +2 -2
- data/lib/opal/nodes/constants.rb +5 -20
- data/lib/opal/nodes/def.rb +4 -4
- data/lib/opal/nodes/defined.rb +3 -3
- data/lib/opal/nodes/definitions.rb +1 -1
- data/lib/opal/nodes/for.rb +35 -0
- data/lib/opal/nodes/helpers.rb +2 -2
- data/lib/opal/nodes/iter.rb +3 -3
- data/lib/opal/nodes/literal.rb +10 -2
- data/lib/opal/nodes/masgn.rb +2 -2
- data/lib/opal/nodes/module.rb +2 -2
- data/lib/opal/nodes/scope.rb +1 -0
- data/lib/opal/nodes/singleton_class.rb +2 -2
- data/lib/opal/nodes/super.rb +2 -2
- data/lib/opal/nodes/top.rb +30 -3
- data/lib/opal/parser.rb +15 -1
- data/lib/opal/parser/grammar.rb +2571 -2452
- data/lib/opal/parser/grammar.y +37 -5
- data/lib/opal/parser/keywords.rb +2 -0
- data/lib/opal/parser/lexer.rb +21 -11
- data/lib/opal/path_reader.rb +28 -0
- data/lib/opal/paths.rb +38 -0
- data/lib/opal/source_map.rb +32 -15
- data/lib/opal/sprockets/environment.rb +9 -2
- data/lib/opal/sprockets/erb.rb +1 -2
- data/lib/opal/sprockets/path_reader.rb +34 -0
- data/lib/opal/sprockets/processor.rb +40 -39
- data/lib/opal/sprockets/server.rb +47 -33
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +10 -5
- data/opal/README.md +6 -0
- data/opal/corelib/array.rb +36 -4
- data/opal/corelib/array/inheritance.rb +6 -6
- data/opal/corelib/basic_object.rb +9 -9
- data/opal/corelib/boolean.rb +1 -1
- data/opal/corelib/class.rb +12 -12
- data/opal/corelib/dir.rb +20 -0
- data/opal/corelib/enumerable.rb +42 -42
- data/opal/corelib/enumerator.rb +1 -1
- data/opal/corelib/error.rb +2 -2
- data/opal/corelib/file.rb +56 -0
- data/opal/corelib/hash.rb +5 -5
- data/opal/corelib/helpers.rb +3 -3
- data/opal/corelib/io.rb +13 -10
- data/opal/corelib/kernel.rb +44 -68
- data/opal/corelib/method.rb +1 -1
- data/opal/corelib/module.rb +89 -114
- data/opal/corelib/nil_class.rb +1 -1
- data/opal/corelib/numeric.rb +27 -23
- data/opal/corelib/proc.rb +5 -5
- data/opal/corelib/range.rb +8 -4
- data/opal/corelib/regexp.rb +5 -5
- data/opal/corelib/runtime.js +589 -272
- data/opal/corelib/string.rb +52 -37
- data/opal/corelib/string/inheritance.rb +5 -5
- data/opal/corelib/time.rb +102 -52
- data/opal/corelib/variables.rb +3 -3
- data/opal/opal.rb +2 -0
- data/package.json +9 -0
- data/spec/filters/bugs/array.rb +0 -6
- data/spec/filters/bugs/language.rb +4 -0
- data/spec/filters/bugs/numeric.rb +7 -6
- data/spec/filters/bugs/opal.rb +2 -0
- data/spec/filters/bugs/regexp.rb +4 -0
- data/spec/filters/bugs/string.rb +0 -7
- data/spec/filters/bugs/stringscanner.rb +4 -1
- data/spec/filters/unsupported/private_methods.rb +2 -0
- data/spec/lib/builder_processors_spec.rb +27 -0
- data/spec/lib/builder_spec.rb +66 -0
- data/spec/{cli → lib}/cli_spec.rb +60 -5
- data/spec/{cli → lib}/compiler_spec.rb +66 -5
- data/spec/{cli → lib}/dependency_resolver_spec.rb +1 -1
- data/spec/lib/fixtures/no_requires.rb +1 -0
- data/spec/{cli → lib}/fixtures/opal_file.rb +0 -0
- data/spec/lib/fixtures/require_tree_test.rb +3 -0
- data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
- data/spec/lib/fixtures/requires.rb +7 -0
- data/spec/{cli → lib}/fixtures/sprockets_file.js.rb +0 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/hike_path_finder_spec.rb +23 -0
- data/spec/{cli → lib}/lexer_spec.rb +1 -1
- data/spec/{cli → lib}/parser/alias_spec.rb +1 -1
- data/spec/{cli → lib}/parser/and_spec.rb +1 -1
- data/spec/{cli → lib}/parser/attrasgn_spec.rb +1 -1
- data/spec/{cli → lib}/parser/begin_spec.rb +1 -1
- data/spec/{cli → lib}/parser/block_spec.rb +1 -1
- data/spec/{cli → lib}/parser/break_spec.rb +1 -1
- data/spec/{cli → lib}/parser/call_spec.rb +1 -1
- data/spec/{cli → lib}/parser/class_spec.rb +1 -1
- data/spec/{cli → lib}/parser/comments_spec.rb +1 -1
- data/spec/{cli → lib}/parser/def_spec.rb +1 -1
- data/spec/{cli → lib}/parser/if_spec.rb +1 -1
- data/spec/{cli → lib}/parser/iter_spec.rb +1 -1
- data/spec/{cli → lib}/parser/lambda_spec.rb +1 -1
- data/spec/{cli → lib}/parser/literal_spec.rb +1 -1
- data/spec/{cli → lib}/parser/masgn_spec.rb +1 -1
- data/spec/{cli → lib}/parser/module_spec.rb +1 -1
- data/spec/{cli → lib}/parser/not_spec.rb +1 -1
- data/spec/{cli → lib}/parser/op_asgn1_spec.rb +1 -1
- data/spec/{cli → lib}/parser/op_asgn2_spec.rb +1 -1
- data/spec/{cli → lib}/parser/or_spec.rb +1 -1
- data/spec/{cli → lib}/parser/return_spec.rb +1 -1
- data/spec/{cli → lib}/parser/sclass_spec.rb +1 -1
- data/spec/{cli → lib}/parser/string_spec.rb +8 -1
- data/spec/{cli → lib}/parser/super_spec.rb +1 -1
- data/spec/lib/parser/unary_spec.rb +48 -0
- data/spec/{cli → lib}/parser/undef_spec.rb +1 -1
- data/spec/{cli → lib}/parser/unless_spec.rb +1 -1
- data/spec/{cli → lib}/parser/variables_spec.rb +1 -1
- data/spec/{cli → lib}/parser/while_spec.rb +1 -1
- data/spec/{cli → lib}/parser/yield_spec.rb +1 -1
- data/spec/lib/path_reader_spec.rb +24 -0
- data/spec/lib/shared/path_finder_shared.rb +19 -0
- data/spec/lib/shared/path_reader_shared.rb +31 -0
- data/spec/lib/spec_helper.rb +9 -0
- data/spec/lib/sprockets/environment_spec.rb +30 -0
- data/spec/{cli → lib}/sprockets/erb_spec.rb +1 -1
- data/spec/lib/sprockets/path_reader_spec.rb +25 -0
- data/spec/{cli → lib}/sprockets/processor_spec.rb +9 -2
- data/spec/lib/sprockets/server_spec.rb +20 -0
- data/spec/opal/compiler/irb_spec.rb +11 -11
- data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +7 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +2 -2
- data/spec/opal/core/runtime/method_missing_spec.rb +19 -0
- data/spec/opal/core/source_map_spec.rb +2 -2
- data/spec/opal/core/string_spec.rb +11 -0
- data/spec/opal/stdlib/erb/erb_spec.rb +0 -1
- data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
- data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
- data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
- data/spec/rubyspecs +54 -11
- data/spec/spec_helper.rb +18 -3
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/{cli/spec_helper.rb → support/parser_helpers.rb} +10 -10
- data/stdlib/README.md +3 -0
- data/stdlib/benchmark.rb +10 -0
- data/stdlib/date.rb +2 -2
- data/stdlib/dir.rb +1 -5
- data/stdlib/file.rb +1 -7
- data/stdlib/json.rb +10 -1
- data/stdlib/native.rb +5 -5
- data/stdlib/nodejs.rb +5 -0
- data/stdlib/nodejs/dir.rb +13 -0
- data/stdlib/nodejs/file.rb +98 -0
- data/stdlib/nodejs/fileutils.rb +26 -0
- data/stdlib/nodejs/io.rb +2 -0
- data/stdlib/nodejs/irb.rb +45 -0
- data/stdlib/nodejs/process.rb +16 -0
- data/stdlib/nodejs/require.rb +32 -0
- data/stdlib/nodejs/rubygems.rb +68 -0
- data/stdlib/nodejs/runtime.rb +25 -0
- data/stdlib/nodejs/yaml.rb +11 -0
- data/stdlib/opal-parser.rb +1 -2
- data/stdlib/opal-source-maps.rb +2 -0
- data/stdlib/phantomjs.rb +8 -0
- data/stdlib/process.rb +10 -0
- data/stdlib/promise.rb +12 -4
- data/stdlib/set.rb +27 -0
- data/stdlib/source_map.rb +5 -63
- data/stdlib/source_map/map.rb +220 -0
- data/stdlib/source_map/mapping.rb +26 -0
- data/stdlib/source_map/offset.rb +88 -0
- data/stdlib/source_map/version.rb +3 -0
- data/stdlib/source_map/vlq.rb +77 -101
- data/stdlib/sourcemap.rb +1 -0
- data/stdlib/strscan.rb +7 -1
- data/stdlib/template.rb +1 -1
- data/stdlib/thread.rb +147 -7
- metadata +238 -104
- data/lib/mspec/opal/mspec_fixes.rb +0 -87
- data/spec/cli/sprockets/environment_spec.rb +0 -14
- data/spec/filters/bugs/symbol.rb +0 -5
- data/spec/opal/core/kernel/warn_spec.rb +0 -83
- data/spec/opal/core/language/numbers_spec.rb +0 -60
- data/stdlib/opal-source-maps.js.erb +0 -2
- data/stdlib/source_map/generator.rb +0 -251
- data/stdlib/source_map/parser.rb +0 -102
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'rack/file'
|
2
|
+
require 'rack/static'
|
2
3
|
require 'rack/urlmap'
|
3
4
|
require 'rack/builder'
|
5
|
+
require 'rack/deflater'
|
4
6
|
require 'rack/directory'
|
5
7
|
require 'rack/showexceptions'
|
6
8
|
require 'opal/source_map'
|
@@ -10,40 +12,54 @@ require 'erb'
|
|
10
12
|
module Opal
|
11
13
|
|
12
14
|
class SourceMapServer
|
13
|
-
def initialize sprockets
|
15
|
+
def initialize sprockets, prefix = '/'
|
14
16
|
@sprockets = sprockets
|
17
|
+
@prefix = prefix
|
15
18
|
end
|
16
19
|
|
17
|
-
attr_reader :sprockets
|
18
|
-
|
19
|
-
attr_writer :prefix
|
20
|
-
|
21
|
-
def prefix
|
22
|
-
@prefix ||= '/__opal_source_maps__'
|
23
|
-
end
|
20
|
+
attr_reader :sprockets, :prefix
|
24
21
|
|
25
22
|
def inspect
|
26
23
|
"#<#{self.class}:#{object_id}>"
|
27
24
|
end
|
28
25
|
|
29
26
|
def call(env)
|
30
|
-
|
27
|
+
prefix_regex = %r{^(?:#{prefix}/|/)}
|
28
|
+
path_info = env['PATH_INFO'].to_s.sub(prefix_regex, '')
|
31
29
|
|
32
|
-
|
33
|
-
|
30
|
+
case path_info
|
31
|
+
when %r{^(.*)\.map$}
|
32
|
+
path = $1
|
34
33
|
asset = sprockets[path]
|
35
|
-
return
|
34
|
+
return not_found(path) if asset.nil?
|
36
35
|
|
37
|
-
|
36
|
+
# "logical_name" of a BundledAsset keeps the .js extension
|
37
|
+
source = register[asset.logical_path.sub(/\.js$/, '')]
|
38
|
+
return not_found(asset) if source.nil?
|
39
|
+
|
40
|
+
return [200, {"Content-Type" => "text/json"}, [source.to_s]]
|
41
|
+
when %r{^(.*)\.rb$}
|
42
|
+
source = File.read(sprockets.resolve(path_info))
|
43
|
+
return not_found(path_info) if source.nil?
|
44
|
+
return [200, {"Content-Type" => "text/ruby"}, [source]]
|
38
45
|
else
|
39
|
-
|
46
|
+
not_found(path_info)
|
40
47
|
end
|
41
48
|
end
|
49
|
+
|
50
|
+
def not_found(*messages)
|
51
|
+
not_found = [404, {}, [{not_found: messages, keys: register.keys}.inspect]]
|
52
|
+
end
|
53
|
+
|
54
|
+
def register
|
55
|
+
Opal::Processor.source_map_register
|
56
|
+
end
|
42
57
|
end
|
43
58
|
|
44
59
|
class Server
|
45
60
|
|
46
|
-
attr_accessor :debug, :use_index, :index_path, :main, :public_root,
|
61
|
+
attr_accessor :debug, :use_index, :index_path, :main, :public_root,
|
62
|
+
:public_urls, :sprockets, :prefix
|
47
63
|
|
48
64
|
def initialize debug_or_options = {}
|
49
65
|
unless Hash === debug_or_options
|
@@ -59,6 +75,7 @@ module Opal
|
|
59
75
|
@public_urls = ['/']
|
60
76
|
@sprockets = Environment.new
|
61
77
|
@debug = options.fetch(:debug, true)
|
78
|
+
@prefix = options.fetch(:prefix, '/assets')
|
62
79
|
|
63
80
|
yield self if block_given?
|
64
81
|
create_app
|
@@ -86,24 +103,21 @@ module Opal
|
|
86
103
|
end
|
87
104
|
|
88
105
|
def create_app
|
89
|
-
server, sprockets = self, @sprockets
|
90
|
-
|
106
|
+
server, sprockets, prefix = self, @sprockets, self.prefix
|
107
|
+
sprockets.logger.level ||= Logger::DEBUG
|
91
108
|
@app = Rack::Builder.app do
|
92
109
|
not_found = lambda { |env| [404, {}, []] }
|
93
|
-
|
94
110
|
use Rack::Deflater
|
95
111
|
use Rack::ShowExceptions
|
96
|
-
map('/assets') { run sprockets }
|
97
|
-
map(server.source_maps.prefix) { run server.source_maps } if server.source_map_enabled
|
98
112
|
use Index, server if server.use_index
|
113
|
+
assets = []
|
114
|
+
assets << SourceMapServer.new(sprockets, prefix) if server.source_map_enabled
|
115
|
+
assets << sprockets
|
116
|
+
map(prefix) { run Rack::Cascade.new(assets) }
|
99
117
|
run Rack::Static.new(not_found, :root => server.public_root, :urls => server.public_urls)
|
100
118
|
end
|
101
119
|
end
|
102
120
|
|
103
|
-
def source_maps
|
104
|
-
@source_maps ||= SourceMapServer.new(@sprockets)
|
105
|
-
end
|
106
|
-
|
107
121
|
def call(env)
|
108
122
|
@app.call env
|
109
123
|
end
|
@@ -151,15 +165,15 @@ module Opal
|
|
151
165
|
end
|
152
166
|
|
153
167
|
SOURCE = <<-HTML
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
168
|
+
<!DOCTYPE html>
|
169
|
+
<html>
|
170
|
+
<head>
|
171
|
+
<title>Opal Server</title>
|
172
|
+
</head>
|
173
|
+
<body>
|
174
|
+
<%= javascript_include_tag @server.main %>
|
175
|
+
</body>
|
176
|
+
</html>
|
163
177
|
HTML
|
164
178
|
end
|
165
179
|
end
|
data/lib/opal/version.rb
CHANGED
data/opal.gemspec
CHANGED
@@ -18,14 +18,19 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.require_paths = ['lib']
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
required_ruby_version = '>= 1.9.3'
|
22
|
+
|
23
|
+
s.add_dependency 'sourcemap', '~> 0.1.0'
|
24
|
+
s.add_dependency 'sprockets', '>= 2.2.1', '< 4.0.0'
|
25
|
+
s.add_dependency 'hike', '~> 1.2'
|
26
|
+
s.add_dependency 'tilt', '~> 1.4'
|
23
27
|
|
24
28
|
s.add_development_dependency 'mspec', '1.5.20'
|
25
29
|
s.add_development_dependency 'rake'
|
26
30
|
s.add_development_dependency 'racc'
|
27
|
-
s.add_development_dependency 'rspec', '~> 2.
|
31
|
+
s.add_development_dependency 'rspec', '~> 2.99'
|
28
32
|
s.add_development_dependency 'octokit', '~> 2.4.0'
|
29
|
-
s.add_development_dependency 'bundler', '~> 1.
|
30
|
-
s.add_development_dependency 'yard'
|
33
|
+
s.add_development_dependency 'bundler', '~> 1.5'
|
34
|
+
s.add_development_dependency 'yard', '~> 0.8.7'
|
35
|
+
s.add_development_dependency 'rack-test'
|
31
36
|
end
|
data/opal/README.md
ADDED
data/opal/corelib/array.rb
CHANGED
@@ -4,7 +4,7 @@ class Array
|
|
4
4
|
include Enumerable
|
5
5
|
|
6
6
|
# Mark all javascript arrays as being valid ruby arrays
|
7
|
-
`def
|
7
|
+
`def.$$is_array = true`
|
8
8
|
|
9
9
|
def self.[](*objects)
|
10
10
|
objects
|
@@ -95,6 +95,38 @@ class Array
|
|
95
95
|
}
|
96
96
|
end
|
97
97
|
|
98
|
+
def |(other)
|
99
|
+
if Array === other
|
100
|
+
other = other.to_a
|
101
|
+
else
|
102
|
+
other = Opal.coerce_to(other, Array, :to_ary).to_a
|
103
|
+
end
|
104
|
+
|
105
|
+
%x{
|
106
|
+
var result = [],
|
107
|
+
seen = {};
|
108
|
+
|
109
|
+
for (var i = 0, length = self.length; i < length; i++) {
|
110
|
+
var item = self[i];
|
111
|
+
|
112
|
+
if (!seen[item]) {
|
113
|
+
seen[item] = true;
|
114
|
+
result.push(item);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
for (var i = 0, length = other.length; i < length; i++) {
|
119
|
+
var item = other[i];
|
120
|
+
|
121
|
+
if (!seen[item]) {
|
122
|
+
seen[item] = true;
|
123
|
+
result.push(item);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
return result;
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
98
130
|
def *(other)
|
99
131
|
return `self.join(#{other.to_str})` if other.respond_to? :to_str
|
100
132
|
|
@@ -212,7 +244,7 @@ class Array
|
|
212
244
|
var a = self[i],
|
213
245
|
b = other[i];
|
214
246
|
|
215
|
-
if (a
|
247
|
+
if (a.$$is_array && b.$$is_array && (a === self)) {
|
216
248
|
continue;
|
217
249
|
}
|
218
250
|
|
@@ -689,7 +721,7 @@ class Array
|
|
689
721
|
var a = self[i],
|
690
722
|
b = other[i];
|
691
723
|
|
692
|
-
if (a
|
724
|
+
if (a.$$is_array && b.$$is_array && (a === self)) {
|
693
725
|
continue;
|
694
726
|
}
|
695
727
|
|
@@ -884,7 +916,7 @@ class Array
|
|
884
916
|
end
|
885
917
|
|
886
918
|
def hash
|
887
|
-
`self
|
919
|
+
`self.$$id || (self.$$id = Opal.uid())`
|
888
920
|
end
|
889
921
|
|
890
922
|
def include?(member)
|
@@ -3,10 +3,10 @@ class Array
|
|
3
3
|
replace = Class.new(Array::Wrapper)
|
4
4
|
|
5
5
|
%x{
|
6
|
-
klass
|
7
|
-
klass
|
8
|
-
klass
|
9
|
-
klass
|
6
|
+
klass.$$proto = replace.$$proto;
|
7
|
+
klass.$$proto.$$class = klass;
|
8
|
+
klass.$$alloc = replace.$$alloc;
|
9
|
+
klass.$$parent = #{Array::Wrapper};
|
10
10
|
|
11
11
|
klass.$allocate = replace.$allocate;
|
12
12
|
klass.$new = replace.$new;
|
@@ -79,7 +79,7 @@ class Array::Wrapper
|
|
79
79
|
%x{
|
80
80
|
var result = #{@literal * other};
|
81
81
|
|
82
|
-
if (result
|
82
|
+
if (result.$$is_array) {
|
83
83
|
return #{self.class.allocate(`result`)}
|
84
84
|
}
|
85
85
|
else {
|
@@ -92,7 +92,7 @@ class Array::Wrapper
|
|
92
92
|
%x{
|
93
93
|
var result = #{@literal.slice(index, length)};
|
94
94
|
|
95
|
-
if (result
|
95
|
+
if (result.$$is_array && (index.$$is_range || length !== undefined)) {
|
96
96
|
return #{self.class.allocate(`result`)}
|
97
97
|
}
|
98
98
|
else {
|
@@ -7,7 +7,7 @@ class BasicObject
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def __id__
|
10
|
-
`self
|
10
|
+
`self.$$id || (self.$$id = Opal.uid())`
|
11
11
|
end
|
12
12
|
|
13
13
|
def __send__(symbol, *args, &block)
|
@@ -16,14 +16,14 @@ class BasicObject
|
|
16
16
|
|
17
17
|
if (func) {
|
18
18
|
if (block !== nil) {
|
19
|
-
func
|
19
|
+
func.$$p = block;
|
20
20
|
}
|
21
21
|
|
22
22
|
return func.apply(self, args);
|
23
23
|
}
|
24
24
|
|
25
25
|
if (block !== nil) {
|
26
|
-
self.$method_missing
|
26
|
+
self.$method_missing.$$p = block;
|
27
27
|
}
|
28
28
|
|
29
29
|
return self.$method_missing.apply(self, [symbol].concat(args));
|
@@ -41,12 +41,12 @@ class BasicObject
|
|
41
41
|
Kernel.raise ArgumentError, "no block given" unless block
|
42
42
|
|
43
43
|
%x{
|
44
|
-
var old = block
|
44
|
+
var old = block.$$s,
|
45
45
|
result;
|
46
46
|
|
47
|
-
block
|
47
|
+
block.$$s = null;
|
48
48
|
result = block.call(self, self);
|
49
|
-
block
|
49
|
+
block.$$s = old;
|
50
50
|
|
51
51
|
return result;
|
52
52
|
}
|
@@ -56,12 +56,12 @@ class BasicObject
|
|
56
56
|
Kernel.raise ArgumentError, "no block given" unless block
|
57
57
|
|
58
58
|
%x{
|
59
|
-
var block_self = block
|
59
|
+
var block_self = block.$$s,
|
60
60
|
result;
|
61
61
|
|
62
|
-
block
|
62
|
+
block.$$s = null;
|
63
63
|
result = block.apply(self, args);
|
64
|
-
block
|
64
|
+
block.$$s = block_self;
|
65
65
|
|
66
66
|
return result;
|
67
67
|
}
|
data/opal/corelib/boolean.rb
CHANGED
data/opal/corelib/class.rb
CHANGED
@@ -3,25 +3,25 @@ require 'corelib/module'
|
|
3
3
|
class Class
|
4
4
|
def self.new(sup = Object, &block)
|
5
5
|
%x{
|
6
|
-
if (!sup
|
6
|
+
if (!sup.$$is_class || sup.$$is_mod) {
|
7
7
|
#{raise TypeError, "superclass must be a Class"};
|
8
8
|
}
|
9
9
|
|
10
10
|
function AnonClass(){};
|
11
|
-
var klass
|
12
|
-
klass
|
13
|
-
klass
|
11
|
+
var klass = Opal.boot(sup, AnonClass)
|
12
|
+
klass.$$name = nil;
|
13
|
+
klass.$$parent = sup;
|
14
14
|
|
15
15
|
// inherit scope from parent
|
16
|
-
$opal.create_scope(sup
|
16
|
+
$opal.create_scope(sup.$$scope, klass);
|
17
17
|
|
18
18
|
sup.$inherited(klass);
|
19
19
|
|
20
20
|
if (block !== nil) {
|
21
|
-
var block_self = block
|
22
|
-
block
|
21
|
+
var block_self = block.$$s;
|
22
|
+
block.$$s = null;
|
23
23
|
block.call(klass);
|
24
|
-
block
|
24
|
+
block.$$s = block_self;
|
25
25
|
}
|
26
26
|
|
27
27
|
return klass;
|
@@ -30,8 +30,8 @@ class Class
|
|
30
30
|
|
31
31
|
def allocate
|
32
32
|
%x{
|
33
|
-
var obj = new self
|
34
|
-
obj
|
33
|
+
var obj = new self.$$alloc;
|
34
|
+
obj.$$id = Opal.uid();
|
35
35
|
return obj;
|
36
36
|
}
|
37
37
|
end
|
@@ -43,13 +43,13 @@ class Class
|
|
43
43
|
%x{
|
44
44
|
var obj = #{allocate};
|
45
45
|
|
46
|
-
obj.$initialize
|
46
|
+
obj.$initialize.$$p = block;
|
47
47
|
obj.$initialize.apply(obj, args);
|
48
48
|
return obj;
|
49
49
|
}
|
50
50
|
end
|
51
51
|
|
52
52
|
def superclass
|
53
|
-
`self
|
53
|
+
`self.$$super || nil`
|
54
54
|
end
|
55
55
|
end
|
data/opal/corelib/dir.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class Dir
|
2
|
+
class << self
|
3
|
+
def chdir(dir)
|
4
|
+
prev_cwd = `$opal.current_dir`
|
5
|
+
`$opal.current_dir = #{dir}`
|
6
|
+
yield
|
7
|
+
ensure
|
8
|
+
`$opal.current_dir = #{prev_cwd}`
|
9
|
+
end
|
10
|
+
|
11
|
+
def pwd
|
12
|
+
`$opal.current_dir` || '.'
|
13
|
+
end
|
14
|
+
alias getwd pwd
|
15
|
+
|
16
|
+
def home
|
17
|
+
ENV['HOME'] || '.'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/opal/corelib/enumerable.rb
CHANGED
@@ -4,7 +4,7 @@ module Enumerable
|
|
4
4
|
var result = true;
|
5
5
|
|
6
6
|
if (block !== nil) {
|
7
|
-
self.$each
|
7
|
+
self.$each.$$p = function() {
|
8
8
|
var value = $opal.$yieldX(block, arguments);
|
9
9
|
|
10
10
|
if (value === $breaker) {
|
@@ -19,7 +19,7 @@ module Enumerable
|
|
19
19
|
}
|
20
20
|
}
|
21
21
|
else {
|
22
|
-
self.$each
|
22
|
+
self.$each.$$p = function(obj) {
|
23
23
|
if (arguments.length == 1 && #{Opal.falsy?(`obj`)}) {
|
24
24
|
result = false;
|
25
25
|
return $breaker;
|
@@ -38,7 +38,7 @@ module Enumerable
|
|
38
38
|
var result = false;
|
39
39
|
|
40
40
|
if (block !== nil) {
|
41
|
-
self.$each
|
41
|
+
self.$each.$$p = function() {
|
42
42
|
var value = $opal.$yieldX(block, arguments);
|
43
43
|
|
44
44
|
if (value === $breaker) {
|
@@ -53,7 +53,7 @@ module Enumerable
|
|
53
53
|
};
|
54
54
|
}
|
55
55
|
else {
|
56
|
-
self.$each
|
56
|
+
self.$each.$$p = function(obj) {
|
57
57
|
if (arguments.length != 1 || #{Opal.truthy?(`obj`)}) {
|
58
58
|
result = true;
|
59
59
|
return $breaker;
|
@@ -77,7 +77,7 @@ module Enumerable
|
|
77
77
|
%x{
|
78
78
|
var result = [];
|
79
79
|
|
80
|
-
self.$each
|
80
|
+
self.$each.$$p = function() {
|
81
81
|
var value = $opal.$yieldX(block, arguments);
|
82
82
|
|
83
83
|
if (value === $breaker) {
|
@@ -112,7 +112,7 @@ module Enumerable
|
|
112
112
|
block = function() { return true; };
|
113
113
|
}
|
114
114
|
|
115
|
-
self.$each
|
115
|
+
self.$each.$$p = function() {
|
116
116
|
var value = $opal.$yieldX(block, arguments);
|
117
117
|
|
118
118
|
if (value === $breaker) {
|
@@ -144,7 +144,7 @@ module Enumerable
|
|
144
144
|
var result,
|
145
145
|
all = [];
|
146
146
|
|
147
|
-
self.$each
|
147
|
+
self.$each.$$p = function() {
|
148
148
|
var param = #{Opal.destructure(`arguments`)},
|
149
149
|
value = $opal.$yield1(block, param);
|
150
150
|
|
@@ -202,7 +202,7 @@ module Enumerable
|
|
202
202
|
%x{
|
203
203
|
var result = undefined;
|
204
204
|
|
205
|
-
self.$each
|
205
|
+
self.$each.$$p = function() {
|
206
206
|
var params = #{Opal.destructure(`arguments`)},
|
207
207
|
value = $opal.$yield1(block, params);
|
208
208
|
|
@@ -243,7 +243,7 @@ module Enumerable
|
|
243
243
|
var result = [],
|
244
244
|
current = 0;
|
245
245
|
|
246
|
-
self.$each
|
246
|
+
self.$each.$$p = function() {
|
247
247
|
if (number <= current) {
|
248
248
|
result.push(#{Opal.destructure(`arguments`)});
|
249
249
|
}
|
@@ -264,7 +264,7 @@ module Enumerable
|
|
264
264
|
var result = [],
|
265
265
|
dropping = true;
|
266
266
|
|
267
|
-
self.$each
|
267
|
+
self.$each.$$p = function() {
|
268
268
|
var param = #{Opal.destructure(`arguments`)};
|
269
269
|
|
270
270
|
if (dropping) {
|
@@ -312,7 +312,7 @@ module Enumerable
|
|
312
312
|
var result,
|
313
313
|
slice = []
|
314
314
|
|
315
|
-
self.$each
|
315
|
+
self.$each.$$p = function() {
|
316
316
|
var param = #{Opal.destructure(`arguments`)};
|
317
317
|
|
318
318
|
slice.push(param);
|
@@ -351,7 +351,7 @@ module Enumerable
|
|
351
351
|
var result,
|
352
352
|
index = 0;
|
353
353
|
|
354
|
-
self.$each
|
354
|
+
self.$each.$$p = function() {
|
355
355
|
var param = #{Opal.destructure(`arguments`)},
|
356
356
|
value = block(param, index);
|
357
357
|
|
@@ -379,7 +379,7 @@ module Enumerable
|
|
379
379
|
%x{
|
380
380
|
var result;
|
381
381
|
|
382
|
-
self.$each
|
382
|
+
self.$each.$$p = function() {
|
383
383
|
var param = #{Opal.destructure(`arguments`)},
|
384
384
|
value = block(param, object);
|
385
385
|
|
@@ -403,7 +403,7 @@ module Enumerable
|
|
403
403
|
%x{
|
404
404
|
var result = [];
|
405
405
|
|
406
|
-
self.$each
|
406
|
+
self.$each.$$p = function() {
|
407
407
|
result.push(#{Opal.destructure(`arguments`)});
|
408
408
|
};
|
409
409
|
|
@@ -421,7 +421,7 @@ module Enumerable
|
|
421
421
|
%x{
|
422
422
|
var result = [];
|
423
423
|
|
424
|
-
self.$each
|
424
|
+
self.$each.$$p = function() {
|
425
425
|
var param = #{Opal.destructure(`arguments`)},
|
426
426
|
value = $opal.$yield1(block, param);
|
427
427
|
|
@@ -449,7 +449,7 @@ module Enumerable
|
|
449
449
|
index = 0;
|
450
450
|
|
451
451
|
if (object != null) {
|
452
|
-
self.$each
|
452
|
+
self.$each.$$p = function() {
|
453
453
|
var param = #{Opal.destructure(`arguments`)};
|
454
454
|
|
455
455
|
if (#{`param` == `object`}) {
|
@@ -461,7 +461,7 @@ module Enumerable
|
|
461
461
|
};
|
462
462
|
}
|
463
463
|
else if (block !== nil) {
|
464
|
-
self.$each
|
464
|
+
self.$each.$$p = function() {
|
465
465
|
var value = $opal.$yieldX(block, arguments);
|
466
466
|
|
467
467
|
if (value === $breaker) {
|
@@ -489,7 +489,7 @@ module Enumerable
|
|
489
489
|
result = nil
|
490
490
|
|
491
491
|
%x{
|
492
|
-
self.$each
|
492
|
+
self.$each.$$p = function() {
|
493
493
|
result = #{Opal.destructure(`arguments`)};
|
494
494
|
|
495
495
|
return $breaker;
|
@@ -513,7 +513,7 @@ module Enumerable
|
|
513
513
|
var current = 0,
|
514
514
|
number = #{Opal.coerce_to number, Integer, :to_int};
|
515
515
|
|
516
|
-
self.$each
|
516
|
+
self.$each.$$p = function() {
|
517
517
|
result.push(#{Opal.destructure(`arguments`)});
|
518
518
|
|
519
519
|
if (number <= ++current) {
|
@@ -535,7 +535,7 @@ module Enumerable
|
|
535
535
|
var result = [];
|
536
536
|
|
537
537
|
if (block !== nil) {
|
538
|
-
self.$each
|
538
|
+
self.$each.$$p = function() {
|
539
539
|
var param = #{Opal.destructure(`arguments`)},
|
540
540
|
value = #{pattern === `param`};
|
541
541
|
|
@@ -552,7 +552,7 @@ module Enumerable
|
|
552
552
|
};
|
553
553
|
}
|
554
554
|
else {
|
555
|
-
self.$each
|
555
|
+
self.$each.$$p = function() {
|
556
556
|
var param = #{Opal.destructure(`arguments`)},
|
557
557
|
value = #{pattern === `param`};
|
558
558
|
|
@@ -576,7 +576,7 @@ module Enumerable
|
|
576
576
|
%x{
|
577
577
|
var result;
|
578
578
|
|
579
|
-
self.$each
|
579
|
+
self.$each.$$p = function() {
|
580
580
|
var param = #{Opal.destructure(`arguments`)},
|
581
581
|
value = $opal.$yield1(block, param);
|
582
582
|
|
@@ -602,7 +602,7 @@ module Enumerable
|
|
602
602
|
%x{
|
603
603
|
var result = false;
|
604
604
|
|
605
|
-
self.$each
|
605
|
+
self.$each.$$p = function() {
|
606
606
|
var param = #{Opal.destructure(`arguments`)};
|
607
607
|
|
608
608
|
if (#{`param` == obj}) {
|
@@ -622,7 +622,7 @@ module Enumerable
|
|
622
622
|
var result = object;
|
623
623
|
|
624
624
|
if (block !== nil && sym === undefined) {
|
625
|
-
self.$each
|
625
|
+
self.$each.$$p = function() {
|
626
626
|
var value = #{Opal.destructure(`arguments`)};
|
627
627
|
|
628
628
|
if (result === undefined) {
|
@@ -650,7 +650,7 @@ module Enumerable
|
|
650
650
|
result = undefined;
|
651
651
|
}
|
652
652
|
|
653
|
-
self.$each
|
653
|
+
self.$each.$$p = function() {
|
654
654
|
var value = #{Opal.destructure(`arguments`)};
|
655
655
|
|
656
656
|
if (result === undefined) {
|
@@ -686,7 +686,7 @@ module Enumerable
|
|
686
686
|
var result;
|
687
687
|
|
688
688
|
if (block !== nil) {
|
689
|
-
self.$each
|
689
|
+
self.$each.$$p = function() {
|
690
690
|
var param = #{Opal.destructure(`arguments`)};
|
691
691
|
|
692
692
|
if (result === undefined) {
|
@@ -711,7 +711,7 @@ module Enumerable
|
|
711
711
|
};
|
712
712
|
}
|
713
713
|
else {
|
714
|
-
self.$each
|
714
|
+
self.$each.$$p = function() {
|
715
715
|
var param = #{Opal.destructure(`arguments`)};
|
716
716
|
|
717
717
|
if (result === undefined) {
|
@@ -738,7 +738,7 @@ module Enumerable
|
|
738
738
|
var result,
|
739
739
|
by;
|
740
740
|
|
741
|
-
self.$each
|
741
|
+
self.$each.$$p = function() {
|
742
742
|
var param = #{Opal.destructure(`arguments`)},
|
743
743
|
value = $opal.$yield1(block, param);
|
744
744
|
|
@@ -772,7 +772,7 @@ module Enumerable
|
|
772
772
|
var result;
|
773
773
|
|
774
774
|
if (block !== nil) {
|
775
|
-
self.$each
|
775
|
+
self.$each.$$p = function() {
|
776
776
|
var param = #{Opal.destructure(`arguments`)};
|
777
777
|
|
778
778
|
if (result === undefined) {
|
@@ -797,7 +797,7 @@ module Enumerable
|
|
797
797
|
};
|
798
798
|
}
|
799
799
|
else {
|
800
|
-
self.$each
|
800
|
+
self.$each.$$p = function() {
|
801
801
|
var param = #{Opal.destructure(`arguments`)};
|
802
802
|
|
803
803
|
if (result === undefined) {
|
@@ -824,7 +824,7 @@ module Enumerable
|
|
824
824
|
var result,
|
825
825
|
by;
|
826
826
|
|
827
|
-
self.$each
|
827
|
+
self.$each.$$p = function() {
|
828
828
|
var param = #{Opal.destructure(`arguments`)},
|
829
829
|
value = $opal.$yield1(block, param);
|
830
830
|
|
@@ -864,7 +864,7 @@ module Enumerable
|
|
864
864
|
var result = true;
|
865
865
|
|
866
866
|
if (block !== nil) {
|
867
|
-
self.$each
|
867
|
+
self.$each.$$p = function() {
|
868
868
|
var value = $opal.$yieldX(block, arguments);
|
869
869
|
|
870
870
|
if (value === $breaker) {
|
@@ -879,7 +879,7 @@ module Enumerable
|
|
879
879
|
}
|
880
880
|
}
|
881
881
|
else {
|
882
|
-
self.$each
|
882
|
+
self.$each.$$p = function() {
|
883
883
|
var value = #{Opal.destructure(`arguments`)};
|
884
884
|
|
885
885
|
if (#{Opal.truthy?(`value`)}) {
|
@@ -900,7 +900,7 @@ module Enumerable
|
|
900
900
|
var result = false;
|
901
901
|
|
902
902
|
if (block !== nil) {
|
903
|
-
self.$each
|
903
|
+
self.$each.$$p = function() {
|
904
904
|
var value = $opal.$yieldX(block, arguments);
|
905
905
|
|
906
906
|
if (value === $breaker) {
|
@@ -919,7 +919,7 @@ module Enumerable
|
|
919
919
|
}
|
920
920
|
}
|
921
921
|
else {
|
922
|
-
self.$each
|
922
|
+
self.$each.$$p = function() {
|
923
923
|
var value = #{Opal.destructure(`arguments`)};
|
924
924
|
|
925
925
|
if (#{Opal.truthy?(`value`)}) {
|
@@ -945,7 +945,7 @@ module Enumerable
|
|
945
945
|
%x{
|
946
946
|
var truthy = [], falsy = [];
|
947
947
|
|
948
|
-
self.$each
|
948
|
+
self.$each.$$p = function() {
|
949
949
|
var param = #{Opal.destructure(`arguments`)},
|
950
950
|
value = $opal.$yield1(block, param);
|
951
951
|
|
@@ -976,7 +976,7 @@ module Enumerable
|
|
976
976
|
%x{
|
977
977
|
var result = [];
|
978
978
|
|
979
|
-
self.$each
|
979
|
+
self.$each.$$p = function() {
|
980
980
|
var param = #{Opal.destructure(`arguments`)},
|
981
981
|
value = $opal.$yield1(block, param);
|
982
982
|
|
@@ -1002,7 +1002,7 @@ module Enumerable
|
|
1002
1002
|
%x{
|
1003
1003
|
var result = [];
|
1004
1004
|
|
1005
|
-
self.$each
|
1005
|
+
self.$each.$$p = function() {
|
1006
1006
|
result.push(arguments);
|
1007
1007
|
};
|
1008
1008
|
|
@@ -1029,7 +1029,7 @@ module Enumerable
|
|
1029
1029
|
|
1030
1030
|
if (block !== nil) {
|
1031
1031
|
if (pattern === undefined) {
|
1032
|
-
self.$each
|
1032
|
+
self.$each.$$p = function() {
|
1033
1033
|
var param = #{Opal.destructure(`arguments`)},
|
1034
1034
|
value = $opal.$yield1(block, param);
|
1035
1035
|
|
@@ -1042,7 +1042,7 @@ module Enumerable
|
|
1042
1042
|
};
|
1043
1043
|
}
|
1044
1044
|
else {
|
1045
|
-
self.$each
|
1045
|
+
self.$each.$$p = function() {
|
1046
1046
|
var param = #{Opal.destructure(`arguments`)},
|
1047
1047
|
value = block(param, #{pattern.dup});
|
1048
1048
|
|
@@ -1056,7 +1056,7 @@ module Enumerable
|
|
1056
1056
|
}
|
1057
1057
|
}
|
1058
1058
|
else {
|
1059
|
-
self.$each
|
1059
|
+
self.$each.$$p = function() {
|
1060
1060
|
var param = #{Opal.destructure(`arguments`)},
|
1061
1061
|
value = #{pattern === `param`};
|
1062
1062
|
|
@@ -1102,7 +1102,7 @@ module Enumerable
|
|
1102
1102
|
%x{
|
1103
1103
|
var result = [];
|
1104
1104
|
|
1105
|
-
self.$each
|
1105
|
+
self.$each.$$p = function() {
|
1106
1106
|
var param = #{Opal.destructure(`arguments`)},
|
1107
1107
|
value = $opal.$yield1(block, param);
|
1108
1108
|
|