blob: 53706df1eede758e954673b7b23288c1d022eea6 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Flags: --strong-mode --allow-natives-syntax
6
7// TODO(conradw): Track implementation of strong bit for other objects, add
8// tests.
9
10function getSloppyObjects() {
11 return [(function(){}), ({})];
12}
13
14function getStrictObjects() {
15 "use strict";
16 return [(function(){}), ({})];
17}
18
19function getStrongObjects() {
20 "use strong";
21 return [(function(){}), ({})];
22}
23
24function declareObjectLiteralWithProtoSloppy() {
25 return {__proto__: {}};
26}
27
28function declareObjectLiteralWithProtoStrong() {
29 "use strong";
30 return {__proto__: {}};
31}
32
33function testStrongObjectSetProto() {
34 "use strict";
35 let sloppyObjects = getSloppyObjects();
36 let strictObjects = getStrictObjects();
37 let strongObjects = getStrongObjects();
38 let weakObjects = sloppyObjects.concat(strictObjects);
39
40 for (let o of weakObjects) {
41 let setProtoBuiltin = function(o){Object.setPrototypeOf(o, {})};
42 let setProtoProperty = function(o){o.__proto__ = {}};
43 for (let setProtoFunc of [setProtoBuiltin, setProtoProperty]) {
44 assertDoesNotThrow(function(){setProtoFunc(o)});
45 assertDoesNotThrow(function(){setProtoFunc(o)});
46 assertDoesNotThrow(function(){setProtoFunc(o)});
47 %OptimizeFunctionOnNextCall(setProtoFunc);
48 assertDoesNotThrow(function(){setProtoFunc(o)});
49 %DeoptimizeFunction(setProtoFunc);
50 assertDoesNotThrow(function(){setProtoFunc(o)});
51 }
52 }
53 for (let o of strongObjects) {
54 let setProtoBuiltin = function(o){Object.setPrototypeOf(o, {})};
55 let setProtoProperty = function(o){o.__proto__ = {}};
56 for (let setProtoFunc of [setProtoBuiltin, setProtoProperty]) {
57 assertThrows(function(){setProtoFunc(o)}, TypeError);
58 assertThrows(function(){setProtoFunc(o)}, TypeError);
59 assertThrows(function(){setProtoFunc(o)}, TypeError);
60 %OptimizeFunctionOnNextCall(setProtoFunc);
61 assertThrows(function(){setProtoFunc(o)}, TypeError);
62 %DeoptimizeFunction(setProtoFunc);
63 assertThrows(function(){setProtoFunc(o)}, TypeError);
64 }
65 }
66
67 assertDoesNotThrow(declareObjectLiteralWithProtoSloppy);
68 assertDoesNotThrow(declareObjectLiteralWithProtoSloppy);
69 assertDoesNotThrow(declareObjectLiteralWithProtoSloppy);
70 %OptimizeFunctionOnNextCall(declareObjectLiteralWithProtoSloppy);
71 assertDoesNotThrow(declareObjectLiteralWithProtoSloppy);
72 %DeoptimizeFunction(declareObjectLiteralWithProtoSloppy);
73 assertDoesNotThrow(declareObjectLiteralWithProtoSloppy);
74
75 assertDoesNotThrow(declareObjectLiteralWithProtoStrong);
76 assertDoesNotThrow(declareObjectLiteralWithProtoStrong);
77 assertDoesNotThrow(declareObjectLiteralWithProtoStrong);
78 %OptimizeFunctionOnNextCall(declareObjectLiteralWithProtoStrong);
79 assertDoesNotThrow(declareObjectLiteralWithProtoStrong);
80 %DeoptimizeFunction(declareObjectLiteralWithProtoStrong);
81 assertDoesNotThrow(declareObjectLiteralWithProtoStrong);
82}
83testStrongObjectSetProto();