Test sample:
----------------------------

#include "v8.h"
#include "stdio.h"

#ifndef CRASH
#define CRASH() do { \
    *(int *)(unsigned int *)0xbbadbeef = 0; \
    ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \
} while(false)
#endif

static void handleFatalErrorInV8()
{
//    CRASH();
}

static void reportFatalErrorInV8(const char* location, const char*
message)
{
    printf("V8 error: %s (%s)\n", message, location);
    handleFatalErrorInV8();
}

#define EXPECT(condition) if(!condition) printf("fail\n")

void TestRunScriptOutOfMemory()
{
    static const int K = 1024;
    v8::ResourceConstraints constraints;
    constraints.set_max_young_space_size(256 * K);
    constraints.set_max_old_space_size(4 * K * K);
    v8::SetResourceConstraints(&constraints);

    // Execute a script that causes out of memory.
    v8::HandleScope scope;
    v8::Persistent<v8::Context> context = v8::Context::New();
    v8::Context::Scope contextScope(context);
    v8::V8::IgnoreOutOfMemoryException();
            v8::V8::SetFatalErrorHandler(reportFatalErrorInV8);
    v8::Local<v8::Script> script =
    v8::Script::Compile(v8::String::New("a = new Array(); while (1)
{ (a = new Array(a)).sort(); }"));
    v8::Local<v8::Value> result = script->Run();
    EXPECT(result.IsEmpty());
    EXPECT(context->HasOutOfMemoryException());
    context.Dispose();
}

int main()
{
    TestRunScriptOutOfMemory();
    return 0;
}
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---

Reply via email to