From bcd16f9453e543ba819385d87bd7061a4caeb325 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 11 Oct 2011 15:06:25 +1000 Subject: Update V8 Change-Id: Ic239ef1e55bed06260e4a04cc2199f64c2d30059 Reviewed-by: Kent Hansen --- tests/auto/v8/tst_v8.cpp | 12 +++++++ tests/auto/v8/v8main.cpp | 11 +++++-- tests/auto/v8/v8test.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/auto/v8/v8test.h | 2 ++ 4 files changed, 105 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/v8/tst_v8.cpp b/tests/auto/v8/tst_v8.cpp index c753806518..77a3413718 100644 --- a/tests/auto/v8/tst_v8.cpp +++ b/tests/auto/v8/tst_v8.cpp @@ -57,6 +57,8 @@ private slots: void eval(); void evalwithinwith(); void userobjectcompare(); + void externalteardown(); + void globalcall(); }; void tst_v8::eval() @@ -74,6 +76,16 @@ void tst_v8::userobjectcompare() QVERIFY(v8test_userobjectcompare()); } +void tst_v8::externalteardown() +{ + QVERIFY(v8test_externalteardown()); +} + +void tst_v8::globalcall() +{ + QVERIFY(v8test_globalcall()); +} + int main(int argc, char *argv[]) { V8::SetFlagsFromCommandLine(&argc, argv, true); diff --git a/tests/auto/v8/v8main.cpp b/tests/auto/v8/v8main.cpp index b38bbabbd5..091d2cae28 100644 --- a/tests/auto/v8/v8main.cpp +++ b/tests/auto/v8/v8main.cpp @@ -41,10 +41,15 @@ #include "v8test.h" #include +#include #define RUN_TEST(testname) { \ - if (!v8test_ ## testname()) \ - printf ("Test %s FAILED\n", # testname); \ + if (argc == 1 || 0 == ::strcmp(argv[1], # testname)) { \ + if (!v8test_ ## testname()) \ + printf ("Test %s FAILED\n", # testname); \ + else \ + printf ("Test %s PASS\n", # testname); \ + } \ } int main(int argc, char *argv[]) @@ -54,6 +59,8 @@ int main(int argc, char *argv[]) RUN_TEST(eval); RUN_TEST(evalwithinwith); RUN_TEST(userobjectcompare); + RUN_TEST(externalteardown); + RUN_TEST(globalcall); return -1; } diff --git a/tests/auto/v8/v8test.cpp b/tests/auto/v8/v8test.cpp index 0b299ed23c..d9a71dd26a 100644 --- a/tests/auto/v8/v8test.cpp +++ b/tests/auto/v8/v8test.cpp @@ -54,6 +54,59 @@ using namespace v8; } \ } +struct MyStringResource : public String::ExternalAsciiStringResource +{ + static bool wasDestroyed; + virtual ~MyStringResource() { wasDestroyed = true; } + virtual const char* data() const { return "v8test"; } + virtual size_t length() const { return 6; } +}; +bool MyStringResource::wasDestroyed = false; + +struct MyResource : public Object::ExternalResource +{ + static bool wasDestroyed; + virtual ~MyResource() { wasDestroyed = true; } +}; +bool MyResource::wasDestroyed = false; + +bool v8test_externalteardown() +{ + BEGINTEST(); + + Isolate *isolate = v8::Isolate::New(); + isolate->Enter(); + + { + HandleScope handle_scope; + Persistent context = Context::New(); + Context::Scope context_scope(context); + + Local str = String::NewExternal(new MyStringResource); + + Local ft = FunctionTemplate::New(); + ft->InstanceTemplate()->SetHasExternalResource(true); + + Local obj = ft->GetFunction()->NewInstance(); + obj->SetExternalResource(new MyResource); + + context.Dispose(); + } + + // while (!v8::V8::IdleNotification()) ; + isolate->Exit(); + isolate->Dispose(); + + // ExternalString resources aren't guaranteed to be freed by v8 at this + // point. Uncommenting the IdleNotification() line above helps. +// VERIFY(MyStringResource::wasDestroyed); + + VERIFY(MyResource::wasDestroyed); + +cleanup: + + ENDTEST(); +} bool v8test_eval() { @@ -81,6 +134,35 @@ cleanup: ENDTEST(); } +bool v8test_globalcall() +{ + BEGINTEST(); + + HandleScope handle_scope; + Persistent context = Context::New(); + Context::Scope context_scope(context); + + Local qmlglobal = Object::New(); + +#define SOURCE "function func1() { return 1; }\n" \ + "function func2() { var sum = 0; for (var ii = 0; ii < 10000000; ++ii) { sum += func1(); } return sum; }\n" \ + "func2();" + + Local