opal 0.3.16 → 0.3.17
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +8 -7
- data/README.md +21 -13
- data/Rakefile +64 -78
- data/bin/opal +18 -29
- data/core/alpha.rb +2 -9
- data/core/array.rb +106 -50
- data/core/basic_object.rb +10 -8
- data/core/boolean.rb +2 -0
- data/core/class.rb +25 -13
- data/core/comparable.rb +6 -6
- data/core/enumerable.rb +90 -94
- data/core/enumerator.rb +3 -3
- data/core/hash.rb +86 -46
- data/core/kernel.rb +55 -39
- data/core/load_order +2 -5
- data/core/match_data.rb +1 -1
- data/core/module.rb +45 -20
- data/core/nil_class.rb +6 -2
- data/core/numeric.rb +20 -10
- data/core/proc.rb +2 -2
- data/core/range.rb +72 -13
- data/core/regexp.rb +5 -3
- data/core/runtime.js +228 -287
- data/core/string.rb +345 -37
- data/core/top_self.rb +1 -1
- data/lib/opal.rb +13 -91
- data/lib/opal/builder.rb +47 -120
- data/lib/opal/builder_task.rb +74 -0
- data/lib/opal/{parser/grammar.rb → grammar.rb} +1094 -1083
- data/lib/opal/{parser/grammar.y → grammar.y} +7 -0
- data/lib/opal/{parser/lexer.rb → lexer.rb} +32 -11
- data/lib/opal/{parser/parser.rb → parser.rb} +232 -238
- data/lib/opal/{parser/scope.rb → scope.rb} +72 -9
- data/lib/opal/version.rb +2 -3
- data/opal.gemspec +1 -2
- data/{core_spec → spec}/core/array/allocate_spec.rb +1 -3
- data/{core_spec → spec}/core/array/append_spec.rb +1 -4
- data/{core_spec → spec}/core/array/assoc_spec.rb +1 -4
- data/{core_spec → spec}/core/array/at_spec.rb +1 -3
- data/{core_spec → spec}/core/array/clear_spec.rb +1 -3
- data/spec/core/array/clone_spec.rb +15 -0
- data/{core_spec/core/array/shared/collect.rb → spec/core/array/collect_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/compact_spec.rb +1 -3
- data/{core_spec → spec}/core/array/concat_spec.rb +1 -3
- data/{core_spec → spec}/core/array/constructor_spec.rb +9 -3
- data/{core_spec → spec}/core/array/count_spec.rb +1 -3
- data/{core_spec → spec}/core/array/delete_at_spec.rb +1 -4
- data/{core_spec → spec}/core/array/delete_if_spec.rb +1 -4
- data/{core_spec → spec}/core/array/delete_spec.rb +1 -4
- data/{core_spec → spec}/core/array/each_index_spec.rb +1 -4
- data/{core_spec → spec}/core/array/each_spec.rb +1 -4
- data/{core_spec → spec}/core/array/element_reference_spec.rb +74 -4
- data/{core_spec → spec}/core/array/empty_spec.rb +1 -4
- data/{core_spec/core/array/shared/eql.rb → spec/core/array/eql_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/fetch_spec.rb +1 -4
- data/{core_spec → spec}/core/array/first_spec.rb +1 -3
- data/{core_spec → spec}/core/array/flatten_spec.rb +1 -3
- data/{core_spec → spec}/core/array/include_spec.rb +1 -3
- data/{core_spec → spec}/core/array/insert_spec.rb +1 -4
- data/{core_spec → spec}/core/array/last_spec.rb +1 -4
- data/{core_spec/core/array/shared/length.rb → spec/core/array/length_spec.rb} +1 -1
- data/spec/core/array/map_spec.rb +53 -0
- data/{core_spec → spec}/core/array/plus_spec.rb +1 -4
- data/{core_spec → spec}/core/array/pop_spec.rb +1 -4
- data/{core_spec → spec}/core/array/push_spec.rb +1 -4
- data/{core_spec → spec}/core/array/rassoc_spec.rb +1 -4
- data/{core_spec → spec}/core/array/reject_spec.rb +1 -4
- data/{core_spec/core/array/shared/replace.rb → spec/core/array/replace_spec.rb} +1 -1
- data/{core_spec → spec}/core/array/reverse_each_spec.rb +1 -4
- data/{core_spec → spec}/core/array/reverse_spec.rb +1 -4
- data/spec/core/array/size_spec.rb +6 -0
- data/spec/core/array/to_ary_spec.rb +6 -0
- data/spec/core/array/uniq_spec.rb +22 -0
- data/spec/core/array/zip_spec.rb +20 -0
- data/{core_spec → spec}/core/class/new_spec.rb +1 -4
- data/{core_spec → spec}/core/enumerable/all_spec.rb +1 -4
- data/{core_spec → spec}/core/enumerable/any_spec.rb +1 -4
- data/{core_spec/core/enumerable/shared/collect.rb → spec/core/enumerable/collect_spec.rb} +1 -1
- data/{core_spec → spec}/core/enumerable/count_spec.rb +2 -5
- data/{core_spec → spec}/core/enumerable/fixtures/classes.rb +1 -2
- data/{core_spec → spec}/core/false/and_spec.rb +1 -3
- data/{core_spec → spec}/core/false/inspect_spec.rb +1 -3
- data/{core_spec → spec}/core/false/or_spec.rb +1 -3
- data/{core_spec → spec}/core/false/to_s_spec.rb +1 -3
- data/{core_spec → spec}/core/false/xor_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/allocate_spec.rb +1 -3
- data/spec/core/hash/assoc_spec.rb +25 -0
- data/{core_spec → spec}/core/hash/clear_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/clone_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/default_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/delete_if_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/element_reference_spec.rb +1 -3
- data/{core_spec → spec}/core/hash/element_set_spec.rb +1 -3
- data/spec/core/hash/merge_spec.rb +37 -0
- data/{core_spec → spec}/core/hash/new_spec.rb +1 -3
- data/{core_spec → spec}/core/matchdata/to_a_spec.rb +1 -3
- data/{core_spec → spec}/core/nil/and_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/inspect_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/nil_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/or_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_a_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_f_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_i_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/to_s_spec.rb +1 -4
- data/{core_spec → spec}/core/nil/xor_spec.rb +1 -4
- data/{core_spec → spec}/core/numeric/equal_value_spec.rb +1 -3
- data/{core_spec → spec}/core/regexp/match_spec.rb +10 -3
- data/{core_spec → spec}/core/symbol/to_proc_spec.rb +1 -3
- data/{core_spec → spec}/core/true/and_spec.rb +1 -3
- data/{core_spec → spec}/core/true/inspect_spec.rb +1 -3
- data/{core_spec → spec}/core/true/or_spec.rb +1 -3
- data/{core_spec → spec}/core/true/to_s_spec.rb +1 -3
- data/{core_spec → spec}/core/true/xor_spec.rb +1 -3
- data/spec/index.html +11 -0
- data/{core_spec → spec}/language/alias_spec.rb +1 -3
- data/{core_spec → spec}/language/and_spec.rb +1 -4
- data/{core_spec → spec}/language/array_spec.rb +1 -4
- data/{core_spec → spec}/language/block_spec.rb +20 -3
- data/{core_spec → spec}/language/break_spec.rb +40 -3
- data/{core_spec → spec}/language/case_spec.rb +1 -4
- data/{core_spec → spec}/language/defined_spec.rb +9 -3
- data/{core_spec → spec}/language/ensure_spec.rb +38 -3
- data/{core_spec → spec}/language/hash_spec.rb +1 -3
- data/{core_spec → spec}/language/if_spec.rb +1 -4
- data/{core_spec → spec}/language/loop_spec.rb +1 -3
- data/spec/language/metaclass_spec.rb +13 -0
- data/{core_spec → spec}/language/next_spec.rb +47 -3
- data/{core_spec → spec}/language/or_spec.rb +1 -4
- data/{core_spec → spec}/language/predefined_spec.rb +1 -3
- data/{core_spec/language/regexp/interpolation_spec.rb → spec/language/regexp_spec.rb} +6 -3
- data/{core_spec → spec}/language/send_spec.rb +38 -4
- data/spec/language/singleton_class_spec.rb +31 -0
- data/spec/language/super_spec.rb +188 -0
- data/{core_spec → spec}/language/symbol_spec.rb +1 -3
- data/{core_spec → spec}/language/undef_spec.rb +1 -3
- data/{core_spec → spec}/language/unless_spec.rb +1 -4
- data/{core_spec → spec}/language/until_spec.rb +1 -3
- data/{core_spec → spec}/language/variables_spec.rb +1 -3
- data/{core_spec → spec}/language/while_spec.rb +1 -3
- data/{spec → test}/builder/build_source_spec.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/adam.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/a.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/wow/b.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/bar/wow/cow/c.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/beynon.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/charles.js +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/a.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/b.rb +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/x.js +0 -0
- data/{spec → test}/builder/fixtures/build_source/foo/y.js +0 -0
- data/{spec → test}/grammar/alias_spec.rb +0 -0
- data/{spec → test}/grammar/and_spec.rb +0 -0
- data/{spec → test}/grammar/array_spec.rb +0 -0
- data/{spec → test}/grammar/attrasgn_spec.rb +0 -0
- data/{spec → test}/grammar/begin_spec.rb +0 -0
- data/{spec → test}/grammar/block_spec.rb +0 -0
- data/{spec → test}/grammar/break_spec.rb +0 -0
- data/{spec → test}/grammar/call_spec.rb +0 -0
- data/{spec → test}/grammar/class_spec.rb +0 -0
- data/{spec → test}/grammar/const_spec.rb +0 -0
- data/{spec → test}/grammar/cvar_spec.rb +0 -0
- data/{spec → test}/grammar/def_spec.rb +0 -0
- data/{spec → test}/grammar/false_spec.rb +0 -0
- data/{spec → test}/grammar/file_spec.rb +0 -0
- data/{spec → test}/grammar/gvar_spec.rb +0 -0
- data/{spec → test}/grammar/hash_spec.rb +0 -0
- data/{spec → test}/grammar/iasgn_spec.rb +0 -0
- data/{spec → test}/grammar/if_spec.rb +0 -0
- data/{spec → test}/grammar/iter_spec.rb +0 -0
- data/{spec → test}/grammar/ivar_spec.rb +0 -0
- data/{spec → test}/grammar/lasgn_spec.rb +0 -0
- data/{spec → test}/grammar/line_spec.rb +0 -0
- data/{spec → test}/grammar/lvar_spec.rb +0 -0
- data/{spec → test}/grammar/masgn_spec.rb +0 -0
- data/{spec → test}/grammar/module_spec.rb +0 -0
- data/{spec → test}/grammar/nil_spec.rb +0 -0
- data/{spec → test}/grammar/not_spec.rb +0 -0
- data/{spec → test}/grammar/op_asgn1_spec.rb +0 -0
- data/{spec → test}/grammar/op_asgn2_spec.rb +0 -0
- data/{spec → test}/grammar/or_spec.rb +0 -0
- data/{spec → test}/grammar/return_spec.rb +0 -0
- data/{spec → test}/grammar/sclass_spec.rb +0 -0
- data/{spec → test}/grammar/self_spec.rb +0 -0
- data/{spec → test}/grammar/str_spec.rb +0 -0
- data/{spec → test}/grammar/super_spec.rb +0 -0
- data/{spec → test}/grammar/true_spec.rb +0 -0
- data/{spec → test}/grammar/undef_spec.rb +0 -0
- data/{spec → test}/grammar/unless_spec.rb +0 -0
- data/{spec → test}/grammar/while_spec.rb +0 -0
- data/{spec → test}/grammar/xstr_spec.rb +0 -0
- data/{spec → test}/grammar/yield_spec.rb +0 -0
- data/{spec → test}/spec_helper.rb +0 -0
- metadata +330 -264
- data/core/debug.js +0 -59
- data/core/debug.rb +0 -35
- data/core/dir.rb +0 -90
- data/core/file.rb +0 -83
- data/core/gemlib.rb +0 -30
- data/core/io.rb +0 -44
- data/core_spec/README.md +0 -34
- data/core_spec/core/array/collect_spec.rb +0 -3
- data/core_spec/core/array/element_set_spec.rb +0 -7
- data/core_spec/core/array/eql_spec.rb +0 -3
- data/core_spec/core/array/equal_value_spec.rb +0 -3
- data/core_spec/core/array/fixtures/classes.rb +0 -8
- data/core_spec/core/array/length_spec.rb +0 -3
- data/core_spec/core/array/map_spec.rb +0 -3
- data/core_spec/core/array/replace_spec.rb +0 -3
- data/core_spec/core/enumerable/collect_spec.rb +0 -3
- data/core_spec/core/enumerable/detect_spec.rb +0 -3
- data/core_spec/core/enumerable/find_spec.rb +0 -3
- data/core_spec/core/enumerable/first_spec.rb +0 -3
- data/core_spec/core/enumerable/shared/entries.rb +0 -7
- data/core_spec/core/enumerable/shared/find.rb +0 -49
- data/core_spec/core/enumerable/shared/take.rb +0 -31
- data/core_spec/core/enumerable/to_a_spec.rb +0 -7
- data/core_spec/core/hash/assoc_spec.rb +0 -29
- data/core_spec/core/object/is_a_spec.rb +0 -2
- data/core_spec/core/object/shared/kind_of.rb +0 -0
- data/core_spec/core/regexp/shared/match.rb +0 -11
- data/core_spec/language/fixtures/block.rb +0 -19
- data/core_spec/language/fixtures/break.rb +0 -39
- data/core_spec/language/fixtures/defined.rb +0 -9
- data/core_spec/language/fixtures/ensure.rb +0 -37
- data/core_spec/language/fixtures/next.rb +0 -46
- data/core_spec/language/fixtures/send.rb +0 -36
- data/core_spec/language/fixtures/super.rb +0 -43
- data/core_spec/language/regexp_spec.rb +0 -7
- data/core_spec/language/string_spec.rb +0 -4
- data/core_spec/language/super_spec.rb +0 -18
- data/core_spec/language/versions/hash_1.9.rb +0 -20
- data/core_spec/opal/opal/defined_spec.rb +0 -15
- data/core_spec/opal/opal/function_spec.rb +0 -11
- data/core_spec/opal/opal/native_spec.rb +0 -16
- data/core_spec/opal/opal/null_spec.rb +0 -10
- data/core_spec/opal/opal/number_spec.rb +0 -11
- data/core_spec/opal/opal/object_spec.rb +0 -16
- data/core_spec/opal/opal/string_spec.rb +0 -11
- data/core_spec/opal/opal/typeof_spec.rb +0 -9
- data/core_spec/opal/opal/undefined_spec.rb +0 -10
- data/core_spec/opal/true/case_compare_spec.rb +0 -12
- data/core_spec/opal/true/class_spec.rb +0 -10
- data/core_spec/release_runner.html +0 -17
- data/core_spec/runner.html +0 -16
- data/core_spec/spec_helper.rb +0 -23
- data/lib/opal/context.rb +0 -269
- data/lib/opal/dependency_builder.rb +0 -133
- data/lib/opal/environment.rb +0 -87
- data/lib/opal/parser/sexp.rb +0 -17
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "Opal.defined?" do
|
4
|
-
it "should return nil when given `undefined`" do
|
5
|
-
Opal.defined?(`undefined`).should be_nil
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should return the type of object for anything else" do
|
9
|
-
Opal.defined?("wow").should == 'string'
|
10
|
-
Opal.defined?(42).should == 'number'
|
11
|
-
Opal.defined?(Object.new).should == 'object'
|
12
|
-
Opal.defined?(nil).should == 'object'
|
13
|
-
Opal.defined?(`null`).should == 'object'
|
14
|
-
end
|
15
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "Opal.function?" do
|
4
|
-
it "returns true if the object is a function, false otherwise" do
|
5
|
-
Opal.function?(proc do; end).should be_true
|
6
|
-
Opal.function?(`function(){}`).should be_true
|
7
|
-
Opal.function?(nil).should be_false
|
8
|
-
Opal.function?(Object.new).should be_false
|
9
|
-
Opal.function?(Proc).should be_false
|
10
|
-
end
|
11
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "Opal.native?" do
|
4
|
-
it "returns true if the object is not a ruby object, false if it is" do
|
5
|
-
Opal.native?(`{}`).should be_true
|
6
|
-
Opal.native?(`new Object()`).should be_true
|
7
|
-
Opal.native?(`null`).should be_true
|
8
|
-
Opal.native?(`undefined`).should be_true
|
9
|
-
|
10
|
-
Opal.native?(Object.new).should be_false
|
11
|
-
Opal.native?([1, 2, 3]).should be_false
|
12
|
-
Opal.native?(true).should be_false
|
13
|
-
Opal.native?(false).should be_false
|
14
|
-
Opal.native?(nil).should be_false
|
15
|
-
end
|
16
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "Opal.null?" do
|
4
|
-
it "returns true if the given object is null, false otherwise" do
|
5
|
-
Opal.null?(`null`).should be_true
|
6
|
-
Opal.null?(`undefined`).should be_false
|
7
|
-
Opal.null?(nil).should be_false
|
8
|
-
Opal.null?(Object.new).should be_false
|
9
|
-
end
|
10
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "Opal.number?" do
|
4
|
-
it "returns true if the object is a number" do
|
5
|
-
Opal.number?(42).should be_true
|
6
|
-
Opal.number?(Object.new).should be_false
|
7
|
-
Opal.number?(nil).should be_false
|
8
|
-
Opal.number?(`null`).should be_false
|
9
|
-
Opal.number?(`undefined`).should be_false
|
10
|
-
end
|
11
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "Opal.object?" do
|
4
|
-
it "returns true if the object is a ruby object, false otherwise" do
|
5
|
-
Opal.object?(Object.new).should be_true
|
6
|
-
Opal.object?([1, 2, 3]).should be_true
|
7
|
-
Opal.object?(true).should be_true
|
8
|
-
Opal.object?(false).should be_true
|
9
|
-
Opal.object?(nil).should be_true
|
10
|
-
|
11
|
-
Opal.object?(`{}`).should be_false
|
12
|
-
Opal.object?(`new Object()`).should be_false
|
13
|
-
Opal.object?(`null`).should be_false
|
14
|
-
Opal.object?(`undefined`).should be_false
|
15
|
-
end
|
16
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "Opal.string?" do
|
4
|
-
it "returns true if the object is a string" do
|
5
|
-
Opal.string?("foo").should be_true
|
6
|
-
Opal.string?(Object.new).should be_false
|
7
|
-
Opal.string?(nil).should be_false
|
8
|
-
Opal.string?(`null`).should be_false
|
9
|
-
Opal.string?(`undefined`).should be_false
|
10
|
-
end
|
11
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "Opal.typeof" do
|
4
|
-
it "returns the javascript type of the object" do
|
5
|
-
Opal.typeof(`null`).should == 'object'
|
6
|
-
Opal.typeof(`undefined`).should == 'undefined'
|
7
|
-
Opal.typeof(nil).should == 'object'
|
8
|
-
end
|
9
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "Opal.undefined?" do
|
4
|
-
it "returns true if the arg is undefined, false otherwise" do
|
5
|
-
Opal.undefined?(`undefined`).should be_true
|
6
|
-
Opal.undefined?(Object.new).should be_false
|
7
|
-
Opal.undefined?(nil).should be_false
|
8
|
-
Opal.undefined?(`null`).should be_false
|
9
|
-
end
|
10
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "TrueClass#===" do
|
4
|
-
it "returns true when the given object is the literal 'true'" do
|
5
|
-
(TrueClass === true).should == true
|
6
|
-
(TrueClass === false).should == false
|
7
|
-
(TrueClass === nil).should == false
|
8
|
-
(TrueClass === "").should == false
|
9
|
-
(TrueClass === 'x').should == false
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
describe "TrueClass#class" do
|
4
|
-
it "should return true for the 'true' literal, otherwise false" do
|
5
|
-
true.class.should == TrueClass
|
6
|
-
(false.class == TrueClass).should == false
|
7
|
-
(nil.class == TrueClass).should == false
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
@@ -1,17 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
5
|
-
|
6
|
-
<title>Opal Spec Runner</title>
|
7
|
-
</head>
|
8
|
-
<body>
|
9
|
-
<script src="../opal.js"></script>
|
10
|
-
<script src="../opal-spec.js"></script>
|
11
|
-
<script src="../core_spec.js"></script>
|
12
|
-
<script>
|
13
|
-
opal.main('/core_spec/spec_helper.rb');
|
14
|
-
</script>
|
15
|
-
</body>
|
16
|
-
</html>
|
17
|
-
|
data/core_spec/runner.html
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
5
|
-
|
6
|
-
<title>Opal Spec Runner</title>
|
7
|
-
</head>
|
8
|
-
<body>
|
9
|
-
<script src="../opal.debug.js"></script>
|
10
|
-
<script src="../opal-spec.debug.js"></script>
|
11
|
-
<script src="../core_spec.debug.js"></script>
|
12
|
-
<script>
|
13
|
-
opal.main('/core_spec/spec_helper.rb');
|
14
|
-
</script>
|
15
|
-
</body>
|
16
|
-
</html>
|
data/core_spec/spec_helper.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# make sure these tests are indeed running inside opal, not any other
|
2
|
-
# ruby engine.
|
3
|
-
unless RUBY_ENGINE =~ /opal/
|
4
|
-
abort <<-EOS
|
5
|
-
Opal Tests
|
6
|
-
==========
|
7
|
-
|
8
|
-
These tests MUST be run inside opal, not `#{RUBY_ENGINE}' engine
|
9
|
-
|
10
|
-
To run Array#first tests, for example:
|
11
|
-
|
12
|
-
opal core_spec/core/array/first_spec.rb
|
13
|
-
|
14
|
-
EOS
|
15
|
-
end
|
16
|
-
|
17
|
-
require 'opal/spec/autorun'
|
18
|
-
|
19
|
-
# Spec runner - if in browser, and spec_helper.rb is the main file then
|
20
|
-
# just run the spec files immediately.
|
21
|
-
if $0 == __FILE__
|
22
|
-
Dir['core_spec/**/*.rb'].each { |spec| require spec }
|
23
|
-
end
|
data/lib/opal/context.rb
DELETED
@@ -1,269 +0,0 @@
|
|
1
|
-
require 'opal/environment'
|
2
|
-
|
3
|
-
module Opal
|
4
|
-
class Context
|
5
|
-
|
6
|
-
attr_reader :v8
|
7
|
-
attr_reader :parser
|
8
|
-
attr_reader :environment
|
9
|
-
|
10
|
-
##
|
11
|
-
# Glob may be a file or glob path, as a string.
|
12
|
-
|
13
|
-
def self.runner(glob, debug = true)
|
14
|
-
ctx = self.new debug
|
15
|
-
files = Dir[glob]
|
16
|
-
ctx.v8['opal_tmp_glob'] = files
|
17
|
-
|
18
|
-
main = File.expand_path files.first unless files.empty?
|
19
|
-
|
20
|
-
runner = <<-CODE
|
21
|
-
files = `opal_tmp_glob`
|
22
|
-
$0 = '#{main}'
|
23
|
-
|
24
|
-
files.each do |a|
|
25
|
-
require a
|
26
|
-
end
|
27
|
-
CODE
|
28
|
-
|
29
|
-
ctx.eval_irb runner, '(runner)'
|
30
|
-
ctx.finish
|
31
|
-
end
|
32
|
-
|
33
|
-
def initialize(debug = true)
|
34
|
-
@debug = true
|
35
|
-
@environment = Environment.load Dir.getwd
|
36
|
-
@parser = Opal::Parser.new :debug => debug
|
37
|
-
@loaded_paths = false
|
38
|
-
|
39
|
-
setup_v8
|
40
|
-
end
|
41
|
-
|
42
|
-
# Start normal js repl
|
43
|
-
def start_repl
|
44
|
-
require 'readline'
|
45
|
-
setup_v8
|
46
|
-
|
47
|
-
loop do
|
48
|
-
# on SIGINT lets just return from the loop..
|
49
|
-
trap("SIGINT") { finish; return }
|
50
|
-
line = Readline.readline '>> ', true
|
51
|
-
|
52
|
-
# if we type exit, then we need to close down context
|
53
|
-
if line == "exit" or line.nil?
|
54
|
-
break
|
55
|
-
end
|
56
|
-
|
57
|
-
puts "=> #{eval_irb line, '(irb)'}"
|
58
|
-
end
|
59
|
-
|
60
|
-
finish
|
61
|
-
end
|
62
|
-
|
63
|
-
def eval_builder(content, file)
|
64
|
-
@parser.parse content, file
|
65
|
-
end
|
66
|
-
|
67
|
-
def eval(content, file = "(irb)", line = "")
|
68
|
-
@v8.eval eval_builder(content, file), file
|
69
|
-
end
|
70
|
-
|
71
|
-
def eval_irb(content, file = '(irb)')
|
72
|
-
code = <<-CODE
|
73
|
-
(function() { try {
|
74
|
-
opal.FILE = '#{file}';
|
75
|
-
var res = #{ eval_builder content, file };
|
76
|
-
return res.$inspect();
|
77
|
-
}
|
78
|
-
catch (e) {
|
79
|
-
console.log(e.$klass.$name + ': ' + e.message);
|
80
|
-
console.log("\\t" + e.$backtrace().join("\\n\\t"));
|
81
|
-
return "nil";
|
82
|
-
}
|
83
|
-
})()
|
84
|
-
CODE
|
85
|
-
|
86
|
-
@v8.eval code, file
|
87
|
-
rescue Opal::OpalParseError => e
|
88
|
-
puts "ParseError: #{e.message}"
|
89
|
-
"nil"
|
90
|
-
rescue V8::JSError => e
|
91
|
-
puts "SyntaxError: #{e.message}"
|
92
|
-
"nil"
|
93
|
-
end
|
94
|
-
|
95
|
-
# Finishes the context, i.e. tidy everything up. This will cause
|
96
|
-
# the opal runtime to do it's at_exit() calls (if applicable) and
|
97
|
-
# then the v8 context will de removed. It can be reset by calling
|
98
|
-
# #setup_v8
|
99
|
-
def finish
|
100
|
-
return unless @v8
|
101
|
-
@v8.eval "opal.do_at_exit()", "(irb)"
|
102
|
-
|
103
|
-
@v8 = nil
|
104
|
-
end
|
105
|
-
|
106
|
-
# Setup the context. This basically loads opal.js into our context, and
|
107
|
-
# replace the loader etc with our custom loader for a Ruby environment. The
|
108
|
-
# default "browser" loader cannot access files from disk.
|
109
|
-
def setup_v8
|
110
|
-
return if @v8
|
111
|
-
|
112
|
-
begin
|
113
|
-
require 'v8'
|
114
|
-
rescue LoadError => e
|
115
|
-
abort "therubyracer is required for running javascript. Install it with `gem install therubyracer`"
|
116
|
-
end
|
117
|
-
|
118
|
-
@v8 = V8::Context.new
|
119
|
-
@v8['console'] = Console.new
|
120
|
-
@v8['opal_filesystem'] = FileSystem.new(self)
|
121
|
-
|
122
|
-
load_runtime
|
123
|
-
load_gem_runtime
|
124
|
-
end
|
125
|
-
|
126
|
-
##
|
127
|
-
# Loads the runtime from build/*.js. This isnt included in the git repo,
|
128
|
-
# so needs to be built before running (gems should have these files included)
|
129
|
-
|
130
|
-
def load_runtime
|
131
|
-
code = @debug ? Opal.runtime_debug_code : Opal.runtime_code
|
132
|
-
@v8.eval code, '(runtime)'
|
133
|
-
end
|
134
|
-
|
135
|
-
##
|
136
|
-
# Load gem specific runtime.
|
137
|
-
|
138
|
-
def load_gem_runtime
|
139
|
-
path = File.join Opal.opal_dir, 'core', 'gemlib.rb'
|
140
|
-
eval File.read(path), path
|
141
|
-
end
|
142
|
-
|
143
|
-
##
|
144
|
-
# Console class is used to mimic the console object in web browsers
|
145
|
-
# to allow simple debugging to the stdout.
|
146
|
-
|
147
|
-
class Console
|
148
|
-
def log(*str)
|
149
|
-
puts str.join("\n")
|
150
|
-
nil
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
##
|
155
|
-
# FileSystem is used to interact with the file system from the ruby
|
156
|
-
# version of opal. The methods on this class replace the default ones
|
157
|
-
# made available in the web browser.
|
158
|
-
|
159
|
-
class FileSystem
|
160
|
-
|
161
|
-
def initialize context
|
162
|
-
@context = context
|
163
|
-
@environment = context.environment
|
164
|
-
@cache = {}
|
165
|
-
end
|
166
|
-
|
167
|
-
##
|
168
|
-
# Used to bootstrap loadpaths.
|
169
|
-
|
170
|
-
def find_paths
|
171
|
-
return @paths if @paths
|
172
|
-
|
173
|
-
paths = []
|
174
|
-
|
175
|
-
@environment.require_paths.each do |p|
|
176
|
-
dir = File.join(@environment.root, p)
|
177
|
-
paths << dir
|
178
|
-
|
179
|
-
opal_dir = File.join dir, 'opal'
|
180
|
-
paths << opal_dir if File.exists? opal_dir
|
181
|
-
end
|
182
|
-
|
183
|
-
@environment.specs.each do |spec|
|
184
|
-
gemspec = @environment.find_spec spec
|
185
|
-
next unless gemspec
|
186
|
-
|
187
|
-
gemspec.require_paths.each do |r|
|
188
|
-
dir = File.join(gemspec.full_gem_path, r)
|
189
|
-
paths << dir
|
190
|
-
|
191
|
-
opal_dir = File.join dir, 'opal'
|
192
|
-
paths << opal_dir if File.exists? opal_dir
|
193
|
-
end
|
194
|
-
#paths.push *gemspec.load_paths
|
195
|
-
end
|
196
|
-
|
197
|
-
@paths = @context.v8.eval paths.inspect
|
198
|
-
end
|
199
|
-
|
200
|
-
##
|
201
|
-
# Require a file from context
|
202
|
-
|
203
|
-
def require path, paths
|
204
|
-
resolved = find_lib path, paths
|
205
|
-
|
206
|
-
return nil unless resolved
|
207
|
-
|
208
|
-
return false if @cache[resolved]
|
209
|
-
|
210
|
-
@cache[resolved] = true
|
211
|
-
@context.v8.eval "opal.FILE = '#{resolved}'"
|
212
|
-
@context.eval File.read(resolved), resolved
|
213
|
-
|
214
|
-
resolved
|
215
|
-
end
|
216
|
-
|
217
|
-
def find_lib path, paths
|
218
|
-
paths.each do |l|
|
219
|
-
candidate = File.join l, "#{path}.rb"
|
220
|
-
return candidate if File.exists? candidate
|
221
|
-
|
222
|
-
candidate = File.join l, path
|
223
|
-
return candidate if File.exists? candidate
|
224
|
-
end
|
225
|
-
|
226
|
-
abs = File.expand_path path
|
227
|
-
[abs, abs + '.rb'].each do |c|
|
228
|
-
return c if File.exists?(c) && !File.directory?(c)
|
229
|
-
end
|
230
|
-
|
231
|
-
nil
|
232
|
-
end
|
233
|
-
|
234
|
-
##
|
235
|
-
# Build body for given ruby file. Should return a function
|
236
|
-
# capable of being executed by opal of form:
|
237
|
-
#
|
238
|
-
# function(self, FILE) { ... }
|
239
|
-
|
240
|
-
def file_body(path)
|
241
|
-
@context.eval File.read(path), path
|
242
|
-
end
|
243
|
-
|
244
|
-
def cwd
|
245
|
-
Dir.getwd
|
246
|
-
end
|
247
|
-
|
248
|
-
def glob(*arr)
|
249
|
-
Dir.glob arr
|
250
|
-
end
|
251
|
-
|
252
|
-
def exist_p(path)
|
253
|
-
File.exist? path
|
254
|
-
end
|
255
|
-
|
256
|
-
def expand_path(filename, dir_string = nil)
|
257
|
-
File.expand_path filename, dir_string
|
258
|
-
end
|
259
|
-
|
260
|
-
def dirname(file)
|
261
|
-
File.dirname file
|
262
|
-
end
|
263
|
-
|
264
|
-
def join(*parts)
|
265
|
-
File.join *parts
|
266
|
-
end
|
267
|
-
end # FileSystem
|
268
|
-
end
|
269
|
-
end
|