opal 0.3.16 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +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
data/core/runtime.js
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
var
|
2
|
-
|
1
|
+
var Opal = this.Opal = {};
|
2
|
+
|
3
|
+
Opal.global = this;
|
3
4
|
|
4
5
|
// Minify common function calls
|
5
|
-
var
|
6
|
-
|
6
|
+
var __hasOwn = Object.prototype.hasOwnProperty,
|
7
|
+
__slice = Array.prototype.slice;
|
7
8
|
|
8
9
|
// Types - also added to bridged objects
|
9
10
|
var T_CLASS = 0x0001,
|
@@ -22,40 +23,13 @@ var T_CLASS = 0x0001,
|
|
22
23
|
// Generates unique id for every ruby object
|
23
24
|
var unique_id = 0;
|
24
25
|
|
25
|
-
// Find function body for the super call
|
26
|
-
function find_super(klass, callee, mid) {
|
27
|
-
var cur_method;
|
28
|
-
|
29
|
-
while (klass) {
|
30
|
-
if (klass.$m[mid]) {
|
31
|
-
if (klass.$m[mid] == callee) {
|
32
|
-
cur_method = klass.$m[mid];
|
33
|
-
break;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
klass = klass.$s;
|
37
|
-
}
|
38
|
-
|
39
|
-
if (!(klass && cur_method)) { return null; }
|
40
|
-
|
41
|
-
klass = klass.$s;
|
42
|
-
|
43
|
-
while (klass) {
|
44
|
-
if (klass.$m[mid]) {
|
45
|
-
return klass.$m[mid];
|
46
|
-
}
|
47
|
-
|
48
|
-
klass = klass.$s;
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
26
|
// Jump return - return in proc body
|
53
|
-
|
27
|
+
Opal.jump = function(value, func) {
|
54
28
|
throw new Error('jump return');
|
55
29
|
};
|
56
30
|
|
57
31
|
// Get constant with given id
|
58
|
-
|
32
|
+
Opal.const_get = function(const_table, id) {
|
59
33
|
if (const_table[id]) {
|
60
34
|
return const_table[id];
|
61
35
|
}
|
@@ -64,56 +38,35 @@ opal.const_get = function(const_table, id) {
|
|
64
38
|
};
|
65
39
|
|
66
40
|
// Table holds all class variables
|
67
|
-
|
68
|
-
|
69
|
-
// Array of all procs to be called at_exit
|
70
|
-
var end_procs = [];
|
71
|
-
|
72
|
-
// Call exit blocks in reverse order
|
73
|
-
opal.do_at_exit = function() {
|
74
|
-
var proc;
|
75
|
-
|
76
|
-
while (proc = end_procs.pop()) {
|
77
|
-
proc.call(proc.$S);
|
78
|
-
}
|
79
|
-
};
|
41
|
+
Opal.cvars = {};
|
80
42
|
|
81
43
|
// Globals table
|
82
|
-
|
44
|
+
Opal.gvars = {};
|
83
45
|
|
84
46
|
// Define a method alias
|
85
|
-
|
47
|
+
Opal.alias = function(klass, new_name, old_name) {
|
86
48
|
new_name = mid_to_jsid(new_name);
|
87
49
|
old_name = mid_to_jsid(old_name);
|
88
50
|
|
89
|
-
var body = klass
|
51
|
+
var body = klass._proto[old_name];
|
90
52
|
|
91
53
|
if (!body) {
|
92
|
-
throw RubyNameError.$new("undefined method `" + old_name + "' for class `" + klass
|
54
|
+
// throw RubyNameError.$new(null, "undefined method `" + old_name + "' for class `" + klass._name + "'");
|
55
|
+
throw new Error("undefined method `" + old_name + "' for class `" + klass._name + "'");
|
93
56
|
}
|
94
57
|
|
95
58
|
define_method(klass, new_name, body);
|
96
|
-
return
|
59
|
+
return null;
|
97
60
|
};
|
98
61
|
|
99
|
-
// method missing yielder - used in debug mode to call method_missing.
|
100
|
-
opal.mm = function(jsid) {
|
101
|
-
var mid = jsid_to_mid(jsid);
|
102
|
-
return function() {
|
103
|
-
var args = $slice.call(arguments);
|
104
|
-
args.unshift(mid);
|
105
|
-
return this.$method_missing.apply(this, args);
|
106
|
-
};
|
107
|
-
}
|
108
|
-
|
109
62
|
// Actually define methods
|
110
|
-
var define_method =
|
63
|
+
var define_method = Opal.defn = function(klass, id, body) {
|
111
64
|
// If an object, make sure to use its class
|
112
|
-
if (klass
|
113
|
-
klass = klass
|
65
|
+
if (klass._flags & T_OBJECT) {
|
66
|
+
klass = klass._klass;
|
114
67
|
}
|
115
68
|
|
116
|
-
klass
|
69
|
+
klass._alloc.prototype[id] = body;
|
117
70
|
|
118
71
|
var included_in = klass.$included_in, includee;
|
119
72
|
|
@@ -125,56 +78,51 @@ var define_method = opal.defn = function(klass, id, body) {
|
|
125
78
|
}
|
126
79
|
}
|
127
80
|
|
128
|
-
if (klass
|
129
|
-
klass
|
81
|
+
if (klass._bridge) {
|
82
|
+
klass._bridge[id] = body;
|
130
83
|
}
|
131
84
|
|
132
85
|
|
133
|
-
return
|
86
|
+
return null;
|
134
87
|
}
|
135
88
|
|
136
|
-
// Fake yielder used when no block given
|
137
|
-
opal.no_proc = function() {
|
138
|
-
throw RubyLocalJumpError.$new('no block given');
|
139
|
-
};
|
140
|
-
|
141
89
|
function define_module(base, id) {
|
142
90
|
var module;
|
143
91
|
|
144
92
|
module = boot_module();
|
145
|
-
module
|
93
|
+
module._name = (base === RubyObject ? id : base._name + '::' + id)
|
146
94
|
|
147
95
|
make_metaclass(module, RubyModule);
|
148
96
|
|
149
|
-
module
|
97
|
+
module._flags = T_MODULE;
|
150
98
|
module.$included_in = [];
|
151
99
|
|
152
100
|
var const_alloc = function() {};
|
153
|
-
var const_scope = const_alloc.prototype = new base
|
154
|
-
module
|
101
|
+
var const_scope = const_alloc.prototype = new base._scope.alloc();
|
102
|
+
module._scope = const_scope;
|
155
103
|
const_scope.alloc = const_alloc;
|
156
104
|
|
157
|
-
base
|
105
|
+
base._scope[id] = module;
|
158
106
|
|
159
107
|
return module;
|
160
108
|
}
|
161
109
|
|
162
|
-
//
|
163
|
-
|
110
|
+
// Opal define class. 0: regular, 1: module, 2: shift class.
|
111
|
+
Opal.klass = function(base, superklass, id, body, type) {
|
164
112
|
var klass;
|
165
113
|
|
166
114
|
switch (type) {
|
167
115
|
case 0:
|
168
|
-
if (base
|
169
|
-
base = class_real(base
|
116
|
+
if (base._flags & T_OBJECT) {
|
117
|
+
base = class_real(base._klass);
|
170
118
|
}
|
171
119
|
|
172
|
-
if (superklass ===
|
120
|
+
if (superklass === null) {
|
173
121
|
superklass = RubyObject;
|
174
122
|
}
|
175
123
|
|
176
|
-
if (
|
177
|
-
klass = base
|
124
|
+
if (__hasOwn.call(base._scope, id)) {
|
125
|
+
klass = base._scope[id];
|
178
126
|
}
|
179
127
|
else {
|
180
128
|
klass = define_class(base, id, superklass);
|
@@ -183,12 +131,12 @@ opal.klass = function(base, superklass, id, body, type) {
|
|
183
131
|
break;
|
184
132
|
|
185
133
|
case 1:
|
186
|
-
if (base
|
187
|
-
base = class_real(base
|
134
|
+
if (base._flags & T_OBJECT) {
|
135
|
+
base = class_real(base._klass);
|
188
136
|
}
|
189
137
|
|
190
|
-
if (
|
191
|
-
klass = base
|
138
|
+
if (__hasOwn.call(base._scope, id)) {
|
139
|
+
klass = base._scope[id];
|
192
140
|
}
|
193
141
|
else {
|
194
142
|
klass = define_module(base, id);
|
@@ -197,22 +145,22 @@ opal.klass = function(base, superklass, id, body, type) {
|
|
197
145
|
break;
|
198
146
|
|
199
147
|
case 2:
|
200
|
-
klass = singleton_class(
|
148
|
+
klass = base.$singleton_class();
|
201
149
|
break;
|
202
150
|
}
|
203
151
|
|
204
152
|
return body.call(klass);
|
205
153
|
};
|
206
154
|
|
207
|
-
|
155
|
+
Opal.slice = __slice;
|
208
156
|
|
209
|
-
|
210
|
-
return define_method(singleton_class(
|
157
|
+
Opal.defs = function(base, id, body) {
|
158
|
+
return define_method(base.$singleton_class(), id, body);
|
211
159
|
};
|
212
160
|
|
213
161
|
// Undefine one or more methods
|
214
|
-
|
215
|
-
var args =
|
162
|
+
Opal.undef = function(klass) {
|
163
|
+
var args = __slice.call(arguments, 1);
|
216
164
|
|
217
165
|
for (var i = 0, length = args.length; i < length; i++) {
|
218
166
|
var mid = args[i], id = mid_to_jsid[mid];
|
@@ -222,19 +170,76 @@ opal.undef = function(klass) {
|
|
222
170
|
};
|
223
171
|
|
224
172
|
// Calls a super method.
|
225
|
-
|
226
|
-
var
|
227
|
-
func = find_super(self.$klass, callee, mid);
|
173
|
+
Opal.zuper = function(callee, jsid, self, args) {
|
174
|
+
var func = find_super(self._klass, callee, jsid);
|
228
175
|
|
229
176
|
if (!func) {
|
230
|
-
throw RubyNoMethodError.$new("super: no superclass method `" +
|
231
|
-
|
177
|
+
throw RubyNoMethodError.$new(null, "super: no superclass method `" +
|
178
|
+
jsid_to_mid(jsid) + "'" + " for " + self.$inspect());
|
232
179
|
}
|
233
180
|
|
234
181
|
return func.apply(self, args);
|
235
182
|
};
|
236
183
|
|
237
|
-
|
184
|
+
// dynamic super (inside block)
|
185
|
+
Opal.dsuper = function(scopes, defn, jsid, self, args) {
|
186
|
+
var method, scope = scopes[0];
|
187
|
+
|
188
|
+
for (var i = 0, length = scopes.length; i < length; i++) {
|
189
|
+
if (scope.o$jsid) {
|
190
|
+
jsid = scope.o$jsid;
|
191
|
+
method = scope;
|
192
|
+
break;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
if (method) {
|
197
|
+
// one of the nested blocks was define_method'd
|
198
|
+
return Opal.zuper(method, jsid, self, args);
|
199
|
+
}
|
200
|
+
else if (defn) {
|
201
|
+
// blocks not define_method'd, but they were enclosed by a real method
|
202
|
+
return Opal.zuper(defn, jsid, self, args);
|
203
|
+
}
|
204
|
+
|
205
|
+
// if we get here then we were inside a nest of just blocks, and none have
|
206
|
+
// been defined as a method
|
207
|
+
throw RubyNoMethodError.$new(null, "super: cannot call super when not in method");
|
208
|
+
}
|
209
|
+
|
210
|
+
// Find function body for the super call
|
211
|
+
function find_super(klass, callee, mid) {
|
212
|
+
var cur_method;
|
213
|
+
|
214
|
+
while (klass) {
|
215
|
+
if (klass._proto.hasOwnProperty(mid)) {
|
216
|
+
if (klass._proto[mid] === callee) {
|
217
|
+
cur_method = klass._proto[mid];
|
218
|
+
break;
|
219
|
+
}
|
220
|
+
}
|
221
|
+
klass = klass._super;
|
222
|
+
}
|
223
|
+
|
224
|
+
if (!(klass && cur_method)) { return null; }
|
225
|
+
|
226
|
+
klass = klass._super;
|
227
|
+
|
228
|
+
while (klass) {
|
229
|
+
if (klass._proto.hasOwnProperty(mid)) {
|
230
|
+
// make sure our found method isnt the same - this can happen if this
|
231
|
+
// newly found method is from a module and we are now looking at the
|
232
|
+
// module it came from.
|
233
|
+
if (klass._proto[mid] !== callee) {
|
234
|
+
return klass._proto[mid];
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
klass = klass._super;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
var mid_to_jsid = Opal.mid_to_jsid = function(mid) {
|
238
243
|
if (method_names[mid]) {
|
239
244
|
return method_names[mid];
|
240
245
|
}
|
@@ -242,7 +247,7 @@ var mid_to_jsid = opal.mid_to_jsid = function(mid) {
|
|
242
247
|
return '$' + mid.replace('!', '$b').replace('?', '$p').replace('=', '$e');
|
243
248
|
}
|
244
249
|
|
245
|
-
var jsid_to_mid =
|
250
|
+
var jsid_to_mid = Opal.jsid_to_mid = function(jsid) {
|
246
251
|
if (reverse_method_names[jsid]) {
|
247
252
|
return reverse_method_names[jsid];
|
248
253
|
}
|
@@ -252,14 +257,14 @@ var jsid_to_mid = opal.jsid_to_mid = function(jsid) {
|
|
252
257
|
return jsid.replace('$b', '!').replace('$p', '?').replace('$e', '=');
|
253
258
|
}
|
254
259
|
|
255
|
-
|
256
|
-
throw RubyArgError.$new('wrong number of arguments(' + given + ' for ' + expected + ')');
|
260
|
+
Opal.arg_error = function(given, expected) {
|
261
|
+
throw RubyArgError.$new(null, 'wrong number of arguments(' + given + ' for ' + expected + ')');
|
257
262
|
};
|
258
263
|
|
259
264
|
// Boot a base class (makes instances).
|
260
265
|
function boot_defclass(superklass) {
|
261
266
|
var cls = function() {
|
262
|
-
this
|
267
|
+
this._id = unique_id++;
|
263
268
|
|
264
269
|
return this;
|
265
270
|
};
|
@@ -272,7 +277,7 @@ function boot_defclass(superklass) {
|
|
272
277
|
}
|
273
278
|
|
274
279
|
cls.prototype.constructor = cls;
|
275
|
-
cls.prototype
|
280
|
+
cls.prototype._flags = T_OBJECT;
|
276
281
|
|
277
282
|
return cls;
|
278
283
|
}
|
@@ -280,7 +285,7 @@ function boot_defclass(superklass) {
|
|
280
285
|
// Boot actual (meta classes) of core objects.
|
281
286
|
function boot_makemeta(id, klass, superklass) {
|
282
287
|
var meta = function() {
|
283
|
-
this
|
288
|
+
this._id = unique_id++;
|
284
289
|
|
285
290
|
return this;
|
286
291
|
};
|
@@ -292,15 +297,15 @@ function boot_makemeta(id, klass, superklass) {
|
|
292
297
|
|
293
298
|
var proto = meta.prototype;
|
294
299
|
proto.$included_in = [];
|
295
|
-
proto
|
296
|
-
proto
|
297
|
-
proto
|
298
|
-
proto
|
300
|
+
proto._alloc = klass;
|
301
|
+
proto._flags = T_CLASS;
|
302
|
+
proto._name = id;
|
303
|
+
proto._super = superklass;
|
299
304
|
proto.constructor = meta;
|
300
305
|
|
301
306
|
var result = new meta();
|
302
|
-
klass.prototype
|
303
|
-
result
|
307
|
+
klass.prototype._klass = result;
|
308
|
+
result._proto = klass.prototype;
|
304
309
|
|
305
310
|
return result;
|
306
311
|
}
|
@@ -309,23 +314,23 @@ function boot_makemeta(id, klass, superklass) {
|
|
309
314
|
function boot_class(superklass) {
|
310
315
|
// instances
|
311
316
|
var cls = function() {
|
312
|
-
this
|
317
|
+
this._id = unique_id++;
|
313
318
|
|
314
319
|
return this;
|
315
320
|
};
|
316
321
|
|
317
322
|
var ctor = function() {};
|
318
|
-
ctor.prototype = superklass
|
323
|
+
ctor.prototype = superklass._alloc.prototype;
|
319
324
|
|
320
325
|
cls.prototype = new ctor();
|
321
326
|
|
322
327
|
var proto = cls.prototype;
|
323
328
|
proto.constructor = cls;
|
324
|
-
proto
|
329
|
+
proto._flags = T_OBJECT;
|
325
330
|
|
326
331
|
// class itself
|
327
332
|
var meta = function() {
|
328
|
-
this
|
333
|
+
this._id = unique_id++;
|
329
334
|
|
330
335
|
return this;
|
331
336
|
};
|
@@ -336,15 +341,15 @@ function boot_class(superklass) {
|
|
336
341
|
meta.prototype = new mtor();
|
337
342
|
|
338
343
|
proto = meta.prototype;
|
339
|
-
proto
|
340
|
-
proto
|
344
|
+
proto._alloc = cls;
|
345
|
+
proto._flags = T_CLASS;
|
341
346
|
proto.constructor = meta;
|
342
|
-
proto
|
347
|
+
proto._super = superklass;
|
343
348
|
|
344
349
|
var result = new meta();
|
345
|
-
cls.prototype
|
346
|
-
|
347
|
-
result
|
350
|
+
cls.prototype._klass = result;
|
351
|
+
|
352
|
+
result._proto = cls.prototype;
|
348
353
|
|
349
354
|
return result;
|
350
355
|
}
|
@@ -354,33 +359,33 @@ function boot_module() {
|
|
354
359
|
// can be a regular object
|
355
360
|
var module_cons = function(){};
|
356
361
|
var module_inst = module_cons.prototype;
|
357
|
-
|
362
|
+
|
358
363
|
// Module itself
|
359
364
|
var meta = function() {
|
360
|
-
this
|
365
|
+
this._id = unique_id++;
|
361
366
|
return this;
|
362
367
|
};
|
363
|
-
|
368
|
+
|
364
369
|
var mtor = function(){};
|
365
370
|
mtor.prototype = RubyModule.constructor.prototype;
|
366
371
|
meta.prototype = new mtor();
|
367
|
-
|
372
|
+
|
368
373
|
var proto = meta.prototype;
|
369
|
-
proto
|
370
|
-
proto
|
374
|
+
proto._alloc = module_cons;
|
375
|
+
proto._flags = T_MODULE;
|
371
376
|
proto.constructor = meta;
|
372
|
-
proto
|
373
|
-
|
377
|
+
proto._super = null;
|
378
|
+
|
374
379
|
var module = new meta();
|
375
|
-
module
|
376
|
-
|
380
|
+
module._proto = module_inst;
|
381
|
+
|
377
382
|
return module;
|
378
383
|
}
|
379
384
|
|
380
385
|
// Get actual class ignoring singleton classes and iclasses.
|
381
386
|
function class_real(klass) {
|
382
|
-
while (klass
|
383
|
-
klass = klass
|
387
|
+
while (klass._flags & FL_SINGLETON) {
|
388
|
+
klass = klass._super;
|
384
389
|
}
|
385
390
|
|
386
391
|
return klass;
|
@@ -388,21 +393,23 @@ function class_real(klass) {
|
|
388
393
|
|
389
394
|
// Make metaclass for the given class
|
390
395
|
function make_metaclass(klass, superklass) {
|
391
|
-
if (klass
|
392
|
-
if ((klass
|
396
|
+
if (klass._flags & T_CLASS) {
|
397
|
+
if ((klass._flags & T_CLASS) && (klass._flags & FL_SINGLETON)) {
|
393
398
|
throw RubyException.$new('too much meta: return klass?');
|
394
399
|
}
|
395
400
|
else {
|
396
|
-
var class_id = "#<Class:" + klass
|
401
|
+
var class_id = "#<Class:" + klass._name + ">",
|
397
402
|
meta = boot_class(superklass);
|
398
403
|
|
399
|
-
meta
|
400
|
-
meta
|
401
|
-
meta
|
404
|
+
meta._name = class_id;
|
405
|
+
meta._alloc.prototype = klass.constructor.prototype;
|
406
|
+
meta._proto = meta._alloc.prototype;
|
407
|
+
meta._flags |= FL_SINGLETON;
|
408
|
+
meta._klass = RubyClass;
|
402
409
|
|
403
|
-
klass
|
410
|
+
klass._klass = meta;
|
404
411
|
|
405
|
-
meta
|
412
|
+
meta._scope = klass._scope;
|
406
413
|
meta.__attached__ = klass;
|
407
414
|
|
408
415
|
return meta;
|
@@ -414,20 +421,20 @@ function make_metaclass(klass, superklass) {
|
|
414
421
|
}
|
415
422
|
|
416
423
|
function make_singleton_class(obj) {
|
417
|
-
var orig_class = obj
|
418
|
-
class_id = "#<Class:#<" + orig_class
|
424
|
+
var orig_class = obj._klass,
|
425
|
+
class_id = "#<Class:#<" + orig_class._name + ":" + orig_class._id + ">>";
|
419
426
|
|
420
427
|
klass = boot_class(orig_class);
|
421
|
-
klass
|
428
|
+
klass._name = class_id;
|
422
429
|
|
423
|
-
klass
|
424
|
-
klass
|
430
|
+
klass._flags |= FL_SINGLETON;
|
431
|
+
klass._bridge = obj;
|
425
432
|
|
426
|
-
obj
|
433
|
+
obj._klass = klass;
|
427
434
|
|
428
435
|
klass.__attached__ = obj;
|
429
436
|
|
430
|
-
klass
|
437
|
+
klass._klass = class_real(orig_class)._klass;
|
431
438
|
|
432
439
|
return klass;
|
433
440
|
}
|
@@ -436,13 +443,13 @@ function bridge_class(constructor, flags, id) {
|
|
436
443
|
var klass = define_class(RubyObject, id, RubyObject),
|
437
444
|
prototype = constructor.prototype;
|
438
445
|
|
439
|
-
klass
|
440
|
-
klass
|
446
|
+
klass._alloc = constructor;
|
447
|
+
klass._proto = prototype;
|
441
448
|
|
442
449
|
bridged_classes.push(klass);
|
443
450
|
|
444
|
-
prototype
|
445
|
-
prototype
|
451
|
+
prototype._klass = klass;
|
452
|
+
prototype._flags = flags;
|
446
453
|
|
447
454
|
return klass;
|
448
455
|
}
|
@@ -451,19 +458,19 @@ function bridge_class(constructor, flags, id) {
|
|
451
458
|
function define_class(base, id, superklass) {
|
452
459
|
var klass;
|
453
460
|
|
454
|
-
var class_id = (base === RubyObject ? id : base
|
461
|
+
var class_id = (base === RubyObject ? id : base._name + '::' + id);
|
455
462
|
|
456
463
|
klass = boot_class(superklass);
|
457
|
-
klass
|
464
|
+
klass._name = class_id;
|
458
465
|
|
459
|
-
make_metaclass(klass, superklass
|
466
|
+
make_metaclass(klass, superklass._klass);
|
460
467
|
|
461
468
|
var const_alloc = function() {};
|
462
|
-
var const_scope = const_alloc.prototype = new base
|
463
|
-
klass
|
469
|
+
var const_scope = const_alloc.prototype = new base._scope.alloc();
|
470
|
+
klass._scope = const_scope;
|
464
471
|
const_scope.alloc = const_alloc;
|
465
472
|
|
466
|
-
base
|
473
|
+
base._scope[id] = klass;
|
467
474
|
|
468
475
|
if (superklass.$inherited) {
|
469
476
|
superklass.$inherited(klass);
|
@@ -472,112 +479,25 @@ function define_class(base, id, superklass) {
|
|
472
479
|
return klass;
|
473
480
|
}
|
474
481
|
|
475
|
-
|
476
|
-
|
477
|
-
var klass;
|
478
|
-
|
479
|
-
if (obj.$flags & T_OBJECT) {
|
480
|
-
if ((obj.$flags & T_NUMBER) || (obj.$flags & T_STRING)) {
|
481
|
-
throw RubyTypeError.$new("can't define singleton");
|
482
|
-
}
|
483
|
-
}
|
482
|
+
function define_iclass(klass, module) {
|
483
|
+
var sup = klass._super;
|
484
484
|
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
485
|
+
var iclass = {};
|
486
|
+
iclass._proto = module._proto;
|
487
|
+
iclass._super = sup;
|
488
|
+
iclass._flags = T_ICLASS;
|
489
|
+
iclass._klass = module;
|
490
|
+
iclass._name = module._name;
|
490
491
|
|
491
|
-
|
492
|
-
}
|
492
|
+
klass._super = iclass;
|
493
493
|
|
494
|
-
return
|
494
|
+
return iclass;
|
495
495
|
}
|
496
496
|
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
top_self.$require(id);
|
502
|
-
|
503
|
-
opal.do_at_exit();
|
504
|
-
}
|
505
|
-
catch (e) {
|
506
|
-
// this is defined in debug.js
|
507
|
-
console.log(e.$klass.$name + ': ' + e.message);
|
508
|
-
console.log("\t" + e.$backtrace().join("\n\t"));
|
509
|
-
}
|
510
|
-
};
|
511
|
-
|
512
|
-
/**
|
513
|
-
* Register a standard file. This can be used to register non-lib files.
|
514
|
-
* For example, specs can be registered here so they are available.
|
515
|
-
*
|
516
|
-
* NOTE: Files should be registered as a full path with given factory.
|
517
|
-
*
|
518
|
-
* Usage:
|
519
|
-
*
|
520
|
-
* opal.file('/spec/foo.rb': function() {
|
521
|
-
* // ...
|
522
|
-
* });
|
523
|
-
*/
|
524
|
-
opal.file = function(file, factory) {
|
525
|
-
FACTORIES[file] = factory;
|
526
|
-
};
|
527
|
-
|
528
|
-
/**
|
529
|
-
* Register a lib.
|
530
|
-
*
|
531
|
-
* Usage:
|
532
|
-
*
|
533
|
-
* opal.lib('my_lib', function() {
|
534
|
-
* // ...
|
535
|
-
* });
|
536
|
-
*
|
537
|
-
* opal.lib('my_lib/foo', function() {
|
538
|
-
* // ...
|
539
|
-
* });
|
540
|
-
*/
|
541
|
-
opal.lib = function(lib, factory) {
|
542
|
-
var file = '/lib/' + lib + '.rb';
|
543
|
-
FACTORIES[file] = factory;
|
544
|
-
LIBS[lib] = file;
|
545
|
-
};
|
546
|
-
|
547
|
-
var FACTORIES = {},
|
548
|
-
FEATURES = [],
|
549
|
-
LIBS = {},
|
550
|
-
LOADER_PATHS = ['', '/lib'],
|
551
|
-
LOADER_CACHE = {};
|
552
|
-
|
553
|
-
function find_lib(id) {
|
554
|
-
var path;
|
555
|
-
|
556
|
-
// try to load a lib path first - i.e. something in our load path
|
557
|
-
if (path = LIBS[id]) return path;
|
558
|
-
|
559
|
-
// find '/opal/x' style libs
|
560
|
-
if (path = LIBS['opal/' + id]) return path;
|
561
|
-
|
562
|
-
// next, incase our require() has a ruby extension..
|
563
|
-
if (FACTORIES['/lib/' +id]) return '/lib/' + id;
|
564
|
-
|
565
|
-
// check if id is full path..
|
566
|
-
if (FACTORIES[id]) return id;
|
567
|
-
|
568
|
-
// full path without '.rb'
|
569
|
-
if (FACTORIES[id + '.rb']) return id + '.rb';
|
570
|
-
|
571
|
-
// check in current working directory.
|
572
|
-
var in_cwd = FS_CWD + '/' + id;
|
573
|
-
|
574
|
-
if (FACTORIES[in_cwd]) return in_cwd;
|
575
|
-
};
|
576
|
-
|
577
|
-
// Current working directory
|
578
|
-
var FS_CWD = '/';
|
579
|
-
|
580
|
-
// Turns a glob string into a regexp
|
497
|
+
// Handling requires
|
498
|
+
function require_handler(path) {
|
499
|
+
throw new Error('Cannot require ' + path);
|
500
|
+
}
|
581
501
|
|
582
502
|
// Initialization
|
583
503
|
// --------------
|
@@ -593,20 +513,24 @@ var RubyModule = boot_makemeta('Module', BootModule, RubyObject.constructor);
|
|
593
513
|
var RubyClass = boot_makemeta('Class', BootClass, RubyModule.constructor);
|
594
514
|
|
595
515
|
// Fix boot classes to use meta class
|
596
|
-
RubyObject
|
597
|
-
RubyModule
|
598
|
-
RubyClass
|
516
|
+
RubyObject._klass = RubyClass;
|
517
|
+
RubyModule._klass = RubyClass;
|
518
|
+
RubyClass._klass = RubyClass;
|
599
519
|
|
600
520
|
// fix superclasses
|
601
|
-
RubyObject
|
602
|
-
RubyModule
|
603
|
-
RubyClass
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
//
|
521
|
+
RubyObject._super = null;
|
522
|
+
RubyModule._super = RubyObject;
|
523
|
+
RubyClass._super = RubyModule;
|
524
|
+
|
525
|
+
Opal.Object = RubyObject;
|
526
|
+
Opal.Module = RubyModule;
|
527
|
+
Opal.Class = RubyClass;
|
528
|
+
|
529
|
+
// Make object act like a module. Internally, `Object` gets included
|
530
|
+
// into all the bridged classes. This is because the native prototypes
|
531
|
+
// for these bridged classes need to get all the `Object` methods as
|
532
|
+
// well. This allows `Object` to just donate its instance methods to
|
533
|
+
// the bridged classes using the exact same method that modules use.
|
610
534
|
var bridged_classes = RubyObject.$included_in = [];
|
611
535
|
|
612
536
|
// Top level Object scope (used by object and top_self).
|
@@ -614,27 +538,43 @@ var top_const_alloc = function(){};
|
|
614
538
|
var top_const_scope = top_const_alloc.prototype;
|
615
539
|
top_const_scope.alloc = top_const_alloc;
|
616
540
|
|
617
|
-
RubyObject
|
541
|
+
RubyObject._scope = Opal.constants = top_const_scope;
|
618
542
|
|
619
543
|
var module_const_alloc = function(){};
|
620
544
|
var module_const_scope = new top_const_alloc();
|
621
545
|
module_const_scope.alloc = module_const_alloc;
|
622
|
-
RubyModule
|
546
|
+
RubyModule._scope = module_const_scope;
|
623
547
|
|
624
548
|
var class_const_alloc = function(){};
|
625
549
|
var class_const_scope = new top_const_alloc();
|
626
550
|
class_const_scope.alloc = class_const_alloc;
|
627
|
-
RubyClass
|
628
|
-
|
629
|
-
RubyObject
|
630
|
-
RubyObject
|
631
|
-
RubyObject
|
632
|
-
RubyObject
|
551
|
+
RubyClass._scope = class_const_scope;
|
552
|
+
|
553
|
+
RubyObject._scope.BasicObject = RubyObject;
|
554
|
+
RubyObject._scope.Object = RubyObject;
|
555
|
+
RubyObject._scope.Module = RubyModule;
|
556
|
+
RubyObject._scope.Class = RubyClass;
|
557
|
+
|
558
|
+
// Every ruby object (except natives) will have their #to_s method aliased
|
559
|
+
// to the native .toString() function so that accessing ruby objects from
|
560
|
+
// javascript will return a nicer string format. This is also used when
|
561
|
+
// interpolating objects into strings as the js engine will call toString
|
562
|
+
// which in turn calls #to_s.
|
563
|
+
//
|
564
|
+
// This is also used as the hashing function. In ruby, #hash should return
|
565
|
+
// an integer. This is not possible in Opal as strings cannot be mutable
|
566
|
+
// and can not therefore have unique integer hashes. Seeing as strings or
|
567
|
+
// symbols are used more often as hash keys, this role is changed in Opal
|
568
|
+
// so that hash values should be strings, and this function makes the #to_s
|
569
|
+
// value for an object the default.
|
570
|
+
RubyObject._proto.toString = function() {
|
571
|
+
return this.$to_s();
|
572
|
+
};
|
633
573
|
|
634
|
-
var top_self =
|
574
|
+
var top_self = Opal.top = new RubyObject._alloc();
|
635
575
|
|
636
576
|
var RubyNilClass = define_class(RubyObject, 'NilClass', RubyObject);
|
637
|
-
|
577
|
+
Opal.nil = new RubyNilClass._alloc();
|
638
578
|
|
639
579
|
bridge_class(Array, T_OBJECT | T_ARRAY, 'Array');
|
640
580
|
bridge_class(Number, T_OBJECT | T_NUMBER, 'Numeric');
|
@@ -646,6 +586,7 @@ bridge_class(RegExp, T_OBJECT, 'Regexp');
|
|
646
586
|
|
647
587
|
var RubyMatch = define_class(RubyObject, 'MatchData', RubyObject);
|
648
588
|
var RubyRange = define_class(RubyObject, 'Range', RubyObject);
|
589
|
+
RubyRange._proto._flags = T_OBJECT | T_RANGE;
|
649
590
|
|
650
591
|
var RubyException = bridge_class(Error, T_OBJECT, 'Exception');
|
651
592
|
var RubyStandardError = define_class(RubyObject, 'StandardError', RubyException);
|
@@ -662,11 +603,11 @@ var RubyKeyError = define_class(RubyObject, 'KeyError', RubyIndexError);
|
|
662
603
|
var RubyRangeError = define_class(RubyObject, 'RangeError', RubyStandardError);
|
663
604
|
var RubyNotImplError = define_class(RubyObject, 'NotImplementedError', RubyException);
|
664
605
|
|
665
|
-
RubyException
|
666
|
-
return this
|
606
|
+
RubyException._alloc.prototype.toString = function() {
|
607
|
+
return this._klass._name + ': ' + this.message;
|
667
608
|
};
|
668
609
|
|
669
|
-
var breaker =
|
670
|
-
breaker
|
610
|
+
var breaker = Opal.breaker = new Error('unexpected break');
|
611
|
+
breaker._klass = RubyLocalJumpError;
|
671
612
|
breaker.$t = function() { throw this; };
|
672
613
|
|