-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node::Environment isn't accessible to user APIs, so extend smalloc to also accept v8::Isolate. Fixes: 75adde0 "src: remove `node_isolate` from source" PR-URL: #905 Reviewed-by: Fedor Indutny <fedor@indutny.com>
- Loading branch information
1 parent
bada87b
commit 9deade4
Showing
5 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'binding', | ||
'sources': [ 'binding.cc' ] | ||
} | ||
] | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |