v8js_class.cc 32 KB

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