Skip to content

Commit

Permalink
Merge remote-tracking branch 'rbri_rhino/mozilla#437'
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jul 28, 2018
2 parents 211c5e6 + 7a1c3e2 commit e7ce0f7
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 37 deletions.
16 changes: 2 additions & 14 deletions src/org/mozilla/javascript/EqualObjectGraphs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

import org.mozilla.javascript.debug.DebuggableObject;
import org.mozilla.javascript.typedarrays.NativeArrayBuffer;
import org.mozilla.javascript.typedarrays.NativeTypedArrayView;

/**
* An object that implements deep equality test of objects, including their
Expand Down Expand Up @@ -300,18 +299,7 @@ private static String getSymbolName(final Symbol s) {
private static Object[] getIds(final Scriptable s) {
if (s instanceof ScriptableObject) {
// Grabs symbols too
try {
return ((ScriptableObject)s).getIds(true, true);
} catch (IllegalArgumentException e) {
if (s instanceof NativeArrayBuffer) {
// TODO: remove this once https://github.com/mozilla/rhino/issues/437 is fixed
return new String[0];
} else if (s instanceof NativeTypedArrayView) {
// TODO: remove this once https://github.com/mozilla/rhino/issues/449 is fixed
return s.getIds();
}
throw e;
}
return ((ScriptableObject)s).getIds(true, true);
} else if (s instanceof DebuggableObject) {
return ((DebuggableObject)s).getAllIds();
} else {
Expand Down
8 changes: 3 additions & 5 deletions src/org/mozilla/javascript/typedarrays/NativeArrayBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ protected void initPrototypeId(int id)
protected int findPrototypeId(String s)
{
int id;
// #generated#
// #generated# Last update: 2018-07-20 08:21:54 MESZ
L0: { id = 0; String X = null;
int s_length = s.length();
if (s_length==5) { X="slice";id=Id_slice; }
else if (s_length==6) { X="isView";id=Id_isView; }
else if (s_length==11) { X="constructor";id=Id_constructor; }
if (X!=null && X!=s && !X.equals(s)) id = 0;
break L0;
Expand All @@ -181,14 +180,13 @@ protected int findPrototypeId(String s)
private static final int
Id_constructor = 1,
Id_slice = 2,
Id_isView = 3,
MAX_PROTOTYPE_ID = Id_isView;
MAX_PROTOTYPE_ID = Id_slice;

// #/string_id_map#

// Constructor (aka static) functions here

private static final int ConstructorId_isView = -Id_isView;
private static final int ConstructorId_isView = -1;

@Override
protected void fillConstructorProperties(IdFunctionObject ctor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ else if (s_length==10) {
private static final int
Id_buffer = 1,
Id_byteOffset = 2,
Id_byteLength = 3,
Id_byteLength = 3;

// to be visible by subclasses
protected static final int
MAX_INSTANCE_ID = Id_byteLength;

// #/string_id_map#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ protected int findInstanceIdInfo(String s)
* These must not conflict with ids in the parent since we delegate there for property dispatching.
*/
private static final int
Id_length = 10,
Id_BYTES_PER_ELEMENT = 11,
Id_length = NativeArrayBufferView.MAX_INSTANCE_ID + 1,
Id_BYTES_PER_ELEMENT = Id_length + 1,
MAX_INSTANCE_ID = Id_BYTES_PER_ELEMENT;

// #/string_id_map#
Expand Down
29 changes: 29 additions & 0 deletions testsrc/org/mozilla/javascript/tests/NativeArrayBufferTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* 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.junit.Assert;
import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Undefined;

public class NativeArrayBufferTest {

/**
* Test case for issue {@link https://github.com/mozilla/rhino/issues/437}
*
* @throws Exception in case of failure
*/
@Test
public void test() throws Exception {
Context cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_ES6);
Scriptable global = cx.initStandardObjects();
Object result = cx.evaluateString(global, "(new ArrayBuffer(5)).isView", "", 1, null);
Assert.assertEquals(Undefined.instance, result);
Context.exit();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
package org.mozilla.javascript.tests.harmony;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import org.junit.Test;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.typedarrays.NativeArrayBuffer;
import org.mozilla.javascript.typedarrays.NativeFloat32Array;
import org.mozilla.javascript.typedarrays.NativeFloat64Array;
import org.mozilla.javascript.typedarrays.NativeArrayBuffer;
import org.mozilla.javascript.typedarrays.NativeInt16Array;
import org.mozilla.javascript.typedarrays.NativeInt32Array;
import org.mozilla.javascript.typedarrays.NativeInt8Array;
Expand All @@ -12,15 +27,6 @@
import org.mozilla.javascript.typedarrays.NativeUint8Array;
import org.mozilla.javascript.typedarrays.NativeUint8ClampedArray;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import static org.junit.Assert.*;

/**
* Ensure that the "List" contract is valid for a typed array.
*/
Expand Down Expand Up @@ -292,4 +298,35 @@ private <T> void testTwoList(List<T> list, T a, T b, T bogus)
} catch (UnsupportedOperationException e) {
}
}

/**
* Test case for {@link https://github.com/mozilla/rhino/issues/449}
*
* @throws Exception if test failed
*/
@Test
public void getAllIds() throws Exception {
String[] allNativeTypes = {
"Float32Array",
"Float64Array",
"Int8Array",
"Int16Array",
"Int32Array",
"Uint8Array",
"Uint16Array",
"Uint32Array",
"Uint8ClampedArray"
};

Context cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_ES6);
Scriptable global = cx.initStandardObjects();

for (String type : allNativeTypes) {
ScriptableObject obj = (ScriptableObject)cx.evaluateString(global, "new " + type + "(5)", "", 1, null);
obj.getAllIds();
}

Context.exit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CodePrinter {
// length of u-type escape like \u12AB
private static final int LITERAL_CHAR_MAX_SIZE = 6;

private String lineTerminator = "\n";
private String lineTerminator = System.lineSeparator();

private int indentStep = 4;
private int indentTabSize = 8;
Expand Down Expand Up @@ -159,7 +159,7 @@ public void indent(int level) {
}

public void nl() {
p('\n');
p(getLineTerminator());
}

public void line(int indent_level, String s) {
Expand All @@ -175,7 +175,4 @@ public void erase(int begin, int end) {
public String toString() {
return new String(buffer, 0, offset);
}



}

0 comments on commit e7ce0f7

Please sign in to comment.