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

getAllIds on Float32Array fails #449

Closed
szegedi opened this issue Jun 17, 2018 · 1 comment
Closed

getAllIds on Float32Array fails #449

szegedi opened this issue Jun 17, 2018 · 1 comment

Comments

@szegedi
Copy link
Contributor

szegedi commented Jun 17, 2018

Trying to query all IDs on a Float32Array throws an IllegalArgumentException. The issue seems to be that there is a gap of undefined instance IDs between Float32Array and its superclass NativeTypedArrayView.

Here's a little test that illustrates the issue:

package org.mozilla.javascript.tests;

import junit.framework.TestCase;
import org.mozilla.javascript.*;

public class Float32ArrayTest extends TestCase {
    public void test() throws Exception {
        Context cx = Context.enter();
        cx.setLanguageVersion(Context.VERSION_ES6);
        Scriptable global = cx.initStandardObjects();
        ScriptableObject obj = (ScriptableObject)cx.evaluateString(global, "new Float32Array(5)", "", 1, null);
        obj.getAllIds();
        Context.exit();
    }
}

It results in:

java.lang.IllegalArgumentException: 9
	at org.mozilla.javascript.IdScriptableObject.getInstanceIdName(IdScriptableObject.java:699)
	at org.mozilla.javascript.typedarrays.NativeArrayBufferView.getInstanceIdName(NativeArrayBufferView.java:100)
	at org.mozilla.javascript.typedarrays.NativeTypedArrayView.getInstanceIdName(NativeTypedArrayView.java:400)
	at org.mozilla.javascript.IdScriptableObject.getIds(IdScriptableObject.java:629)
	at org.mozilla.javascript.ScriptableObject.getAllIds(ScriptableObject.java:995)
	at org.mozilla.javascript.tests.Float32ArrayTest.test(Float32ArrayTest.java:20)

The issue might be similar to #437.

szegedi added a commit to szegedi/rhino that referenced this issue Jun 17, 2018
szegedi added a commit to szegedi/rhino that referenced this issue Jun 17, 2018
@szegedi
Copy link
Contributor Author

szegedi commented Jun 17, 2018

It seems to me that the below change fixes it. Not sure why these values were 10 and 11 in the first place, though. A less brittle way of specifying them, counting from superclass MAX_INSTANCE_ID might be desirable.

--- a/src/org/mozilla/javascript/typedarrays/NativeTypedArrayView.java
+++ b/src/org/mozilla/javascript/typedarrays/NativeTypedArrayView.java
@@ -439,8 +439,8 @@ public abstract class NativeTypedArrayView<T>
      * 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               = 4,
+        Id_BYTES_PER_ELEMENT    = 5,
         MAX_INSTANCE_ID         = Id_BYTES_PER_ELEMENT;
 
 // #/string_id_map#

szegedi added a commit to szegedi/rhino that referenced this issue Jun 17, 2018
szegedi added a commit to szegedi/rhino that referenced this issue Jun 17, 2018
szegedi added a commit to szegedi/rhino that referenced this issue Jun 17, 2018
szegedi added a commit to szegedi/rhino that referenced this issue Jun 17, 2018
szegedi added a commit to szegedi/rhino that referenced this issue Jun 17, 2018
szegedi added a commit to szegedi/rhino that referenced this issue Jul 1, 2018
szegedi added a commit to szegedi/rhino that referenced this issue Jul 1, 2018
szegedi added a commit to szegedi/rhino that referenced this issue Jul 1, 2018
gbrail pushed a commit that referenced this issue Jul 12, 2018
@gbrail gbrail closed this as completed in 2f5b476 Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant