Created
January 3, 2018 20:35
-
-
Save mpobrien/09a4175c1d9d3dd98571dfa276bf5c62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void memLimitTest() { | |
Isolate::CreateParams create_params; | |
v8::ResourceConstraints constraints; | |
constraints.set_max_old_space_size(100); | |
create_params.constraints = constraints; | |
create_params.array_buffer_allocator = | |
v8::ArrayBuffer::Allocator::NewDefaultAllocator(); | |
Isolate *isolate = Isolate::New(create_params); | |
{ | |
Isolate::Scope isolate_scope(isolate); | |
HandleScope handle_scope(isolate); | |
Local<Context> context = Context::New(isolate); | |
Context::Scope context_scope(context); | |
Local<String> source = | |
String::NewFromUtf8(isolate, | |
"(function(){" | |
" var a = [];" | |
" var b ='xxxxxxxxxxxxxxxxx';" | |
" for(i=0;i<5000000;i++){ a.push(b) }" | |
" return a.length;" | |
"})()", | |
NewStringType::kNormal) | |
.ToLocalChecked(); | |
Local<Script> script = Script::Compile(context, source).ToLocalChecked(); | |
Local<Value> result = script->Run(context).ToLocalChecked(); | |
String::Utf8Value utf8(result); | |
printf("%s\n", *utf8); | |
} | |
isolate->Dispose(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment