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/core/enumerator.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
class Enumerator
|
2
|
+
include Enumerable
|
3
|
+
|
4
|
+
class Yielder
|
5
|
+
def initialize(block)
|
6
|
+
@block = block
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(block)
|
10
|
+
@call = block
|
11
|
+
|
12
|
+
@block.call
|
13
|
+
end
|
14
|
+
|
15
|
+
def yield(value)
|
16
|
+
@call.call(value)
|
17
|
+
end
|
18
|
+
|
19
|
+
alias << yield
|
20
|
+
end
|
21
|
+
|
22
|
+
class Generator
|
23
|
+
attr_reader :enumerator
|
24
|
+
|
25
|
+
def initialize(block)
|
26
|
+
@yielder = Yielder.new(block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def each(&block)
|
30
|
+
@yielder.call(block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(object = nil, method = :each, *args, &block)
|
35
|
+
if block_given?
|
36
|
+
@object = Generator.new(block)
|
37
|
+
end
|
38
|
+
|
39
|
+
raise ArgumentError, 'wrong number of argument (0 for 1+)' unless object
|
40
|
+
|
41
|
+
@object = object
|
42
|
+
@method = method
|
43
|
+
@args = args
|
44
|
+
end
|
45
|
+
|
46
|
+
def next
|
47
|
+
_init_cache
|
48
|
+
|
49
|
+
result = @cache[@current] or raise StopIteration, 'iteration reached an end'
|
50
|
+
@current += 1
|
51
|
+
|
52
|
+
result
|
53
|
+
end
|
54
|
+
|
55
|
+
def next_values
|
56
|
+
result = self.next
|
57
|
+
|
58
|
+
result.is_a?(Array) ? result : [result]
|
59
|
+
end
|
60
|
+
|
61
|
+
def peek
|
62
|
+
_init_cache
|
63
|
+
|
64
|
+
@cache[@current] or raise StopIteration, 'iteration reached an end'
|
65
|
+
end
|
66
|
+
|
67
|
+
def peel_values
|
68
|
+
result = self.peek
|
69
|
+
|
70
|
+
result.is_a?(Array) ? result : [result]
|
71
|
+
end
|
72
|
+
|
73
|
+
def rewind
|
74
|
+
_clear_cache
|
75
|
+
end
|
76
|
+
|
77
|
+
def each(&block)
|
78
|
+
return self unless block
|
79
|
+
|
80
|
+
@object.__send__ @method, *args, &block
|
81
|
+
end
|
82
|
+
|
83
|
+
def each_with_index(&block)
|
84
|
+
with_index &block
|
85
|
+
end
|
86
|
+
|
87
|
+
def with_index(offset = 0)
|
88
|
+
return Enumerator.new(self, :with_index, offset) unless block_given?
|
89
|
+
|
90
|
+
current = 0
|
91
|
+
|
92
|
+
each {|*args|
|
93
|
+
next unless current >= offset
|
94
|
+
|
95
|
+
yield *args, current
|
96
|
+
|
97
|
+
current += 1
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
def with_object(object)
|
102
|
+
return Enumerator.new(self, :with_object, object) unless block_given?
|
103
|
+
|
104
|
+
each {|*args|
|
105
|
+
yield *args, object
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
def _init_cache
|
110
|
+
@current ||= 0
|
111
|
+
@cache ||= to_a
|
112
|
+
end
|
113
|
+
|
114
|
+
def _clear_cache
|
115
|
+
@cache = nil
|
116
|
+
@current = nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
module Kernel
|
121
|
+
def enum_for (method = :each, *args)
|
122
|
+
Enumerator.new(self, method, *args)
|
123
|
+
end
|
124
|
+
|
125
|
+
alias to_enum enum_for
|
126
|
+
end
|
data/core/error.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
class Exception
|
2
|
+
def initialize(message = '')
|
3
|
+
%x{
|
4
|
+
if (Error.captureStackTrace) {
|
5
|
+
Error.captureStackTrace(this);
|
6
|
+
}
|
7
|
+
|
8
|
+
this.message = message;
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def backtrace
|
13
|
+
%x{
|
14
|
+
if (this._bt !== undefined) {
|
15
|
+
return this._bt;
|
16
|
+
}
|
17
|
+
|
18
|
+
var backtrace = this.stack;
|
19
|
+
|
20
|
+
if (typeof(backtrace) === 'string') {
|
21
|
+
return this._bt = backtrace.split("\\n");
|
22
|
+
}
|
23
|
+
else if (backtrace) {
|
24
|
+
this._bt = backtrace;
|
25
|
+
}
|
26
|
+
|
27
|
+
return this._bt = ["No backtrace available"];
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def inspect
|
32
|
+
"#<#{self.class}: '#{message}'>"
|
33
|
+
end
|
34
|
+
|
35
|
+
def message
|
36
|
+
`this.message`
|
37
|
+
end
|
38
|
+
|
39
|
+
alias to_s message
|
40
|
+
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
class File
|
2
|
+
# Regexp to split path into dirname, basename and extname
|
3
|
+
PATH_RE = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/
|
4
|
+
|
2
5
|
def self.expand_path(path, base = undefined)
|
3
6
|
%x{
|
4
7
|
if (!base) {
|
@@ -43,7 +46,7 @@ class File
|
|
43
46
|
|
44
47
|
def self.dirname(path)
|
45
48
|
%x{
|
46
|
-
var dirname = PATH_RE.exec(path)[1];
|
49
|
+
var dirname = #{PATH_RE}.exec(path)[1];
|
47
50
|
|
48
51
|
if (!dirname) {
|
49
52
|
return '.';
|
@@ -59,7 +62,7 @@ class File
|
|
59
62
|
|
60
63
|
def self.extname(path)
|
61
64
|
%x{
|
62
|
-
var extname = PATH_RE.exec(path)[3];
|
65
|
+
var extname = #{PATH_RE}.exec(path)[3];
|
63
66
|
|
64
67
|
if (!extname || extname === '.') {
|
65
68
|
return '';
|
@@ -75,6 +78,6 @@ class File
|
|
75
78
|
end
|
76
79
|
|
77
80
|
def self.exist?(path)
|
78
|
-
|
81
|
+
`!!FACTORIES[#{ expand_path path }]`
|
79
82
|
end
|
80
83
|
end
|
data/core/gemlib.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# ...........................................................
|
2
|
+
# GEMLIB - only loaded when running inside v8 in gem
|
3
|
+
#
|
4
|
+
|
5
|
+
# In gem, use 'opal-ruby-. Browser (default) uses 'opal-browser'
|
6
|
+
RUBY_ENGINE = 'opal-ruby'
|
7
|
+
|
8
|
+
# Update load paths (aliasing does not yet work as planned)
|
9
|
+
$: = $LOAD_PATH = `opal_filesystem.find_paths`
|
10
|
+
|
11
|
+
$" = $LOADED_FEATURES = []
|
12
|
+
|
13
|
+
module Kernel
|
14
|
+
def require(path)
|
15
|
+
%x{
|
16
|
+
var resolved = opal_filesystem.require(#{path}, #{$:});
|
17
|
+
|
18
|
+
if (resolved === false) {
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
else if (!resolved) {
|
22
|
+
#{ raise LoadError, "cannot load file -- #{path}" };
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
#{ $LOADED_FEATURES << `resolved` };
|
26
|
+
return true;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
@@ -1,17 +1,35 @@
|
|
1
1
|
class Hash
|
2
2
|
include Enumerable
|
3
3
|
|
4
|
+
%x{
|
5
|
+
var hash_class = this;
|
6
|
+
|
7
|
+
$opal.hash = function() {
|
8
|
+
var hash = new hash_class.$allocator(),
|
9
|
+
args = $slice.call(arguments),
|
10
|
+
assocs = {},
|
11
|
+
key;
|
12
|
+
|
13
|
+
hash.map = assocs;
|
14
|
+
hash.none = nil;
|
15
|
+
hash.proc = nil;
|
16
|
+
|
17
|
+
for (var i = 0, length = args.length; i < length; i++) {
|
18
|
+
key = args[i];
|
19
|
+
assocs[key.$hash()] = [key, args[++i]];
|
20
|
+
}
|
21
|
+
|
22
|
+
return hash;
|
23
|
+
};
|
24
|
+
}
|
25
|
+
|
4
26
|
def self.[](*objs)
|
5
27
|
`$opal.hash.apply(null, objs)`
|
6
28
|
end
|
7
29
|
|
8
|
-
def self.allocate
|
9
|
-
`new $opal.hash()`
|
10
|
-
end
|
11
|
-
|
12
30
|
def self.new(defaults = undefined, &block)
|
13
31
|
%x{
|
14
|
-
var hash =
|
32
|
+
var hash = $opal.hash();
|
15
33
|
|
16
34
|
if (defaults !== undefined) {
|
17
35
|
hash.none = defaults;
|
@@ -100,7 +118,7 @@ class Hash
|
|
100
118
|
|
101
119
|
def clone
|
102
120
|
%x{
|
103
|
-
var result =
|
121
|
+
var result = $opal.hash(),
|
104
122
|
map = this.map,
|
105
123
|
map2 = result.map;
|
106
124
|
|
@@ -154,7 +172,7 @@ class Hash
|
|
154
172
|
var bucket = map[assoc],
|
155
173
|
value;
|
156
174
|
|
157
|
-
if ((value = $yield.call($context,
|
175
|
+
if ((value = $yield.call($context, bucket[0], bucket[1])) === $breaker) {
|
158
176
|
return $breaker.$v;
|
159
177
|
}
|
160
178
|
|
@@ -176,7 +194,7 @@ class Hash
|
|
176
194
|
for (var assoc in map) {
|
177
195
|
var bucket = map[assoc];
|
178
196
|
|
179
|
-
if ($yield.call($context,
|
197
|
+
if ($yield.call($context, bucket[0], bucket[1]) === $breaker) {
|
180
198
|
return $breaker.$v;
|
181
199
|
}
|
182
200
|
}
|
@@ -194,7 +212,7 @@ class Hash
|
|
194
212
|
for (var assoc in map) {
|
195
213
|
var bucket = map[assoc];
|
196
214
|
|
197
|
-
if ($yield.call($context,
|
215
|
+
if ($yield.call($context, bucket[0]) === $breaker) {
|
198
216
|
return $breaker.$v;
|
199
217
|
}
|
200
218
|
}
|
@@ -203,7 +221,7 @@ class Hash
|
|
203
221
|
}
|
204
222
|
end
|
205
223
|
|
206
|
-
|
224
|
+
alias each_pair each
|
207
225
|
|
208
226
|
def each_value(&block)
|
209
227
|
return enum_for :each_value unless block_given?
|
@@ -214,7 +232,7 @@ class Hash
|
|
214
232
|
for (var assoc in map) {
|
215
233
|
var bucket = map[assoc];
|
216
234
|
|
217
|
-
if ($yield.call($context,
|
235
|
+
if ($yield.call($context, bucket[1]) === $breaker) {
|
218
236
|
return $breaker.$v;
|
219
237
|
}
|
220
238
|
}
|
@@ -233,7 +251,7 @@ class Hash
|
|
233
251
|
}
|
234
252
|
end
|
235
253
|
|
236
|
-
|
254
|
+
alias eql? ==
|
237
255
|
|
238
256
|
def fetch(key, defaults = undefined, &block)
|
239
257
|
%x{
|
@@ -242,7 +260,7 @@ class Hash
|
|
242
260
|
if (block !== nil) {
|
243
261
|
var value;
|
244
262
|
|
245
|
-
if ((value = $yield.call($context,
|
263
|
+
if ((value = $yield.call($context, key)) === $breaker) {
|
246
264
|
return $breaker.$v;
|
247
265
|
}
|
248
266
|
|
@@ -274,7 +292,7 @@ class Hash
|
|
274
292
|
result.push(value);
|
275
293
|
}
|
276
294
|
else {
|
277
|
-
result = result.concat(#{value
|
295
|
+
result = result.concat(#{`value`.flatten(level - 1)});
|
278
296
|
}
|
279
297
|
}
|
280
298
|
else {
|
@@ -350,7 +368,7 @@ class Hash
|
|
350
368
|
}
|
351
369
|
end
|
352
370
|
|
353
|
-
|
371
|
+
alias key? has_key?
|
354
372
|
|
355
373
|
def keys
|
356
374
|
%x{
|
@@ -376,7 +394,7 @@ class Hash
|
|
376
394
|
}
|
377
395
|
end
|
378
396
|
|
379
|
-
|
397
|
+
alias member? has_key?
|
380
398
|
|
381
399
|
def merge(other)
|
382
400
|
%x{
|
@@ -447,7 +465,7 @@ class Hash
|
|
447
465
|
}
|
448
466
|
end
|
449
467
|
|
450
|
-
|
468
|
+
alias size length
|
451
469
|
|
452
470
|
def to_a
|
453
471
|
%x{
|
@@ -468,25 +486,9 @@ class Hash
|
|
468
486
|
self
|
469
487
|
end
|
470
488
|
|
471
|
-
|
472
|
-
%x{
|
473
|
-
var map = this.map,
|
474
|
-
result = {};
|
475
|
-
|
476
|
-
for (var assoc in map) {
|
477
|
-
var key = map[assoc][0],
|
478
|
-
value = map[assoc][1];
|
479
|
-
|
480
|
-
result[key] = #{Opal.object?(`value`) ? `value`.to_native : `value`};
|
481
|
-
}
|
482
|
-
|
483
|
-
return result;
|
484
|
-
}
|
485
|
-
end
|
486
|
-
|
487
|
-
alias_method :to_s, :inspect
|
489
|
+
alias to_s inspect
|
488
490
|
|
489
|
-
|
491
|
+
alias update merge!
|
490
492
|
|
491
493
|
def values
|
492
494
|
%x{
|
File without changes
|
@@ -7,21 +7,19 @@ module Kernel
|
|
7
7
|
`this == other`
|
8
8
|
end
|
9
9
|
|
10
|
-
def Object (object)
|
11
|
-
Opal.native?(object) ? Native::Object.new(object) : object
|
12
|
-
end
|
13
|
-
|
14
10
|
def Array(object)
|
15
11
|
return [] unless object
|
16
12
|
|
17
|
-
unless Opal.native?(object)
|
18
|
-
return object.to_ary if object.respond_to? :to_ary
|
19
|
-
return object.to_a if object.respond_to? :to_a
|
20
|
-
end
|
21
|
-
|
22
13
|
%x{
|
14
|
+
if (object.$to_ary) {
|
15
|
+
return #{object.to_ary};
|
16
|
+
}
|
17
|
+
else if (object.$to_a) {
|
18
|
+
return #{object.to_a};
|
19
|
+
}
|
20
|
+
|
23
21
|
var length = object.length || 0,
|
24
|
-
result =
|
22
|
+
result = [];
|
25
23
|
|
26
24
|
while (length--) {
|
27
25
|
result[length] = object[length];
|
@@ -86,7 +84,7 @@ module Kernel
|
|
86
84
|
end
|
87
85
|
|
88
86
|
def instance_variable_defined?(name)
|
89
|
-
`
|
87
|
+
`hasOwnProperty.call(this, name.substr(1))`
|
90
88
|
end
|
91
89
|
|
92
90
|
def instance_variable_get(name)
|
@@ -129,7 +127,7 @@ module Kernel
|
|
129
127
|
}
|
130
128
|
end
|
131
129
|
|
132
|
-
|
130
|
+
alias kind_of? is_a?
|
133
131
|
|
134
132
|
def lambda(&block)
|
135
133
|
block
|
@@ -140,7 +138,7 @@ module Kernel
|
|
140
138
|
|
141
139
|
%x{
|
142
140
|
while (true) {
|
143
|
-
if ($yield.call($context
|
141
|
+
if ($yield.call($context) === breaker) {
|
144
142
|
return breaker.$v;
|
145
143
|
}
|
146
144
|
}
|
@@ -161,17 +159,26 @@ module Kernel
|
|
161
159
|
$stdout.print *strs
|
162
160
|
end
|
163
161
|
|
162
|
+
def private(*)
|
163
|
+
end
|
164
|
+
|
164
165
|
def proc(&block)
|
165
166
|
block
|
166
167
|
end
|
167
168
|
|
169
|
+
def protected(*)
|
170
|
+
end
|
171
|
+
|
172
|
+
def public(*)
|
173
|
+
end
|
174
|
+
|
168
175
|
def puts(*strs)
|
169
176
|
$stdout.puts *strs
|
170
177
|
end
|
171
178
|
|
172
179
|
def raise(exception, string = undefined)
|
173
180
|
%x{
|
174
|
-
if (
|
181
|
+
if (typeof(exception) === 'string') {
|
175
182
|
exception = #{`RubyRuntimeError`.new `exception`};
|
176
183
|
}
|
177
184
|
else if (#{!exception.is_a? `RubyException`}) {
|
@@ -199,18 +206,16 @@ module Kernel
|
|
199
206
|
}
|
200
207
|
|
201
208
|
LOADER_CACHE[resolved] = true;
|
209
|
+
FEATURES.push(resolved);
|
202
210
|
$opal.FILE = resolved;
|
203
|
-
FACTORIES[resolved]
|
211
|
+
FACTORIES[resolved]();
|
204
212
|
|
205
213
|
return true;
|
206
214
|
}
|
207
215
|
end
|
208
216
|
|
209
217
|
def respond_to?(name)
|
210
|
-
|
211
|
-
var meth = this[mid_to_jsid(name)];
|
212
|
-
return !!meth;
|
213
|
-
}
|
218
|
+
`!!this[mid_to_jsid(name)]`
|
214
219
|
end
|
215
220
|
|
216
221
|
def singleton_class
|
@@ -223,7 +228,7 @@ module Kernel
|
|
223
228
|
raise(RubyLocalJumpError, 'no block given');
|
224
229
|
}
|
225
230
|
|
226
|
-
if ($yield.call($context,
|
231
|
+
if ($yield.call($context, this) === breaker) {
|
227
232
|
return breaker.$v;
|
228
233
|
}
|
229
234
|
|
@@ -232,6 +237,6 @@ module Kernel
|
|
232
237
|
end
|
233
238
|
|
234
239
|
def to_s
|
235
|
-
`
|
240
|
+
`return "#<" + class_real(this.$klass).$name + ":0x" + (this.$id * 400487).toString(16) + ">";`
|
236
241
|
end
|
237
242
|
end
|