0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 04:01:51 +00:00

Handle non-construct call

This commit is contained in:
Stefan Siegl 2013-06-23 00:18:31 +02:00
parent 5987d5d3da
commit 286b0d8ac0
3 changed files with 46 additions and 1 deletions

View File

@ -49,6 +49,7 @@ extern "C" {
#define V8JS_FLOAT(v) v8::Number::New(v)
#define V8JS_BOOL(v) v8::Boolean::New(v)
#define V8JS_NULL v8::Null()
#define V8JS_UNDEFINED v8::Undefined()
#define V8JS_MN(name) v8js_method_##name
#define V8JS_METHOD(name) void V8JS_MN(name)(const v8::FunctionCallbackInfo<v8::Value>& info)
#define V8JS_THROW(type, message, message_len) v8::ThrowException(v8::Exception::type(V8JS_STRL(message, message_len)))

View File

@ -0,0 +1,40 @@
--TEST--
Test V8::executeString() : Test PHP object construction controlled by JavaScript (non-construction call)
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$v8 = new V8Js();
class Greeter {
function sayHello($a) {
echo "Hello $a\n";
}
}
$v8->greeter = new Greeter();
$v8->executeString('
function JsGreeter() { };
JsGreeter.prototype.sayHello = function(a) {
print("Hello " + a + "\n");
};
jsGreeter = new JsGreeter();
jsGreeter.sayHello("Paul");
print(jsGreeter.constructor());
print("\n");
// ----- now the same using v8Js -----
PHP.greeter.sayHello("John");
print(PHP.greeter.constructor());
print("\n");
');
?>
===EOF===
--EXPECT--
Hello Paul
undefined
Hello John
undefined
===EOF===

View File

@ -159,13 +159,17 @@ static void php_v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& inf
static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
{
v8::Isolate *isolate = v8::Isolate::GetCurrent();
info.GetReturnValue().Set(V8JS_NULL);
info.GetReturnValue().Set(V8JS_UNDEFINED);
// @todo assert constructor call
v8::Handle<v8::Object> newobj = info.This();
zval *value;
TSRMLS_FETCH();
if (!info.IsConstructCall()) {
return;
}
if (info[0]->IsExternal()) {
// Object created by v8js in php_v8js_hash_to_jsobj, PHP object passed as v8::External.
value = static_cast<zval *>(v8::External::Cast(*info[0])->Value());