Commit 57b71185 authored by mercury233's avatar mercury233

do not track node_modules

parent 68673d01
function byteField(p, offset) {
this.length = 1;
this.get = function () {
return p.buf[offset];
}
this.set = function (val) {
p.buf[offset] = val;
}
}
function boolField(p, offset, length) {
this.length = length;
this.get = function () {
return (p.buf[offset] > 0 );
}
this.set = function (val) {
p.buf[offset] = val ? 1 : 0;
}
}
function intField(p, offset, length, le, signed) {
this.length = length;
function bec(cb) {
for (var i = 0; i < length; i++)
cb(i, length - i - 1);
}
function lec(cb) {
for (var i = 0; i < length; i++)
cb(i, i);
}
function getUVal(bor) {
var val = 0;
bor(function (i, o) {
val += Math.pow(256, o) * p.buf[offset + i];
})
return val;
}
function getSVal(bor) {
var val = getUVal(bor);
if ((p.buf[offset + ( le ? (length - 1) : 0)] & 0x80) == 0x80) {
val -= Math.pow(256, length);
}
return val;
}
function setVal(bor, val) {
bor(function (i, o) {
p.buf[offset + i] = Math.floor(val / Math.pow(256, o)) & 0xff;
});
}
this.get = function () {
var bor = le ? lec : bec;
return ( signed ? getSVal(bor) : getUVal(bor));
}
this.set = function (val) {
var bor = le ? lec : bec;
setVal(bor, val);
}
}
function charField(p, offset, length, encoding) {
this.length = length;
this.encoding = encoding;
this.get = function () {
var result = p.buf.toString(this.encoding, offset, offset + length);
var strlen = result.indexOf("\0");
if (strlen == -1) {
return result;
} else {
return result.slice(0, strlen);
}
}
this.set = function (val) {
val += "\0";
if (val.length > length)
val = val.substring(0, length);
p.buf.write(val, offset, this.encoding);
}
}
function structField(p, offset, struct) {
this.length = struct.length();
this.get = function () {
return struct;
}
this.set = function (val) {
struct.set(val);
}
this.allocate = function () {
struct._setBuff(p.buf.slice(offset, offset + struct.length()));
}
}
function arrayField(p, offset, len, type) {
var as = Struct();
var args = [].slice.call(arguments, 4);
args.unshift(0);
for (var i = 0; i < len; i++) {
if (type instanceof Struct) {
as.struct(i, type.clone());
} else if (type in as) {
args[0] = i;
as[type].apply(as, args);
}
}
this.length = as.length();
this.allocate = function () {
as._setBuff(p.buf.slice(offset, offset + as.length()));
}
this.get = function () {
return as;
}
this.set = function (val) {
as.set(val);
}
}
function Struct() {
if (!(this instanceof Struct))
return new Struct;
var priv = {
buf: {},
allocated: false,
len: 0,
fields: {},
closures: []
}, self = this;
function checkAllocated() {
if (priv.allocated)
throw new Error('Cant change struct after allocation');
}
this.word8 = function (key) {
checkAllocated();
priv.closures.push(function (p) {
p.fields[key] = new byteField(p, p.len);
p.len++;
});
return this;
};
// Create handlers for various Bool Field Variants
[1, 2, 3, 4].forEach(function (n) {
self['bool' + (n == 1 ? '' : n)] = function (key) {
checkAllocated();
priv.closures.push(function (p) {
p.fields[key] = new boolField(p, p.len, n);
p.len += n;
});
return this;
}
});
// Create handlers for various Integer Field Variants
[1, 2, 3, 4, 6, 8].forEach(function (n) {
[true, false].forEach(function (le) {
[true, false].forEach(function (signed) {
var name = 'word' + (n * 8) + ( signed ? 'S' : 'U') + ( le ? 'le' : 'be');
self[name] = function (key) {
checkAllocated();
priv.closures.push(function (p) {
p.fields[key] = new intField(p, p.len, n, le, signed);
p.len += n;
});
return this;
};
});
});
});
this.chars = function (key, length, encoding) {
checkAllocated();
priv.closures.push(function (p) {
p.fields[key] = new charField(p, p.len, length, encoding || 'ascii');
p.len += length;
});
return this;
}
this.struct = function (key, struct) {
checkAllocated();
priv.closures.push(function (p) {
p.fields[key] = new structField(p, p.len, struct.clone());
p.len += p.fields[key].length;
});
return this;
}
function construct(constructor, args) {
function F() {
return constructor.apply(this, args);
}
F.prototype = constructor.prototype;
return new F();
}
this.array = function (key, length, type) {
checkAllocated();
var args = [].slice.call(arguments, 1);
args.unshift(null);
args.unshift(null);
priv.closures.push(function (p) {
args[0] = p;
args[1] = p.len;
p.fields[key] = construct(arrayField, args);
p.len += p.fields[key].length;
});
return this;
}
var beenHere = false;
function applyClosures(p) {
if (beenHere)
return;
p.closures.forEach(function (el) {
el(p);
});
beenHere = true;
}
function allocateFields() {
for (var key in priv.fields) {
if ('allocate' in priv.fields[key])
priv.fields[key].allocate();
}
}
this._setBuff = function (buff) {
priv.buf = buff;
applyClosures(priv);
allocateFields();
priv.allocated = true;
}
this.allocate = function () {
applyClosures(priv);
priv.buf = new Buffer(priv.len);
allocateFields();
priv.allocated = true;
return this;
}
this._getPriv = function () {
return priv;
}
this.clone = function () {
var c = new Struct;
var p = c._getPriv();
p.closures = priv.closures;
return c;
}
this.length = function () {
applyClosures(priv);
return priv.len;
}
this.get = function (key) {
if (key in priv.fields) {
return priv.fields[key].get();
} else
throw new Error('Can not find field ' + key);
}
this.set = function (key, val) {
if (arguments.length == 2) {
if (key in priv.fields) {
priv.fields[key].set(val);
} else
throw new Error('Can not find field ' + key);
} else if (Buffer.isBuffer(key)) {
this._setBuff(key);
} else {
for (var k in key) {
this.set(k, key[k]);
}
}
}
this.buffer = function () {
return priv.buf;
}
function getFields() {
var fields = {};
Object.keys(priv.fields).forEach(function (key) {
Object.defineProperty(fields, key, {
get: function () {
var res = self.get(key);
if (res instanceof Struct) return res.fields;
else return res;
},
set: function (newVal) {
self.set(key, newVal);
},
enumerable: true
});
});
return fields;
};
var _fields;
Object.defineProperty(this, 'fields', {
get: function () {
if (_fields) return _fields;
return (_fields = getFields());
},
enumerable: true,
configurable: true
});
}
exports.Struct = Struct;
Copyright (c) 2010 Sam Shull http://www.google.com/profiles/brickysam26
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.
node-proxy is an implementation of Harmony Proxies http://wiki.ecmascript.org/doku.php?id=harmony:proxies
that allows the developer to create "catch-all" property handlers for an object or a function in node.js.
Author: Sam Shull
Repository: http://github.com/samshull/node-proxy
Issues: http://github.com/samshull/node-proxy/issues
*** This does not work appropriately in node versions 0.1.100 - 0.1.102. You will need to install node_version.h in $PREFIX/include/node
Methods:
Object create(ProxyHandler handler [, Object proto ] ) throws Error, TypeError
Function createFunction(ProxyHandler handler, Function callTrap [, Function constructTrap ] ) throws Error, TypeError
Boolean isTrapping(Object obj) throws Error
Additional Methods (for ECMAScript 5 compatibliity): @see http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf
Boolean freeze(Object obj) throws Error, TypeError
Boolean seal(Object obj) throws Error, TypeError
Boolean preventExtensions(Object obj) throws Error, TypeError
Boolean isFrozen(Object obj) throws Error, TypeError
Boolean isSealed(Object obj) throws Error, TypeError
Boolean isExtensible(Object obj) throws Error, TypeError
PropertyDescriptor getOwnPropertyDescriptor(Object obj, String name) throws Error, TypeError
Boolean defineProperty(Object obj, String name, PropertyDescriptor pd) throws Error, TypeError
Boolean defineProperties(Object obj, Object descriptors) throws Error, TypeError
More methods:
Object hidden(Object obj, String name [, Object value ] ) throws Error
- Set or retrieve a hidden property on an Object
Object clone(Object obj) throws Error
- Create a shallow copy of an Object
Boolean isProxy(Object obj)
- determine if an object was created by Proxy
Boolean setPrototype(Object obj, Object obj) throws Error
-set the prototype of a given object to the second given object
{
'targets': [
{
'target_name': 'nodeproxy',
'sources': [
'src/node-proxy.cc',
],
}
]
}
/*
* This package exports one function: namespace
* in order to create a system of namespace loading
* from a given directory. Directories and files are
* loaded into a proxy object in order to provide a
* system for loading additional files and directories
* the namespace.
*
* This system does not proxy scalar values on an object
* because of the
*
*/
var Proxy = require("node-proxy"),
fs = require("fs"),
sys = require("sys"),
path = require("path"),
undef, extensions;
function isFunction(fn) {
return !!fn &&
Object.prototype.toString.call(fn) ==
"[object Function]";
}
function isScalar(fn) {
switch (typeof fn) {
case "string": return true;
case "number": return true;
}
return false;
}
function inPath(file) {
var i = 0, l = extensions.length;
for (;i<l;++i) {
if (path.existsSync(file + "." + extensions[i])) {
return true;
}
}
return false;
}
exports.namespace = function namespace(filePath, properties) {
properties = properties || {};
var scalar = isScalar(properties),
func = isFunction(filePath),
handlers = {
get: function(rec, name) {
if (name === "valueOf" || name === "toString") {
return function(){
return properties[name]();
};
}
if (!(name in properties)) {
if (func) {
handlers[name] = filePath(name, properties);
} else {
//sys.puts(name);
var file = path.join(filePath, name),
stat, obj;
if (inPath(file)) {
obj = require(file);
}
if (!obj) {
try{
// would work if it was a directory
stat = fs.statSync(file);
} catch(e) {}
}
if (stat || obj) {
properties[name] = obj ?
namespace(file, obj) :
// this allows you to use an
// object as a namespace as well
namespace(file);
} else {
return undef;
}
}
} else if (!isScalar(properties[name]) && !Proxy.isProxy(properties[name])) {
properties[name] = namespace(path.join(filePath, name), properties[name]);
}
//sys.puts("returning");
return properties[name];
},
has: function(name) {
return name === "valueOf" ||
name === "toString" ||
inPath(path.join(filePath, name));
},
set: function(rec, name, value) {
properties[name] = value;
},
"delete": function(name) {
return false;
},
enumerate: function() {
return Object.keys(properties);
},
fix: function() {
return undef;
}
};
return isFunction(properties) ?
Proxy.createFunction(handlers, function() {
return properties.apply(this, arguments);
}) :
Proxy.create(handlers, properties.constructor.prototype);
};
extensions = exports.namespace.extensions = ["js", "node"];
/*
* This is an example of creating an object that autoloads
* files and directories from a specified folder into an object
* in order to emulate a namespace loader.
*
* The preferred naming convention is property names
* of Objects begin lower case, while directory and file names
* should begin upper case in order to avoid naming conflicts
*
*/
var sys = require("sys"),
assert = require("assert"),
namespace = require(__dirname + "/autoload-namespace").namespace,
org = namespace(__dirname + "/org");
sys.puts("test 1");
assert.equal(typeof(org), "object", "org is not an object");
sys.puts("test 2");
assert.equal(typeof(org.w3c), "object", "org.w3c is not an object");
sys.puts("test 3");
assert.equal(typeof(org.w3c.DOM), "object", "org.w3c.DOM is not an object");
sys.puts("test 4");
assert.equal(typeof(org.w3c.DOM.Document), "object", "org.w3c.DOM.Document is not an object");
sys.puts("test 5");
assert.equal(typeof(org.w3c.DOM.Document.string), "string", "org.w3c.DOM.Document.string is not a string");
sys.puts("test 6");
assert.equal(org.w3c.DOM.Document.string.toString(), "String", "org.w3c.DOM.Document.string is not equal to 'String'");
sys.puts("test 7");
assert.equal(typeof(org.w3c.DOM.Document.String.Test), "object", "org.w3c.DOM.Document.String.Test is not an object");
sys.puts("test 8");
assert.equal(typeof(org.w3c.DOM.Document.String.Test.success), "string", "org.w3c.DOM.Document.String.Test.success is not an string");
sys.puts("test 9");
assert.equal(org.w3c.DOM.Document.String.Test.success, "success", "org.w3c.DOM.Document.String.Test.success is not equal to 'success'");
sys.puts(typeof(org.w3c.DOM.Document.create));
sys.puts(typeof(function(){}));
sys.puts(Object.prototype.toString.call(org.w3c.DOM.Document.create));
sys.puts(org.w3c.DOM.Document.create instanceof Function);
org.w3c.DOM.Document.create(sys);
\ No newline at end of file
exports.string = "String";
exports.object = {};
exports.regexp = /regex/;
exports.create = function(sys) {
sys.puts("A proxified function was called inside of Document.js")
};
\ No newline at end of file
module.exports = exports = require('../build/Release/nodeproxy.node');
\ No newline at end of file
{
"name": "node-proxy",
"version": "0.6.0",
"description": "A module for node implementing __noSuchMethod__-type handlers, such as object overloading, as part of the Harmony Catch-All Proxies specification found at http://wiki.ecmascript.org/doku.php?id=harmony:proxies",
"keywords": [
"interceptor",
"proxy",
"overload",
"__noSuchMethod__"
],
"contributors": [
{
"name": "Sam Shull",
"email": "http://www.google.com/profiles/brickysam26"
},
{
"name": "richardms",
"email": "https://github.com/richardms"
},
{
"name": "Andreas Botsikas",
"email": "http://webinos.org/bio-andreas-botsikas/"
}
],
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.html"
}
],
"bugs": {
"url": "http://github.com/samshull/node-proxy/issues"
},
"implements": [
"http://wiki.ecmascript.org/doku.php?id=harmony:proxies"
],
"engines": {
"node": ">=0.6",
"npm": ">= 1.1.17"
},
"repositories": [
{
"type": "git",
"url": "http://github.com/samshull/node-proxy"
}
],
"main": "./lib/node-proxy.js",
"scripts": {
"install": "node-gyp configure build",
"test": "node test/test.js"
},
"readme": "node-proxy is an implementation of Harmony Proxies http://wiki.ecmascript.org/doku.php?id=harmony:proxies\nthat allows the developer to create \"catch-all\" property handlers for an object or a function in node.js.\n\nAuthor: Sam Shull \nRepository: http://github.com/samshull/node-proxy \nIssues: http://github.com/samshull/node-proxy/issues \n\n*** This does not work appropriately in node versions 0.1.100 - 0.1.102. You will need to install node_version.h in $PREFIX/include/node\n\nMethods:\n\nObject create(ProxyHandler handler [, Object proto ] ) throws Error, TypeError\n\nFunction createFunction(ProxyHandler handler, Function callTrap [, Function constructTrap ] ) throws Error, TypeError\n\nBoolean isTrapping(Object obj) throws Error\n\n\nAdditional Methods (for ECMAScript 5 compatibliity): @see http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf\n\nBoolean freeze(Object obj) throws Error, TypeError\n\nBoolean seal(Object obj) throws Error, TypeError\n\nBoolean preventExtensions(Object obj) throws Error, TypeError\n\nBoolean isFrozen(Object obj) throws Error, TypeError\n\nBoolean isSealed(Object obj) throws Error, TypeError\n\nBoolean isExtensible(Object obj) throws Error, TypeError\n\nPropertyDescriptor getOwnPropertyDescriptor(Object obj, String name) throws Error, TypeError\n\nBoolean defineProperty(Object obj, String name, PropertyDescriptor pd) throws Error, TypeError\n\nBoolean defineProperties(Object obj, Object descriptors) throws Error, TypeError\n\n\nMore methods:\n\nObject hidden(Object obj, String name [, Object value ] ) throws Error\n- Set or retrieve a hidden property on an Object\n\nObject clone(Object obj) throws Error\n- Create a shallow copy of an Object\n\nBoolean isProxy(Object obj)\n- determine if an object was created by Proxy\n\nBoolean setPrototype(Object obj, Object obj) throws Error\n-set the prototype of a given object to the second given object\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "http://github.com/samshull/node-proxy"
},
"_id": "node-proxy@0.6.0",
"dist": {
"shasum": "cb44fdeb7efc10ad4e0fb4b6478da3b19bd9fa81"
},
"_from": "node-proxy@>=0.5.1",
"_resolved": "https://registry.npmjs.org/node-proxy/-/node-proxy-0.6.0.tgz"
}
/**
*
*
*
* @author Sam Shull <http://samshull.blogspot.com/>
* @version 0.1
*
* @copyright Copyright (c) 2009 Sam Shull <http://samshull.blogspot.com/>
* @license <http://www.opensource.org/licenses/mit-license.html>
*
* 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.
*
*
* CHANGES:
*/
#ifndef NODE_PROXY_H // NOLINT
#define NODE_PROXY_H
#include <v8.h>
#include <node.h>
#include <node_version.h>
#define THREXCW(str) ThrowException(Exception::Error(str))
#define THREXC(str) THREXCW(String::New(str))
#define THR_TYPE_ERROR(str) \
ThrowException(Exception::TypeError(String::New(str)))
#define PROXY_NODE_PSYMBOL(s) \
Persistent<String>::New(String::NewSymbol(s))
// had to redefine NODE_VERSION_AT_LEAST here because of missing parenthesis
#define PROXY_NODE_VERSION_AT_LEAST(major, minor, patch) \
(((major) < NODE_MAJOR_VERSION) \
|| ((major) == NODE_MAJOR_VERSION && (minor) < NODE_MINOR_VERSION) \
|| ((major) == NODE_MAJOR_VERSION && (minor) == NODE_MINOR_VERSION && \
(patch) <= NODE_PATCH_VERSION))
// using namespace v8;
namespace v8 {
class NodeProxy {
public:
// fundamental traps
static Persistent<String> getOwnPropertyDescriptor;
static Persistent<String> getPropertyDescriptor;
static Persistent<String> getOwnPropertyNames;
static Persistent<String> getPropertyNames;
static Persistent<String> defineProperty;
static Persistent<String> delete_;
static Persistent<String> fix;
// derived traps
static Persistent<String> has;
static Persistent<String> hasOwn;
static Persistent<String> get;
static Persistent<String> set;
static Persistent<String> enumerate;
static Persistent<String> keys;
// string identifiers
static Persistent<String> callTrap;
static Persistent<String> constructorTrap;
static Persistent<String> value;
static Persistent<String> writable;
static Persistent<String> enumerable;
static Persistent<String> configurable;
static Persistent<String> name;
static Persistent<String> trapping;
static Persistent<String> sealed;
static Persistent<String> frozen;
static Persistent<String> extensible;
static Persistent<String> seal;
static Persistent<String> freeze;
static Persistent<String> preventExtensions;
static Persistent<String> isTrapping;
static Persistent<String> isSealed;
static Persistent<String> isFrozen;
static Persistent<String> isExtensible;
static Persistent<String> isProxy;
static Persistent<String> hidden;
static Persistent<String> hiddenPrivate;
static Persistent<ObjectTemplate> ObjectCreator;
static Persistent<ObjectTemplate> FunctionCreator;
static void Init(Handle<Object> target);
protected:
NodeProxy();
~NodeProxy();
static Handle<Integer>
GetPropertyAttributeFromPropertyDescriptor(Local<Object> pd);
static Local<Value> CorrectPropertyDescriptor(Local<Object> pd);
static Handle<Value> ValidateProxyHandler(Local<Object> handler);
static Handle<Value> Clone(const Arguments& args);
static Handle<Value> Hidden(const Arguments& args);
static Handle<Value> Create(const Arguments& args);
static Handle<Value> SetPrototype(const Arguments& args);
static Handle<Value> CreateFunction(const Arguments& args);
static Handle<Value> Freeze(const Arguments& args);
static Handle<Value> IsLocked(const Arguments& args);
static Handle<Value> IsProxy(const Arguments& args);
static Handle<Value> GetOwnPropertyDescriptor(const Arguments& args);
static Handle<Value> DefineProperty(const Arguments& args);
static Handle<Value> DefineProperties(const Arguments& args);
static Handle<Value> New(const Arguments& args);
static Handle<Value>
GetNamedProperty(Local<String> name, const AccessorInfo &info);
static Handle<Value>
SetNamedProperty(Local<String> name,
Local<Value> value,
const AccessorInfo &info);
static Handle<Boolean>
QueryNamedProperty(Local<String> name,
const AccessorInfo &info);
static Handle<Integer>
QueryNamedPropertyInteger(Local<String> name,
const AccessorInfo &info);
static Handle<Boolean>
DeleteNamedProperty(Local<String> name,
const AccessorInfo &info);
static Handle<Array>
EnumerateNamedProperties(const AccessorInfo &info);
static Handle<Value>
GetIndexedProperty(uint32_t index,
const AccessorInfo &info);
static Handle<Value>
SetIndexedProperty(uint32_t index,
Local<Value> value,
const AccessorInfo &info);
static Handle<Boolean>
QueryIndexedProperty(uint32_t index,
const AccessorInfo &info);
static Handle<Integer>
QueryIndexedPropertyInteger(uint32_t index,
const AccessorInfo &info);
static Handle<Boolean>
DeleteIndexedProperty(uint32_t index,
const AccessorInfo &info);
static Local<Value> CallPropertyDescriptorGet(Local<Value> descriptor,
Handle<Object> context,
Local<Value> args[1]);
static Local<Value> CallPropertyDescriptorSet(Local<Value> descriptor,
Handle<Object> context,
Local<Value> name,
Local<Value> value);
};
}
extern "C" void init(v8::Handle<v8::Object> target);
#endif // NODE_CLASSTEMPLATE_H // NOLINT
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment