v8js_class.cc 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2013 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | http://www.opensource.org/licenses/mit-license.php MIT License |
  8. +----------------------------------------------------------------------+
  9. | Author: Jani Taskinen <[email protected]> |
  10. | Author: Patrick Reilly <[email protected]> |
  11. +----------------------------------------------------------------------+
  12. */
  13. #ifdef HAVE_CONFIG_H
  14. #include "config.h"
  15. #endif
  16. extern "C" {
  17. #include "php.h"
  18. #include "ext/date/php_date.h"
  19. #include "ext/standard/php_string.h"
  20. #include "zend_interfaces.h"
  21. #include "zend_closures.h"
  22. #include "ext/spl/spl_exceptions.h"
  23. #include "zend_exceptions.h"
  24. }
  25. #include "php_v8js_macros.h"
  26. #include "v8js_v8.h"
  27. #include "v8js_debug.h"
  28. #include "v8js_exceptions.h"
  29. #include "v8js_v8object_class.h"
  30. #include "v8js_timer.h"
  31. #include <functional>
  32. #include <algorithm>
  33. #define PHP_V8JS_SCRIPT_RES_NAME "V8Js script"
  34. /* {{{ Class Entries */
  35. static zend_class_entry *php_ce_v8js;
  36. /* }}} */
  37. /* {{{ Object Handlers */
  38. static zend_object_handlers v8js_object_handlers;
  39. /* }}} */
  40. typedef struct _v8js_script {
  41. char *name;
  42. v8js_ctx *ctx;
  43. v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>> *script;
  44. } v8js_script;
  45. static void v8js_script_free(v8js_script *res);
  46. int le_v8js_script;
  47. /* {{{ Extension container */
  48. struct v8js_jsext {
  49. zend_bool auto_enable;
  50. HashTable *deps_ht;
  51. const char **deps;
  52. int deps_count;
  53. char *name;
  54. char *source;
  55. v8::Extension *extension;
  56. };
  57. /* }}} */
  58. #if PHP_V8_API_VERSION >= 4004010
  59. class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
  60. public:
  61. virtual void* Allocate(size_t length) {
  62. void* data = AllocateUninitialized(length);
  63. return data == NULL ? data : memset(data, 0, length);
  64. }
  65. virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
  66. virtual void Free(void* data, size_t) { free(data); }
  67. };
  68. #endif
  69. static void v8js_free_storage(void *object TSRMLS_DC) /* {{{ */
  70. {
  71. v8js_ctx *c = (v8js_ctx *) object;
  72. zend_object_std_dtor(&c->std TSRMLS_CC);
  73. if (c->pending_exception) {
  74. zval_ptr_dtor(&c->pending_exception);
  75. }
  76. if (c->module_loader) {
  77. zval_ptr_dtor(&c->module_loader);
  78. }
  79. /* Delete PHP global object from JavaScript */
  80. if (!c->context.IsEmpty()) {
  81. v8::Locker locker(c->isolate);
  82. v8::Isolate::Scope isolate_scope(c->isolate);
  83. v8::HandleScope handle_scope(c->isolate);
  84. v8::Local<v8::Context> v8_context = v8::Local<v8::Context>::New(c->isolate, c->context);
  85. v8::Context::Scope context_scope(v8_context);
  86. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(c->isolate, c->object_name);
  87. V8JS_GLOBAL(c->isolate)->Delete(object_name_js);
  88. }
  89. c->object_name.Reset();
  90. c->object_name.~Persistent();
  91. c->global_template.Reset();
  92. c->global_template.~Persistent();
  93. /* Clear persistent handles in template cache */
  94. for (std::map<const char *,v8js_tmpl_t>::iterator it = c->template_cache.begin();
  95. it != c->template_cache.end(); ++it) {
  96. it->second.Reset();
  97. }
  98. c->template_cache.~map();
  99. /* Clear contexts */
  100. for (std::vector<v8js_accessor_ctx*>::iterator it = c->accessor_list.begin();
  101. it != c->accessor_list.end(); ++it) {
  102. v8js_accessor_ctx_dtor(*it TSRMLS_CC);
  103. }
  104. c->accessor_list.~vector();
  105. /* Clear global object, dispose context */
  106. if (!c->context.IsEmpty()) {
  107. c->context.Reset();
  108. }
  109. c->context.~Persistent();
  110. /* Dispose yet undisposed weak refs */
  111. for (std::map<zval *, v8js_persistent_obj_t>::iterator it = c->weak_objects.begin();
  112. it != c->weak_objects.end(); ++it) {
  113. zval *value = it->first;
  114. zval_ptr_dtor(&value);
  115. c->isolate->AdjustAmountOfExternalAllocatedMemory(-1024);
  116. it->second.Reset();
  117. }
  118. c->weak_objects.~map();
  119. for (std::map<v8js_tmpl_t *, v8js_persistent_obj_t>::iterator it = c->weak_closures.begin();
  120. it != c->weak_closures.end(); ++it) {
  121. v8js_tmpl_t *persist_tpl_ = it->first;
  122. persist_tpl_->Reset();
  123. delete persist_tpl_;
  124. it->second.Reset();
  125. }
  126. c->weak_closures.~map();
  127. for (std::list<v8js_v8object *>::iterator it = c->v8js_v8objects.begin();
  128. it != c->v8js_v8objects.end(); it ++) {
  129. (*it)->v8obj.Reset();
  130. (*it)->ctx = NULL;
  131. }
  132. c->v8js_v8objects.~list();
  133. for (std::vector<v8js_script *>::iterator it = c->script_objects.begin();
  134. it != c->script_objects.end(); it ++) {
  135. (*it)->ctx = NULL;
  136. (*it)->script->Reset();
  137. }
  138. c->script_objects.~vector();
  139. /* Clear persistent handles in module cache */
  140. for (std::map<char *, v8js_persistent_obj_t>::iterator it = c->modules_loaded.begin();
  141. it != c->modules_loaded.end(); ++it) {
  142. efree(it->first);
  143. it->second.Reset();
  144. }
  145. c->modules_loaded.~map();
  146. if(c->isolate) {
  147. /* c->isolate is initialized by V8Js::__construct, but __wakeup calls
  148. * are not fully constructed and hence this would cause a NPE. */
  149. c->isolate->Dispose();
  150. }
  151. if(c->tz != NULL) {
  152. free(c->tz);
  153. }
  154. c->modules_stack.~vector();
  155. c->modules_base.~vector();
  156. efree(object);
  157. }
  158. /* }}} */
  159. static zend_object_value v8js_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */
  160. {
  161. zend_object_value retval;
  162. v8js_ctx *c;
  163. c = (v8js_ctx *) ecalloc(1, sizeof(*c));
  164. zend_object_std_init(&c->std, ce TSRMLS_CC);
  165. TSRMLS_SET_CTX(c->zts_ctx);
  166. #if PHP_VERSION_ID >= 50400
  167. object_properties_init(&c->std, ce);
  168. #else
  169. zval *tmp;
  170. zend_hash_copy(c->std.properties, &ce->default_properties,
  171. (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
  172. #endif
  173. new(&c->object_name) v8::Persistent<v8::String>();
  174. new(&c->context) v8::Persistent<v8::Context>();
  175. new(&c->global_template) v8::Persistent<v8::FunctionTemplate>();
  176. new(&c->modules_stack) std::vector<char*>();
  177. new(&c->modules_base) std::vector<char*>();
  178. new(&c->modules_loaded) std::map<char *, v8js_persistent_obj_t, cmp_str>;
  179. new(&c->template_cache) std::map<const char *,v8js_tmpl_t>();
  180. new(&c->accessor_list) std::vector<v8js_accessor_ctx *>();
  181. new(&c->weak_closures) std::map<v8js_tmpl_t *, v8js_persistent_obj_t>();
  182. new(&c->weak_objects) std::map<zval *, v8js_persistent_obj_t>();
  183. new(&c->v8js_v8objects) std::list<v8js_v8object *>();
  184. new(&c->script_objects) std::vector<v8js_script *>();
  185. retval.handle = zend_objects_store_put(c, NULL, (zend_objects_free_object_storage_t) v8js_free_storage, NULL TSRMLS_CC);
  186. retval.handlers = &v8js_object_handlers;
  187. return retval;
  188. }
  189. /* }}} */
  190. static void v8js_free_ext_strarr(const char **arr, int count) /* {{{ */
  191. {
  192. int i;
  193. if (arr) {
  194. for (i = 0; i < count; i++) {
  195. if (arr[i]) {
  196. free((void *) arr[i]);
  197. }
  198. }
  199. free(arr);
  200. }
  201. }
  202. /* }}} */
  203. static void v8js_jsext_dtor(v8js_jsext *jsext) /* {{{ */
  204. {
  205. if (jsext->deps_ht) {
  206. zend_hash_destroy(jsext->deps_ht);
  207. free(jsext->deps_ht);
  208. }
  209. if (jsext->deps) {
  210. v8js_free_ext_strarr(jsext->deps, jsext->deps_count);
  211. }
  212. delete jsext->extension;
  213. free(jsext->name);
  214. free(jsext->source);
  215. }
  216. /* }}} */
  217. static int v8js_create_ext_strarr(const char ***retval, int count, HashTable *ht) /* {{{ */
  218. {
  219. const char **exts = NULL;
  220. HashPosition pos;
  221. zval **tmp;
  222. int i = 0;
  223. exts = (const char **) calloc(1, count * sizeof(char *));
  224. zend_hash_internal_pointer_reset_ex(ht, &pos);
  225. while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &pos) == SUCCESS) {
  226. if (Z_TYPE_PP(tmp) == IS_STRING) {
  227. exts[i++] = zend_strndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
  228. } else {
  229. v8js_free_ext_strarr(exts, i);
  230. return FAILURE;
  231. }
  232. zend_hash_move_forward_ex(ht, &pos);
  233. }
  234. *retval = exts;
  235. return SUCCESS;
  236. }
  237. /* }}} */
  238. static void v8js_fatal_error_handler(const char *location, const char *message) /* {{{ */
  239. {
  240. v8::Isolate *isolate = v8::Isolate::GetCurrent();
  241. if (isolate) {
  242. isolate->Exit();
  243. }
  244. if (location) {
  245. zend_error(E_ERROR, "%s %s", location, message);
  246. } else {
  247. zend_error(E_ERROR, "%s", message);
  248. }
  249. }
  250. /* }}} */
  251. /* {{{ proto void V8Js::__construct([string object_name [, array variables [, array extensions [, bool report_uncaught_exceptions]]])
  252. __construct for V8Js */
  253. static PHP_METHOD(V8Js, __construct)
  254. {
  255. char *object_name = NULL, *class_name = NULL;
  256. int object_name_len = 0, free = 0;
  257. zend_uint class_name_len = 0;
  258. zend_bool report_uncaught = 1;
  259. zval *vars_arr = NULL, *exts_arr = NULL;
  260. const char **exts = NULL;
  261. int exts_count = 0;
  262. v8js_ctx *c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  263. if (!c->context.IsEmpty()) {
  264. /* called __construct() twice, bail out */
  265. return;
  266. }
  267. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|saab", &object_name, &object_name_len, &vars_arr, &exts_arr, &report_uncaught) == FAILURE) {
  268. return;
  269. }
  270. /* Initialize V8 */
  271. v8js_v8_init(TSRMLS_C);
  272. /* Throw PHP exception if uncaught exceptions exist */
  273. c->report_uncaught = report_uncaught;
  274. c->pending_exception = NULL;
  275. c->in_execution = 0;
  276. #if PHP_V8_API_VERSION >= 4004044
  277. static ArrayBufferAllocator array_buffer_allocator;
  278. static v8::Isolate::CreateParams create_params;
  279. create_params.array_buffer_allocator = &array_buffer_allocator;
  280. c->isolate = v8::Isolate::New(create_params);
  281. #else
  282. c->isolate = v8::Isolate::New();
  283. #endif
  284. c->isolate->SetData(0, c);
  285. c->time_limit = 0;
  286. c->time_limit_hit = false;
  287. c->memory_limit = 0;
  288. c->memory_limit_hit = false;
  289. c->module_loader = NULL;
  290. /* Include extensions used by this context */
  291. /* Note: Extensions registered with auto_enable do not need to be added separately like this. */
  292. if (exts_arr)
  293. {
  294. exts_count = zend_hash_num_elements(Z_ARRVAL_P(exts_arr));
  295. if (v8js_create_ext_strarr(&exts, exts_count, Z_ARRVAL_P(exts_arr)) == FAILURE) {
  296. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid extensions array passed");
  297. return;
  298. }
  299. }
  300. /* Declare configuration for extensions */
  301. v8::ExtensionConfiguration extension_conf(exts_count, exts);
  302. // Isolate execution
  303. v8::Isolate *isolate = c->isolate;
  304. v8::Locker locker(isolate);
  305. v8::Isolate::Scope isolate_scope(isolate);
  306. /* Handle scope */
  307. v8::HandleScope handle_scope(isolate);
  308. /* Redirect fatal errors to PHP error handler */
  309. // This needs to be done within the context isolate
  310. v8::V8::SetFatalErrorHandler(v8js_fatal_error_handler);
  311. /* Create global template for global object */
  312. // Now we are using multiple isolates this needs to be created for every context
  313. v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(c->isolate, 0);
  314. tpl->SetClassName(V8JS_SYM("V8Js"));
  315. c->global_template.Reset(isolate, tpl);
  316. /* Register builtin methods */
  317. v8js_register_methods(tpl->InstanceTemplate(), c);
  318. /* Create context */
  319. v8::Local<v8::Context> context = v8::Context::New(isolate, &extension_conf, tpl->InstanceTemplate());
  320. if (exts) {
  321. v8js_free_ext_strarr(exts, exts_count);
  322. }
  323. /* If extensions have errors, context will be empty. (NOTE: This is V8 stuff, they expect the passed sources to compile :) */
  324. if (context.IsEmpty()) {
  325. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to create V8 context. Check that registered extensions do not have errors.");
  326. ZVAL_NULL(getThis());
  327. return;
  328. }
  329. context->SetAlignedPointerInEmbedderData(1, c);
  330. c->context.Reset(isolate, context);
  331. /* Enter context */
  332. v8::Context::Scope context_scope(context);
  333. /* Create the PHP container object's function template */
  334. v8::Local<v8::FunctionTemplate> php_obj_t = v8::FunctionTemplate::New(isolate, 0);
  335. /* Set class name for PHP object */
  336. #if PHP_VERSION_ID >= 50400
  337. free = !zend_get_object_classname(getThis(), const_cast<const char**>(&class_name), &class_name_len TSRMLS_CC);
  338. #else
  339. free = !zend_get_object_classname(getThis(), &class_name, &class_name_len TSRMLS_CC);
  340. #endif
  341. php_obj_t->SetClassName(V8JS_SYML(class_name, class_name_len));
  342. if (free) {
  343. efree(class_name);
  344. }
  345. /* Register Get accessor for passed variables */
  346. if (vars_arr && zend_hash_num_elements(Z_ARRVAL_P(vars_arr)) > 0) {
  347. v8js_register_accessors(&c->accessor_list, php_obj_t, vars_arr, isolate TSRMLS_CC);
  348. }
  349. /* Set name for the PHP JS object */
  350. v8::Local<v8::String> object_name_js = (object_name_len) ? V8JS_SYML(object_name, object_name_len) : V8JS_SYM("PHP");
  351. c->object_name.Reset(isolate, object_name_js);
  352. /* Add the PHP object into global object */
  353. v8::Local<v8::Object> php_obj = php_obj_t->InstanceTemplate()->NewInstance();
  354. V8JS_GLOBAL(isolate)->ForceSet(object_name_js, php_obj, v8::ReadOnly);
  355. /* Export public property values */
  356. HashTable *properties = zend_std_get_properties(getThis() TSRMLS_CC);
  357. HashPosition pos;
  358. zval **value;
  359. ulong index;
  360. char *member;
  361. uint member_len;
  362. for(zend_hash_internal_pointer_reset_ex(properties, &pos);
  363. zend_hash_get_current_data_ex(properties, (void **) &value, &pos) == SUCCESS;
  364. zend_hash_move_forward_ex(properties, &pos)) {
  365. if(zend_hash_get_current_key_ex(properties, &member, &member_len, &index, 0, &pos) != HASH_KEY_IS_STRING) {
  366. continue;
  367. }
  368. zval zmember;
  369. INIT_ZVAL(zmember);
  370. ZVAL_STRING(&zmember, member, 0);
  371. zend_property_info *property_info = zend_get_property_info(c->std.ce, &zmember, 1 TSRMLS_CC);
  372. if(property_info && property_info->flags & ZEND_ACC_PUBLIC) {
  373. /* Write value to PHP JS object */
  374. php_obj->ForceSet(V8JS_SYML(member, member_len - 1), zval_to_v8js(*value, isolate TSRMLS_CC), v8::ReadOnly);
  375. }
  376. }
  377. }
  378. /* }}} */
  379. /* {{{ proto V8JS::__sleep()
  380. */
  381. PHP_METHOD(V8Js, __sleep)
  382. {
  383. zend_throw_exception(php_ce_v8js_exception,
  384. "You cannot serialize or unserialize V8Js instances", 0 TSRMLS_CC);
  385. RETURN_FALSE;
  386. }
  387. /* }}} */
  388. /* {{{ proto V8JS::__wakeup()
  389. */
  390. PHP_METHOD(V8Js, __wakeup)
  391. {
  392. zend_throw_exception(php_ce_v8js_exception,
  393. "You cannot serialize or unserialize V8Js instances", 0 TSRMLS_CC);
  394. RETURN_FALSE;
  395. }
  396. /* }}} */
  397. static void v8js_compile_script(zval *this_ptr, const char *str, int str_len, const char *identifier, int identifier_len, v8js_script **ret TSRMLS_DC)
  398. {
  399. v8js_script *res = NULL;
  400. V8JS_BEGIN_CTX(c, this_ptr)
  401. /* Catch JS exceptions */
  402. v8::TryCatch try_catch;
  403. /* Set script identifier */
  404. v8::Local<v8::String> sname = identifier_len ? V8JS_SYML(identifier, identifier_len) : V8JS_SYM("V8Js::compileString()");
  405. /* Compiles a string context independently. TODO: Add a php function which calls this and returns the result as resource which can be executed later. */
  406. v8::Local<v8::String> source = V8JS_STRL(str, str_len);
  407. v8::Local<v8::Script> script = v8::Script::Compile(source, sname);
  408. /* Compile errors? */
  409. if (script.IsEmpty()) {
  410. v8js_throw_script_exception(&try_catch TSRMLS_CC);
  411. return;
  412. }
  413. res = (v8js_script *)emalloc(sizeof(v8js_script));
  414. res->script = new v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>>(c->isolate, script);
  415. v8::String::Utf8Value _sname(sname);
  416. res->name = estrndup(ToCString(_sname), _sname.length());
  417. res->ctx = c;
  418. *ret = res;
  419. return;
  420. }
  421. static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, long memory_limit, zval **return_value TSRMLS_DC)
  422. {
  423. v8js_ctx *c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  424. if (res->ctx != c) {
  425. zend_error(E_WARNING, "Script resource from wrong V8Js object passed");
  426. ZVAL_BOOL(*return_value, 0);
  427. return;
  428. }
  429. if (!c->in_execution && time_limit == 0) {
  430. time_limit = c->time_limit;
  431. }
  432. if (!c->in_execution && memory_limit == 0) {
  433. memory_limit = c->memory_limit;
  434. }
  435. std::function< v8::Local<v8::Value>(v8::Isolate *) > v8_call = [res](v8::Isolate *isolate) {
  436. v8::Local<v8::Script> script = v8::Local<v8::Script>::New(isolate, *res->script);
  437. return script->Run();
  438. };
  439. v8js_v8_call(c, return_value, flags, time_limit, memory_limit, v8_call TSRMLS_CC);
  440. }
  441. /* {{{ proto mixed V8Js::executeString(string script [, string identifier [, int flags]])
  442. */
  443. static PHP_METHOD(V8Js, executeString)
  444. {
  445. char *str = NULL, *identifier = NULL, *tz = NULL;
  446. int str_len = 0, identifier_len = 0;
  447. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  448. v8js_script *res = NULL;
  449. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|slll", &str, &str_len, &identifier, &identifier_len, &flags, &time_limit, &memory_limit) == FAILURE) {
  450. return;
  451. }
  452. v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC);
  453. if (!res) {
  454. RETURN_FALSE;
  455. }
  456. v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
  457. v8js_script_free(res);
  458. efree(res);
  459. }
  460. /* }}} */
  461. /* {{{ proto mixed V8Js::compileString(string script [, string identifier])
  462. */
  463. static PHP_METHOD(V8Js, compileString)
  464. {
  465. char *str = NULL, *identifier = NULL;
  466. int str_len = 0, identifier_len = 0;
  467. v8js_script *res = NULL;
  468. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, &identifier, &identifier_len) == FAILURE) {
  469. return;
  470. }
  471. v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC);
  472. if (res) {
  473. ZEND_REGISTER_RESOURCE(return_value, res, le_v8js_script);
  474. v8js_ctx *ctx;
  475. ctx = (v8js_ctx *) zend_object_store_get_object(this_ptr TSRMLS_CC);
  476. ctx->script_objects.push_back(res);
  477. }
  478. return;
  479. }
  480. /* }}} */
  481. /* {{{ proto mixed V8Js::executeScript(resource script [, int flags]])
  482. */
  483. static PHP_METHOD(V8Js, executeScript)
  484. {
  485. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  486. zval *zscript;
  487. v8js_script *res;
  488. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lll", &zscript, &flags, &time_limit, &memory_limit) == FAILURE) {
  489. return;
  490. }
  491. ZEND_FETCH_RESOURCE(res, v8js_script*, &zscript, -1, PHP_V8JS_SCRIPT_RES_NAME, le_v8js_script);
  492. ZEND_VERIFY_RESOURCE(res);
  493. v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
  494. }
  495. /* }}} */
  496. /* {{{ proto mixed V8Js::checkString(string script)
  497. */
  498. static PHP_METHOD(V8Js, checkString)
  499. {
  500. char *str = NULL;
  501. int str_len = 0;
  502. const char *identifier = "V8Js::checkString()";
  503. int identifier_len = 19;
  504. v8js_script *res = NULL;
  505. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) {
  506. return;
  507. }
  508. v8js_compile_script(getThis(), str, str_len, identifier, identifier_len, &res TSRMLS_CC);
  509. if (!res) {
  510. RETURN_FALSE;
  511. }
  512. v8js_script_free(res);
  513. efree(res);
  514. RETURN_TRUE;
  515. }
  516. /* }}} */
  517. /* {{{ proto mixed V8Js::getPendingException()
  518. */
  519. static PHP_METHOD(V8Js, getPendingException)
  520. {
  521. v8js_ctx *c;
  522. if (zend_parse_parameters_none() == FAILURE) {
  523. return;
  524. }
  525. c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  526. if (c->pending_exception) {
  527. RETURN_ZVAL(c->pending_exception, 1, 0);
  528. }
  529. }
  530. /* }}} */
  531. /* {{{ proto void V8Js::clearPendingException()
  532. */
  533. static PHP_METHOD(V8Js, clearPendingException)
  534. {
  535. v8js_ctx *c;
  536. if (zend_parse_parameters_none() == FAILURE) {
  537. return;
  538. }
  539. c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  540. if (c->pending_exception) {
  541. zval_ptr_dtor(&c->pending_exception);
  542. c->pending_exception = NULL;
  543. }
  544. }
  545. /* }}} */
  546. /* {{{ proto void V8Js::setModuleLoader(string module)
  547. */
  548. static PHP_METHOD(V8Js, setModuleLoader)
  549. {
  550. v8js_ctx *c;
  551. zval *callable;
  552. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callable) == FAILURE) {
  553. return;
  554. }
  555. c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  556. c->module_loader = callable;
  557. Z_ADDREF_P(c->module_loader);
  558. }
  559. /* }}} */
  560. /* {{{ proto void V8Js::setTimeLimit(int time_limit)
  561. */
  562. static PHP_METHOD(V8Js, setTimeLimit)
  563. {
  564. v8js_ctx *c;
  565. long time_limit = 0;
  566. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &time_limit) == FAILURE) {
  567. return;
  568. }
  569. c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  570. c->time_limit = time_limit;
  571. V8JSG(timer_mutex).lock();
  572. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  573. it != V8JSG(timer_stack).end(); it ++) {
  574. if((*it)->ctx == c && !(*it)->killed) {
  575. (*it)->time_limit = time_limit;
  576. // Calculate the time point when the time limit is exceeded
  577. std::chrono::milliseconds duration(time_limit);
  578. std::chrono::time_point<std::chrono::high_resolution_clock> from = std::chrono::high_resolution_clock::now();
  579. (*it)->time_point = from + duration;
  580. }
  581. }
  582. V8JSG(timer_mutex).unlock();
  583. if (c->in_execution && time_limit && !V8JSG(timer_thread)) {
  584. /* If timer thread is not started already and we now impose a time limit
  585. * finally install the timer. */
  586. V8JSG(timer_thread) = new std::thread(v8js_timer_thread TSRMLS_CC);
  587. }
  588. }
  589. /* }}} */
  590. /* {{{ proto void V8Js::setMemoryLimit(int memory_limit)
  591. */
  592. static PHP_METHOD(V8Js, setMemoryLimit)
  593. {
  594. v8js_ctx *c;
  595. long memory_limit = 0;
  596. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &memory_limit) == FAILURE) {
  597. return;
  598. }
  599. c = (v8js_ctx *) zend_object_store_get_object(getThis() TSRMLS_CC);
  600. c->memory_limit = memory_limit;
  601. V8JSG(timer_mutex).lock();
  602. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  603. it != V8JSG(timer_stack).end(); it ++) {
  604. if((*it)->ctx == c && !(*it)->killed) {
  605. (*it)->memory_limit = memory_limit;
  606. }
  607. }
  608. V8JSG(timer_mutex).unlock();
  609. if (c->in_execution && memory_limit && !V8JSG(timer_thread)) {
  610. /* If timer thread is not started already and we now impose a memory limit
  611. * finally install the timer. */
  612. V8JSG(timer_thread) = new std::thread(v8js_timer_thread TSRMLS_CC);
  613. }
  614. }
  615. /* }}} */
  616. static void v8js_persistent_zval_ctor(zval **p) /* {{{ */
  617. {
  618. zval *orig_ptr = *p;
  619. *p = (zval *) malloc(sizeof(zval));
  620. **p = *orig_ptr;
  621. switch (Z_TYPE_P(*p)) {
  622. case IS_STRING:
  623. Z_STRVAL_P(*p) = (char *) zend_strndup(Z_STRVAL_P(*p), Z_STRLEN_P(*p));
  624. break;
  625. default:
  626. zend_bailout();
  627. }
  628. INIT_PZVAL(*p);
  629. }
  630. /* }}} */
  631. static void v8js_persistent_zval_dtor(zval **p) /* {{{ */
  632. {
  633. switch (Z_TYPE_P(*p)) {
  634. case IS_STRING:
  635. free(Z_STRVAL_P(*p));
  636. break;
  637. default:
  638. zend_bailout();
  639. }
  640. free(*p);
  641. }
  642. /* }}} */
  643. static void v8js_script_free(v8js_script *res)
  644. {
  645. efree(res->name);
  646. delete res->script; // does Reset()
  647. }
  648. static void v8js_script_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
  649. {
  650. v8js_script *res = (v8js_script *)rsrc->ptr;
  651. if (res) {
  652. if(res->ctx) {
  653. std::vector<v8js_script *>::iterator it = std::find(res->ctx->script_objects.begin(), res->ctx->script_objects.end(), res);
  654. res->ctx->script_objects.erase(it);
  655. }
  656. v8js_script_free(res);
  657. efree(res);
  658. }
  659. }
  660. /* }}} */
  661. static int v8js_register_extension(char *name, uint name_len, char *source, uint source_len, zval *deps_arr, zend_bool auto_enable TSRMLS_DC) /* {{{ */
  662. {
  663. v8js_jsext *jsext = NULL;
  664. if (!V8JSG(extensions)) {
  665. V8JSG(extensions) = (HashTable *) malloc(sizeof(HashTable));
  666. zend_hash_init(V8JSG(extensions), 1, NULL, (dtor_func_t) v8js_jsext_dtor, 1);
  667. } else if (zend_hash_exists(V8JSG(extensions), name, name_len + 1)) {
  668. return FAILURE;
  669. }
  670. jsext = (v8js_jsext *) calloc(1, sizeof(v8js_jsext));
  671. if (deps_arr) {
  672. jsext->deps_count = zend_hash_num_elements(Z_ARRVAL_P(deps_arr));
  673. if (v8js_create_ext_strarr(&jsext->deps, jsext->deps_count, Z_ARRVAL_P(deps_arr)) == FAILURE) {
  674. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid dependency array passed");
  675. v8js_jsext_dtor(jsext);
  676. free(jsext);
  677. return FAILURE;
  678. }
  679. }
  680. jsext->auto_enable = auto_enable;
  681. jsext->name = zend_strndup(name, name_len);
  682. jsext->source = zend_strndup(source, source_len);
  683. if (jsext->deps) {
  684. jsext->deps_ht = (HashTable *) malloc(sizeof(HashTable));
  685. zend_hash_init(jsext->deps_ht, jsext->deps_count, NULL, (dtor_func_t) v8js_persistent_zval_dtor, 1);
  686. zend_hash_copy(jsext->deps_ht, Z_ARRVAL_P(deps_arr), (copy_ctor_func_t) v8js_persistent_zval_ctor, NULL, sizeof(zval *));
  687. }
  688. jsext->extension = new v8::Extension(jsext->name, jsext->source, jsext->deps_count, jsext->deps);
  689. if (zend_hash_add(V8JSG(extensions), name, name_len + 1, jsext, sizeof(v8js_jsext), NULL) == FAILURE) {
  690. v8js_jsext_dtor(jsext);
  691. free(jsext);
  692. return FAILURE;
  693. }
  694. jsext->extension->set_auto_enable(auto_enable ? true : false);
  695. v8::RegisterExtension(jsext->extension);
  696. free(jsext);
  697. return SUCCESS;
  698. }
  699. /* }}} */
  700. /* {{{ proto bool V8Js::registerExtension(string ext_name, string script [, array deps [, bool auto_enable]])
  701. */
  702. static PHP_METHOD(V8Js, registerExtension)
  703. {
  704. char *ext_name, *script;
  705. zval *deps_arr = NULL;
  706. int ext_name_len, script_len;
  707. zend_bool auto_enable = 0;
  708. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ab", &ext_name, &ext_name_len, &script, &script_len, &deps_arr, &auto_enable) == FAILURE) {
  709. return;
  710. }
  711. if (!ext_name_len) {
  712. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Extension name cannot be empty");
  713. } else if (!script_len) {
  714. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Script cannot be empty");
  715. } else if (v8js_register_extension(ext_name, ext_name_len, script, script_len, deps_arr, auto_enable TSRMLS_CC) == SUCCESS) {
  716. RETURN_TRUE;
  717. }
  718. RETURN_FALSE;
  719. }
  720. /* }}} */
  721. /* ## Static methods ## */
  722. /* {{{ proto array V8Js::getExtensions()
  723. */
  724. static PHP_METHOD(V8Js, getExtensions)
  725. {
  726. v8js_jsext *jsext;
  727. zval *ext, *deps_arr;
  728. HashPosition pos;
  729. ulong index;
  730. char *key;
  731. uint key_len;
  732. if (zend_parse_parameters_none() == FAILURE) {
  733. return;
  734. }
  735. array_init(return_value);
  736. if (V8JSG(extensions)) {
  737. zend_hash_internal_pointer_reset_ex(V8JSG(extensions), &pos);
  738. while (zend_hash_get_current_data_ex(V8JSG(extensions), (void **) &jsext, &pos) == SUCCESS) {
  739. if (zend_hash_get_current_key_ex(V8JSG(extensions), &key, &key_len, &index, 0, &pos) == HASH_KEY_IS_STRING) {
  740. MAKE_STD_ZVAL(ext)
  741. array_init(ext);
  742. add_assoc_bool_ex(ext, ZEND_STRS("auto_enable"), jsext->auto_enable);
  743. if (jsext->deps_ht) {
  744. MAKE_STD_ZVAL(deps_arr);
  745. array_init(deps_arr);
  746. zend_hash_copy(Z_ARRVAL_P(deps_arr), jsext->deps_ht, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
  747. add_assoc_zval_ex(ext, ZEND_STRS("deps"), deps_arr);
  748. }
  749. add_assoc_zval_ex(return_value, key, key_len, ext);
  750. }
  751. zend_hash_move_forward_ex(V8JSG(extensions), &pos);
  752. }
  753. }
  754. }
  755. /* }}} */
  756. /* {{{ arginfo */
  757. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_construct, 0, 0, 0)
  758. ZEND_ARG_INFO(0, object_name)
  759. ZEND_ARG_INFO(0, variables)
  760. ZEND_ARG_INFO(0, extensions)
  761. ZEND_ARG_INFO(0, report_uncaught_exceptions)
  762. ZEND_END_ARG_INFO()
  763. ZEND_BEGIN_ARG_INFO(arginfo_v8js_sleep, 0)
  764. ZEND_END_ARG_INFO()
  765. ZEND_BEGIN_ARG_INFO(arginfo_v8js_wakeup, 0)
  766. ZEND_END_ARG_INFO()
  767. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_executestring, 0, 0, 1)
  768. ZEND_ARG_INFO(0, script)
  769. ZEND_ARG_INFO(0, identifier)
  770. ZEND_ARG_INFO(0, flags)
  771. ZEND_ARG_INFO(0, time_limit)
  772. ZEND_ARG_INFO(0, memory_limit)
  773. ZEND_END_ARG_INFO()
  774. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_compilestring, 0, 0, 1)
  775. ZEND_ARG_INFO(0, script)
  776. ZEND_ARG_INFO(0, identifier)
  777. ZEND_END_ARG_INFO()
  778. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_executescript, 0, 0, 1)
  779. ZEND_ARG_INFO(0, script)
  780. ZEND_ARG_INFO(0, flags)
  781. ZEND_ARG_INFO(0, time_limit)
  782. ZEND_ARG_INFO(0, memory_limit)
  783. ZEND_END_ARG_INFO()
  784. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_checkstring, 0, 0, 1)
  785. ZEND_ARG_INFO(0, script)
  786. ZEND_END_ARG_INFO()
  787. #ifdef ENABLE_DEBUGGER_SUPPORT
  788. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_destruct, 0, 0, 0)
  789. ZEND_END_ARG_INFO()
  790. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_startdebugagent, 0, 0, 0)
  791. ZEND_ARG_INFO(0, agentName)
  792. ZEND_ARG_INFO(0, port)
  793. ZEND_ARG_INFO(0, auto_break)
  794. ZEND_END_ARG_INFO()
  795. #endif /* ENABLE_DEBUGGER_SUPPORT */
  796. ZEND_BEGIN_ARG_INFO(arginfo_v8js_getpendingexception, 0)
  797. ZEND_END_ARG_INFO()
  798. ZEND_BEGIN_ARG_INFO(arginfo_v8js_clearpendingexception, 0)
  799. ZEND_END_ARG_INFO()
  800. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmoduleloader, 0, 0, 1)
  801. ZEND_ARG_INFO(0, callable)
  802. ZEND_END_ARG_INFO()
  803. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_registerextension, 0, 0, 2)
  804. ZEND_ARG_INFO(0, extension_name)
  805. ZEND_ARG_INFO(0, script)
  806. ZEND_ARG_INFO(0, dependencies)
  807. ZEND_ARG_INFO(0, auto_enable)
  808. ZEND_END_ARG_INFO()
  809. ZEND_BEGIN_ARG_INFO(arginfo_v8js_getextensions, 0)
  810. ZEND_END_ARG_INFO()
  811. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_settimelimit, 0, 0, 1)
  812. ZEND_ARG_INFO(0, time_limit)
  813. ZEND_END_ARG_INFO()
  814. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmemorylimit, 0, 0, 1)
  815. ZEND_ARG_INFO(0, memory_limit)
  816. ZEND_END_ARG_INFO()
  817. static const zend_function_entry v8js_methods[] = { /* {{{ */
  818. PHP_ME(V8Js, __construct, arginfo_v8js_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
  819. PHP_ME(V8Js, __sleep, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
  820. PHP_ME(V8Js, __wakeup, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
  821. PHP_ME(V8Js, executeString, arginfo_v8js_executestring, ZEND_ACC_PUBLIC)
  822. PHP_ME(V8Js, compileString, arginfo_v8js_compilestring, ZEND_ACC_PUBLIC)
  823. PHP_ME(V8Js, executeScript, arginfo_v8js_executescript, ZEND_ACC_PUBLIC)
  824. PHP_ME(V8Js, checkString, arginfo_v8js_checkstring, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
  825. PHP_ME(V8Js, getPendingException, arginfo_v8js_getpendingexception, ZEND_ACC_PUBLIC)
  826. PHP_ME(V8Js, clearPendingException, arginfo_v8js_clearpendingexception, ZEND_ACC_PUBLIC)
  827. PHP_ME(V8Js, setModuleLoader, arginfo_v8js_setmoduleloader, ZEND_ACC_PUBLIC)
  828. PHP_ME(V8Js, registerExtension, arginfo_v8js_registerextension, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  829. PHP_ME(V8Js, getExtensions, arginfo_v8js_getextensions, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  830. PHP_ME(V8Js, setTimeLimit, arginfo_v8js_settimelimit, ZEND_ACC_PUBLIC)
  831. PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC)
  832. #ifdef ENABLE_DEBUGGER_SUPPORT
  833. PHP_ME(V8Js, __destruct, arginfo_v8js_destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
  834. PHP_ME(V8Js, startDebugAgent, arginfo_v8js_startdebugagent, ZEND_ACC_PUBLIC)
  835. #endif
  836. {NULL, NULL, NULL}
  837. };
  838. /* }}} */
  839. /* V8Js object handlers */
  840. static void v8js_write_property(zval *object, zval *member, zval *value ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
  841. {
  842. V8JS_BEGIN_CTX(c, object)
  843. /* Check whether member is public, if so, export to V8. */
  844. zend_property_info *property_info = zend_get_property_info(c->std.ce, member, 1 TSRMLS_CC);
  845. if(property_info->flags & ZEND_ACC_PUBLIC) {
  846. /* Global PHP JS object */
  847. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  848. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
  849. /* Write value to PHP JS object */
  850. jsobj->ForceSet(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)), zval_to_v8js(value, isolate TSRMLS_CC), v8::ReadOnly);
  851. }
  852. /* Write value to PHP object */
  853. std_object_handlers.write_property(object, member, value ZEND_HASH_KEY_CC TSRMLS_CC);
  854. }
  855. /* }}} */
  856. static void v8js_unset_property(zval *object, zval *member ZEND_HASH_KEY_DC TSRMLS_DC) /* {{{ */
  857. {
  858. V8JS_BEGIN_CTX(c, object)
  859. /* Global PHP JS object */
  860. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  861. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
  862. /* Delete value from PHP JS object */
  863. jsobj->Delete(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)));
  864. /* Unset from PHP object */
  865. std_object_handlers.unset_property(object, member ZEND_HASH_KEY_CC TSRMLS_CC);
  866. }
  867. /* }}} */
  868. PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
  869. {
  870. zend_class_entry ce;
  871. /* V8Js Class */
  872. INIT_CLASS_ENTRY(ce, "V8Js", v8js_methods);
  873. php_ce_v8js = zend_register_internal_class(&ce TSRMLS_CC);
  874. php_ce_v8js->create_object = v8js_new;
  875. /* V8Js handlers */
  876. memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  877. v8js_object_handlers.clone_obj = NULL;
  878. v8js_object_handlers.write_property = v8js_write_property;
  879. v8js_object_handlers.unset_property = v8js_unset_property;
  880. /* V8Js Class Constants */
  881. zend_declare_class_constant_string(php_ce_v8js, ZEND_STRL("V8_VERSION"), PHP_V8_VERSION TSRMLS_CC);
  882. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_NONE"), V8JS_FLAG_NONE TSRMLS_CC);
  883. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_FORCE_ARRAY"), V8JS_FLAG_FORCE_ARRAY TSRMLS_CC);
  884. #ifdef ENABLE_DEBUGGER_SUPPORT
  885. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("DEBUG_AUTO_BREAK_NEVER"), V8JS_DEBUG_AUTO_BREAK_NEVER TSRMLS_CC);
  886. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("DEBUG_AUTO_BREAK_ONCE"), V8JS_DEBUG_AUTO_BREAK_ONCE TSRMLS_CC);
  887. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("DEBUG_AUTO_BREAK_ALWAYS"), V8JS_DEBUG_AUTO_BREAK_ALWAYS TSRMLS_CC);
  888. #endif
  889. le_v8js_script = zend_register_list_destructors_ex(v8js_script_dtor, NULL, PHP_V8JS_SCRIPT_RES_NAME, module_number);
  890. #if PHP_V8_API_VERSION >= 4004010 && PHP_V8_API_VERSION < 4004044
  891. static ArrayBufferAllocator array_buffer_allocator;
  892. v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
  893. #endif
  894. return SUCCESS;
  895. } /* }}} */
  896. /*
  897. * Local variables:
  898. * tab-width: 4
  899. * c-basic-offset: 4
  900. * End:
  901. * vim600: noet sw=4 ts=4 fdm=marker
  902. * vim<600: noet sw=4 ts=4
  903. */