opal 0.3.15 → 0.3.16
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.
- data/.gitignore +1 -1
- data/Gemfile +8 -2
- data/README.md +1 -1
- data/Rakefile +51 -57
- data/bin/opal +50 -2
- data/{runtime/corelib → core}/alpha.rb +6 -1
- data/{runtime/corelib → core}/array.rb +38 -42
- data/{runtime/corelib → core}/basic_object.rb +6 -17
- data/core/boolean.rb +40 -0
- data/core/class.rb +69 -0
- data/{runtime/corelib → core}/comparable.rb +0 -0
- data/core/debug.js +59 -0
- data/core/debug.rb +35 -0
- data/core/dir.rb +90 -0
- data/core/enumerable.rb +331 -0
- data/core/enumerator.rb +126 -0
- data/core/error.rb +40 -0
- data/{runtime/corelib → core}/file.rb +6 -3
- data/core/gemlib.rb +30 -0
- data/{runtime/corelib → core}/hash.rb +37 -35
- data/{runtime/corelib → core}/io.rb +0 -0
- data/{runtime/corelib → core}/kernel.rb +26 -21
- data/{runtime/corelib → core}/load_order +2 -5
- data/{runtime/corelib → core}/match_data.rb +2 -4
- data/core/module.rb +204 -0
- data/{runtime/corelib → core}/nil_class.rb +1 -7
- data/{runtime/corelib → core}/numeric.rb +9 -13
- data/core/object.rb +17 -0
- data/{runtime/corelib → core}/proc.rb +2 -13
- data/{runtime/corelib → core}/range.rb +19 -7
- data/{runtime/corelib → core}/rational.rb +0 -0
- data/{runtime/corelib → core}/regexp.rb +2 -6
- data/core/runtime.js +672 -0
- data/{runtime/corelib → core}/string.rb +25 -9
- data/{runtime/corelib → core}/struct.rb +0 -0
- data/core/time.rb +111 -0
- data/{runtime/corelib → core}/top_self.rb +0 -0
- data/{runtime/spec → core_spec}/README.md +0 -0
- data/{runtime/spec → core_spec}/core/array/allocate_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/append_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/assoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/at_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/clear_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/collect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/compact_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/concat_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/constructor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/count_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_at_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/delete_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/each_index_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/each_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/element_reference_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/element_set_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/empty_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/eql_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/equal_value_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/fetch_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/first_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/fixtures/classes.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/flatten_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/include_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/insert_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/last_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/length_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/map_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/plus_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/pop_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/push_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/rassoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reject_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/replace_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reverse_each_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/reverse_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/collect.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/eql.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/length.rb +0 -0
- data/{runtime/spec → core_spec}/core/array/shared/replace.rb +0 -0
- data/{runtime/spec → core_spec}/core/class/new_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/all_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/any_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/collect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/count_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/detect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/find_spec.rb +0 -0
- data/core_spec/core/enumerable/first_spec.rb +3 -0
- data/{runtime/spec → core_spec}/core/enumerable/fixtures/classes.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/collect.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/entries.rb +0 -0
- data/{runtime/spec → core_spec}/core/enumerable/shared/find.rb +0 -0
- data/core_spec/core/enumerable/shared/take.rb +31 -0
- data/{runtime/spec → core_spec}/core/enumerable/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/false/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/allocate_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/assoc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/clear_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/clone_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/default_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/delete_if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/element_reference_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/element_set_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/hash/new_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/matchdata/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/nil_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_f_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_i_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/nil/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/numeric/equal_value_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/object/is_a_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/object/shared/kind_of.rb +0 -0
- data/{runtime/spec → core_spec}/core/regexp/match_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/regexp/shared/match.rb +0 -0
- data/{runtime/spec → core_spec}/core/symbol/to_proc_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/inspect_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/to_s_spec.rb +0 -0
- data/{runtime/spec → core_spec}/core/true/xor_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/alias_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/and_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/array_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/block_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/break_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/case_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/defined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/ensure_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/block.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/break.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/defined.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/ensure.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/next.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/send.rb +0 -0
- data/{runtime/spec → core_spec}/language/fixtures/super.rb +0 -0
- data/{runtime/spec → core_spec}/language/hash_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/if_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/loop_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/next_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/or_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/predefined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/regexp/interpolation_spec.rb +8 -0
- data/{runtime/spec → core_spec}/language/regexp_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/send_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/string_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/super_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/symbol_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/undef_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/unless_spec.rb +0 -0
- data/{runtime/spec → core_spec}/language/until_spec.rb +0 -0
- data/core_spec/language/variables_spec.rb +112 -0
- data/{runtime/spec → core_spec}/language/versions/hash_1.9.rb +0 -0
- data/{runtime/spec → core_spec}/language/while_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/defined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/function_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/native_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/null_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/number_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/object_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/string_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/typeof_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/opal/undefined_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/true/case_compare_spec.rb +0 -0
- data/{runtime/spec → core_spec}/opal/true/class_spec.rb +0 -0
- data/{docs/spec_runner.html → core_spec/release_runner.html} +4 -3
- data/core_spec/runner.html +16 -0
- data/core_spec/spec_helper.rb +23 -0
- data/lib/opal.rb +85 -2
- data/lib/opal/builder.rb +129 -46
- data/lib/opal/context.rb +47 -26
- data/lib/opal/dependency_builder.rb +113 -14
- data/lib/opal/environment.rb +40 -45
- data/lib/opal/parser/grammar.rb +2296 -2254
- data/lib/opal/parser/grammar.y +27 -8
- data/lib/opal/parser/lexer.rb +12 -3
- data/lib/opal/parser/parser.rb +117 -30
- data/lib/opal/parser/scope.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +3 -8
- data/spec/grammar/masgn_spec.rb +37 -0
- metadata +177 -227
- data/index.html +0 -434
- data/lib/opal/command.rb +0 -73
- data/runtime/README.md +0 -25
- data/runtime/corelib/boolean.rb +0 -44
- data/runtime/corelib/class.rb +0 -43
- data/runtime/corelib/complex.rb +0 -2
- data/runtime/corelib/dir.rb +0 -29
- data/runtime/corelib/enumerable.rb +0 -316
- data/runtime/corelib/enumerator.rb +0 -80
- data/runtime/corelib/error.rb +0 -25
- data/runtime/corelib/module.rb +0 -171
- data/runtime/corelib/native.rb +0 -50
- data/runtime/corelib/object.rb +0 -21
- data/runtime/corelib/time.rb +0 -196
- data/runtime/gemlib/alpha.rb +0 -5
- data/runtime/gemlib/kernel.rb +0 -17
- data/runtime/gemlib/load_order +0 -2
- data/runtime/kernel/class.js +0 -256
- data/runtime/kernel/debug.js +0 -42
- data/runtime/kernel/init.js +0 -114
- data/runtime/kernel/load_order +0 -5
- data/runtime/kernel/loader.js +0 -151
- data/runtime/kernel/runtime.js +0 -414
- data/runtime/spec/language/variables_spec.rb +0 -28
- data/runtime/spec/library/stringscanner/scan_spec.rb +0 -36
- data/runtime/spec/opal/forwardable/def_instance_delegator_spec.rb +0 -49
- data/runtime/spec/spec_helper.rb +0 -25
- data/runtime/stdlib/base64.rb +0 -91
- data/runtime/stdlib/date.rb +0 -4
- data/runtime/stdlib/dev.rb +0 -171
- data/runtime/stdlib/forwardable.rb +0 -33
- data/runtime/stdlib/optparse.rb +0 -0
- data/runtime/stdlib/pp.rb +0 -6
- data/runtime/stdlib/racc/parser.rb +0 -159
- data/runtime/stdlib/rbconfig.rb +0 -0
- data/runtime/stdlib/si.rb +0 -17
- data/runtime/stdlib/strscan.rb +0 -53
- data/runtime/stdlib/uri.rb +0 -111
- data/runtime/stdlib/uri/common.rb +0 -1014
- data/runtime/stdlib/uri/ftp.rb +0 -261
- data/runtime/stdlib/uri/generic.rb +0 -1599
- data/runtime/stdlib/uri/http.rb +0 -106
- data/runtime/stdlib/uri/https.rb +0 -22
- data/runtime/stdlib/uri/ldap.rb +0 -260
- data/runtime/stdlib/uri/ldaps.rb +0 -20
- data/runtime/stdlib/uri/mailto.rb +0 -280
- data/spec/builder/output_path_spec.rb +0 -50
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
|
-
# Specify your gem's dependencies in opal.gemspec
|
4
3
|
gemspec
|
5
4
|
|
5
|
+
gem "racc"
|
6
6
|
gem "rake"
|
7
|
+
gem "therubyracer"
|
7
8
|
|
8
|
-
group :
|
9
|
+
group :opal do
|
9
10
|
gem "opal-spec"
|
10
11
|
end
|
12
|
+
|
13
|
+
#group :docs do
|
14
|
+
# gem "redcarpet", "1.2.0"
|
15
|
+
# gem "rocco"
|
16
|
+
#end
|
data/README.md
CHANGED
@@ -12,6 +12,6 @@ the hood. The Opal gem includes the compiler used to convert ruby sources
|
|
12
12
|
into javascript.
|
13
13
|
|
14
14
|
For docs, visit the website:
|
15
|
-
[http://
|
15
|
+
[http://opalrb.org](http://opalrb.org)
|
16
16
|
|
17
17
|
Join the IRC channel on Freenode: `#opal`.
|
data/Rakefile
CHANGED
@@ -1,43 +1,55 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require 'bundler/gem_tasks'
|
3
|
-
require 'opal'
|
4
1
|
require 'fileutils'
|
5
|
-
require '
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.setup
|
6
4
|
|
7
|
-
|
8
|
-
desc "Build opal runtime to opal.js"
|
9
|
-
task :opal do
|
10
|
-
File.open("opal.js", 'w+') { |o| o.write build_runtime false }
|
11
|
-
end
|
5
|
+
require 'opal'
|
12
6
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
7
|
+
begin
|
8
|
+
require 'rocco'
|
9
|
+
rescue LoadError
|
10
|
+
end
|
11
|
+
|
12
|
+
task :runtime do
|
13
|
+
FileUtils.rm_f 'opal.js'
|
14
|
+
code = Opal.runtime_code
|
15
|
+
File.open('opal.js', 'w+') { |o| o.write code }
|
16
|
+
end
|
17
|
+
|
18
|
+
task :debug_runtime do
|
19
|
+
FileUtils.rm_f 'opal.debug.js'
|
20
|
+
code = Opal.runtime_debug_code
|
21
|
+
File.open('opal.debug.js', 'w+') { |o| o.write code }
|
22
|
+
end
|
17
23
|
|
24
|
+
namespace :opal do
|
18
25
|
desc "Tests for browser to opal.test.js"
|
19
26
|
task :test do
|
20
|
-
|
27
|
+
sh "bundle exec bin/opal build core_spec"
|
21
28
|
end
|
29
|
+
end
|
22
30
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
31
|
+
desc "Build dependencies into ."
|
32
|
+
task :dependencies do
|
33
|
+
sh "bundle exec bin/opal dependencies"
|
27
34
|
end
|
28
35
|
|
29
|
-
desc "Build opal and debug opal into
|
30
|
-
task :
|
36
|
+
desc "Build opal.js and opal.debug.js opal into ."
|
37
|
+
task :opal => %w(runtime debug_runtime)
|
38
|
+
|
39
|
+
desc "Run opal specs (from core_spec/*) in debug mode"
|
40
|
+
task :test => :opal do
|
41
|
+
Opal::Context.runner 'core_spec/**/*.rb'
|
42
|
+
end
|
31
43
|
|
32
|
-
desc "Run
|
33
|
-
task :
|
34
|
-
Opal::Context.runner '
|
44
|
+
desc "Run core_spec/ in release mode"
|
45
|
+
task :test_release => :opal do
|
46
|
+
Opal::Context.runner 'core_spec/**/*.rb', false
|
35
47
|
end
|
36
48
|
|
37
49
|
desc "Check file sizes for core builds"
|
38
50
|
task :sizes do
|
39
|
-
sizes '
|
40
|
-
sizes '
|
51
|
+
sizes 'opal.js'
|
52
|
+
sizes 'opal.debug.js'
|
41
53
|
end
|
42
54
|
|
43
55
|
desc "Rebuild grammar.rb for opal parser"
|
@@ -59,45 +71,27 @@ namespace :docs do
|
|
59
71
|
end
|
60
72
|
|
61
73
|
desc "Copy required files into gh-pages dir"
|
62
|
-
task :copy => :
|
74
|
+
task :copy => :opal do
|
63
75
|
%w[opal.js opal.debug.js index.html].each do |f|
|
64
76
|
FileUtils.cp f, "gh-pages/#{f}"
|
65
77
|
end
|
66
78
|
end
|
67
|
-
end
|
68
79
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
def build_runtime debug = false
|
80
|
-
rborder = File.read('runtime/corelib/load_order').strip.split
|
81
|
-
rbcore = rborder.map { |c| File.read "runtime/corelib/#{c}.rb" }
|
82
|
-
jsorder = File.read('runtime/kernel/load_order').strip.split
|
83
|
-
jscore = jsorder.map { |c| File.read "runtime/kernel/#{c}.js" }
|
84
|
-
|
85
|
-
parser = Opal::Parser.new :debug => debug
|
86
|
-
parsed = parser.parse rbcore.join("\n"), '(corelib)'
|
87
|
-
methods = Opal::Parser::METHOD_NAMES.map { |f, t| "'#{f}': 'm$#{t}$'" }
|
88
|
-
result = []
|
89
|
-
|
90
|
-
result << '(function(undefined) {'
|
91
|
-
result << jscore.join
|
92
|
-
result << "var method_names = {#{methods.join ', '}};"
|
93
|
-
result << "var reverse_method_names = {}; for (var id in method_names) {"
|
94
|
-
result << "reverse_method_names[method_names[id]] = id;}"
|
95
|
-
result << parsed
|
96
|
-
result << '}).call(this);'
|
97
|
-
|
98
|
-
HEADER + result.join("\n")
|
80
|
+
desc "rocco"
|
81
|
+
task :rocco do
|
82
|
+
FileUtils.mkdir_p 'docs'
|
83
|
+
%w[builder dependency_builder].each do |src|
|
84
|
+
path = "lib/opal/#{src}.rb"
|
85
|
+
out = "docs/#{src}.html"
|
86
|
+
|
87
|
+
File.open(out, 'w+') { |o| o.write Rocco.new(path).to_html }
|
88
|
+
end
|
89
|
+
end
|
99
90
|
end
|
100
91
|
|
92
|
+
# Takes a file path, reads it and prints out the file size as it is, once
|
93
|
+
# minified and once minified + gzipped. Depends on uglifyjs being installed
|
94
|
+
# for node.js
|
101
95
|
def sizes file
|
102
96
|
o = File.read file
|
103
97
|
m = uglify o
|
data/bin/opal
CHANGED
@@ -1,6 +1,54 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'optparse'
|
4
|
+
require 'fileutils'
|
3
5
|
require 'opal'
|
4
|
-
require 'opal/command'
|
5
6
|
|
6
|
-
|
7
|
+
# Parse command line options/files.
|
8
|
+
options = {}
|
9
|
+
|
10
|
+
case ARGV.first
|
11
|
+
when 'dependencies'
|
12
|
+
options[:dependencies] = true
|
13
|
+
ARGV.shift
|
14
|
+
when 'build'
|
15
|
+
options[:build] = true
|
16
|
+
ARGV.shift
|
17
|
+
end
|
18
|
+
|
19
|
+
OptionParser.new do |opts|
|
20
|
+
opts.on('-c', '--compile', 'Compile ruby') do |c|
|
21
|
+
options[:build] = true
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-o', '--out FILE', 'Output file') do |o|
|
25
|
+
options[:out] = o
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on('-d', '--debug', 'Debug mode') do |d|
|
29
|
+
options[:debug] = true
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on_tail("-v", "--version", "Show version") do
|
33
|
+
puts Opal::VERSION
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
end.parse! rescue abort("See `opal --help' for usage information.")
|
37
|
+
|
38
|
+
if options[:dependencies]
|
39
|
+
options.delete :dependencies
|
40
|
+
Opal::DependencyBuilder.new(options).build
|
41
|
+
|
42
|
+
elsif options[:build]
|
43
|
+
options[:files] = ARGV.empty? ? ['lib'] : ARGV.dup
|
44
|
+
Opal::Builder.new(options).build
|
45
|
+
|
46
|
+
else
|
47
|
+
if ARGV.empty?
|
48
|
+
Opal::Context.new.start_repl
|
49
|
+
elsif File.exists? ARGV.first
|
50
|
+
Opal::Context.runner ARGV.first
|
51
|
+
else
|
52
|
+
abort "File does not exist: #{ARGV.first}"
|
53
|
+
end
|
54
|
+
end
|
@@ -1,10 +1,15 @@
|
|
1
1
|
# load path getters
|
2
2
|
$LOAD_PATH = $: = `LOADER_PATHS`
|
3
3
|
|
4
|
+
# loaded features
|
5
|
+
$LOADED_FEATURES = $" = `FEATURES`
|
6
|
+
|
4
7
|
# regexp matches
|
5
8
|
$~ = nil
|
6
9
|
|
10
|
+
$/ = "\n"
|
11
|
+
|
7
12
|
RUBY_ENGINE = 'opal-browser'
|
8
13
|
RUBY_PLATFORM = 'opal'
|
9
14
|
RUBY_VERSION = '1.9.2'
|
10
|
-
ARGV = []
|
15
|
+
ARGV = []
|
@@ -53,7 +53,7 @@ class Array
|
|
53
53
|
|
54
54
|
def *(other)
|
55
55
|
%x{
|
56
|
-
if (
|
56
|
+
if (typeof(other) === 'string') {
|
57
57
|
return this.join(other);
|
58
58
|
}
|
59
59
|
|
@@ -195,7 +195,7 @@ class Array
|
|
195
195
|
var result = [];
|
196
196
|
|
197
197
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
198
|
-
if ((value = $yield.call($context,
|
198
|
+
if ((value = $yield.call($context, this[i])) === $breaker) {
|
199
199
|
return $breaker.$v;
|
200
200
|
}
|
201
201
|
|
@@ -211,7 +211,7 @@ class Array
|
|
211
211
|
|
212
212
|
%x{
|
213
213
|
for (var i = 0, length = this.length, val; i < length; i++) {
|
214
|
-
if ((val = $yield.call($context,
|
214
|
+
if ((val = $yield.call($context, this[i])) === $breaker) {
|
215
215
|
return $breaker.$v;
|
216
216
|
}
|
217
217
|
|
@@ -321,7 +321,7 @@ class Array
|
|
321
321
|
|
322
322
|
%x{
|
323
323
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
324
|
-
if ((value = $yield.call($context,
|
324
|
+
if ((value = $yield.call($context, this[i])) === $breaker) {
|
325
325
|
return $breaker.$v;
|
326
326
|
}
|
327
327
|
|
@@ -338,7 +338,7 @@ class Array
|
|
338
338
|
end
|
339
339
|
|
340
340
|
def drop(number)
|
341
|
-
`
|
341
|
+
`this.slice(number)`
|
342
342
|
end
|
343
343
|
|
344
344
|
def drop_while(&block)
|
@@ -346,7 +346,7 @@ class Array
|
|
346
346
|
|
347
347
|
%x{
|
348
348
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
349
|
-
if ((value = $yield.call($context,
|
349
|
+
if ((value = $yield.call($context, this[i])) === $breaker) {
|
350
350
|
return $breaker.$v;
|
351
351
|
}
|
352
352
|
|
@@ -364,7 +364,7 @@ class Array
|
|
364
364
|
|
365
365
|
%x{
|
366
366
|
for (var i = 0, length = this.length; i < length; i++) {
|
367
|
-
if ($yield.call($context,
|
367
|
+
if ($yield.call($context, this[i]) === $breaker) {
|
368
368
|
return $breaker.$v;
|
369
369
|
}
|
370
370
|
}
|
@@ -378,7 +378,7 @@ class Array
|
|
378
378
|
|
379
379
|
%x{
|
380
380
|
for (var i = 0, length = this.length; i < length; i++) {
|
381
|
-
if ($yield.call($context,
|
381
|
+
if ($yield.call($context, i) === $breaker) {
|
382
382
|
return $breaker.$v;
|
383
383
|
}
|
384
384
|
}
|
@@ -392,7 +392,7 @@ class Array
|
|
392
392
|
|
393
393
|
%x{
|
394
394
|
for (var i = 0, length = this.length; i < length; i++) {
|
395
|
-
if ($yield.call($context,
|
395
|
+
if ($yield.call($context, this[i], i) === $breaker) {
|
396
396
|
return $breaker.$v;
|
397
397
|
}
|
398
398
|
}
|
@@ -422,7 +422,7 @@ class Array
|
|
422
422
|
}
|
423
423
|
|
424
424
|
if (block !== nil) {
|
425
|
-
return $yield.call($context,
|
425
|
+
return $yield.call($context, original);
|
426
426
|
}
|
427
427
|
|
428
428
|
raise(RubyIndexError, 'Array#fetch');
|
@@ -468,17 +468,10 @@ class Array
|
|
468
468
|
|
469
469
|
def flatten!(level = undefined)
|
470
470
|
%x{
|
471
|
-
var
|
472
|
-
|
473
|
-
for (var i = 0, length = this.length; i < length; i++) {
|
474
|
-
if (this[i].$flags & T_ARRAY) {
|
475
|
-
flattenable = true;
|
476
|
-
|
477
|
-
break;
|
478
|
-
}
|
479
|
-
}
|
471
|
+
var size = this.length;
|
472
|
+
#{replace flatten level};
|
480
473
|
|
481
|
-
return
|
474
|
+
return size === this.length ? nil : this;
|
482
475
|
}
|
483
476
|
end
|
484
477
|
|
@@ -520,7 +513,7 @@ class Array
|
|
520
513
|
%x{
|
521
514
|
if (block !== nil) {
|
522
515
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
523
|
-
if ((value = $yield.call($context,
|
516
|
+
if ((value = $yield.call($context, this[i])) === $breaker) {
|
524
517
|
return $breaker.$v;
|
525
518
|
}
|
526
519
|
|
@@ -557,7 +550,7 @@ class Array
|
|
557
550
|
}
|
558
551
|
|
559
552
|
for (var length = this.length, value; i < length; i++) {
|
560
|
-
if ((value = $yield.call($context,
|
553
|
+
if ((value = $yield.call($context, result, this[i])) === $breaker) {
|
561
554
|
return $breaker.$v;
|
562
555
|
}
|
563
556
|
|
@@ -619,7 +612,7 @@ class Array
|
|
619
612
|
return enum_for :keep_if unless block_given?
|
620
613
|
%x{
|
621
614
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
622
|
-
if ((value = $yield.call($context,
|
615
|
+
if ((value = $yield.call($context, this[i])) === $breaker) {
|
623
616
|
return $breaker.$v;
|
624
617
|
}
|
625
618
|
|
@@ -658,9 +651,9 @@ class Array
|
|
658
651
|
`this.length`
|
659
652
|
end
|
660
653
|
|
661
|
-
|
654
|
+
alias map collect
|
662
655
|
|
663
|
-
|
656
|
+
alias map! collect!
|
664
657
|
|
665
658
|
def pop(count = undefined)
|
666
659
|
%x{
|
@@ -711,7 +704,7 @@ class Array
|
|
711
704
|
var result = [];
|
712
705
|
|
713
706
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
714
|
-
if ((value = $yield.call($context,
|
707
|
+
if ((value = $yield.call($context, this[i])) === $breaker) {
|
715
708
|
return $breaker.$v;
|
716
709
|
}
|
717
710
|
|
@@ -730,7 +723,7 @@ class Array
|
|
730
723
|
var original = this.length;
|
731
724
|
|
732
725
|
for (var i = 0, length = this.length, value; i < length; i++) {
|
733
|
-
if ((value = $yield.call($context,
|
726
|
+
if ((value = $yield.call($context, this[i])) === $breaker) {
|
734
727
|
return $breaker.$v;
|
735
728
|
}
|
736
729
|
|
@@ -747,8 +740,11 @@ class Array
|
|
747
740
|
end
|
748
741
|
|
749
742
|
def replace(other)
|
750
|
-
|
751
|
-
|
743
|
+
%x{
|
744
|
+
this.splice(0);
|
745
|
+
this.push.apply(this, other);
|
746
|
+
return this;
|
747
|
+
}
|
752
748
|
end
|
753
749
|
|
754
750
|
def reverse
|
@@ -756,7 +752,11 @@ class Array
|
|
756
752
|
end
|
757
753
|
|
758
754
|
def reverse!
|
759
|
-
|
755
|
+
%x{
|
756
|
+
this.splice(0);
|
757
|
+
this.push.apply(this, #{reverse});
|
758
|
+
return this;
|
759
|
+
}
|
760
760
|
end
|
761
761
|
|
762
762
|
def reverse_each(&block)
|
@@ -773,7 +773,7 @@ class Array
|
|
773
773
|
%x{
|
774
774
|
if (block !== nil) {
|
775
775
|
for (var i = this.length - 1, value; i >= 0; i--) {
|
776
|
-
if ((value = $yield.call($context,
|
776
|
+
if ((value = $yield.call($context, this[i])) === $breaker) {
|
777
777
|
return $breaker.$v;
|
778
778
|
}
|
779
779
|
|
@@ -803,7 +803,7 @@ class Array
|
|
803
803
|
for (var i = 0, length = this.length, item, value; i < length; i++) {
|
804
804
|
item = this[i];
|
805
805
|
|
806
|
-
if ((value = $yield.call($context,
|
806
|
+
if ((value = $yield.call($context, item)) === $breaker) {
|
807
807
|
return $breaker.$v;
|
808
808
|
}
|
809
809
|
|
@@ -824,7 +824,7 @@ class Array
|
|
824
824
|
for (var i = 0, length = original, item, value; i < length; i++) {
|
825
825
|
item = this[i];
|
826
826
|
|
827
|
-
if ((value = $yield.call($context,
|
827
|
+
if ((value = $yield.call($context, item)) === $breaker) {
|
828
828
|
return $breaker.$v;
|
829
829
|
}
|
830
830
|
|
@@ -844,9 +844,9 @@ class Array
|
|
844
844
|
`count === undefined ? this.shift() : this.splice(0, count)`
|
845
845
|
end
|
846
846
|
|
847
|
-
|
847
|
+
alias size length
|
848
848
|
|
849
|
-
|
849
|
+
alias slice :[]
|
850
850
|
|
851
851
|
def slice!(index, length = undefined)
|
852
852
|
%x{
|
@@ -879,7 +879,7 @@ class Array
|
|
879
879
|
for (var i = 0, length = this.length, item, value; i < length; i++) {
|
880
880
|
item = this[i];
|
881
881
|
|
882
|
-
if ((value = $yield.call($context,
|
882
|
+
if ((value = $yield.call($context, item)) === $breaker) {
|
883
883
|
return $breaker.$v;
|
884
884
|
}
|
885
885
|
|
@@ -898,13 +898,9 @@ class Array
|
|
898
898
|
self
|
899
899
|
end
|
900
900
|
|
901
|
-
|
902
|
-
|
903
|
-
def to_native
|
904
|
-
map { |obj| Opal.object?(obj) ? obj.to_native : obj }
|
905
|
-
end
|
901
|
+
alias to_ary to_a
|
906
902
|
|
907
|
-
|
903
|
+
alias to_s inspect
|
908
904
|
|
909
905
|
def uniq
|
910
906
|
%x{
|