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

fix propertyIsEnumerable when using an index to access string #585

Merged
merged 2 commits into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
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
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
29 changes: 21 additions & 8 deletions src/org/mozilla/javascript/regexp/RegExpImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,36 @@ public Object action(Context cx, Scriptable scope,
switch (actionType) {
case RA_MATCH:
{
NativeRegExp re = createRegExp(cx, scope, args, 1, false);
Object rval = matchOrReplace(cx, scope, thisObj, args,
this, data, re);
int optarg = Integer.MAX_VALUE;
if (cx.getLanguageVersion() < Context.VERSION_1_6) {
optarg = 1;
}

NativeRegExp re = createRegExp(cx, scope, args, optarg, false);
Object rval = matchOrReplace(cx, scope, thisObj, args, this, data, re);
return data.arrayobj == null ? rval : data.arrayobj;
}

case RA_SEARCH:
{
NativeRegExp re = createRegExp(cx, scope, args, 1, false);
return matchOrReplace(cx, scope, thisObj, args,
this, data, re);
int optarg = Integer.MAX_VALUE;
if (cx.getLanguageVersion() < Context.VERSION_1_6) {
optarg = 1;
}

NativeRegExp re = createRegExp(cx, scope, args, optarg, false);
return matchOrReplace(cx, scope, thisObj, args, this, data, re);
}

case RA_REPLACE:
{
boolean useRE = (args.length > 0 && args[0] instanceof NativeRegExp)
|| args.length > 2;
boolean useRE = args.length > 0 && args[0] instanceof NativeRegExp;

// ignore other parameters
if (cx.getLanguageVersion() < Context.VERSION_1_6) {
useRE |= args.length > 2;
}

NativeRegExp re = null;
String search = null;
if (useRE) {
Expand Down
25 changes: 25 additions & 0 deletions testsrc/jstests/es6/string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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'));
})();

(function TestReplaceNotUsedArguments() {
assertEquals("axdefg", "abcdefg".replace("bc", "x", "not used"));
})();

(function TestMatchNotUsedArguments() {
assertNull("abcdefg".match("AB", "not used"));
})();

(function TestSearchNotUsedArguments() {
assertEquals(2, "abcdEfg".search("cd", "not used"));
})();

"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
{
}