-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[BUGFIX release] Fix cyclic references on Array.prototype #17374
[BUGFIX release] Fix cyclic references on Array.prototype #17374
Conversation
9c805b7
to
36fce9e
Compare
36fce9e
to
3029e9d
Compare
I am looking at this again as it seems to have failed to correctly identify the point in git commit history was introduced. (It appears to pass against 246435e although that seems to be where the regression happened) |
@rwjblue Thanks for taking this on. Could you help me understand something here? How come when I checkout 246435e and build it, running the script below in node shows the problem, but running the test that import Test by loading Ember in NodeJSScript global.EmberENV = {
EXTEND_PROTOTYPES: false,
};
const Ember = require('./dist/ember.debug.js');
const isOK = (a, original) => {
original = original || a;
for (let p in a) {
if (a[p] === a) {
return false;
}
else if (typeof a === 'object') {
try {
if (!isOK(a[p], a)) {
return false;
}
} catch(e) {
console.warn(`Caught exception while attempting recursive call: ${e.message}`);
return false;
}
}
}
return true;
}
const check = (klass) => {
const a = new klass();
const result = isOK(a);
console.log(` * ${klass.name} ${result ? 'is ok' : 'is NOT OK -- cycle detected!'}`);
}
// Extend this instead of built-in Array to avoid pollution
class ExtendedArray extends Array {}
Ember.NativeArray.apply(ExtendedArray.prototype);
// Just for fun, check nested case:
class CyclicThing {
constructor() {
this.sneaky = {
firstLevelProp: 'foo',
bar: {
baz: 'quux',
cycleWillBeHere: null
}
}
this.sneaky.bar.cycleWillBeHere = this.sneaky;
}
}
[Array, ExtendedArray, CyclicThing].forEach(check); Output
|
Also, FWIW, there's an |
…ble. This fixes the following example case: ```js $.extend(true, {}, {a:['a']}) ``` Prior to this change, the above would trigger maximum call stack error. This is because the `[]` computed property added to the array prototype references itself, which ultimately makes `$.extend` (and other deep equality style comparisons) fail.
Just pushed a commit fixing the issue (details in the comments and commit message). |
Unfortunately, `class Foo extends Array{}` doesn't work well with older browsers (and would even require changes in our transpilation for production builds for modern ones). The actual test doesn't care if its running on an Array (without the fixes in this PR this modified test still fails the same way).
My first non-doc
ember.js
PR so please be kind :)