Prechádzať zdrojové kódy

- Fixed Object >> ifNil:ifNotNil:
- Better tests for #ifNotNil: in the compiler

Nicolas Petton 11 rokov pred
rodič
commit
ffcf53a4bf

+ 4 - 0
js/Compiler-Tests.deploy.js

@@ -739,6 +739,10 @@ var self=this;
 return smalltalk.withContext(function($ctx1) { 
 _st(self)._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
 _st(self)._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
+_st(self)._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
+_st(self)._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
+_st(self)._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
+_st(self)._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
 return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},smalltalk.CodeGeneratorTest)})},
 messageSends: ["should:return:"]}),
 smalltalk.CodeGeneratorTest);

+ 5 - 1
js/Compiler-Tests.js

@@ -985,9 +985,13 @@ var self=this;
 return smalltalk.withContext(function($ctx1) { 
 _st(self)._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
 _st(self)._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
+_st(self)._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
+_st(self)._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
+_st(self)._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
+_st(self)._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
 return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},smalltalk.CodeGeneratorTest)})},
 args: [],
-source: "testifNotNilWithArgument\x0a\x09self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ]' return: nil",
+source: "testifNotNilWithArgument\x0a\x09self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ]' return: nil.\x0a\x09\x0a\x09self should: 'foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 5.\x0a\x09\x0a\x09self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 5",
 messageSends: ["should:return:"],
 referencedClasses: []
 }),

+ 2 - 2
js/Kernel-Objects.deploy.js

@@ -309,10 +309,10 @@ fn: function (aBlock,anotherBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 var $1;
-$1=_st(anotherBlock)._value();
+$1=_st(anotherBlock)._value_(self);
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"ifNil:ifNotNil:",{aBlock:aBlock,anotherBlock:anotherBlock},smalltalk.Object)})},
-messageSends: ["value"]}),
+messageSends: ["value:"]}),
 smalltalk.Object);
 
 smalltalk.addMethod(

+ 3 - 3
js/Kernel-Objects.js

@@ -416,12 +416,12 @@ fn: function (aBlock,anotherBlock){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 var $1;
-$1=_st(anotherBlock)._value();
+$1=_st(anotherBlock)._value_(self);
 return $1;
 }, function($ctx1) {$ctx1.fill(self,"ifNil:ifNotNil:",{aBlock:aBlock,anotherBlock:anotherBlock},smalltalk.Object)})},
 args: ["aBlock", "anotherBlock"],
-source: "ifNil: aBlock ifNotNil: anotherBlock\x0a\x09\x22inlined in the Compiler\x22\x0a\x09^anotherBlock value",
-messageSends: ["value"],
+source: "ifNil: aBlock ifNotNil: anotherBlock\x0a\x09\x22inlined in the Compiler\x22\x0a\x09^anotherBlock value: self",
+messageSends: ["value:"],
 referencedClasses: []
 }),
 smalltalk.Object);

+ 7 - 1
st/Compiler-Tests.st

@@ -423,7 +423,13 @@ testifNotNil
 
 testifNotNilWithArgument
 	self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ]' return: 3.
-	self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ]' return: nil
+	self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ]' return: nil.
+	
+	self should: 'foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 3.
+	self should: 'foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 5.
+	
+	self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 3.
+	self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 5
 !
 
 testifTrue

+ 1 - 1
st/Kernel-Objects.st

@@ -265,7 +265,7 @@ ifNil: aBlock
 
 ifNil: aBlock ifNotNil: anotherBlock
 	"inlined in the Compiler"
-	^anotherBlock value
+	^anotherBlock value: self
 !
 
 ifNotNil: aBlock