diff --git a/tests/commonjs_node_compat_001.phpt b/tests/commonjs_node_compat_001.phpt new file mode 100644 index 0000000..36738a5 --- /dev/null +++ b/tests/commonjs_node_compat_001.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test V8Js::setModuleLoader : this === module.exports +--SKIPIF-- + +--FILE-- +setModuleLoader(function ($moduleName) { + return <<<'EOJS' + var_dump(this === global); + var_dump(this === module.exports); +EOJS + ; +}); + +$v8->executeString(<<<'EOJS' + var result = require('foo'); +EOJS +); + +?> +===EOF=== +--EXPECT-- +bool(false) +bool(true) +===EOF=== diff --git a/tests/commonjs_node_compat_basic.phpt b/tests/commonjs_node_compat_basic.phpt index ac03757..6da4094 100644 --- a/tests/commonjs_node_compat_basic.phpt +++ b/tests/commonjs_node_compat_basic.phpt @@ -1,5 +1,5 @@ --TEST-- -Test V8::executeString() : exports/module.exports behaviour +Test V8Js::setModuleLoader : exports/module.exports behaviour --SKIPIF-- --FILE-- diff --git a/v8js_methods.cc b/v8js_methods.cc index 69786d6..ac69d64 100644 --- a/v8js_methods.cc +++ b/v8js_methods.cc @@ -462,7 +462,7 @@ V8JS_METHOD(require) jsArgv[1] = module; // actually call the module - v8::Local::Cast(module_function)->Call(V8JS_GLOBAL(isolate), 2, jsArgv); + v8::Local::Cast(module_function)->Call(exports, 2, jsArgv); } // Remove this module and path from the stack