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

The JsModuleEvaluation method always returns a result equal to undefined #6266

Closed
Taritsyn opened this issue Sep 5, 2019 · 4 comments
Closed

Comments

@Taritsyn
Copy link
Contributor

Taritsyn commented Sep 5, 2019

I am working on implementing support of the ECMAScript 2015 static modules in a .NET library (JavaScript Engine Switcher project). I've already read the API documentation and “Steps needed for es6 modules embedding ChakraCore” discussion.

But I have not found anywhere information about how to get the result of module evaluation. Suppose there is the following code of root module:

import * as geometry from './geometry/geometry.js';
new geometry.Square(15).area;

The expected result of evaluating this module is a numerical value equal to 225, but the JsModuleEvaluation method always returns undefined.

To make it easier for you to find the reason for this behavior, I created a .NET Core console application.

@rhuanjl
Copy link
Collaborator

rhuanjl commented Sep 5, 2019

I've done a bit of digging - the ability to get a result value via JsModuleEvaluation appears to be an untested feature (nothing in the test suite looks at it) that either never worked or if it did work it was broken a while ago.

As far as I can see it is not currently possible to retrieve a value from a module unless it's exported.

Currently in the release branches the result from JsModuleEvaluation will always be undefined in the master branch it will always be {done : true} neither is useful.

I will have a look at fixing this.

@Taritsyn
Copy link
Contributor Author

Taritsyn commented Sep 6, 2019

Hello, Richard!

Thanks for quick response!

Currently in the release branches the result from JsModuleEvaluation will always be undefined in the master branch it will always be {done : true} neither is useful.

I do not know how standard this behavior is, but in the Microsoft ClearScript during evaluation of the similar code returns a numerical value.

I've done a bit of digging - the ability to get a result value via JsModuleEvaluation appears to be an untested feature (nothing in the test suite looks at it) that either never worked or if it did work it was broken a while ago.

Here I would like to receive a comment from @liminzhu.

@fatcerberus
Copy link
Contributor

IIRC, as written in the ECMAScript specification, the module evaluation algorithm canonically returns a normal completion of undefined, so ChakraCore’s result here is correct.

The only thing you’re meant to be able to extract from a successfully evaluated ES module is its module namespace object (i.e. its export table).

@rhuanjl
Copy link
Collaborator

rhuanjl commented Sep 9, 2019

@fatcerberus if that's the case I should fix master to return undefined again - as there's no test of this return value I hadn't noticed that my work in #6171 changed it until this issue prompted me to look.

However the documentation of JsModuleEvaluation implies that it perhaps provides some kind of useful value - which it obviously doesn't.

chakrabot pushed a commit that referenced this issue Sep 10, 2019
Merge pull request #6272 from rhuanjl:moduleReturnUndefined

Picking up on discussion in #6266 this reverts an unintended side-effect of #6171

The successful completion value of a module is `undefined` - this was not tested and the change in #6171 had resulted in it being  `{done : true}` instead.
@rhuanjl rhuanjl closed this as completed Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants