kopia lustrzana https://github.com/backface/turtlestitch
prevent inserting items at non-integer / out-of-bounds indices
rodzic
199feb9fa1
commit
cbba33bc15
|
@ -5,11 +5,13 @@
|
||||||
* **Notable Fixes:**
|
* **Notable Fixes:**
|
||||||
* fixed recursive calls in PIPE
|
* fixed recursive calls in PIPE
|
||||||
* the "length of list" block no longer appears twice in search results
|
* the "length of list" block no longer appears twice in search results
|
||||||
|
* prevent inserting items at non-integer / out-of-bounds indices
|
||||||
|
|
||||||
### 2021-03-09
|
### 2021-03-09
|
||||||
* new dev version
|
* new dev version
|
||||||
* objects: fixed #2797
|
* objects: fixed #2797
|
||||||
* fixed recursive calls in PIPE
|
* fixed recursive calls in PIPE
|
||||||
|
* lists: prevent usage of lists as dictionaries
|
||||||
|
|
||||||
## 6.7.0
|
## 6.7.0
|
||||||
* **New Features:**
|
* **New Features:**
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<script src="src/objects.js?version=2021-03-09"></script>
|
<script src="src/objects.js?version=2021-03-09"></script>
|
||||||
<script src="src/gui.js?version=2021-03-09"></script>
|
<script src="src/gui.js?version=2021-03-09"></script>
|
||||||
<script src="src/paint.js?version=2020-05-17"></script>
|
<script src="src/paint.js?version=2020-05-17"></script>
|
||||||
<script src="src/lists.js?version=2021-02-20"></script>
|
<script src="src/lists.js?version=2021-03-09"></script>
|
||||||
<script src="src/byob.js?version=2021-03-05"></script>
|
<script src="src/byob.js?version=2021-03-05"></script>
|
||||||
<script src="src/tables.js?version=2021-03-05"></script>
|
<script src="src/tables.js?version=2021-03-05"></script>
|
||||||
<script src="src/sketch.js?version=2020-07-13"></script>
|
<script src="src/sketch.js?version=2020-07-13"></script>
|
||||||
|
|
18
src/lists.js
18
src/lists.js
|
@ -63,7 +63,7 @@ MorphicPreferences, TableDialogMorph, SpriteBubbleMorph, SpeechBubbleMorph,
|
||||||
TableFrameMorph, TableMorph, Variable, isSnapObject, Costume, contains, detect,
|
TableFrameMorph, TableMorph, Variable, isSnapObject, Costume, contains, detect,
|
||||||
ZERO, WHITE*/
|
ZERO, WHITE*/
|
||||||
|
|
||||||
modules.lists = '2021-February-20';
|
modules.lists = '2021-March-09';
|
||||||
|
|
||||||
var List;
|
var List;
|
||||||
var ListWatcherMorph;
|
var ListWatcherMorph;
|
||||||
|
@ -192,7 +192,7 @@ List.prototype.add = function (element, index) {
|
||||||
insert the element before the given slot index,
|
insert the element before the given slot index,
|
||||||
if no index is specifed, append the element
|
if no index is specifed, append the element
|
||||||
*/
|
*/
|
||||||
var idx = index || this.length() + 1,
|
var idx = Math.round(+index) || this.length() + 1,
|
||||||
obj = isNil(element) ? null : element;
|
obj = isNil(element) ? null : element;
|
||||||
|
|
||||||
this.becomeArray();
|
this.becomeArray();
|
||||||
|
@ -202,19 +202,23 @@ List.prototype.add = function (element, index) {
|
||||||
|
|
||||||
List.prototype.put = function (element, index) {
|
List.prototype.put = function (element, index) {
|
||||||
// exchange the element at the given slot for another
|
// exchange the element at the given slot for another
|
||||||
var data = element === 0 ? 0
|
var idx = Math.round(+index) || 0,
|
||||||
|
data = element === 0 ? 0
|
||||||
: element === false ? false
|
: element === false ? false
|
||||||
: element || null;
|
: element || null;
|
||||||
|
|
||||||
this.becomeArray();
|
this.becomeArray();
|
||||||
this.contents[index - 1] = data;
|
if (idx < 1 || idx > this.contents.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.contents[idx - 1] = data;
|
||||||
this.changed();
|
this.changed();
|
||||||
};
|
};
|
||||||
|
|
||||||
List.prototype.remove = function (index) {
|
List.prototype.remove = function (index) {
|
||||||
// remove the given slot, shortening the list
|
// remove the given slot, shortening the list
|
||||||
this.becomeArray();
|
this.becomeArray();
|
||||||
this.contents.splice(index - 1, 1);
|
this.contents.splice(Math.round(+index || 0) - 1, 1);
|
||||||
this.changed();
|
this.changed();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -256,7 +260,9 @@ List.prototype.length = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
List.prototype.at = function (index) {
|
List.prototype.at = function (index) {
|
||||||
var value, idx = +index, pair = this;
|
var value,
|
||||||
|
idx = Math.round(+index || 0),
|
||||||
|
pair = this;
|
||||||
while (pair.isLinked) {
|
while (pair.isLinked) {
|
||||||
if (idx > 1) {
|
if (idx > 1) {
|
||||||
pair = pair.rest;
|
pair = pair.rest;
|
||||||
|
|
Ładowanie…
Reference in New Issue