opal 0.3.43 → 0.3.44
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +19 -0
- data/README.md +1 -0
- data/Rakefile +29 -19
- data/examples/native/Gemfile +3 -0
- data/examples/native/README.md +17 -0
- data/examples/native/app/app.rb +38 -0
- data/examples/native/config.ru +8 -0
- data/examples/native/index.html.erb +12 -0
- data/lib/opal/lexer.rb +5 -1
- data/lib/opal/parser.rb +36 -10
- data/lib/opal/processor.rb +10 -9
- data/lib/opal/server.rb +17 -7
- data/lib/opal/target_scope.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/opal/opal-browser/script_loader.rb +8 -13
- data/opal/opal.rb +23 -5
- data/opal/opal/array.rb +128 -14
- data/opal/opal/boolean.rb +1 -1
- data/opal/opal/class.rb +92 -18
- data/opal/opal/enumerable.rb +90 -0
- data/opal/opal/error.rb +1 -1
- data/opal/opal/hash.rb +2 -2
- data/opal/opal/kernel.rb +3 -3
- data/opal/opal/numeric.rb +1 -1
- data/opal/opal/proc.rb +1 -1
- data/opal/opal/regexp.rb +31 -31
- data/opal/opal/runtime.js +181 -69
- data/opal/opal/string.rb +561 -40
- data/opal/opal/time.rb +1 -1
- data/opal/rbconfig.rb +17 -3
- data/opal/strscan.rb +41 -5
- data/spec/opal/class/new_spec.rb +27 -0
- data/spec/opal/native_spec.rb +127 -0
- data/spec/ospec/runner.rb +0 -2
- data/spec/parser/strscan/get_byte_spec.rb +29 -0
- data/spec/parser/strscan/skip_spec.rb +40 -0
- data/spec/rubyspec/core/array/each_spec.rb +1 -1
- data/spec/rubyspec/core/array/intersection_spec.rb +5 -0
- data/spec/rubyspec/core/array/max_spec.rb +32 -0
- data/spec/rubyspec/core/array/min_spec.rb +32 -0
- data/spec/rubyspec/core/array/minus_spec.rb +7 -5
- data/spec/rubyspec/core/array/multiply_spec.rb +1 -1
- data/spec/rubyspec/core/array/plus_spec.rb +1 -1
- data/spec/rubyspec/core/array/pop_spec.rb +1 -1
- data/spec/rubyspec/core/array/push_spec.rb +1 -1
- data/spec/rubyspec/core/array/rassoc_spec.rb +1 -1
- data/spec/rubyspec/core/array/reject_spec.rb +2 -2
- data/spec/rubyspec/core/array/reverse_each_spec.rb +2 -2
- data/spec/rubyspec/core/array/rindex_spec.rb +2 -2
- data/spec/rubyspec/core/array/select_spec.rb +1 -1
- data/spec/rubyspec/core/array/shift_spec.rb +1 -1
- data/spec/rubyspec/core/array/slice_spec.rb +1 -1
- data/spec/rubyspec/core/array/sort_spec.rb +15 -15
- data/spec/rubyspec/core/array/to_a_spec.rb +1 -1
- data/spec/rubyspec/core/array/to_ary_spec.rb +1 -1
- data/spec/rubyspec/core/array/uniq_spec.rb +1 -1
- data/spec/rubyspec/core/array/unshift_spec.rb +1 -1
- data/spec/rubyspec/core/array/zip_spec.rb +1 -1
- data/spec/rubyspec/core/enumerable/select_spec.rb +4 -1
- data/spec/rubyspec/core/module/const_defined_spec.rb +86 -0
- data/spec/rubyspec/core/module/const_get_spec.rb +55 -3
- data/spec/rubyspec/core/module/const_set_spec.rb +2 -2
- data/spec/rubyspec/core/module/constants_spec.rb +49 -0
- data/spec/rubyspec/core/regexp/match_spec.rb +66 -1
- data/spec/rubyspec/core/string/center_spec.rb +71 -0
- data/spec/rubyspec/core/string/chomp_spec.rb +6 -1
- data/spec/rubyspec/core/string/clone_spec.rb +8 -0
- data/spec/rubyspec/core/string/dup_spec.rb +8 -0
- data/spec/rubyspec/core/string/end_with_spec.rb +5 -1
- data/spec/rubyspec/core/string/gsub_spec.rb +15 -1
- data/spec/rubyspec/core/string/lines_spec.rb +9 -0
- data/spec/rubyspec/core/string/ljust_spec.rb +17 -0
- data/spec/rubyspec/core/string/match_spec.rb +25 -3
- data/spec/rubyspec/core/string/rindex_spec.rb +50 -0
- data/spec/rubyspec/core/string/rjust_spec.rb +17 -0
- data/spec/rubyspec/core/string/scan_spec.rb +66 -0
- data/spec/rubyspec/core/string/sub_spec.rb +17 -1
- data/spec/rubyspec/core/string/tr_s_spec.rb +31 -0
- data/spec/rubyspec/core/string/tr_spec.rb +31 -0
- data/spec/rubyspec/fixtures/constants.rb +6 -0
- data/spec/rubyspec/language/class_spec.rb +4 -8
- data/spec/rubyspec/language/numbers_spec.rb +10 -4
- data/spec/rubyspec/language/predefined_spec.rb +69 -2
- data/spec/rubyspec/library/rbconfig/config_spec.rb +47 -0
- data/spec/rubyspec/spec_helper.rb +6 -0
- metadata +46 -25
- data/opal/opal-eventable.rb +0 -26
- data/opal/opal/native.rb +0 -115
- data/spec/opal/eventable_spec.rb +0 -75
- data/spec/opal/native/element_reference_spec.rb +0 -40
- data/spec/opal/native/equal_spec.rb +0 -17
- data/spec/opal/native/fixtures/classes.rb +0 -27
- data/spec/opal/native/global_spec.rb +0 -12
- data/spec/opal/native/initialize_spec.rb +0 -8
- data/spec/opal/native/method_missing_spec.rb +0 -53
- data/spec/opal/native/to_native_spec.rb +0 -8
- data/spec/rubyspec/core/string/demodulize_spec.rb +0 -10
- data/spec/rubyspec/core/string/underscore_spec.rb +0 -17
data/opal/opal-eventable.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# A simple event registering/triggering module to mix into classes.
|
2
|
-
# Events are stored in the `@events` ivar.
|
3
|
-
module Eventable
|
4
|
-
|
5
|
-
# Register a handler for the given event name.
|
6
|
-
#
|
7
|
-
# obj.on(:foo) { puts "foo was called" }
|
8
|
-
#
|
9
|
-
# @param [String, Symbol] name event name
|
10
|
-
def on(name, &handler)
|
11
|
-
@events ||= Hash.new { |hash, key| hash[key] = [] }
|
12
|
-
@events[name] << handler
|
13
|
-
end
|
14
|
-
|
15
|
-
# Trigger the given event name and passes all args to each handler
|
16
|
-
# for this event.
|
17
|
-
#
|
18
|
-
# obj.trigger(:foo)
|
19
|
-
# obj.trigger(:foo, 1, 2, 3)
|
20
|
-
#
|
21
|
-
# @param [String, Symbol] name event name to trigger
|
22
|
-
def trigger(name, *args)
|
23
|
-
@events ||= Hash.new { |hash, key| hash[key] = [] }
|
24
|
-
@events[name].each { |handler| handler.call(*args) }
|
25
|
-
end
|
26
|
-
end
|
data/opal/opal/native.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
class Native < BasicObject
|
2
|
-
def self.global
|
3
|
-
@global ||= Native.new(`Opal.global`)
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.[](key)
|
7
|
-
global[key]
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(native)
|
11
|
-
%x{
|
12
|
-
if (#{native} == null) {
|
13
|
-
#{ Kernel.raise "null or undefined passed to Native" };
|
14
|
-
}
|
15
|
-
}
|
16
|
-
|
17
|
-
@native = native
|
18
|
-
end
|
19
|
-
|
20
|
-
def each(&block)
|
21
|
-
%x{
|
22
|
-
var n = #{@native}, value;
|
23
|
-
|
24
|
-
for (var key in n) {
|
25
|
-
value = n[key];
|
26
|
-
|
27
|
-
if (value == null) {
|
28
|
-
value = nil;
|
29
|
-
}
|
30
|
-
else if (typeof(value) === 'object') {
|
31
|
-
if (!value._klass) {
|
32
|
-
value = #{Native.new `value`};
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
block(key, value);
|
37
|
-
}
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
def key? name
|
42
|
-
`#{@native}[name] != null`
|
43
|
-
end
|
44
|
-
|
45
|
-
def method_missing(symbol, *args, &block)
|
46
|
-
native = @native
|
47
|
-
|
48
|
-
%x{
|
49
|
-
var prop = #{native}[#{symbol}];
|
50
|
-
|
51
|
-
if (typeof(prop) === 'function') {
|
52
|
-
prop = prop.apply(#{native}, #{args});
|
53
|
-
|
54
|
-
if (typeof(prop) === 'object' || typeof(prop) === 'function') {
|
55
|
-
if (!prop._klass) {
|
56
|
-
return #{ Native.new `prop` };
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
return prop;
|
61
|
-
}
|
62
|
-
else if (symbol.charAt(symbol.length - 1) === '=') {
|
63
|
-
prop = symbol.slice(0, symbol.length - 1);
|
64
|
-
return #{native}[prop] = args[0];
|
65
|
-
}
|
66
|
-
else if (prop != null) {
|
67
|
-
if (typeof(prop) === 'object') {
|
68
|
-
if (!prop._klass) {
|
69
|
-
return #{Native.new `prop`};
|
70
|
-
}
|
71
|
-
}
|
72
|
-
return prop;
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
nil
|
77
|
-
end
|
78
|
-
|
79
|
-
def [](key)
|
80
|
-
%x{
|
81
|
-
var value = #{@native}[key];
|
82
|
-
|
83
|
-
if (value == null) return #{nil};
|
84
|
-
|
85
|
-
return value;
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
def ==(other)
|
90
|
-
`#{@native} === #{other}.native`
|
91
|
-
end
|
92
|
-
|
93
|
-
def to_a
|
94
|
-
%x{
|
95
|
-
var n = #{@native}, result;
|
96
|
-
|
97
|
-
if (n.length) {
|
98
|
-
result = [];
|
99
|
-
|
100
|
-
for (var i = 0, len = n.length; i < len; i++) {
|
101
|
-
result.push(#{ Native.new `n[i]` });
|
102
|
-
}
|
103
|
-
}
|
104
|
-
else {
|
105
|
-
result = [n];
|
106
|
-
}
|
107
|
-
|
108
|
-
return result;
|
109
|
-
}
|
110
|
-
end
|
111
|
-
|
112
|
-
def to_native
|
113
|
-
@native
|
114
|
-
end
|
115
|
-
end
|
data/spec/opal/eventable_spec.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
require "opal-eventable"
|
2
|
-
|
3
|
-
class EventableSpec
|
4
|
-
include Eventable
|
5
|
-
|
6
|
-
attr_reader :events
|
7
|
-
end
|
8
|
-
|
9
|
-
describe Eventable do
|
10
|
-
describe "#on" do
|
11
|
-
before do
|
12
|
-
@obj = EventableSpec.new
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should register event handlers for given name" do
|
16
|
-
handler = Proc.new {}
|
17
|
-
@obj.on(:foo, &handler)
|
18
|
-
@obj.events[:foo].should == [handler]
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#trigger" do
|
23
|
-
before do
|
24
|
-
@obj = EventableSpec.new
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should call handler" do
|
28
|
-
called = false
|
29
|
-
|
30
|
-
@obj.on(:foo) { called = true }
|
31
|
-
called.should == false
|
32
|
-
|
33
|
-
@obj.trigger(:foo)
|
34
|
-
called.should == true
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should pass all arguments to handler" do
|
38
|
-
args = nil
|
39
|
-
@obj.on(:foo) { |*a| args = a }
|
40
|
-
|
41
|
-
@obj.trigger(:foo)
|
42
|
-
args.should == []
|
43
|
-
|
44
|
-
@obj.trigger(:foo, 1)
|
45
|
-
args.should == [1]
|
46
|
-
|
47
|
-
@obj.trigger(:foo, 1, 2, 3)
|
48
|
-
args.should == [1, 2, 3]
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should allow multiple different events to be registered" do
|
52
|
-
result = []
|
53
|
-
@obj.on(:foo) { result << :foo }
|
54
|
-
@obj.on(:bar) { result << :bar }
|
55
|
-
|
56
|
-
@obj.trigger(:foo)
|
57
|
-
result.should == [:foo]
|
58
|
-
|
59
|
-
@obj.trigger(:bar)
|
60
|
-
result.should == [:foo, :bar]
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should allow multiple handlers for an event" do
|
64
|
-
count = 0
|
65
|
-
|
66
|
-
@obj.on(:foo) { count += 1 }
|
67
|
-
@obj.on(:foo) { count += 1 }
|
68
|
-
@obj.on(:foo) { count += 1 }
|
69
|
-
@obj.on(:foo) { count += 1 }
|
70
|
-
@obj.trigger(:foo)
|
71
|
-
|
72
|
-
count.should == 4
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "Native#[]" do
|
4
|
-
before do
|
5
|
-
%x{
|
6
|
-
var obj = {
|
7
|
-
foo: 'FOO',
|
8
|
-
|
9
|
-
str: 'LOL',
|
10
|
-
num: 42,
|
11
|
-
on: true,
|
12
|
-
off: false
|
13
|
-
};
|
14
|
-
}
|
15
|
-
|
16
|
-
@native = Native.new(`obj`)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "returns a value from the native object" do
|
20
|
-
@native['foo'].should == "FOO"
|
21
|
-
end
|
22
|
-
|
23
|
-
it "returns nil for a key not existing on native object" do
|
24
|
-
@native['bar'].should be_nil
|
25
|
-
end
|
26
|
-
|
27
|
-
it "returns direct values for strings, numerics and booleans" do
|
28
|
-
@native['str'].should == 'LOL'
|
29
|
-
@native['num'].should == 42
|
30
|
-
@native['on'].should == true
|
31
|
-
@native['off'].should == false
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "Native.[]" do
|
36
|
-
it "accesses properties on Native.global" do
|
37
|
-
Native.global.some_random_property_we_should_remove = 42
|
38
|
-
Native['some_random_property_we_should_remove'].should == 42
|
39
|
-
end
|
40
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
|
-
describe "Native#==" do
|
5
|
-
it "returns true if the wrapped objects are `===` to each other" do
|
6
|
-
%x{
|
7
|
-
var obj1 = {}, obj2 = {};
|
8
|
-
}
|
9
|
-
|
10
|
-
a = Native.new(`obj1`)
|
11
|
-
b = Native.new(`obj1`)
|
12
|
-
c = Native.new(`obj2`)
|
13
|
-
|
14
|
-
(a == b).should be_true
|
15
|
-
(a == c).should be_false
|
16
|
-
end
|
17
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module NativeSpecs
|
2
|
-
%x{
|
3
|
-
var obj = {
|
4
|
-
property: 42,
|
5
|
-
|
6
|
-
simple: function() {
|
7
|
-
return 'foo';
|
8
|
-
},
|
9
|
-
|
10
|
-
context_check: function() {
|
11
|
-
return this === obj;
|
12
|
-
},
|
13
|
-
|
14
|
-
check_args: function(a, b, c) {
|
15
|
-
return [a, b, c];
|
16
|
-
},
|
17
|
-
|
18
|
-
array: [1, 2, 3, 4],
|
19
|
-
|
20
|
-
child_object: {
|
21
|
-
grand_child: 100
|
22
|
-
}
|
23
|
-
};
|
24
|
-
}
|
25
|
-
|
26
|
-
OBJ = Native.new(`obj`)
|
27
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
|
-
describe "Native#global" do
|
5
|
-
it "is an instance of Native" do
|
6
|
-
(Native === Native.global).should be_true
|
7
|
-
end
|
8
|
-
|
9
|
-
it "wraps Opal.global" do
|
10
|
-
(Native.global == Native.new(`Opal.global`)).should be_true
|
11
|
-
end
|
12
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
require File.expand_path('../fixtures/classes', __FILE__)
|
3
|
-
|
4
|
-
describe "Native#method_missing" do
|
5
|
-
before do
|
6
|
-
@obj = NativeSpecs::OBJ
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "accessing a null/undefined property" do
|
10
|
-
it "returns nil" do
|
11
|
-
@obj.doesnt_exist.should == nil
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "with a mid ending with '='" do
|
16
|
-
it "sets the value on the property" do
|
17
|
-
@obj.set_property = 100
|
18
|
-
@obj.set_property.should == 100
|
19
|
-
|
20
|
-
@obj.set_property = [1, 2, 3]
|
21
|
-
@obj.set_property.should == [1, 2, 3]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "accessing a property" do
|
26
|
-
it "returns values from the native object" do
|
27
|
-
@obj.property.should == 42
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns an array without wrapping" do
|
31
|
-
@obj.array.should == [1, 2, 3, 4]
|
32
|
-
end
|
33
|
-
|
34
|
-
it "returns the property in a new Native object if a js object" do
|
35
|
-
res = @obj.child_object
|
36
|
-
(Native === res).should be_true
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "accessing a function property" do
|
41
|
-
it "forwards methods to wrapped object as native function calls" do
|
42
|
-
@obj.simple.should == "foo"
|
43
|
-
end
|
44
|
-
|
45
|
-
it "calls functions with native object as context" do
|
46
|
-
@obj.context_check.should be_true
|
47
|
-
end
|
48
|
-
|
49
|
-
it "passes each argument to native function" do
|
50
|
-
@obj.check_args(1, 2, 3).should == [1, 2, 3]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
describe "String#demodulize" do
|
2
|
-
it "removes any preceding module name from the string" do
|
3
|
-
"Foo::Bar".demodulize.should == "Bar"
|
4
|
-
"Foo::Bar::Baz".demodulize.should == "Baz"
|
5
|
-
end
|
6
|
-
|
7
|
-
it "has no affect on strings with no module seperator" do
|
8
|
-
"SomeClassName".demodulize.should == "SomeClassName"
|
9
|
-
end
|
10
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
describe "String#underscore" do
|
2
|
-
it "replaces '-' in dasherized strings with underscores" do
|
3
|
-
"well-hello-there".underscore.should == "well_hello_there"
|
4
|
-
end
|
5
|
-
|
6
|
-
it "converts single all-upcase strings into lowercase" do
|
7
|
-
"OMG".underscore.should == "omg"
|
8
|
-
end
|
9
|
-
|
10
|
-
it "splits word bounderies and seperates using underscore" do
|
11
|
-
"AdamBeynon".underscore.should == "adam_beynon"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "does not split when 2 or more capitalized letters together" do
|
15
|
-
"HTMLParser".underscore.should == "html_parser"
|
16
|
-
end
|
17
|
-
end
|