OLD | NEW |
| (Empty) |
1 // 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 | |
10 function getSloppyObjects() { | |
11 return [(function(){}), ({})]; | |
12 } | |
13 | |
14 function getStrictObjects() { | |
15 "use strict"; | |
16 return [(function(){}), ({})]; | |
17 } | |
18 | |
19 function getStrongObjects() { | |
20 "use strong"; | |
21 return [(function(){}), ({})]; | |
22 } | |
23 | |
24 function declareObjectLiteralWithProtoSloppy() { | |
25 return {__proto__: {}}; | |
26 } | |
27 | |
28 function declareObjectLiteralWithProtoStrong() { | |
29 "use strong"; | |
30 return {__proto__: {}}; | |
31 } | |
32 | |
33 function 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 } | |
83 testStrongObjectSetProto(); | |
OLD | NEW |