v8js_class.cc 32 KB

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