opal 0.5.2 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/lib/opal.rb +0 -5
  4. data/lib/opal/compiler.rb +24 -44
  5. data/lib/opal/nodes/base.rb +5 -8
  6. data/lib/opal/nodes/call.rb +4 -0
  7. data/lib/opal/nodes/class.rb +6 -7
  8. data/lib/opal/nodes/def.rb +4 -4
  9. data/lib/opal/nodes/definitions.rb +0 -14
  10. data/lib/opal/nodes/iter.rb +51 -38
  11. data/lib/opal/nodes/literal.rb +21 -24
  12. data/lib/opal/nodes/module.rb +4 -4
  13. data/lib/opal/nodes/runtime_helpers.rb +45 -0
  14. data/lib/opal/nodes/scope.rb +280 -0
  15. data/lib/opal/nodes/singleton_class.rb +4 -5
  16. data/lib/opal/nodes/super.rb +1 -1
  17. data/lib/opal/nodes/top.rb +9 -7
  18. data/lib/opal/nodes/yield.rb +14 -3
  19. data/lib/opal/parser.rb +4 -18
  20. data/lib/opal/parser/grammar.rb +3745 -3667
  21. data/lib/opal/parser/grammar.y +1692 -1778
  22. data/lib/opal/parser/keywords.rb +35 -35
  23. data/lib/opal/parser/lexer.rb +356 -325
  24. data/lib/opal/parser/sexp.rb +1 -1
  25. data/lib/opal/version.rb +1 -1
  26. data/opal.gemspec +1 -0
  27. data/opal/core/array.rb +320 -81
  28. data/opal/core/enumerable.rb +46 -5
  29. data/opal/core/hash.rb +6 -64
  30. data/opal/core/helpers.rb +67 -0
  31. data/opal/core/method.rb +1 -1
  32. data/opal/core/module.rb +4 -4
  33. data/opal/core/range.rb +1 -12
  34. data/opal/core/regexp.rb +2 -8
  35. data/opal/core/runtime.js +74 -3
  36. data/opal/core/string.rb +99 -74
  37. data/opal/opal.rb +3 -72
  38. data/spec/filters/bugs/array.rb +2 -30
  39. data/spec/filters/bugs/basic_object.rb +0 -1
  40. data/spec/filters/bugs/string.rb +26 -21
  41. data/spec/filters/unsupported/enumerator.rb +3 -0
  42. data/spec/filters/unsupported/float.rb +1 -0
  43. data/spec/filters/unsupported/immutable_strings.rb +15 -0
  44. data/spec/filters/unsupported/tainted.rb +58 -30
  45. data/spec/filters/unsupported/trusted.rb +35 -15
  46. data/spec/opal/parser/class_spec.rb +4 -4
  47. data/spec/opal/parser/def_spec.rb +4 -4
  48. data/spec/opal/parser/lvar_spec.rb +6 -6
  49. data/spec/opal/parser/module_spec.rb +4 -4
  50. data/spec/opal/parser/sclass_spec.rb +2 -2
  51. data/spec/stdlib/native/exposure_spec.rb +33 -0
  52. data/stdlib/buffer.rb +1 -1
  53. data/stdlib/buffer/view.rb +1 -1
  54. data/stdlib/native.rb +193 -174
  55. data/stdlib/opal-parser.rb +0 -6
  56. data/stdlib/pp.rb +9 -0
  57. data/tasks/mspec.rake +3 -1
  58. metadata +9 -9
  59. data/lib/opal/nodes/base_scope.rb +0 -11
  60. data/lib/opal/target_scope.rb +0 -281
  61. data/spec/filters/20.rb +0 -4
  62. data/spec/filters/unsupported/array_subclasses.rb +0 -37
@@ -1,4 +1,3 @@
1
1
  opal_filter "BasicObject" do
2
2
  fails "BasicObject#instance_eval evaluates strings"
3
- fails "BasicObject#instance_exec passes arguments to the block"
4
3
  end
@@ -1,37 +1,42 @@
1
1
  opal_filter "String" do
2
+ fails "String#capitalize is locale insensitive (only upcases a-z and only downcases A-Z)"
3
+
4
+ fails "String#center with length, padding raises an ArgumentError if padstr is empty"
5
+ fails "String#center with length, padding raises a TypeError when padstr can't be converted to a string"
6
+ fails "String#center with length, padding calls #to_str to convert padstr to a String"
7
+ fails "String#center with length, padding raises a TypeError when length can't be converted to an integer"
8
+ fails "String#center with length, padding calls #to_int to convert length to an integer"
2
9
  fails "String#center with length, padding pads with whitespace if no padstr is given"
3
10
  fails "String#center with length, padding returns a new string of specified length with self centered and padded with padstr"
4
11
 
5
- fails "String#lines should split on the default record separator and return enumerator if not block is given"
12
+ fails "String#downcase is locale insensitive (only replaces A-Z)"
6
13
 
7
- fails "String#upcase is locale insensitive (only replaces a-z)"
8
- fails "String#size returns the length of self"
9
- fails "String#length returns the length of self"
14
+ fails "String#end_with? converts its argument using :to_str"
15
+ fails "String#end_with? returns true if other is empty"
10
16
 
11
- fails "String#index with Regexp converts start_offset to an integer via to_int"
17
+ fails "String#index raises a TypeError if passed a Symbol"
18
+ # we need regexp rewriting for these
12
19
  fails "String#index with Regexp supports \\G which matches at the given start offset"
13
20
  fails "String#index with Regexp starts the search at the given offset"
14
21
  fails "String#index with Regexp returns the index of the first match of regexp"
15
- fails "String#index calls #to_int to convert the second argument"
16
- fails "String#index calls #to_str to convert the first argument"
17
- fails "String#index raises a TypeError if passed a Symbol"
18
22
 
23
+ fails "String#intern does not special case certain operators"
19
24
  fails "String#intern special cases +(binary) and -(binary)"
20
- fails "String#to_sym special cases +(binary) and -(binary)"
25
+
26
+ fails "String#length returns the length of self"
27
+
28
+ fails "String#lines should split on the default record separator and return enumerator if not block is given"
29
+
30
+ fails "String#size returns the length of self"
21
31
 
22
32
  fails "String#start_with? ignores arguments not convertible to string"
23
33
  fails "String#start_with? converts its argument using :to_str"
24
- fails "String#end_with? converts its argument using :to_str"
25
- fails "String#end_with? returns true if other is empty"
26
- fails "String#downcase is locale insensitive (only replaces A-Z)"
27
- fails "String#intern does not special case certain operators"
34
+
28
35
  fails "String#to_sym does not special case certain operators"
29
- fails "String#capitalize is locale insensitive (only upcases a-z and only downcases A-Z)"
30
- fails "String#center with length, padding raises an ArgumentError if padstr is empty"
31
- fails "String#center with length, padding raises a TypeError when padstr can't be converted to a string"
32
- fails "String#center with length, padding calls #to_str to convert padstr to a String"
33
- fails "String#center with length, padding raises a TypeError when length can't be converted to an integer"
34
- fails "String#center with length, padding calls #to_int to convert length to an integer"
35
- fails "String#chomp when passed an Object raises a TypeError if #to_str does not return a String"
36
- fails "String#chomp when passed no argument returns a copy of the String when it is not modified"
36
+ fails "String#to_sym special cases +(binary) and -(binary)"
37
+
38
+ fails "String#upcase is locale insensitive (only replaces a-z)"
39
+
40
+ # 1.9.3 => 2.0
41
+ fails "String#end_with? ignores arguments not convertible to string"
37
42
  end
@@ -10,4 +10,7 @@ opal_filter "Enumerator as generator" do
10
10
  fails "Enumerator#rewind does nothing if the object doesn't have a #rewind method"
11
11
  fails "Enumerator#rewind works with peek to reset the position"
12
12
  fails "Enumerator#rewind calls the enclosed object's rewind method if one exists"
13
+
14
+ # 1.9.3 => 2.0
15
+ fails "Enumerator.new ignores block if arg given"
13
16
  end
@@ -1,4 +1,5 @@
1
1
  opal_filter "Float" do
2
2
  fails "Array#inspect represents a recursive element with '[...]'"
3
3
  fails "Array#to_s represents a recursive element with '[...]'"
4
+ fails "Array#eql? returns false if any corresponding elements are not #eql?"
4
5
  end
@@ -6,4 +6,19 @@ opal_filter "immutable strings" do
6
6
  fails "Time#strftime formats time according to the directives in the given format string"
7
7
  fails "Time#strftime with %z formats a local time with positive UTC offset as '+HHMM'"
8
8
  fails "Time#strftime with %z formats a local time with negative UTC offset as '-HHMM'"
9
+
10
+ fails "String#chomp when passed no argument returns a copy of the String when it is not modified"
11
+
12
+ fails "String#chop returns a new string when applied to an empty string"
13
+
14
+ fails "String#chop! removes the final character"
15
+ fails "String#chop! removes the final carriage return"
16
+ fails "String#chop! removes the final newline"
17
+ fails "String#chop! removes the final carriage return, newline"
18
+ fails "String#chop! removes the carrige return, newline if they are the only characters"
19
+ fails "String#chop! does not remove more than the final carriage return, newline"
20
+ fails "String#chop! returns self if modifications were made"
21
+ fails "String#chop! returns nil when called on an empty string"
22
+ fails "String#chop! raises a RuntimeError on a frozen instance that is modified"
23
+ fails "String#chop! raises a RuntimeError on a frozen instance that would not be modified"
9
24
  end
@@ -1,58 +1,72 @@
1
1
  opal_filter 'tainted' do
2
- fails "Array#clear keeps tainted status"
3
- fails "Array#compact! keeps tainted status even if all elements are removed"
4
- fails "Array#delete_at keeps tainted status"
5
- fails "Array#delete_if keeps tainted status"
6
- fails "Array#delete keeps tainted status"
7
- fails "Array#shift passed a number n as an argument keeps taint status"
8
- fails "Array#shift passed a number n as an argument returns an untainted array even if the array is tainted"
9
- fails "Array#pop passed a number n as an argument keeps taint status"
10
- fails "Array#pop passed a number n as an argument returns an untainted array even if the array is tainted"
11
- fails "Array#pop keeps taint status"
12
- fails "Array#+ does not get infected even if an original array is tainted"
2
+ fails "Kernel#to_s returns a tainted result if self is tainted"
3
+
4
+ fails "Array#* with a string with a tainted separator taints the result if the array has two or more elements"
5
+ fails "Array#* with a string with a tainted separator does not taint the result if the array has only one element"
6
+ fails "Array#* with a string with a tainted separator does not taint the result if the array is empty"
13
7
  fails "Array#* with an integer copies the taint status of the original array if the passed count is not 0"
14
8
  fails "Array#* with an integer copies the taint status of the original array even if the array is empty"
15
9
  fails "Array#* with an integer copies the taint status of the original array even if the passed count is 0"
16
- fails "Array#compact does not keep tainted status even if all elements are removed"
17
- fails "Array#map! keeps tainted status"
18
- fails "Array#map does not copy tainted status"
10
+
11
+ fails "Array#+ does not get infected even if an original array is tainted"
12
+
13
+ fails "Array#clear keeps tainted status"
14
+
19
15
  fails "Array#clone copies taint status from the original"
20
- fails "Array#collect! keeps tainted status"
16
+
21
17
  fails "Array#collect does not copy tainted status"
18
+
19
+ fails "Array#collect! keeps tainted status"
20
+
21
+ fails "Array#compact does not keep tainted status even if all elements are removed"
22
+
23
+ fails "Array#compact! keeps tainted status even if all elements are removed"
24
+
22
25
  fails "Array#concat keeps tainted status"
23
26
  fails "Array#concat keeps the tainted status of elements"
27
+
28
+ fails "Array#delete keeps tainted status"
29
+
30
+ fails "Array#delete_at keeps tainted status"
31
+
32
+ fails "Array#delete_if keeps tainted status"
33
+
24
34
  fails "Array#dup copies taint status from the original"
