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

Eliminate usages of getArrayCopy() #402

Closed
Tracked by #408
samreid opened this issue Nov 22, 2020 · 3 comments
Closed
Tracked by #408

Eliminate usages of getArrayCopy() #402

samreid opened this issue Nov 22, 2020 · 3 comments

Comments

@samreid
Copy link
Member

samreid commented Nov 22, 2020

From phetsims/axon#334, Energy Forms and Changes has 30 occurrences of getArrayCopy. I'm not sure whether it's important that those are (a) shallow copies or (b) something with the Array interface or (c) both. Since we started using Proxy, observable arrays now satisfy the Array interface. If a shallow copy is needed, perhaps we should use slice. Can you please take a look and see if these can be deleted or converted to slice?

@KatieWoe
Copy link
Contributor

KatieWoe commented Dec 7, 2020

In CT:

energy-forms-and-changes : fuzz : unbuilt
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/energy-forms-and-changes_en.html?continuousTest=%7B%22test%22%3A%5B%22energy-forms-and-changes%22%2C%22fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1607341314522%22%2C%22timestamp%22%3A1607342196340%7D&brand=phet&ea&fuzz&memoryLimit=1000
Query: brand=phet&ea&fuzz&memoryLimit=1000
Uncaught Error: Assertion failed: item not found in Array
Error: Assertion failed: item not found in Array
at window.assertions.assertFunction (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/assert/js/assert.js:25:13)
at arrayRemove (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-core/js/arrayRemove.js:19:13)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:34
at Proxy.forEach (<anonymous>)
at Proxy.removeAll (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:14)
at Biker.extractOutgoingEnergyChunks (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/EnergySource.js:52:26)
at SystemsModel.stepModel (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:261:42)
at SystemsModel.step (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:245:12)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/joist/js/Sim.js:282:22
at Action.execute (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/Action.js:225:18)
id: Bayes Chrome
Snapshot from 12/7/2020, 4:41:54 AM

----------------------------------

energy-forms-and-changes : fuzz : unbuilt
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/energy-forms-and-changes_en.html?continuousTest=%7B%22test%22%3A%5B%22energy-forms-and-changes%22%2C%22fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1607341314522%22%2C%22timestamp%22%3A1607349827797%7D&brand=phet&ea&fuzz&memoryLimit=1000
Query: brand=phet&ea&fuzz&memoryLimit=1000
Uncaught Error: Assertion failed: item not found in Array
Error: Assertion failed: item not found in Array
at window.assertions.assertFunction (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/assert/js/assert.js:25:13)
at arrayRemove (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-core/js/arrayRemove.js:19:13)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:34
at Proxy.forEach (<anonymous>)
at Proxy.removeAll (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:14)
at Biker.extractOutgoingEnergyChunks (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/EnergySource.js:52:26)
at SystemsModel.stepModel (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:261:42)
at SystemsModel.step (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:245:12)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/joist/js/Sim.js:282:22
at Action.execute (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/Action.js:225:18)
id: Bayes Chrome
Snapshot from 12/7/2020, 4:41:54 AM

----------------------------------

energy-forms-and-changes : fuzz : unbuilt : assertSlow
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/energy-forms-and-changes_en.html?continuousTest=%7B%22test%22%3A%5B%22energy-forms-and-changes%22%2C%22fuzz%22%2C%22unbuilt%22%2C%22assertSlow%22%5D%2C%22snapshotName%22%3A%22snapshot-1607341314522%22%2C%22timestamp%22%3A1607347981671%7D&brand=phet&eall&fuzz&memoryLimit=1000
Query: brand=phet&eall&fuzz&memoryLimit=1000
Uncaught Error: Assertion failed: item not found in Array
Error: Assertion failed: item not found in Array
at window.assertions.assertFunction (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/assert/js/assert.js:25:13)
at arrayRemove (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-core/js/arrayRemove.js:19:13)
at Proxy.remove (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:345:33)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SunEnergySource.js:182:47
at Proxy.forEach (<anonymous>)
at SunEnergySource.updateEnergyChunkPositions (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SunEnergySource.js:175:26)
at SunEnergySource.preloadEnergyChunks (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SunEnergySource.js:273:12)
at SystemsModel.preloadEnergyChunks (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:277:12)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:203:14
at TinyEmitter.emit (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/TinyEmitter.js:71:18)
id: Bayes Chrome
Snapshot from 12/7/2020, 4:41:54 AM

