From 95e880ad33ebec6709fcbf14ee1bc946f0c1fe63 Mon Sep 17 00:00:00 2001 From: "kasperl@chromium.org" Date: Thu, 30 Oct 2008 14:16:02 +0000 Subject: [PATCH] Extend test case to cover calling runtime functions from JavaScript. Review URL: http://codereview.chromium.org/8915 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@658 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- test/cctest/test-alloc.cc | 46 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/test/cctest/test-alloc.cc b/test/cctest/test-alloc.cc index 551635377..9996eeb0a 100644 --- a/test/cctest/test-alloc.cc +++ b/test/cctest/test-alloc.cc @@ -26,6 +26,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "v8.h" +#include "accessors.h" #include "top.h" #include "cctest.h" @@ -87,12 +88,13 @@ static Object* AllocateAfterFailures() { return Smi::FromInt(42); } + static Handle Test() { CALL_HEAP_FUNCTION(AllocateAfterFailures(), Object); } -TEST(Stress) { +TEST(StressHandles) { v8::Persistent env = v8::Context::New(); v8::HandleScope scope; env->Enter(); @@ -100,3 +102,45 @@ TEST(Stress) { CHECK(o->IsSmi() && Smi::cast(*o)->value() == 42); env->Exit(); } + + +static Object* TestAccessorGet(Object* object, void*) { + return AllocateAfterFailures(); +} + + +const AccessorDescriptor kDescriptor = { + TestAccessorGet, + 0, + 0 +}; + + +TEST(StressJS) { + v8::Persistent env = v8::Context::New(); + v8::HandleScope scope; + env->Enter(); + Handle function = + Factory::NewFunction(Factory::function_symbol(), Factory::null_value()); + // Force the creation of an initial map and set the code to + // something empty. + Factory::NewJSObject(function); + function->set_code(Builtins::builtin(Builtins::EmptyFunction)); + // Patch the map to have an accessor for "get". + Handle map(function->initial_map()); + Handle instance_descriptors(map->instance_descriptors()); + Handle proxy = Factory::NewProxy(&kDescriptor); + instance_descriptors = Factory::CopyAppendProxyDescriptor( + instance_descriptors, + Factory::NewStringFromAscii(Vector("get", 3)), + proxy, + static_cast(0)); + map->set_instance_descriptors(*instance_descriptors); + // Add the Foo constructor the global object. + env->Global()->Set(v8::String::New("Foo"), v8::Utils::ToLocal(function)); + // Call the accessor through JavaScript. + v8::Handle result = + v8::Script::Compile(v8::String::New("(new Foo).get"))->Run(); + CHECK_EQ(42, result->Int32Value()); + env->Exit(); +} -- 2.34.1