Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 76ef2f3

Browse files
committedOct 18, 2014
WIP
1 parent fa7e6f8 commit 76ef2f3

15 files changed

+210
-187
lines changed
 

‎lib/opal/nodes/def.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def compile
9999
if recvr
100100
unshift '$opal.defs(', recv(recvr), ", '$#{mid}', "
101101
push ')'
102-
elsif scope.class? and %w(Object BasicObject).include?(scope.name)
102+
elsif scope.class?
103103
wrap "$opal.defn(self, '$#{mid}', ", ')'
104104
elsif scope.class_scope?
105105
scope.methods << "$#{mid}"

‎opal/corelib/array.rb

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
require 'corelib/enumerable'
22

3-
class Array
4-
include Enumerable
5-
6-
# Mark all javascript arrays as being valid ruby arrays
3+
class Array < `Array`
74
`def.$$is_array = true`
85

96
def self.[](*objects)
@@ -672,6 +669,8 @@ def drop(number)
672669

673670
alias dup clone
674671

672+
include Enumerable
673+
675674
def each(&block)
676675
return enum_for :each unless block_given?
677676

@@ -968,7 +967,7 @@ def insert(index, *objects)
968967
index += self.length + 1;
969968
970969
if (index < 0) {
971-
#{ raise IndexError, "#{index} is out of bounds" };
970+
#{raise IndexError, "#{index} is out of bounds"};
972971
}
973972
}
974973
if (index > self.length) {
@@ -986,21 +985,21 @@ def insert(index, *objects)
986985

987986
def inspect
988987
%x{
989-
var i, inspect, el, el_insp, length, object_id;
990-
991-
inspect = [];
992-
object_id = #{object_id};
993-
length = self.length;
994-
995-
for (i = 0; i < length; i++) {
996-
el = #{self[`i`]};
988+
var result = [],
989+
id = #{object_id};
997990
998-
// Check object_id to ensure it's not the same array get into an infinite loop
999-
el_insp = #{`el`.object_id} === object_id ? '[...]' : #{`el`.inspect};
991+
for (var i = 0, length = self.length; i < length; i++) {
992+
var item = #{self[`i`]};
1000993
1001-
inspect.push(el_insp);
994+
if (#{`item`.object_id} === id) {
995+
result.push('[...]');
996+
}
997+
else {
998+
result.push(#{`item`.inspect});
999+
}
10021000
}
1003-
return '[' + inspect.join(', ') + ']';
1001+
1002+
return '[' + result.join(', ') + ']';
10041003
}
10051004
end
10061005

‎opal/corelib/basic_object.rb

+3
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,7 @@ def instance_exec(*args, &block)
7070
def method_missing(symbol, *args, &block)
7171
Kernel.raise NoMethodError, "undefined method `#{symbol}' for BasicObject instance"
7272
end
73+
74+
def singleton_method_added(symbol)
75+
end
7376
end

‎opal/corelib/boolean.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Boolean
1+
class Boolean < `Boolean`
22
`def.$$is_boolean = true`
33

44
class << self

‎opal/corelib/comparable.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def ==(other)
1111
return true if equal?(other)
1212

1313
return false unless cmp = (self <=> other)
14-
return Comparable.normalize(cmp) == 0
14+
15+
return `#{Comparable.normalize(cmp)} == 0`
1516
rescue StandardError
1617
false
1718
end
@@ -21,31 +22,31 @@ def >(other)
2122
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
2223
end
2324

24-
Comparable.normalize(cmp) > 0
25+
`#{Comparable.normalize(cmp)} > 0`
2526
end
2627

2728
def >=(other)
2829
unless cmp = (self <=> other)
2930
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
3031
end
3132

32-
Comparable.normalize(cmp) >= 0
33+
`#{Comparable.normalize(cmp)} >= 0`
3334
end
3435

3536
def <(other)
3637
unless cmp = (self <=> other)
3738
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
3839
end
3940

40-
Comparable.normalize(cmp) < 0
41+
`#{Comparable.normalize(cmp)} < 0`
4142
end
4243

4344
def <=(other)
4445
unless cmp = (self <=> other)
4546
raise ArgumentError, "comparison of #{self.class} with #{other.class} failed"
4647
end
4748

48-
Comparable.normalize(cmp) <= 0
49+
`#{Comparable.normalize(cmp)} <= 0`
4950
end
5051

5152
def between?(min, max)

‎opal/corelib/error.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Exception
1+
class Exception < `Error`
22
attr_reader :message
33

44
def self.new(message = '')

‎opal/corelib/helpers.rb

+4
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,8 @@ def self.inspect(obj)
9999
}
100100
}
101101
end
102+
103+
def self.bridge(klass, constructor)
104+
`Opal.bridge(klass, constructor)`
105+
end
102106
end

‎opal/corelib/kernel.rb

+8-6
Original file line numberDiff line numberDiff line change
@@ -544,18 +544,20 @@ def respond_to_missing?(method_name)
544544
false
545545
end
546546

547-
def require file
548-
`$opal.require( $opal.normalize_loadable_path(#{file}) )`
547+
def require(file)
548+
`$opal.require($opal.normalize_loadable_path(#{file}))`
549549
end
550550

551-
def require_relative file
551+
def require_relative(file)
552552
file = File.expand_path File.join(`$opal.current_file`, '..', file)
553-
`$opal.require( $opal.normalize_loadable_path(#{file}) )`
553+
554+
`$opal.require($opal.normalize_loadable_path(#{file}))`
554555
end
555556

556557
# `path` should be the ful path to be found in registered modules (`Opal.modules`)
557-
def require_tree path
558+
def require_tree(path)
558559
path = File.expand_path(path)
560+
559561
%x{
560562
var file_name, file_names = Object.keys($opal.modules);
561563
path = path.replace(/\/?$/, '/');
@@ -570,6 +572,6 @@ def require_tree path
570572
end
571573

572574
def load file
573-
`$opal.load( $opal.normalize_loadable_path(#{file}) )`
575+
`$opal.load($opal.normalize_loadable_path(#{file}))`
574576
end
575577
end

‎opal/corelib/module.rb

+28-16
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,8 @@ def <(other)
4646
end
4747

4848
def alias_method(newname, oldname)
49-
%x{
50-
self.$$proto['$' + newname] = self.$$proto['$' + oldname];
49+
`self.$$proto['$' + newname] = self.$$proto['$' + oldname]`
5150

52-
if (self.$$methods) {
53-
$opal.donate(self, ['$' + newname ])
54-
}
55-
}
5651
self
5752
end
5853

@@ -178,15 +173,18 @@ def const_get(name, inherit = true)
178173

179174
%x{
180175
var scopes = [self.$$scope];
176+
181177
if (inherit || self == Opal.Object) {
182178
var parent = self.$$super;
179+
183180
while (parent !== Opal.BasicObject) {
184181
scopes.push(parent.$$scope);
182+
185183
parent = parent.$$super;
186184
}
187185
}
188186
189-
for (var i = 0, len = scopes.length; i < len; i++) {
187+
for (var i = 0, length = scopes.length; i < length; i++) {
190188
if (scopes[i].hasOwnProperty(name)) {
191189
return scopes[i][name];
192190
}
@@ -198,11 +196,14 @@ def const_get(name, inherit = true)
198196

199197
def const_missing(const)
200198
%x{
201-
var autoloader;
199+
if (self.$$autoload) {
200+
var file = self.$$autoload[#{const}];
201+
202+
if (file) {
203+
self.$require(file);
202204
203-
if (self.$$autoload && (autoloader = self.$$autoload[#{const}])) {
204-
self.$require(autoloader);
205-
return self.$$scope.get(#{const});
205+
return #{const_get const};
206+
}
206207
}
207208
}
208209

@@ -265,6 +266,10 @@ def include(*mods)
265266
for (var i = mods.length - 1; i >= 0; i--) {
266267
var mod = mods[i];
267268
269+
if (!mod.$$is_mod) {
270+
#{raise TypeError, "wrong argument type #{`mod`.class.name} (expected Module)"};
271+
}
272+
268273
if (mod === self) {
269274
continue;
270275
}
@@ -305,15 +310,22 @@ def instance_method(name)
305310

306311
def instance_methods(include_super = false)
307312
%x{
308-
var methods = [], proto = self.$$proto;
313+
var methods = [],
314+
proto = self.$$proto;
309315
310-
for (var prop in self.$$proto) {
311-
if (!include_super && !proto.hasOwnProperty(prop)) {
316+
for (var prop in proto) {
317+
if (typeof(proto[prop]) !== "function") {
312318
continue;
313319
}
314320
315-
if (!include_super && proto[prop].$$donated) {
316-
continue;
321+
if (!self.$$is_mod) {
322+
if (!include_super && !proto.hasOwnProperty(prop)) {
323+
continue;
324+
}
325+
326+
if (!include_super && proto[prop].$$donated) {
327+
continue;
328+
}
317329
}
318330
319331
if (prop.charAt(0) === '$') {

‎opal/corelib/numeric.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
require 'corelib/comparable'
22

3-
class Numeric
4-
include Comparable
5-
3+
class Numeric < `Number`
64
`def.$$is_number = true`
75

86
def coerce(other, type = :operation)
@@ -174,6 +172,8 @@ def >=(other)
174172
}
175173
end
176174

175+
include Comparable
176+
177177
def <=>(other)
178178
%x{
179179
if (other.$$is_number) {

‎opal/corelib/proc.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
class Proc
2-
`def.$$is_proc = true`
1+
class Proc < `Function`
2+
`def.$$is_proc = true`
33
`def.$$is_lambda = false`
44

55
def self.new(&block)

‎opal/corelib/regexp.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Regexp
1+
class Regexp < `RegExp`
22
`def.$$is_regexp = true`
33

44
class << self

‎opal/corelib/runtime.js

+134-132
Large diffs are not rendered by default.

‎opal/corelib/string.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'corelib/comparable'
22

3-
class String
3+
class String < `String`
44
include Comparable
55

66
`def.$$is_string = true`

‎opal/corelib/time.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'corelib/comparable'
22

3-
class Time
3+
class Time < `Date`
44
include Comparable
55

66
%x{

0 commit comments

Comments
 (0)
Please sign in to comment.