mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 08:11:52 +00:00
Merge pull request #348 from stesie/native-modules
support native modules
This commit is contained in:
commit
723e71c35a
24
tests/commonjs_native_basic.phpt
Normal file
24
tests/commonjs_native_basic.phpt
Normal file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
Test V8Js::setModuleLoader : Native Module basic behaviour
|
||||
--SKIPIF--
|
||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class NativeModule {
|
||||
public function sayHello($name)
|
||||
{
|
||||
echo "Hello $name!\n";
|
||||
}
|
||||
}
|
||||
|
||||
$v8 = new V8Js();
|
||||
$v8->setModuleLoader(function($module) {
|
||||
return new NativeModule();
|
||||
});
|
||||
$v8->executeString('require("foo").sayHello("World");');
|
||||
?>
|
||||
===EOF===
|
||||
--EXPECT--
|
||||
Hello World!
|
||||
===EOF===
|
@ -406,6 +406,15 @@ V8JS_METHOD(require)
|
||||
return;
|
||||
}
|
||||
|
||||
if(Z_TYPE(module_code) == IS_OBJECT) {
|
||||
v8::Local<v8::Object> newobj = zval_to_v8js(&module_code, isolate)->ToObject();
|
||||
c->modules_loaded[normalised_module_id].Reset(isolate, newobj);
|
||||
info.GetReturnValue().Set(newobj);
|
||||
|
||||
efree(normalised_path);
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the return value to string
|
||||
if (Z_TYPE(module_code) != IS_STRING) {
|
||||
convert_to_string(&module_code);
|
||||
|
Loading…
Reference in New Issue
Block a user