opal 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/.travis.yml +0 -4
- data/README.md +6 -0
- data/Rakefile +30 -6
- data/bin/opal +6 -82
- data/corelib/{opal/array.rb → array.rb} +40 -56
- data/corelib/{opal/basic_object.rb → basic_object.rb} +2 -2
- data/corelib/{opal/boolean.rb → boolean.rb} +0 -8
- data/corelib/class.rb +47 -0
- data/corelib/{opal/comparable.rb → comparable.rb} +0 -0
- data/corelib/{opal/enumerable.rb → enumerable.rb} +208 -141
- data/corelib/{opal/enumerator.rb → enumerator.rb} +3 -3
- data/corelib/{opal/error.rb → error.rb} +1 -0
- data/corelib/{opal/hash.rb → hash.rb} +67 -56
- data/corelib/io.rb +39 -0
- data/corelib/{opal/kernel.rb → kernel.rb} +35 -31
- data/corelib/{opal/class.rb → module.rb} +29 -57
- data/corelib/native.rb +148 -0
- data/corelib/{opal/nil_class.rb → nil_class.rb} +2 -10
- data/corelib/{opal/numeric.rb → numeric.rb} +39 -14
- data/corelib/opal.rb +42 -25
- data/corelib/{opal/proc.rb → proc.rb} +3 -3
- data/corelib/{opal/range.rb → range.rb} +5 -1
- data/corelib/{opal/regexp.rb → regexp.rb} +0 -0
- data/corelib/{opal/runtime.js → runtime.js} +96 -188
- data/corelib/{opal/string.rb → string.rb} +20 -15
- data/corelib/struct.rb +139 -0
- data/corelib/{opal/time.rb → time.rb} +0 -0
- data/lib/opal.rb +4 -0
- data/lib/opal/cli.rb +79 -32
- data/lib/opal/cli_options.rb +91 -0
- data/lib/opal/erb.rb +41 -8
- data/lib/opal/grammar.rb +24 -10
- data/lib/opal/grammar.y +15 -4
- data/lib/opal/grammar_helpers.rb +4 -0
- data/lib/opal/lexer.rb +214 -143
- data/lib/opal/parser.rb +596 -562
- data/lib/opal/require_parser.rb +1 -1
- data/lib/opal/source_map.rb +15 -30
- data/lib/opal/target_scope.rb +24 -5
- data/lib/opal/version.rb +1 -1
- data/mri_spec/cli_spec.rb +18 -0
- data/mri_spec/fixtures/opal_file.rb +2 -0
- data/mri_spec/spec_helper.rb +17 -0
- data/opal.gemspec +5 -2
- data/spec/{rubyspec/filters → filters}/bugs/alias.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/ancestors.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array.rb +0 -0
- data/spec/filters/bugs/array/combination.rb +11 -0
- data/spec/filters/bugs/array/count.rb +3 -0
- data/spec/filters/bugs/array/delete_if.rb +3 -0
- data/spec/filters/bugs/array/drop.rb +3 -0
- data/spec/filters/bugs/array/drop_while.rb +5 -0
- data/spec/filters/bugs/array/eql.rb +3 -0
- data/spec/filters/bugs/array/flatten.rb +9 -0
- data/spec/filters/bugs/array/minus.rb +5 -0
- data/spec/filters/bugs/array/multipliy.rb +9 -0
- data/spec/filters/bugs/array/new.rb +3 -0
- data/spec/filters/bugs/array/pop.rb +6 -0
- data/spec/filters/bugs/array/rassoc.rb +4 -0
- data/spec/filters/bugs/array/rindex.rb +6 -0
- data/spec/filters/bugs/array/select.rb +3 -0
- data/spec/filters/bugs/array/shift.rb +7 -0
- data/spec/filters/bugs/array/shuffle.rb +11 -0
- data/spec/filters/bugs/array/slice.rb +7 -0
- data/spec/filters/bugs/array/take.rb +3 -0
- data/spec/filters/bugs/array/to_a.rb +3 -0
- data/spec/filters/bugs/array/try_convert.rb +7 -0
- data/spec/filters/bugs/array/uniq.rb +10 -0
- data/spec/filters/bugs/array/zip.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_delete.rb +1 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_fetch.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_first.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_flatten.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_intersection.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/array_join.rb +0 -0
- data/spec/{rubyspec/filters → filters}/bugs/break.rb +0 -0
- data/spec/filters/bugs/case.rb +4 -0
- data/spec/{rubyspec/filters → filters}/bugs/coerce_integer.rb +0 -0
- data/spec/filters/bugs/enumerable_sort_by.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/kernel/instance_variables.rb +0 -0
- data/spec/filters/bugs/kernel/rand.rb +4 -0
- data/spec/filters/bugs/language/array.rb +3 -0
- data/spec/filters/bugs/language/block.rb +6 -0
- data/spec/filters/bugs/language/break.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class.rb +3 -0
- data/spec/{rubyspec/filters → filters}/bugs/language/class_variables.rb +0 -0
- data/spec/filters/bugs/language/def.rb +27 -0
- data/spec/filters/bugs/language/defined.rb +3 -0
- data/spec/filters/bugs/language/ensure.rb +4 -0
- data/spec/filters/bugs/language/execution.rb +4 -0
- data/spec/filters/bugs/language/for.rb +18 -0
- data/spec/filters/bugs/language/if.rb +13 -0
- data/spec/filters/bugs/language/loop.rb +4 -0
- data/spec/filters/bugs/language/metaclass.rb +14 -0
- data/spec/filters/bugs/language/module.rb +6 -0
- data/spec/filters/bugs/language/next.rb +3 -0
- data/spec/filters/bugs/language/or.rb +3 -0
- data/spec/filters/bugs/language/order.rb +4 -0
- data/spec/filters/bugs/language/precedence.rb +10 -0
- data/spec/filters/bugs/language/proc.rb +24 -0
- data/spec/filters/bugs/language/redo.rb +5 -0
- data/spec/filters/bugs/language/rescue.rb +9 -0
- data/spec/filters/bugs/language/retry.rb +5 -0
- data/spec/filters/bugs/language/send.rb +10 -0
- data/spec/filters/bugs/language/super.rb +9 -0
- data/spec/filters/bugs/language/until.rb +8 -0
- data/spec/filters/bugs/language/variables.rb +37 -0
- data/spec/filters/bugs/language/while.rb +6 -0
- data/spec/filters/bugs/language/yield.rb +5 -0
- data/spec/{rubyspec/filters → filters}/bugs/module/class_variables.rb +0 -0
- data/spec/filters/bugs/module/method_defined.rb +6 -0
- data/spec/filters/bugs/parser.rb +10 -0
- data/spec/{rubyspec/filters → filters}/bugs/public_methods.rb +1 -0
- data/spec/filters/bugs/return.rb +7 -0
- data/spec/filters/bugs/singleton/instance.rb +4 -0
- data/spec/filters/bugs/source_map.rb +3 -0
- data/spec/filters/bugs/string/center.rb +4 -0
- data/spec/filters/bugs/string/lines.rb +3 -0
- data/spec/{rubyspec/filters → filters}/mspec/mocks.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/ruby_exe.rb +0 -0
- data/spec/{rubyspec/filters → filters}/mspec/should_receive.rb +0 -0
- data/spec/{rubyspec/filters → filters}/parser/block_args.rb +0 -0
- data/spec/{rubyspec/filters → filters}/unsupported/array_subclasses.rb +1 -0
- data/spec/filters/unsupported/frozen.rb +32 -0
- data/spec/filters/unsupported/immutable_strings.rb +3 -0
- data/spec/filters/unsupported/tainted.rb +17 -0
- data/spec/filters/unsupported/trusted.rb +15 -0
- data/spec/opal/class/constants_spec.rb +7 -0
- data/spec/opal/erb/erb_spec.rb +7 -1
- data/spec/opal/erb/inline_block.opalerb +3 -0
- data/spec/opal/hash/allocate_spec.rb +16 -0
- data/spec/opal/hash/new_spec.rb +10 -0
- data/spec/opal/hash/to_s_spec.rb +9 -0
- data/spec/opal/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/kernel/rand_spec.rb +5 -5
- data/spec/opal/kernel/respond_to_spec.rb +14 -1
- data/spec/opal/language/block_spec.rb +13 -0
- data/spec/opal/language/rescue_spec.rb +27 -0
- data/spec/opal/language/return_spec.rb +38 -0
- data/spec/opal/language/singleton_class_spec.rb +13 -0
- data/spec/opal/language/super_spec.rb +99 -0
- data/spec/opal/language/variables_spec.rb +20 -0
- data/spec/opal/module/attr_accessor_spec.rb +8 -0
- data/spec/opal/module/constants_spec.rb +2 -2
- data/spec/opal/native/alias_native_spec.rb +18 -0
- data/spec/opal/native/each_spec.rb +14 -0
- data/spec/opal/native/element_reference_spec.rb +14 -0
- data/spec/opal/native/method_missing_spec.rb +39 -0
- data/spec/opal/native/new_spec.rb +19 -0
- data/spec/opal/native/nil_spec.rb +14 -0
- data/spec/opal/runtime2/class_hierarchy_spec.rb +2 -2
- data/spec/opal/source_map_spec.rb +3 -7
- data/spec/ospec/main.rb.erb +2 -5
- data/spec/parser/alias_spec.rb +4 -4
- data/spec/parser/and_spec.rb +2 -2
- data/spec/parser/array_spec.rb +6 -6
- data/spec/parser/attrasgn_spec.rb +8 -8
- data/spec/parser/begin_spec.rb +11 -11
- data/spec/parser/block_spec.rb +3 -3
- data/spec/parser/break_spec.rb +4 -4
- data/spec/parser/call_spec.rb +50 -48
- data/spec/parser/class_spec.rb +2 -2
- data/spec/parser/const_spec.rb +1 -1
- data/spec/parser/cvar_spec.rb +1 -1
- data/spec/parser/def_spec.rb +5 -5
- data/spec/parser/gvar_spec.rb +2 -2
- data/spec/parser/hash_spec.rb +4 -4
- data/spec/parser/iasgn_spec.rb +3 -3
- data/spec/parser/if_spec.rb +6 -6
- data/spec/parser/iter_spec.rb +6 -6
- data/spec/parser/lambda_spec.rb +5 -5
- data/spec/parser/lasgn_spec.rb +2 -2
- data/spec/parser/line_spec.rb +2 -2
- data/spec/parser/lvar_spec.rb +5 -5
- data/spec/parser/masgn_spec.rb +1 -1
- data/spec/parser/module_spec.rb +2 -2
- data/spec/parser/not_spec.rb +4 -4
- data/spec/parser/op_asgn1_spec.rb +2 -2
- data/spec/parser/op_asgn2_spec.rb +2 -2
- data/spec/parser/or_spec.rb +2 -2
- data/spec/parser/parse_spec.rb +66 -0
- data/spec/parser/parser_spec.rb +32 -38
- data/spec/parser/regexp_spec.rb +4 -4
- data/spec/parser/return_spec.rb +4 -4
- data/spec/parser/sclass_spec.rb +4 -4
- data/spec/parser/str_spec.rb +3 -3
- data/spec/parser/super_spec.rb +6 -6
- data/spec/parser/undef_spec.rb +3 -3
- data/spec/parser/unless_spec.rb +4 -4
- data/spec/parser/while_spec.rb +3 -3
- data/spec/parser/xstr_spec.rb +3 -3
- data/spec/parser/yield_spec.rb +6 -6
- data/spec/rubyspec/core/array/drop_spec.rb +1 -1
- data/spec/rubyspec/core/array/keep_if_spec.rb +1 -3
- data/spec/rubyspec/core/array/length_spec.rb +1 -3
- data/spec/rubyspec/core/array/map_spec.rb +2 -6
- data/spec/rubyspec/core/array/minus_spec.rb +3 -3
- data/spec/rubyspec/core/array/multiply_spec.rb +14 -16
- data/spec/rubyspec/core/array/new_spec.rb +3 -5
- data/spec/rubyspec/core/array/plus_spec.rb +2 -2
- data/spec/rubyspec/core/array/pop_spec.rb +4 -4
- data/spec/rubyspec/core/array/rassoc_spec.rb +2 -2
- data/spec/rubyspec/core/array/reject_spec.rb +2 -6
- data/spec/rubyspec/core/array/replace_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_each_spec.rb +1 -3
- data/spec/rubyspec/core/array/reverse_spec.rb +4 -4
- data/spec/rubyspec/core/array/rindex_spec.rb +1 -1
- data/spec/rubyspec/core/array/select_spec.rb +3 -7
- data/spec/rubyspec/core/array/shared/collect.rb +7 -0
- data/spec/rubyspec/core/array/shared/index.rb +1 -1
- data/spec/rubyspec/core/array/shared/keep_if.rb +3 -0
- data/spec/rubyspec/core/array/shared/length.rb +3 -0
- data/spec/rubyspec/core/array/shared/replace.rb +3 -0
- data/spec/rubyspec/core/array/shared/slice.rb +3 -0
- data/spec/rubyspec/core/array/shuffle_spec.rb +1 -1
- data/spec/rubyspec/core/array/size_spec.rb +1 -3
- data/spec/rubyspec/core/array/slice_spec.rb +4 -6
- data/spec/rubyspec/core/array/sort_spec.rb +2 -2
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/try_convert_spec.rb +7 -7
- data/spec/rubyspec/core/array/uniq_spec.rb +7 -7
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/collect_spec.rb +24 -0
- data/spec/rubyspec/core/enumerable/count_spec.rb +35 -19
- data/spec/rubyspec/core/enumerable/find_spec.rb +5 -0
- data/spec/rubyspec/core/hash/each_pair_spec.rb +7 -7
- data/spec/rubyspec/core/hash/each_spec.rb +13 -7
- data/spec/rubyspec/core/module/method_defined_spec.rb +4 -4
- data/spec/rubyspec/core/module/public_method_defined_spec.rb +19 -0
- data/spec/rubyspec/core/module/remove_const_spec.rb +23 -0
- data/spec/rubyspec/core/numeric/step_spec.rb +14 -0
- data/spec/rubyspec/core/string/center_spec.rb +43 -65
- data/spec/rubyspec/core/string/lines_spec.rb +1 -1
- data/spec/rubyspec/core/string/ljust_spec.rb +25 -9
- data/spec/rubyspec/core/string/rjust_spec.rb +26 -10
- data/spec/rubyspec/core/struct/fixtures/classes.rb +26 -0
- data/spec/rubyspec/core/struct/initialize_spec.rb +11 -0
- data/spec/rubyspec/core/struct/new_spec.rb +24 -0
- data/spec/rubyspec/fixtures/constants.rb +7 -0
- data/spec/rubyspec/language/break_spec.rb +1 -1
- data/spec/rubyspec/language/case_spec.rb +30 -30
- data/spec/rubyspec/language/def_spec.rb +34 -34
- data/spec/rubyspec/language/defined_spec.rb +2 -2
- data/spec/rubyspec/language/ensure_spec.rb +2 -2
- data/spec/rubyspec/language/execution_spec.rb +2 -2
- data/spec/rubyspec/language/for_spec.rb +17 -17
- data/spec/rubyspec/language/hash_spec.rb +3 -3
- data/spec/rubyspec/language/if_spec.rb +11 -11
- data/spec/rubyspec/language/loop_spec.rb +3 -3
- data/spec/rubyspec/language/metaclass_spec.rb +14 -14
- data/spec/rubyspec/language/module_spec.rb +6 -6
- data/spec/rubyspec/language/next_spec.rb +5 -5
- data/spec/rubyspec/language/not_spec.rb +1 -1
- data/spec/rubyspec/language/or_spec.rb +1 -1
- data/spec/rubyspec/language/order_spec.rb +3 -5
- data/spec/rubyspec/language/precedence_spec.rb +19 -19
- data/spec/rubyspec/language/proc_spec.rb +29 -29
- data/spec/rubyspec/language/redo_spec.rb +3 -5
- data/spec/rubyspec/language/rescue_spec.rb +7 -7
- data/spec/rubyspec/language/retry_spec.rb +2 -2
- data/spec/rubyspec/language/return_spec.rb +12 -12
- data/spec/rubyspec/language/send_spec.rb +9 -9
- data/spec/rubyspec/language/singleton_class_spec.rb +3 -4
- data/spec/rubyspec/language/super_spec.rb +7 -11
- data/spec/rubyspec/language/until_spec.rb +10 -10
- data/spec/rubyspec/language/variables_spec.rb +59 -67
- data/spec/rubyspec/language/versions/array_1.9.rb +1 -1
- data/spec/rubyspec/language/versions/block_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/break_1.9.rb +0 -0
- data/spec/rubyspec/language/versions/literal_lambda_1.9.rb +12 -12
- data/spec/rubyspec/language/versions/send_1.9.rb +23 -23
- data/spec/rubyspec/language/versions/symbol_1.9.rb +2 -2
- data/spec/rubyspec/language/versions/variables_1.9.rb +1 -1
- data/spec/rubyspec/language/while_spec.rb +4 -4
- data/spec/rubyspec/language/yield_spec.rb +3 -3
- data/spec/rubyspec/library/erb/util/html_escape_spec.rb +10 -0
- data/spec/rubyspec/library/singleton/clone_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/dup_spec.rb +8 -0
- data/spec/rubyspec/library/singleton/fixtures/classes.rb +18 -0
- data/spec/rubyspec/library/singleton/instance_spec.rb +30 -0
- data/spec/spec_helper.rb +214 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/erb.rb +11 -20
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +78 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/rbconfig.rb +1 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/stringio.rb +173 -0
- data/stdlib/template.rb +44 -0
- metadata +285 -79
- data/corelib/opal/native.rb +0 -31
- data/spec/opal/class/bridge_class_spec.rb +0 -39
- data/spec/opal/native_spec.rb +0 -209
- data/spec/ospec/runner.rb +0 -223
- data/spec/rubyspec/filters/bugs/block_args.rb +0 -3
- data/spec/rubyspec/filters/bugs/case.rb +0 -8
- data/spec/rubyspec/filters/bugs/language/module.rb +0 -3
- data/spec/rubyspec/filters/unsupported/frozen.rb +0 -4
- data/spec/rubyspec/filters/unsupported/tainted.rb +0 -7
data/corelib/opal.rb
CHANGED
@@ -1,22 +1,25 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require '
|
11
|
-
require '
|
12
|
-
require '
|
13
|
-
require '
|
14
|
-
require '
|
15
|
-
require '
|
16
|
-
require '
|
17
|
-
require '
|
18
|
-
require '
|
19
|
-
require '
|
1
|
+
require 'runtime'
|
2
|
+
require 'module'
|
3
|
+
require 'class'
|
4
|
+
require 'basic_object'
|
5
|
+
require 'kernel'
|
6
|
+
require 'nil_class'
|
7
|
+
require 'boolean'
|
8
|
+
require 'error'
|
9
|
+
require 'regexp'
|
10
|
+
require 'comparable'
|
11
|
+
require 'enumerable'
|
12
|
+
require 'enumerator'
|
13
|
+
require 'array'
|
14
|
+
require 'hash'
|
15
|
+
require 'string'
|
16
|
+
require 'numeric'
|
17
|
+
require 'proc'
|
18
|
+
require 'range'
|
19
|
+
require 'time'
|
20
|
+
require 'struct'
|
21
|
+
require 'native'
|
22
|
+
require 'io'
|
20
23
|
|
21
24
|
# regexp matches
|
22
25
|
$& = $~ = $` = $' = nil
|
@@ -26,9 +29,10 @@ $: = []
|
|
26
29
|
|
27
30
|
# split lines
|
28
31
|
$/ = "\n"
|
32
|
+
$, = " "
|
29
33
|
|
30
34
|
# native global
|
31
|
-
$$ = $global = `Opal.global`
|
35
|
+
$$ = $global = Native(`Opal.global`)
|
32
36
|
|
33
37
|
ARGV = []
|
34
38
|
ARGF = Object.new
|
@@ -37,15 +41,28 @@ TRUE = true
|
|
37
41
|
FALSE = false
|
38
42
|
NIL = nil
|
39
43
|
|
40
|
-
STDERR = $stderr =
|
41
|
-
STDIN = $stdin =
|
42
|
-
STDOUT = $stdout =
|
44
|
+
STDERR = $stderr = IO.new
|
45
|
+
STDIN = $stdin = IO.new
|
46
|
+
STDOUT = $stdout = IO.new
|
47
|
+
|
48
|
+
def $stdout.puts(*strs)
|
49
|
+
%x{
|
50
|
+
for (var i = 0; i < strs.length; i++) {
|
51
|
+
if(strs[i] instanceof Array) {
|
52
|
+
#{ puts(*`strs[i]`) }
|
53
|
+
} else {
|
54
|
+
$opal.puts(#{ `strs[i]`.to_s });
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
nil
|
59
|
+
end
|
43
60
|
|
44
61
|
RUBY_PLATFORM = 'opal'
|
45
62
|
RUBY_ENGINE = 'opal'
|
46
63
|
RUBY_VERSION = '1.9.3'
|
47
|
-
RUBY_ENGINE_VERSION = '0.4.
|
48
|
-
RUBY_RELEASE_DATE = '2013-
|
64
|
+
RUBY_ENGINE_VERSION = '0.4.4'
|
65
|
+
RUBY_RELEASE_DATE = '2013-08-13'
|
49
66
|
|
50
67
|
def self.to_s
|
51
68
|
'main'
|
@@ -3,7 +3,7 @@ class Proc
|
|
3
3
|
`def.is_lambda = true`
|
4
4
|
|
5
5
|
def self.new(&block)
|
6
|
-
`if (block === nil)
|
6
|
+
`if (block === nil) { throw new Error("no block given"); }`
|
7
7
|
`block.is_lambda = false`
|
8
8
|
block
|
9
9
|
end
|
@@ -12,8 +12,8 @@ class Proc
|
|
12
12
|
%x{
|
13
13
|
var result = #{self}.apply(null, #{args});
|
14
14
|
|
15
|
-
if (result ===
|
16
|
-
return
|
15
|
+
if (result === $breaker) {
|
16
|
+
return $breaker.$v;
|
17
17
|
}
|
18
18
|
|
19
19
|
return result;
|
@@ -42,6 +42,10 @@ class Range
|
|
42
42
|
`#{self}.begin` <= value && value <= (exclude_end? ? `#{self}.end` - 1 : `#{self}.end`)
|
43
43
|
end
|
44
44
|
|
45
|
+
def last
|
46
|
+
self.end
|
47
|
+
end
|
48
|
+
|
45
49
|
def each(&block)
|
46
50
|
current = min
|
47
51
|
|
@@ -67,7 +71,7 @@ class Range
|
|
67
71
|
end
|
68
72
|
|
69
73
|
# FIXME: currently hardcoded to assume range holds numerics
|
70
|
-
def include?(
|
74
|
+
def include?(obj)
|
71
75
|
`return obj >= #{self}.begin && obj <= #{self}.end`
|
72
76
|
end
|
73
77
|
|
File without changes
|
@@ -11,6 +11,9 @@
|
|
11
11
|
// Class' class
|
12
12
|
function Class(){}
|
13
13
|
|
14
|
+
// Module's class
|
15
|
+
function Module(){}
|
16
|
+
|
14
17
|
// the class of nil
|
15
18
|
function NilClass(){}
|
16
19
|
|
@@ -27,8 +30,8 @@
|
|
27
30
|
Opal.global = this;
|
28
31
|
|
29
32
|
// Minify common function calls
|
30
|
-
var
|
31
|
-
var
|
33
|
+
var $hasOwn = Opal.hasOwnProperty;
|
34
|
+
var $slice = Opal.slice = Array.prototype.slice;
|
32
35
|
|
33
36
|
// Generates unique id for every ruby object
|
34
37
|
var unique_id = 0;
|
@@ -61,20 +64,6 @@
|
|
61
64
|
}
|
62
65
|
}
|
63
66
|
|
64
|
-
/*
|
65
|
-
Define a bridged class. Bridged classes will always be in the top level
|
66
|
-
scope, and will always be a subclass of Object.
|
67
|
-
*/
|
68
|
-
Opal.bridge = function(name, constructor) {
|
69
|
-
var klass = bridge_class(constructor);
|
70
|
-
|
71
|
-
klass._name = name;
|
72
|
-
|
73
|
-
create_scope(Opal, klass, name);
|
74
|
-
|
75
|
-
return klass;
|
76
|
-
};
|
77
|
-
|
78
67
|
Opal.klass = function(base, superklass, id, constructor) {
|
79
68
|
var klass;
|
80
69
|
|
@@ -86,7 +75,7 @@
|
|
86
75
|
superklass = ObjectClass;
|
87
76
|
}
|
88
77
|
|
89
|
-
if (
|
78
|
+
if ($hasOwn.call(base._scope, id)) {
|
90
79
|
klass = base._scope[id];
|
91
80
|
|
92
81
|
if (!klass._isClass) {
|
@@ -122,7 +111,7 @@
|
|
122
111
|
base = base._klass;
|
123
112
|
}
|
124
113
|
|
125
|
-
if (
|
114
|
+
if ($hasOwn.call(base._scope, id)) {
|
126
115
|
klass = base._scope[id];
|
127
116
|
|
128
117
|
if (!klass._mod$ && klass !== ObjectClass) {
|
@@ -142,11 +131,6 @@
|
|
142
131
|
return klass;
|
143
132
|
};
|
144
133
|
|
145
|
-
// Utility function to raise a "no block given" error
|
146
|
-
var no_block_given = function() {
|
147
|
-
throw new Error('no block given');
|
148
|
-
};
|
149
|
-
|
150
134
|
// Boot a base class (makes instances).
|
151
135
|
var boot_defclass = function(id, constructor, superklass) {
|
152
136
|
if (superklass) {
|
@@ -175,7 +159,6 @@
|
|
175
159
|
RubyClass.prototype = new ctor();
|
176
160
|
|
177
161
|
var prototype = RubyClass.prototype;
|
178
|
-
prototype._isBoot = true;
|
179
162
|
prototype._alloc = klass;
|
180
163
|
prototype._isClass = true;
|
181
164
|
prototype._name = id;
|
@@ -230,7 +213,7 @@
|
|
230
213
|
return constructor;
|
231
214
|
};
|
232
215
|
|
233
|
-
var bridge_class = function(constructor) {
|
216
|
+
var bridge_class = function(name, constructor) {
|
234
217
|
var klass = boot_class(ObjectClass, constructor);
|
235
218
|
var i, length, m;
|
236
219
|
|
@@ -249,184 +232,102 @@
|
|
249
232
|
constructor.prototype[m] = table[m];
|
250
233
|
}
|
251
234
|
|
235
|
+
klass._name = name;
|
236
|
+
create_scope(Opal, klass, name);
|
237
|
+
|
252
238
|
return klass;
|
253
239
|
};
|
254
240
|
|
255
241
|
Opal.puts = function(a) { console.log(a); };
|
256
242
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
};
|
261
|
-
|
262
|
-
// Singleton class
|
263
|
-
Opal.singleton = function(obj) {
|
264
|
-
if (obj == null) {
|
265
|
-
return Opal.NilClass;
|
266
|
-
}
|
267
|
-
else if (obj.$singleton_class) {
|
268
|
-
return obj.$singleton_class();
|
269
|
-
}
|
270
|
-
else {
|
271
|
-
native_singleton.prototype = obj;
|
272
|
-
return native_singleton;
|
273
|
-
}
|
274
|
-
};
|
275
|
-
|
276
|
-
// Method missing dispatcher
|
277
|
-
Opal.mm = function(mid) {
|
278
|
-
var dispatcher = function() {
|
279
|
-
var args = __slice.call(arguments);
|
243
|
+
Opal.add_stubs = function(stubs) {
|
244
|
+
for (var i = 0, length = stubs.length; i < length; i++) {
|
245
|
+
var stub = stubs[i];
|
280
246
|
|
281
|
-
if (
|
282
|
-
|
283
|
-
|
284
|
-
}
|
285
|
-
else {
|
286
|
-
native_send._p = dispatcher._p;
|
287
|
-
return native_send(this, mid, args);
|
247
|
+
if (!BasicObject.prototype[stub]) {
|
248
|
+
BasicObject.prototype[stub] = true;
|
249
|
+
add_stub_for(BasicObject.prototype, stub);
|
288
250
|
}
|
289
|
-
};
|
290
|
-
|
291
|
-
return dispatcher;
|
292
|
-
};
|
293
|
-
|
294
|
-
// send a method to a native object
|
295
|
-
var native_send = function(obj, mid, args) {
|
296
|
-
var prop, block = native_send._p;
|
297
|
-
native_send._p = null;
|
298
|
-
|
299
|
-
if ( (prop = native_methods[mid]) ) {
|
300
|
-
return prop(obj, args, block);
|
301
251
|
}
|
252
|
+
};
|
302
253
|
|
303
|
-
|
254
|
+
function add_stub_for(prototype, stub) {
|
255
|
+
function method_missing_stub() {
|
256
|
+
this.$method_missing._p = method_missing_stub._p;
|
257
|
+
method_missing_stub._p = null;
|
304
258
|
|
305
|
-
|
306
|
-
prop = prop.apply(obj, args.$to_n());
|
259
|
+
return this.$method_missing.apply(this, [stub.slice(1)].concat($slice.call(arguments)));
|
307
260
|
}
|
308
|
-
else if (mid.charAt(mid.length - 1) === "=") {
|
309
|
-
prop = mid.slice(0, mid.length - 1);
|
310
261
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
}
|
315
|
-
|
316
|
-
return obj[prop] = args[0];
|
317
|
-
}
|
262
|
+
method_missing_stub.rb_stub = true;
|
263
|
+
prototype[stub] = method_missing_stub;
|
264
|
+
}
|
318
265
|
|
319
|
-
|
320
|
-
return nil;
|
321
|
-
}
|
266
|
+
Opal.add_stub_for = add_stub_for;
|
322
267
|
|
323
|
-
|
268
|
+
// Const missing dispatcher
|
269
|
+
Opal.cm = function(name) {
|
270
|
+
return this.base.$const_missing(name);
|
324
271
|
};
|
325
272
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
var prop = obj[args[0]];
|
333
|
-
|
334
|
-
if (prop == null) {
|
335
|
-
return nil;
|
336
|
-
}
|
337
|
-
|
338
|
-
return prop;
|
339
|
-
},
|
340
|
-
|
341
|
-
"[]=": function(obj, args) {
|
342
|
-
var value = args[1];
|
343
|
-
|
344
|
-
if (value === nil) {
|
345
|
-
value = null;
|
346
|
-
}
|
347
|
-
|
348
|
-
return obj[args[0]] = value;
|
349
|
-
},
|
273
|
+
// Arity count error dispatcher
|
274
|
+
Opal.ac = function(actual, expected, object, meth) {
|
275
|
+
var inspect = ((typeof(object) !== 'function') ? object.constructor._name + '#' : object._name + '.') + meth;
|
276
|
+
var msg = '[' + inspect + '] wrong number of arguments(' + actual + ' for ' + expected + ')';
|
277
|
+
throw Opal.ArgumentError.$new(msg);
|
278
|
+
};
|
350
279
|
|
351
|
-
|
352
|
-
|
353
|
-
|
280
|
+
// Super dispatcher
|
281
|
+
Opal.dispatch_super = function(obj, jsid, args, iter, defs) {
|
282
|
+
var dispatcher;
|
354
283
|
|
355
|
-
|
356
|
-
|
357
|
-
}
|
284
|
+
if (defs) {
|
285
|
+
dispatcher = obj._isClass ? defs._super : obj._klass._proto;
|
286
|
+
}
|
287
|
+
else {
|
288
|
+
dispatcher = obj._isClass ? obj._klass : obj._klass._super._proto;
|
289
|
+
}
|
358
290
|
|
359
|
-
|
360
|
-
|
361
|
-
},
|
291
|
+
dispatcher = dispatcher['$' + jsid];
|
292
|
+
dispatcher._p = iter;
|
362
293
|
|
363
|
-
|
364
|
-
|
294
|
+
return dispatcher.apply(obj, args);
|
295
|
+
};
|
365
296
|
|
366
|
-
|
367
|
-
|
368
|
-
|
297
|
+
// return helper
|
298
|
+
Opal.$return = function(val) {
|
299
|
+
Opal.returner.$v = val;
|
300
|
+
throw Opal.returner;
|
301
|
+
};
|
369
302
|
|
370
|
-
|
371
|
-
|
372
|
-
|
303
|
+
// handles yield calls for 1 yielded arg
|
304
|
+
Opal.$yield1 = function(block, arg) {
|
305
|
+
if (typeof(block) !== "function") {
|
306
|
+
throw Opal.LocalJumpError.$new("no block given");
|
307
|
+
}
|
373
308
|
|
374
|
-
|
375
|
-
|
309
|
+
if (block.length > 1) {
|
310
|
+
if (arg._isArray) {
|
311
|
+
return block.apply(null, arg);
|
376
312
|
}
|
377
313
|
else {
|
378
|
-
|
379
|
-
prop = obj[key];
|
380
|
-
|
381
|
-
if (prop == null) {
|
382
|
-
prop = nil;
|
383
|
-
}
|
384
|
-
|
385
|
-
block(key, prop);
|
386
|
-
}
|
314
|
+
return block(arg);
|
387
315
|
}
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
"to_a": function(obj, args) {
|
393
|
-
var result = [];
|
394
|
-
|
395
|
-
for (var i = 0, length = obj.length; i < length; i++) {
|
396
|
-
result.push(obj[i]);
|
397
|
-
}
|
398
|
-
|
399
|
-
return result;
|
400
|
-
},
|
401
|
-
|
402
|
-
"to_h": function(obj) {
|
403
|
-
var keys = [], values = {}, value;
|
404
|
-
|
405
|
-
for (var key in obj) {
|
406
|
-
value = obj[key];
|
407
|
-
keys.push(key);
|
408
|
-
|
409
|
-
if (value == null) {
|
410
|
-
value = nil;
|
411
|
-
}
|
412
|
-
|
413
|
-
values[key] = value;
|
414
|
-
}
|
415
|
-
|
416
|
-
return Opal.hash2(keys, values);
|
316
|
+
}
|
317
|
+
else {
|
318
|
+
return block(arg);
|
417
319
|
}
|
418
320
|
};
|
419
321
|
|
420
|
-
//
|
421
|
-
Opal
|
422
|
-
|
423
|
-
|
322
|
+
// handles yield for > 1 yielded arg
|
323
|
+
Opal.$yieldX = function(block, args) {
|
324
|
+
if (block.length > 1 && args.length == 1) {
|
325
|
+
if (args[0]._isArray) {
|
326
|
+
return block.apply(null, args[0]);
|
327
|
+
}
|
328
|
+
}
|
424
329
|
|
425
|
-
|
426
|
-
Opal.ac = function(actual, expected, object, meth) {
|
427
|
-
var inspect = ((typeof(object) !== 'function') ? object.constructor._name + '#' : object._name + '.') + meth;
|
428
|
-
var msg = '[' + inspect + '] wrong number of arguments(' + actual + ' for ' + expected + ')';
|
429
|
-
throw Opal.ArgumentError.$new(msg);
|
330
|
+
return block.apply(null, args);
|
430
331
|
};
|
431
332
|
|
432
333
|
/*
|
@@ -445,7 +346,7 @@
|
|
445
346
|
@param [String] mid ruby method to call
|
446
347
|
*/
|
447
348
|
Opal.send = function(recv, mid) {
|
448
|
-
var args =
|
349
|
+
var args = $slice.call(arguments, 2),
|
449
350
|
func = recv['$' + mid];
|
450
351
|
|
451
352
|
if (func) {
|
@@ -456,7 +357,7 @@
|
|
456
357
|
};
|
457
358
|
|
458
359
|
Opal.block_send = function(recv, mid, block) {
|
459
|
-
var args =
|
360
|
+
var args = $slice.call(arguments, 3),
|
460
361
|
func = recv['$' + mid];
|
461
362
|
|
462
363
|
if (func) {
|
@@ -500,22 +401,26 @@
|
|
500
401
|
// Constructors for *instances* of core objects
|
501
402
|
boot_defclass('BasicObject', BasicObject);
|
502
403
|
boot_defclass('Object', Object, BasicObject);
|
503
|
-
boot_defclass('
|
404
|
+
boot_defclass('Module', Module, Object);
|
405
|
+
boot_defclass('Class', Class, Module);
|
504
406
|
|
505
407
|
// Constructors for *classes* of core objects
|
506
408
|
var BasicObjectClass = boot_makemeta('BasicObject', BasicObject, Class);
|
507
409
|
var ObjectClass = boot_makemeta('Object', Object, BasicObjectClass.constructor);
|
508
|
-
var
|
410
|
+
var ModuleClass = boot_makemeta('Module', Module, ObjectClass.constructor);
|
411
|
+
var ClassClass = boot_makemeta('Class', Class, ModuleClass.constructor);
|
509
412
|
|
510
413
|
// Fix booted classes to use their metaclass
|
511
414
|
BasicObjectClass._klass = ClassClass;
|
512
415
|
ObjectClass._klass = ClassClass;
|
416
|
+
ModuleClass._klass = ClassClass;
|
513
417
|
ClassClass._klass = ClassClass;
|
514
418
|
|
515
419
|
// Fix superclasses of booted classes
|
516
420
|
BasicObjectClass._super = null;
|
517
421
|
ObjectClass._super = BasicObjectClass;
|
518
|
-
|
422
|
+
ModuleClass._super = ObjectClass;
|
423
|
+
ClassClass._super = ModuleClass;
|
519
424
|
|
520
425
|
// Defines methods onto Object (which are then donated to bridged classes)
|
521
426
|
ObjectClass._defn = function (mid, body) {
|
@@ -527,15 +432,17 @@
|
|
527
432
|
|
528
433
|
Opal.base = ObjectClass;
|
529
434
|
BasicObjectClass._scope = ObjectClass._scope = Opal;
|
530
|
-
Opal.Module = Opal.Class;
|
531
435
|
Opal.Kernel = ObjectClass;
|
532
436
|
|
437
|
+
create_scope(Opal, ModuleClass);
|
533
438
|
create_scope(Opal, ClassClass);
|
534
439
|
|
535
440
|
ObjectClass._proto.toString = function() {
|
536
441
|
return this.$to_s();
|
537
442
|
};
|
538
443
|
|
444
|
+
ClassClass._proto._defn = function(mid, body) { this._proto[mid] = body; };
|
445
|
+
|
539
446
|
Opal.top = new ObjectClass._alloc();
|
540
447
|
|
541
448
|
Opal.klass(ObjectClass, ObjectClass, 'NilClass', NilClass);
|
@@ -544,15 +451,16 @@
|
|
544
451
|
nil.call = nil.apply = function() { throw Opal.LocalJumpError.$new('no block given'); };
|
545
452
|
|
546
453
|
Opal.breaker = new Error('unexpected break');
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
454
|
+
Opal.returner = new Error('unexpected return');
|
455
|
+
|
456
|
+
bridge_class('Array', Array);
|
457
|
+
bridge_class('Boolean', Boolean);
|
458
|
+
bridge_class('Numeric', Number);
|
459
|
+
bridge_class('String', String);
|
460
|
+
bridge_class('Proc', Function);
|
461
|
+
bridge_class('Exception', Error);
|
462
|
+
bridge_class('Regexp', RegExp);
|
463
|
+
bridge_class('Time', Date);
|
556
464
|
|
557
465
|
TypeError._super = Error;
|
558
466
|
}).call(this);
|