-
-
Notifications
You must be signed in to change notification settings - Fork 565
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
Promise was rejected with value ReferenceError: c2 has not been initialized #1385
Comments
What might be this popular library? Without repro it's hard to say what's happening. You probably need to run Jint sources under debugger to gather some context about what's going wrong. |
I searched I made a "minimal"* repro: *: might be possible to make it even shorter, but I think it's good enough. if (typeof print === "undefined") {
globalThis.print = console.log;
}
print("start of script");
const promise1 = new Promise((resolve, reject) => {
print("promise1 before resolve");
resolve();
print("promise1 after resolve");
}).then(() => [promise2])
print("promise1 is defined");
const promise2 = waitForPromise(promise1).then(() => "This is the value of promise2");
print("promise2 is defined");
promise2.catch(e => {
print("promise2 catch");
print(e)
});
promise2.then((value) => {
print("promise2 then");
print(value)
});
print("end of script, print");
print(promise1)
print(promise2)
print("end of script, end of print")
async function waitForPromise(promise) {
print("promise waiting");
const value = await promise;
print("promise waited");
print(value);
print("end of promise waited");
};
|
After transforming the script with babel so it uses Probably related to |
I think the problem probably is that async function call result is not dispatched to event loop. |
Hey. To confirm it is We would like to remove babel entirely from our pipeline, for now we cant since there is a parser bug with the Out of curiosity, how much effort would it be to fix dispatching async results to the event loop? |
Thank you very much for looking into this and helping with the repro code. |
The problem is here as far as I can tell: jint/Jint/Runtime/Interpreter/JintFunctionDefinition.cs Lines 109 to 145 in 7480cfc
Basically it dispatches immediately the code in question ( |
Hey. So I have shrunk down the repro to work as a unit test under const promise1 = new Promise(resolve => {
resolve();
}).then(() => [promise2])
const promise2 = waitForPromise(promise1);
promise2.catch(e => {
assert(false, e)
});
async function waitForPromise(promise) {
await promise;
} Using this and digging deeper it seems that its an issue within the |
A minimal reproducible issue: [Fact]
public void ShouldPromiseBeResolved()
{
var log = new List<string>();
Engine engine = new();
engine.SetValue("log", (string str) =>
{
log.Add(str);
});
var result = engine.Execute("""
async function main() {
return new Promise(function (resolve) {
log('Promise!')
resolve(null)
}).then(function () {
log('Resolved!')
})
}
""");
JsValue val = result.GetValue("main");
if (val is Function func)
{
func.Call().UnwrapIfPromise();
}
Assert.Equal(2, log.Count);
Assert.Equal("Promise!", log[0]);
Assert.Equal("Resolved!", log[1]);
} |
Hey, I am working on getting a popular library to work in Jint. At the moment I end up running into an issue related to variable initialization:
Following the stack trace, it points to this line:
This code runs fine in NodeJS. I am trying to get a minimum reproducible example but it is proving difficult. I would really appreciate any guidance as to where the issue could be coming from and what I could do in order to create a minimal repro example.
The text was updated successfully, but these errors were encountered: