15 Commits
Author SHA1 Message Date
Martin Carlberg d70199ca58 Fixed: Asynchronous and output changes from the new Terser compressor 2021-09-21 11:09:09 +02:00
Martin Carlberg 81c02f24c6 New: msgSend will return undefined instead of nil when the receiver is undefined.
The msgSend function has always returned nil if the receiver has been nil or undefined.
Example:

var a = undefined;
var b = [a someSelector]; // b = nil

The variable b is now nil.

This pull request adds the ability for the msgSend function to return undefined if the receiver is undefined. If the receiver is nil it still return nil.
The above example again:

var a = undefined;
var b = [a someSelector]; // b = undefined

The variable b is now undefined.

Background.
The use of nil in Objective-C corresponds to the use of null in C and C++ and stands for "no value". A fundamental function in Objective-C is when you send a message to a receiver that is nil the result is again a nil value. This can be very convenient as you don't need the check if a receiver is nil before sending a message to it.

Objective-J adds the ability the use class structures and message send functionality for Javascript in the same way as Objective-C adds this to C and C++. Javascript also has the value null and is handled in the same way for Objective-J. Javascript also has the value undefined that stands for "not yet defined". This can sometimes be confusing and many try to handle null and undefined as the same thing. This is almost what Objective-J and the Cappuccino frameworks always has been doing. They try to always check for both null and ``undefined and always return nil but never undefined. We can say that Objective-J understands undefined but will try to translate it to nil.

Why do we need this change.
Javascript has both null and undefined and Objective-J is a superset of Javascript. It is now very hard to use undefined in Objective-J code as it will always try to translate it to nil. There are some Javascript libraries that use both null and undefined values and they are very hard to use from Objective-J programs today.  Same if you decide to use nil and undefined as a value in your own Objective-J code. This small change will make undefined a full member of the Objective-J language. It should be as it is a superset of Javascript. The Cappuccino frameworks will still handle undefined but only return nil.

How will it impact.
Today most methods will never return undefined so this is a very limited problem. If any does this the main concern is if some code will only check for nil and not undefined.
Example:

var a = [someObject someSelector];
If (a === nil) a = 42;
...

If the variable someObject contains undefined the variable a will now be set to undefined instead of nil.  But the variable a will then never be set to 42.
The correct way is to check for both nil and undefined like this:

var a = [someObject someSelector];
If (a == nil) a = 42;
...
2019-06-24 17:36:15 +02:00
Martin Carlberg b132a66707 Fixed: Compiler option 'IncludeTypeSignatures' is default turn on for all type of builds. It can optionally be turned off. 2015-11-20 12:33:00 +01:00
Martin Carlberg 26a123f5a8 Fixed: Added code generation unit test cases with inlined objj_msgSend functions for all tests in OutputTest. 2015-10-07 15:58:28 +02:00
Martin Carlberg ee13978115 Fixed: @ref did not generate self.x for an ivar x 2014-12-02 13:54:02 +01:00
Martin Carlberg ab5674aa4e Fixed: Send message test cases now work. Also added a test case for send message with 'self' as receiver 2014-04-14 16:38:34 +02:00
Martin Carlberg 0f5b36e9c5 Fixed: Code generated in test cases is corrected for the fast msgSend function 2014-04-09 17:02:28 +02:00
Alexander Ljungberg c1f538ece5 Formatting: whitespace.
Refs #1974.
2013-11-28 18:39:01 +00:00
Martin Carlberg 23fb618596 Fixed: Compiler now generates correct empty statement after 'if (a);'
Earlier the compiler generated the 'if' without the last ';' when a empty statement is used, with sometimes devastating result. The same if an empty statement was after the 'else'.

I have also added a test case for some different empty statement senarios.
2013-09-09 16:38:38 +02:00
Martin Carlberg a2257dab8f New: Empty loop test cases for compiler generator 2013-05-22 11:41:17 +02:00
Alexander Ljungberg 8c5015a0bc Test: verify compiler output for return statement without space.
Refs #1830.
2013-05-18 01:00:49 +01:00
Martin Carlberg 392aafb360 Revert "Revert "New: Added test cases for some preprocess directives in OutputTest.j""
This reverts commit 5e6c89ca8b.

Conflicts:
	Tests/Objective-J/Preprocessor/OutputTests/OutputTest.j
2013-05-16 12:05:57 +02:00
Martin Carlberg 5e6c89ca8b Revert "New: Added test cases for some preprocess directives in OutputTest.j"
This reverts commit 9b709b85a9.
2013-05-15 15:21:49 +02:00
Martin Carlberg 9b709b85a9 New: Added test cases for some preprocess directives in OutputTest.j
Also fixed so OutputTest.j now uses the new compiler instead of the old.
2013-05-14 10:31:29 +02:00
Paul Baumgart e62fd3cf40 Add a test case to test some reductions of regexes that current cause errors in the Preprocessor. 2010-09-24 16:46:31 -07:00