35
+
25
36
  fails "Array#inspect taints the result if an element is tainted"
26
37
  fails "Array#inspect does not taint the result if the Array is tainted but empty"
27
38
  fails "Array#inspect taints the result if the Array is non-empty and tainted"
28
- fails "Array#to_s taints the result if an element is tainted"
29
- fails "Array#to_s does not taint the result if the Array is tainted but empty"
30
- fails "Array#to_s taints the result if the Array is non-empty and tainted"
39
+
31
40
  fails "Array#join with a tainted separator taints the result if the array has two or more elements"
32
41
  fails "Array#join with a tainted separator does not taint the result if the array has only one element"
33
42
  fails "Array#join with a tainted separator does not taint the result if the array is empty"
34
43
  fails "Array#join taints the result if the result of coercing an element is tainted"
35
44
  fails "Array#join does not taint the result if the Array is tainted but empty"
36
45
  fails "Array#join taints the result if the Array is tainted and non-empty"
37
- fails "Array#* with a string with a tainted separator taints the result if the array has two or more elements"
38
- fails "Array#* with a string with a tainted separator does not taint the result if the array has only one element"
39
- fails "Array#* with a string with a tainted separator does not taint the result if the array is empty"
40
46
 
41
- fails "Hash#reject taints the resulting hash"
47
+ fails "Array#pop passed a number n as an argument keeps taint status"
48
+ fails "Array#pop passed a number n as an argument returns an untainted array even if the array is tainted"
49
+ fails "Array#pop keeps taint status"
42
50
 
43
- fails "Kernel#to_s returns a tainted result if self is tainted"
51
+ fails "Array#map! keeps tainted status"
52
+ fails "Array#map does not copy tainted status"
44
53
 
45
- fails "String#upcase taints result when self is tainted"
46
- fails "String#to_s taints the result when self is tainted"
47
- fails "String#to_str taints the result when self is tainted"
48
- fails "String#swapcase taints resulting string when self is tainted"
49
- fails "String#reverse taints the result if self is tainted"
54
+ fails "Array#shift passed a number n as an argument keeps taint status"
55
+ fails "Array#shift passed a number n as an argument returns an untainted array even if the array is tainted"
56
+
57
+ fails "Array#to_s taints the result if an element is tainted"
58
+ fails "Array#to_s does not taint the result if the Array is tainted but empty"
59
+ fails "Array#to_s taints the result if the Array is non-empty and tainted"
60
+
61
+ fails "Hash#reject taints the resulting hash"
50
62
 
51
- fails "Pathname.new is tainted if path is tainted"
52
- fails "String#downcase taints result when self is tainted"
53
63
  fails "String#capitalize taints resulting string when self is tainted"
64
+
65
+ fails "String#downcase taints result when self is tainted"
66
+
54
67
  fails "String#center with length, padding when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self"
55
68
  fails "String#center with length, padding taints result when self or padstr is tainted"
69
+
56
70
  fails "String#chomp when passed a String does not taint the result when the argument is tainted"
57
71
  fails "String#chomp when passed a String taints the result if self is tainted"
58
72
  fails "String#chomp when passed '\\n' taints the result if self is tainted"
@@ -60,4 +74,18 @@ opal_filter 'tainted' do
60
74
  fails "String#chomp when passed nil taints the result if self is tainted"
61
75
  fails "String#chomp when passed nil returns a copy of the String"
62
76
  fails "String#chomp when passed no argument taints the result if self is tainted"
77
+
78
+ fails "String#chop taints result when self is tainted"
79
+
80
+ fails "String#reverse taints the result if self is tainted"
81
+
82
+ fails "String#swapcase taints resulting string when self is tainted"
83
+
84
+ fails "String#to_s taints the result when self is tainted"
85
+
86
+ fails "String#to_str taints the result when self is tainted"
87
+
88
+ fails "String#upcase taints result when self is tainted"
89
+
90
+ fails "Pathname.new is tainted if path is tainted"
63
91
  end
@@ -1,41 +1,61 @@
1
1
  opal_filter "Object#trusted/untrusted" do
2
- fails "Array#pop passed a number n as an argument keeps untrusted status"
3
- fails "Array#pop passed a number n as an argument returns a trusted array even if the array is untrusted"
4
- fails "Array#pop keeps untrusted status"
2
+ fails "Kernel#to_s returns an untrusted result if self is untrusted"
3
+
5
4
  fails "Array#+ does not infected even if an original array is untrusted"
5
+
6
6
  fails "Array#* with an integer copies the untrusted status of the original array if the passed count is not 0"
7
7
  fails "Array#* with an integer copies the untrusted status of the original array even if the array is empty"
8
8
  fails "Array#* with an integer copies the untrusted status of the original array even if the passed count is 0"
9
+ fails "Array#* with a string with an untrusted separator untrusts the result if the array has two or more elements"
10
+ fails "Array#* with a string with an untrusted separator does not untrust the result if the array has only one element"
11
+ fails "Array#* with a string with an untrusted separator does not untrust the result if the array is empty"
12
+
9
13
  fails "Array#delete keeps untrusted status"
14
+
10
15
  fails "Array#delete_if keeps untrusted status"
16
+
11
17
  fails "Array#delete_at keeps untrusted status"
12
- fails "Array#compact! keeps untrusted status even if all elements are removed"
13
- fails "Array#compact does not keep untrusted status even if all elements are removed"
18
+
14
19
  fails "Array#clear keeps untrusted status"
15
- fails "Array#map does not copy untrusted status"
20
+
16
21
  fails "Array#clone copies untrusted status from the original"
17
- fails "Array#collect! keeps untrusted status"
22
+
18
23
  fails "Array#collect does not copy untrusted status"
24
+
25
+ fails "Array#compact does not keep untrusted status even if all elements are removed"
26
+
27
+ fails "Array#compact! keeps untrusted status even if all elements are removed"
28
+
29
+ fails "Array#collect! keeps untrusted status"
30
+
19
31
  fails "Array#concat keeps untrusted status"
20
32
  fails "Array#concat is not infected untrustedness by the other"
21
33
  fails "Array#concat keeps the untrusted status of elements"
34
+
22
35
  fails "Array#dup copies untrusted status from the original"
23
- fails "Array#map! keeps untrusted status"
36
+
24
37
  fails "Array#inspect untrusts the result if an element is untrusted"
25
38
  fails "Array#inspect does not untrust the result if the Array is untrusted but empty"
26
39
  fails "Array#inspect untrusts the result if the Array is untrusted"
27
- fails "Array#to_s untrusts the result if an element is untrusted"
28
- fails "Array#to_s does not untrust the result if the Array is untrusted but empty"
29
- fails "Array#to_s untrusts the result if the Array is untrusted"
40
+
30
41
  fails "Array#join with an untrusted separator untrusts the result if the array has two or more elements"
31
42
  fails "Array#join with an untrusted separator does not untrust the result if the array has only one element"
32
43
  fails "Array#join with an untrusted separator does not untrust the result if the array is empty"
33
44
  fails "Array#join untrusts the result if the result of coercing an element is untrusted"
34
45
  fails "Array#join does not untrust the result if the Array is untrusted but empty"
35
46
  fails "Array#join untrusts the result if the Array is untrusted and non-empty"
36
- fails "Array#* with a string with an untrusted separator untrusts the result if the array has two or more elements"
37
- fails "Array#* with a string with an untrusted separator does not untrust the result if the array has only one element"
38
- fails "Array#* with a string with an untrusted separator does not untrust the result if the array is empty"
39
47
 
