Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Mahendraker committed Mar 3, 2012
0 parents commit d205b77
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
/build
.lock-wscript
/src/.lock-wscript
tmp
3 changes: 3 additions & 0 deletions index.js
@@ -0,0 +1,3 @@
var hashify = require("./build/Release/hashify");

module.exports = hashify.hashify;
20 changes: 20 additions & 0 deletions package.json
@@ -0,0 +1,20 @@
{
"author": "Siddharth Mahendraker <siddharth_mahen@me.com>",
"name": "hashify",
"description": "Access native v8 object hashes",
"keywords": [
"object",
"hash"
],
"version": "0.0.1",
"repository": {
"url": ""
},
"main": "index.js",
"scripts": {
"preinstall": "node-waf clean || true; node-waf configure build"
},
"engines": {
"node": "*"
}
}
25 changes: 25 additions & 0 deletions src/hashify.cc
@@ -0,0 +1,25 @@
#define BUILDING_NODE_EXTENSION
#include <node.h>

using namespace v8;

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

if(args.Length() < 1 || !args[0]->IsObject()){
ThrowException(Exception::TypeError(String::New("Invalid arguments")));
return scope.Close(Undefined());
}

Local<Object> obj = Local<Object>::Cast(args[0]);
Local<Number> num = Number::New(obj->GetIdentityHash());

return scope.Close(num);
}

void init(Handle<Object> target) {
target->Set(String::NewSymbol("hashify"),
FunctionTemplate::New(hashify)->GetFunction());
}

NODE_MODULE(hashify, init)
15 changes: 15 additions & 0 deletions wscript
@@ -0,0 +1,15 @@
srcdir = 'src'
blddir = 'build'
VERSION = '0.0.1'

def set_options(opt):
opt.tool_options('compiler_cxx')

def configure(conf):
conf.check_tool('compiler_cxx')
conf.check_tool('node_addon')

def build(bld):
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
obj.target = 'hashify'
obj.source = [ srcdir+'/'+'hashify.cc']

0 comments on commit d205b77

Please sign in to comment.