Conversation
This change migrates the deprecated V8 Array API to new APIs.
src/node_util.cc
Outdated
|
|
||
| int state = promise->State(); | ||
| ret->Set(env->context(), 0, Integer::New(isolate, state)).FromJust(); | ||
| std::vector<Local<Value>> values; |
There was a problem hiding this comment.
values(2), as we can have a maximum of two values.
There was a problem hiding this comment.
Then way not simply:
| std::vector<Local<Value>> values; | |
| Local<Value> values[2] = { Integer::New(isolate, state) }; | |
| size_t number_of_values = 1; | |
| if (state != Promise::PromiseState::kPending) | |
| values[number_of_values++] = promise->Result(); | |
| DCHECK_LE(number_of_values, arraysize(values)); | |
| Local<Array> ret = Array::New(isolate, values, number_of_values); |
There was a problem hiding this comment.
That’s much longer and doesn’t really provide too much of an advantage over using a vector.
There was a problem hiding this comment.
AFAICT it's only one line longer, and we get everything on the stack with no free-store allocations.
I thought that when possible, we prefer static sized data structures?
There was a problem hiding this comment.
I tried @refack's suggestion, but I couldn't find a reasonable way to include DCHECK_LE in this file. DCHECK_LE is defined in deps/v8/src/base/logging.h, and when I add #include "../deps/v8/src/base/logging.h" at the top, the compile doesn't seem passing (relative path inside logging.h doesn't seem resolving...)
There was a problem hiding this comment.
I followed @TimothyGu's comment for the moment.
There was a problem hiding this comment.
With values(2), the values are initialized with empty values and it has size 2. So I needed to add an else block and .pop_back() the last (empty) value. (I think that's unnecessarily complex and not desirable code.)
So I changed the code to follow @refack's comment (without DCHECK_LE assertion).
This addresses the comment in nodejs#24613
fe987df to
0098eb2
Compare
Use static sized data structure
0098eb2 to
3729328
Compare
|
(I force-pushed with empty change a few times to fix CI status but it keeps failing because of the rate limit of github API, which is used for fetching the commit message.) |
|
Landed in 27139fc |
This change migrates the deprecated V8 Array API to new APIs. PR-URL: nodejs#24613 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
|
Thank you for the reviews! Thank you for landing! |
This change migrates the deprecated V8 Array API to new APIs. PR-URL: #24613 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
This change migrates the deprecated V8 Array API to new APIs. PR-URL: nodejs#24613 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
This PR uses new V8 API for array creation, instead of old one.
related PR: #24125
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes