v8js_class.cc 32 KB

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