Skip to content

Commit 3a6ce29

Browse files
committed
Workaround Node.js 6 inability to get the list of property names of an undefined object
1 parent e726c93 commit 3a6ce29

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/njsConnection.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ bool njsConnection::ProcessExecuteBinds(Local<Object> binds, njsBaton *baton)
641641

642642
// determine bind names (if binding by name)
643643
baton->bindArraySize = 1;
644-
if (!binds->IsArray())
644+
if (!binds->IsUndefined() && !binds->IsArray())
645645
bindNames = binds->GetOwnPropertyNames();
646646

647647
// initialize variables; if there are no variables, nothing further to do!
@@ -863,7 +863,7 @@ bool njsConnection::ProcessExecuteManyBinds(Local<Array> binds,
863863
// the number of bind variables and types
864864
if (scanRequired)
865865
bindDefs = Nan::Get(binds, 0).ToLocalChecked();
866-
if (!bindDefs->IsArray())
866+
if (!bindDefs->IsUndefined() && !bindDefs->IsArray())
867867
bindNames = bindDefs.As<Object>()->GetOwnPropertyNames();
868868

869869
// initialize variables; if there are no variables, nothing further to do!
@@ -1034,12 +1034,11 @@ bool njsConnection::InitBindVars(Local<Object> bindObj,
10341034

10351035
// create bind variables (one for each element of the bind array or each
10361036
// property of the bind object)
1037-
if (byPosition)
1037+
if (bindObj->IsUndefined())
1038+
baton->numBindVars = 0;
1039+
else if (byPosition)
10381040
baton->numBindVars = bindObj.As<Array>()->Length();
1039-
else {
1040-
bindNames = bindObj->GetOwnPropertyNames();
1041-
baton->numBindVars = bindNames->Length();
1042-
}
1041+
else baton->numBindVars = bindNames->Length();
10431042
baton->bindVars = new njsVariable[baton->numBindVars];
10441043

10451044
// initialize bind variables (set position or name)

0 commit comments

Comments
 (0)