OLD | NEW |
| (Empty) |
1 // Copyright 2011 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | |
28 // Flags: --allow-natives-syntax --expose-natives-as=builtins | |
29 | |
30 // Verify that the builtin typed arrays have been pretenured. | |
31 assertFalse(%InNewSpace(builtins.kMath)); | |
32 assertFalse(%InNewSpace(builtins.rempio2result)); | |
33 assertFalse(%InNewSpace(builtins.rngstate)); | |
34 | |
35 // Checks that all function properties of the builtin object that are actually | |
36 // constructors (recognized by having properties on their .prototype object), | |
37 // have only unconfigurable properties on the prototype, and the methods | |
38 // are also non-writable. | |
39 | |
40 var names = Object.getOwnPropertyNames(builtins); | |
41 | |
42 function isFunction(obj) { | |
43 return typeof obj == "function"; | |
44 } | |
45 | |
46 function isV8Native(name) { | |
47 return name == "GeneratorFunction" || | |
48 name == "GeneratorFunctionPrototype" || | |
49 name == "SetIterator" || | |
50 name == "MapIterator" || | |
51 name == "ArrayIterator" || | |
52 name == "StringIterator"; | |
53 } | |
54 var V8NativePrototypes = { | |
55 GeneratorFunction: Function.prototype, | |
56 // TODO(jugglinmike): Update the following values to the %IteratorPrototype% | |
57 // intrinsic once it is implemented. | |
58 // Issue 3568: Generator Prototype should have an object between itself | |
59 // and Object.prototype | |
60 // https://code.google.com/p/v8/issues/detail?id=3568 | |
61 GeneratorFunctionPrototype: Object.prototype, | |
62 SetIterator: Object.prototype, | |
63 MapIterator: Object.prototype, | |
64 ArrayIterator: Object.prototype, | |
65 StringIterator: Object.prototype | |
66 }; | |
67 | |
68 function checkConstructor(func, name) { | |
69 // A constructor is a function with a prototype and properties on the | |
70 // prototype object besides "constructor"; | |
71 if (name.charAt(0) == "$") return; | |
72 if (typeof func.prototype != "object") return; | |
73 var propNames = Object.getOwnPropertyNames(func.prototype); | |
74 if (propNames.length == 0 || | |
75 (propNames.length == 1 && propNames[0] == "constructor")) { | |
76 // Not a constructor. | |
77 return; | |
78 } | |
79 var proto_desc = Object.getOwnPropertyDescriptor(func, "prototype"); | |
80 assertTrue(proto_desc.hasOwnProperty("value"), name); | |
81 assertFalse(proto_desc.writable, name); | |
82 assertFalse(proto_desc.configurable, name); | |
83 var prototype = proto_desc.value; | |
84 assertEquals(V8NativePrototypes[name] || null, | |
85 Object.getPrototypeOf(prototype), | |
86 name); | |
87 for (var i = 0; i < propNames.length; i++) { | |
88 var propName = propNames[i]; | |
89 if (propName == "constructor") continue; | |
90 if (isV8Native(name)) continue; | |
91 var testName = name + "-" + propName; | |
92 var propDesc = Object.getOwnPropertyDescriptor(prototype, propName); | |
93 assertTrue(propDesc.hasOwnProperty("value"), testName); | |
94 assertFalse(propDesc.configurable, testName); | |
95 if (isFunction(propDesc.value)) { | |
96 assertFalse(propDesc.writable, testName); | |
97 } | |
98 } | |
99 } | |
100 | |
101 for (var i = 0; i < names.length; i++) { | |
102 var name = names[i]; | |
103 var desc = Object.getOwnPropertyDescriptor(builtins, name); | |
104 assertTrue(desc.hasOwnProperty("value")); | |
105 var value = desc.value; | |
106 if (isFunction(value)) { | |
107 checkConstructor(value, name); | |
108 } | |
109 } | |
OLD | NEW |