40
- fails "Kernel#to_s returns an untrusted result if self is untrusted"
48
+ fails "Array#map does not copy untrusted status"
49
+
50
+ fails "Array#pop passed a number n as an argument keeps untrusted status"
51
+ fails "Array#pop passed a number n as an argument returns a trusted array even if the array is untrusted"
52
+ fails "Array#pop keeps untrusted status"
53
+
54
+ fails "Array#map! keeps untrusted status"
55
+
56
+ fails "Array#to_s untrusts the result if an element is untrusted"
57
+ fails "Array#to_s does not untrust the result if the Array is untrusted but empty"
58
+ fails "Array#to_s untrusts the result if the Array is untrusted"
59
+
60
+ fails "String#chop untrusts result when self is untrusted"
41
61
  end
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "The class keyword" do
4
- it "returns a plain s(:scope) when given an empty body" do
5
- opal_parse('class A; end').should == [:class, :A, nil, [:scope]]
4
+ it "returns an empty s(:block) when given an empty body" do
5
+ opal_parse('class A; end').should == [:class, :A, nil, [:block]]
6
6
  end
7
7
 
8
8
  it "does not place single expressions into a s(:block)" do
9
- opal_parse('class A; 1; end').should == [:class, :A, nil, [:scope, [:int, 1]]]
9
+ opal_parse('class A; 1; end').should == [:class, :A, nil, [:int, 1]]
10
10
  end
11
11
 
12
12
  it "adds multiple body expressions into a s(:block)" do
13
- opal_parse('class A; 1; 2; end').should == [:class, :A, nil, [:scope, [:block, [:int, 1], [:int, 2]]]]
13
+ opal_parse('class A; 1; 2; end').should == [:class, :A, nil, [:block, [:int, 1], [:int, 2]]]
14
14
  end
15
15
 
16
16
  it "uses nil as a placeholder when no superclass is given" do
@@ -3,21 +3,21 @@ require 'spec_helper'
3
3
  describe "The def keyword" do
4
4
  describe "for normal definitions" do
5
5
  it "should return s(:def)" do
6
- opal_parse("def a; end").should == [:def, nil, :a, [:args], [:scope, [:block, [:nil]]]]
6
+ opal_parse("def a; end").should == [:def, nil, :a, [:args], [:block, [:nil]]]
7
7
  end
8
8
 
9
9
  it "adds s(:nil) on an empty body" do
10
- opal_parse("def foo; end").last.should == [:scope, [:block, [:nil]]]
10
+ opal_parse("def foo; end").last.should == [:block, [:nil]]
11
11
  end
12
12
  end
13
13
 
14
14
  describe "for singleton definitions" do
15
15
  it "should return s(:def)" do
16
- opal_parse("def self.a; end").should == [:def, [:self], :a, [:args], [:scope, [:block, [:nil]]]]
16
+ opal_parse("def self.a; end").should == [:def, [:self], :a, [:args], [:block, [:nil]]]
17
17
  end
18
18
 
19
19
  it "adds s(:nil) on an empty body" do
20
- opal_parse("def self.foo; end").last.should == [:scope, [:block, [:nil]]]
20
+ opal_parse("def self.foo; end").last.should == [:block, [:nil]]
21
21
  end
22
22
  end
23
23
 
@@ -15,24 +15,24 @@ describe "An lvar" do
15
15
 
16
16
  describe "inside a def" do
17
17
  it "should created by a norm arg" do
18
- opal_parse("def a(b); b; end").should == [:def, nil, :a, [:args, :b], [:scope, [:block, [:lvar, :b]]]]
19
- opal_parse("def a(b, c); c; end").should == [:def, nil, :a, [:args, :b, :c], [:scope, [:block, [:lvar, :c]]]]
18
+ opal_parse("def a(b); b; end").should == [:def, nil, :a, [:args, :b], [:block, [:lvar, :b]]]
19
+ opal_parse("def a(b, c); c; end").should == [:def, nil, :a, [:args, :b, :c], [:block, [:lvar, :c]]]
20
20
  end
21
21
 
22
22
  it "should be created by an opt arg" do
23
- opal_parse("def a(b=10); b; end").should == [:def, nil, :a, [:args, :b, [:block, [:lasgn, :b, [:int, 10]]]], [:scope, [:block, [:lvar, :b]]]]
23
+ opal_parse("def a(b=10); b; end").should == [:def, nil, :a, [:args, :b, [:block, [:lasgn, :b, [:int, 10]]]], [:block, [:lvar, :b]]]
24
24
  end
25
25
 
26
26
  it "should be created by a rest arg" do
27
- opal_parse("def a(*b); b; end").should == [:def, nil, :a, [:args, :"*b"], [:scope, [:block, [:lvar, :b]]]]
27
+ opal_parse("def a(*b); b; end").should == [:def, nil, :a, [:args, :"*b"], [:block, [:lvar, :b]]]
28
28
  end
29
29
 
30
30
  it "should be created by a block arg" do
31
- opal_parse("def a(&b); b; end").should == [:def, nil, :a, [:args, :"&b"], [:scope, [:block, [:lvar, :b]]]]
31
+ opal_parse("def a(&b); b; end").should == [:def, nil, :a, [:args, :"&b"], [:block, [:lvar, :b]]]
32
32
  end
33
33
 
34
34
  it "should not be created from locals outside the def" do
35
- opal_parse("a = 10; def b; a; end").should == [:block, [:lasgn, :a, [:int, 10]], [:def, nil, :b, [:args], [:scope, [:block, [:call, nil, :a, [:arglist]]]]]]
35
+ opal_parse("a = 10; def b; a; end").should == [:block, [:lasgn, :a, [:int, 10]], [:def, nil, :b, [:args], [:block, [:call, nil, :a, [:arglist]]]]]
36
36
  end
37
37
  end
38
38
  end
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "The module keyword" do
4
- it "returns a plain s(:scope) when given an empty body" do
5
- opal_parse('module A; end').should == [:module, :A, [:scope]]
4
+ it "returns an empty s(:block) when given an empty body" do
5
+ opal_parse('module A; end').should == [:module, :A, [:block]]
6
6
  end
7
7
 
8
8
  it "does not place single expressions into a s(:block)" do
9
- opal_parse('module A; 1; end').should == [:module, :A, [:scope, [:int, 1]]]
9
+ opal_parse('module A; 1; end').should == [:module, :A, [:int, 1]]
10
10
  end
11
11
 
12
12
  it "adds multiple body expressions into a s(:block)" do
13
- opal_parse('module A; 1; 2; end').should == [:module, :A, [:scope, [:block, [:int, 1], [:int, 2]]]]
13
+ opal_parse('module A; 1; 2; end').should == [:module, :A, [:block, [:int, 1], [:int, 2]]]
14
14
  end
15
15
 
16
16
  it "should accept just a constant for the module name" do
@@ -6,11 +6,11 @@ describe "Singleton classes" do
6
6
  end
7
7
 
8
8
  it "does not place single expressions into an s(:block)" do
9
- opal_parse('class << A; 1; end')[2].should == [:scope, [:int, 1]]
9
+ opal_parse('class << A; 1; end')[2].should == [:int, 1]
10
10
  end
11
11
 
12
12
  it "adds multiple body expressions into a s(:block)" do
13
- opal_parse('class << A; 1; 2; end')[2].should == [:scope, [:block, [:int, 1], [:int, 2]]]
13
+ opal_parse('class << A; 1; 2; end')[2].should == [:block, [:int, 1], [:int, 2]]
14
14
  end
15
15
 
16
16
  it "should accept any expressions for singleton part" do
@@ -0,0 +1,33 @@
1
+ require 'native'
2
+
3
+ describe 'Native exposure' do
4
+ describe Class do
5
+ describe '#native_alias' do
6
+ it 'exposes a method to javascript' do
7
+ c = Class.new do
8
+ def ruby_method
9
+ :ruby
10
+ end
11
+
12
+ native_alias :rubyMethod, :ruby_method
13
+ end
14
+
15
+ `#{c.new}.rubyMethod()`.should == :ruby
16
+ end
17
+ end
18
+
19
+ describe '#native_class' do
20
+ it 'exposes a Class on the JS global object' do
21
+ c = Class.new do
22
+ def self.name
23
+ 'Pippo'
24
+ end
25
+
26
+ native_class
27
+ end
28
+
29
+ `Pippo`.should == c
30
+ end
31
+ end
32
+ end
33
+ end