mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 03:01:51 +00:00
use "this = module.exports" for modules
This commit is contained in:
parent
f3a46ff833
commit
384ec9b1b6
28
tests/commonjs_node_compat_001.phpt
Normal file
28
tests/commonjs_node_compat_001.phpt
Normal file
@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
Test V8Js::setModuleLoader : this === module.exports
|
||||
--SKIPIF--
|
||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$v8 = new V8Js();
|
||||
|
||||
$v8->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===
|
@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Test V8::executeString() : exports/module.exports behaviour
|
||||
Test V8Js::setModuleLoader : exports/module.exports behaviour
|
||||
--SKIPIF--
|
||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||
--FILE--
|
||||
|
@ -462,7 +462,7 @@ V8JS_METHOD(require)
|
||||
jsArgv[1] = module;
|
||||
|
||||
// actually call the module
|
||||
v8::Local<v8::Function>::Cast(module_function)->Call(V8JS_GLOBAL(isolate), 2, jsArgv);
|
||||
v8::Local<v8::Function>::Cast(module_function)->Call(exports, 2, jsArgv);
|
||||
}
|
||||
|
||||
// Remove this module and path from the stack
|
||||
|
Loading…
Reference in New Issue
Block a user