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

[JSC] TypedArray iteration does not need to get "length" #3038

Conversation

Constellation
Copy link
Member

@Constellation Constellation commented Aug 5, 2022

af1cc8c

[JSC] TypedArray iteration does not need to get "length"
https://bugs.webkit.org/show_bug.cgi?id=243581

Reviewed by Alexey Shvayka.

ArrayIterator#next spec says that if the array is TypedArray, we do not need to look up "length",
and we can directly get TypedArray's internal length. This means that "length" property of instance,
Uint8Array.prototype, and TypedArray.prototype are unrelated to iterator protocol. This makes iterator
protocol guarantee simplified.

This patch applies this change: we no longer ensure "length" validity. We also adjust ArrayIterator#next's
slow path implementation to the spec.

[1]: https://tc39.es/ecma262/#sec-createarrayiterator

* JSTests/stress/typed-array-from-custom-length.js:
* Source/JavaScriptCore/builtins/ArrayIteratorPrototype.js:
(linkTimeConstant.arrayIteratorNextHelper):
* Source/JavaScriptCore/runtime/JSArrayBufferView.cpp:
(JSC::JSArrayBufferView::isIteratorProtocolFastAndNonObservable):
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::installTypedArrayIteratorProtocolWatchpoint):
(JSC::JSGlobalObject::installTypedArrayPrototypeIteratorProtocolWatchpoint):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::typedArrayPrototypeLengthAbsenceWatchpoint): Deleted.
* Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp:
(JSC::JSTypedArrayViewPrototype::finishCreation):

Canonical link: https://commits.webkit.org/253153@main

@Constellation Constellation requested a review from a team as a code owner August 5, 2022 08:20
@Constellation Constellation self-assigned this Aug 5, 2022
@Constellation Constellation added JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. WebKit Nightly Build labels Aug 5, 2022
@Constellation Constellation force-pushed the eng/JSC-TypedArray-iteration-does-not-need-to-get-length branch from 83da25e to f89bee3 Compare August 5, 2022 08:48
Copy link
Member

@shvaikalesh shvaikalesh left a comment

Choose a reason for hiding this comment

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

Lovely, r=me.

I wish we could export JSTests/stress/typed-array-from-custom-length.js and JSTests/stress/detached-typed-array-iteration.js to test262 suite some day.

@Constellation Constellation added the merge-queue Applied to send a pull request to merge-queue label Aug 5, 2022
https://bugs.webkit.org/show_bug.cgi?id=243581

Reviewed by Alexey Shvayka.

ArrayIterator#next spec says that if the array is TypedArray, we do not need to look up "length",
and we can directly get TypedArray's internal length. This means that "length" property of instance,
Uint8Array.prototype, and TypedArray.prototype are unrelated to iterator protocol. This makes iterator
protocol guarantee simplified.

This patch applies this change: we no longer ensure "length" validity. We also adjust ArrayIterator#next's
slow path implementation to the spec.

[1]: https://tc39.es/ecma262/#sec-createarrayiterator

* JSTests/stress/typed-array-from-custom-length.js:
* Source/JavaScriptCore/builtins/ArrayIteratorPrototype.js:
(linkTimeConstant.arrayIteratorNextHelper):
* Source/JavaScriptCore/runtime/JSArrayBufferView.cpp:
(JSC::JSArrayBufferView::isIteratorProtocolFastAndNonObservable):
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::installTypedArrayIteratorProtocolWatchpoint):
(JSC::JSGlobalObject::installTypedArrayPrototypeIteratorProtocolWatchpoint):
* Source/JavaScriptCore/runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::typedArrayPrototypeLengthAbsenceWatchpoint): Deleted.
* Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp:
(JSC::JSTypedArrayViewPrototype::finishCreation):

Canonical link: https://commits.webkit.org/253153@main
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/JSC-TypedArray-iteration-does-not-need-to-get-length branch from f89bee3 to af1cc8c Compare August 5, 2022 18:00
@webkit-commit-queue
Copy link
Collaborator

Committed 253153@main (af1cc8c): https://commits.webkit.org/253153@main

Reviewed commits have been landed. Closing PR #3038 and removing active labels.

@webkit-early-warning-system webkit-early-warning-system merged commit af1cc8c into WebKit:main Aug 5, 2022
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Aug 5, 2022
@Constellation Constellation deleted the eng/JSC-TypedArray-iteration-does-not-need-to-get-length branch August 5, 2022 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.
Projects
None yet
4 participants