|
148 | 148 |
|
149 | 149 | // Copy all parent constants to child, unless parent is Object
|
150 | 150 | if (superklass !== ObjectClass && superklass !== BasicObjectClass) {
|
151 |
| - Opal.donate_constants(superklass, klass); |
| 151 | + donate_constants(superklass, klass); |
152 | 152 | }
|
153 | 153 |
|
154 | 154 | // call .inherited() hook with new class on the superclass
|
|
358 | 358 | return object.$$meta = meta;
|
359 | 359 | }
|
360 | 360 |
|
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 | + */ |
364 | 380 | Opal.append_features = function(module, klass) {
|
365 | 381 | var included = klass.$$inc;
|
366 | 382 |
|
|
409 | 425 | donate_methods(klass, methods.slice(), true);
|
410 | 426 | }
|
411 | 427 |
|
412 |
| - Opal.donate_constants(module, klass); |
| 428 | + donate_constants(module, klass); |
413 | 429 | };
|
414 | 430 |
|
415 | 431 | // Boot a base class (makes instances).
|
|
557 | 573 | * When a source module is included into the target module, we must also copy
|
558 | 574 | * its constants to the target.
|
559 | 575 | */
|
560 |
| - Opal.donate_constants = function(source_mod, target_mod) { |
| 576 | + function donate_constants(source_mod, target_mod) { |
561 | 577 | var source_constants = source_mod.$$scope.constants,
|
562 | 578 | target_scope = target_mod.$$scope,
|
563 | 579 | target_constants = target_scope.constants;
|
|
1 commit comments
elia commentedon Nov 27, 2014
@adambeynon you're the best ✨