2015-07-13 15:00:55 +00:00
|
|
|
// Copyright 2015 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: --strong-mode
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function getClass() {
|
|
|
|
class Foo {
|
|
|
|
static get bar() { return 0 }
|
2015-07-14 11:31:38 +00:00
|
|
|
get bar() { return 0 }
|
2015-07-13 15:00:55 +00:00
|
|
|
}
|
|
|
|
return Foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getClassExpr() {
|
2015-07-14 11:31:38 +00:00
|
|
|
return (class { static get bar() { return 0 } get bar() { return 0 } });
|
2015-07-13 15:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getClassStrong() {
|
|
|
|
"use strong";
|
|
|
|
class Foo {
|
|
|
|
static get bar() { return 0 }
|
2015-07-14 11:31:38 +00:00
|
|
|
get bar() { return 0 }
|
2015-07-13 15:00:55 +00:00
|
|
|
}
|
|
|
|
return Foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getClassExprStrong() {
|
|
|
|
"use strong";
|
2015-07-14 11:31:38 +00:00
|
|
|
return (class { static get bar() { return 0 } get bar() { return 0 } });
|
2015-07-13 15:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function addProperty(o) {
|
|
|
|
o.baz = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertPropertyToData(o) {
|
|
|
|
assertTrue(o.hasOwnProperty("bar"));
|
|
|
|
Object.defineProperty(o, "bar", { value: 1 });
|
|
|
|
}
|
|
|
|
|
2015-07-14 11:31:38 +00:00
|
|
|
function testWeakClass(classFunc) {
|
|
|
|
assertDoesNotThrow(function(){addProperty(classFunc())});
|
|
|
|
assertDoesNotThrow(function(){addProperty(classFunc().prototype)});
|
|
|
|
assertDoesNotThrow(function(){convertPropertyToData(classFunc())});
|
|
|
|
assertDoesNotThrow(function(){convertPropertyToData(classFunc().prototype)});
|
|
|
|
}
|
|
|
|
|
|
|
|
function testStrongClass(classFunc) {
|
|
|
|
assertThrows(function(){addProperty(classFunc())}, TypeError);
|
|
|
|
assertThrows(function(){addProperty(classFunc().prototype)}, TypeError);
|
|
|
|
assertThrows(function(){convertPropertyToData(classFunc())}, TypeError);
|
|
|
|
assertThrows(function(){convertPropertyToData(classFunc().prototype)},
|
|
|
|
TypeError);
|
|
|
|
}
|
|
|
|
|
|
|
|
testWeakClass(getClass);
|
|
|
|
testWeakClass(getClassExpr);
|
2015-07-13 15:00:55 +00:00
|
|
|
|
2015-07-14 11:31:38 +00:00
|
|
|
testStrongClass(getClassStrong);
|
|
|
|
testStrongClass(getClassExprStrong);
|
2015-07-13 15:00:55 +00:00
|
|
|
|
|
|
|
// Check strong classes don't freeze their parents.
|
|
|
|
(function() {
|
|
|
|
let parent = getClass();
|
|
|
|
|
2015-07-14 11:31:38 +00:00
|
|
|
let classFunc = function() {
|
|
|
|
"use strong";
|
|
|
|
class Foo extends parent {
|
|
|
|
static get bar() { return 0 }
|
|
|
|
get bar() { return 0 }
|
|
|
|
}
|
|
|
|
return Foo;
|
2015-07-13 15:00:55 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 11:31:38 +00:00
|
|
|
testStrongClass(classFunc);
|
2015-07-13 15:00:55 +00:00
|
|
|
assertDoesNotThrow(function(){addProperty(parent)});
|
|
|
|
assertDoesNotThrow(function(){convertPropertyToData(parent)});
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Check strong classes don't freeze their children.
|
|
|
|
(function() {
|
|
|
|
let parent = getClassStrong();
|
|
|
|
|
2015-07-14 11:31:38 +00:00
|
|
|
let classFunc = function() {
|
|
|
|
class Foo extends parent {
|
|
|
|
static get bar() { return 0 }
|
|
|
|
get bar() { return 0 }
|
|
|
|
}
|
|
|
|
return Foo;
|
2015-07-13 15:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assertThrows(function(){addProperty(parent)}, TypeError);
|
|
|
|
assertThrows(function(){convertPropertyToData(parent)}, TypeError);
|
2015-07-14 11:31:38 +00:00
|
|
|
testWeakClass(classFunc);
|
2015-07-13 15:00:55 +00:00
|
|
|
})();
|