Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Convert NativeArrayBuffer, NativeDataView, and TypedArrays to lambda #1709

Merged
merged 3 commits into from
Oct 28, 2024

Conversation

camnwalter
Copy link
Contributor

This PR converts the ArrayBuffer and adjacent classes to using LambdaConstructor.

I haven't added any new functionality, just a basic conversion from IdScriptable to using lambdas. Hopefully will get to adding more correct functionality in the future...

This should fix these inside #963 :

  • TypedArray.buffer/byteLength/byteOffset
  • DataView.buffer/byteLength/byteOffset
  • ArrayBuffer.byteLength
    as they should all be accessor properties now.

Copy link
Collaborator

@gbrail gbrail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small things, but in general this is really good progress and I like how it fixes so many tests as well!

double start = isArg(args, 0) ? ScriptRuntime.toNumber(args[0]) : 0;
double end = isArg(args, 1) ? ScriptRuntime.toNumber(args[1]) : self.getLength();
int endI =
ScriptRuntime.toInt32(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong here, but aren't most of the values here -- "self.getLength()" -- integers already? And is this method supposed to work if "start" and "end" are not integers? It looks like we are converting a bunch of integers into a floating-point value and then back to integers again.

Or are the "start" and "end" parameters here actually doubles because they could theoretically represent a value larger than 2^31? And if so can we handle that with our native byte arrays anyway?

In other words I'm asking if this whole thing shouldn't be done with integer arithmetic, and there may well be a reason!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to look into it. I think I just copy pasted what was done before, but I'll see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does allow for non-integers but they are supposed to get converted to integers before all the max/mins in the following lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, after seeing what tests failed, you were right. It looks like they can be more than 2^31, but in that case, the value would be greater than the length of the byte array, so when taking the min, it will just be the original byte array length, avoiding any issues.

constructor.defineProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this is defined as a lambda function call -- it seems like rather than making the property value a function that returns a constant, can't we just set the value directly as an Integer object? This pattern happens in all the subclasses so my same comment would apply there too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change. Thanks

scope,
"set",
0,
(Context lcx, Scriptable lscope, Scriptable thisObj, Object[] args) -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but this seems like a bit too much code to be embedded inline like this, and it'd probably benefit from being a separate method.

This also updates the external-array harmony file taken from V8. There are still a few spots that error out with the new file, so I will get to those soon.
@camnwalter
Copy link
Contributor Author

camnwalter commented Oct 26, 2024

Rebased on master

Will fix issues..

@gbrail
Copy link
Collaborator

gbrail commented Oct 28, 2024

Thanks -- this looks good!

@gbrail gbrail merged commit d0663ed into mozilla:master Oct 28, 2024
1 check passed
@camnwalter camnwalter deleted the nativearray branch October 28, 2024 20:51
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants