OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #include "v8.h" | 28 #include "v8.h" |
| 29 #include "accessors.h" |
29 #include "top.h" | 30 #include "top.h" |
30 | 31 |
31 #include "cctest.h" | 32 #include "cctest.h" |
32 | 33 |
33 | 34 |
34 using namespace v8::internal; | 35 using namespace v8::internal; |
35 | 36 |
36 | 37 |
37 static Object* AllocateAfterFailures() { | 38 static Object* AllocateAfterFailures() { |
38 static int attempts = 0; | 39 static int attempts = 0; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 CHECK(!Heap::AllocateMap(instance_type, instance_size)->IsFailure()); | 81 CHECK(!Heap::AllocateMap(instance_type, instance_size)->IsFailure()); |
81 | 82 |
82 // Test that we can allocate in old pointer space and code space. | 83 // Test that we can allocate in old pointer space and code space. |
83 CHECK(!Heap::AllocateFixedArray(100, TENURED)->IsFailure()); | 84 CHECK(!Heap::AllocateFixedArray(100, TENURED)->IsFailure()); |
84 CHECK(!Heap::CopyCode(Builtins::builtin(Builtins::Illegal))->IsFailure()); | 85 CHECK(!Heap::CopyCode(Builtins::builtin(Builtins::Illegal))->IsFailure()); |
85 | 86 |
86 // Return success. | 87 // Return success. |
87 return Smi::FromInt(42); | 88 return Smi::FromInt(42); |
88 } | 89 } |
89 | 90 |
| 91 |
90 static Handle<Object> Test() { | 92 static Handle<Object> Test() { |
91 CALL_HEAP_FUNCTION(AllocateAfterFailures(), Object); | 93 CALL_HEAP_FUNCTION(AllocateAfterFailures(), Object); |
92 } | 94 } |
93 | 95 |
94 | 96 |
95 TEST(Stress) { | 97 TEST(StressHandles) { |
96 v8::Persistent<v8::Context> env = v8::Context::New(); | 98 v8::Persistent<v8::Context> env = v8::Context::New(); |
97 v8::HandleScope scope; | 99 v8::HandleScope scope; |
98 env->Enter(); | 100 env->Enter(); |
99 Handle<Object> o = Test(); | 101 Handle<Object> o = Test(); |
100 CHECK(o->IsSmi() && Smi::cast(*o)->value() == 42); | 102 CHECK(o->IsSmi() && Smi::cast(*o)->value() == 42); |
101 env->Exit(); | 103 env->Exit(); |
102 } | 104 } |
| 105 |
| 106 |
| 107 static Object* TestAccessorGet(Object* object, void*) { |
| 108 return AllocateAfterFailures(); |
| 109 } |
| 110 |
| 111 |
| 112 const AccessorDescriptor kDescriptor = { |
| 113 TestAccessorGet, |
| 114 0, |
| 115 0 |
| 116 }; |
| 117 |
| 118 |
| 119 TEST(StressJS) { |
| 120 v8::Persistent<v8::Context> env = v8::Context::New(); |
| 121 v8::HandleScope scope; |
| 122 env->Enter(); |
| 123 Handle<JSFunction> function = |
| 124 Factory::NewFunction(Factory::function_symbol(), Factory::null_value()); |
| 125 // Force the creation of an initial map and set the code to |
| 126 // something empty. |
| 127 Factory::NewJSObject(function); |
| 128 function->set_code(Builtins::builtin(Builtins::EmptyFunction)); |
| 129 // Patch the map to have an accessor for "get". |
| 130 Handle<Map> map(function->initial_map()); |
| 131 Handle<DescriptorArray> instance_descriptors(map->instance_descriptors()); |
| 132 Handle<Proxy> proxy = Factory::NewProxy(&kDescriptor); |
| 133 instance_descriptors = Factory::CopyAppendProxyDescriptor( |
| 134 instance_descriptors, |
| 135 Factory::NewStringFromAscii(Vector<const char>("get", 3)), |
| 136 proxy, |
| 137 static_cast<PropertyAttributes>(0)); |
| 138 map->set_instance_descriptors(*instance_descriptors); |
| 139 // Add the Foo constructor the global object. |
| 140 env->Global()->Set(v8::String::New("Foo"), v8::Utils::ToLocal(function)); |
| 141 // Call the accessor through JavaScript. |
| 142 v8::Handle<v8::Value> result = |
| 143 v8::Script::Compile(v8::String::New("(new Foo).get"))->Run(); |
| 144 CHECK_EQ(42, result->Int32Value()); |
| 145 env->Exit(); |
| 146 } |
OLD | NEW |