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

Async call handling #7

Closed
deepalitandel opened this issue May 3, 2016 · 11 comments
Closed

Async call handling #7

deepalitandel opened this issue May 3, 2016 · 11 comments

Comments

@deepalitandel
Copy link

How does NJSTrace handle async call?

@ValYouW
Copy link
Owner

ValYouW commented May 3, 2016

Not sure I understand the question.

@drv1234
Copy link

drv1234 commented Apr 30, 2018

hi,
could you please help me? It seems async is not supported.
If I change the example file to this, exception happens when I try to run.

// *** mymod.js ***
exports.run = async function(number) {
number = await first(number);
printResult(number);
}
:
:

@ValYouW
Copy link
Owner

ValYouW commented Apr 30, 2018

@drv1234 async/await is part of ES8, need to check if it supported by the javascript parser being used

@drv1234
Copy link

drv1234 commented May 1, 2018

I use the latest node js. Without njstrace instrment the code runs fine.

@drv1234
Copy link

drv1234 commented May 1, 2018

here is the printout:

njsTrace: New instance of NJSTrace created with config: { enabled: true,
files: [ '/*.js', '!/node_modules/**' ],
wrapFunctions: false,
logger: true,
inspectArgs: true }
njsTrace: Creating new Injector and hijacking Module.prototype._compile
njsTrace: Setting global.njsTraceEntry function
njsTrace: Setting global.njsTraceExit function
njsTrace: Setting global.njsOnCatchClause function
njsTrace: njsTrace done loading...
njsTrace: Instrumenting: c:\temp\mymod.js
njsTrace: ERROR: Error instrumenting file: c:\temp\mymod.js , Exception: { Error: Line 3: Unexpected token function
at throwError (c:\temp\node_modules\falafel\node_modules\esprima\esprima.js:1467:21)
at throwUnexpected (c:\temp\node_modules\falafel\node_modules\esprima\esprima.js:1521:13)
at consumeSemicolon (c:\temp\node_modules\falafel\node_modules\esprima\esprima.js:1605:13)
at parseStatement (c:\temp\node_modules\falafel\node_modules\esprima\esprima.js:2853:9)
at c:\temp\node_modules\falafel\node_modules\esprima\esprima.js:3588:38
at parseSourceElement (c:\temp\node_modules\falafel\node_modules\esprima\esprima.js:3073:20)
at parseFunctionSourceElements (c:\temp\node_modules\falafel\node_modules\esprima\esprima.js:2905:29)
at c:\temp\node_modules\falafel\node_modules\esprima\esprima.js:3588:38
at parseFunctionExpression (c:\temp\node_modules\falafel\node_modules\esprima\esprima.js:3045:16)
at c:\temp\node_modules\falafel\node_modules\esprima\esprima.js:3588:38
index: 104,
lineNumber: 3,
column: 21,
description: 'Unexpected token function' }
c:\temp\main.js:10
mymod.run(parseFloat(Math.random().toFixed(4)));
^

TypeError: mymod.run is not a function
at Object. (c:\temp\main.js:10:7)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3

@ValYouW
Copy link
Owner

ValYouW commented May 1, 2018

I know async await is suppurted in Nodejs, it is not supported by the library I am using to parse the javascript files (at lease in the way I'm currently doing it)

@drv1234
Copy link

drv1234 commented May 2, 2018

Thanks.
Are you planning to support it in the near future?
Or shall I find other ways?

@ValYouW
Copy link
Owner

ValYouW commented May 2, 2018

It is really up to whether this library supports it, if it does it should be relatively easy to support it. I'll try to find some time to check it on the weekend

@drv1234
Copy link

drv1234 commented May 3, 2018

Thank you in advance!
Please let me know.

@ValYouW
Copy link
Owner

ValYouW commented May 5, 2018

@drv1234 Please see if the latest version (1.0.1) works for you. Did some very basic async/await and it seems ok, not sure how it will work on a large scale project...

@ValYouW ValYouW closed this as completed May 5, 2018
@drv1234
Copy link

drv1234 commented May 7, 2018

hi,
thanks, I tried on my project and it works like a charm.

But...
The named (optional) parameters are not printed even if they are in the caller line.
I don't know is it up to you or it comes from external lib.
(unfortunately there are a lot of this kind of function in my project, because it is a test framework and it is continuously developed but older test are not modified)

To see, modify the example:

// *** main.js
:
mymod.run(parseFloat(Math.random().toFixed(4)), xx=11);

// *** mymod.js ***
exports.run = async function (number, xx=22) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants