Skip to content

Commit 384ec9b

Browse files
committed
use "this = module.exports" for modules
1 parent f3a46ff commit 384ec9b

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Test V8Js::setModuleLoader : this === module.exports
3+
--SKIPIF--
4+
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
8+
$v8 = new V8Js();
9+
10+
$v8->setModuleLoader(function ($moduleName) {
11+
return <<<'EOJS'
12+
var_dump(this === global);
13+
var_dump(this === module.exports);
14+
EOJS
15+
;
16+
});
17+
18+
$v8->executeString(<<<'EOJS'
19+
var result = require('foo');
20+
EOJS
21+
);
22+
23+
?>
24+
===EOF===
25+
--EXPECT--
26+
bool(false)
27+
bool(true)
28+
===EOF===

tests/commonjs_node_compat_basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Test V8::executeString() : exports/module.exports behaviour
2+
Test V8Js::setModuleLoader : exports/module.exports behaviour
33
--SKIPIF--
44
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
55
--FILE--

v8js_methods.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ V8JS_METHOD(require)
462462
jsArgv[1] = module;
463463

464464
// actually call the module
465-
v8::Local<v8::Function>::Cast(module_function)->Call(V8JS_GLOBAL(isolate), 2, jsArgv);
465+
v8::Local<v8::Function>::Cast(module_function)->Call(exports, 2, jsArgv);
466466
}
467467

468468
// Remove this module and path from the stack

0 commit comments

Comments
 (0)