Author: [EMAIL PROTECTED]
Date: Thu Oct 30 07:16:02 2008
New Revision: 658

Modified:
    branches/bleeding_edge/test/cctest/test-alloc.cc

Log:
Extend test case to cover calling runtime functions
from JavaScript.
Review URL: http://codereview.chromium.org/8915

Modified: branches/bleeding_edge/test/cctest/test-alloc.cc
==============================================================================
--- branches/bleeding_edge/test/cctest/test-alloc.cc    (original)
+++ branches/bleeding_edge/test/cctest/test-alloc.cc    Thu Oct 30 07:16:02  
2008
@@ -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,16 +88,59 @@
    return Smi::FromInt(42);
  }

+
  static Handle<Object> Test() {
    CALL_HEAP_FUNCTION(AllocateAfterFailures(), Object);
  }


-TEST(Stress) {
+TEST(StressHandles) {
    v8::Persistent<v8::Context> env = v8::Context::New();
    v8::HandleScope scope;
    env->Enter();
    Handle<Object> o = Test();
    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<v8::Context> env = v8::Context::New();
+  v8::HandleScope scope;
+  env->Enter();
+  Handle<JSFunction> 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> map(function->initial_map());
+  Handle<DescriptorArray>  
instance_descriptors(map->instance_descriptors());
+  Handle<Proxy> proxy = Factory::NewProxy(&kDescriptor);
+  instance_descriptors = Factory::CopyAppendProxyDescriptor(
+      instance_descriptors,
+      Factory::NewStringFromAscii(Vector<const char>("get", 3)),
+      proxy,
+      static_cast<PropertyAttributes>(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<v8::Value> result =
+      v8::Script::Compile(v8::String::New("(new Foo).get"))->Run();
+  CHECK_EQ(42, result->Int32Value());
    env->Exit();
  }

--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to