Optimisation bug in Node 5.x causes constructing ADTs to randomly fail
robotlolita opened this issue · 0 comments
data(typeId, patterns)
fails in Node 5.x (v8 4.6.85.x) due to a bug in the optimising compiler. This bug has since been fixed (Node 6+ versions are okay), and does not affect older v8 versions (Node 4.x is also okay).
What's happening here?
Folktale uses an extend function to define properties on objects:
function extend(target, ...sources) {
sources.forEach(source => {
keys(source).forEach(key => {
if (key === 'prototype') {
target[key] = source[key];
} else {
defineProperty(target, key, property(source, key));
}
});
symbols(source).forEach(symbol => {
defineProperty(target, symbol, property(source, symbol));
});
});
return target;
}
This function is then invoked in the defineVariants function to construct Variant objects. Certain optimisations to these two functions cause the expression:
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
To be evaluated as:
Object.defineProperty(target, key, undefined);
Thus causing the native defineProperty
function to fail.
What we're doing?
These optimisations can be prevented by using something like eval('true')
somewhere in the defineVariants
function. They might also not kick in if the code is written in a different way. Because these are unpredictable optimisation bugs, and because Node 5.x isn't a stable Node version anymore, we're dropping support for it — as optimisations in that version are not generally safe.
What platforms are affected?
The entire Node 5.x branch (v8 4.6.85.x) is affected by this issue.
Recommended action for affected users
If you're using Node 5.x, you should upgrade to Node 6.x (latest stable branch), or downgrade to Node 4.x (LTS version)