mirror of
https://github.com/phpv8/v8js.git
synced 2025-01-03 12:21:51 +00:00
Unwrap PHP objects when passing them back from JavaScript to PHP.
This commit is contained in:
parent
6de3e901fa
commit
2516e76ff8
@ -43,12 +43,13 @@ var_dump($a->executeString("test(false);", "test9.js"));
|
||||
===EOF===
|
||||
--EXPECT--
|
||||
NULL
|
||||
object(V8Object)#3 (2) {
|
||||
["mytest"]=>
|
||||
object(V8Function)#4 (0) {
|
||||
}
|
||||
object(Testing)#2 (3) {
|
||||
["foo"]=>
|
||||
string(8) "ORIGINAL"
|
||||
["my_private":"Testing":private]=>
|
||||
string(3) "arf"
|
||||
["my_protected":protected]=>
|
||||
string(4) "argh"
|
||||
}
|
||||
array(3) {
|
||||
[0]=>
|
||||
|
@ -28,6 +28,8 @@ extern "C" {
|
||||
#include <v8.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#define PHPJS_OBJECT_KEY "phpjs::object"
|
||||
|
||||
#if PHP_V8_API_VERSION < 3022000
|
||||
/* CopyablePersistentTraits is only part of V8 from 3.22.0 on,
|
||||
to be compatible with lower versions add our own (compatible) version. */
|
||||
@ -231,6 +233,7 @@ static void php_v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value
|
||||
|
||||
newobj->SetAlignedPointerInInternalField(0, value);
|
||||
newobj->SetAlignedPointerInInternalField(1, (void *) isolate);
|
||||
newobj->SetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY), v8::True(isolate));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -734,6 +737,13 @@ int v8js_to_zval(v8::Handle<v8::Value> jsValue, zval *return_value, int flags, v
|
||||
}
|
||||
else if (jsValue->IsObject())
|
||||
{
|
||||
v8::Handle<v8::Object> self = v8::Handle<v8::Object>::Cast(jsValue);
|
||||
// if this is a wrapped PHP object, then just unwrap it.
|
||||
if (!self->GetHiddenValue(V8JS_SYM(PHPJS_OBJECT_KEY)).IsEmpty()) {
|
||||
zval *object = reinterpret_cast<zval *>(self->GetAlignedPointerFromInternalField(0));
|
||||
RETVAL_ZVAL(object, 1, 0);
|
||||
return SUCCESS;
|
||||
}
|
||||
if ((flags & V8JS_FLAG_FORCE_ARRAY) || jsValue->IsArray()) {
|
||||
array_init(return_value);
|
||||
return php_v8js_v8_get_properties_hash(jsValue, Z_ARRVAL_P(return_value), flags, isolate TSRMLS_CC);
|
||||
|
Loading…
Reference in New Issue
Block a user