-
Notifications
You must be signed in to change notification settings - Fork 30k
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
src: add internal isArrayBufferDetached #45568
src: add internal isArrayBufferDetached #45568
Conversation
7d64817
to
dcee530
Compare
dcee530
to
4d5d53b
Compare
@@ -560,6 +562,14 @@ function SideEffectFreeRegExpPrototypeExec(regex, string) { | |||
return FunctionPrototypeCall(RegExpFromAnotherRealm.prototype.exec, regex, string); | |||
} | |||
|
|||
function isArrayBufferDetached(value) { | |||
if (ArrayBufferPrototypeGetByteLength(value) === 0) { | |||
return _isArrayBufferDetached(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crossing the JS-C++ boundary is gonna be slower than the current implementation although I'm not sure if this call in the zero length case is gonna be the primary bottleneck for any user code.
Did you consider implementing @jasnell's suggestion in #45512 (comment)? Seems like that approach would solve this problem without adding any performance overhead in any case.
One thing we might be able to do is add a hidden symbol to ArrayBuffer instances when we detach them in c++ land. Then we can have an isDetached check in js that checks the length and the presence of that symbol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, that is the perfect solution for performance, but I believe it's too hacky to maintain in the long term. I can't think of a good/maintainable way to enforce attaching the hidden symbol as a rule.
If it's the consensus @jasnell thinks is the best way, I'll be happy to implement it regardless.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with or without a nit.
Adding a test would also be nice.
if (ArrayBufferPrototypeGetByteLength(value) === 0) { | ||
return _isArrayBufferDetached(value); | ||
} | ||
|
||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the flow might look semantically better like this
if (ArrayBufferPrototypeGetByteLength(value) === 0) { | |
return _isArrayBufferDetached(value); | |
} | |
return false; | |
if (ArrayBufferPrototypeGetByteLength(value) !== 0) { | |
return false; | |
} | |
return _isArrayBufferDetached(value); |
Landed in 9a8d82b |
PR-URL: nodejs#45568 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
PR-URL: #45568 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
PR-URL: #45568 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
PR-URL: #45568 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
PR-URL: #45568 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
PR-URL: #45568 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
PR-URL: #45568 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
PR-URL: #45568 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name>
Follow up on #45512