Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: test/mjsunit/object-literal.js

Issue 2445333002: Ensure slow properties for simple {__proto__:null} literals. (Closed)
Patch Set: addressing nits Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/object-literal.js
diff --git a/test/mjsunit/object-literal.js b/test/mjsunit/object-literal.js
index 8fdf68d42e1b3e1a5ad8cbb57cfa7c2ccbb022ac..f3727163f6fbcde9469f2ea0b80f40fbaa4f494d 100644
--- a/test/mjsunit/object-literal.js
+++ b/test/mjsunit/object-literal.js
@@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// Flags: --allow-natives-syntax
+
var obj = {
a: 7,
b: { x: 12, y: 24 },
@@ -301,3 +303,50 @@ TestNumericNamesSetter(['1.2', '1.3'], {
var l = new Proxy({[prop]: 'my value'}, handler);
assertEquals('my value', l[prop]);
})();
+
+(function TestLiteralWithNullProto() {
+ // Assume dictionary usage for simple null prototype literal objects,
+ // this is equivalent to Object.create(null).
+ var obj = {__proto__:null};
+ assertFalse(%HasFastProperties(obj));
+ assertEquals(Object.getPrototypeOf(obj), null);
+ // Once we add inline properties we probably don't want slow properties
+ // anymore.
+ obj = {__proto__:null, a:1, b:2};
+ assertFalse(%HasFastProperties(obj));
+ assertEquals(Object.getPrototypeOf(obj), null);
+
+ obj = {__proto__: null, ["a"]: 1};
+ assertFalse(%HasFastProperties(obj));
+ assertEquals(Object.getPrototypeOf(obj), null);
+
+ obj = {__proto__: null, a: obj};
+ assertFalse(%HasFastProperties(obj));
+ assertEquals(Object.getPrototypeOf(obj), null);
+
+ obj = {a:1, b:2, __proto__:null};
+ assertFalse(%HasFastProperties(obj));
+ assertEquals(Object.getPrototypeOf(obj), null);
+
+ obj = {["a"]: 1, __proto__: null};
+ assertFalse(%HasFastProperties(obj));
+ assertEquals(Object.getPrototypeOf(obj), null);
+
+ obj = {a: obj, __proto__: null};
+ assertFalse(%HasFastProperties(obj));
+ assertEquals(Object.getPrototypeOf(obj), null);
+})();
+
+(function TestSlowLiteralOptimized() {
+ function f() {
+ return {__proto__:null};
+ }
+ let obj = f();
+ assertFalse(%HasFastProperties(obj));
+ assertEquals(Object.getPrototypeOf(obj), null);
+
+ %OptimizeFunctionOnNextCall(f);
+ obj = f();
+ assertFalse(%HasFastProperties(obj));
+ assertEquals(Object.getPrototypeOf(obj), null);
+})();

Powered by Google App Engine
This is Rietveld 408576698