v8js_methods.cc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2017 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | http://www.opensource.org/licenses/mit-license.php MIT License |
  8. +----------------------------------------------------------------------+
  9. | Author: Jani Taskinen <[email protected]> |
  10. | Author: Patrick Reilly <[email protected]> |
  11. | Author: Stefan Siegl <[email protected]> |
  12. +----------------------------------------------------------------------+
  13. */
  14. #ifdef HAVE_CONFIG_H
  15. #include "config.h"
  16. #endif
  17. #include "php_v8js_macros.h"
  18. #include "v8js_commonjs.h"
  19. #include "v8js_exceptions.h"
  20. extern "C" {
  21. #include "zend_exceptions.h"
  22. }
  23. /* global.exit - terminate execution */
  24. V8JS_METHOD(exit) /* {{{ */
  25. {
  26. v8::Isolate *isolate = info.GetIsolate();
  27. v8js_terminate_execution(isolate);
  28. }
  29. /* }}} */
  30. /* global.sleep - sleep for passed seconds */
  31. V8JS_METHOD(sleep) /* {{{ */
  32. {
  33. v8::Isolate *isolate = info.GetIsolate();
  34. v8js_ctx *c = (v8js_ctx *) isolate->GetData(0);
  35. v8::Maybe<int32_t> t = info[0]->Int32Value(v8::Local<v8::Context>::New(isolate, c->context));
  36. if (t.IsJust()) {
  37. php_sleep(t.FromJust());
  38. }
  39. }
  40. /* }}} */
  41. /* global.print - php print() */
  42. V8JS_METHOD(print) /* {{{ */
  43. {
  44. v8::Isolate *isolate = info.GetIsolate();
  45. zend_long ret = 0;
  46. for (int i = 0; i < info.Length(); i++) {
  47. v8::String::Utf8Value str(isolate, info[i]);
  48. const char *cstr = ToCString(str);
  49. ret = PHPWRITE(cstr, strlen(cstr));
  50. }
  51. info.GetReturnValue().Set(zend_long_to_v8js(ret, isolate));
  52. }
  53. /* }}} */
  54. static void v8js_dumper(v8::Isolate *isolate, v8::Local<v8::Value> var, int level) /* {{{ */
  55. {
  56. v8js_ctx *c = (v8js_ctx *) isolate->GetData(0);
  57. v8::Local<v8::Context> v8_context = v8::Local<v8::Context>::New(isolate, c->context);
  58. if (level > 1) {
  59. php_printf("%*c", (level - 1) * 2, ' ');
  60. }
  61. if (var.IsEmpty())
  62. {
  63. php_printf("<empty>\n");
  64. return;
  65. }
  66. if (var->IsNull() || var->IsUndefined() /* PHP compat */)
  67. {
  68. php_printf("NULL\n");
  69. return;
  70. }
  71. if (var->IsInt32())
  72. {
  73. v8::Maybe<int64_t> value = var->IntegerValue(v8_context);
  74. if (value.IsNothing())
  75. {
  76. php_printf("<empty>\n");
  77. }
  78. else
  79. {
  80. php_printf("int(%ld)\n", (long) value.FromJust());
  81. }
  82. return;
  83. }
  84. if (var->IsUint32())
  85. {
  86. v8::Maybe<uint32_t> value = var->Uint32Value(v8_context);
  87. if (value.IsNothing())
  88. {
  89. php_printf("<empty>\n");
  90. }
  91. else
  92. {
  93. php_printf("int(%lu)\n", (unsigned long) value.FromJust());
  94. }
  95. return;
  96. }
  97. if (var->IsNumber())
  98. {
  99. v8::Maybe<double> value = var->NumberValue(v8_context);
  100. if (value.IsNothing())
  101. {
  102. php_printf("<empty>\n");
  103. }
  104. else
  105. {
  106. php_printf("float(%f)\n", value.FromJust());
  107. }
  108. return;
  109. }
  110. if (var->IsBoolean())
  111. {
  112. bool value = var->BooleanValue(isolate);
  113. php_printf("bool(%s)\n", value ? "true" : "false");
  114. return;
  115. }
  116. v8::TryCatch try_catch(isolate); /* object.toString() can throw an exception */
  117. v8::Local<v8::String> details;
  118. if(var->IsRegExp()) {
  119. v8::RegExp *re = v8::RegExp::Cast(*var);
  120. details = re->GetSource();
  121. }
  122. else {
  123. details = var->ToDetailString(v8_context).FromMaybe(v8::Local<v8::String>());
  124. if (try_catch.HasCaught()) {
  125. details = V8JS_SYM("<toString threw exception>");
  126. }
  127. }
  128. v8::String::Utf8Value str(isolate, details);
  129. const char *valstr = ToCString(str);
  130. size_t valstr_len = str.length();
  131. if (var->IsString())
  132. {
  133. php_printf("string(%zu) \"", valstr_len);
  134. PHPWRITE(valstr, valstr_len);
  135. php_printf("\"\n");
  136. }
  137. else if (var->IsDate())
  138. {
  139. // fake the fields of a PHP DateTime
  140. php_printf("Date(%s)\n", valstr);
  141. }
  142. else if (var->IsRegExp())
  143. {
  144. php_printf("regexp(/%s/)\n", valstr);
  145. }
  146. else if (var->IsArray())
  147. {
  148. v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(var);
  149. uint32_t length = array->Length();
  150. php_printf("array(%d) {\n", length);
  151. for (unsigned i = 0; i < length; i++) {
  152. php_printf("%*c[%d] =>\n", level * 2, ' ', i);
  153. v8::MaybeLocal<v8::Value> value = array->Get(v8_context, i);
  154. if (value.IsEmpty())
  155. {
  156. php_printf("<empty>\n");
  157. }
  158. else
  159. {
  160. v8js_dumper(isolate, value.ToLocalChecked(), level + 1);
  161. }
  162. }
  163. if (level > 1) {
  164. php_printf("%*c", (level - 1) * 2, ' ');
  165. }
  166. ZEND_PUTS("}\n");
  167. }
  168. else if (var->IsObject())
  169. {
  170. v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(var);
  171. v8::String::Utf8Value cname(isolate, object->GetConstructorName());
  172. int hash = object->GetIdentityHash();
  173. if (var->IsFunction() && strcmp(ToCString(cname), "Closure") != 0)
  174. {
  175. php_printf("object(Closure)#%d {\n%*c", hash, level * 2 + 2, ' ');
  176. v8::Local<v8::String> source;
  177. if (object->ToString(v8_context).ToLocal(&source))
  178. {
  179. v8::String::Utf8Value csource(isolate, source);
  180. php_printf("%s\n", ToCString(csource));
  181. }
  182. else
  183. {
  184. php_printf("<empty>\n");
  185. }
  186. }
  187. else
  188. {
  189. v8::MaybeLocal<v8::Array> keys = object->GetOwnPropertyNames(v8_context);
  190. uint32_t length = keys.IsEmpty() ? 0 : keys.ToLocalChecked()->Length();
  191. if (strcmp(ToCString(cname), "Array") == 0 ||
  192. strcmp(ToCString(cname), "V8Object") == 0) {
  193. php_printf("array");
  194. } else {
  195. php_printf("object(%s)#%d", ToCString(cname), hash);
  196. }
  197. php_printf(" (%d) {\n", length);
  198. for (unsigned i = 0; i < length; i++) {
  199. v8::MaybeLocal<v8::Value> key_slot = keys.ToLocalChecked()->Get(v8_context, i);
  200. v8::Local<v8::String> key;
  201. if (key_slot.IsEmpty() || !key_slot.ToLocalChecked()->ToString(v8_context).ToLocal(&key))
  202. {
  203. key = V8JS_SYM("<empty>");
  204. }
  205. v8::String::Utf8Value key_name(isolate, key);
  206. php_printf("%*c[\"%s\"] =>\n", level * 2, ' ', ToCString(key_name));
  207. v8::MaybeLocal<v8::Value> value = object->Get(v8_context, key);
  208. if (value.IsEmpty())
  209. {
  210. php_printf("<empty>\n");
  211. }
  212. else
  213. {
  214. v8js_dumper(isolate, value.ToLocalChecked(), level + 1);
  215. }
  216. }
  217. }
  218. if (level > 1) {
  219. php_printf("%*c", (level - 1) * 2, ' ');
  220. }
  221. ZEND_PUTS("}\n");
  222. }
  223. else /* null, undefined, etc. */
  224. {
  225. php_printf("<%s>\n", valstr);
  226. }
  227. }
  228. /* }}} */
  229. /* global.var_dump - Dump JS values */
  230. V8JS_METHOD(var_dump) /* {{{ */
  231. {
  232. v8::Isolate *isolate = info.GetIsolate();
  233. for (int i = 0; i < info.Length(); i++) {
  234. v8js_dumper(isolate, info[i], 1);
  235. }
  236. info.GetReturnValue().Set(V8JS_NULL);
  237. }
  238. /* }}} */
  239. V8JS_METHOD(require)
  240. {
  241. v8::Isolate *isolate = info.GetIsolate();
  242. v8js_ctx *c = (v8js_ctx *) isolate->GetData(0);
  243. v8::String::Utf8Value module_base(isolate, info.Data());
  244. const char *module_base_cstr = ToCString(module_base);
  245. // Check that we have a module loader
  246. if(Z_TYPE(c->module_loader) == IS_NULL) {
  247. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("No module loader")));
  248. return;
  249. }
  250. v8::String::Utf8Value module_id_v8(isolate, info[0]);
  251. const char *module_id = ToCString(module_id_v8);
  252. char *normalised_path, *module_name;
  253. if (Z_TYPE(c->module_normaliser) == IS_NULL) {
  254. // No custom normalisation routine registered, use internal one
  255. normalised_path = (char *)emalloc(PATH_MAX);
  256. module_name = (char *)emalloc(PATH_MAX);
  257. v8js_commonjs_normalise_identifier(module_base_cstr, module_id, normalised_path, module_name);
  258. }
  259. else {
  260. // Call custom normaliser
  261. int call_result;
  262. zval params[2];
  263. zval normaliser_result;
  264. zend_try {
  265. {
  266. isolate->Exit();
  267. v8::Unlocker unlocker(isolate);
  268. ZVAL_STRING(&params[0], module_base_cstr);
  269. ZVAL_STRING(&params[1], module_id);
  270. #if (PHP_MAJOR_VERSION < 8)
  271. call_result = call_user_function_ex(EG(function_table), NULL, &c->module_normaliser,
  272. &normaliser_result, 2, params, 0, NULL);
  273. #else
  274. call_result = call_user_function(EG(function_table), NULL, &c->module_normaliser,
  275. &normaliser_result, 2, params);
  276. #endif
  277. }
  278. isolate->Enter();
  279. if (call_result == FAILURE) {
  280. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module normaliser callback failed")));
  281. }
  282. }
  283. zend_catch {
  284. v8js_terminate_execution(isolate);
  285. V8JSG(fatal_error_abort) = 1;
  286. call_result = FAILURE;
  287. }
  288. zend_end_try();
  289. zval_ptr_dtor(&params[0]);
  290. zval_ptr_dtor(&params[1]);
  291. if(call_result == FAILURE) {
  292. return;
  293. }
  294. // Check if an exception was thrown
  295. if (EG(exception)) {
  296. if (c->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) {
  297. zval tmp_zv;
  298. ZVAL_OBJ(&tmp_zv, EG(exception));
  299. info.GetReturnValue().Set(isolate->ThrowException(zval_to_v8js(&tmp_zv, isolate)));
  300. zend_clear_exception();
  301. } else {
  302. v8js_terminate_execution(isolate);
  303. }
  304. return;
  305. }
  306. if (Z_TYPE(normaliser_result) != IS_ARRAY) {
  307. zval_ptr_dtor(&normaliser_result);
  308. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module normaliser didn't return an array")));
  309. return;
  310. }
  311. HashTable *ht = HASH_OF(&normaliser_result);
  312. int num_elements = zend_hash_num_elements(ht);
  313. if(num_elements != 2) {
  314. zval_ptr_dtor(&normaliser_result);
  315. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module normaliser expected to return array of 2 strings")));
  316. return;
  317. }
  318. zval *data;
  319. zend_ulong index = 0;
  320. ZEND_HASH_FOREACH_VAL(ht, data) {
  321. if (Z_TYPE_P(data) != IS_STRING) {
  322. convert_to_string(data);
  323. }
  324. switch(index++) {
  325. case 0: // normalised path
  326. normalised_path = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data));
  327. break;
  328. case 1: // normalised module id
  329. module_name = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data));
  330. break;
  331. }
  332. }
  333. ZEND_HASH_FOREACH_END();
  334. zval_ptr_dtor(&normaliser_result);
  335. }
  336. char *normalised_module_id = (char *)emalloc(strlen(normalised_path)+1+strlen(module_name)+1);
  337. *normalised_module_id = 0;
  338. if (strlen(normalised_path) > 0) {
  339. strcat(normalised_module_id, normalised_path);
  340. strcat(normalised_module_id, "/");
  341. }
  342. strcat(normalised_module_id, module_name);
  343. efree(module_name);
  344. // Check for module cyclic dependencies
  345. for (std::vector<char *>::iterator it = c->modules_stack.begin(); it != c->modules_stack.end(); ++it)
  346. {
  347. if (!strcmp(*it, normalised_module_id)) {
  348. efree(normalised_module_id);
  349. efree(normalised_path);
  350. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module cyclic dependency")));
  351. return;
  352. }
  353. }
  354. // If we have already loaded and cached this module then use it
  355. if (c->modules_loaded.count(normalised_module_id) > 0) {
  356. v8::Persistent<v8::Value> newobj;
  357. newobj.Reset(isolate, c->modules_loaded[normalised_module_id]);
  358. // TODO store v8::Global in c->modules_loaded directly!?
  359. info.GetReturnValue().Set(v8::Global<v8::Value>(isolate, newobj));
  360. efree(normalised_module_id);
  361. efree(normalised_path);
  362. return;
  363. }
  364. // Callback to PHP to load the module code
  365. zval module_code;
  366. int call_result;
  367. zval params[1];
  368. {
  369. isolate->Exit();
  370. v8::Unlocker unlocker(isolate);
  371. zend_try {
  372. ZVAL_STRING(&params[0], normalised_module_id);
  373. #if (PHP_MAJOR_VERSION < 8)
  374. call_result = call_user_function_ex(EG(function_table), NULL, &c->module_loader, &module_code, 1, params, 0, NULL);
  375. #else
  376. call_result = call_user_function(EG(function_table), NULL, &c->module_loader, &module_code, 1, params);
  377. #endif
  378. }
  379. zend_catch {
  380. v8js_terminate_execution(isolate);
  381. V8JSG(fatal_error_abort) = 1;
  382. }
  383. zend_end_try();
  384. }
  385. isolate->Enter();
  386. if (V8JSG(fatal_error_abort)) {
  387. call_result = FAILURE;
  388. }
  389. else if (call_result == FAILURE) {
  390. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module loader callback failed")));
  391. }
  392. zval_ptr_dtor(&params[0]);
  393. if (call_result == FAILURE) {
  394. efree(normalised_module_id);
  395. efree(normalised_path);
  396. return;
  397. }
  398. // Check if an exception was thrown
  399. if (EG(exception)) {
  400. efree(normalised_module_id);
  401. efree(normalised_path);
  402. if (c->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) {
  403. zval tmp_zv;
  404. ZVAL_OBJ(&tmp_zv, EG(exception));
  405. info.GetReturnValue().Set(isolate->ThrowException(zval_to_v8js(&tmp_zv, isolate)));
  406. zend_clear_exception();
  407. } else {
  408. v8js_terminate_execution(isolate);
  409. }
  410. return;
  411. }
  412. if(Z_TYPE(module_code) == IS_ARRAY) {
  413. v8::Local<v8::Value> newarray = zval_to_v8js(&module_code, isolate);
  414. c->modules_loaded[normalised_module_id].Reset(isolate, newarray);
  415. info.GetReturnValue().Set(newarray);
  416. efree(normalised_path);
  417. return;
  418. }
  419. if(Z_TYPE(module_code) == IS_OBJECT) {
  420. v8::Local<v8::Object> newobj = zval_to_v8js(&module_code, isolate)->ToObject(isolate->GetEnteredOrMicrotaskContext()).ToLocalChecked();
  421. c->modules_loaded[normalised_module_id].Reset(isolate, newobj);
  422. info.GetReturnValue().Set(newobj);
  423. efree(normalised_path);
  424. return;
  425. }
  426. // Convert the return value to string
  427. if (Z_TYPE(module_code) != IS_STRING) {
  428. convert_to_string(&module_code);
  429. }
  430. v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, c->context);
  431. // Catch JS exceptions
  432. v8::TryCatch try_catch(isolate);
  433. v8::Locker locker(isolate);
  434. v8::Isolate::Scope isolate_scope(isolate);
  435. v8::HandleScope handle_scope(isolate);
  436. // Enter the module context
  437. v8::Context::Scope scope(context);
  438. // Set script identifier
  439. v8::Local<v8::String> sname = V8JS_STR(normalised_module_id);
  440. v8::ScriptOrigin origin(sname);
  441. if (Z_STRLEN(module_code) > std::numeric_limits<int>::max()) {
  442. zend_throw_exception(php_ce_v8js_exception,
  443. "Module code size exceeds maximum supported length", 0);
  444. return;
  445. }
  446. v8::Local<v8::String> source = V8JS_ZSTR(Z_STR(module_code));
  447. zval_ptr_dtor(&module_code);
  448. source = v8::String::Concat(isolate, V8JS_SYM("(function (exports, module, require) {"), source);
  449. source = v8::String::Concat(isolate, source, V8JS_SYM("\n});"));
  450. // Create and compile script
  451. v8::MaybeLocal<v8::Script> script = v8::Script::Compile(context, source, &origin);
  452. // The script will be empty if there are compile errors
  453. if (script.IsEmpty()) {
  454. efree(normalised_module_id);
  455. efree(normalised_path);
  456. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module script compile failed")));
  457. return;
  458. }
  459. v8::Local<v8::String> base_path = V8JS_STR(normalised_path);
  460. v8::MaybeLocal<v8::Function> require_fn = v8::FunctionTemplate::New(isolate, V8JS_MN(require), base_path)->GetFunction(context);
  461. if (require_fn.IsEmpty()) {
  462. efree(normalised_path);
  463. efree(normalised_module_id);
  464. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Failed to create require method")));
  465. return;
  466. }
  467. // Add this module and path to the stack
  468. c->modules_stack.push_back(normalised_module_id);
  469. // Run script to evaluate closure
  470. v8::MaybeLocal<v8::Value> module_function = script.ToLocalChecked()->Run(context);
  471. // Prepare exports & module object
  472. v8::Local<v8::Object> exports = v8::Object::New(isolate);
  473. v8::Local<v8::Object> module = v8::Object::New(isolate);
  474. module->Set(context, V8JS_SYM("id"), V8JS_STR(normalised_module_id));
  475. module->Set(context, V8JS_SYM("exports"), exports);
  476. if (!module_function.IsEmpty() && module_function.ToLocalChecked()->IsFunction()) {
  477. v8::Local<v8::Value> *jsArgv = static_cast<v8::Local<v8::Value> *>(alloca(3 * sizeof(v8::Local<v8::Value>)));
  478. new(&jsArgv[0]) v8::Local<v8::Value>;
  479. jsArgv[0] = exports;
  480. new(&jsArgv[1]) v8::Local<v8::Value>;
  481. jsArgv[1] = module;
  482. new(&jsArgv[2]) v8::Local<v8::Value>;
  483. jsArgv[2] = require_fn.ToLocalChecked();
  484. // actually call the module
  485. v8::Local<v8::Function>::Cast(module_function.ToLocalChecked())->Call(context, exports, 3, jsArgv);
  486. }
  487. // Remove this module and path from the stack
  488. c->modules_stack.pop_back();
  489. efree(normalised_path);
  490. if (module_function.IsEmpty() || !module_function.ToLocalChecked()->IsFunction()) {
  491. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Wrapped module script failed to return function")));
  492. efree(normalised_module_id);
  493. return;
  494. }
  495. // Script possibly terminated, return immediately
  496. if (!try_catch.CanContinue()) {
  497. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Module script compile failed")));
  498. efree(normalised_module_id);
  499. return;
  500. }
  501. // Handle runtime JS exceptions
  502. if (try_catch.HasCaught()) {
  503. // Rethrow the exception back to JS
  504. info.GetReturnValue().Set(try_catch.ReThrow());
  505. efree(normalised_module_id);
  506. return;
  507. }
  508. v8::Local<v8::Value> newobj;
  509. // Cache the module so it doesn't need to be compiled and run again
  510. // Ensure compatibility with CommonJS implementations such as NodeJS by playing nicely with module.exports and exports
  511. v8::Local<v8::String> sym_exports = V8JS_SYM("exports");
  512. if (module->Has(context, sym_exports).FromMaybe(false))
  513. {
  514. module->Get(context, sym_exports).ToLocal(&newobj);
  515. }
  516. c->modules_loaded[normalised_module_id].Reset(isolate, newobj);
  517. info.GetReturnValue().Set(newobj);
  518. }
  519. void v8js_register_methods(v8::Local<v8::ObjectTemplate> global, v8js_ctx *c) /* {{{ */
  520. {
  521. v8::Isolate *isolate = c->isolate;
  522. global->Set(V8JS_SYM("exit"), v8::FunctionTemplate::New(isolate, V8JS_MN(exit)), v8::ReadOnly);
  523. global->Set(V8JS_SYM("sleep"), v8::FunctionTemplate::New(isolate, V8JS_MN(sleep)), v8::ReadOnly);
  524. global->Set(V8JS_SYM("print"), v8::FunctionTemplate::New(isolate, V8JS_MN(print)), v8::ReadOnly);
  525. global->Set(V8JS_SYM("var_dump"), v8::FunctionTemplate::New(isolate, V8JS_MN(var_dump)), v8::ReadOnly);
  526. v8::Local<v8::String> base_path = V8JS_STRL("", 0);
  527. global->Set(V8JS_SYM("require"), v8::FunctionTemplate::New(isolate, V8JS_MN(require), base_path), v8::ReadOnly);
  528. }
  529. /* }}} */
  530. /*
  531. * Local variables:
  532. * tab-width: 4
  533. * c-basic-offset: 4
  534. * indent-tabs-mode: t
  535. * End:
  536. * vim600: noet sw=4 ts=4 fdm=marker
  537. * vim<600: noet sw=4 ts=4
  538. */