1
0
Ver Fonte

kernel: Allow null traitComposition.

Herbert Vojčík há 7 anos atrás
pai
commit
d891a4d41e
3 ficheiros alterados com 18 adições e 9 exclusões
  1. 12 4
      src/Kernel-Classes.js
  2. 3 1
      src/Kernel-Classes.st
  3. 3 4
      support/kernel-fundamentals.js

+ 12 - 4
src/Kernel-Classes.js

@@ -2998,25 +2998,33 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return $recv($self._basicAt_("traitComposition"))._collect_((function(each){
+var $1,$receiver;
+$1=$self._basicAt_("traitComposition");
+if(($receiver = $1) == null || $receiver.a$nil){
+return [];
+} else {
+var aCollection;
+aCollection=$receiver;
+return $recv(aCollection)._collect_((function(each){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
 return $recv($globals.TraitTransformation)._fromJSON_(each);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,3)});
 //>>excludeEnd("ctx");
 }));
+}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"traitComposition",{},$globals.TBehaviorProvider)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "traitComposition\x0a\x09^ (self basicAt: 'traitComposition') collect: [ :each | TraitTransformation fromJSON: each ]",
+source: "traitComposition\x0a\x09^ (self basicAt: 'traitComposition')\x0a\x09\x09ifNil: [ #() ]\x0a\x09\x09ifNotNil: [ :aCollection | aCollection collect: [ :each | TraitTransformation fromJSON: each ] ]",
 referencedClasses: ["TraitTransformation"],
 //>>excludeEnd("ide");
-messageSends: ["collect:", "basicAt:", "fromJSON:"]
+messageSends: ["ifNil:ifNotNil:", "basicAt:", "collect:", "fromJSON:"]
 }),
 $globals.TBehaviorProvider);
 

+ 3 - 1
src/Kernel-Classes.st

@@ -694,7 +694,9 @@ selectors
 !
 
 traitComposition
-	^ (self basicAt: 'traitComposition') collect: [ :each | TraitTransformation fromJSON: each ]
+	^ (self basicAt: 'traitComposition')
+		ifNil: [ #() ]
+		ifNotNil: [ :aCollection | aCollection collect: [ :each | TraitTransformation fromJSON: each ] ]
 !
 
 traitCompositionDefinition

+ 3 - 4
support/kernel-fundamentals.js

@@ -273,7 +273,6 @@ define(['./compatibility' /* TODO remove */], function () {
 
         this.setupMethods = function (traitOrBehavior) {
             setupClassOrganization(traitOrBehavior);
-            traitOrBehavior.traitComposition = [];
             traitOrBehavior.localMethods = Object.create(null);
             traitOrBehavior.methods = Object.create(null);
         };
@@ -379,11 +378,11 @@ define(['./compatibility' /* TODO remove */], function () {
             for (selector in oldLocalMethods) {
                 updateMethod(selector, traitOrBehavior);
             }
-            traitOrBehavior.traitComposition.forEach(function (each) {
+            (traitOrBehavior.traitComposition || []).forEach(function (each) {
                 each.trait.removeUser(traitOrBehavior);
             });
-            traitOrBehavior.traitComposition = traitComposition;
-            traitOrBehavior.traitComposition.forEach(function (each) {
+            traitOrBehavior.traitComposition = traitComposition && traitComposition.length ? traitComposition : null;
+            (traitOrBehavior.traitComposition || []).forEach(function (each) {
                 each.trait.addUser(traitOrBehavior);
             });
         };