Skip to content

Commit 1765c8c

Browse files
committedNov 13, 2013
Generate named function inside class body with '$' prefix
1 parent 8c1ce51 commit 1765c8c

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed
 

‎lib/opal/nodes/class.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ def compile
1212
helper :klass
1313

1414
push "(function($base, $super) {"
15-
line " function #{name}(){};"
16-
line " var self = #{name} = $klass($base, $super, '#{name}', #{name});"
15+
line " function $#{name}(){};"
16+
line " var self = $#{name} = $klass($base, $super, '#{name}', $#{name});"
1717

1818
in_scope(:class) do
1919
scope.name = name
20-
add_temp "#{scope.proto} = #{name}._proto"
21-
add_temp "$scope = #{name}._scope"
20+
add_temp "#{scope.proto} = $#{name}._proto"
21+
add_temp "$scope = $#{name}._scope"
2222

2323
body_code = self.body_code
2424
empty_line

‎lib/opal/nodes/super.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def compile_dispatcher
1818
if scope.def?
1919
scope.uses_block!
2020
scope_name = scope.identify!
21-
class_name = scope.parent.name || 'self._klass._proto'
21+
class_name = scope.parent.name ? "$#{scope.parent.name}" : 'self._klass._proto'
2222

2323
if scope.defs
2424
push "$opal.find_super_dispatcher(self, '#{scope.mid.to_s}', #{scope_name}, "

‎opal/core/hash.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ def to_a
664664

665665
def to_h
666666
%x{
667-
var hash = new Hash._alloc,
667+
var hash = new Opal.Hash._alloc,
668668
cloned = #{clone};
669669
670670
hash.map = cloned.map;

‎opal/core/module.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ class Module
22
def self.new(&block)
33
%x{
44
function AnonModule(){}
5-
var klass = Opal.boot(Module, AnonModule);
5+
var klass = Opal.boot(Opal.Module, AnonModule);
66
klass._name = nil;
7-
klass._klass = Module;
7+
klass._klass = Opal.Module;
88
klass.__dep__ = []
99
klass.__mod__ = true;
1010
klass._proto = {};
1111
1212
// inherit scope from parent
13-
$opal.create_scope(Module._scope, klass);
13+
$opal.create_scope(Opal.Module._scope, klass);
1414
1515
if (block !== nil) {
1616
var block_self = block._s;

‎opal/core/range.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Range
22
include Enumerable
33

4-
`Range._proto._isRange = true;`
4+
`def._isRange = true;`
55

66
attr_reader :begin, :end
77

‎opal/core/string.rb

+10-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ class String
22
include Comparable
33

44
`def._isString = true`
5-
`var native_string = "".constructor;`
65

76
def self.try_convert(what)
87
what.to_str
@@ -11,7 +10,7 @@ def self.try_convert(what)
1110
end
1211

1312
def self.new(str = '')
14-
`new native_string(str)`
13+
`new String(str)`
1514
end
1615

1716
def %(data)
@@ -439,7 +438,7 @@ def next
439438
}
440439
441440
var initial = #{self}.substr(0, #{self}.length - 1);
442-
var last = native_string.fromCharCode(#{self}.charCodeAt(#{self}.length - 1) + 1);
441+
var last = String.fromCharCode(#{self}.charCodeAt(#{self}.length - 1) + 1);
443442
444443
return initial + last;
445444
}
@@ -466,7 +465,7 @@ def reverse
466465
def rindex(search, offset = undefined)
467466
%x{
468467
var search_type = (search == null ? Opal.NilClass : search.constructor);
469-
if (search_type != native_string && search_type != RegExp) {
468+
if (search_type != String && search_type != RegExp) {
470469
var msg = "type mismatch: " + search_type + " given";
471470
#{raise TypeError.new(`msg`)};
472471
}
@@ -481,7 +480,7 @@ def rindex(search, offset = undefined)
481480
offset = #{self}.length + offset;
482481
}
483482
484-
if (search_type == native_string) {
483+
if (search_type == String) {
485484
result = #{self}.lastIndexOf(search, offset);
486485
}
487486
else {
@@ -492,7 +491,7 @@ def rindex(search, offset = undefined)
492491
}
493492
}
494493
else {
495-
if (search_type == native_string) {
494+
if (search_type == String) {
496495
result = #{self}.lastIndexOf(search);
497496
}
498497
else {
@@ -658,7 +657,7 @@ def swapcase
658657
return $1 ? $0.toUpperCase() : $0.toLowerCase();
659658
});
660659
661-
if (#{self}.constructor === native_string) {
660+
if (#{self}.constructor === String) {
662661
return str;
663662
}
664663
@@ -761,7 +760,7 @@ def tr(from, to)
761760
var start = last_from.charCodeAt(0) + 1;
762761
var end = char.charCodeAt(0);
763762
for (var c = start; c < end; c++) {
764-
from_chars_expanded.push(native_string.fromCharCode(c));
763+
from_chars_expanded.push(String.fromCharCode(c));
765764
}
766765
from_chars_expanded.push(char);
767766
in_range = null;
@@ -807,7 +806,7 @@ def tr(from, to)
807806
var start = last_from.charCodeAt(0) + 1;
808807
var end = char.charCodeAt(0);
809808
for (var c = start; c < end; c++) {
810-
to_chars_expanded.push(native_string.fromCharCode(c));
809+
to_chars_expanded.push(String.fromCharCode(c));
811810
}
812811
to_chars_expanded.push(char);
813812
in_range = null;
@@ -896,7 +895,7 @@ def tr_s(from, to)
896895
var start = last_from.charCodeAt(0) + 1;
897896
var end = char.charCodeAt(0);
898897
for (var c = start; c < end; c++) {
899-
from_chars_expanded.push(native_string.fromCharCode(c));
898+
from_chars_expanded.push(String.fromCharCode(c));
900899
}
901900
from_chars_expanded.push(char);
902901
in_range = null;
@@ -942,7 +941,7 @@ def tr_s(from, to)
942941
var start = last_from.charCodeAt(0) + 1;
943942
var end = char.charCodeAt(0);
944943
for (var c = start; c < end; c++) {
945-
to_chars_expanded.push(native_string.fromCharCode(c));
944+
to_chars_expanded.push(String.fromCharCode(c));
946945
}
947946
to_chars_expanded.push(char);
948947
in_range = null;

0 commit comments

Comments
 (0)
Please sign in to comment.