Skip to content

Commit

Permalink
Fix Array.include return a wrapped Boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
nename0 authored and gbrail committed Jun 28, 2019
1 parent 96eca5b commit ea80b70
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/org/mozilla/javascript/NativeArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope,
return js_lastIndexOf(cx, scope, thisObj, args);

case Id_includes:
return ScriptRuntime.toObject(cx, scope, ((long) js_indexOf(cx, scope, thisObj, args)) > -1);
return Boolean.valueOf(((long) js_indexOf(cx, scope, thisObj, args)) > -1);

case Id_fill:
return js_fill(cx, scope, thisObj, args);
Expand Down
5 changes: 5 additions & 0 deletions testsrc/jstests/es7-array-includes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load("testsrc/assert.js");

assertEquals(2, [1, 2, 3, 4].filter(t => [1, 2].includes(t)).length);

"success";
16 changes: 16 additions & 0 deletions testsrc/org/mozilla/javascript/tests/ES7ArrayIncludesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.javascript.tests;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.drivers.LanguageVersion;
import org.mozilla.javascript.drivers.RhinoTest;
import org.mozilla.javascript.drivers.ScriptTestsBase;

@RhinoTest("testsrc/jstests/es7-array-includes.js")
@LanguageVersion(Context.VERSION_ES6)
public class ES7ArrayIncludesTest extends ScriptTestsBase {
}

0 comments on commit ea80b70

Please sign in to comment.