v8js_class.cc 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  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. #include <functional>
  18. #include <algorithm>
  19. #include "php_v8js_macros.h"
  20. #include "v8js_v8.h"
  21. #include "v8js_exceptions.h"
  22. #include "v8js_v8object_class.h"
  23. #include "v8js_timer.h"
  24. extern "C" {
  25. #include "php.h"
  26. #include "ext/date/php_date.h"
  27. #include "ext/standard/php_string.h"
  28. #include "zend_interfaces.h"
  29. #include "zend_closures.h"
  30. #include "ext/spl/spl_exceptions.h"
  31. #include "zend_exceptions.h"
  32. }
  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. zend_string *name;
  54. zend_string *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(zend_object *object TSRMLS_DC) /* {{{ */
  70. {
  71. v8js_ctx *c = v8js_ctx_fetch_object(object);
  72. zend_object_std_dtor(&c->std TSRMLS_CC);
  73. zval_dtor(&c->pending_exception);
  74. zval_dtor(&c->module_normaliser);
  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. if (location) {
  257. zend_error(E_WARNING, "Fatal V8 error in %s: %s", location, message);
  258. } else {
  259. zend_error(E_WARNING, "Fatal V8 error: %s", message);
  260. }
  261. }
  262. /* }}} */
  263. /* {{{ proto void V8Js::__construct([string object_name [, array variables [, array extensions [, bool report_uncaught_exceptions]]])
  264. __construct for V8Js */
  265. static PHP_METHOD(V8Js, __construct)
  266. {
  267. zend_string *object_name = NULL;
  268. zend_bool report_uncaught = 1;
  269. zval *vars_arr = NULL, *exts_arr = NULL;
  270. const char **exts = NULL;
  271. int exts_count = 0;
  272. v8js_ctx *c = Z_V8JS_CTX_OBJ_P(getThis())
  273. if (!c->context.IsEmpty()) {
  274. /* called __construct() twice, bail out */
  275. return;
  276. }
  277. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|Saab", &object_name, &vars_arr, &exts_arr, &report_uncaught) == FAILURE) {
  278. return;
  279. }
  280. /* Initialize V8 */
  281. v8js_v8_init(TSRMLS_C);
  282. /* Throw PHP exception if uncaught exceptions exist */
  283. c->report_uncaught = report_uncaught;
  284. ZVAL_NULL(&c->pending_exception);
  285. c->in_execution = 0;
  286. #if PHP_V8_API_VERSION >= 4004044
  287. static ArrayBufferAllocator array_buffer_allocator;
  288. static v8::Isolate::CreateParams create_params;
  289. create_params.array_buffer_allocator = &array_buffer_allocator;
  290. c->isolate = v8::Isolate::New(create_params);
  291. #else
  292. c->isolate = v8::Isolate::New();
  293. #endif
  294. c->isolate->SetData(0, c);
  295. c->time_limit = 0;
  296. c->time_limit_hit = false;
  297. c->memory_limit = 0;
  298. c->memory_limit_hit = false;
  299. ZVAL_NULL(&c->module_normaliser);
  300. ZVAL_NULL(&c->module_loader);
  301. /* Include extensions used by this context */
  302. /* Note: Extensions registered with auto_enable do not need to be added separately like this. */
  303. if (exts_arr)
  304. {
  305. exts_count = zend_hash_num_elements(Z_ARRVAL_P(exts_arr));
  306. if (v8js_create_ext_strarr(&exts, exts_count, Z_ARRVAL_P(exts_arr)) == FAILURE) {
  307. zend_throw_exception(php_ce_v8js_exception,
  308. "Invalid extensions array passed", 0);
  309. return;
  310. }
  311. }
  312. /* Declare configuration for extensions */
  313. v8::ExtensionConfiguration extension_conf(exts_count, exts);
  314. // Isolate execution
  315. v8::Isolate *isolate = c->isolate;
  316. v8::Locker locker(isolate);
  317. v8::Isolate::Scope isolate_scope(isolate);
  318. /* Handle scope */
  319. v8::HandleScope handle_scope(isolate);
  320. /* Redirect fatal errors to PHP error handler */
  321. // This needs to be done within the context isolate
  322. v8::V8::SetFatalErrorHandler(v8js_fatal_error_handler);
  323. /* Create global template for global object */
  324. // Now we are using multiple isolates this needs to be created for every context
  325. v8::Local<v8::FunctionTemplate> tpl = v8::FunctionTemplate::New(c->isolate, 0);
  326. tpl->SetClassName(V8JS_SYM("V8Js"));
  327. c->global_template.Reset(isolate, tpl);
  328. /* Register builtin methods */
  329. v8js_register_methods(tpl->InstanceTemplate(), c);
  330. /* Create context */
  331. v8::Local<v8::Context> context = v8::Context::New(isolate, &extension_conf, tpl->InstanceTemplate());
  332. if (exts) {
  333. v8js_free_ext_strarr(exts, exts_count);
  334. }
  335. /* If extensions have errors, context will be empty. (NOTE: This is V8 stuff, they expect the passed sources to compile :) */
  336. if (context.IsEmpty()) {
  337. zend_throw_exception(php_ce_v8js_exception,
  338. "Failed to create V8 context. "
  339. "Check that registered extensions do not have errors.", 0);
  340. return;
  341. }
  342. context->SetAlignedPointerInEmbedderData(1, c);
  343. c->context.Reset(isolate, context);
  344. /* Enter context */
  345. v8::Context::Scope context_scope(context);
  346. /* Create the PHP container object's function template */
  347. v8::Local<v8::FunctionTemplate> php_obj_t = v8::FunctionTemplate::New(isolate, 0);
  348. /* Set class name for PHP object */
  349. zend_class_entry *ce = Z_OBJCE_P(getThis());
  350. php_obj_t->SetClassName(V8JS_SYML(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name)));
  351. /* Register Get accessor for passed variables */
  352. if (vars_arr && zend_hash_num_elements(Z_ARRVAL_P(vars_arr)) > 0) {
  353. v8js_register_accessors(&c->accessor_list, php_obj_t, vars_arr, isolate TSRMLS_CC);
  354. }
  355. /* Set name for the PHP JS object */
  356. v8::Local<v8::String> object_name_js = (object_name && ZSTR_LEN(object_name))
  357. ? V8JS_ZSYM(object_name)
  358. : V8JS_SYM("PHP");
  359. c->object_name.Reset(isolate, object_name_js);
  360. /* Add the PHP object into global object */
  361. v8::Local<v8::Object> php_obj = php_obj_t->InstanceTemplate()->NewInstance();
  362. V8JS_GLOBAL(isolate)->ForceSet(object_name_js, php_obj, v8::ReadOnly);
  363. /* Export public property values */
  364. HashTable *properties = zend_std_get_properties(getThis() TSRMLS_CC);
  365. zval *value;
  366. zend_string *member;
  367. ZEND_HASH_FOREACH_STR_KEY(properties, member) {
  368. zend_property_info *property_info = zend_get_property_info(c->std.ce, member, 1 TSRMLS_CC);
  369. if(property_info &&
  370. property_info != ZEND_WRONG_PROPERTY_INFO &&
  371. property_info->flags & ZEND_ACC_PUBLIC) {
  372. /* Write value to PHP JS object */
  373. value = OBJ_PROP(Z_OBJ_P(getThis()), property_info->offset);
  374. php_obj->ForceSet(V8JS_ZSYM(member), zval_to_v8js(value, isolate TSRMLS_CC), v8::ReadOnly);
  375. }
  376. } ZEND_HASH_FOREACH_END();
  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, zend_string *str, zend_string *identifier, 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 ? V8JS_ZSTR(identifier) : 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_ZSTR(str);
  407. v8::Local<v8::Script> script = v8::Script::Compile(source, sname);
  408. /* Compile errors? */
  409. if (script.IsEmpty()) {
  410. v8js_throw_script_exception(c->isolate, &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 = Z_V8JS_CTX_OBJ_P(this_ptr);
  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 relies on its dtor to be executed, otherwise it leaks
  436. * some memory on bailout. */
  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. if(V8JSG(fatal_error_abort)) {
  445. /* Check for fatal error marker possibly set by v8js_error_handler; just
  446. * rethrow the error since we're now out of V8. */
  447. zend_bailout();
  448. }
  449. }
  450. /* {{{ proto mixed V8Js::executeString(string script [, string identifier [, int flags]])
  451. */
  452. static PHP_METHOD(V8Js, executeString)
  453. {
  454. zend_string *str = NULL, *identifier = NULL;
  455. int str_len = 0, identifier_len = 0;
  456. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  457. v8js_script *res = NULL;
  458. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|Slll", &str, &identifier, &flags, &time_limit, &memory_limit) == FAILURE) {
  459. return;
  460. }
  461. v8js_compile_script(getThis(), str, identifier, &res TSRMLS_CC);
  462. if (!res) {
  463. RETURN_FALSE;
  464. }
  465. zend_try {
  466. v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
  467. v8js_script_free(res);
  468. }
  469. zend_catch {
  470. v8js_script_free(res);
  471. zend_bailout();
  472. }
  473. zend_end_try()
  474. efree(res);
  475. }
  476. /* }}} */
  477. /* {{{ proto mixed V8Js::compileString(string script [, string identifier])
  478. */
  479. static PHP_METHOD(V8Js, compileString)
  480. {
  481. zend_string *str = NULL, *identifier = NULL;
  482. int str_len = 0, identifier_len = 0;
  483. v8js_script *res = NULL;
  484. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &str, &identifier) == FAILURE) {
  485. return;
  486. }
  487. v8js_compile_script(getThis(), str, identifier, &res TSRMLS_CC);
  488. if (res) {
  489. RETVAL_RES(zend_register_resource(res, le_v8js_script));
  490. v8js_ctx *ctx;
  491. ctx = Z_V8JS_CTX_OBJ_P(getThis());
  492. ctx->script_objects.push_back(res);
  493. }
  494. return;
  495. }
  496. /* }}} */
  497. /* {{{ proto mixed V8Js::executeScript(resource script [, int flags]])
  498. */
  499. static PHP_METHOD(V8Js, executeScript)
  500. {
  501. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  502. zval *zscript;
  503. v8js_script *res;
  504. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lll", &zscript, &flags, &time_limit, &memory_limit) == FAILURE) {
  505. return;
  506. }
  507. if((res = (v8js_script *)zend_fetch_resource(Z_RES_P(zscript), PHP_V8JS_SCRIPT_RES_NAME, le_v8js_script)) == NULL) {
  508. RETURN_FALSE;
  509. }
  510. v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
  511. }
  512. /* }}} */
  513. /* {{{ proto mixed V8Js::checkString(string script)
  514. */
  515. static PHP_METHOD(V8Js, checkString)
  516. {
  517. zend_string *str = NULL;
  518. int str_len = 0;
  519. zend_string *identifier = zend_string_init("V8Js::checkString()", 19, 0);
  520. v8js_script *res = NULL;
  521. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) {
  522. return;
  523. }
  524. v8js_compile_script(getThis(), str, identifier, &res TSRMLS_CC);
  525. zend_string_release(identifier);
  526. if (!res) {
  527. RETURN_FALSE;
  528. }
  529. v8js_script_free(res);
  530. efree(res);
  531. RETURN_TRUE;
  532. }
  533. /* }}} */
  534. /* {{{ proto mixed V8Js::getPendingException()
  535. */
  536. static PHP_METHOD(V8Js, getPendingException)
  537. {
  538. v8js_ctx *c;
  539. if (zend_parse_parameters_none() == FAILURE) {
  540. return;
  541. }
  542. c = Z_V8JS_CTX_OBJ_P(getThis());
  543. if (Z_TYPE(c->pending_exception) == IS_OBJECT) {
  544. RETURN_ZVAL(&c->pending_exception, 1, 0);
  545. }
  546. }
  547. /* }}} */
  548. /* {{{ proto void V8Js::clearPendingException()
  549. */
  550. static PHP_METHOD(V8Js, clearPendingException)
  551. {
  552. v8js_ctx *c;
  553. if (zend_parse_parameters_none() == FAILURE) {
  554. return;
  555. }
  556. c = Z_V8JS_CTX_OBJ_P(getThis());
  557. if (Z_TYPE(c->pending_exception) == IS_OBJECT) {
  558. zval_dtor(&c->pending_exception);
  559. ZVAL_NULL(&c->pending_exception);
  560. }
  561. }
  562. /* }}} */
  563. /* {{{ proto void V8Js::setModuleNormaliser(string base, string module_id)
  564. */
  565. static PHP_METHOD(V8Js, setModuleNormaliser)
  566. {
  567. v8js_ctx *c;
  568. zval *callable;
  569. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callable) == FAILURE) {
  570. return;
  571. }
  572. c = Z_V8JS_CTX_OBJ_P(getThis());
  573. ZVAL_COPY(&c->module_normaliser, callable);
  574. }
  575. /* }}} */
  576. /* {{{ proto void V8Js::setModuleLoader(string module)
  577. */
  578. static PHP_METHOD(V8Js, setModuleLoader)
  579. {
  580. v8js_ctx *c;
  581. zval *callable;
  582. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callable) == FAILURE) {
  583. return;
  584. }
  585. c = Z_V8JS_CTX_OBJ_P(getThis());
  586. ZVAL_COPY(&c->module_loader, callable);
  587. }
  588. /* }}} */
  589. /* {{{ proto void V8Js::setTimeLimit(int time_limit)
  590. */
  591. static PHP_METHOD(V8Js, setTimeLimit)
  592. {
  593. v8js_ctx *c;
  594. long time_limit = 0;
  595. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &time_limit) == FAILURE) {
  596. return;
  597. }
  598. c = Z_V8JS_CTX_OBJ_P(getThis());
  599. c->time_limit = time_limit;
  600. V8JSG(timer_mutex).lock();
  601. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  602. it != V8JSG(timer_stack).end(); it ++) {
  603. if((*it)->ctx == c && !(*it)->killed) {
  604. (*it)->time_limit = time_limit;
  605. // Calculate the time point when the time limit is exceeded
  606. std::chrono::milliseconds duration(time_limit);
  607. std::chrono::time_point<std::chrono::high_resolution_clock> from = std::chrono::high_resolution_clock::now();
  608. (*it)->time_point = from + duration;
  609. }
  610. }
  611. V8JSG(timer_mutex).unlock();
  612. if (c->in_execution && time_limit && !V8JSG(timer_thread)) {
  613. /* If timer thread is not started already and we now impose a time 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. /* {{{ proto void V8Js::setMemoryLimit(int memory_limit)
  620. */
  621. static PHP_METHOD(V8Js, setMemoryLimit)
  622. {
  623. v8js_ctx *c;
  624. long memory_limit = 0;
  625. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &memory_limit) == FAILURE) {
  626. return;
  627. }
  628. c = Z_V8JS_CTX_OBJ_P(getThis());
  629. c->memory_limit = memory_limit;
  630. V8JSG(timer_mutex).lock();
  631. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  632. it != V8JSG(timer_stack).end(); it ++) {
  633. if((*it)->ctx == c && !(*it)->killed) {
  634. (*it)->memory_limit = memory_limit;
  635. }
  636. }
  637. V8JSG(timer_mutex).unlock();
  638. if (c->in_execution && memory_limit && !V8JSG(timer_thread)) {
  639. /* If timer thread is not started already and we now impose a memory limit
  640. * finally install the timer. */
  641. V8JSG(timer_thread) = new std::thread(v8js_timer_thread, ZEND_MODULE_GLOBALS_BULK(v8js));
  642. }
  643. }
  644. /* }}} */
  645. static void v8js_persistent_zval_ctor(zval *p) /* {{{ */
  646. {
  647. assert(Z_TYPE_P(p) == IS_STRING);
  648. Z_STR_P(p) = zend_string_dup(Z_STR_P(p), 1);
  649. }
  650. /* }}} */
  651. static void v8js_persistent_zval_dtor(zval *p) /* {{{ */
  652. {
  653. assert(Z_TYPE_P(p) == IS_STRING);
  654. free(Z_STR_P(p));
  655. }
  656. /* }}} */
  657. static void v8js_script_free(v8js_script *res)
  658. {
  659. efree(res->name);
  660. delete res->script; // does Reset()
  661. }
  662. static void v8js_script_dtor(zend_resource *rsrc) /* {{{ */
  663. {
  664. v8js_script *res = (v8js_script *)rsrc->ptr;
  665. if (res) {
  666. if(res->ctx) {
  667. std::vector<v8js_script *>::iterator it = std::find(res->ctx->script_objects.begin(), res->ctx->script_objects.end(), res);
  668. res->ctx->script_objects.erase(it);
  669. }
  670. v8js_script_free(res);
  671. efree(res);
  672. }
  673. }
  674. /* }}} */
  675. static int v8js_register_extension(zend_string *name, zend_string *source, zval *deps_arr, zend_bool auto_enable TSRMLS_DC) /* {{{ */
  676. {
  677. v8js_jsext *jsext = NULL;
  678. #ifdef ZTS
  679. v8js_process_globals.lock.lock();
  680. #endif
  681. if (!v8js_process_globals.extensions) {
  682. v8js_process_globals.extensions = (HashTable *) malloc(sizeof(HashTable));
  683. zend_hash_init(v8js_process_globals.extensions, 1, NULL, v8js_jsext_dtor, 1);
  684. } else if (zend_hash_exists(v8js_process_globals.extensions, name)) {
  685. #ifdef ZTS
  686. v8js_process_globals.lock.unlock();
  687. #endif
  688. return FAILURE;
  689. }
  690. jsext = (v8js_jsext *) calloc(1, sizeof(v8js_jsext));
  691. if (deps_arr) {
  692. jsext->deps_count = zend_hash_num_elements(Z_ARRVAL_P(deps_arr));
  693. if (v8js_create_ext_strarr(&jsext->deps, jsext->deps_count, Z_ARRVAL_P(deps_arr)) == FAILURE) {
  694. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid dependency array passed");
  695. v8js_jsext_free_storage(jsext);
  696. #ifdef ZTS
  697. v8js_process_globals.lock.unlock();
  698. #endif
  699. return FAILURE;
  700. }
  701. }
  702. jsext->auto_enable = auto_enable;
  703. jsext->name = zend_string_dup(name, 1);
  704. jsext->source = zend_string_dup(source, 1);
  705. if (jsext->deps) {
  706. jsext->deps_ht = (HashTable *) malloc(sizeof(HashTable));
  707. zend_hash_init(jsext->deps_ht, jsext->deps_count, NULL, v8js_persistent_zval_dtor, 1);
  708. zend_hash_copy(jsext->deps_ht, Z_ARRVAL_P(deps_arr), v8js_persistent_zval_ctor);
  709. }
  710. jsext->extension = new v8::Extension(ZSTR_VAL(jsext->name), ZSTR_VAL(jsext->source), jsext->deps_count, jsext->deps);
  711. if (!zend_hash_add_ptr(v8js_process_globals.extensions, jsext->name, jsext)) {
  712. v8js_jsext_free_storage(jsext);
  713. #ifdef ZTS
  714. v8js_process_globals.lock.unlock();
  715. #endif
  716. return FAILURE;
  717. }
  718. #ifdef ZTS
  719. v8js_process_globals.lock.unlock();
  720. #endif
  721. jsext->extension->set_auto_enable(auto_enable ? true : false);
  722. v8::RegisterExtension(jsext->extension);
  723. return SUCCESS;
  724. }
  725. /* }}} */
  726. /* {{{ proto bool V8Js::registerExtension(string ext_name, string script [, array deps [, bool auto_enable]])
  727. */
  728. static PHP_METHOD(V8Js, registerExtension)
  729. {
  730. zend_string *ext_name, *script;
  731. zval *deps_arr = NULL;
  732. zend_bool auto_enable = 0;
  733. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ab", &ext_name, &script, &deps_arr, &auto_enable) == FAILURE) {
  734. return;
  735. }
  736. if (!ZSTR_LEN(ext_name)) {
  737. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Extension name cannot be empty");
  738. } else if (!ZSTR_LEN(script)) {
  739. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Script cannot be empty");
  740. } else if (v8js_register_extension(ext_name, script, deps_arr, auto_enable TSRMLS_CC) == SUCCESS) {
  741. RETURN_TRUE;
  742. }
  743. RETURN_FALSE;
  744. }
  745. /* }}} */
  746. /* ## Static methods ## */
  747. /* {{{ proto array V8Js::getExtensions()
  748. */
  749. static PHP_METHOD(V8Js, getExtensions)
  750. {
  751. v8js_jsext *jsext;
  752. ulong index;
  753. zend_string *key;
  754. zval *val, ext;
  755. if (zend_parse_parameters_none() == FAILURE) {
  756. return;
  757. }
  758. array_init(return_value);
  759. #ifdef ZTS
  760. v8js_process_globals.lock.lock();
  761. #endif
  762. if (v8js_process_globals.extensions) {
  763. ZEND_HASH_FOREACH_KEY_VAL(v8js_process_globals.extensions, index, key, val) {
  764. if (key) {
  765. jsext = (v8js_jsext *) Z_PTR_P(val);
  766. array_init(&ext);
  767. add_assoc_bool_ex(&ext, ZEND_STRL("auto_enable"), jsext->auto_enable);
  768. if (jsext->deps_ht) {
  769. zval deps_arr;
  770. array_init(&deps_arr);
  771. zend_hash_copy(Z_ARRVAL_P(&deps_arr), jsext->deps_ht, (copy_ctor_func_t) zval_add_ref);
  772. add_assoc_zval_ex(&ext, ZEND_STRL("deps"), &deps_arr);
  773. }
  774. add_assoc_zval_ex(return_value, ZSTR_VAL(key), ZSTR_LEN(key), &ext);
  775. }
  776. } ZEND_HASH_FOREACH_END();
  777. }
  778. #ifdef ZTS
  779. v8js_process_globals.lock.unlock();
  780. #endif
  781. }
  782. /* }}} */
  783. /* {{{ arginfo */
  784. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_construct, 0, 0, 0)
  785. ZEND_ARG_INFO(0, object_name)
  786. ZEND_ARG_INFO(0, variables)
  787. ZEND_ARG_INFO(0, extensions)
  788. ZEND_ARG_INFO(0, report_uncaught_exceptions)
  789. ZEND_END_ARG_INFO()
  790. ZEND_BEGIN_ARG_INFO(arginfo_v8js_sleep, 0)
  791. ZEND_END_ARG_INFO()
  792. ZEND_BEGIN_ARG_INFO(arginfo_v8js_wakeup, 0)
  793. ZEND_END_ARG_INFO()
  794. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_executestring, 0, 0, 1)
  795. ZEND_ARG_INFO(0, script)
  796. ZEND_ARG_INFO(0, identifier)
  797. ZEND_ARG_INFO(0, flags)
  798. ZEND_ARG_INFO(0, time_limit)
  799. ZEND_ARG_INFO(0, memory_limit)
  800. ZEND_END_ARG_INFO()
  801. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_compilestring, 0, 0, 1)
  802. ZEND_ARG_INFO(0, script)
  803. ZEND_ARG_INFO(0, identifier)
  804. ZEND_END_ARG_INFO()
  805. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_executescript, 0, 0, 1)
  806. ZEND_ARG_INFO(0, script)
  807. ZEND_ARG_INFO(0, flags)
  808. ZEND_ARG_INFO(0, time_limit)
  809. ZEND_ARG_INFO(0, memory_limit)
  810. ZEND_END_ARG_INFO()
  811. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_checkstring, 0, 0, 1)
  812. ZEND_ARG_INFO(0, script)
  813. ZEND_END_ARG_INFO()
  814. ZEND_BEGIN_ARG_INFO(arginfo_v8js_getpendingexception, 0)
  815. ZEND_END_ARG_INFO()
  816. ZEND_BEGIN_ARG_INFO(arginfo_v8js_clearpendingexception, 0)
  817. ZEND_END_ARG_INFO()
  818. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmodulenormaliser, 0, 0, 2)
  819. ZEND_ARG_INFO(0, base)
  820. ZEND_ARG_INFO(0, module_id)
  821. ZEND_END_ARG_INFO()
  822. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmoduleloader, 0, 0, 1)
  823. ZEND_ARG_INFO(0, callable)
  824. ZEND_END_ARG_INFO()
  825. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_registerextension, 0, 0, 2)
  826. ZEND_ARG_INFO(0, extension_name)
  827. ZEND_ARG_INFO(0, script)
  828. ZEND_ARG_INFO(0, dependencies)
  829. ZEND_ARG_INFO(0, auto_enable)
  830. ZEND_END_ARG_INFO()
  831. ZEND_BEGIN_ARG_INFO(arginfo_v8js_getextensions, 0)
  832. ZEND_END_ARG_INFO()
  833. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_settimelimit, 0, 0, 1)
  834. ZEND_ARG_INFO(0, time_limit)
  835. ZEND_END_ARG_INFO()
  836. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmemorylimit, 0, 0, 1)
  837. ZEND_ARG_INFO(0, memory_limit)
  838. ZEND_END_ARG_INFO()
  839. static const zend_function_entry v8js_methods[] = { /* {{{ */
  840. PHP_ME(V8Js, __construct, arginfo_v8js_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
  841. PHP_ME(V8Js, __sleep, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
  842. PHP_ME(V8Js, __wakeup, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
  843. PHP_ME(V8Js, executeString, arginfo_v8js_executestring, ZEND_ACC_PUBLIC)
  844. PHP_ME(V8Js, compileString, arginfo_v8js_compilestring, ZEND_ACC_PUBLIC)
  845. PHP_ME(V8Js, executeScript, arginfo_v8js_executescript, ZEND_ACC_PUBLIC)
  846. PHP_ME(V8Js, checkString, arginfo_v8js_checkstring, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
  847. PHP_ME(V8Js, getPendingException, arginfo_v8js_getpendingexception, ZEND_ACC_PUBLIC)
  848. PHP_ME(V8Js, clearPendingException, arginfo_v8js_clearpendingexception, ZEND_ACC_PUBLIC)
  849. PHP_ME(V8Js, setModuleNormaliser, arginfo_v8js_setmodulenormaliser, ZEND_ACC_PUBLIC)
  850. PHP_ME(V8Js, setModuleLoader, arginfo_v8js_setmoduleloader, ZEND_ACC_PUBLIC)
  851. PHP_ME(V8Js, registerExtension, arginfo_v8js_registerextension, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  852. PHP_ME(V8Js, getExtensions, arginfo_v8js_getextensions, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  853. PHP_ME(V8Js, setTimeLimit, arginfo_v8js_settimelimit, ZEND_ACC_PUBLIC)
  854. PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC)
  855. {NULL, NULL, NULL}
  856. };
  857. /* }}} */
  858. /* V8Js object handlers */
  859. static void v8js_write_property(zval *object, zval *member, zval *value, void **cache_slot TSRMLS_DC) /* {{{ */
  860. {
  861. V8JS_BEGIN_CTX(c, object)
  862. /* Check whether member is public, if so, export to V8. */
  863. zend_property_info *property_info = zend_get_property_info(c->std.ce, Z_STR_P(member), 1 TSRMLS_CC);
  864. if(!property_info ||
  865. (property_info != ZEND_WRONG_PROPERTY_INFO &&
  866. property_info->flags & ZEND_ACC_PUBLIC)) {
  867. /* Global PHP JS object */
  868. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  869. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
  870. /* Write value to PHP JS object */
  871. jsobj->ForceSet(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)), zval_to_v8js(value, isolate TSRMLS_CC), v8::ReadOnly);
  872. }
  873. /* Write value to PHP object */
  874. std_object_handlers.write_property(object, member, value, NULL);
  875. }
  876. /* }}} */
  877. static void v8js_unset_property(zval *object, zval *member, void **cache_slot TSRMLS_DC) /* {{{ */
  878. {
  879. V8JS_BEGIN_CTX(c, object)
  880. /* Global PHP JS object */
  881. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  882. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
  883. /* Delete value from PHP JS object */
  884. jsobj->Delete(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)));
  885. /* Unset from PHP object */
  886. std_object_handlers.unset_property(object, member, NULL);
  887. }
  888. /* }}} */
  889. PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
  890. {
  891. zend_class_entry ce;
  892. /* V8Js Class */
  893. INIT_CLASS_ENTRY(ce, "V8Js", v8js_methods);
  894. php_ce_v8js = zend_register_internal_class(&ce TSRMLS_CC);
  895. php_ce_v8js->create_object = v8js_new;
  896. /* V8Js handlers */
  897. memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  898. v8js_object_handlers.clone_obj = NULL;
  899. v8js_object_handlers.write_property = v8js_write_property;
  900. v8js_object_handlers.unset_property = v8js_unset_property;
  901. /* V8Js Class Constants */
  902. zend_declare_class_constant_string(php_ce_v8js, ZEND_STRL("V8_VERSION"), PHP_V8_VERSION TSRMLS_CC);
  903. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_NONE"), V8JS_FLAG_NONE TSRMLS_CC);
  904. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_FORCE_ARRAY"), V8JS_FLAG_FORCE_ARRAY TSRMLS_CC);
  905. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_PROPAGATE_PHP_EXCEPTIONS"), V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS TSRMLS_CC);
  906. le_v8js_script = zend_register_list_destructors_ex(v8js_script_dtor, NULL, PHP_V8JS_SCRIPT_RES_NAME, module_number);
  907. #if PHP_V8_API_VERSION >= 4004010 && PHP_V8_API_VERSION < 4004044
  908. static ArrayBufferAllocator array_buffer_allocator;
  909. v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
  910. #endif
  911. return SUCCESS;
  912. } /* }}} */
  913. /*
  914. * Local variables:
  915. * tab-width: 4
  916. * c-basic-offset: 4
  917. * End:
  918. * vim600: noet sw=4 ts=4 fdm=marker
  919. * vim<600: noet sw=4 ts=4
  920. */