@@ -101,6 +101,8 @@ Persistent<String> domain_symbol;
101101
102102static Persistent<Object> process;
103103
104+ static Persistent<String> exports_symbol;
105+
104106static Persistent<String> errno_symbol;
105107static Persistent<String> syscall_symbol;
106108static Persistent<String> errpath_symbol;
@@ -1786,8 +1788,8 @@ Handle<Value> Hrtime(const v8::Arguments& args) {
17861788
17871789typedef void (UV_DYNAMIC* extInit)(Handle<Object> exports);
17881790
1789- // DLOpen is node .dlopen(). Used to load ' module.node' dynamically shared
1790- // objects.
1791+ // DLOpen is process .dlopen(module, filename).
1792+ // Used to load 'module.node' dynamically shared objects.
17911793Handle<Value> DLOpen (const v8::Arguments& args) {
17921794 HandleScope scope;
17931795 char symbol[1024 ], *base, *pos;
@@ -1800,8 +1802,13 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
18001802 return ThrowException (exception);
18011803 }
18021804
1803- String::Utf8Value filename (args[0 ]); // Cast
1804- Local<Object> target = args[1 ]->ToObject (); // Cast
1805+ Local<Object> module = args[0 ]->ToObject (); // Cast
1806+ String::Utf8Value filename (args[1 ]); // Cast
1807+
1808+ if (exports_symbol.IsEmpty ()) {
1809+ exports_symbol = NODE_PSYMBOL (" exports" );
1810+ }
1811+ Local<Object> exports = module ->Get (exports_symbol)->ToObject ();
18051812
18061813 if (uv_dlopen (*filename, &lib)) {
18071814 Local<String> errmsg = String::New (uv_dlerror (&lib));
@@ -1812,7 +1819,7 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
18121819 return ThrowException (Exception::Error (errmsg));
18131820 }
18141821
1815- String::Utf8Value path (args[0 ]);
1822+ String::Utf8Value path (args[1 ]);
18161823 base = *path;
18171824
18181825 /* Find the shared library filename within the full path. */
@@ -1869,7 +1876,7 @@ Handle<Value> DLOpen(const v8::Arguments& args) {
18691876 }
18701877
18711878 // Execute the C++ module
1872- mod->register_func (target );
1879+ mod->register_func (exports, module );
18731880
18741881 // Tell coverity that 'handle' should not be freed when we return.
18751882 // coverity[leaked_storage]
@@ -1953,7 +1960,9 @@ static Handle<Value> Binding(const Arguments& args) {
19531960
19541961 if ((modp = get_builtin_module (*module_v)) != NULL ) {
19551962 exports = Object::New ();
1956- modp->register_func (exports);
1963+ // Internal bindings don't have a "module" object,
1964+ // only exports.
1965+ modp->register_func (exports, Undefined ());
19571966 binding_cache->Set (module , exports);
19581967
19591968 } else if (!strcmp (*module_v, " constants" )) {
0 commit comments