----------------------------------

energy-forms-and-changes : phet-io-fuzz : unbuilt
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/energy-forms-and-changes_en.html?continuousTest=%7B%22test%22%3A%5B%22energy-forms-and-changes%22%2C%22phet-io-fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1607341314522%22%2C%22timestamp%22%3A1607342438074%7D&ea&brand=phet-io&phetioStandalone&fuzz&memoryLimit=1000
Query: ea&brand=phet-io&phetioStandalone&fuzz&memoryLimit=1000
Uncaught Error: Assertion failed: item not found in Array
Error: Assertion failed: item not found in Array
at window.assertions.assertFunction (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/assert/js/assert.js:25:13)
at arrayRemove (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-core/js/arrayRemove.js:19:13)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:34
at Proxy.forEach (<anonymous>)
at Proxy.removeAll (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:14)
at Biker.extractOutgoingEnergyChunks (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/EnergySource.js:52:26)
at SystemsModel.stepModel (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:261:42)
at SystemsModel.step (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:245:12)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/joist/js/Sim.js:282:22
at Action.execute (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/Action.js:225:18)
id: Bayes Chrome
Snapshot from 12/7/2020, 4:41:54 AM

----------------------------------

energy-forms-and-changes : phet-io-state-fuzz : unbuilt
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-io-wrappers/state/?sim=energy-forms-and-changes&phetioDebug&fuzz&wrapperContinuousTest=%7B%22test%22%3A%5B%22energy-forms-and-changes%22%2C%22phet-io-state-fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1607341314522%22%2C%22timestamp%22%3A1607342045106%7D
Uncaught Error: Uncaught Error: Assertion failed: item not found in Array
Error: Assertion failed: item not found in Array
at window.assertions.assertFunction (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/assert/js/assert.js:25:13)
at arrayRemove (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-core/js/arrayRemove.js:19:13)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:34
at Array.forEach (<anonymous>)
at Proxy.removeAll (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:14)
at Generator.extractOutgoingEnergyChunks (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/Generator.js:424:33)
at SystemsModel.stepModel (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:263:40)
at SystemsModel.step (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:245:12)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/joist/js/Sim.js:282:22
at Action.execute (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/Action.js:225:18)
id: Bayes Chrome
Snapshot from 12/7/2020, 4:41:54 AM

----------------------------------

energy-forms-and-changes : phet-io-state-fuzz : unbuilt
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-io-wrappers/state/?sim=energy-forms-and-changes&phetioDebug&fuzz&wrapperContinuousTest=%7B%22test%22%3A%5B%22energy-forms-and-changes%22%2C%22phet-io-state-fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1607341314522%22%2C%22timestamp%22%3A1607349433844%7D
Uncaught Error: Uncaught Error: Assertion failed: item not found in Array
Error: Assertion failed: item not found in Array
at window.assertions.assertFunction (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/assert/js/assert.js:25:13)
at arrayRemove (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-core/js/arrayRemove.js:19:13)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:34
at Proxy.forEach (<anonymous>)
at Proxy.removeAll (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:14)
at SunEnergySource.extractOutgoingEnergyChunks (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/EnergySource.js:52:26)
at SystemsModel.stepModel (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:261:42)
at SystemsModel.step (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:245:12)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/joist/js/Sim.js:282:22
at Action.execute (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/Action.js:225:18)
id: Bayes Chrome
Snapshot from 12/7/2020, 4:41:54 AM

----------------------------------

energy-forms-and-changes : phet-io-studio-fuzz : unbuilt
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/studio/?sim=energy-forms-and-changes&phetioDebug&fuzz&wrapperContinuousTest=%7B%22test%22%3A%5B%22energy-forms-and-changes%22%2C%22phet-io-studio-fuzz%22%2C%22unbuilt%22%5D%2C%22snapshotName%22%3A%22snapshot-1607341314522%22%2C%22timestamp%22%3A1607343304255%7D
Uncaught Error: Uncaught Error: Assertion failed: item not found in Array
Error: Assertion failed: item not found in Array
at window.assertions.assertFunction (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/assert/js/assert.js:25:13)
at arrayRemove (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-core/js/arrayRemove.js:19:13)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:34
at Proxy.forEach (<anonymous>)
at Proxy.removeAll (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:14)
at Biker.extractOutgoingEnergyChunks (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/EnergySource.js:52:26)
at SystemsModel.stepModel (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:261:42)
at SystemsModel.step (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:245:12)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/joist/js/Sim.js:282:22
at Action.execute (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/Action.js:225:18)
id: Bayes Chrome
Snapshot from 12/7/2020, 4:41:54 AM

----------------------------------

energy-forms-and-changes : xss-fuzz
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/energy-forms-and-changes_en.html?continuousTest=%7B%22test%22%3A%5B%22energy-forms-and-changes%22%2C%22xss-fuzz%22%5D%2C%22snapshotName%22%3A%22snapshot-1607341314522%22%2C%22timestamp%22%3A1607345031078%7D&brand=phet&ea&fuzz&stringTest=xss&memoryLimit=1000
Query: brand=phet&ea&fuzz&stringTest=xss&memoryLimit=1000
Uncaught Error: Assertion failed: item not found in Array
Error: Assertion failed: item not found in Array
at window.assertions.assertFunction (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/assert/js/assert.js:25:13)
at arrayRemove (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-core/js/arrayRemove.js:19:13)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:34
at Proxy.forEach (<anonymous>)
at Proxy.removeAll (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:14)
at Biker.extractOutgoingEnergyChunks (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/EnergySource.js:52:26)
at SystemsModel.stepModel (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:261:42)
at SystemsModel.step (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:245:12)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/joist/js/Sim.js:282:22
at Action.execute (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/Action.js:225:18)
id: Bayes Chrome
Snapshot from 12/7/2020, 4:41:54 AM

----------------------------------

energy-forms-and-changes : xss-fuzz
https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/energy-forms-and-changes_en.html?continuousTest=%7B%22test%22%3A%5B%22energy-forms-and-changes%22%2C%22xss-fuzz%22%5D%2C%22snapshotName%22%3A%22snapshot-1607341314522%22%2C%22timestamp%22%3A1607350524345%7D&brand=phet&ea&fuzz&stringTest=xss&memoryLimit=1000
Query: brand=phet&ea&fuzz&stringTest=xss&memoryLimit=1000
Uncaught Error: Assertion failed: item not found in Array
Error: Assertion failed: item not found in Array
at window.assertions.assertFunction (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/assert/js/assert.js:25:13)
at arrayRemove (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/phet-core/js/arrayRemove.js:19:13)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:34
at Proxy.forEach (<anonymous>)
at Proxy.removeAll (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/createObservableArray.js:349:14)
at Biker.extractOutgoingEnergyChunks (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/EnergySource.js:52:26)
at SystemsModel.stepModel (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:261:42)
at SystemsModel.step (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/energy-forms-and-changes/js/systems/model/SystemsModel.js:245:12)
at https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/joist/js/Sim.js:282:22
at Action.execute (https://bayes.colorado.edu/continuous-testing/ct-snapshots/1607341314522/axon/js/Action.js:225:18)
id: Bayes Chrome
Snapshot from 12/7/2020, 4:41:54 AM

@samreid
Copy link
Member Author

samreid commented Dec 7, 2020

The preceding comment is being tracked in #403 (comment)

@chrisklus
Copy link
Contributor

I went through usages and converted most to use slice() - i found two usages that were safe to just directly iterate over. There were also two usages from PhetioGroups, so I left those as getArrayCopy. Tested with phet brand and Studio/preview sim. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants