mirror of https://github.com/lukechilds/node.git
Browse Source
node::Environment isn't accessible to user APIs, so extend smalloc to
also accept v8::Isolate.
Fixes: 75adde07
"src: remove `node_isolate` from source"
PR-URL: https://github.com/iojs/io.js/pull/905
Reviewed-by: Fedor Indutny <fedor@indutny.com>
v0.12.2-release
5 changed files with 137 additions and 7 deletions
@ -0,0 +1,30 @@ |
|||||
|
#include <node.h> |
||||
|
#include <smalloc.h> |
||||
|
#include <v8.h> |
||||
|
|
||||
|
using namespace v8; |
||||
|
|
||||
|
void Alloc(const FunctionCallbackInfo<Value>& args) { |
||||
|
Isolate* isolate = args.GetIsolate(); |
||||
|
Local<Object> obj = Object::New(isolate); |
||||
|
size_t len = args[0]->Uint32Value(); |
||||
|
node::smalloc::Alloc(isolate, obj, len); |
||||
|
args.GetReturnValue().Set(obj); |
||||
|
} |
||||
|
|
||||
|
void Dispose(const FunctionCallbackInfo<Value>& args) { |
||||
|
node::smalloc::AllocDispose(args.GetIsolate(), args[0].As<Object>()); |
||||
|
} |
||||
|
|
||||
|
void HasExternalData(const FunctionCallbackInfo<Value>& args) { |
||||
|
args.GetReturnValue().Set( |
||||
|
node::smalloc::HasExternalData(args.GetIsolate(), args[0].As<Object>())); |
||||
|
} |
||||
|
|
||||
|
void init(Handle<Object> target) { |
||||
|
NODE_SET_METHOD(target, "alloc", Alloc); |
||||
|
NODE_SET_METHOD(target, "dispose", Dispose); |
||||
|
NODE_SET_METHOD(target, "hasExternalData", HasExternalData); |
||||
|
} |
||||
|
|
||||
|
NODE_MODULE(binding, init); |
@ -0,0 +1,8 @@ |
|||||
|
{ |
||||
|
'targets': [ |
||||
|
{ |
||||
|
'target_name': 'binding', |
||||
|
'sources': [ 'binding.cc' ] |
||||
|
} |
||||
|
] |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
var assert = require('assert'); |
||||
|
var binding = require('./build/Release/binding'); |
||||
|
var obj = binding.alloc(16); |
||||
|
for (var i = 0; i < 16; i++) { |
||||
|
assert.ok(typeof obj[i] == 'number'); |
||||
|
} |
||||
|
assert.ok(binding.hasExternalData(obj)); |
||||
|
binding.dispose(obj); |
||||
|
assert.ok(typeof obj[0] !== 'number'); |
Loading…
Reference in new issue