v8js_convert.cc 17 KB

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