Skip to content

Commit 5c87c77

Browse files
committed
Fixed using DbObjects and JS objects as AQ payload
1 parent cb7bd1a commit 5c87c77

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/njsAqQueue.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ bool njsAqQueue_createBaton(napi_env env, napi_callback_info info,
108108
static bool njsAqQueue_createMessage(njsBaton *baton, njsAqQueue *queue,
109109
napi_env env, napi_value value, dpiMsgProps **handle)
110110
{
111-
napi_value payloadObj, constructor;
111+
napi_value payloadObj, constructor, temp;
112112
napi_valuetype valueType;
113113
dpiMsgProps *tempHandle;
114114
bool found, isDbObject;
@@ -135,14 +135,25 @@ static bool njsAqQueue_createMessage(njsBaton *baton, njsAqQueue *queue,
135135
NJS_CHECK_NAPI(env, napi_get_named_property(env, value,
136136
"payload", &payloadObj))
137137
NJS_CHECK_NAPI(env, napi_typeof(env, payloadObj, &valueType))
138+
if (valueType == napi_string)
139+
break;
138140
if (valueType == napi_object) {
139141
NJS_CHECK_NAPI(env, napi_instanceof(env, payloadObj,
140142
constructor, &isDbObject))
143+
if (isDbObject || njsUtils_isBuffer(env, payloadObj))
144+
break;
145+
if (queue->payloadObjectType) {
146+
NJS_CHECK_NAPI(env, napi_get_reference_value(env,
147+
queue->payloadObjectType->jsDbObjectConstructor,
148+
&constructor))
149+
NJS_CHECK_NAPI(env, napi_new_instance(env, constructor,
150+
1, &payloadObj, &temp))
151+
payloadObj = temp;
152+
isDbObject = true;
153+
break;
154+
}
141155
}
142-
if (valueType != napi_string &&
143-
(valueType != napi_object || !isDbObject ||
144-
!njsUtils_isBuffer(env, payloadObj)))
145-
return njsBaton_setError(baton, errInvalidAqMessage);
156+
return njsBaton_setError(baton, errInvalidAqMessage);
146157
}
147158
break;
148159
default:

test/aq2.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ describe('218. aq2.js', function() {
212212
}
213213
}); // 218.4
214214

215-
it.skip('218.5 Enqueue a DB object as payload attribute', async () => {
215+
it('218.5 Enqueue a DB object as payload attribute', async () => {
216216
try {
217217
const addrData = {
218218
NAME: "Changjie",
@@ -243,7 +243,7 @@ describe('218. aq2.js', function() {
243243
}
244244
}); // 218.5
245245

246-
it.skip('218.6 Enqueue a JavaScript object as payload attribute', async () => {
246+
it('218.6 Enqueue a JavaScript object as payload attribute', async () => {
247247
try {
248248
const addrData = {
249249
NAME: "Chris",
@@ -306,4 +306,4 @@ describe('218. aq2.js', function() {
306306
should.not.exist(err);
307307
}
308308
}); // 218.7
309-
});
309+
});

0 commit comments

Comments
 (0)