samshull / node-proxy

Deprecated: Harmony Proxies in node (no longer needed)
MIT License
162 stars 29 forks source link

Segmentation fault (core dumped) on node v0.6.x #20

Open jifeon opened 12 years ago

jifeon commented 12 years ago

The code below crashes sometimes with segmentation error. I tested it on node 0.6.6( crashes ) and 0.4.12 ( works ) Look to get in the handler, other traps are default.

var Proxy = require( 'node-proxy' );

function ProxyHandler( target ) {
  return {

    getOwnPropertyDescriptor : function( name ) {
      var desc = Object.getOwnPropertyDescriptor( target, name );
      if ( desc !== undefined ) {
        desc.configurable = true;
      }
      return desc;
    },

    getPropertyDescriptor : function( name ) {
      var desc    = Object.getOwnPropertyDescriptor( target, name );
      var parent  = Object.getPrototypeOf( target );

      while ( desc === undefined && parent !== null ) {
        desc = Object.getOwnPropertyDescriptor( parent, name );
        parent = Object.getPrototypeOf( parent );
      }
      if ( desc !== undefined ) {
        desc.configurable = true;
      }
      return desc;
    },

    getOwnPropertyNames : function() {
      return Object.getOwnPropertyNames( target );
    },

    getPropertyNames : function() {
      var props   = Object.getOwnPropertyNames( target );
      var parent  = Object.getPrototypeOf( target );

      while ( parent !== null ) {
        props = props.concat( Object.getOwnPropertyNames( parent ) );
        parent = Object.getPrototypeOf( parent );
      }

      return props;
    },

    defineProperty : function( name, desc ) {
      return Object.defineProperty( target, name, desc );
    },

    'delete' : function( name ) {
      return delete target[ name ];
    },

    fix : function() {
      if ( !Object.isFrozen( target ) ) return undefined;

      var props = {};
      for ( var name in target ) {
        props[ name ] = Object.getOwnPropertyDescriptor( target, name );
      }

      return props;
    },

    has : function( name ) {
      return name in target;
    },

    hasOwn : function( name ) {
      return ({}).hasOwnProperty.call( target, name );
    },

    get : function( receiver, name ) {
      var super_prototype = Object.getPrototypeOf( Object.getPrototypeOf( Object.getPrototypeOf( target ) ));

      return super_prototype[ name ].bind( target );
    },

    set : function( receiver, name, val ) {
      target[ name ] = val;
      return true;
    },

    enumerate : function() {
      var result = [];
      for ( var name in target ) {
        result.push( name );
      }

      return result;
    },

    iterate : function() {
      var props = this.enumerate();
      var i = 0;
      return {
        next: function() {
          if ( i === props.length ) throw StopIteration;
          return props[i++];
        }
      };
    },

    keys : function() {
      return Object.keys( target );
    }
  }
}

function ClassA() {}
ClassA.prototype.method = function() {};

require('util').inherits( ClassB, ClassA );
function ClassB() {}

ClassB.prototype.method = function() {
  var handler = ProxyHandler( this );
  var s = Proxy.create( handler, Object.getPrototypeOf( this ) );
  s.method();
};

var j = 0;
require('util').inherits( ClassC, ClassB );
function ClassC() {
  console.log( j++ );
  this.method();
}

for( var i = 0; i < 50; i++ ) new ClassC;
console.log( 'All good' );
jifeon commented 12 years ago

My output ( count of numbers is always different ):

$ node index.js 
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Erreur de segmentation (core dumped)
kovacssupki commented 12 years ago

it does make error mesage on node make server and on npm install

module.js:340 throw err; ^ Error: Cannot find module '../build/Release/nodeproxy.node' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:362:17) at require (module.js:378:17) at Object. (/var/www/vhosts/compusysco/compusysco.ro/httpdocs/popcorn/butter/node_modules/client-sessions/node_modules/node-proxy/lib/node-proxy.js:1:90) at Module._compile (module.js:449:26) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:362:17) server process exited with code 1

kovacssupki commented 12 years ago

on npm install throws the following error

node-proxy@0.6.0 install /usr/lib/node_modules/butter/node_modules/client-sess ions/node_modules/node-proxy node-gyp configure build

npm http GET https://registry.npmjs.org/hashish/0.0.4 make: Entering directory /usr/lib/node_modules/butter/node_modules/sqlite3/buil d' CC(target) Debug/obj.target/sqlite3/deps/sqlite3/sqlite3.o npm http 304 https://registry.npmjs.org/burrito/0.2.12 npm http 304 https://registry.npmjs.org/eyes/0.1.8 npm http 304 https://registry.npmjs.org/diff/1.0.3 ../deps/sqlite3/sqlite3.c: In function âposixUnlockâ: ../deps/sqlite3/sqlite3.c:26153:7: warning: variable âhâ set but not used [-Wunu sed-but-set-variable] ../deps/sqlite3/sqlite3.c: In function âsqlite3RefillIndexâ: ../deps/sqlite3/sqlite3.c:81465:7: warning: variable âregIdxKeyâ set but not use d [-Wunused-but-set-variable] ../deps/sqlite3/sqlite3.c: In function âsqlite3CommitTransactionâ: ../deps/sqlite3/sqlite3.c:82550:12: warning: variable âdbâ set but not used [-Wu nused-but-set-variable] ../deps/sqlite3/sqlite3.c: In function âsqlite3RollbackTransactionâ: ../deps/sqlite3/sqlite3.c:82570:12: warning: variable âdbâ set but not used [-Wu nused-but-set-variable] npm http 304 https://registry.npmjs.org/hashish/0.0.4 ../deps/sqlite3/sqlite3.c: In function âsqlite3Parserâ: ../deps/sqlite3/sqlite3.c:108822:7: warning: variable âyyendofinputâ set but not used [-Wunused-but-set-variable] ../deps/sqlite3/sqlite3.c: In function âporter_stemmerâ: ../deps/sqlite3/sqlite3.c:121289:41: warning: value computed is not used [-Wunus ed-value] ../deps/sqlite3/sqlite3.c:121293:39: warning: value computed is not used [-Wunus ed-value] ../deps/sqlite3/sqlite3.c:121306:35: warning: value computed is not used [-Wunus ed-value] ../deps/sqlite3/sqlite3.c:121311:39: warning: value computed is not used [-Wunus ed-value] ../deps/sqlite3/sqlite3.c:121317:41: warning: value computed is not used [-Wunus ed-value] ../deps/sqlite3/sqlite3.c:121322:39: warning: value computed is not used [-Wunus ed-value] ../deps/sqlite3/sqlite3.c:121331:38: warning: value computed is not used [-Wunus ed-value] ../deps/sqlite3/sqlite3.c:121338:37: warning: value computed is not used [-Wunus ed-value] ../deps/sqlite3/sqlite3.c:121381:39: warning: value computed is not used [-Wunus ed-value] ../deps/sqlite3/sqlite3.c:121401:34: warning: value computed is not used [-Wunus ed-value] npm http GET https://registry.npmjs.org/uglify-js/1.1.1 ../deps/sqlite3/sqlite3.c: In function âChooseLeafâ: ../deps/sqlite3/sqlite3.c:128597:11: warning: variable âfMinOverlapâ set but not used [-Wunused-but-set-variable] npm http GET https://registry.npmjs.org/traverse/0.5.2 npm http GET https://registry.npmjs.org/traverse/0.6.3 make: Entering directory/usr/lib/node_modules/butter/node_modules/client-sessi ons/node_modules/node-proxy/build' CXX(target) Debug/obj.target/nodeproxy/src/node-proxy.o npm http 304 https://registry.npmjs.org/uglify-js/1.1.1 npm http 304 https://registry.npmjs.org/traverse/0.5.2 npm http 304 https://registry.npmjs.org/traverse/0.6.3 ../src/node-proxy.cc: In static member function âstatic v8::Handlev8::Value v8 ::NodeProxy::GetNamedProperty(v8::Localv8::String, const v8::AccessorInfo&)â: ../src/node-proxy.cc:816:1: warning: control reaches end of non-void function [- Wreturn-type] SOLINK_MODULE(target) Debug/obj.target/nodeproxy.node SOLINK_MODULE(target) Debug/obj.target/nodeproxy.node: Finished COPY Debug/nodeproxy.node make: Leaving directory /usr/lib/node_modules/butter/node_modules/client-sessio ns/node_modules/node-proxy/build' AR(target) Debug/obj.target/deps/sqlite3/sqlite3.node CXX(target) Debug/obj.target/node_sqlite3/src/database.o CXX(target) Debug/obj.target/node_sqlite3/src/node_sqlite3.o CXX(target) Debug/obj.target/node_sqlite3/src/statement.o SOLINK_MODULE(target) Debug/obj.target/node_sqlite3.node SOLINK_MODULE(target) Debug/obj.target/node_sqlite3.node: Finished COPY Debug/node_sqlite3.node make: Leaving directory/usr/lib/node_modules/butter/node_modules/sqlite3/build ' butter@1.0.0 /usr/lib/node_modules/butter âââ express-persona@0.0.6 âââ node-uuid@1.3.3 âââ csslint@0.9.9 âââ shelljs@0.0.6 âââ requirejs@2.0.6 âââ uglify-js@1.3.3 âââ less@1.3.0 âââ knox@0.3.1 (mime@1.2.7) âââ less-middleware@0.1.7 (mkdirp@0.3.4) âââ jade@0.27.2 (commander@0.6.1, mkdirp@0.3.0) âââ supertest@0.3.1 (methods@0.0.1, superagent@0.9.5) âââ express@2.5.11 (qs@0.4.2, mime@1.2.4, mkdirp@0.3.0, connect@1.9.2) âââ jshint@0.6.2 (argsparser@0.0.6, minimatch@0.0.5) âââ config@0.4.16 (coffee-script@1.3.3, js-yaml@0.3.7, vows@0.6.4) âââ sequelize@1.5.0 (generic-pool@1.0.9, commander@0.6.1, lingo@0.0.5, validator @0.3.9, underscore@1.2.4, underscore.string@2.0.0, moment@1.1.1, mysql@0.9.6) âââ tap@0.3.1 (deep-equal@0.0.0, buffer-equal@0.0.0, mkdirp@0.3.4, slide@1.1.3, nopt@2.0.0, difflet@0.2.3, runforcover@0.0.2) âââ client-sessions@0.0.9 (cookies@0.1.7, node-proxy@0.6.0) âââ sqlite3@2.1.5