Skip to content

Commit

Permalink
Remove getCompletionCallback function for all and jsapi for users (#648)
Browse files Browse the repository at this point in the history
This change removes the jsapi for user facing JavaScriptInvoke calls. For internal calls this change removes the getCompletionCallback from the jsapi object.
  • Loading branch information
rajsite authored Oct 18, 2019
1 parent 1bf1f9c commit 30d335d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 654 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test_script:
- make testjs
- make testnative
- make testhttpbin
- npm run test-min -- --browsers FirefoxHeadless
- npm run test-min -- --browsers FirefoxHeadless --skip-tags FailsFirefox

# Using the same naming convention as rust https://forge.rust-lang.org/platform-support.html
after_test:
Expand Down
22 changes: 11 additions & 11 deletions source/io/module_javaScriptInvoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ var assignJavaScriptInvoke;
};

var generateAPI = function (occurrencePointer, functionName, returnValueRef, errorValueRef, completionCallbackStatus, isInternalFunction) {
var api = {};
api.getCompletionCallback = function () {
var jsapi = {};
var getCompletionCallback = function () {
// The following checks are not LabVIEW errors because they may happen after JavaScriptInvoke completion finishes if user holds reference
if (completionCallbackStatus.retrievalState === completionCallbackRetrievalEnum.RETRIEVED) {
throw new Error(`The completion callback was retrieved more than once for ${functionName}.`);
Expand All @@ -395,7 +395,7 @@ var assignJavaScriptInvoke;
};

if (isInternalFunction) {
api.setLabVIEWError = function (status, code, source) {
jsapi.setLabVIEWError = function (status, code, source) {
var newError = {
status: status,
code: code,
Expand All @@ -404,7 +404,7 @@ var assignJavaScriptInvoke;
Module.coreHelpers.mergeErrors(errorValueRef, newError);
};
}
return api;
return {jsapi, getCompletionCallback};
};

publicAPI.javaScriptInvoke.registerInternalFunctions = function (functionsToAdd) {
Expand Down Expand Up @@ -462,10 +462,10 @@ var assignJavaScriptInvoke;
invocationState: completionCallbackInvocationEnum.PENDING
};

var jsapi;
if (isInternalFunction || functionToCall.length === parameters.length + 1) {
jsapi = generateAPI(occurrencePointer, functionName, returnValueRef, errorValueRef, completionCallbackStatus, isInternalFunction);
parameters.push(jsapi);
var generateAPIResults;
if (isInternalFunction) {
generateAPIResults = generateAPI(occurrencePointer, functionName, returnValueRef, errorValueRef, completionCallbackStatus, isInternalFunction);
parameters.push(generateAPIResults.jsapi);
}

var returnValue;
Expand Down Expand Up @@ -494,11 +494,11 @@ var assignJavaScriptInvoke;
return;
}

if (jsapi === undefined) {
jsapi = generateAPI(occurrencePointer, functionName, returnValueRef, errorValueRef, completionCallbackStatus, isInternalFunction);
if (generateAPIResults === undefined) {
generateAPIResults = generateAPI(occurrencePointer, functionName, returnValueRef, errorValueRef, completionCallbackStatus, isInternalFunction);
}

completionCallback = jsapi.getCompletionCallback();
completionCallback = generateAPIResults.getCompletionCallback();
returnValue.then(completionCallback).catch((returnValue) => completionCallback(coerceToError(returnValue)));
// Do not setOccurrence when returning here since waiting asynchronously for user Promise to resolve
return;
Expand Down
Loading

0 comments on commit 30d335d

Please sign in to comment.