mirror of
https://github.com/phpv8/v8js.git
synced 2024-11-09 15:18:41 +00:00
support native modules
This commit is contained in:
parent
ea89904966
commit
7663fb6888
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;
|
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
|
// Convert the return value to string
|
||||||
if (Z_TYPE(module_code) != IS_STRING) {
|
if (Z_TYPE(module_code) != IS_STRING) {
|
||||||
convert_to_string(&module_code);
|
convert_to_string(&module_code);
|
||||||
|
Loading…
Reference in New Issue
Block a user