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

Cannot modify length property of TypedArray #1572

Open
andreabergia opened this issue Aug 21, 2024 · 4 comments
Open

Cannot modify length property of TypedArray #1572

andreabergia opened this issue Aug 21, 2024 · 4 comments
Labels
Arrays bug Issues considered a bug Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec

Comments

@andreabergia
Copy link
Contributor

This is not allowed by rhino:

var a = new Int8Array([1,2,3]);
Object.defineProperty(a, 'length', {configurable: true, value: 42});
@p-bakker
Copy link
Collaborator

Do you know if this is just a misconfigured propertyDescriptor, or is there more to it?

@p-bakker p-bakker added Arrays bug Issues considered a bug Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec and removed bug Issues considered a bug labels Aug 21, 2024
@p-bakker
Copy link
Collaborator

I'm not sure I get what this case is about. Unless I'm reading things wrong, the length property of a TypedArray is to be an accessor property without a set, see https://tc39.es/ecma262/multipage/indexed-collections.html#sec-get-%typedarray%.prototype.length

The above referenced spec doesn't say anything more about the setup of the property, meaning https://tc39.es/ecma262/multipage/ecmascript-data-types-and-values.html#sec-property-attributes kicks in, which says that unless specified the defaults kick in and configurable is false by default

So that leads me to conclude that it shouldn't be possible to redefine the length property

Or am I missing something?

@andreabergia
Copy link
Contributor Author

I haven't checked the spec, but there's a lot of test262 cases that fail because of this issue. They are those named get-length-uses-internal-arraylength.js, where they do something like this:

Object.defineProperty(TypedArray.prototype, "length", {value: 0});

or

Object.defineProperty(TypedArray.prototype, "length", desc);

@p-bakker
Copy link
Collaborator

Had a look at /test262/test/built-ins/TypedArray/prototype/every/get-length-uses-internal-arraylength.js: the test likely already bombs out because it does Object.defineProperty(TypedArray.prototype, "length", desc);, while TypedArray(.prototype)is undefined, resulting in a TypeError.

Once the test would be able to get passed that hurdle, I'm not sure what would happen: the test tries to reconfigure the length property to see whether the internal code never looks at the length property(as per the spec it should look at the [ArrayLength] internal slot).

While I think our impl. does that, the test may or may not bomb out because Rhino seems to have some flaws in redefining properties.

Long story short I don't think we need this case:

Agree?

@p-bakker p-bakker reopened this Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrays bug Issues considered a bug Ecma Incompatibility Issues about Rhino being incompatible with the EcmaScript spec
Projects
None yet
Development

No branches or pull requests

2 participants