Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
Ensure index & original array are passed to map fn #632
Browse files Browse the repository at this point in the history
  • Loading branch information
kipz committed Jun 5, 2017
1 parent a7c8e37 commit a3f91c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Ensure index and original array are also passed to map callback
functions [#632][632]
- Now only load Gherkin feature definitions from the `.atomist/tests`
directory [#629][629]

[632]: https://github.com/atomist/rug/issues/632
[629]: https://github.com/atomist/rug/issues/629

## [1.0.0-m.4] - 2017-06-01
Expand Down
6 changes: 2 additions & 4 deletions src/main/scala/com/atomist/util/lang/JavaScriptArray.scala
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,10 @@ class JavaScriptArray[T](val toProxy: java.util.List[T])
case "map" => new AbstractJSObject {
override def call(thiz: scala.Any, args: AnyRef*): AnyRef = {
val map = args.head.asInstanceOf[ScriptObjectMirror]
val iter = lyst.listIterator()
val res = new JavaScriptArray[AnyRef](new util.ArrayList[AnyRef]())
while (iter.hasNext) {
val thing = iter.next()
for(i <- 0 until lyst.size()){
val thisArg = if (args.length > 1) args(1) else thiz
res.add(map.call(thisArg, thing.asInstanceOf[Object]))
res.add(map.call(thisArg, lyst.get(i).asInstanceOf[Object], i.asInstanceOf[Integer], lyst))
}
res
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ class JavaScriptArrayTest extends FlatSpec with Matchers {
|
| //this.lyst.forEach(t => console.log(t))
|
| let another: number[] = this.lyst.map(t => t.length)
| let another: number[] = this.lyst.map((item, index, arr) => {
| if(index === undefined) throw new Error("Index should be a number");
| if(arr === undefined) throw new Error ("Array should be defined");
| return item.length;
| });
| if(another.length != this.lyst.length){
| throw new Error("Length of array after map should be the same")
| }
Expand Down

0 comments on commit a3f91c2

Please sign in to comment.