Skip to content

Commit dd76afc

Browse files
committedNov 27, 2014
Only donate methods inside the runtime
1 parent ae79ecd commit dd76afc

File tree

3 files changed

+10
-41
lines changed

3 files changed

+10
-41
lines changed
 

‎lib/opal/nodes/module.rb

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def compile
2424

2525
line scope.to_vars
2626
line body_code
27-
line scope.to_donate_methods
2827
end
2928

3029
line "})(", base, ")"

‎lib/opal/nodes/scope.rb

-17
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,6 @@ def proto
110110
"def"
111111
end
112112

113-
# A scope donates its methods if it is a module, or the core Object
114-
# class. Modules donate their methods to classes or objects they are
115-
# included in. Object donates methods to bridged classes whose native
116-
# prototypes do not actually inherit from Opal.Object.prototype.
117-
def should_donate?
118-
@type == :module
119-
end
120-
121113
##
122114
# Vars to use inside each scope
123115
def to_vars
@@ -148,15 +140,6 @@ def to_vars
148140
fragment(result)
149141
end
150142

151-
# Generates code for this module to donate methods
152-
def to_donate_methods
153-
if should_donate? and !@methods.empty?
154-
fragment("%s;Opal.donate(self, [%s]);" % [@compiler.parser_indent, @methods.map(&:inspect).join(', ')])
155-
else
156-
fragment("")
157-
end
158-
end
159-
160143
def add_scope_ivar(ivar)
161144
if def_in_class?
162145
@parent.add_proto_ivar ivar

‎opal/corelib/module.rb

+10-23
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ def <(other)
4747

4848
def alias_method(newname, oldname)
4949
%x{
50-
self.$$proto['$' + newname] = self.$$proto['$' + oldname];
51-
52-
if (self.$$methods) {
53-
Opal.donate(self, ['$' + newname ])
54-
}
50+
Opal.defn(self, '$' + newname, self.$$proto['$' + oldname]);
5551
}
5652
self
5753
end
@@ -88,18 +84,16 @@ def attr_accessor(*names)
8884

8985
def attr_reader(*names)
9086
%x{
91-
var proto = self.$$proto, cls = self;
9287
for (var i = 0, length = names.length; i < length; i++) {
9388
(function(name) {
94-
proto[name] = nil;
89+
self.$$proto[name] = nil;
9590
var func = function() { return this[name] };
9691
97-
if (cls.$$is_singleton) {
98-
proto.constructor.prototype['$' + name] = func;
92+
if (self.$$is_singleton) {
93+
self.$$proto.constructor.prototype['$' + name] = func;
9994
}
10095
else {
101-
proto['$' + name] = func;
102-
Opal.donate(self, ['$' + name ]);
96+
Opal.defn(self, '$' + name, func);
10397
}
10498
})(names[i]);
10599
}
@@ -110,18 +104,16 @@ def attr_reader(*names)
110104

111105
def attr_writer(*names)
112106
%x{
113-
var proto = self.$$proto, cls = self;
114107
for (var i = 0, length = names.length; i < length; i++) {
115108
(function(name) {
116-
proto[name] = nil;
109+
self.$$proto[name] = nil;
117110
var func = function(value) { return this[name] = value; };
118111
119-
if (cls.$$is_singleton) {
120-
proto.constructor.prototype['$' + name + '='] = func;
112+
if (self.$$is_singleton) {
113+
self.$$proto.constructor.prototype['$' + name + '='] = func;
121114
}
122115
else {
123-
proto['$' + name + '='] = func;
124-
Opal.donate(self, ['$' + name + '=']);
116+
Opal.defn(self, '$' + name + '=', func);
125117
}
126118
})(names[i]);
127119
}
@@ -241,12 +233,7 @@ def define_method(name, method = undefined, &block)
241233
block.$$s = null;
242234
block.$$def = block;
243235
244-
if (self.$$is_mod) {
245-
block.$$owner = obj;
246-
}
247-
248-
self.$$proto[jsid] = block;
249-
Opal.donate(self, [jsid]);
236+
Opal.defn(self, jsid, block);
250237
251238
return name;
252239
}

0 commit comments

Comments
 (0)
Please sign in to comment.