chakra-core / ChakraCore

ChakraCore is an open source Javascript engine with a C API.
MIT License
9.1k stars 1.19k forks source link

A question about uninitialized variables #6516

Open NWU-NISL opened 3 years ago

NWU-NISL commented 3 years ago
Version

chakra-1_11_22

Test case
var h = function f(a0 = function () {
  a2;
}(), a2) {
};
h();
Execution steps
./ChakraCore/out/Debug/ch testcase.js
Output
Expected behavior
ReferenceError: can't access lexical declaration `a2' before initialization
Description

When executing this test case, a2 is not initialized before the call, other engines (such as v8, spiderMonkey, JavaScriptCore, etc.) threw a ReferenceError, but chakra did not do so. Is this a different implementation of chakra?

ppenzin commented 3 years ago

The symbol is defined in the second argument, but used in the first. I need to research the scoping rules a bit more, but if the arguments have to be evaluated left to right, this would be a bug.

pleath commented 3 years ago

The other engines are right. I can imagine a couple of possible root causes: a2 isn't being initialized prior to the evaluation of a0 in a way that supports the use-before-declaration check, or the reference to a2 isn't being properly bound to the parameter.

ppenzin commented 3 years ago

I am going to cautiously add some labels inviting contributions, I am still on the fence whether this should be a beginner issue.

pleath commented 3 years ago

Hm. I wouldn't necessarily call it a beginner issue. It likely has to do with the binding algorithm in the parser, which isn't trivial.

ppenzin commented 3 years ago

OK, let's keep this one off "good first issue" list for now.