Skip to content

Commit

Permalink
fix propertyIsEnumerable when using an index to access string; closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri authored and gbrail committed Jul 24, 2019
1 parent a27fac1 commit 8fea6de
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/org/mozilla/javascript/NativeString.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,18 @@ public boolean has(int index, Scriptable start) {
return super.has(index, start);
}

@Override
public int getAttributes(int index) {
if (0 <= index && index < string.length()) {
int attribs = READONLY | PERMANENT;
if (Context.getContext().getLanguageVersion() < Context.VERSION_ES6) {
attribs |= DONTENUM;
}
return attribs;
}
return super.getAttributes(index);
}

@Override
protected Object[] getIds(boolean nonEnumerable, boolean getSymbols)
{
Expand Down
13 changes: 13 additions & 0 deletions testsrc/jstests/es6/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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/.

load("testsrc/assert.js");

(function TestIsEnumerable() {
var obj = new Object("z");

assertTrue(obj.propertyIsEnumerable('0'));
})();

"success";
16 changes: 16 additions & 0 deletions testsrc/org/mozilla/javascript/tests/es6/NativeStringTest.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.es6;

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/es6/string.js")
@LanguageVersion(Context.VERSION_ES6)
public class NativeStringTest extends ScriptTestsBase
{
}

0 comments on commit 8fea6de

Please sign in to comment.