f6450b97ec
1) Computed property keys (esp functions in them) shouldn't be inside the object literal scope. 2) I was using an imprecise "maybe uses super" and storing it to preparse data. This won't fly, since it pollutes sister scopes and leads to confusion wrt whether an object literal needs a home object or not. Made it precise (mostly cancelling changes in the original CL). 3) PreParser::NewSuperPropertyReference was creating a VariableProxy for this_function (which made it used) -> inconsistent scopes between parsing and preparsing. 4) MultipleEntryBlockContextScope was messing up the accumulator Original: https://chromium-review.googlesource.com/c/v8/v8/+/2563275 This saves memory (the home object doesn't need to be stored for each method, but only once per class) and hopefully makes the home object a constant in the optimized code. Detailed documentation of the changes: https://docs.google.com/document/d/1ZVXcoQdf9IdMsnRI9iyUjyq9NDoEyx9nA3XqMgwflMs/edit?usp=sharing Bug: v8:9237, chromium:1167918, chromium:1167981, chromium:1167988, chromium:1168055 Change-Id: I4f53f18cc18762c33e53d8c802909b42f1c33538 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2637220 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Marja Hölttä <marja@chromium.org> Cr-Commit-Position: refs/heads/master@{#72169}
130 lines
2.3 KiB
JavaScript
130 lines
2.3 KiB
JavaScript
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flags: --allow-natives-syntax
|
|
|
|
(function TestMethod() {
|
|
var object = {
|
|
__proto__: {
|
|
method(x) {
|
|
return 'proto' + x;
|
|
}
|
|
},
|
|
method(x) {
|
|
return super.method(x);
|
|
}
|
|
};
|
|
assertEquals('proto42', object.method(42));
|
|
})();
|
|
|
|
|
|
(function TestGetter() {
|
|
var object = {
|
|
__proto__: {
|
|
_x: 42,
|
|
get x() {
|
|
return 'proto' + this._x;
|
|
}
|
|
},
|
|
get x() {
|
|
return super.x;
|
|
}
|
|
};
|
|
assertEquals('proto42', object.x);
|
|
})();
|
|
|
|
|
|
(function TestSetter() {
|
|
var object = {
|
|
__proto__: {
|
|
_x: 0,
|
|
set x(v) {
|
|
return this._x = v;
|
|
}
|
|
},
|
|
set x(v) {
|
|
super.x = v;
|
|
}
|
|
};
|
|
assertEquals(1, object.x = 1);
|
|
assertEquals(1, object._x);
|
|
assertEquals(0, Object.getPrototypeOf(object)._x);
|
|
})();
|
|
|
|
|
|
(function TestOptimized() {
|
|
// Object literals without any accessors get optimized.
|
|
var object = {
|
|
method() {
|
|
return super.toString;
|
|
}
|
|
};
|
|
assertEquals(Object.prototype.toString, object.method());
|
|
})();
|
|
|
|
|
|
(function TestConciseGenerator() {
|
|
var o = {
|
|
__proto__: {
|
|
m() {
|
|
return 42;
|
|
}
|
|
},
|
|
*g() {
|
|
yield super.m();
|
|
},
|
|
};
|
|
|
|
assertEquals(42, o.g().next().value);
|
|
})();
|
|
|
|
|
|
(function TestSuperPropertyInEval() {
|
|
var y = 3;
|
|
var p = {
|
|
m() { return 1; },
|
|
get x() { return 2; }
|
|
};
|
|
var o = {
|
|
__proto__: p,
|
|
evalM() {
|
|
assertEquals(1, eval('super.m()'));
|
|
},
|
|
evalX() {
|
|
assertEquals(2, eval('super.x'));
|
|
},
|
|
globalEval1() {
|
|
assertThrows('super.x', SyntaxError);
|
|
assertThrows('super.m()', SyntaxError);
|
|
},
|
|
globalEval2() {
|
|
super.x;
|
|
assertThrows('super.x', SyntaxError);
|
|
assertThrows('super.m()', SyntaxError);
|
|
}
|
|
};
|
|
o.evalM();
|
|
o.evalX();
|
|
o.globalEval1();
|
|
o.globalEval2();
|
|
})();
|
|
|
|
|
|
(function TestSuperPropertyInArrow() {
|
|
var y = 3;
|
|
var p = {
|
|
m() { return 1; },
|
|
get x() { return 2; }
|
|
};
|
|
var o = {
|
|
__proto__: p,
|
|
arrow() {
|
|
assertSame(super.x, (() => super.x)());
|
|
assertSame(super.m(), (() => super.m())());
|
|
return (() => super.m())();
|
|
}
|
|
};
|
|
assertSame(1, o.arrow());
|
|
})();
|