opal 0.6.3 → 0.7.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.spectator +2 -0
- data/.spectator-mspec +3 -0
- data/.travis.yml +8 -11
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTING.md +8 -43
- data/Gemfile +15 -4
- data/Guardfile +77 -0
- data/README.md +15 -9
- data/Rakefile +36 -12
- data/benchmarks/operators.rb +11 -0
- data/bin/opal +10 -13
- data/bin/opal-build +4 -4
- data/bin/opal-mspec +10 -0
- data/bin/opal-repl +4 -3
- data/examples/sinatra/Gemfile +1 -1
- data/examples/sinatra/config.ru +3 -3
- data/lib/mspec/opal/main.rb.erb +2 -2
- data/lib/mspec/opal/rake_task.rb +31 -24
- data/lib/mspec/opal/runner.rb +18 -1
- data/lib/mspec/opal/sprockets.js +17 -0
- data/lib/opal.rb +1 -34
- data/lib/opal/builder.rb +92 -58
- data/lib/opal/builder_processors.rb +165 -0
- data/lib/opal/cli.rb +85 -144
- data/lib/opal/cli_options.rb +136 -90
- data/lib/opal/cli_runners.rb +10 -0
- data/lib/opal/cli_runners/nodejs.rb +56 -0
- data/lib/opal/cli_runners/phantom.js +35 -0
- data/lib/opal/cli_runners/phantomjs.rb +28 -0
- data/lib/opal/cli_runners/server.rb +54 -0
- data/lib/opal/compiler.rb +35 -16
- data/lib/opal/erb.rb +29 -15
- data/lib/opal/hike_path_finder.rb +18 -0
- data/lib/opal/nodes.rb +1 -0
- data/lib/opal/nodes/call.rb +107 -26
- data/lib/opal/nodes/call_special.rb +31 -6
- data/lib/opal/nodes/class.rb +2 -2
- data/lib/opal/nodes/constants.rb +5 -20
- data/lib/opal/nodes/def.rb +4 -4
- data/lib/opal/nodes/defined.rb +3 -3
- data/lib/opal/nodes/definitions.rb +1 -1
- data/lib/opal/nodes/for.rb +35 -0
- data/lib/opal/nodes/helpers.rb +2 -2
- data/lib/opal/nodes/iter.rb +3 -3
- data/lib/opal/nodes/literal.rb +10 -2
- data/lib/opal/nodes/masgn.rb +2 -2
- data/lib/opal/nodes/module.rb +2 -2
- data/lib/opal/nodes/scope.rb +1 -0
- data/lib/opal/nodes/singleton_class.rb +2 -2
- data/lib/opal/nodes/super.rb +2 -2
- data/lib/opal/nodes/top.rb +30 -3
- data/lib/opal/parser.rb +15 -1
- data/lib/opal/parser/grammar.rb +2571 -2452
- data/lib/opal/parser/grammar.y +37 -5
- data/lib/opal/parser/keywords.rb +2 -0
- data/lib/opal/parser/lexer.rb +21 -11
- data/lib/opal/path_reader.rb +28 -0
- data/lib/opal/paths.rb +38 -0
- data/lib/opal/source_map.rb +32 -15
- data/lib/opal/sprockets/environment.rb +9 -2
- data/lib/opal/sprockets/erb.rb +1 -2
- data/lib/opal/sprockets/path_reader.rb +34 -0
- data/lib/opal/sprockets/processor.rb +40 -39
- data/lib/opal/sprockets/server.rb +47 -33
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +10 -5
- data/opal/README.md +6 -0
- data/opal/corelib/array.rb +36 -4
- data/opal/corelib/array/inheritance.rb +6 -6
- data/opal/corelib/basic_object.rb +9 -9
- data/opal/corelib/boolean.rb +1 -1
- data/opal/corelib/class.rb +12 -12
- data/opal/corelib/dir.rb +20 -0
- data/opal/corelib/enumerable.rb +42 -42
- data/opal/corelib/enumerator.rb +1 -1
- data/opal/corelib/error.rb +2 -2
- data/opal/corelib/file.rb +56 -0
- data/opal/corelib/hash.rb +5 -5
- data/opal/corelib/helpers.rb +3 -3
- data/opal/corelib/io.rb +13 -10
- data/opal/corelib/kernel.rb +44 -68
- data/opal/corelib/method.rb +1 -1
- data/opal/corelib/module.rb +89 -114
- data/opal/corelib/nil_class.rb +1 -1
- data/opal/corelib/numeric.rb +27 -23
- data/opal/corelib/proc.rb +5 -5
- data/opal/corelib/range.rb +8 -4
- data/opal/corelib/regexp.rb +5 -5
- data/opal/corelib/runtime.js +589 -272
- data/opal/corelib/string.rb +52 -37
- data/opal/corelib/string/inheritance.rb +5 -5
- data/opal/corelib/time.rb +102 -52
- data/opal/corelib/variables.rb +3 -3
- data/opal/opal.rb +2 -0
- data/package.json +9 -0
- data/spec/filters/bugs/array.rb +0 -6
- data/spec/filters/bugs/language.rb +4 -0
- data/spec/filters/bugs/numeric.rb +7 -6
- data/spec/filters/bugs/opal.rb +2 -0
- data/spec/filters/bugs/regexp.rb +4 -0
- data/spec/filters/bugs/string.rb +0 -7
- data/spec/filters/bugs/stringscanner.rb +4 -1
- data/spec/filters/unsupported/private_methods.rb +2 -0
- data/spec/lib/builder_processors_spec.rb +27 -0
- data/spec/lib/builder_spec.rb +66 -0
- data/spec/{cli → lib}/cli_spec.rb +60 -5
- data/spec/{cli → lib}/compiler_spec.rb +66 -5
- data/spec/{cli → lib}/dependency_resolver_spec.rb +1 -1
- data/spec/lib/fixtures/no_requires.rb +1 -0
- data/spec/{cli → lib}/fixtures/opal_file.rb +0 -0
- data/spec/lib/fixtures/require_tree_test.rb +3 -0
- data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
- data/spec/lib/fixtures/requires.rb +7 -0
- data/spec/{cli → lib}/fixtures/sprockets_file.js.rb +0 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/hike_path_finder_spec.rb +23 -0
- data/spec/{cli → lib}/lexer_spec.rb +1 -1
- data/spec/{cli → lib}/parser/alias_spec.rb +1 -1
- data/spec/{cli → lib}/parser/and_spec.rb +1 -1
- data/spec/{cli → lib}/parser/attrasgn_spec.rb +1 -1
- data/spec/{cli → lib}/parser/begin_spec.rb +1 -1
- data/spec/{cli → lib}/parser/block_spec.rb +1 -1
- data/spec/{cli → lib}/parser/break_spec.rb +1 -1
- data/spec/{cli → lib}/parser/call_spec.rb +1 -1
- data/spec/{cli → lib}/parser/class_spec.rb +1 -1
- data/spec/{cli → lib}/parser/comments_spec.rb +1 -1
- data/spec/{cli → lib}/parser/def_spec.rb +1 -1
- data/spec/{cli → lib}/parser/if_spec.rb +1 -1
- data/spec/{cli → lib}/parser/iter_spec.rb +1 -1
- data/spec/{cli → lib}/parser/lambda_spec.rb +1 -1
- data/spec/{cli → lib}/parser/literal_spec.rb +1 -1
- data/spec/{cli → lib}/parser/masgn_spec.rb +1 -1
- data/spec/{cli → lib}/parser/module_spec.rb +1 -1
- data/spec/{cli → lib}/parser/not_spec.rb +1 -1
- data/spec/{cli → lib}/parser/op_asgn1_spec.rb +1 -1
- data/spec/{cli → lib}/parser/op_asgn2_spec.rb +1 -1
- data/spec/{cli → lib}/parser/or_spec.rb +1 -1
- data/spec/{cli → lib}/parser/return_spec.rb +1 -1
- data/spec/{cli → lib}/parser/sclass_spec.rb +1 -1
- data/spec/{cli → lib}/parser/string_spec.rb +8 -1
- data/spec/{cli → lib}/parser/super_spec.rb +1 -1
- data/spec/lib/parser/unary_spec.rb +48 -0
- data/spec/{cli → lib}/parser/undef_spec.rb +1 -1
- data/spec/{cli → lib}/parser/unless_spec.rb +1 -1
- data/spec/{cli → lib}/parser/variables_spec.rb +1 -1
- data/spec/{cli → lib}/parser/while_spec.rb +1 -1
- data/spec/{cli → lib}/parser/yield_spec.rb +1 -1
- data/spec/lib/path_reader_spec.rb +24 -0
- data/spec/lib/shared/path_finder_shared.rb +19 -0
- data/spec/lib/shared/path_reader_shared.rb +31 -0
- data/spec/lib/spec_helper.rb +9 -0
- data/spec/lib/sprockets/environment_spec.rb +30 -0
- data/spec/{cli → lib}/sprockets/erb_spec.rb +1 -1
- data/spec/lib/sprockets/path_reader_spec.rb +25 -0
- data/spec/{cli → lib}/sprockets/processor_spec.rb +9 -2
- data/spec/lib/sprockets/server_spec.rb +20 -0
- data/spec/opal/compiler/irb_spec.rb +11 -11
- data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +7 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +2 -2
- data/spec/opal/core/runtime/method_missing_spec.rb +19 -0
- data/spec/opal/core/source_map_spec.rb +2 -2
- data/spec/opal/core/string_spec.rb +11 -0
- data/spec/opal/stdlib/erb/erb_spec.rb +0 -1
- data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
- data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
- data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
- data/spec/rubyspecs +54 -11
- data/spec/spec_helper.rb +18 -3
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/{cli/spec_helper.rb → support/parser_helpers.rb} +10 -10
- data/stdlib/README.md +3 -0
- data/stdlib/benchmark.rb +10 -0
- data/stdlib/date.rb +2 -2
- data/stdlib/dir.rb +1 -5
- data/stdlib/file.rb +1 -7
- data/stdlib/json.rb +10 -1
- data/stdlib/native.rb +5 -5
- data/stdlib/nodejs.rb +5 -0
- data/stdlib/nodejs/dir.rb +13 -0
- data/stdlib/nodejs/file.rb +98 -0
- data/stdlib/nodejs/fileutils.rb +26 -0
- data/stdlib/nodejs/io.rb +2 -0
- data/stdlib/nodejs/irb.rb +45 -0
- data/stdlib/nodejs/process.rb +16 -0
- data/stdlib/nodejs/require.rb +32 -0
- data/stdlib/nodejs/rubygems.rb +68 -0
- data/stdlib/nodejs/runtime.rb +25 -0
- data/stdlib/nodejs/yaml.rb +11 -0
- data/stdlib/opal-parser.rb +1 -2
- data/stdlib/opal-source-maps.rb +2 -0
- data/stdlib/phantomjs.rb +8 -0
- data/stdlib/process.rb +10 -0
- data/stdlib/promise.rb +12 -4
- data/stdlib/set.rb +27 -0
- data/stdlib/source_map.rb +5 -63
- data/stdlib/source_map/map.rb +220 -0
- data/stdlib/source_map/mapping.rb +26 -0
- data/stdlib/source_map/offset.rb +88 -0
- data/stdlib/source_map/version.rb +3 -0
- data/stdlib/source_map/vlq.rb +77 -101
- data/stdlib/sourcemap.rb +1 -0
- data/stdlib/strscan.rb +7 -1
- data/stdlib/template.rb +1 -1
- data/stdlib/thread.rb +147 -7
- metadata +238 -104
- data/lib/mspec/opal/mspec_fixes.rb +0 -87
- data/spec/cli/sprockets/environment_spec.rb +0 -14
- data/spec/filters/bugs/symbol.rb +0 -5
- data/spec/opal/core/kernel/warn_spec.rb +0 -83
- data/spec/opal/core/language/numbers_spec.rb +0 -60
- data/stdlib/opal-source-maps.js.erb +0 -2
- data/stdlib/source_map/generator.rb +0 -251
- data/stdlib/source_map/parser.rb +0 -102
data/opal/corelib/enumerator.rb
CHANGED
data/opal/corelib/error.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
class File < IO
|
2
|
+
Separator = SEPARATOR = '/'
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def expand_path(path, basedir = nil)
|
6
|
+
path = [basedir, path].compact.join(SEPARATOR)
|
7
|
+
parts = path.split(SEPARATOR)
|
8
|
+
new_parts = []
|
9
|
+
parts[0] = Dir.home if parts.first == '~'
|
10
|
+
|
11
|
+
parts.each do |part|
|
12
|
+
if part == '..'
|
13
|
+
new_parts.pop
|
14
|
+
else
|
15
|
+
new_parts << part
|
16
|
+
end
|
17
|
+
end
|
18
|
+
new_parts.join(SEPARATOR)
|
19
|
+
end
|
20
|
+
|
21
|
+
def dirname(path)
|
22
|
+
split(path)[0..-2]
|
23
|
+
end
|
24
|
+
|
25
|
+
def basename(path)
|
26
|
+
split(path)[-1]
|
27
|
+
end
|
28
|
+
|
29
|
+
def exist? path
|
30
|
+
`Opal.modules[#{path}] != null`
|
31
|
+
end
|
32
|
+
alias exists? exist?
|
33
|
+
|
34
|
+
def directory?(path)
|
35
|
+
files = []
|
36
|
+
%x{
|
37
|
+
for (var key in Opal.modules) {
|
38
|
+
#{files}.push(key)
|
39
|
+
}
|
40
|
+
}
|
41
|
+
path = path.gsub(%r{(^.#{SEPARATOR}+|#{SEPARATOR}+$)})
|
42
|
+
file = files.find do |file|
|
43
|
+
file =~ /^#{path}/
|
44
|
+
end
|
45
|
+
file
|
46
|
+
end
|
47
|
+
|
48
|
+
def join(*paths)
|
49
|
+
paths.join(SEPARATOR).gsub(%r{#{SEPARATOR}+}, SEPARATOR)
|
50
|
+
end
|
51
|
+
|
52
|
+
def split(path)
|
53
|
+
path.split(SEPARATOR)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/opal/corelib/hash.rb
CHANGED
@@ -9,7 +9,7 @@ class Hash
|
|
9
9
|
|
10
10
|
def self.allocate
|
11
11
|
%x{
|
12
|
-
var hash = new self
|
12
|
+
var hash = new self.$$alloc;
|
13
13
|
|
14
14
|
hash.map = {};
|
15
15
|
hash.keys = [];
|
@@ -125,7 +125,7 @@ class Hash
|
|
125
125
|
map[key] = value;
|
126
126
|
}
|
127
127
|
|
128
|
-
var hash = new self
|
128
|
+
var hash = new self.$$class.$$alloc();
|
129
129
|
|
130
130
|
hash.map = map;
|
131
131
|
hash.keys = keys;
|
@@ -313,7 +313,7 @@ class Hash
|
|
313
313
|
|
314
314
|
result.push(key);
|
315
315
|
|
316
|
-
if (value
|
316
|
+
if (value.$$is_array) {
|
317
317
|
if (level == null || level === 1) {
|
318
318
|
result.push(value);
|
319
319
|
}
|
@@ -347,7 +347,7 @@ class Hash
|
|
347
347
|
end
|
348
348
|
|
349
349
|
def hash
|
350
|
-
`self
|
350
|
+
`self.$$id`
|
351
351
|
end
|
352
352
|
|
353
353
|
alias include? has_key?
|
@@ -689,7 +689,7 @@ class Hash
|
|
689
689
|
|
690
690
|
def to_h
|
691
691
|
%x{
|
692
|
-
var hash = new Opal.Hash
|
692
|
+
var hash = new Opal.Hash.$$alloc,
|
693
693
|
cloned = #{clone};
|
694
694
|
|
695
695
|
hash.map = cloned.map;
|
data/opal/corelib/helpers.rb
CHANGED
@@ -64,7 +64,7 @@ module Opal
|
|
64
64
|
if (args.length == 1) {
|
65
65
|
return args[0];
|
66
66
|
}
|
67
|
-
else if (args
|
67
|
+
else if (args.$$is_array) {
|
68
68
|
return args;
|
69
69
|
}
|
70
70
|
else {
|
@@ -75,7 +75,7 @@ module Opal
|
|
75
75
|
|
76
76
|
def self.respond_to?(obj, method)
|
77
77
|
%x{
|
78
|
-
if (obj == null || !obj
|
78
|
+
if (obj == null || !obj.$$class) {
|
79
79
|
return false;
|
80
80
|
}
|
81
81
|
}
|
@@ -91,7 +91,7 @@ module Opal
|
|
91
91
|
else if (obj === null) {
|
92
92
|
return "null";
|
93
93
|
}
|
94
|
-
else if (!obj
|
94
|
+
else if (!obj.$$class) {
|
95
95
|
return obj.toString();
|
96
96
|
}
|
97
97
|
else {
|
data/opal/corelib/io.rb
CHANGED
@@ -3,19 +3,28 @@ class IO
|
|
3
3
|
SEEK_CUR = 1
|
4
4
|
SEEK_END = 2
|
5
5
|
|
6
|
+
attr_accessor :write_proc
|
7
|
+
|
8
|
+
def write(string)
|
9
|
+
`self.write_proc(string)`
|
10
|
+
string.size
|
11
|
+
end
|
12
|
+
|
6
13
|
module Writable
|
7
14
|
def <<(string)
|
8
15
|
write(string)
|
9
|
-
|
10
16
|
self
|
11
17
|
end
|
12
18
|
|
13
19
|
def print(*args)
|
14
20
|
write args.map { |arg| String(arg) }.join($,)
|
21
|
+
nil
|
15
22
|
end
|
16
23
|
|
17
24
|
def puts(*args)
|
18
|
-
|
25
|
+
newline = $/
|
26
|
+
write args.map { |arg| String(arg).chomp }.concat([nil]).join(newline)
|
27
|
+
nil
|
19
28
|
end
|
20
29
|
end
|
21
30
|
|
@@ -42,15 +51,9 @@ STDERR = $stderr = IO.new
|
|
42
51
|
STDIN = $stdin = IO.new
|
43
52
|
STDOUT = $stdout = IO.new
|
44
53
|
|
45
|
-
def $stdout.write(string)
|
46
|
-
`console.log(#{string.to_s});`
|
47
|
-
nil
|
48
|
-
end
|
49
54
|
|
50
|
-
|
51
|
-
|
52
|
-
nil
|
53
|
-
end
|
55
|
+
$stdout.write_proc = `typeof(process) === 'object' ? function(s){process.stdout.write(s)} : function(s){console.log(s)}`
|
56
|
+
$stderr.write_proc = `typeof(process) === 'object' ? function(s){process.stderr.write(s)} : function(s){console.warn(s)}`
|
54
57
|
|
55
58
|
$stdout.extend(IO::Writable)
|
56
59
|
$stderr.extend(IO::Writable)
|
data/opal/corelib/kernel.rb
CHANGED
@@ -25,7 +25,7 @@ module Kernel
|
|
25
25
|
%x{
|
26
26
|
var meth = self['$' + name];
|
27
27
|
|
28
|
-
if (!meth || meth
|
28
|
+
if (!meth || meth.$$stub) {
|
29
29
|
#{raise NameError, "undefined method `#{name}' for class `#{self.class.name}'"};
|
30
30
|
}
|
31
31
|
|
@@ -44,7 +44,7 @@ module Kernel
|
|
44
44
|
continue;
|
45
45
|
}
|
46
46
|
}
|
47
|
-
if (self[key]
|
47
|
+
if (self[key].$$stub === undefined) {
|
48
48
|
methods.push(key.substr(1));
|
49
49
|
}
|
50
50
|
}
|
@@ -78,16 +78,14 @@ module Kernel
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def class
|
81
|
-
`self
|
81
|
+
`self.$$class`
|
82
82
|
end
|
83
83
|
|
84
84
|
def copy_instance_variables(other)
|
85
85
|
%x{
|
86
86
|
for (var name in other) {
|
87
87
|
if (name.charAt(0) !== '$') {
|
88
|
-
|
89
|
-
self[name] = other[name];
|
90
|
-
}
|
88
|
+
self[name] = other[name];
|
91
89
|
}
|
92
90
|
}
|
93
91
|
}
|
@@ -113,11 +111,11 @@ module Kernel
|
|
113
111
|
|
114
112
|
%x{
|
115
113
|
var jsid = '$' + name;
|
116
|
-
body
|
117
|
-
body
|
118
|
-
body
|
114
|
+
body.$$jsid = name;
|
115
|
+
body.$$s = null;
|
116
|
+
body.$$def = body;
|
119
117
|
|
120
|
-
#{singleton_class}
|
118
|
+
#{singleton_class}.$$proto[jsid] = body;
|
121
119
|
|
122
120
|
return self;
|
123
121
|
}
|
@@ -204,7 +202,7 @@ module Kernel
|
|
204
202
|
switch (spec) {
|
205
203
|
case 'c':
|
206
204
|
obj = args[idx];
|
207
|
-
if (obj
|
205
|
+
if (obj.$$is_string) {
|
208
206
|
str = obj.charAt(0);
|
209
207
|
} else {
|
210
208
|
str = String.fromCharCode(#{`obj`.to_i});
|
@@ -291,7 +289,7 @@ module Kernel
|
|
291
289
|
end
|
292
290
|
|
293
291
|
def hash
|
294
|
-
`self
|
292
|
+
`self.$$id`
|
295
293
|
end
|
296
294
|
|
297
295
|
def initialize_copy(other)
|
@@ -302,7 +300,7 @@ module Kernel
|
|
302
300
|
end
|
303
301
|
|
304
302
|
def instance_of?(klass)
|
305
|
-
`self
|
303
|
+
`self.$$class === klass`
|
306
304
|
end
|
307
305
|
|
308
306
|
def instance_variable_defined?(name)
|
@@ -327,7 +325,7 @@ module Kernel
|
|
327
325
|
|
328
326
|
for (var name in self) {
|
329
327
|
if (name.charAt(0) !== '$') {
|
330
|
-
if (name !== '
|
328
|
+
if (name !== '$$class' && name !== '$$id') {
|
331
329
|
result.push('@' + name);
|
332
330
|
}
|
333
331
|
}
|
@@ -392,7 +390,7 @@ module Kernel
|
|
392
390
|
alias kind_of? is_a?
|
393
391
|
|
394
392
|
def lambda(&block)
|
395
|
-
`block
|
393
|
+
`block.$$is_lambda = true`
|
396
394
|
|
397
395
|
block
|
398
396
|
end
|
@@ -423,16 +421,17 @@ module Kernel
|
|
423
421
|
nil
|
424
422
|
end
|
425
423
|
|
426
|
-
def private_methods
|
424
|
+
def private_methods(*)
|
427
425
|
[]
|
428
426
|
end
|
427
|
+
alias private_instance_methods private_methods
|
429
428
|
|
430
429
|
def proc(&block)
|
431
430
|
unless block
|
432
431
|
raise ArgumentError, "tried to create Proc object without a block"
|
433
432
|
end
|
434
433
|
|
435
|
-
`block
|
434
|
+
`block.$$is_lambda = false`
|
436
435
|
block
|
437
436
|
end
|
438
437
|
|
@@ -452,7 +451,6 @@ module Kernel
|
|
452
451
|
|
453
452
|
def warn(*strs)
|
454
453
|
$stderr.puts(*strs) unless $VERBOSE.nil? || strs.empty?
|
455
|
-
nil
|
456
454
|
end
|
457
455
|
|
458
456
|
def raise(exception = undefined, string = undefined)
|
@@ -460,7 +458,7 @@ module Kernel
|
|
460
458
|
if (exception == null && #$!) {
|
461
459
|
exception = #$!;
|
462
460
|
}
|
463
|
-
else if (exception
|
461
|
+
else if (exception.$$is_string) {
|
464
462
|
exception = #{RuntimeError.new exception};
|
465
463
|
}
|
466
464
|
else if (!#{exception.is_a? Exception}) {
|
@@ -479,7 +477,7 @@ module Kernel
|
|
479
477
|
if (max === undefined) {
|
480
478
|
return Math.random();
|
481
479
|
}
|
482
|
-
else if (max
|
480
|
+
else if (max.$$is_range) {
|
483
481
|
var arr = #{max.to_a};
|
484
482
|
|
485
483
|
return arr[#{rand(`arr.length`)}];
|
@@ -499,7 +497,7 @@ module Kernel
|
|
499
497
|
%x{
|
500
498
|
var body = self['$' + name];
|
501
499
|
|
502
|
-
if (typeof(body) === "function" && !body
|
500
|
+
if (typeof(body) === "function" && !body.$$stub) {
|
503
501
|
return true;
|
504
502
|
}
|
505
503
|
}
|
@@ -511,52 +509,7 @@ module Kernel
|
|
511
509
|
alias public_send __send__
|
512
510
|
|
513
511
|
def singleton_class
|
514
|
-
%x{
|
515
|
-
if (self._isClass) {
|
516
|
-
if (self.__meta__) {
|
517
|
-
return self.__meta__;
|
518
|
-
}
|
519
|
-
|
520
|
-
var meta = new $opal.Class._alloc;
|
521
|
-
meta._klass = $opal.Class;
|
522
|
-
self.__meta__ = meta;
|
523
|
-
// FIXME - is this right? (probably - methods defined on
|
524
|
-
// class' singleton should also go to subclasses?)
|
525
|
-
meta._proto = self.constructor.prototype;
|
526
|
-
meta._isSingleton = true;
|
527
|
-
meta.__inc__ = [];
|
528
|
-
meta._methods = [];
|
529
|
-
|
530
|
-
meta._scope = self._scope;
|
531
|
-
|
532
|
-
return meta;
|
533
|
-
}
|
534
|
-
|
535
|
-
if (self._isClass) {
|
536
|
-
return self._klass;
|
537
|
-
}
|
538
|
-
|
539
|
-
if (self.__meta__) {
|
540
|
-
return self.__meta__;
|
541
|
-
}
|
542
|
-
|
543
|
-
else {
|
544
|
-
var orig_class = self._klass,
|
545
|
-
class_id = "#<Class:#<" + orig_class._name + ":" + orig_class._id + ">>";
|
546
|
-
|
547
|
-
var Singleton = function () {};
|
548
|
-
var meta = Opal.boot(orig_class, Singleton);
|
549
|
-
meta._name = class_id;
|
550
|
-
|
551
|
-
meta._proto = self;
|
552
|
-
self.__meta__ = meta;
|
553
|
-
meta._klass = orig_class._klass;
|
554
|
-
meta._scope = orig_class._scope;
|
555
|
-
meta.__parent = orig_class;
|
556
|
-
|
557
|
-
return meta;
|
558
|
-
}
|
559
|
-
}
|
512
|
+
%x{$opal.get_singleton_class(self)}
|
560
513
|
end
|
561
514
|
|
562
515
|
alias sprintf format
|
@@ -575,7 +528,7 @@ module Kernel
|
|
575
528
|
end
|
576
529
|
|
577
530
|
def to_s
|
578
|
-
`"#<" + #{self.class.name} + ":" + self
|
531
|
+
`"#<" + #{self.class.name} + ":" + self.$$id + ">"`
|
579
532
|
end
|
580
533
|
|
581
534
|
def freeze
|
@@ -590,4 +543,27 @@ module Kernel
|
|
590
543
|
def respond_to_missing?(method_name)
|
591
544
|
false
|
592
545
|
end
|
546
|
+
|
547
|
+
def require file
|
548
|
+
`$opal.require( $opal.normalize_loadable_path(#{file}) )`
|
549
|
+
end
|
550
|
+
|
551
|
+
# `path` should be the ful path to be found in registered modules (`Opal.modules`)
|
552
|
+
def require_tree path
|
553
|
+
%x{
|
554
|
+
var file_name, file_names = Object.keys($opal.modules);
|
555
|
+
path = path.replace(/\/?$/, '/');
|
556
|
+
for (var i = 0; i < file_names.length; i++) {
|
557
|
+
file_name = file_names[i];
|
558
|
+
if (file_name['$start_with?'](path)) {
|
559
|
+
$opal.require(file_name);
|
560
|
+
}
|
561
|
+
}
|
562
|
+
}
|
563
|
+
nil
|
564
|
+
end
|
565
|
+
|
566
|
+
def load file
|
567
|
+
`$opal.load( $opal.normalize_loadable_path(#{file}) )`
|
568
|
+
end
|
593
569
|
end
|
data/opal/corelib/method.rb
CHANGED
data/opal/corelib/module.rb
CHANGED
@@ -2,21 +2,21 @@ class Module
|
|
2
2
|
def self.new(&block)
|
3
3
|
%x{
|
4
4
|
function AnonModule(){}
|
5
|
-
var klass
|
6
|
-
klass
|
7
|
-
klass
|
8
|
-
klass
|
9
|
-
klass
|
10
|
-
klass
|
5
|
+
var klass = Opal.boot(Opal.Module, AnonModule);
|
6
|
+
klass.$$name = nil;
|
7
|
+
klass.$$class = Opal.Module;
|
8
|
+
klass.$$dep = []
|
9
|
+
klass.$$is_mod = true;
|
10
|
+
klass.$$proto = {};
|
11
11
|
|
12
12
|
// inherit scope from parent
|
13
|
-
$opal.create_scope(Opal.Module
|
13
|
+
$opal.create_scope(Opal.Module.$$scope, klass);
|
14
14
|
|
15
15
|
if (block !== nil) {
|
16
|
-
var block_self = block
|
17
|
-
block
|
16
|
+
var block_self = block.$$s;
|
17
|
+
block.$$s = null;
|
18
18
|
block.call(klass);
|
19
|
-
block
|
19
|
+
block.$$s = block_self;
|
20
20
|
}
|
21
21
|
|
22
22
|
return klass;
|
@@ -38,7 +38,7 @@ class Module
|
|
38
38
|
return true;
|
39
39
|
}
|
40
40
|
|
41
|
-
working = working
|
41
|
+
working = working.$$parent;
|
42
42
|
}
|
43
43
|
|
44
44
|
return false;
|
@@ -47,9 +47,9 @@ class Module
|
|
47
47
|
|
48
48
|
def alias_method(newname, oldname)
|
49
49
|
%x{
|
50
|
-
self
|
50
|
+
self.$$proto['$' + newname] = self.$$proto['$' + oldname];
|
51
51
|
|
52
|
-
if (self
|
52
|
+
if (self.$$methods) {
|
53
53
|
$opal.donate(self, ['$' + newname ])
|
54
54
|
}
|
55
55
|
}
|
@@ -57,7 +57,7 @@ class Module
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def alias_native(mid, jsid = mid)
|
60
|
-
`self
|
60
|
+
`self.$$proto['$' + mid] = self.$$proto[jsid]`
|
61
61
|
end
|
62
62
|
|
63
63
|
def ancestors
|
@@ -67,9 +67,9 @@ class Module
|
|
67
67
|
|
68
68
|
while (parent) {
|
69
69
|
result.push(parent);
|
70
|
-
result = result.concat(parent
|
70
|
+
result = result.concat(parent.$$inc);
|
71
71
|
|
72
|
-
parent = parent
|
72
|
+
parent = parent.$$super;
|
73
73
|
}
|
74
74
|
|
75
75
|
return result;
|
@@ -77,56 +77,7 @@ class Module
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def append_features(klass)
|
80
|
-
|
81
|
-
var module = self,
|
82
|
-
included = klass.__inc__;
|
83
|
-
|
84
|
-
// check if this module is already included in the klass
|
85
|
-
for (var i = 0, length = included.length; i < length; i++) {
|
86
|
-
if (included[i] === module) {
|
87
|
-
return;
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
included.push(module);
|
92
|
-
module.__dep__.push(klass);
|
93
|
-
|
94
|
-
// iclass
|
95
|
-
var iclass = {
|
96
|
-
name: module._name,
|
97
|
-
|
98
|
-
_proto: module._proto,
|
99
|
-
__parent: klass.__parent,
|
100
|
-
__iclass: true
|
101
|
-
};
|
102
|
-
|
103
|
-
klass.__parent = iclass;
|
104
|
-
|
105
|
-
var donator = module._proto,
|
106
|
-
prototype = klass._proto,
|
107
|
-
methods = module._methods;
|
108
|
-
|
109
|
-
for (var i = 0, length = methods.length; i < length; i++) {
|
110
|
-
var method = methods[i];
|
111
|
-
|
112
|
-
if (prototype.hasOwnProperty(method) && !prototype[method]._donated) {
|
113
|
-
// if the target class already has a method of the same name defined
|
114
|
-
// and that method was NOT donated, then it must be a method defined
|
115
|
-
// by the class so we do not want to override it
|
116
|
-
}
|
117
|
-
else {
|
118
|
-
prototype[method] = donator[method];
|
119
|
-
prototype[method]._donated = true;
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
if (klass.__dep__) {
|
124
|
-
$opal.donate(klass, methods.slice(), true);
|
125
|
-
}
|
126
|
-
|
127
|
-
$opal.donate_constants(module, klass);
|
128
|
-
}
|
129
|
-
|
80
|
+
`Opal.append_features(self, klass)`
|
130
81
|
self
|
131
82
|
end
|
132
83
|
|
@@ -137,13 +88,13 @@ class Module
|
|
137
88
|
|
138
89
|
def attr_reader(*names)
|
139
90
|
%x{
|
140
|
-
var proto = self
|
91
|
+
var proto = self.$$proto, cls = self;
|
141
92
|
for (var i = 0, length = names.length; i < length; i++) {
|
142
93
|
(function(name) {
|
143
94
|
proto[name] = nil;
|
144
95
|
var func = function() { return this[name] };
|
145
96
|
|
146
|
-
if (cls
|
97
|
+
if (cls.$$is_singleton) {
|
147
98
|
proto.constructor.prototype['$' + name] = func;
|
148
99
|
}
|
149
100
|
else {
|
@@ -159,13 +110,13 @@ class Module
|
|
159
110
|
|
160
111
|
def attr_writer(*names)
|
161
112
|
%x{
|
162
|
-
var proto = self
|
113
|
+
var proto = self.$$proto, cls = self;
|
163
114
|
for (var i = 0, length = names.length; i < length; i++) {
|
164
115
|
(function(name) {
|
165
116
|
proto[name] = nil;
|
166
117
|
var func = function(value) { return this[name] = value; };
|
167
118
|
|
168
|
-
if (cls
|
119
|
+
if (cls.$$is_singleton) {
|
169
120
|
proto.constructor.prototype['$' + name + '='] = func;
|
170
121
|
}
|
171
122
|
else {
|
@@ -180,8 +131,21 @@ class Module
|
|
180
131
|
|
181
132
|
alias attr attr_accessor
|
182
133
|
|
134
|
+
def autoload(const, path)
|
135
|
+
%x{
|
136
|
+
var autoloaders;
|
137
|
+
|
138
|
+
if (!(autoloaders = self.$$autoload)) {
|
139
|
+
autoloaders = self.$$autoload = {};
|
140
|
+
}
|
141
|
+
|
142
|
+
autoloaders[#{const}] = #{path};
|
143
|
+
return nil;
|
144
|
+
}
|
145
|
+
end
|
146
|
+
|
183
147
|
def constants
|
184
|
-
`self.
|
148
|
+
`self.$$scope.constants`
|
185
149
|
end
|
186
150
|
|
187
151
|
# check for constant within current scope
|
@@ -190,12 +154,12 @@ class Module
|
|
190
154
|
raise NameError, "wrong constant name #{name}" unless name =~ /^[A-Z]\w*$/
|
191
155
|
|
192
156
|
%x{
|
193
|
-
scopes = [self
|
157
|
+
scopes = [self.$$scope];
|
194
158
|
if (inherit || self === Opal.Object) {
|
195
|
-
var parent = self
|
159
|
+
var parent = self.$$super;
|
196
160
|
while (parent !== Opal.BasicObject) {
|
197
|
-
scopes.push(parent
|
198
|
-
parent = parent
|
161
|
+
scopes.push(parent.$$scope);
|
162
|
+
parent = parent.$$super;
|
199
163
|
}
|
200
164
|
}
|
201
165
|
|
@@ -213,12 +177,12 @@ class Module
|
|
213
177
|
raise NameError, "wrong constant name #{name}" unless name =~ /^[A-Z]\w*$/
|
214
178
|
|
215
179
|
%x{
|
216
|
-
var scopes = [self
|
180
|
+
var scopes = [self.$$scope];
|
217
181
|
if (inherit || self == Opal.Object) {
|
218
|
-
var parent = self
|
182
|
+
var parent = self.$$super;
|
219
183
|
while (parent !== Opal.BasicObject) {
|
220
|
-
scopes.push(parent
|
221
|
-
parent = parent
|
184
|
+
scopes.push(parent.$$scope);
|
185
|
+
parent = parent.$$super;
|
222
186
|
}
|
223
187
|
}
|
224
188
|
|
@@ -233,7 +197,16 @@ class Module
|
|
233
197
|
end
|
234
198
|
|
235
199
|
def const_missing(const)
|
236
|
-
|
200
|
+
%x{
|
201
|
+
var autoloader;
|
202
|
+
|
203
|
+
if (self.$$autoload && (autoloader = self.$$autoload[#{const}])) {
|
204
|
+
self.$require(autoloader);
|
205
|
+
return self.$$scope.get(#{const});
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
name = `self.$$name`
|
237
210
|
|
238
211
|
raise NameError, "uninitialized constant #{name}::#{const}"
|
239
212
|
end
|
@@ -264,11 +237,11 @@ class Module
|
|
264
237
|
}
|
265
238
|
|
266
239
|
var jsid = '$' + name;
|
267
|
-
block
|
268
|
-
block
|
269
|
-
block
|
240
|
+
block.$$jsid = name;
|
241
|
+
block.$$s = null;
|
242
|
+
block.$$def = block;
|
270
243
|
|
271
|
-
self
|
244
|
+
self.$$proto[jsid] = block;
|
272
245
|
$opal.donate(self, [jsid]);
|
273
246
|
|
274
247
|
return name;
|
@@ -278,8 +251,8 @@ class Module
|
|
278
251
|
def remove_method(name)
|
279
252
|
%x{
|
280
253
|
var jsid = '$' + name;
|
281
|
-
var current = self
|
282
|
-
delete self
|
254
|
+
var current = self.$$proto[jsid];
|
255
|
+
delete self.$$proto[jsid];
|
283
256
|
|
284
257
|
// Check if we need to reverse $opal.donate
|
285
258
|
// $opal.retire(self, [jsid]);
|
@@ -307,8 +280,8 @@ class Module
|
|
307
280
|
def include?(mod)
|
308
281
|
%x{
|
309
282
|
for (var cls = self; cls; cls = cls.parent) {
|
310
|
-
for (var i = 0; i != cls.
|
311
|
-
var mod2 = cls
|
283
|
+
for (var i = 0; i != cls.$$inc.length; i++) {
|
284
|
+
var mod2 = cls.$$inc[i];
|
312
285
|
if (mod === mod2) {
|
313
286
|
return true;
|
314
287
|
}
|
@@ -320,9 +293,9 @@ class Module
|
|
320
293
|
|
321
294
|
def instance_method(name)
|
322
295
|
%x{
|
323
|
-
var meth = self
|
296
|
+
var meth = self.$$proto['$' + name];
|
324
297
|
|
325
|
-
if (!meth || meth
|
298
|
+
if (!meth || meth.$$stub) {
|
326
299
|
#{raise NameError, "undefined method `#{name}' for class `#{self.name}'"};
|
327
300
|
}
|
328
301
|
|
@@ -332,14 +305,14 @@ class Module
|
|
332
305
|
|
333
306
|
def instance_methods(include_super = false)
|
334
307
|
%x{
|
335
|
-
var methods = [], proto = self
|
308
|
+
var methods = [], proto = self.$$proto;
|
336
309
|
|
337
|
-
for (var prop in self
|
310
|
+
for (var prop in self.$$proto) {
|
338
311
|
if (!include_super && !proto.hasOwnProperty(prop)) {
|
339
312
|
continue;
|
340
313
|
}
|
341
314
|
|
342
|
-
if (!include_super && proto[prop]
|
315
|
+
if (!include_super && proto[prop].$$donated) {
|
343
316
|
continue;
|
344
317
|
}
|
345
318
|
|
@@ -362,12 +335,12 @@ class Module
|
|
362
335
|
raise ArgumentError, 'no block given' unless block
|
363
336
|
|
364
337
|
%x{
|
365
|
-
var old = block
|
338
|
+
var old = block.$$s,
|
366
339
|
result;
|
367
340
|
|
368
|
-
block
|
341
|
+
block.$$s = null;
|
369
342
|
result = block.call(self);
|
370
|
-
block
|
343
|
+
block.$$s = old;
|
371
344
|
|
372
345
|
return result;
|
373
346
|
}
|
@@ -381,11 +354,11 @@ class Module
|
|
381
354
|
throw new Error("no block given");
|
382
355
|
}
|
383
356
|
|
384
|
-
var block_self = block
|
357
|
+
var block_self = block.$$s, result;
|
385
358
|
|
386
|
-
block
|
359
|
+
block.$$s = null;
|
387
360
|
result = block.apply(self, $slice.call(arguments));
|
388
|
-
block
|
361
|
+
block.$$s = block_self;
|
389
362
|
|
390
363
|
return result;
|
391
364
|
}
|
@@ -395,15 +368,15 @@ class Module
|
|
395
368
|
|
396
369
|
def method_defined?(method)
|
397
370
|
%x{
|
398
|
-
var body = self
|
399
|
-
return (!!body) && !body
|
371
|
+
var body = self.$$proto['$' + method];
|
372
|
+
return (!!body) && !body.$$stub;
|
400
373
|
}
|
401
374
|
end
|
402
375
|
|
403
376
|
def module_function(*methods)
|
404
377
|
%x{
|
405
378
|
for (var i = 0, length = methods.length; i < length; i++) {
|
406
|
-
var meth = methods[i], func = self
|
379
|
+
var meth = methods[i], func = self.$$proto['$' + meth];
|
407
380
|
|
408
381
|
self.constructor.prototype['$' + meth] = func;
|
409
382
|
}
|
@@ -414,20 +387,20 @@ class Module
|
|
414
387
|
|
415
388
|
def name
|
416
389
|
%x{
|
417
|
-
if (self
|
418
|
-
return self
|
390
|
+
if (self.$$full_name) {
|
391
|
+
return self.$$full_name;
|
419
392
|
}
|
420
393
|
|
421
394
|
var result = [], base = self;
|
422
395
|
|
423
396
|
while (base) {
|
424
|
-
if (base
|
397
|
+
if (base.$$name === nil) {
|
425
398
|
return result.length === 0 ? nil : result.join('::');
|
426
399
|
}
|
427
400
|
|
428
|
-
result.unshift(base
|
401
|
+
result.unshift(base.$$name);
|
429
402
|
|
430
|
-
base = base
|
403
|
+
base = base.$$base_module;
|
431
404
|
|
432
405
|
if (base === $opal.Object) {
|
433
406
|
break;
|
@@ -438,19 +411,21 @@ class Module
|
|
438
411
|
return nil;
|
439
412
|
}
|
440
413
|
|
441
|
-
return self
|
414
|
+
return self.$$full_name = result.join('::');
|
442
415
|
}
|
443
416
|
end
|
444
417
|
|
445
418
|
def public(*)
|
446
419
|
end
|
447
420
|
|
421
|
+
alias private public
|
422
|
+
alias protected public
|
423
|
+
alias nesting public
|
424
|
+
|
448
425
|
def private_class_method(name)
|
449
426
|
`self['$' + name] || nil`
|
450
427
|
end
|
451
|
-
|
452
|
-
alias private public
|
453
|
-
alias protected public
|
428
|
+
alias public_class_method private_class_method
|
454
429
|
|
455
430
|
def private_method_defined?(obj)
|
456
431
|
false
|
@@ -470,8 +445,8 @@ class Module
|
|
470
445
|
|
471
446
|
def remove_const(name)
|
472
447
|
%x{
|
473
|
-
var old = self
|
474
|
-
delete self
|
448
|
+
var old = self.$$scope[name];
|
449
|
+
delete self.$$scope[name];
|
475
450
|
return old;
|
476
451
|
}
|
477
452
|
end
|
@@ -481,7 +456,7 @@ class Module
|
|
481
456
|
end
|
482
457
|
|
483
458
|
def undef_method(symbol)
|
484
|
-
`$opal.add_stub_for(self
|
459
|
+
`$opal.add_stub_for(self.$$proto, "$" + symbol)`
|
485
460
|
self
|
486
461
|
end
|
487
462
|
end
|