v8js_class.cc 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  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. zend_string *name;
  55. zend_string *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(zend_object *object TSRMLS_DC) /* {{{ */
  71. {
  72. v8js_ctx *c = v8js_ctx_fetch_object(object);
  73. zend_object_std_dtor(&c->std TSRMLS_CC);
  74. zval_dtor(&c->pending_exception);
  75. zval_dtor(&c->module_loader);
  76. /* Delete PHP global object from JavaScript */
  77. if (!c->context.IsEmpty()) {
  78. v8::Locker locker(c->isolate);
  79. v8::Isolate::Scope isolate_scope(c->isolate);
  80. v8::HandleScope handle_scope(c->isolate);
  81. v8::Local<v8::Context> v8_context = v8::Local<v8::Context>::New(c->isolate, c->context);
  82. v8::Context::Scope context_scope(v8_context);
  83. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(c->isolate, c->object_name);
  84. V8JS_GLOBAL(c->isolate)->Delete(object_name_js);
  85. }
  86. c->object_name.Reset();
  87. c->object_name.~Persistent();
  88. c->global_template.Reset();
  89. c->global_template.~Persistent();
  90. c->array_tmpl.Reset();
  91. c->array_tmpl.~Persistent();
  92. /* Clear persistent call_impl & method_tmpls templates */
  93. for (std::map<v8js_tmpl_t *, v8js_tmpl_t>::iterator it = c->call_impls.begin();
  94. it != c->call_impls.end(); ++it) {
  95. // No need to free it->first, as it is stored in c->template_cache and freed below
  96. it->second.Reset();
  97. }
  98. c->call_impls.~map();
  99. for (std::map<zend_function *, v8js_tmpl_t>::iterator it = c->method_tmpls.begin();
  100. it != c->method_tmpls.end(); ++it) {
  101. it->second.Reset();
  102. }
  103. c->method_tmpls.~map();
  104. /* Clear persistent handles in template cache */
  105. for (std::map<const zend_string *,v8js_tmpl_t>::iterator it = c->template_cache.begin();
  106. it != c->template_cache.end(); ++it) {
  107. it->second.Reset();
  108. }
  109. c->template_cache.~map();
  110. /* Clear contexts */
  111. for (std::vector<v8js_accessor_ctx*>::iterator it = c->accessor_list.begin();
  112. it != c->accessor_list.end(); ++it) {
  113. v8js_accessor_ctx_dtor(*it TSRMLS_CC);
  114. }
  115. c->accessor_list.~vector();
  116. /* Clear global object, dispose context */
  117. if (!c->context.IsEmpty()) {
  118. c->context.Reset();
  119. }
  120. c->context.~Persistent();
  121. /* Dispose yet undisposed weak refs */
  122. for (std::map<zend_object *, v8js_persistent_obj_t>::iterator it = c->weak_objects.begin();
  123. it != c->weak_objects.end(); ++it) {
  124. zend_object *object = it->first;
  125. zval value;
  126. ZVAL_OBJ(&value, object);
  127. zval_dtor(&value);
  128. c->isolate->AdjustAmountOfExternalAllocatedMemory(-1024);
  129. it->second.Reset();
  130. }
  131. c->weak_objects.~map();
  132. for (std::map<v8js_tmpl_t *, v8js_persistent_obj_t>::iterator it = c->weak_closures.begin();
  133. it != c->weak_closures.end(); ++it) {
  134. v8js_tmpl_t *persist_tpl_ = it->first;
  135. persist_tpl_->Reset();
  136. delete persist_tpl_;
  137. it->second.Reset();
  138. }
  139. c->weak_closures.~map();
  140. for (std::list<v8js_v8object *>::iterator it = c->v8js_v8objects.begin();
  141. it != c->v8js_v8objects.end(); it ++) {
  142. (*it)->v8obj.Reset();
  143. (*it)->ctx = NULL;
  144. }
  145. c->v8js_v8objects.~list();
  146. for (std::vector<v8js_script *>::iterator it = c->script_objects.begin();
  147. it != c->script_objects.end(); it ++) {
  148. (*it)->ctx = NULL;
  149. (*it)->script->Reset();
  150. }
  151. c->script_objects.~vector();
  152. /* Clear persistent handles in module cache */
  153. for (std::map<char *, v8js_persistent_obj_t>::iterator it = c->modules_loaded.begin();
  154. it != c->modules_loaded.end(); ++it) {
  155. efree(it->first);
  156. it->second.Reset();
  157. }
  158. c->modules_loaded.~map();
  159. if(c->isolate) {
  160. /* c->isolate is initialized by V8Js::__construct, but __wakeup calls
  161. * are not fully constructed and hence this would cause a NPE. */
  162. c->isolate->Dispose();
  163. }
  164. if(c->tz != NULL) {
  165. free(c->tz);
  166. }
  167. c->modules_stack.~vector();
  168. c->modules_base.~vector();
  169. }
  170. /* }}} */
  171. static zend_object* v8js_new(zend_class_entry *ce TSRMLS_DC) /* {{{ */
  172. {
  173. v8js_ctx *c;
  174. c = (v8js_ctx *) ecalloc(1, sizeof(*c) + zend_object_properties_size(ce));
  175. zend_object_std_init(&c->std, ce TSRMLS_CC);
  176. object_properties_init(&c->std, ce);
  177. c->std.handlers = &v8js_object_handlers;
  178. TSRMLS_SET_CTX(c->zts_ctx);
  179. new(&c->object_name) v8::Persistent<v8::String>();
  180. new(&c->context) v8::Persistent<v8::Context>();
  181. new(&c->global_template) v8::Persistent<v8::FunctionTemplate>();
  182. new(&c->array_tmpl) v8::Persistent<v8::FunctionTemplate>();
  183. new(&c->modules_stack) std::vector<char*>();
  184. new(&c->modules_base) std::vector<char*>();
  185. new(&c->modules_loaded) std::map<char *, v8js_persistent_obj_t, cmp_str>;
  186. new(&c->template_cache) std::map<const zend_string *,v8js_tmpl_t>();
  187. new(&c->accessor_list) std::vector<v8js_accessor_ctx *>();
  188. new(&c->weak_closures) std::map<v8js_tmpl_t *, v8js_persistent_obj_t>();
  189. new(&c->weak_objects) std::map<zend_object *, v8js_persistent_obj_t>();
  190. new(&c->call_impls) std::map<v8js_tmpl_t *, v8js_tmpl_t>();
  191. new(&c->method_tmpls) std::map<zend_function *, v8js_tmpl_t>();
  192. new(&c->v8js_v8objects) std::list<v8js_v8object *>();
  193. new(&c->script_objects) std::vector<v8js_script *>();
  194. // @fixme following is const, run on startup
  195. v8js_object_handlers.offset = XtOffsetOf(struct v8js_ctx, std);
  196. v8js_object_handlers.free_obj = v8js_free_storage;
  197. return &c->std;
  198. }
  199. /* }}} */
  200. static void v8js_free_ext_strarr(const char **arr, int count) /* {{{ */
  201. {
  202. int i;
  203. if (arr) {
  204. for (i = 0; i < count; i++) {
  205. if (arr[i]) {
  206. free((void *) arr[i]);
  207. }
  208. }
  209. free(arr);
  210. }
  211. }
  212. /* }}} */
  213. static void v8js_jsext_free_storage(v8js_jsext *jsext) /* {{{ */
  214. {
  215. if (jsext->deps_ht) {
  216. zend_hash_destroy(jsext->deps_ht);
  217. free(jsext->deps_ht);
  218. }
  219. if (jsext->deps) {
  220. v8js_free_ext_strarr(jsext->deps, jsext->deps_count);
  221. }
  222. delete jsext->extension;
  223. zend_string_release(jsext->name);
  224. zend_string_release(jsext->source);
  225. free(jsext);
  226. }
  227. /* }}} */
  228. static void v8js_jsext_dtor(zval *zv) /* {{{ */
  229. {
  230. v8js_jsext_free_storage(reinterpret_cast<v8js_jsext *>(Z_PTR_P(zv)));
  231. }
  232. /* }}} */
  233. static int v8js_create_ext_strarr(const char ***retval, int count, HashTable *ht) /* {{{ */
  234. {
  235. const char **exts = NULL;
  236. HashPosition pos;
  237. zval *tmp;
  238. int i = 0;
  239. exts = (const char **) calloc(1, count * sizeof(char *));
  240. zend_hash_internal_pointer_reset_ex(ht, &pos);
  241. while ((tmp = zend_hash_get_current_data_ex(ht, &pos))) {
  242. if (Z_TYPE_P(tmp) == IS_STRING) {
  243. exts[i++] = zend_strndup(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
  244. } else {
  245. v8js_free_ext_strarr(exts, i);
  246. return FAILURE;
  247. }
  248. zend_hash_move_forward_ex(ht, &pos);
  249. }
  250. *retval = exts;
  251. return SUCCESS;
  252. }
  253. /* }}} */
  254. static void v8js_fatal_error_handler(const char *location, const char *message) /* {{{ */
  255. {
  256. v8::Isolate *isolate = v8::Isolate::GetCurrent();
  257. if (isolate) {
  258. isolate->Exit();
  259. }
  260. if (location) {
  261. zend_error(E_ERROR, "%s %s", location, message);
  262. } else {
  263. zend_error(E_ERROR, "%s", message);
  264. }
  265. }
  266. /* }}} */
  267. /* {{{ proto void V8Js::__construct([string object_name [, array variables [, array extensions [, bool report_uncaught_exceptions]]])
  268. __construct for V8Js */
  269. static PHP_METHOD(V8Js, __construct)
  270. {
  271. zend_string *object_name = NULL;
  272. zend_bool report_uncaught = 1;
  273. zval *vars_arr = NULL, *exts_arr = NULL;
  274. const char **exts = NULL;
  275. int exts_count = 0;
  276. v8js_ctx *c = Z_V8JS_CTX_OBJ_P(getThis())
  277. if (!c->context.IsEmpty()) {
  278. /* called __construct() twice, bail out */
  279. return;
  280. }
  281. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|Saab", &object_name, &vars_arr, &exts_arr, &report_uncaught) == FAILURE) {
  282. return;
  283. }
  284. /* Initialize V8 */
  285. v8js_v8_init(TSRMLS_C);
  286. /* Throw PHP exception if uncaught exceptions exist */
  287. c->report_uncaught = report_uncaught;
  288. ZVAL_NULL(&c->pending_exception);
  289. c->in_execution = 0;
  290. #if PHP_V8_API_VERSION >= 4004044
  291. static ArrayBufferAllocator array_buffer_allocator;
  292. static v8::Isolate::CreateParams create_params;
  293. create_params.array_buffer_allocator = &array_buffer_allocator;
  294. c->isolate = v8::Isolate::New(create_params);
  295. #else
  296. c->isolate = v8::Isolate::New();
  297. #endif
  298. c->isolate->SetData(0, c);
  299. c->time_limit = 0;
  300. c->time_limit_hit = false;
  301. c->memory_limit = 0;
  302. c->memory_limit_hit = false;
  303. ZVAL_NULL(&c->module_loader);
  304. /* Include extensions used by this context */
  305. /* Note: Extensions registered with auto_enable do not need to be added separately like this. */
  306. if (exts_arr)
  307. {
  308. exts_count = zend_hash_num_elements(Z_ARRVAL_P(exts_arr));
  309. if (v8js_create_ext_strarr(&exts, exts_count, Z_ARRVAL_P(exts_arr)) == FAILURE) {
  310. zend_throw_exception(php_ce_v8js_exception,
  311. "Invalid extensions array passed", 0);
  312. return;
  313. }
  314. }
  315. /* Declare configuration for extensions */
  316. v8::ExtensionConfiguration extension_conf(exts_count, exts);
  317. // Isolate execution
  318. v8::Isolate *isolate = c->isolate;
  319. v8::Locker locker(isolate);
  320. v8::Isolate::Scope isolate_scope(isolate);
  321. /* Handle scope */
  322. v8::HandleScope handle_scope(isolate);
  323. /* Redirect fatal errors to PHP error handler */
  324. // This needs to be done within the context isolate
  325. v8::V8::SetFatalErrorHandler(v8js_fatal_error_handler);
  326. /* Create global template for global object */
  327. // Now we are using multiple isolates this needs to be created for every context
  328. v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(c->isolate, 0);
  329. tpl->SetClassName(V8JS_SYM("V8Js"));
  330. c->global_template.Reset(isolate, tpl);
  331. /* Register builtin methods */
  332. v8js_register_methods(tpl->InstanceTemplate(), c);
  333. /* Create context */
  334. v8::Local<v8::Context> context = v8::Context::New(isolate, &extension_conf, tpl->InstanceTemplate());
  335. if (exts) {
  336. v8js_free_ext_strarr(exts, exts_count);
  337. }
  338. /* If extensions have errors, context will be empty. (NOTE: This is V8 stuff, they expect the passed sources to compile :) */
  339. if (context.IsEmpty()) {
  340. zend_throw_exception(php_ce_v8js_exception,
  341. "Failed to create V8 context. "
  342. "Check that registered extensions do not have errors.", 0);
  343. return;
  344. }
  345. context->SetAlignedPointerInEmbedderData(1, c);
  346. c->context.Reset(isolate, context);
  347. /* Enter context */
  348. v8::Context::Scope context_scope(context);
  349. /* Create the PHP container object's function template */
  350. v8::Local<v8::FunctionTemplate> php_obj_t = v8::FunctionTemplate::New(isolate, 0);
  351. /* Set class name for PHP object */
  352. zend_class_entry *ce = Z_OBJCE_P(getThis());
  353. php_obj_t->SetClassName(V8JS_SYML(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name)));
  354. /* Register Get accessor for passed variables */
  355. if (vars_arr && zend_hash_num_elements(Z_ARRVAL_P(vars_arr)) > 0) {
  356. v8js_register_accessors(&c->accessor_list, php_obj_t, vars_arr, isolate TSRMLS_CC);
  357. }
  358. /* Set name for the PHP JS object */
  359. v8::Local<v8::String> object_name_js = (object_name && ZSTR_LEN(object_name))
  360. ? V8JS_ZSYM(object_name)
  361. : V8JS_SYM("PHP");
  362. c->object_name.Reset(isolate, object_name_js);
  363. /* Add the PHP object into global object */
  364. v8::Local<v8::Object> php_obj = php_obj_t->InstanceTemplate()->NewInstance();
  365. V8JS_GLOBAL(isolate)->ForceSet(object_name_js, php_obj, v8::ReadOnly);
  366. /* Export public property values */
  367. HashTable *properties = zend_std_get_properties(getThis() TSRMLS_CC);
  368. zval *value;
  369. zend_string *member;
  370. ZEND_HASH_FOREACH_STR_KEY(properties, member) {
  371. zend_property_info *property_info = zend_get_property_info(c->std.ce, member, 1 TSRMLS_CC);
  372. if(property_info &&
  373. property_info != ZEND_WRONG_PROPERTY_INFO &&
  374. property_info->flags & ZEND_ACC_PUBLIC) {
  375. /* Write value to PHP JS object */
  376. value = OBJ_PROP(Z_OBJ_P(getThis()), property_info->offset);
  377. php_obj->ForceSet(V8JS_ZSYM(member), zval_to_v8js(value, isolate TSRMLS_CC), v8::ReadOnly);
  378. }
  379. } ZEND_HASH_FOREACH_END();
  380. }
  381. /* }}} */
  382. /* {{{ proto V8JS::__sleep()
  383. */
  384. PHP_METHOD(V8Js, __sleep)
  385. {
  386. zend_throw_exception(php_ce_v8js_exception,
  387. "You cannot serialize or unserialize V8Js instances", 0 TSRMLS_CC);
  388. RETURN_FALSE;
  389. }
  390. /* }}} */
  391. /* {{{ proto V8JS::__wakeup()
  392. */
  393. PHP_METHOD(V8Js, __wakeup)
  394. {
  395. zend_throw_exception(php_ce_v8js_exception,
  396. "You cannot serialize or unserialize V8Js instances", 0 TSRMLS_CC);
  397. RETURN_FALSE;
  398. }
  399. /* }}} */
  400. static void v8js_compile_script(zval *this_ptr, zend_string *str, zend_string *identifier, v8js_script **ret TSRMLS_DC)
  401. {
  402. v8js_script *res = NULL;
  403. V8JS_BEGIN_CTX(c, this_ptr)
  404. /* Catch JS exceptions */
  405. v8::TryCatch try_catch;
  406. /* Set script identifier */
  407. v8::Local<v8::String> sname = identifier ? V8JS_ZSTR(identifier) : V8JS_SYM("V8Js::compileString()");
  408. /* Compiles a string context independently. TODO: Add a php function which calls this and returns the result as resource which can be executed later. */
  409. v8::Local<v8::String> source = V8JS_ZSTR(str);
  410. v8::Local<v8::Script> script = v8::Script::Compile(source, sname);
  411. /* Compile errors? */
  412. if (script.IsEmpty()) {
  413. v8js_throw_script_exception(c->isolate, &try_catch TSRMLS_CC);
  414. return;
  415. }
  416. res = (v8js_script *)emalloc(sizeof(v8js_script));
  417. res->script = new v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>>(c->isolate, script);
  418. v8::String::Utf8Value _sname(sname);
  419. res->name = estrndup(ToCString(_sname), _sname.length());
  420. res->ctx = c;
  421. *ret = res;
  422. return;
  423. }
  424. static void v8js_execute_script(zval *this_ptr, v8js_script *res, long flags, long time_limit, long memory_limit, zval **return_value TSRMLS_DC)
  425. {
  426. v8js_ctx *c = Z_V8JS_CTX_OBJ_P(this_ptr);
  427. if (res->ctx != c) {
  428. zend_error(E_WARNING, "Script resource from wrong V8Js object passed");
  429. ZVAL_BOOL(*return_value, 0);
  430. return;
  431. }
  432. if (!c->in_execution && time_limit == 0) {
  433. time_limit = c->time_limit;
  434. }
  435. if (!c->in_execution && memory_limit == 0) {
  436. memory_limit = c->memory_limit;
  437. }
  438. std::function< v8::Local<v8::Value>(v8::Isolate *) > v8_call = [res](v8::Isolate *isolate) {
  439. v8::Local<v8::Script> script = v8::Local<v8::Script>::New(isolate, *res->script);
  440. return script->Run();
  441. };
  442. v8js_v8_call(c, return_value, flags, time_limit, memory_limit, v8_call TSRMLS_CC);
  443. }
  444. /* {{{ proto mixed V8Js::executeString(string script [, string identifier [, int flags]])
  445. */
  446. static PHP_METHOD(V8Js, executeString)
  447. {
  448. zend_string *str = NULL, *identifier = NULL;
  449. int str_len = 0, identifier_len = 0;
  450. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  451. v8js_script *res = NULL;
  452. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|Slll", &str, &identifier, &flags, &time_limit, &memory_limit) == FAILURE) {
  453. return;
  454. }
  455. v8js_compile_script(getThis(), str, identifier, &res TSRMLS_CC);
  456. if (!res) {
  457. RETURN_FALSE;
  458. }
  459. v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
  460. v8js_script_free(res);
  461. efree(res);
  462. }
  463. /* }}} */
  464. /* {{{ proto mixed V8Js::compileString(string script [, string identifier])
  465. */
  466. static PHP_METHOD(V8Js, compileString)
  467. {
  468. zend_string *str = NULL, *identifier = NULL;
  469. int str_len = 0, identifier_len = 0;
  470. v8js_script *res = NULL;
  471. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &str, &identifier) == FAILURE) {
  472. return;
  473. }
  474. v8js_compile_script(getThis(), str, identifier, &res TSRMLS_CC);
  475. if (res) {
  476. RETVAL_RES(zend_register_resource(res, le_v8js_script));
  477. v8js_ctx *ctx;
  478. ctx = Z_V8JS_CTX_OBJ_P(getThis());
  479. ctx->script_objects.push_back(res);
  480. }
  481. return;
  482. }
  483. /* }}} */
  484. /* {{{ proto mixed V8Js::executeScript(resource script [, int flags]])
  485. */
  486. static PHP_METHOD(V8Js, executeScript)
  487. {
  488. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  489. zval *zscript;
  490. v8js_script *res;
  491. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lll", &zscript, &flags, &time_limit, &memory_limit) == FAILURE) {
  492. return;
  493. }
  494. if((res = (v8js_script *)zend_fetch_resource(Z_RES_P(zscript), PHP_V8JS_SCRIPT_RES_NAME, le_v8js_script)) == NULL) {
  495. RETURN_FALSE;
  496. }
  497. v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
  498. }
  499. /* }}} */
  500. /* {{{ proto mixed V8Js::checkString(string script)
  501. */
  502. static PHP_METHOD(V8Js, checkString)
  503. {
  504. zend_string *str = NULL;
  505. int str_len = 0;
  506. zend_string *identifier = zend_string_init("V8Js::checkString()", 19, 0);
  507. v8js_script *res = NULL;
  508. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) {
  509. return;
  510. }
  511. v8js_compile_script(getThis(), str, identifier, &res TSRMLS_CC);
  512. zend_string_release(identifier);
  513. if (!res) {
  514. RETURN_FALSE;
  515. }
  516. v8js_script_free(res);
  517. efree(res);
  518. RETURN_TRUE;
  519. }
  520. /* }}} */
  521. /* {{{ proto mixed V8Js::getPendingException()
  522. */
  523. static PHP_METHOD(V8Js, getPendingException)
  524. {
  525. v8js_ctx *c;
  526. if (zend_parse_parameters_none() == FAILURE) {
  527. return;
  528. }
  529. c = Z_V8JS_CTX_OBJ_P(getThis());
  530. if (Z_TYPE(c->pending_exception) == IS_OBJECT) {
  531. RETURN_ZVAL(&c->pending_exception, 1, 0);
  532. }
  533. }
  534. /* }}} */
  535. /* {{{ proto void V8Js::clearPendingException()
  536. */
  537. static PHP_METHOD(V8Js, clearPendingException)
  538. {
  539. v8js_ctx *c;
  540. if (zend_parse_parameters_none() == FAILURE) {
  541. return;
  542. }
  543. c = Z_V8JS_CTX_OBJ_P(getThis());
  544. if (Z_TYPE(c->pending_exception) == IS_OBJECT) {
  545. zval_dtor(&c->pending_exception);
  546. ZVAL_NULL(&c->pending_exception);
  547. }
  548. }
  549. /* }}} */
  550. /* {{{ proto void V8Js::setModuleLoader(string module)
  551. */
  552. static PHP_METHOD(V8Js, setModuleLoader)
  553. {
  554. v8js_ctx *c;
  555. zval *callable;
  556. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callable) == FAILURE) {
  557. return;
  558. }
  559. c = Z_V8JS_CTX_OBJ_P(getThis());
  560. ZVAL_COPY(&c->module_loader, callable);
  561. }
  562. /* }}} */
  563. /* {{{ proto void V8Js::setTimeLimit(int time_limit)
  564. */
  565. static PHP_METHOD(V8Js, setTimeLimit)
  566. {
  567. v8js_ctx *c;
  568. long time_limit = 0;
  569. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &time_limit) == FAILURE) {
  570. return;
  571. }
  572. c = Z_V8JS_CTX_OBJ_P(getThis());
  573. c->time_limit = time_limit;
  574. V8JSG(timer_mutex).lock();
  575. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  576. it != V8JSG(timer_stack).end(); it ++) {
  577. if((*it)->ctx == c && !(*it)->killed) {
  578. (*it)->time_limit = time_limit;
  579. // Calculate the time point when the time limit is exceeded
  580. std::chrono::milliseconds duration(time_limit);
  581. std::chrono::time_point<std::chrono::high_resolution_clock> from = std::chrono::high_resolution_clock::now();
  582. (*it)->time_point = from + duration;
  583. }
  584. }
  585. V8JSG(timer_mutex).unlock();
  586. if (c->in_execution && time_limit && !V8JSG(timer_thread)) {
  587. /* If timer thread is not started already and we now impose a time limit
  588. * finally install the timer. */
  589. V8JSG(timer_thread) = new std::thread(v8js_timer_thread, ZEND_MODULE_GLOBALS_BULK(v8js));
  590. }
  591. }
  592. /* }}} */
  593. /* {{{ proto void V8Js::setMemoryLimit(int memory_limit)
  594. */
  595. static PHP_METHOD(V8Js, setMemoryLimit)
  596. {
  597. v8js_ctx *c;
  598. long memory_limit = 0;
  599. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &memory_limit) == FAILURE) {
  600. return;
  601. }
  602. c = Z_V8JS_CTX_OBJ_P(getThis());
  603. c->memory_limit = memory_limit;
  604. V8JSG(timer_mutex).lock();
  605. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  606. it != V8JSG(timer_stack).end(); it ++) {
  607. if((*it)->ctx == c && !(*it)->killed) {
  608. (*it)->memory_limit = memory_limit;
  609. }
  610. }
  611. V8JSG(timer_mutex).unlock();
  612. if (c->in_execution && memory_limit && !V8JSG(timer_thread)) {
  613. /* If timer thread is not started already and we now impose a memory limit
  614. * finally install the timer. */
  615. V8JSG(timer_thread) = new std::thread(v8js_timer_thread, ZEND_MODULE_GLOBALS_BULK(v8js));
  616. }
  617. }
  618. /* }}} */
  619. static void v8js_persistent_zval_ctor(zval *p) /* {{{ */
  620. {
  621. assert(Z_TYPE_P(p) == IS_STRING);
  622. Z_STR_P(p) = zend_string_dup(Z_STR_P(p), 1);
  623. }
  624. /* }}} */
  625. static void v8js_persistent_zval_dtor(zval *p) /* {{{ */
  626. {
  627. assert(Z_TYPE_P(p) == IS_STRING);
  628. free(Z_STR_P(p));
  629. }
  630. /* }}} */
  631. static void v8js_script_free(v8js_script *res)
  632. {
  633. efree(res->name);
  634. delete res->script; // does Reset()
  635. }
  636. static void v8js_script_dtor(zend_resource *rsrc) /* {{{ */
  637. {
  638. v8js_script *res = (v8js_script *)rsrc->ptr;
  639. if (res) {
  640. if(res->ctx) {
  641. std::vector<v8js_script *>::iterator it = std::find(res->ctx->script_objects.begin(), res->ctx->script_objects.end(), res);
  642. res->ctx->script_objects.erase(it);
  643. }
  644. v8js_script_free(res);
  645. efree(res);
  646. }
  647. }
  648. /* }}} */
  649. static int v8js_register_extension(zend_string *name, zend_string *source, zval *deps_arr, zend_bool auto_enable TSRMLS_DC) /* {{{ */
  650. {
  651. v8js_jsext *jsext = NULL;
  652. #ifdef ZTS
  653. v8js_process_globals.lock.lock();
  654. #endif
  655. if (!v8js_process_globals.extensions) {
  656. v8js_process_globals.extensions = (HashTable *) malloc(sizeof(HashTable));
  657. zend_hash_init(v8js_process_globals.extensions, 1, NULL, v8js_jsext_dtor, 1);
  658. } else if (zend_hash_exists(v8js_process_globals.extensions, name)) {
  659. #ifdef ZTS
  660. v8js_process_globals.lock.unlock();
  661. #endif
  662. return FAILURE;
  663. }
  664. jsext = (v8js_jsext *) calloc(1, sizeof(v8js_jsext));
  665. if (deps_arr) {
  666. jsext->deps_count = zend_hash_num_elements(Z_ARRVAL_P(deps_arr));
  667. if (v8js_create_ext_strarr(&jsext->deps, jsext->deps_count, Z_ARRVAL_P(deps_arr)) == FAILURE) {
  668. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid dependency array passed");
  669. v8js_jsext_free_storage(jsext);
  670. #ifdef ZTS
  671. v8js_process_globals.lock.unlock();
  672. #endif
  673. return FAILURE;
  674. }
  675. }
  676. jsext->auto_enable = auto_enable;
  677. jsext->name = zend_string_dup(name, 1);
  678. jsext->source = zend_string_dup(source, 1);
  679. if (jsext->deps) {
  680. jsext->deps_ht = (HashTable *) malloc(sizeof(HashTable));
  681. zend_hash_init(jsext->deps_ht, jsext->deps_count, NULL, v8js_persistent_zval_dtor, 1);
  682. zend_hash_copy(jsext->deps_ht, Z_ARRVAL_P(deps_arr), v8js_persistent_zval_ctor);
  683. }
  684. jsext->extension = new v8::Extension(ZSTR_VAL(jsext->name), ZSTR_VAL(jsext->source), jsext->deps_count, jsext->deps);
  685. if (!zend_hash_add_ptr(v8js_process_globals.extensions, jsext->name, jsext)) {
  686. v8js_jsext_free_storage(jsext);
  687. #ifdef ZTS
  688. v8js_process_globals.lock.unlock();
  689. #endif
  690. return FAILURE;
  691. }
  692. #ifdef ZTS
  693. v8js_process_globals.lock.unlock();
  694. #endif
  695. jsext->extension->set_auto_enable(auto_enable ? true : false);
  696. v8::RegisterExtension(jsext->extension);
  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. zend_string *ext_name, *script;
  705. zval *deps_arr = NULL;
  706. zend_bool auto_enable = 0;
  707. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ab", &ext_name, &script, &deps_arr, &auto_enable) == FAILURE) {
  708. return;
  709. }
  710. if (!ZSTR_LEN(ext_name)) {
  711. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Extension name cannot be empty");
  712. } else if (!ZSTR_LEN(script)) {
  713. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Script cannot be empty");
  714. } else if (v8js_register_extension(ext_name, script, deps_arr, auto_enable TSRMLS_CC) == SUCCESS) {
  715. RETURN_TRUE;
  716. }
  717. RETURN_FALSE;
  718. }
  719. /* }}} */
  720. /* ## Static methods ## */
  721. /* {{{ proto array V8Js::getExtensions()
  722. */
  723. static PHP_METHOD(V8Js, getExtensions)
  724. {
  725. v8js_jsext *jsext;
  726. ulong index;
  727. zend_string *key;
  728. zval *val, ext;
  729. if (zend_parse_parameters_none() == FAILURE) {
  730. return;
  731. }
  732. array_init(return_value);
  733. #ifdef ZTS
  734. v8js_process_globals.lock.lock();
  735. #endif
  736. if (v8js_process_globals.extensions) {
  737. ZEND_HASH_FOREACH_KEY_VAL(v8js_process_globals.extensions, index, key, val) {
  738. if (key) {
  739. jsext = (v8js_jsext *) Z_PTR_P(val);
  740. array_init(&ext);
  741. add_assoc_bool_ex(&ext, ZEND_STRL("auto_enable"), jsext->auto_enable);
  742. if (jsext->deps_ht) {
  743. zval deps_arr;
  744. array_init(&deps_arr);
  745. zend_hash_copy(Z_ARRVAL_P(&deps_arr), jsext->deps_ht, (copy_ctor_func_t) zval_add_ref);
  746. add_assoc_zval_ex(&ext, ZEND_STRL("deps"), &deps_arr);
  747. }
  748. add_assoc_zval_ex(return_value, ZSTR_VAL(key), ZSTR_LEN(key), &ext);
  749. }
  750. } ZEND_HASH_FOREACH_END();
  751. }
  752. #ifdef ZTS
  753. v8js_process_globals.lock.unlock();
  754. #endif
  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, void **cache_slot 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, Z_STR_P(member), 1 TSRMLS_CC);
  846. if(!property_info ||
  847. (property_info != ZEND_WRONG_PROPERTY_INFO &&
  848. property_info->flags & ZEND_ACC_PUBLIC)) {
  849. /* Global PHP JS object */
  850. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  851. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
  852. /* Write value to PHP JS object */
  853. jsobj->ForceSet(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)), zval_to_v8js(value, isolate TSRMLS_CC), v8::ReadOnly);
  854. }
  855. /* Write value to PHP object */
  856. std_object_handlers.write_property(object, member, value, NULL);
  857. }
  858. /* }}} */
  859. static void v8js_unset_property(zval *object, zval *member, void **cache_slot TSRMLS_DC) /* {{{ */
  860. {
  861. V8JS_BEGIN_CTX(c, object)
  862. /* Global PHP JS object */
  863. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  864. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
  865. /* Delete value from PHP JS object */
  866. jsobj->Delete(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)));
  867. /* Unset from PHP object */
  868. std_object_handlers.unset_property(object, member, NULL);
  869. }
  870. /* }}} */
  871. PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
  872. {
  873. zend_class_entry ce;
  874. /* V8Js Class */
  875. INIT_CLASS_ENTRY(ce, "V8Js", v8js_methods);
  876. php_ce_v8js = zend_register_internal_class(&ce TSRMLS_CC);
  877. php_ce_v8js->create_object = v8js_new;
  878. /* V8Js handlers */
  879. memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  880. v8js_object_handlers.clone_obj = NULL;
  881. v8js_object_handlers.write_property = v8js_write_property;
  882. v8js_object_handlers.unset_property = v8js_unset_property;
  883. /* V8Js Class Constants */
  884. zend_declare_class_constant_string(php_ce_v8js, ZEND_STRL("V8_VERSION"), PHP_V8_VERSION TSRMLS_CC);
  885. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_NONE"), V8JS_FLAG_NONE TSRMLS_CC);
  886. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_FORCE_ARRAY"), V8JS_FLAG_FORCE_ARRAY TSRMLS_CC);
  887. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_PROPAGATE_PHP_EXCEPTIONS"), V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS TSRMLS_CC);
  888. #ifdef ENABLE_DEBUGGER_SUPPORT
  889. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("DEBUG_AUTO_BREAK_NEVER"), V8JS_DEBUG_AUTO_BREAK_NEVER TSRMLS_CC);
  890. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("DEBUG_AUTO_BREAK_ONCE"), V8JS_DEBUG_AUTO_BREAK_ONCE TSRMLS_CC);
  891. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("DEBUG_AUTO_BREAK_ALWAYS"), V8JS_DEBUG_AUTO_BREAK_ALWAYS TSRMLS_CC);
  892. #endif
  893. le_v8js_script = zend_register_list_destructors_ex(v8js_script_dtor, NULL, PHP_V8JS_SCRIPT_RES_NAME, module_number);
  894. #if PHP_V8_API_VERSION >= 4004010 && PHP_V8_API_VERSION < 4004044
  895. static ArrayBufferAllocator array_buffer_allocator;
  896. v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
  897. #endif
  898. return SUCCESS;
  899. } /* }}} */
  900. /*
  901. * Local variables:
  902. * tab-width: 4
  903. * c-basic-offset: 4
  904. * End:
  905. * vim600: noet sw=4 ts=4 fdm=marker
  906. * vim<600: noet sw=4 ts=4
  907. */