Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
billywhizz committed Apr 11, 2010
0 parents commit 1142479
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
18 changes: 18 additions & 0 deletions LICENSE
@@ -0,0 +1,18 @@
// Copyright 2010, devKnowledge.com Ltd. All rights reserved.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
21 changes: 21 additions & 0 deletions README
@@ -0,0 +1,21 @@
node-gc
=============

A very small wrapper around v8 Garbage collection.

To build:

node-waf configure
node-waf build

you should then have a gc.node binary which you will need to make available to any
scripts that want to use it.

To use in a script:

var gc = require("./gc");

var GC = new gc.GC();
gc.collect();

run node.js for a full example.
70 changes: 70 additions & 0 deletions gc.cc
@@ -0,0 +1,70 @@
#include <node.h>
#include <node_events.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>

using namespace v8;
using namespace node;

class GC : public EventEmitter {
public:
static void
Initialize (v8::Handle<v8::Object> target)
{
HandleScope scope;

Local<FunctionTemplate> t = FunctionTemplate::New(New);

t->Inherit(EventEmitter::constructor_template);
t->InstanceTemplate()->SetInternalFieldCount(1);

NODE_SET_PROTOTYPE_METHOD(t, "collect", Collect);

target->Set(String::NewSymbol("GC"), t->GetFunction());
}

void Collect() {
while(!V8::IdleNotification()){};
}

protected:

static Handle<Value>
New (const Arguments& args)
{
HandleScope scope;

GC *gc = new GC();
gc->Wrap(args.This());

return args.This();
}

static Handle<Value>
Collect (const Arguments& args)
{
GC *gc = ObjectWrap::Unwrap<GC>(args.This());

HandleScope scope;

gc->Collect();

return v8::Null();
}

GC () : EventEmitter ()
{
}

~GC ()
{
}
};

extern "C" void
init (Handle<Object> target)
{
HandleScope scope;
GC::Initialize(target);
}
6 changes: 6 additions & 0 deletions test.js
@@ -0,0 +1,6 @@
var sys = require("sys");
var gc = require("./gc");

var GC = new gc.GC();
sys.puts(sys.inspect(GC, true, 10));
GC.collect();
30 changes: 30 additions & 0 deletions wscript
@@ -0,0 +1,30 @@
import Options
from os import unlink, symlink, popen
from os.path import exists

srcdir = "."
blddir = "build"
VERSION = "0.0.1"

def set_options(opt):
opt.tool_options("compiler_cxx")
opt.tool_options("compiler_cc")

def configure(conf):
conf.check_tool("compiler_cxx")
conf.check_tool("compiler_cc")
conf.check_tool("node_addon")

def build(bld):
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
obj.target = "gc"
obj.source = "gc.cc"

def shutdown():
# HACK to get compress.node out of build directory.
# better way to do this?
if Options.commands['clean']:
if exists('gc.node'): unlink('gc.node')
else:
if exists('build/default/gc.node') and not exists('gc.node'):
symlink('build/default/gc.node', 'gc.node')

0 comments on commit 1142479

Please sign in to comment.