v8/test/mjsunit/dictionary-properties.js
Frank Emrich 527754fbae [dict-proto] Constness tracking of dictionary properties (jitless)
For dictionary mode objects, whether or not a property is constant was
not tracked before. This CL makes the required non-Turbofan changes,
guarded behind the new flag V8_DICT_PROPERTY_CONST_TRACKING.

In addition, prototypes are not converted to fast mode objects if this
flags is enabled.

Bug: v8:11247
Change-Id: Ia5942733239a97560b6efc015f0e25a35fea3d7a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2566757
Commit-Queue: Frank Emrich <emrich@google.com>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72524}
2021-02-04 11:42:33 +00:00

67 lines
1.8 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
// Test loading existent and nonexistent properties from dictionary
// mode objects.
function SlowObject() {
this.foo = 1;
this.bar = 2;
this.qux = 3;
this.z = 4;
delete this.qux;
assertFalse(%HasFastProperties(this));
}
function SlowObjectWithBaz() {
var o = new SlowObject();
o.baz = 4;
return o;
}
function Load(o) {
return o.baz;
}
for (var i = 0; i < 10; i++) {
var o1 = new SlowObject();
var o2 = SlowObjectWithBaz();
assertEquals(undefined, Load(o1));
assertEquals(4, Load(o2));
}
// Test objects getting optimized as fast prototypes.
function SlowPrototype() {
this.foo = 1;
}
SlowPrototype.prototype.bar = 2;
SlowPrototype.prototype.baz = 3;
SlowPrototype.prototype.z = 4;
delete SlowPrototype.prototype.baz;
assertFalse(%HasFastProperties(SlowPrototype.prototype));
var slow_proto = new SlowPrototype;
// ICs make prototypes fast.
function ic() { return slow_proto.bar; }
ic();
ic();
assertEquals(!%IsDictPropertyConstTrackingEnabled(),
%HasFastProperties(slow_proto.__proto__));
// Prototypes stay fast even after deleting properties.
assertEquals(!%IsDictPropertyConstTrackingEnabled(),
%HasFastProperties(SlowPrototype.prototype));
var fast_proto = new SlowPrototype();
assertEquals(!%IsDictPropertyConstTrackingEnabled(),
%HasFastProperties(SlowPrototype.prototype));
assertEquals(!%IsDictPropertyConstTrackingEnabled(),
%HasFastProperties(fast_proto.__proto__));
if (!%IsDictPropertyConstTrackingEnabled()) {
assertTrue(%HasFastProperties(SlowPrototype.prototype));
assertTrue(%HasFastProperties(fast_proto.__proto__));
}