node/test/addons/stringbytes-external-exceed-max/binding.cc
Ali Ijaz Sheikh 7b60b8f8e9 test: fix flakiness of stringbytes-external
The tests used to rely on precise timing of when a JavaScript object
would be garbage collected to ensure that there is enough memory
available on the system. Switch the test to use a malloc/free pair
instead.

Ref: https://github.com/nodejs/node/pull/5945
Ref: https://github.com/nodejs/node/pull/6039
Ref: https://github.com/nodejs/node/pull/6073

PR-URL: https://github.com/nodejs/node/pull/6705
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-05-17 17:24:43 -07:00

24 lines
605 B
C++

#include <stdlib.h>
#include <node.h>
#include <v8.h>
void EnsureAllocation(const v8::FunctionCallbackInfo<v8::Value> &args) {
v8::Isolate* isolate = args.GetIsolate();
uintptr_t size = args[0]->IntegerValue();
v8::Local<v8::Boolean> success;
void* buffer = malloc(size);
if (buffer) {
success = v8::Boolean::New(isolate, true);
free(buffer);
} else {
success = v8::Boolean::New(isolate, false);
}
args.GetReturnValue().Set(success);
}
void init(v8::Local<v8::Object> target) {
NODE_SET_METHOD(target, "ensureAllocation", EnsureAllocation);
}
NODE_MODULE(binding, init);