Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make recovering from uncompiled or platform-incompatible native binding possible. #118

Open
wants to merge 1 commit into from

2 participants

Ricky Ng-Adam James Halliday
Ricky Ng-Adam

Useful if moving the executables from one platform to the other.

Ricky Ng-Adam rngadam Make recovering from uncompiled or
platform-incompatible native binding possible.
6cd72ed
James Halliday
Owner

I'm willing to accept try/catch guards around the require('weak') but:

  1. The try/catch guards around require() should happen when the file is loaded so that synchronous io doesn't occur while the server is doing work. Modules should be loaded when the application starts up so that errors show up sooner rather than later.
  2. Printing to console.log() seems spammy.

Something like this might be a better approach:

var canWeak = true;
try { var weak = require('weak') } catch (e) { canWeak = false }
...
if (canWeak && opts.weak !== false && !opts.proto) {
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 6, 2012
  1. Ricky Ng-Adam

    Make recovering from uncompiled or

    rngadam authored
    platform-incompatible native binding possible.
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 11 deletions.
  1. +19 −11 index.js
30 index.js
View
@@ -2,7 +2,6 @@ var dnode = require('./lib/dnode');
var parseArgs = require('./lib/parse_args');
var net = require('net');
var util = require('util');
-var weak = require('weak');
exports = module.exports = function (cons, opts) {
return new D(cons, opts);
@@ -24,16 +23,25 @@ function D (cons, opts) {
if (!opts) opts = {};
if (opts.weak !== false && !opts.proto) {
- opts.proto = {};
- opts.proto.wrap = function (cb, id) {
- return weak(cb, function () {
- if (self.proto) self.proto.cull(id);
- });
- };
- opts.proto.unwrap = function (ref, id) {
- var cb = weak.get(ref);
- return cb || function () {};
- };
+ try {
+ var weak = require('weak');
+ } catch(e) {
+ console.log('Skipping weak: native binding not available: ' + e.stack);
+ opts.weak = false;
+ }
+ if(opts.weak) {
+ opts.proto = {};
+ opts.proto.wrap = function (cb, id) {
+ return weak(cb, function () {
+ if (self.proto) self.proto.cull(id);
+ });
+ };
+ opts.proto.unwrap = function (ref, id) {
+ var cb = weak.get(ref);
+ return cb || function () {};
+ };
+ }
+
}
return dnode.call(self, cons, opts);
}
Something went wrong with that request. Please try again.