Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember.warn when ManyArray.objectAt() is undefined #4896

Merged
merged 1 commit into from
Mar 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions addon/-private/system/many-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@module ember-data
*/
import Ember from 'ember';
import { assert } from "ember-data/-private/debug";
import { assert, warn } from "ember-data/-private/debug";
import { PromiseArray } from "./promise-proxies";
import { _objectIsAlive } from "./store/common";
import diffArray from './diff-array';
Expand Down Expand Up @@ -136,7 +136,12 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
objectAt(index) {
let object = this.currentState[index];
//Ember observers such as 'firstObject', 'lastObject' might do out of bounds accesses
if (object === undefined) { return; }
if (object === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to bounds check that index is not length-1 or 0 because of the greediness of firstObject and lastObject.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for future travelers the issue @runspired is referring to is emberjs/ember.js#14843

warn(`ManyArray#objectAt(index) return undefined for index '${index}'. See https://github.com/emberjs/data/issues/4758`, false, {
id: 'ds.many-array.object-at-undefined'
});
return;
}

return object.getRecord();
},
Expand Down