Bug Fixes
In Sym3 version 9.19.4, following macro function has been fixed.
indexOf
In macros Array.indexOf always returns -1 for arrays of strings. Array.indexOf appears to work correctly with integers.
For example, this bit of code
var myArray = ["VALUE1","VALUE2","VALUE3"];
print("VALUE1: " + myArray.indexOf("VALUE1"));
print("VALUE2: " + myArray.indexOf("VALUE2"));
print("VALUE3: " + myArray.indexOf(myArray[2]));
print("VALUE4: " + myArray.indexOf("VALUE4"));
Results in:
VALUE1: -1
VALUE2: -1
VALUE3: -1
VALUE4: -1
After the fix the result will be as follows
VALUE1: 0
VALUE2: 1
VALUE3: 2
VALUE4: -1
lastIndexOf
In macros Array.lastIndexOf always returns -1 for arrays of both strings and integers
For example, this bit of code
var myArray = ["VALUE1","VALUE2","VALUE3"];
print("VALUE1: " + myArray.lastIndexOf("VALUE1"));
print("VALUE2: " + myArray.lastIndexOf("VALUE2"));
print("VALUE3: " + myArray.lastIndexOf(myArray[2]));
print("VALUE4: " + myArray.lastIndexOf("VALUE4"));
Results in:
VALUE1: -1
VALUE2: -1
VALUE3: -1
VALUE4: -1
After the fix the result will be as follows
VALUE1: 0
VALUE2: 1
VALUE3: 2
VALUE4: -1
splice
Array.splice does not work as expected in macro scripting for non-zero index values
For example, this bit of code
// Insert "Lemon", "Kiwi" at 0
checkSplice(0, 0, ["Lemon", "Kiwi", "Banana", "Orange", "Apple", "Mango"]);
// Insert "Lemon", "Kiwi" at 2
checkSplice(2, 0, ["Banana", "Orange", "Lemon", "Kiwi", "Apple", "Mango"]);
// Delete "Banana", "Orange" then insert "Lemon", "Kiwi" at 0
checkSplice(0, 2, ["Lemon", "Kiwi", "Apple", "Mango"]);
// Delete "Apple", "Mango" then insert "Lemon", "Kiwi" at 2
checkSplice(2, 2, ["Banana", "Orange", "Lemon", "Kiwi"]);
// Run the test
function checkSplice(index, count, expected) {
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(index, count, "Lemon", "Kiwi");
print((validateSplice(fruits, expected) ? "[OK ] " : "[FAIL] ") + fruits.join(","))
}
// Check results
function validateSplice(test, expected) {
if (expected.length != test.length) {
return false;
}
for (var i = 0; i < expected.length; i++) {
if (expected[i].localeCompare(test[i]) != 0) {
return false;
}
}
return true;
}
Results in:
[OK ] Lemon,Kiwi,Banana,Orange,Apple,Mango
[FAIL] Lemon,Kiwi,Apple,Mango,Apple,Mango
[OK ] Lemon,Kiwi,Apple,Mango
[FAIL] Lemon,Kiwi,Apple,Mango
After the fix the result will be as follows
[OK ]Lemon,Kiwi,Banana,Orange,Apple,Mango
[OK ]Banana,Orange,Lemon,Kiwi,Apple,Mango
[OK ]Lemon,Kiwi,Apple,Mango
[OK ]Banana,Orange,Lemon,Kiwi