0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-09-16 19:15:17 +00:00

use "this = module.exports" for modules

This commit is contained in:
Stefan Siegl 2017-11-12 16:20:24 +01:00
parent f3a46ff833
commit 384ec9b1b6
No known key found for this signature in database
GPG Key ID: 73942AF5642F3DDA
3 changed files with 30 additions and 2 deletions

View 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===

View File

@ -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--

View 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