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 7d7ef7f

Browse files
committedSep 11, 2014
[snapshot]
1 parent 0084425 commit 7d7ef7f

File tree

5 files changed

+2110
-74
lines changed

5 files changed

+2110
-74
lines changed
 

Diff for: ‎benchmarks/class_boundaries.coffee

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
rb_create_class = (name, superclass = null) ->
3+
class TopProto
4+
class BottomProto extends TopProto
5+
6+
rb_klass = {
7+
top_proto: TopProto
8+
bottom_proto: BottomProto
9+
superclass: null
10+
included_modules: []
11+
}
12+
13+
rb_update_inheritance_chain(rb_klass)
14+
15+
return rb_klass
16+
17+
18+
rb_include = (klass, module) ->
19+
klass.included_modules.push module
20+
klass.update_modules
21+
22+
rb_update_inheritance_chain(klass)
23+
module_copies_list = [klass.top_proto]
24+
klass.included_modules.each (module)->
25+
module_copy = duplicate_module(module)
26+
set_super_prototype(base: module_copy, parent: module_copies_list.last())
27+
set_super_prototype(base: klass.bottom_proto, parent: module_copies_list.last())
28+
29+
set_super_prototype(kwargs)
30+
base = kwargs.base
31+
parent = kwargs.parent
32+
base.prototype
33+
34+
duplicate_module(module)->
35+
module_copy = {}
36+
for method in module
37+
module_copy[method] = module[method]
38+
module_copy

Diff for: ‎opal/corelib/class.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ def self.new(sup = Object, &block)
88
}
99
1010
function AnonClass(){};
11-
var klass = Opal.boot(sup, AnonClass)
12-
klass.$$name = nil;
13-
klass.$$parent = sup;
11+
var klass = Opal.boot(sup, AnonClass)
12+
klass.$$name = nil;
13+
klass.$$parent = sup;
1414
1515
// inherit scope from parent
1616
$opal.create_scope(sup.$$scope, klass);

Diff for: ‎opal/corelib/module.rb

+2-50
Original file line numberDiff line numberDiff line change
@@ -77,56 +77,8 @@ def ancestors
7777
end
7878

7979
def append_features(klass)
80-
%x{
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+
raise TypeError unless Class === klass
81+
`$opal.rb_include_module(klass, self)`
13082
self
13183
end
13284

Diff for: ‎opal/corelib/runtime.js

+73-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function(undefined) {
22
// The Opal object that is exposed globally
3-
var Opal = this.Opal = {};
3+
var Opal = this.Opal = {}, $opal = Opal;
44

55
// All bridged classes - keep track to donate methods from Object
66
var bridged_classes = Opal.bridged_classes = [];
@@ -395,6 +395,67 @@
395395
}
396396
};
397397

398+
399+
function copy_methods(source, target) {
400+
for (method in source) {
401+
if ($hasOwn.call(source, method)) {
402+
target[method] = source[method];
403+
}
404+
}
405+
}
406+
407+
408+
// iclass:
409+
// The ghost class that sits in the inheritance chain
410+
// of a class that has included the module.
411+
// It has all module methods.
412+
//
413+
function boot_iclass(module, klass_parent_ctor) {
414+
var iclass_proto = new klass_parent_ctor();
415+
copy_methods(module.$$proto, iclass_proto)
416+
var iclass = {
417+
name: module.$$name,
418+
$$proto: iclass_proto,
419+
$$iclass_of: module
420+
};
421+
422+
return iclass;
423+
}
424+
425+
426+
Opal.rb_include_module = function rb_include_module(klass, module) {
427+
var included = klass.$$inc;
428+
429+
// ignore if the module included already in superclasses
430+
for (var i = 0, length = included.length; i < length; i++) {
431+
if (included[i] === module) {
432+
return;
433+
}
434+
}
435+
436+
included.push(module);
437+
module.$$dep.push(klass);
438+
439+
var iclass_parent_ctor = function() {};
440+
iclass_parent_ctor.prototype = klass.$$parent.$$proto;
441+
442+
var iclass = boot_iclass(module, iclass_parent_ctor)
443+
444+
iclass.$$parent = klass.$$parent;
445+
klass.$$parent = iclass;
446+
klass.$$proto.constructor.prototype = iclass.$$proto
447+
448+
// var donator = module.$$proto,
449+
// prototype = klass.$$proto,
450+
// methods = module.$$methods;
451+
//
452+
if (klass.$$dep) {
453+
$opal.donate(iclass, methods.slice(), true);
454+
}
455+
456+
$opal.donate_constants(module, klass);
457+
};
458+
398459
/*
399460
* Methods stubs are used to facilitate method_missing in opal. A stub is a
400461
* placeholder function which just calls `method_missing` on the receiver.
@@ -687,26 +748,17 @@
687748
/**
688749
* Donate methods for a class/module
689750
*/
690-
Opal.donate = function(klass, defined, indirect) {
691-
var methods = klass.$$methods, included_in = klass.$$dep;
692-
693-
// if (!indirect) {
694-
klass.$$methods = methods.concat(defined);
695-
// }
696-
697-
if (included_in) {
698-
for (var i = 0, length = included_in.length; i < length; i++) {
699-
var includee = included_in[i];
700-
var dest = includee.$$proto;
701-
702-
for (var j = 0, jj = defined.length; j < jj; j++) {
703-
var method = defined[j];
704-
dest[method] = klass.$$proto[method];
705-
dest[method].$$donated = true;
706-
}
707-
708-
if (includee.$$dep) {
709-
Opal.donate(includee, defined, true);
751+
Opal.donate = function(module, methods) {
752+
var deps = module.$$dep, target, proto = module.$$proto;
753+
console.log('DONATE', module.$$name, methods, deps == null);
754+
if (deps == null) return;
755+
756+
for (method in proto) {
757+
if (!method.$$donated && $hasOwn.call(proto, method)) {
758+
method.$$donated = true
759+
for (var i = deps.length - 1; i >= 0; i--) {
760+
target = deps[i].$$proto;
761+
target[method] = proto[method];
710762
}
711763
}
712764
}

Diff for: ‎puts.js

+1,994
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.