Skip to content
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

Always include the JSAPI reference for internal functions #614

Merged
merged 2 commits into from May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/io/module_javaScriptInvoke.js
Expand Up @@ -428,7 +428,7 @@ var assignJavaScriptInvoke;
};

var jsapi;
if (functionToCall.length === parameters.length + 1) {
if (isInternalFunction || functionToCall.length === parameters.length + 1) {
rajsite marked this conversation as resolved.
Show resolved Hide resolved
jsapi = generateAPI(occurrencePointer, functionName, returnValueRef, errorValueRef, completionCallbackStatus, isInternalFunction);
parameters.push(jsapi);
}
Expand Down
73 changes: 73 additions & 0 deletions test-it/karma/javascriptinvoke/Async.Test.js
Expand Up @@ -786,4 +786,77 @@ describe('A JavaScript function invoke', function () {
await test();
});
});

describe('includes the jsapi reference when requested in arguments for normal functions', function () {
var argumentsCount;
var jsAPIReference;
beforeEach(function () {
argumentsCount = 0;
jsAPIReference = false;
test = async function () {
var viName = 'SingleFunction';
var runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, jsAsyncFunctionsUrl);
var viPathParser = vireoRunner.createVIPathParser(vireo, viName);
var viPathWriter = vireoRunner.createVIPathWriter(vireo, viName);
viPathWriter('input', 3);
vireoRunner.enqueueVI(vireo, viName);

const {rawPrint, rawPrintError} = await runSlicesAsync();
expect(argumentsCount).toBe(2);
expect(jsAPIReference).toHaveMember('getCompletionCallback');
expect(rawPrint).toBeEmptyString();
expect(rawPrintError).toBeEmptyString();
expect(viPathParser('error.status')).toBeFalse();
expect(viPathParser('error.code')).toBe(0);
expect(viPathParser('error.source')).toBeEmptyString();
expect(viPathParser('return')).toBe(9);
};
});
it('using the completion callback', async function () {
window.SingleFunction = function (input, jsapi) {
argumentsCount = arguments.length;
jsAPIReference = arguments[1];
var completionCallback = jsapi.getCompletionCallback();
Promise.resolve().then(function () {
completionCallback(input * input);
});
};
await test();
});
});

describe('does not include jsapi reference in arguments by default for normal functions', function () {
var argumentsCount;
var jsAPIReference;
beforeEach(function () {
argumentsCount = 0;
jsAPIReference = false;
test = async function () {
var viName = 'SingleFunction';
var runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, jsAsyncFunctionsUrl);
var viPathParser = vireoRunner.createVIPathParser(vireo, viName);
var viPathWriter = vireoRunner.createVIPathWriter(vireo, viName);
viPathWriter('input', 3);
vireoRunner.enqueueVI(vireo, viName);

const {rawPrint, rawPrintError} = await runSlicesAsync();
expect(argumentsCount).toBe(1);
expect(jsAPIReference).not.toBeDefined();
expect(rawPrint).toBeEmptyString();
expect(rawPrintError).toBeEmptyString();
expect(viPathParser('error.status')).toBeFalse();
expect(viPathParser('error.code')).toBe(0);
expect(viPathParser('error.source')).toBeEmptyString();
expect(viPathParser('return')).toBe(9);
};
});
it('using promises', async function () {
window.SingleFunction = async function (input) {
argumentsCount = arguments.length;
jsAPIReference = arguments[1];
return input * input;
};
await test();
});
});
});
69 changes: 69 additions & 0 deletions test-it/karma/javascriptinvoke/InternalFunction.Test.js
Expand Up @@ -313,4 +313,73 @@ describe('A JavaScriptInvoke for an internal function', function () {
expect(viPathParser('error.source')).toBeEmptyString();
expect(viPathParser('returnValue')).toBe(2);
});

it('includes the jsAPI if explicit in signature for internal functions', function (done) {
var viName = 'NI_InternalFunction';
var runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, jsInternalFunctionsUrl);
var viPathParser = vireoRunner.createVIPathParser(vireo, viName);
vireoRunner.enqueueVI(vireo, viName);

var argumentsCount;
var jsAPIReference;

vireo.javaScriptInvoke.registerInternalFunctions({
NI_InternalFunction: function (returnValueRef, inputIntegerValueRef, jsAPI) {
argumentsCount = arguments.length;
jsAPIReference = jsAPI;
jsAPI.setLabVIEWError(false, 0, '');
var inputInteger = vireo.eggShell.readDouble(inputIntegerValueRef);
var returnValue = inputInteger + 1;
vireo.eggShell.writeDouble(returnValueRef, returnValue);
}
});

runSlicesAsync(function (rawPrint, rawPrintError) {
expect(argumentsCount).toBe(3);
expect(jsAPIReference).toHaveMember('getCompletionCallback');
expect(rawPrint).toBeEmptyString();
expect(rawPrintError).toBeEmptyString();
expect(viPathParser('error.status')).toBeFalse();
expect(viPathParser('error.code')).toBe(0);
expect(viPathParser('error.source')).toBeEmptyString();
expect(viPathParser('returnValue')).toBe(2);
done();
});
});

it('still includes the jsAPI even if not explicit in signature for internal functions', function (done) {
var viName = 'NI_InternalFunction';
var runSlicesAsync = vireoRunner.rebootAndLoadVia(vireo, jsInternalFunctionsUrl);
var viPathParser = vireoRunner.createVIPathParser(vireo, viName);
vireoRunner.enqueueVI(vireo, viName);

var argumentsCount;
var jsAPIReference;

vireo.javaScriptInvoke.registerInternalFunctions({
NI_InternalFunction: function () {
var returnValueRef = arguments[0];
var inputIntegerValueRef = arguments[1];
var jsAPI = arguments[2];
argumentsCount = arguments.length;
jsAPIReference = jsAPI;
jsAPI.setLabVIEWError(false, 0, '');
var inputInteger = vireo.eggShell.readDouble(inputIntegerValueRef);
var returnValue = inputInteger + 1;
vireo.eggShell.writeDouble(returnValueRef, returnValue);
}
});

runSlicesAsync(function (rawPrint, rawPrintError) {
expect(argumentsCount).toBe(3);
expect(jsAPIReference).toHaveMember('getCompletionCallback');
expect(rawPrint).toBeEmptyString();
expect(rawPrintError).toBeEmptyString();
expect(viPathParser('error.status')).toBeFalse();
expect(viPathParser('error.code')).toBe(0);
expect(viPathParser('error.source')).toBeEmptyString();
expect(viPathParser('returnValue')).toBe(2);
done();
});
});
});