From 384ec9b1b6a73940ef7c9ad8a424a7248ba2872f Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sun, 12 Nov 2017 16:20:24 +0100 Subject: [PATCH] use "this = module.exports" for modules --- tests/commonjs_node_compat_001.phpt | 28 +++++++++++++++++++++++++++ tests/commonjs_node_compat_basic.phpt | 2 +- v8js_methods.cc | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/commonjs_node_compat_001.phpt 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