v8js_class.cc 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2015 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | http://www.opensource.org/licenses/mit-license.php MIT License |
  8. +----------------------------------------------------------------------+
  9. | Author: Jani Taskinen <[email protected]> |
  10. | Author: Patrick Reilly <[email protected]> |
  11. | Author: Stefan Siegl <[email protected]> |
  12. +----------------------------------------------------------------------+
  13. */
  14. #ifdef HAVE_CONFIG_H
  15. #include "config.h"
  16. #endif
  17. extern "C" {
  18. #include "php.h"
  19. #include "ext/date/php_date.h"
  20. #include "ext/standard/php_string.h"
  21. #include "zend_interfaces.h"
  22. #include "zend_closures.h"
  23. #include "ext/spl/spl_exceptions.h"
  24. #include "zend_exceptions.h"
  25. }
  26. #include "php_v8js_macros.h"
  27. #include "v8js_v8.h"
  28. #include "v8js_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 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< v8::Local<v8::Value>(v8::Isolate *) > v8_call = [res](v8::Isolate *isolate) {
  436. v8::Local<v8::Script> script = v8::Local<v8::Script>::New(isolate, *res->script);
  437. return script->Run();
  438. };
  439. v8js_v8_call(c, return_value, flags, time_limit, memory_limit, v8_call TSRMLS_CC);
  440. }
  441. /* {{{ proto mixed V8Js::executeString(string script [, string identifier [, int flags]])
  442. */
  443. static PHP_METHOD(V8Js, executeString)
  444. {
  445. zend_string *str = NULL, *identifier = NULL;
  446. int str_len = 0, identifier_len = 0;
  447. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  448. v8js_script *res = NULL;
  449. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|Slll", &str, &identifier, &flags, &time_limit, &memory_limit) == FAILURE) {
  450. return;
  451. }
  452. v8js_compile_script(getThis(), str, identifier, &res TSRMLS_CC);
  453. if (!res) {
  454. RETURN_FALSE;
  455. }
  456. zend_try {
  457. v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
  458. v8js_script_free(res);
  459. }
  460. zend_catch {
  461. v8js_script_free(res);
  462. zend_bailout();
  463. }
  464. zend_end_try()
  465. efree(res);
  466. }
  467. /* }}} */
  468. /* {{{ proto mixed V8Js::compileString(string script [, string identifier])
  469. */
  470. static PHP_METHOD(V8Js, compileString)
  471. {
  472. zend_string *str = NULL, *identifier = NULL;
  473. int str_len = 0, identifier_len = 0;
  474. v8js_script *res = NULL;
  475. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|S", &str, &identifier) == FAILURE) {
  476. return;
  477. }
  478. v8js_compile_script(getThis(), str, identifier, &res TSRMLS_CC);
  479. if (res) {
  480. RETVAL_RES(zend_register_resource(res, le_v8js_script));
  481. v8js_ctx *ctx;
  482. ctx = Z_V8JS_CTX_OBJ_P(getThis());
  483. ctx->script_objects.push_back(res);
  484. }
  485. return;
  486. }
  487. /* }}} */
  488. /* {{{ proto mixed V8Js::executeScript(resource script [, int flags]])
  489. */
  490. static PHP_METHOD(V8Js, executeScript)
  491. {
  492. long flags = V8JS_FLAG_NONE, time_limit = 0, memory_limit = 0;
  493. zval *zscript;
  494. v8js_script *res;
  495. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lll", &zscript, &flags, &time_limit, &memory_limit) == FAILURE) {
  496. return;
  497. }
  498. if((res = (v8js_script *)zend_fetch_resource(Z_RES_P(zscript), PHP_V8JS_SCRIPT_RES_NAME, le_v8js_script)) == NULL) {
  499. RETURN_FALSE;
  500. }
  501. v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value TSRMLS_CC);
  502. }
  503. /* }}} */
  504. /* {{{ proto mixed V8Js::checkString(string script)
  505. */
  506. static PHP_METHOD(V8Js, checkString)
  507. {
  508. zend_string *str = NULL;
  509. int str_len = 0;
  510. zend_string *identifier = zend_string_init("V8Js::checkString()", 19, 0);
  511. v8js_script *res = NULL;
  512. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S", &str) == FAILURE) {
  513. return;
  514. }
  515. v8js_compile_script(getThis(), str, identifier, &res TSRMLS_CC);
  516. zend_string_release(identifier);
  517. if (!res) {
  518. RETURN_FALSE;
  519. }
  520. v8js_script_free(res);
  521. efree(res);
  522. RETURN_TRUE;
  523. }
  524. /* }}} */
  525. /* {{{ proto mixed V8Js::getPendingException()
  526. */
  527. static PHP_METHOD(V8Js, getPendingException)
  528. {
  529. v8js_ctx *c;
  530. if (zend_parse_parameters_none() == FAILURE) {
  531. return;
  532. }
  533. c = Z_V8JS_CTX_OBJ_P(getThis());
  534. if (Z_TYPE(c->pending_exception) == IS_OBJECT) {
  535. RETURN_ZVAL(&c->pending_exception, 1, 0);
  536. }
  537. }
  538. /* }}} */
  539. /* {{{ proto void V8Js::clearPendingException()
  540. */
  541. static PHP_METHOD(V8Js, clearPendingException)
  542. {
  543. v8js_ctx *c;
  544. if (zend_parse_parameters_none() == FAILURE) {
  545. return;
  546. }
  547. c = Z_V8JS_CTX_OBJ_P(getThis());
  548. if (Z_TYPE(c->pending_exception) == IS_OBJECT) {
  549. zval_dtor(&c->pending_exception);
  550. ZVAL_NULL(&c->pending_exception);
  551. }
  552. }
  553. /* }}} */
  554. /* {{{ proto void V8Js::setModuleNormaliser(string base, string module_id)
  555. */
  556. static PHP_METHOD(V8Js, setModuleNormaliser)
  557. {
  558. v8js_ctx *c;
  559. zval *callable;
  560. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callable) == FAILURE) {
  561. return;
  562. }
  563. c = Z_V8JS_CTX_OBJ_P(getThis());
  564. ZVAL_COPY(&c->module_normaliser, callable);
  565. }
  566. /* }}} */
  567. /* {{{ proto void V8Js::setModuleLoader(string module)
  568. */
  569. static PHP_METHOD(V8Js, setModuleLoader)
  570. {
  571. v8js_ctx *c;
  572. zval *callable;
  573. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &callable) == FAILURE) {
  574. return;
  575. }
  576. c = Z_V8JS_CTX_OBJ_P(getThis());
  577. ZVAL_COPY(&c->module_loader, callable);
  578. }
  579. /* }}} */
  580. /* {{{ proto void V8Js::setTimeLimit(int time_limit)
  581. */
  582. static PHP_METHOD(V8Js, setTimeLimit)
  583. {
  584. v8js_ctx *c;
  585. long time_limit = 0;
  586. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &time_limit) == FAILURE) {
  587. return;
  588. }
  589. c = Z_V8JS_CTX_OBJ_P(getThis());
  590. c->time_limit = time_limit;
  591. V8JSG(timer_mutex).lock();
  592. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  593. it != V8JSG(timer_stack).end(); it ++) {
  594. if((*it)->ctx == c && !(*it)->killed) {
  595. (*it)->time_limit = time_limit;
  596. // Calculate the time point when the time limit is exceeded
  597. std::chrono::milliseconds duration(time_limit);
  598. std::chrono::time_point<std::chrono::high_resolution_clock> from = std::chrono::high_resolution_clock::now();
  599. (*it)->time_point = from + duration;
  600. }
  601. }
  602. V8JSG(timer_mutex).unlock();
  603. if (c->in_execution && time_limit && !V8JSG(timer_thread)) {
  604. /* If timer thread is not started already and we now impose a time limit
  605. * finally install the timer. */
  606. V8JSG(timer_thread) = new std::thread(v8js_timer_thread, ZEND_MODULE_GLOBALS_BULK(v8js));
  607. }
  608. }
  609. /* }}} */
  610. /* {{{ proto void V8Js::setMemoryLimit(int memory_limit)
  611. */
  612. static PHP_METHOD(V8Js, setMemoryLimit)
  613. {
  614. v8js_ctx *c;
  615. long memory_limit = 0;
  616. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &memory_limit) == FAILURE) {
  617. return;
  618. }
  619. c = Z_V8JS_CTX_OBJ_P(getThis());
  620. c->memory_limit = memory_limit;
  621. V8JSG(timer_mutex).lock();
  622. for (std::deque< v8js_timer_ctx* >::iterator it = V8JSG(timer_stack).begin();
  623. it != V8JSG(timer_stack).end(); it ++) {
  624. if((*it)->ctx == c && !(*it)->killed) {
  625. (*it)->memory_limit = memory_limit;
  626. }
  627. }
  628. V8JSG(timer_mutex).unlock();
  629. if (c->in_execution && memory_limit && !V8JSG(timer_thread)) {
  630. /* If timer thread is not started already and we now impose a memory limit
  631. * finally install the timer. */
  632. V8JSG(timer_thread) = new std::thread(v8js_timer_thread, ZEND_MODULE_GLOBALS_BULK(v8js));
  633. }
  634. }
  635. /* }}} */
  636. static void v8js_persistent_zval_ctor(zval *p) /* {{{ */
  637. {
  638. assert(Z_TYPE_P(p) == IS_STRING);
  639. Z_STR_P(p) = zend_string_dup(Z_STR_P(p), 1);
  640. }
  641. /* }}} */
  642. static void v8js_persistent_zval_dtor(zval *p) /* {{{ */
  643. {
  644. assert(Z_TYPE_P(p) == IS_STRING);
  645. free(Z_STR_P(p));
  646. }
  647. /* }}} */
  648. static void v8js_script_free(v8js_script *res)
  649. {
  650. efree(res->name);
  651. delete res->script; // does Reset()
  652. }
  653. static void v8js_script_dtor(zend_resource *rsrc) /* {{{ */
  654. {
  655. v8js_script *res = (v8js_script *)rsrc->ptr;
  656. if (res) {
  657. if(res->ctx) {
  658. std::vector<v8js_script *>::iterator it = std::find(res->ctx->script_objects.begin(), res->ctx->script_objects.end(), res);
  659. res->ctx->script_objects.erase(it);
  660. }
  661. v8js_script_free(res);
  662. efree(res);
  663. }
  664. }
  665. /* }}} */
  666. static int v8js_register_extension(zend_string *name, zend_string *source, zval *deps_arr, zend_bool auto_enable TSRMLS_DC) /* {{{ */
  667. {
  668. v8js_jsext *jsext = NULL;
  669. #ifdef ZTS
  670. v8js_process_globals.lock.lock();
  671. #endif
  672. if (!v8js_process_globals.extensions) {
  673. v8js_process_globals.extensions = (HashTable *) malloc(sizeof(HashTable));
  674. zend_hash_init(v8js_process_globals.extensions, 1, NULL, v8js_jsext_dtor, 1);
  675. } else if (zend_hash_exists(v8js_process_globals.extensions, name)) {
  676. #ifdef ZTS
  677. v8js_process_globals.lock.unlock();
  678. #endif
  679. return FAILURE;
  680. }
  681. jsext = (v8js_jsext *) calloc(1, sizeof(v8js_jsext));
  682. if (deps_arr) {
  683. jsext->deps_count = zend_hash_num_elements(Z_ARRVAL_P(deps_arr));
  684. if (v8js_create_ext_strarr(&jsext->deps, jsext->deps_count, Z_ARRVAL_P(deps_arr)) == FAILURE) {
  685. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid dependency array passed");
  686. v8js_jsext_free_storage(jsext);
  687. #ifdef ZTS
  688. v8js_process_globals.lock.unlock();
  689. #endif
  690. return FAILURE;
  691. }
  692. }
  693. jsext->auto_enable = auto_enable;
  694. jsext->name = zend_string_dup(name, 1);
  695. jsext->source = zend_string_dup(source, 1);
  696. if (jsext->deps) {
  697. jsext->deps_ht = (HashTable *) malloc(sizeof(HashTable));
  698. zend_hash_init(jsext->deps_ht, jsext->deps_count, NULL, v8js_persistent_zval_dtor, 1);
  699. zend_hash_copy(jsext->deps_ht, Z_ARRVAL_P(deps_arr), v8js_persistent_zval_ctor);
  700. }
  701. jsext->extension = new v8::Extension(ZSTR_VAL(jsext->name), ZSTR_VAL(jsext->source), jsext->deps_count, jsext->deps);
  702. if (!zend_hash_add_ptr(v8js_process_globals.extensions, jsext->name, jsext)) {
  703. v8js_jsext_free_storage(jsext);
  704. #ifdef ZTS
  705. v8js_process_globals.lock.unlock();
  706. #endif
  707. return FAILURE;
  708. }
  709. #ifdef ZTS
  710. v8js_process_globals.lock.unlock();
  711. #endif
  712. jsext->extension->set_auto_enable(auto_enable ? true : false);
  713. v8::RegisterExtension(jsext->extension);
  714. return SUCCESS;
  715. }
  716. /* }}} */
  717. /* {{{ proto bool V8Js::registerExtension(string ext_name, string script [, array deps [, bool auto_enable]])
  718. */
  719. static PHP_METHOD(V8Js, registerExtension)
  720. {
  721. zend_string *ext_name, *script;
  722. zval *deps_arr = NULL;
  723. zend_bool auto_enable = 0;
  724. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|ab", &ext_name, &script, &deps_arr, &auto_enable) == FAILURE) {
  725. return;
  726. }
  727. if (!ZSTR_LEN(ext_name)) {
  728. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Extension name cannot be empty");
  729. } else if (!ZSTR_LEN(script)) {
  730. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Script cannot be empty");
  731. } else if (v8js_register_extension(ext_name, script, deps_arr, auto_enable TSRMLS_CC) == SUCCESS) {
  732. RETURN_TRUE;
  733. }
  734. RETURN_FALSE;
  735. }
  736. /* }}} */
  737. /* ## Static methods ## */
  738. /* {{{ proto array V8Js::getExtensions()
  739. */
  740. static PHP_METHOD(V8Js, getExtensions)
  741. {
  742. v8js_jsext *jsext;
  743. ulong index;
  744. zend_string *key;
  745. zval *val, ext;
  746. if (zend_parse_parameters_none() == FAILURE) {
  747. return;
  748. }
  749. array_init(return_value);
  750. #ifdef ZTS
  751. v8js_process_globals.lock.lock();
  752. #endif
  753. if (v8js_process_globals.extensions) {
  754. ZEND_HASH_FOREACH_KEY_VAL(v8js_process_globals.extensions, index, key, val) {
  755. if (key) {
  756. jsext = (v8js_jsext *) Z_PTR_P(val);
  757. array_init(&ext);
  758. add_assoc_bool_ex(&ext, ZEND_STRL("auto_enable"), jsext->auto_enable);
  759. if (jsext->deps_ht) {
  760. zval deps_arr;
  761. array_init(&deps_arr);
  762. zend_hash_copy(Z_ARRVAL_P(&deps_arr), jsext->deps_ht, (copy_ctor_func_t) zval_add_ref);
  763. add_assoc_zval_ex(&ext, ZEND_STRL("deps"), &deps_arr);
  764. }
  765. add_assoc_zval_ex(return_value, ZSTR_VAL(key), ZSTR_LEN(key), &ext);
  766. }
  767. } ZEND_HASH_FOREACH_END();
  768. }
  769. #ifdef ZTS
  770. v8js_process_globals.lock.unlock();
  771. #endif
  772. }
  773. /* }}} */
  774. /* {{{ arginfo */
  775. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_construct, 0, 0, 0)
  776. ZEND_ARG_INFO(0, object_name)
  777. ZEND_ARG_INFO(0, variables)
  778. ZEND_ARG_INFO(0, extensions)
  779. ZEND_ARG_INFO(0, report_uncaught_exceptions)
  780. ZEND_END_ARG_INFO()
  781. ZEND_BEGIN_ARG_INFO(arginfo_v8js_sleep, 0)
  782. ZEND_END_ARG_INFO()
  783. ZEND_BEGIN_ARG_INFO(arginfo_v8js_wakeup, 0)
  784. ZEND_END_ARG_INFO()
  785. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_executestring, 0, 0, 1)
  786. ZEND_ARG_INFO(0, script)
  787. ZEND_ARG_INFO(0, identifier)
  788. ZEND_ARG_INFO(0, flags)
  789. ZEND_ARG_INFO(0, time_limit)
  790. ZEND_ARG_INFO(0, memory_limit)
  791. ZEND_END_ARG_INFO()
  792. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_compilestring, 0, 0, 1)
  793. ZEND_ARG_INFO(0, script)
  794. ZEND_ARG_INFO(0, identifier)
  795. ZEND_END_ARG_INFO()
  796. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_executescript, 0, 0, 1)
  797. ZEND_ARG_INFO(0, script)
  798. ZEND_ARG_INFO(0, flags)
  799. ZEND_ARG_INFO(0, time_limit)
  800. ZEND_ARG_INFO(0, memory_limit)
  801. ZEND_END_ARG_INFO()
  802. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_checkstring, 0, 0, 1)
  803. ZEND_ARG_INFO(0, script)
  804. ZEND_END_ARG_INFO()
  805. ZEND_BEGIN_ARG_INFO(arginfo_v8js_getpendingexception, 0)
  806. ZEND_END_ARG_INFO()
  807. ZEND_BEGIN_ARG_INFO(arginfo_v8js_clearpendingexception, 0)
  808. ZEND_END_ARG_INFO()
  809. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmodulenormaliser, 0, 0, 2)
  810. ZEND_ARG_INFO(0, base)
  811. ZEND_ARG_INFO(0, module_id)
  812. ZEND_END_ARG_INFO()
  813. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmoduleloader, 0, 0, 1)
  814. ZEND_ARG_INFO(0, callable)
  815. ZEND_END_ARG_INFO()
  816. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_registerextension, 0, 0, 2)
  817. ZEND_ARG_INFO(0, extension_name)
  818. ZEND_ARG_INFO(0, script)
  819. ZEND_ARG_INFO(0, dependencies)
  820. ZEND_ARG_INFO(0, auto_enable)
  821. ZEND_END_ARG_INFO()
  822. ZEND_BEGIN_ARG_INFO(arginfo_v8js_getextensions, 0)
  823. ZEND_END_ARG_INFO()
  824. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_settimelimit, 0, 0, 1)
  825. ZEND_ARG_INFO(0, time_limit)
  826. ZEND_END_ARG_INFO()
  827. ZEND_BEGIN_ARG_INFO_EX(arginfo_v8js_setmemorylimit, 0, 0, 1)
  828. ZEND_ARG_INFO(0, memory_limit)
  829. ZEND_END_ARG_INFO()
  830. static const zend_function_entry v8js_methods[] = { /* {{{ */
  831. PHP_ME(V8Js, __construct, arginfo_v8js_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
  832. PHP_ME(V8Js, __sleep, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
  833. PHP_ME(V8Js, __wakeup, arginfo_v8js_sleep, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
  834. PHP_ME(V8Js, executeString, arginfo_v8js_executestring, ZEND_ACC_PUBLIC)
  835. PHP_ME(V8Js, compileString, arginfo_v8js_compilestring, ZEND_ACC_PUBLIC)
  836. PHP_ME(V8Js, executeScript, arginfo_v8js_executescript, ZEND_ACC_PUBLIC)
  837. PHP_ME(V8Js, checkString, arginfo_v8js_checkstring, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
  838. PHP_ME(V8Js, getPendingException, arginfo_v8js_getpendingexception, ZEND_ACC_PUBLIC)
  839. PHP_ME(V8Js, clearPendingException, arginfo_v8js_clearpendingexception, ZEND_ACC_PUBLIC)
  840. PHP_ME(V8Js, setModuleNormaliser, arginfo_v8js_setmodulenormaliser, ZEND_ACC_PUBLIC)
  841. PHP_ME(V8Js, setModuleLoader, arginfo_v8js_setmoduleloader, ZEND_ACC_PUBLIC)
  842. PHP_ME(V8Js, registerExtension, arginfo_v8js_registerextension, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  843. PHP_ME(V8Js, getExtensions, arginfo_v8js_getextensions, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  844. PHP_ME(V8Js, setTimeLimit, arginfo_v8js_settimelimit, ZEND_ACC_PUBLIC)
  845. PHP_ME(V8Js, setMemoryLimit, arginfo_v8js_setmemorylimit, ZEND_ACC_PUBLIC)
  846. {NULL, NULL, NULL}
  847. };
  848. /* }}} */
  849. /* V8Js object handlers */
  850. static void v8js_write_property(zval *object, zval *member, zval *value, void **cache_slot TSRMLS_DC) /* {{{ */
  851. {
  852. V8JS_BEGIN_CTX(c, object)
  853. /* Check whether member is public, if so, export to V8. */
  854. zend_property_info *property_info = zend_get_property_info(c->std.ce, Z_STR_P(member), 1 TSRMLS_CC);
  855. if(!property_info ||
  856. (property_info != ZEND_WRONG_PROPERTY_INFO &&
  857. property_info->flags & ZEND_ACC_PUBLIC)) {
  858. /* Global PHP JS object */
  859. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  860. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
  861. /* Write value to PHP JS object */
  862. jsobj->ForceSet(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)), zval_to_v8js(value, isolate TSRMLS_CC), v8::ReadOnly);
  863. }
  864. /* Write value to PHP object */
  865. std_object_handlers.write_property(object, member, value, NULL);
  866. }
  867. /* }}} */
  868. static void v8js_unset_property(zval *object, zval *member, void **cache_slot TSRMLS_DC) /* {{{ */
  869. {
  870. V8JS_BEGIN_CTX(c, object)
  871. /* Global PHP JS object */
  872. v8::Local<v8::String> object_name_js = v8::Local<v8::String>::New(isolate, c->object_name);
  873. v8::Local<v8::Object> jsobj = V8JS_GLOBAL(isolate)->Get(object_name_js)->ToObject();
  874. /* Delete value from PHP JS object */
  875. jsobj->Delete(V8JS_SYML(Z_STRVAL_P(member), Z_STRLEN_P(member)));
  876. /* Unset from PHP object */
  877. std_object_handlers.unset_property(object, member, NULL);
  878. }
  879. /* }}} */
  880. PHP_MINIT_FUNCTION(v8js_class) /* {{{ */
  881. {
  882. zend_class_entry ce;
  883. /* V8Js Class */
  884. INIT_CLASS_ENTRY(ce, "V8Js", v8js_methods);
  885. php_ce_v8js = zend_register_internal_class(&ce TSRMLS_CC);
  886. php_ce_v8js->create_object = v8js_new;
  887. /* V8Js handlers */
  888. memcpy(&v8js_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  889. v8js_object_handlers.clone_obj = NULL;
  890. v8js_object_handlers.write_property = v8js_write_property;
  891. v8js_object_handlers.unset_property = v8js_unset_property;
  892. /* V8Js Class Constants */
  893. zend_declare_class_constant_string(php_ce_v8js, ZEND_STRL("V8_VERSION"), PHP_V8_VERSION TSRMLS_CC);
  894. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_NONE"), V8JS_FLAG_NONE TSRMLS_CC);
  895. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_FORCE_ARRAY"), V8JS_FLAG_FORCE_ARRAY TSRMLS_CC);
  896. zend_declare_class_constant_long(php_ce_v8js, ZEND_STRL("FLAG_PROPAGATE_PHP_EXCEPTIONS"), V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS TSRMLS_CC);
  897. le_v8js_script = zend_register_list_destructors_ex(v8js_script_dtor, NULL, PHP_V8JS_SCRIPT_RES_NAME, module_number);
  898. #if PHP_V8_API_VERSION >= 4004010 && PHP_V8_API_VERSION < 4004044
  899. static ArrayBufferAllocator array_buffer_allocator;
  900. v8::V8::SetArrayBufferAllocator(&array_buffer_allocator);
  901. #endif
  902. return SUCCESS;
  903. } /* }}} */
  904. /*
  905. * Local variables:
  906. * tab-width: 4
  907. * c-basic-offset: 4
  908. * End:
  909. * vim600: noet sw=4 ts=4 fdm=marker
  910. * vim<600: noet sw=4 ts=4
  911. */