v8js_convert.cc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2010 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | [email protected] so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Jani Taskinen <[email protected]> |
  16. +----------------------------------------------------------------------+
  17. */
  18. /* $Id$ */
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. extern "C" {
  23. #include "php.h"
  24. #include "ext/date/php_date.h"
  25. #include "zend_interfaces.h"
  26. #include "zend_closures.h"
  27. }
  28. #include "php_v8js_macros.h"
  29. #include <v8.h>
  30. /* Callback for PHP methods and functions */
  31. static v8::Handle<v8::Value> php_v8js_php_callback(const v8::Arguments &args) /* {{{ */
  32. {
  33. v8::Handle<v8::Value> return_value;
  34. zval *value = reinterpret_cast<zval *>(args.This()->GetPointerFromInternalField(0));
  35. zend_function *method_ptr;
  36. zend_fcall_info fci;
  37. zend_fcall_info_cache fcc;
  38. zval fname, *retval_ptr = NULL, **argv = NULL;
  39. TSRMLS_FETCH();
  40. zend_class_entry *ce = Z_OBJCE_P(value);
  41. zend_uint argc = args.Length(), min_num_args = 0, max_num_args = 0;
  42. char *error;
  43. int error_len, i, flags = V8JS_FLAG_NONE;
  44. /* Set method_ptr from v8::External or fetch the closure invoker */
  45. if (!args.Data().IsEmpty() && args.Data()->IsExternal()) {
  46. method_ptr = static_cast<zend_function *>(v8::External::Unwrap(args.Data()));
  47. } else {
  48. method_ptr = zend_get_closure_invoke_method(value TSRMLS_CC);
  49. }
  50. /* Set parameter limits */
  51. min_num_args = method_ptr->common.required_num_args;
  52. max_num_args = method_ptr->common.num_args;
  53. /* Function name to call */
  54. ZVAL_STRING(&fname, method_ptr->common.function_name, 0);
  55. /* zend_fcall_info */
  56. fci.size = sizeof(fci);
  57. fci.function_table = &ce->function_table;
  58. fci.function_name = &fname;
  59. fci.symbol_table = NULL;
  60. fci.object_ptr = value;
  61. fci.retval_ptr_ptr = &retval_ptr;
  62. fci.param_count = 0;
  63. /* Check for passed vs required number of arguments */
  64. if (argc < min_num_args)
  65. {
  66. error_len = spprintf(&error, 0,
  67. "%s::%s() expects %s %d parameter%s, %d given",
  68. ce->name,
  69. method_ptr->common.function_name,
  70. min_num_args == max_num_args ? "exactly" : argc < min_num_args ? "at least" : "at most",
  71. argc < min_num_args ? min_num_args : max_num_args,
  72. (argc < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
  73. argc);
  74. return_value = V8JS_THROW(TypeError, error, error_len);
  75. if (ce == zend_ce_closure) {
  76. efree(const_cast<char*>(method_ptr->internal_function.function_name));
  77. efree(method_ptr);
  78. }
  79. efree(error);
  80. return return_value;
  81. }
  82. /* Convert parameters passed from V8 */
  83. if (argc) {
  84. flags = V8JS_GLOBAL_GET_FLAGS();
  85. fci.params = (zval ***) safe_emalloc(argc, sizeof(zval **), 0);
  86. argv = (zval **) safe_emalloc(argc, sizeof(zval *), 0);
  87. for (i = 0; i < argc; i++) {
  88. MAKE_STD_ZVAL(argv[i]);
  89. if (v8js_to_zval(args[i], argv[i], flags TSRMLS_CC) == FAILURE) {
  90. fci.param_count++;
  91. error_len = spprintf(&error, 0, "converting parameter #%d passed to %s() failed", i + 1, method_ptr->common.function_name);
  92. return_value = V8JS_THROW(Error, error, error_len);
  93. efree(error);
  94. goto failure;
  95. }
  96. fci.params[fci.param_count++] = &argv[i];
  97. }
  98. } else {
  99. fci.params = NULL;
  100. }
  101. fci.no_separation = 1;
  102. /* zend_fcall_info_cache */
  103. fcc.initialized = 1;
  104. fcc.function_handler = method_ptr;
  105. fcc.calling_scope = ce;
  106. fcc.called_scope = ce;
  107. fcc.object_ptr = value;
  108. /* Call the method */
  109. zend_call_function(&fci, &fcc TSRMLS_CC);
  110. failure:
  111. /* Cleanup */
  112. if (argc) {
  113. for (i = 0; i < fci.param_count; i++) {
  114. zval_ptr_dtor(&argv[i]);
  115. }
  116. efree(argv);
  117. efree(fci.params);
  118. }
  119. if (retval_ptr != NULL) {
  120. return_value = zval_to_v8js(retval_ptr TSRMLS_CC);
  121. zval_ptr_dtor(&retval_ptr);
  122. } else {
  123. return_value = V8JS_NULL;
  124. }
  125. return return_value;
  126. }
  127. /* }}} */
  128. static int _php_v8js_is_assoc_array(HashTable *myht TSRMLS_DC) /* {{{ */
  129. {
  130. int i;
  131. char *key;
  132. ulong index, idx = 0;
  133. uint key_len;
  134. HashPosition pos;
  135. zend_hash_internal_pointer_reset_ex(myht, &pos);
  136. for (;; zend_hash_move_forward_ex(myht, &pos)) {
  137. i = zend_hash_get_current_key_ex(myht, &key, &key_len, &index, 0, &pos);
  138. if (i == HASH_KEY_NON_EXISTANT)
  139. break;
  140. if (i == HASH_KEY_IS_STRING || index != idx) {
  141. return 1;
  142. }
  143. idx++;
  144. }
  145. return 0;
  146. }
  147. /* }}} */
  148. static v8::Handle<v8::Value> php_v8js_property_caller(const v8::Arguments &args) /* {{{ */
  149. {
  150. v8::Local<v8::Object> self = args.Holder();
  151. v8::Local<v8::String> cname = args.Callee()->GetName()->ToString();
  152. v8::Local<v8::Value> value;
  153. v8::Local<v8::String> cb_func = v8::Local<v8::String>::Cast(args.Data());
  154. value = self->GetHiddenValue(cb_func);
  155. if (!value.IsEmpty() && value->IsFunction())
  156. {
  157. int argc = args.Length(), i = 0;
  158. v8::Local<v8::Value> *argv = new v8::Local<v8::Value>[argc];
  159. v8::Local<v8::Function> cb = v8::Local<v8::Function>::Cast(value);
  160. if (cb_func->Equals(V8JS_SYM(ZEND_INVOKE_FUNC_NAME))) {
  161. for (; i < argc; ++i) {
  162. argv[i] = args[i];
  163. }
  164. value = cb->Call(self, argc, argv);
  165. }
  166. else /* __call() */
  167. {
  168. v8::Local<v8::Array> argsarr = v8::Array::New(argc);
  169. for (; i < argc; ++i) {
  170. argsarr->Set(i, args[i]);
  171. }
  172. v8::Local<v8::Value> argsv[2] = { cname, argsarr };
  173. value = cb->Call(self, 2, argsv);
  174. }
  175. }
  176. if (args.IsConstructCall()) {
  177. if (!value.IsEmpty() && !value->IsNull()) {
  178. return value;
  179. }
  180. return self;
  181. }
  182. return value;
  183. }
  184. /* }}} */
  185. static v8::Handle<v8::Value> php_v8js_property_getter(v8::Local<v8::String> property, const v8::AccessorInfo &info) /* {{{ */
  186. {
  187. v8::Local<v8::Object> self = info.Holder();
  188. v8::Local<v8::Value> value;
  189. v8::Local<v8::Function> cb;
  190. /* Check first if JS object has the named property */
  191. value = self->GetRealNamedProperty(property);
  192. if (!value.IsEmpty()) {
  193. return value;
  194. }
  195. /* If __get() is set for PHP object, call it */
  196. value = self->GetHiddenValue(V8JS_SYM(ZEND_GET_FUNC_NAME));
  197. if (!value.IsEmpty() && value->IsFunction()) {
  198. cb = v8::Local<v8::Function>::Cast(value);
  199. v8::Local<v8::Value> argv[1] = {property};
  200. value = cb->Call(self, 1, argv);
  201. }
  202. /* If __get() does not exist or returns NULL, create new function with callback for __call() */
  203. if ((value.IsEmpty() || value->IsNull()) && info.Data()->IsTrue()) {
  204. v8::Local<v8::FunctionTemplate> cb_t = v8::FunctionTemplate::New(php_v8js_property_caller, V8JS_SYM(ZEND_CALL_FUNC_NAME));
  205. cb = cb_t->GetFunction();
  206. cb->SetName(property);
  207. return cb;
  208. }
  209. return value;
  210. }
  211. /* }}} */
  212. static v8::Handle<v8::Integer> php_v8js_property_query(v8::Local<v8::String> property, const v8::AccessorInfo &info) /* {{{ */
  213. {
  214. v8::Local<v8::Object> self = info.Holder();
  215. v8::Local<v8::Value> value;
  216. /* Return early if property is set in JS object */
  217. if (self->HasRealNamedProperty(property)) {
  218. return V8JS_INT(v8::ReadOnly);
  219. }
  220. value = self->GetHiddenValue(V8JS_SYM(ZEND_ISSET_FUNC_NAME));
  221. if (!value.IsEmpty() && value->IsFunction()) {
  222. v8::Local<v8::Function> cb = v8::Local<v8::Function>::Cast(value);
  223. v8::Local<v8::Value> argv[1] = {property};
  224. value = cb->Call(self, 1, argv);
  225. }
  226. return (!value.IsEmpty() && value->IsTrue()) ? V8JS_INT(v8::ReadOnly) : v8::Local<v8::Integer>();
  227. }
  228. /* }}} */
  229. /* These are not defined by Zend */
  230. #define ZEND_WAKEUP_FUNC_NAME "__wakeup"
  231. #define ZEND_SLEEP_FUNC_NAME "__sleep"
  232. #define ZEND_SET_STATE_FUNC_NAME "__set_state"
  233. #define IS_MAGIC_FUNC(mname) \
  234. ((key_len == sizeof(mname)) && \
  235. !strncasecmp(key, mname, key_len - 1))
  236. #define PHP_V8JS_CALLBACK(mptr) \
  237. v8::FunctionTemplate::New(php_v8js_php_callback, v8::External::New(mptr))->GetFunction()
  238. static v8::Handle<v8::Value> php_v8js_hash_to_jsobj(zval *value TSRMLS_DC) /* {{{ */
  239. {
  240. v8::Local<v8::FunctionTemplate> new_tpl = v8::FunctionTemplate::New();
  241. v8::Local<v8::Object> newobj;
  242. int i;
  243. char *key = NULL;
  244. ulong index;
  245. uint key_len;
  246. HashTable *myht;
  247. HashPosition pos;
  248. zend_class_entry *ce = NULL;
  249. zend_function *method_ptr, *call_ptr = NULL, *get_ptr = NULL, *invoke_ptr = NULL, *isset_ptr = NULL;
  250. if (Z_TYPE_P(value) == IS_ARRAY) {
  251. myht = HASH_OF(value);
  252. } else {
  253. myht = Z_OBJPROP_P(value);
  254. ce = Z_OBJCE_P(value);
  255. }
  256. /* Prevent recursion */
  257. if (myht && myht->nApplyCount > 1) {
  258. return V8JS_NULL;
  259. }
  260. /* Object methods */
  261. if (ce) {
  262. new_tpl->SetClassName(V8JS_STRL(ce->name, ce->name_length));
  263. new_tpl->InstanceTemplate()->SetInternalFieldCount(1);
  264. if (ce == zend_ce_closure) {
  265. new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(php_v8js_php_callback);
  266. newobj = new_tpl->InstanceTemplate()->NewInstance();
  267. } else {
  268. zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos);
  269. for (;; zend_hash_move_forward_ex(&ce->function_table, &pos)) {
  270. if (zend_hash_get_current_key_ex(&ce->function_table, &key, &key_len, &index, 0, &pos) != HASH_KEY_IS_STRING ||
  271. zend_hash_get_current_data_ex(&ce->function_table, (void **) &method_ptr, &pos) == FAILURE
  272. ) {
  273. break;
  274. }
  275. if ((method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) && /* Allow only public methods */
  276. (method_ptr->common.fn_flags & ZEND_ACC_CTOR) == 0 && /* ..and no __construct() */
  277. (method_ptr->common.fn_flags & ZEND_ACC_DTOR) == 0 && /* ..or __destruct() */
  278. (method_ptr->common.fn_flags & ZEND_ACC_CLONE) == 0 /* ..or __clone() functions */
  279. ) {
  280. /* Override native toString() with __tostring() if it is set in passed object */
  281. if (IS_MAGIC_FUNC(ZEND_TOSTRING_FUNC_NAME)) {
  282. new_tpl->InstanceTemplate()->Set(V8JS_SYM("toString"), PHP_V8JS_CALLBACK(method_ptr));
  283. /* TODO: __set(), __unset() disabled as JS is not allowed to modify the passed PHP object yet.
  284. * __sleep(), __wakeup(), __set_state() are always ignored */
  285. } else if (
  286. IS_MAGIC_FUNC(ZEND_CALLSTATIC_FUNC_NAME)|| /* TODO */
  287. IS_MAGIC_FUNC(ZEND_SLEEP_FUNC_NAME) ||
  288. IS_MAGIC_FUNC(ZEND_WAKEUP_FUNC_NAME) ||
  289. IS_MAGIC_FUNC(ZEND_SET_STATE_FUNC_NAME) ||
  290. IS_MAGIC_FUNC(ZEND_SET_FUNC_NAME) ||
  291. IS_MAGIC_FUNC(ZEND_UNSET_FUNC_NAME)
  292. ) {
  293. /* Register all magic function as hidden with lowercase name */
  294. } else if (IS_MAGIC_FUNC(ZEND_GET_FUNC_NAME)) {
  295. get_ptr = method_ptr;
  296. } else if (IS_MAGIC_FUNC(ZEND_CALL_FUNC_NAME)) {
  297. call_ptr = method_ptr;
  298. } else if (IS_MAGIC_FUNC(ZEND_INVOKE_FUNC_NAME)) {
  299. invoke_ptr = method_ptr;
  300. } else if (IS_MAGIC_FUNC(ZEND_ISSET_FUNC_NAME)) {
  301. isset_ptr = method_ptr;
  302. } else {
  303. new_tpl->InstanceTemplate()->Set(V8JS_STR(method_ptr->common.function_name), PHP_V8JS_CALLBACK(method_ptr), v8::ReadOnly);
  304. }
  305. }
  306. }
  307. /* Only register getter, etc. when they're set in PHP side */
  308. if (call_ptr || get_ptr || isset_ptr)
  309. {
  310. /* Set __get() handler which acts also as __call() proxy */
  311. new_tpl->InstanceTemplate()->SetNamedPropertyHandler(
  312. php_v8js_property_getter, /* getter */
  313. 0, /* setter */
  314. isset_ptr ? php_v8js_property_query : 0, /* query */
  315. 0, /* deleter */
  316. 0, /* enumerator */
  317. V8JS_BOOL(call_ptr ? true : false)
  318. );
  319. }
  320. /* __invoke() handler */
  321. if (invoke_ptr) {
  322. new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(php_v8js_property_caller, V8JS_SYM(ZEND_INVOKE_FUNC_NAME));
  323. }
  324. newobj = new_tpl->InstanceTemplate()->NewInstance();
  325. if (call_ptr) {
  326. newobj->SetHiddenValue(V8JS_SYM(ZEND_CALL_FUNC_NAME), PHP_V8JS_CALLBACK(call_ptr));
  327. }
  328. if (get_ptr) {
  329. newobj->SetHiddenValue(V8JS_SYM(ZEND_GET_FUNC_NAME), PHP_V8JS_CALLBACK(get_ptr));
  330. }
  331. if (invoke_ptr) {
  332. newobj->SetHiddenValue(V8JS_SYM(ZEND_INVOKE_FUNC_NAME), PHP_V8JS_CALLBACK(invoke_ptr));
  333. }
  334. if (isset_ptr) {
  335. newobj->SetHiddenValue(V8JS_SYM(ZEND_ISSET_FUNC_NAME), PHP_V8JS_CALLBACK(isset_ptr));
  336. }
  337. }
  338. newobj->SetPointerInInternalField(0, (void *) value);
  339. } else {
  340. new_tpl->SetClassName(V8JS_SYM("Array"));
  341. newobj = new_tpl->InstanceTemplate()->NewInstance();
  342. }
  343. /* Object properties */
  344. i = myht ? zend_hash_num_elements(myht) : 0;
  345. if (i > 0)
  346. {
  347. zval **data;
  348. HashTable *tmp_ht;
  349. zend_hash_internal_pointer_reset_ex(myht, &pos);
  350. for (;; zend_hash_move_forward_ex(myht, &pos)) {
  351. i = zend_hash_get_current_key_ex(myht, &key, &key_len, &index, 0, &pos);
  352. if (i == HASH_KEY_NON_EXISTANT)
  353. break;
  354. if (zend_hash_get_current_data_ex(myht, (void **) &data, &pos) == SUCCESS)
  355. {
  356. tmp_ht = HASH_OF(*data);
  357. if (tmp_ht) {
  358. tmp_ht->nApplyCount++;
  359. }
  360. if (i == HASH_KEY_IS_STRING)
  361. {
  362. if (key[0] == '\0' && Z_TYPE_P(value) == IS_OBJECT) {
  363. /* Skip protected and private members. */
  364. if (tmp_ht) {
  365. tmp_ht->nApplyCount--;
  366. }
  367. continue;
  368. }
  369. newobj->Set(V8JS_STRL(key, key_len - 1), zval_to_v8js(*data TSRMLS_CC), v8::ReadOnly);
  370. } else {
  371. newobj->Set(index, zval_to_v8js(*data TSRMLS_CC));
  372. }
  373. if (tmp_ht) {
  374. tmp_ht->nApplyCount--;
  375. }
  376. }
  377. }
  378. }
  379. return newobj;
  380. }
  381. /* }}} */
  382. static v8::Handle<v8::Value> php_v8js_hash_to_jsarr(zval *value TSRMLS_DC) /* {{{ */
  383. {
  384. HashTable *myht = HASH_OF(value);
  385. int i = myht ? zend_hash_num_elements(myht) : 0;
  386. /* Return object if dealing with assoc array */
  387. if (i > 0 && _php_v8js_is_assoc_array(myht TSRMLS_CC)) {
  388. return php_v8js_hash_to_jsobj(value TSRMLS_CC);
  389. }
  390. v8::Local<v8::Array> newarr;
  391. /* Prevent recursion */
  392. if (myht && myht->nApplyCount > 1) {
  393. return V8JS_NULL;
  394. }
  395. newarr = v8::Array::New(i);
  396. if (i > 0)
  397. {
  398. zval **data;
  399. ulong index = 0;
  400. HashTable *tmp_ht;
  401. HashPosition pos;
  402. for (zend_hash_internal_pointer_reset_ex(myht, &pos);
  403. SUCCESS == zend_hash_get_current_data_ex(myht, (void **) &data, &pos);
  404. zend_hash_move_forward_ex(myht, &pos)
  405. ) {
  406. tmp_ht = HASH_OF(*data);
  407. if (tmp_ht) {
  408. tmp_ht->nApplyCount++;
  409. }
  410. newarr->Set(index++, zval_to_v8js(*data TSRMLS_CC));
  411. if (tmp_ht) {
  412. tmp_ht->nApplyCount--;
  413. }
  414. }
  415. }
  416. return newarr;
  417. }
  418. /* }}} */
  419. v8::Handle<v8::Value> zval_to_v8js(zval *value TSRMLS_DC) /* {{{ */
  420. {
  421. v8::Handle<v8::Value> jsValue;
  422. switch (Z_TYPE_P(value))
  423. {
  424. case IS_ARRAY:
  425. jsValue = php_v8js_hash_to_jsarr(value TSRMLS_CC);
  426. break;
  427. case IS_OBJECT:
  428. jsValue = php_v8js_hash_to_jsobj(value TSRMLS_CC);
  429. break;
  430. case IS_STRING:
  431. jsValue = V8JS_STRL(Z_STRVAL_P(value), Z_STRLEN_P(value));
  432. break;
  433. case IS_LONG:
  434. jsValue = V8JS_INT(Z_LVAL_P(value));
  435. break;
  436. case IS_DOUBLE:
  437. jsValue = V8JS_FLOAT(Z_DVAL_P(value));
  438. break;
  439. case IS_BOOL:
  440. jsValue = V8JS_BOOL(Z_BVAL_P(value));
  441. break;
  442. default:
  443. case IS_NULL:
  444. jsValue = V8JS_NULL;
  445. break;
  446. }
  447. return jsValue;
  448. }
  449. /* }}} */
  450. int v8js_to_zval(v8::Handle<v8::Value> jsValue, zval *return_value, int flags TSRMLS_DC) /* {{{ */
  451. {
  452. if (jsValue->IsString())
  453. {
  454. v8::String::Utf8Value str(jsValue);
  455. const char *cstr = ToCString(str);
  456. RETVAL_STRING(cstr, 1);
  457. }
  458. else if (jsValue->IsBoolean())
  459. {
  460. RETVAL_BOOL(jsValue->Uint32Value());
  461. }
  462. else if (jsValue->IsInt32() || jsValue->IsUint32())
  463. {
  464. RETVAL_LONG((long) jsValue->IntegerValue());
  465. }
  466. else if (jsValue->IsNumber())
  467. {
  468. RETVAL_DOUBLE(jsValue->NumberValue());
  469. }
  470. else if (jsValue->IsDate()) /* Return as a PHP DateTime object */
  471. {
  472. v8::String::Utf8Value str(jsValue);
  473. const char *cstr = ToCString(str);
  474. zend_class_entry *ce = php_date_get_date_ce();
  475. #if PHP_VERSION_ID < 50304
  476. zval *param;
  477. MAKE_STD_ZVAL(param);
  478. ZVAL_STRING(param, cstr, 1);
  479. object_init_ex(return_value, ce TSRMLS_CC);
  480. zend_call_method_with_1_params(&return_value, ce, &ce->constructor, "__construct", NULL, param);
  481. zval_ptr_dtor(&param);
  482. if (EG(exception)) {
  483. return FAILURE;
  484. }
  485. #else
  486. php_date_instantiate(ce, return_value TSRMLS_CC);
  487. if (!php_date_initialize((php_date_obj *) zend_object_store_get_object(return_value TSRMLS_CC), (char *) cstr, strlen(cstr), NULL, NULL, 0 TSRMLS_CC)) {
  488. return FAILURE;
  489. }
  490. #endif
  491. }
  492. else if (jsValue->IsObject())
  493. {
  494. if ((flags & V8JS_FLAG_FORCE_ARRAY) || jsValue->IsArray()) {
  495. array_init(return_value);
  496. return php_v8js_v8_get_properties_hash(jsValue, Z_ARRVAL_P(return_value), flags TSRMLS_CC);
  497. } else {
  498. php_v8js_create_v8(return_value, jsValue, flags TSRMLS_CC);
  499. return SUCCESS;
  500. }
  501. }
  502. else /* types External, RegExp, Undefined and Null are considered NULL */
  503. {
  504. RETVAL_NULL();
  505. }
  506. return SUCCESS;
  507. }
  508. /* }}} */
  509. /*
  510. * Local variables:
  511. * tab-width: 4
  512. * c-basic-offset: 4
  513. * End:
  514. * vim600: noet sw=4 ts=4 fdm=marker
  515. * vim<600: noet sw=4 ts=4
  516. */