-
Notifications
You must be signed in to change notification settings - Fork 0
Support Node 12 and 14 #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
9a3b4e9
ab71c5d
0a43236
3493f16
c9fe85d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: Node CI | ||
|
|
||
| on: [push] | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Test Node.js ${{ matrix.node-version }} on ${{ matrix.os }} | ||
|
|
||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest, macos-latest, windows-latest] | ||
| node-version: [10.x, 12.x, 14.x, 16.x] | ||
|
|
||
| runs-on: ${{ matrix.os }} | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v1 | ||
|
|
||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v1 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
|
|
||
| - name: Print Node.js Version | ||
| run: node --version | ||
|
|
||
| - name: Install Dependencies | ||
| run: npm install | ||
| env: | ||
| CI: true | ||
|
|
||
| - name: Run "build" step | ||
| run: npm run build --if-present | ||
| env: | ||
| CI: true | ||
|
|
||
| - name: Run tests | ||
| run: npm test | ||
| env: | ||
| CI: true |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -128,20 +128,26 @@ NAN_INDEX_DELETER(WeakIndexedPropertyDeleter) { | |||||||||||||||||||||
| info.GetReturnValue().Set(!dead && Nan::Delete(obj, index).FromJust()); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| NAN_PROPERTY_ENUMERATOR(WeakNamedPropertyEnumerator) { | ||||||||||||||||||||||
| UNWRAP | ||||||||||||||||||||||
| #if NODE_MAJOR_VERSION >= 7 | ||||||||||||||||||||||
| info.GetReturnValue().Set(dead ? Nan::New<Array>(0) : obj->GetPropertyNames(Nan::GetCurrentContext(), KeyCollectionMode::kIncludePrototypes, ONLY_ENUMERABLE, IndexFilter::kSkipIndices).ToLocalChecked()); | ||||||||||||||||||||||
| #else | ||||||||||||||||||||||
| info.GetReturnValue().Set(dead ? Nan::New<Array>(0) : Nan::GetPropertyNames(obj).ToLocalChecked()); | ||||||||||||||||||||||
| #endif | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Only one "enumerator" function needs to be defined. This function is used for | ||||||||||||||||||||||
| * both the property and indexed enumerator functions. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| NAN_PROPERTY_ENUMERATOR(WeakPropertyEnumerator) { | ||||||||||||||||||||||
| NAN_INDEX_ENUMERATOR(WeakIndexedPropertyEnumerator) { | ||||||||||||||||||||||
| UNWRAP | ||||||||||||||||||||||
| #if NODE_MAJOR_VERSION >= 7 | ||||||||||||||||||||||
| info.GetReturnValue().Set(dead ? Nan::New<Array>(0) : obj->GetPropertyNames(Nan::GetCurrentContext(), KeyCollectionMode::kIncludePrototypes, static_cast<PropertyFilter> (ONLY_ENUMERABLE | SKIP_STRINGS | SKIP_SYMBOLS), IndexFilter::kIncludeIndices).ToLocalChecked()); | ||||||||||||||||||||||
| #else | ||||||||||||||||||||||
| info.GetReturnValue().Set(dead ? Nan::New<Array>(0) : Nan::GetPropertyNames(obj).ToLocalChecked()); | ||||||||||||||||||||||
| #endif | ||||||||||||||||||||||
|
Comment on lines
+142
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Broken indexed enumeration
The WeakIndexedPropertyEnumerator has the same critical issue as WeakNamedPropertyEnumerator - it returns empty arrays when the target is dead, breaking indexed property enumeration. This affects array-like behavior and indexed access patterns. The conditional dead check should be removed to maintain consistent enumeration behavior. Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #43c5fe Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * Weakref callback function. Invokes the "global" callback function, | ||||||||||||||||||||||
| * which emits the _CB event on the per-object EventEmitter. | ||||||||||||||||||||||
| * Weakref callback function. Invokes the "global" callback function. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| static void TargetCallback(const Nan::WeakCallbackInfo<proxy_container> &info) { | ||||||||||||||||||||||
|
|
@@ -152,11 +158,7 @@ static void TargetCallback(const Nan::WeakCallbackInfo<proxy_container> &info) { | |||||||||||||||||||||
| Local<Value> argv[] = { | ||||||||||||||||||||||
| Nan::New<Object>(cont->emitter) | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| // Invoke callback directly, not via Nan::Callback->Call() which uses | ||||||||||||||||||||||
| // node::MakeCallback() which calls into process._tickCallback() | ||||||||||||||||||||||
| // too. Those other callbacks are not safe to run from here. | ||||||||||||||||||||||
| v8::Local<v8::Function> globalCallbackDirect = globalCallback->GetFunction(); | ||||||||||||||||||||||
| globalCallbackDirect->Call(Nan::GetCurrentContext()->Global(), 1, argv); | ||||||||||||||||||||||
| Nan::Call(*globalCallback, 1, argv); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // clean everything up | ||||||||||||||||||||||
| Local<Object> proxy = Nan::New<Object>(cont->proxy); | ||||||||||||||||||||||
|
|
@@ -177,7 +179,7 @@ NAN_METHOD(Create) { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| Local<Object> _target = info[0].As<Object>(); | ||||||||||||||||||||||
| Local<Object> _emitter = info[1].As<Object>(); | ||||||||||||||||||||||
| Local<Object> proxy = Nan::New<ObjectTemplate>(proxyClass)->NewInstance(); | ||||||||||||||||||||||
| Local<Object> proxy = Nan::NewInstance(Nan::New<ObjectTemplate>(proxyClass)).ToLocalChecked(); | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong instantiation method
The change from Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #43c5fe Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||||||||||||||||||
| cont->proxy.Reset(proxy); | ||||||||||||||||||||||
| cont->emitter.Reset(_emitter); | ||||||||||||||||||||||
| cont->target.Reset(_target); | ||||||||||||||||||||||
|
|
@@ -224,23 +226,6 @@ NAN_METHOD(Get) { | |||||||||||||||||||||
| info.GetReturnValue().Set(Unwrap(proxy)); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * `isNearDeath(weakref)` JS function. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| NAN_METHOD(IsNearDeath) { | ||||||||||||||||||||||
| WEAKREF_FIRST_ARG | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| proxy_container *cont = reinterpret_cast<proxy_container*>( | ||||||||||||||||||||||
| Nan::GetInternalFieldPointer(proxy, FIELD_INDEX_CONTAINER) | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| assert(cont != NULL); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Local<Boolean> rtn = Nan::New<Boolean>(cont->target.IsNearDeath()); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| info.GetReturnValue().Set(rtn); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /** | ||||||||||||||||||||||
| * `isDead(weakref)` JS function. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
|
|
@@ -282,18 +267,17 @@ NAN_MODULE_INIT(Initialize) { | |||||||||||||||||||||
| WeakNamedPropertySetter, | ||||||||||||||||||||||
| WeakNamedPropertyQuery, | ||||||||||||||||||||||
| WeakNamedPropertyDeleter, | ||||||||||||||||||||||
| WeakPropertyEnumerator); | ||||||||||||||||||||||
| WeakNamedPropertyEnumerator); | ||||||||||||||||||||||
| Nan::SetIndexedPropertyHandler(p, | ||||||||||||||||||||||
| WeakIndexedPropertyGetter, | ||||||||||||||||||||||
| WeakIndexedPropertySetter, | ||||||||||||||||||||||
| WeakIndexedPropertyQuery, | ||||||||||||||||||||||
| WeakIndexedPropertyDeleter, | ||||||||||||||||||||||
| WeakPropertyEnumerator); | ||||||||||||||||||||||
| WeakIndexedPropertyEnumerator); | ||||||||||||||||||||||
| p->SetInternalFieldCount(FIELD_COUNT); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Nan::SetMethod(target, "get", Get); | ||||||||||||||||||||||
| Nan::SetMethod(target, "isWeakRef", IsWeakRef); | ||||||||||||||||||||||
| Nan::SetMethod(target, "isNearDeath", IsNearDeath); | ||||||||||||||||||||||
| Nan::SetMethod(target, "isDead", IsDead); | ||||||||||||||||||||||
| Nan::SetMethod(target, "_create", Create); | ||||||||||||||||||||||
| Nan::SetMethod(target, "_getEmitter", GetEmitter); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
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.
The WeakNamedPropertyEnumerator function incorrectly returns empty arrays when the target is dead (garbage collected). This breaks the JavaScript property enumeration contract where proxy objects should consistently enumerate their own properties regardless of target liveness. The
dead ? Nan::New<Array>(0)branch should be removed to always return the proxy's actual property names, ensuring consistent behavior for downstream consumers likeObject.keys(),for...inloops, and JSON serialization.Code suggestion
Code Review Run #43c5fe
Should Bito avoid suggestions like this for future reviews? (Manage Rules)