Hi, Anton,

Thanks for your reply!

But should v8 crash for this?

I have already called v8::V8::IgnoreOutOfMemoryException(), I expect
v8 should throw a v8::Exception, which we can catch using
v8::TryCatch, and then we can continue to process next script.

Am I wrong?

If this "process out of memory" happens, v8 will become unusable
anymore, It seems no chance that we can just ignore it and move on.


Thanks


Sincerely~
Xiang


On Nov 23, 7:31 pm, Anton Muhin <[email protected]> wrote:
> Xian,
>
> I think it's expected behaviour.  You first create an empty array.
> Then you create an array with a single element which is this empty
> array.  Next you wrap it once again thus creating an endless chain of
> nested arrays:
>
>
>
>
>
>
>
>
>
>
>
> > a = new Array()
> > a.length
> 0
> > a = new Array(a)
> > a.length
> 1
> > a[0].length
> 0
> > a = new Array(a)
> > a.length
> 1
> > a[0].length
> 1
> > a[0][0].length
> 0
>
> Eventually you exhaust the memory.
>
> yours,
> anton.
>
>
>
> On Mon, Nov 23, 2009 at 12:51 PM, Xiang <[email protected]> wrote:
>
> > 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