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

Unified Diff: test/mjsunit/strong/class-object-frozen.js

Issue 1225303005: [strong] class objects created in strong mode are frozen (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove print Created 5 years, 5 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
« no previous file with comments | « src/full-codegen.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/strong/class-object-frozen.js
diff --git a/test/mjsunit/strong/class-object-frozen.js b/test/mjsunit/strong/class-object-frozen.js
new file mode 100644
index 0000000000000000000000000000000000000000..011a11d9fc461b8cd78f64a820e2fb82bb2acde7
--- /dev/null
+++ b/test/mjsunit/strong/class-object-frozen.js
@@ -0,0 +1,80 @@
+// 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 }
+ }
+ return Foo;
+}
+
+function getClassExpr() {
+ return (class { static get bar() { return 0 } });
+}
+
+function getClassStrong() {
+ "use strong";
+ class Foo {
+ static get bar() { return 0 }
+ }
+ return Foo;
+}
+
+function getClassExprStrong() {
+ "use strong";
+ return (class { static get bar() { return 0 } });
+}
+
+function addProperty(o) {
+ o.baz = 1;
+}
+
+function convertPropertyToData(o) {
+ assertTrue(o.hasOwnProperty("bar"));
+ Object.defineProperty(o, "bar", { value: 1 });
+}
+
+assertDoesNotThrow(function(){addProperty(getClass())});
+assertDoesNotThrow(function(){convertPropertyToData(getClass())});
+assertDoesNotThrow(function(){addProperty(getClassExpr())});
+assertDoesNotThrow(function(){convertPropertyToData(getClassExpr())});
+
+assertThrows(function(){addProperty(getClassStrong())}, TypeError);
+assertThrows(function(){convertPropertyToData(getClassStrong())}, TypeError);
+assertThrows(function(){addProperty(getClassExprStrong())}, TypeError);
+assertThrows(function(){convertPropertyToData(getClassExprStrong())},
+ TypeError);
+
+// Check strong classes don't freeze their parents.
+(function() {
+ "use strong";
+ let parent = getClass();
+
+ class Foo extends parent {
+ static get bar() { return 0 }
+ }
+
+ assertThrows(function(){addProperty(Foo)}, TypeError);
+ assertThrows(function(){convertPropertyToData(Foo)}, TypeError);
+ assertDoesNotThrow(function(){addProperty(parent)});
+ assertDoesNotThrow(function(){convertPropertyToData(parent)});
+})();
+
+// Check strong classes don't freeze their children.
+(function() {
+ let parent = getClassStrong();
+
+ class Foo extends parent {
+ static get bar() { return 0 }
+ }
+
+ assertThrows(function(){addProperty(parent)}, TypeError);
+ assertThrows(function(){convertPropertyToData(parent)}, TypeError);
+ assertDoesNotThrow(function(){addProperty(Foo)});
+ assertDoesNotThrow(function(){convertPropertyToData(Foo)});
+})();
« no previous file with comments | « src/full-codegen.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698