v8js_class.cc 32 KB

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