Commit 2c95484a authored by Mythri A's avatar Mythri A Committed by Commit Bot

Reland [cleanup][test] split es6/classes.js into different tests

Reland after splitting large classes further.

es6/classes.js is large and causes timeouts and OOM on some of the
configurations.

Bug: v8:9246
Change-Id: I51952447eb6a6b46d78410d5d3798292f5a8d87d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1706061
Commit-Queue: Mythri Alle <mythria@chromium.org>
Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62864}
parent 1c2141ae
// 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
var b = 'b';
(function TestOverwritingInstanceAccessors() {
var C, desc;
C = class {
[b]() { return 'B'; };
get b() { return 'get B'; };
};
desc = Object.getOwnPropertyDescriptor(C.prototype, 'b');
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
assertEquals('get B', desc.get());
assertEquals(undefined, desc.set);
C = class {
[b]() { return 'B'; };
set b(v) { return 'set B'; };
};
desc = Object.getOwnPropertyDescriptor(C.prototype, 'b');
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
assertEquals(undefined, desc.get);
assertEquals('set B', desc.set());
C = class {
set b(v) { return 'get B'; };
[b]() { return 'B'; };
get b() { return 'get B'; };
};
desc = Object.getOwnPropertyDescriptor(C.prototype, 'b');
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
assertEquals('get B', desc.get());
assertEquals(undefined, desc.set);
C = class {
get b() { return 'get B'; };
[b]() { return 'B'; };
set b(v) { return 'set B'; };
};
desc = Object.getOwnPropertyDescriptor(C.prototype, 'b');
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
assertEquals(undefined, desc.get);
assertEquals('set B', desc.set());
})();
(function TestOverwritingStaticAccessors() {
var C, desc;
C = class {
static [b]() { return 'B'; };
static get b() { return 'get B'; };
};
desc = Object.getOwnPropertyDescriptor(C, 'b');
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
assertEquals('get B', desc.get());
assertEquals(undefined, desc.set);
C = class {
static [b]() { return 'B'; };
static set b(v) { return 'set B'; };
};
desc = Object.getOwnPropertyDescriptor(C, 'b');
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
assertEquals(undefined, desc.get);
assertEquals('set B', desc.set());
C = class {
static set b(v) { return 'get B'; };
static [b]() { return 'B'; };
static get b() { return 'get B'; };
};
desc = Object.getOwnPropertyDescriptor(C, 'b');
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
assertEquals('get B', desc.get());
assertEquals(undefined, desc.set);
C = class {
static get b() { return 'get B'; };
static [b]() { return 'B'; };
static set b(v) { return 'set B'; };
};
desc = Object.getOwnPropertyDescriptor(C, 'b');
assertFalse(desc.enumerable);
assertTrue(desc.configurable);
assertEquals(undefined, desc.get);
assertEquals('set B', desc.set());
})();
// 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 TestDefaultConstructorNoCrash() {
// Regression test for https://code.google.com/p/v8/issues/detail?id=3661
class C {}
assertThrows(function () {C();}, TypeError);
assertThrows(function () {C(1);}, TypeError);
assertTrue(new C() instanceof C);
assertTrue(new C(1) instanceof C);
})();
(function TestConstructorCall(){
var realmIndex = Realm.create();
var otherTypeError = Realm.eval(realmIndex, "TypeError");
var A = Realm.eval(realmIndex, '"use strict"; class A {}; A');
var instance = new A();
var constructor = instance.constructor;
var otherTypeError = Realm.eval(realmIndex, 'TypeError');
if (otherTypeError === TypeError) {
throw Error('Should not happen!');
}
// ES6 9.2.1[[Call]] throws a TypeError in the caller context/Realm when the
// called function is a classConstructor
assertThrows(function() { Realm.eval(realmIndex, "A()") }, otherTypeError);
assertThrows(function() { instance.constructor() }, TypeError);
assertThrows(function() { A() }, TypeError);
// ES6 9.3.1 call() first activates the callee context before invoking the
// method. The TypeError from the constructor is thus thrown in the other
// Realm.
assertThrows(function() { Realm.eval(realmIndex, "A.call()") },
otherTypeError);
assertThrows(function() { constructor.call() }, otherTypeError);
assertThrows(function() { A.call() }, otherTypeError);
})();
(function TestConstructorCallOptimized() {
class A { };
function invoke_constructor() { A() }
function call_constructor() { A.call() }
function apply_constructor() { A.apply() }
%PrepareFunctionForOptimization(invoke_constructor);
%PrepareFunctionForOptimization(call_constructor);
%PrepareFunctionForOptimization(apply_constructor);
for (var i=0; i<3; i++) {
assertThrows(invoke_constructor);
assertThrows(call_constructor);
assertThrows(apply_constructor);
}
// Make sure we still check for class constructors when calling optimized
// code.
%OptimizeFunctionOnNextCall(invoke_constructor);
assertThrows(invoke_constructor);
%OptimizeFunctionOnNextCall(call_constructor);
assertThrows(call_constructor);
%OptimizeFunctionOnNextCall(apply_constructor);
assertThrows(apply_constructor);
})();
(function TestDefaultConstructor() {
var calls = 0;
class Base {
constructor() {
calls++;
}
}
class Derived extends Base {}
var object = new Derived;
assertEquals(1, calls);
calls = 0;
assertThrows(function() { Derived(); }, TypeError);
assertEquals(0, calls);
})();
(function TestDefaultConstructorArguments() {
var args, self;
class Base {
constructor() {
self = this;
args = arguments;
}
}
class Derived extends Base {}
new Derived;
assertEquals(0, args.length);
new Derived(0, 1, 2);
assertEquals(3, args.length);
assertTrue(self instanceof Derived);
var arr = new Array(100);
var obj = {};
assertThrows(function() {Derived.apply(obj, arr);}, TypeError);
})();
(function TestDefaultConstructorArguments2() {
var args;
class Base {
constructor(x, y) {
args = arguments;
}
}
class Derived extends Base {}
new Derived;
assertEquals(0, args.length);
new Derived(1);
assertEquals(1, args.length);
assertEquals(1, args[0]);
new Derived(1, 2, 3);
assertEquals(3, args.length);
assertEquals(1, args[0]);
assertEquals(2, args[1]);
assertEquals(3, args[2]);
})();
// 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 TestNameBindingConst() {
assertThrows('class C { constructor() { C = 42; } }; new C();', TypeError);
assertThrows('new (class C { constructor() { C = 42; } })', TypeError);
assertThrows('class C { m() { C = 42; } }; new C().m()', TypeError);
assertThrows('new (class C { m() { C = 42; } }).m()', TypeError);
assertThrows('class C { get x() { C = 42; } }; new C().x', TypeError);
assertThrows('(new (class C { get x() { C = 42; } })).x', TypeError);
assertThrows('class C { set x(_) { C = 42; } }; new C().x = 15;', TypeError);
assertThrows('(new (class C { set x(_) { C = 42; } })).x = 15;', TypeError);
})();
(function TestNameBinding() {
var C2;
class C {
constructor() {
C2 = C;
}
m() {
C2 = C;
}
get x() {
C2 = C;
}
set x(_) {
C2 = C;
}
}
new C();
assertEquals(C, C2);
C2 = undefined;
new C().m();
assertEquals(C, C2);
C2 = undefined;
new C().x;
assertEquals(C, C2);
C2 = undefined;
new C().x = 1;
assertEquals(C, C2);
})();
(function TestNameBindingExpression() {
var C3;
var C = class C2 {
constructor() {
assertEquals(C2, C);
C3 = C2;
}
m() {
assertEquals(C2, C);
C3 = C2;
}
get x() {
assertEquals(C2, C);
C3 = C2;
}
set x(_) {
assertEquals(C2, C);
C3 = C2;
}
}
new C();
assertEquals(C, C3);
C3 = undefined;
new C().m();
assertEquals(C, C3);
C3 = undefined;
new C().x;
assertEquals(C, C3);
C3 = undefined;
new C().x = 1;
assertEquals(C, C3);
})();
(function TestNameBindingInExtendsExpression() {
assertThrows(function() {
class x extends x {}
}, ReferenceError);
assertThrows(function() {
(class x extends x {});
}, ReferenceError);
assertThrows(function() {
var x = (class x extends x {});
}, ReferenceError);
})();
// 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 assertMethodDescriptor(object, name) {
var descr = Object.getOwnPropertyDescriptor(object, name);
assertTrue(descr.configurable);
assertFalse(descr.enumerable);
assertTrue(descr.writable);
assertEquals('function', typeof descr.value);
assertFalse('prototype' in descr.value);
assertEquals(name, descr.value.name);
}
function assertAccessorDescriptor(object, name) {
var descr = Object.getOwnPropertyDescriptor(object, name);
assertTrue(descr.configurable);
assertFalse(descr.enumerable);
assertEquals('function', typeof descr.get);
assertEquals('function', typeof descr.set);
assertFalse('prototype' in descr.get);
assertFalse('prototype' in descr.set);
assertEquals("get " + name, descr.get.name);
assertEquals("set " + name, descr.set.name);
}
(function TestProto() {
class C {
__proto__() { return 1; }
}
assertMethodDescriptor(C.prototype, '__proto__');
assertEquals(1, new C().__proto__());
})();
(function TestProtoStatic() {
class C {
static __proto__() { return 1; }
}
assertMethodDescriptor(C, '__proto__');
assertEquals(1, C.__proto__());
})();
(function TestProtoAccessor() {
class C {
get __proto__() { return this._p; }
set __proto__(v) { this._p = v; }
}
assertAccessorDescriptor(C.prototype, '__proto__');
var c = new C();
c._p = 1;
assertEquals(1, c.__proto__);
c.__proto__ = 2;
assertEquals(2, c.__proto__);
})();
(function TestStaticProtoAccessor() {
class C {
static get __proto__() { return this._p; }
static set __proto__(v) { this._p = v; }
}
assertAccessorDescriptor(C, '__proto__');
C._p = 1;
assertEquals(1, C.__proto__);
C.__proto__ = 2;
assertEquals(2, C.__proto__);
})();
(function TestSettersOnProto() {
function Base() {}
Base.prototype = {
set constructor(_) {
assertUnreachable();
},
set m(_) {
assertUnreachable();
}
};
Object.defineProperty(Base, 'staticM', {
set: function() {
assertUnreachable();
}
});
class C extends Base {
m() {
return 1;
}
static staticM() {
return 2;
}
}
assertEquals(1, new C().m());
assertEquals(2, C.staticM());
})();
(function TestConstructableButNoPrototype() {
var Base = function() {}.bind();
assertThrows(function() {
class C extends Base {}
}, TypeError);
})();
(function TestPrototypeGetter() {
var calls = 0;
var Base = function() {}.bind();
Object.defineProperty(Base, 'prototype', {
get: function() {
calls++;
return null;
},
configurable: true
});
class C extends Base {}
assertEquals(1, calls);
calls = 0;
Object.defineProperty(Base, 'prototype', {
get: function() {
calls++;
return 42;
},
configurable: true
});
assertThrows(function() {
class C extends Base {}
}, TypeError);
assertEquals(1, calls);
})();
(function TestPrototypeSetter() {
var Base = function() {}.bind();
Object.defineProperty(Base, 'prototype', {
set: function() {
assertUnreachable();
}
});
assertThrows(function() {
class C extends Base {}
}, TypeError);
})();
// 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 TestThisAccessRestriction() {
class Base {}
(function() {
class C extends Base {
constructor() {
var y;
super();
}
}; new C();
}());
assertThrows(function() {
class C extends Base {
constructor() {
super(this.x);
}
}; new C();
}, ReferenceError);
assertThrows(function() {
class C extends Base {
constructor() {
super(this);
}
}; new C();
}, ReferenceError);
assertThrows(function() {
class C extends Base {
constructor() {
super.method();
super(this);
}
}; new C();
}, ReferenceError);
assertThrows(function() {
class C extends Base {
constructor() {
super(super.method());
}
}; new C();
}, ReferenceError);
assertThrows(function() {
class C extends Base {
constructor() {
super(super());
}
}; new C();
}, ReferenceError);
assertThrows(function() {
class C extends Base {
constructor() {
super(1, 2, Object.getPrototypeOf(this));
}
}; new C();
}, ReferenceError);
(function() {
class C extends Base {
constructor() {
{ super(1, 2); }
}
}; new C();
}());
(function() {
class C extends Base {
constructor() {
if (1) super();
}
}; new C();
}());
class C1 extends Object {
constructor() {
'use strict';
super();
}
};
new C1();
class C2 extends Object {
constructor() {
; 'use strict';;;;;
super();
}
};
new C2();
class C3 extends Object {
constructor() {
; 'use strict';;;;;
// This is a comment.
super();
}
};
new C3();
}());
function testClassRestrictedProperties(C) {
assertEquals(false, C.hasOwnProperty("arguments"));
assertThrows(function() { return C.arguments; }, TypeError);
assertThrows(function() { C.arguments = {}; }, TypeError);
assertEquals(false, C.hasOwnProperty("caller"));
assertThrows(function() { return C.caller; }, TypeError);
assertThrows(function() { C.caller = {}; }, TypeError);
assertEquals(false, (new C).method.hasOwnProperty("arguments"));
assertThrows(function() { return new C().method.arguments; }, TypeError);
assertThrows(function() { new C().method.arguments = {}; }, TypeError);
assertEquals(false, (new C).method.hasOwnProperty("caller"));
assertThrows(function() { return new C().method.caller; }, TypeError);
assertThrows(function() { new C().method.caller = {}; }, TypeError);
}
(function testRestrictedPropertiesStrict() {
"use strict";
class ClassWithDefaultConstructor {
method() {}
}
class Class {
constructor() {}
method() {}
}
class DerivedClassWithDefaultConstructor extends Class {}
class DerivedClass extends Class { constructor() { super(); } }
testClassRestrictedProperties(ClassWithDefaultConstructor);
testClassRestrictedProperties(Class);
testClassRestrictedProperties(DerivedClassWithDefaultConstructor);
testClassRestrictedProperties(DerivedClass);
testClassRestrictedProperties(class { method() {} });
testClassRestrictedProperties(class { constructor() {} method() {} });
testClassRestrictedProperties(class extends Class { });
testClassRestrictedProperties(
class extends Class { constructor() { super(); } });
})();
(function testRestrictedPropertiesSloppy() {
class ClassWithDefaultConstructor {
method() {}
}
class Class {
constructor() {}
method() {}
}
class DerivedClassWithDefaultConstructor extends Class {}
class DerivedClass extends Class { constructor() { super(); } }
testClassRestrictedProperties(ClassWithDefaultConstructor);
testClassRestrictedProperties(Class);
testClassRestrictedProperties(DerivedClassWithDefaultConstructor);
testClassRestrictedProperties(DerivedClass);
testClassRestrictedProperties(class { method() {} });
testClassRestrictedProperties(class { constructor() {} method() {} });
testClassRestrictedProperties(class extends Class { });
testClassRestrictedProperties(
class extends Class { constructor() { super(); } });
})();
// 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 TestSuperInMethods() {
class B {
method() {
return 1;
}
get x() {
return 2;
}
}
class C extends B {
method() {
assertEquals(2, super.x);
return super.method();
}
}
assertEquals(1, new C().method());
})();
(function TestSuperInGetter() {
class B {
method() {
return 1;
}
get x() {
return 2;
}
}
class C extends B {
get y() {
assertEquals(2, super.x);
return super.method();
}
}
assertEquals(1, new C().y);
})();
(function TestSuperInSetter() {
class B {
method() {
return 1;
}
get x() {
return 2;
}
}
class C extends B {
set y(v) {
assertEquals(3, v);
assertEquals(2, super.x);
assertEquals(1, super.method());
}
}
assertEquals(3, new C().y = 3);
})();
(function TestSuperInStaticMethods() {
class B {
static method() {
return 1;
}
static get x() {
return 2;
}
}
class C extends B {
static method() {
assertEquals(2, super.x);
return super.method();
}
}
assertEquals(1, C.method());
})();
(function TestSuperInStaticGetter() {
class B {
static method() {
return 1;
}
static get x() {
return 2;
}
}
class C extends B {
static get x() {
assertEquals(2, super.x);
return super.method();
}
}
assertEquals(1, C.x);
})();
(function TestSuperInStaticSetter() {
class B {
static method() {
return 1;
}
static get x() {
return 2;
}
}
class C extends B {
static set x(v) {
assertEquals(3, v);
assertEquals(2, super.x);
assertEquals(1, super.method());
}
}
assertEquals(3, C.x = 3);
})();
This diff is collapsed.
// Copyright 2019 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 testLargeClassesMethods() {
// This is to test for dictionary mode when there more than
// kMaxNumberOfDescriptors (1024) properties.
const kLimit = 1030;
let evalString = "(function(i) { " +
"let clazz = class { " +
" constructor(i) { this.value = i; } ";
for (let i = 0; i < kLimit; i++) {
evalString += "property"+i+"() { return "+i+"; }; "
}
evalString += "};" +
" return new clazz(i); })";
let fn = eval(evalString);
%PrepareFunctionForOptimization(fn);
assertEquals(fn(1).value, 1);
assertEquals(fn(2).value, 2);
assertEquals(fn(3).value, 3);
%OptimizeFunctionOnNextCall(fn);
assertEquals(fn(4).value, 4);
let instance = fn(1);
assertEquals(Object.getOwnPropertyNames(instance).length, 1);
assertEquals(Object.getOwnPropertyNames(instance.__proto__).length,
kLimit + 1);
// Call all instance functions.
for (let i = 0; i < kLimit; i++) {
const key = "property" + i;
assertEquals(instance[key](), i);
}
})();
// Copyright 2019 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 testLargeClassesProperties(){
// This is to test for dictionary mode when there more than
// kMaxNumberOfDescriptors (1024) properties.
const kLimit = 1030;
let evalString = "(function(i) { " +
"let clazz = class { " +
" constructor(i) { this.value = i;";
for (let i = 0; i < kLimit ; i++) {
evalString += "this.property"+i +" = "+i+"; "
}
evalString += "}};" +
" return (new clazz(i)); })";
let fn = eval(evalString);
%PrepareFunctionForOptimization(fn);
assertEquals(fn(1).value, 1);
assertEquals(fn(2).value, 2);
assertEquals(fn(3).value, 3);
%OptimizeFunctionOnNextCall(fn);
assertEquals(fn(4).value, 4);
let instance = fn(1);
assertEquals(Object.getOwnPropertyNames(instance).length, kLimit+1);
// Get and set all properties.
for (let i = 0; i < kLimit; i++) {
const key = "property" + i;
assertEquals(instance[key], i);
const value = "value"+i;
instance[key] = value;
assertEquals(instance[key], value);
}
})();
// Copyright 2019 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 testLargeClassesStaticMethods() {
// This is to test for dictionary mode when there more than
// kMaxNumberOfDescriptors (1024) properties.
const kLimit = 1030;
let evalString = "(function(i) { " +
"let clazz = class { " +
" constructor(i) { this.value = i; } ";
for (let i = 0; i < kLimit; i++) {
evalString += "static property"+i+"() { return "+i+" }; "
}
evalString += "};" +
" return new clazz(i); })";
let fn = eval(evalString);
%PrepareFunctionForOptimization(fn);
assertEquals(fn(1).value, 1);
assertEquals(fn(2).value, 2);
assertEquals(fn(3).value, 3);
%OptimizeFunctionOnNextCall(fn);
assertEquals(fn(4).value, 4);
let instance = fn(1);
assertEquals(Object.getOwnPropertyNames(instance).length, 1);
assertEquals(instance.value, 1);
instance.value = 10;
assertEquals(instance.value, 10);
// kLimit + nof default properties (length, prototype, name).
assertEquals(Object.getOwnPropertyNames(instance.constructor).length,
kLimit + 3);
// Call all static properties.
for (let i = 0; i < kLimit; i++) {
const key = "property" + i;
assertEquals(instance.constructor[key](), i);
}
})();
......@@ -581,7 +581,7 @@
'regress/regress-599414-array-concat-fast-path': [PASS, SLOW],
# BUG(v8:9026). Flaky timeouts.
'es6/classes': [SKIP],
'es6/large-classes-properties': [SKIP],
# Slow tests.
'compiler/regress-9017': [PASS, SLOW],
......@@ -855,7 +855,6 @@
'd8/d8-arguments': [SKIP],
# Fails allocation on tsan.
'es6/classes': [PASS, ['tsan', SKIP]],
'regress/regress-779407': [PASS, ['tsan', SKIP]],
# Tests that fail some assertions due to checking internal state sensitive
......@@ -952,10 +951,9 @@
# Flaky crash on Odroid devices: https://crbug.com/v8/7678
'regress/regress-336820': [PASS, ['arch == arm and not simulator_run', SKIP]],
# Too slow for TSAN in stress mode.
# Goes OOM on ODROID devices: https://crbug.com/v8/9026
# Too slow on PPC: https://crbug.com/v8/9246
'es6/classes': [PASS, SLOW, ['tsan or (arch == arm and not simulator_run) or arch in [ppc, ppc64]', SKIP]],
'es6/large-classes-properties': [PASS, SLOW, ['(arch == arm and not simulator_run) or arch in [ppc, ppc64]', SKIP]],
'regress/regress-1122': [PASS, ['tsan', SKIP]],
# Too slow with gc_stress on arm64.
......@@ -975,7 +973,7 @@
##############################################################################
['variant == stress and (arch == arm or arch == arm64) and simulator_run', {
# Slow tests: https://crbug.com/v8/7783
'es6/classes': [SKIP],
'es6/large-classes-properties': [SKIP],
'generated-transition-stub': [SKIP],
'regress/regress-336820': [SKIP],
'wasm/grow-memory': [SKIP],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment