Skip to content

Commit 6bac833

Browse files
committedNov 27, 2014
Document use of iclass in append_features
1 parent f5b6c67 commit 6bac833

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed
 

‎opal/corelib/runtime.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148

149149
// Copy all parent constants to child, unless parent is Object
150150
if (superklass !== ObjectClass && superklass !== BasicObjectClass) {
151-
Opal.donate_constants(superklass, klass);
151+
donate_constants(superklass, klass);
152152
}
153153

154154
// call .inherited() hook with new class on the superclass
@@ -358,9 +358,25 @@
358358
return object.$$meta = meta;
359359
}
360360

361-
/*
362-
* The actual inclusion of a module into a class.
363-
*/
361+
/**
362+
The actual inclusion of a module into a class.
363+
364+
## Class `$$parent` and `iclass`
365+
366+
To handle `super` calls, every class has a `$$parent`. This parent is
367+
used to resolve the next class for a super call. A normal class would
368+
have this point to its superclass. However, if a class includes a module
369+
then this would need to take into account the module. The module would
370+
also have to then point its `$$parent` to the actual superclass. We
371+
cannot modify modules like this, because it might be included in more
372+
then one class. To fix this, we actually insert an `iclass` as the class'
373+
`$$parent` which can then point to the superclass. The `iclass` acts as
374+
a proxy to the actual module, so the `super` chain can then search it for
375+
the required method.
376+
377+
@param [RubyModule] module the module to include
378+
@param [RubyClass] klass the target class to include module into
379+
*/
364380
Opal.append_features = function(module, klass) {
365381
var included = klass.$$inc;
366382

@@ -409,7 +425,7 @@
409425
donate_methods(klass, methods.slice(), true);
410426
}
411427

412-
Opal.donate_constants(module, klass);
428+
donate_constants(module, klass);
413429
};
414430

415431
// Boot a base class (makes instances).
@@ -557,7 +573,7 @@
557573
* When a source module is included into the target module, we must also copy
558574
* its constants to the target.
559575
*/
560-
Opal.donate_constants = function(source_mod, target_mod) {
576+
function donate_constants(source_mod, target_mod) {
561577
var source_constants = source_mod.$$scope.constants,
562578
target_scope = target_mod.$$scope,
563579
target_constants = target_scope.constants;

1 commit comments

Comments
 (1)

elia commented on Nov 27, 2014

@elia
Member

@adambeynon you're the best ✨

Please sign in to comment.