v8js_object_export.cc 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  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_array_access.h"
  19. #include "v8js_exceptions.h"
  20. #include "v8js_generator_export.h"
  21. #include "v8js_object_export.h"
  22. #include "v8js_v8object_class.h"
  23. extern "C" {
  24. #include "ext/date/php_date.h"
  25. #include "ext/standard/php_string.h"
  26. #include "zend_interfaces.h"
  27. #include "zend_closures.h"
  28. #include "zend_exceptions.h"
  29. #include "zend_generators.h"
  30. }
  31. static void v8js_weak_object_callback(const v8::WeakCallbackInfo<zend_object> &data);
  32. /* Callback for PHP methods and functions */
  33. static void v8js_call_php_func(zend_object *object, zend_function *method_ptr, v8::Isolate *isolate, const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
  34. {
  35. v8::Local<v8::Value> return_value = V8JS_NULL;
  36. zend_fcall_info fci;
  37. zend_fcall_info_cache fcc;
  38. zval fname, retval;
  39. unsigned int argc = info.Length(), min_num_args = 0, max_num_args = 0;
  40. char *error;
  41. zend_ulong error_len;
  42. unsigned int i;
  43. v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
  44. /* Set parameter limits */
  45. min_num_args = method_ptr->common.required_num_args;
  46. max_num_args = method_ptr->common.num_args;
  47. /* Function name to call */
  48. ZVAL_STR_COPY(&fname, method_ptr->common.function_name);
  49. /* zend_fcall_info */
  50. fci.size = sizeof(fci);
  51. #if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 0)
  52. fci.function_table = &object->ce->function_table;
  53. fci.symbol_table = NULL;
  54. #endif
  55. fci.function_name = fname;
  56. fci.object = object;
  57. fci.retval = &retval;
  58. fci.param_count = 0;
  59. /* Check for passed vs required number of arguments */
  60. if (argc < min_num_args)
  61. {
  62. error_len = spprintf(&error, 0,
  63. "%s::%s() expects %s %d parameter%s, %d given",
  64. ZSTR_VAL(object->ce->name),
  65. ZSTR_VAL(method_ptr->common.function_name),
  66. min_num_args == max_num_args ? "exactly" : argc < min_num_args ? "at least" : "at most",
  67. argc < min_num_args ? min_num_args : max_num_args,
  68. (argc < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
  69. argc);
  70. if (error_len > std::numeric_limits<int>::max()) {
  71. zend_throw_exception(php_ce_v8js_exception,
  72. "Generated error message length exceeds maximum supported length", 0);
  73. }
  74. else {
  75. return_value = V8JS_THROW(isolate, TypeError, error, static_cast<int>(error_len));
  76. }
  77. if (object->ce == zend_ce_closure) {
  78. zend_string_release(method_ptr->internal_function.function_name);
  79. efree(method_ptr);
  80. }
  81. efree(error);
  82. info.GetReturnValue().Set(return_value);
  83. zval_ptr_dtor(&fname);
  84. return;
  85. }
  86. /* Convert parameters passed from V8 */
  87. if (argc) {
  88. fci.params = (zval *) safe_emalloc(argc, sizeof(zval), 0);
  89. for (i = 0; i < argc; i++) {
  90. if (info[i]->IsObject() && info[i]->ToObject()->InternalFieldCount() == 2) {
  91. /* This is a PHP object, passed to JS and back. */
  92. zend_object *object = reinterpret_cast<zend_object *>(info[i]->ToObject()->GetAlignedPointerFromInternalField(1));
  93. ZVAL_OBJ(&fci.params[i], object);
  94. Z_ADDREF_P(&fci.params[i]);
  95. } else {
  96. if (v8js_to_zval(info[i], &fci.params[i], ctx->flags, isolate) == FAILURE) {
  97. error_len = spprintf(&error, 0, "converting parameter #%d passed to %s() failed", i + 1, method_ptr->common.function_name);
  98. if (error_len > std::numeric_limits<int>::max()) {
  99. zend_throw_exception(php_ce_v8js_exception,
  100. "Generated error message length exceeds maximum supported length", 0);
  101. }
  102. else {
  103. return_value = V8JS_THROW(isolate, Error, error, static_cast<int>(error_len));
  104. }
  105. efree(error);
  106. goto failure;
  107. }
  108. }
  109. fci.param_count++;
  110. }
  111. } else {
  112. fci.params = NULL;
  113. }
  114. fci.no_separation = 1;
  115. info.GetReturnValue().Set(V8JS_NULL);
  116. {
  117. isolate->Exit();
  118. v8::Unlocker unlocker(isolate);
  119. zend_try {
  120. /* zend_fcall_info_cache */
  121. #if PHP_VERSION_ID < 70300
  122. fcc.initialized = 1;
  123. #endif
  124. fcc.function_handler = method_ptr;
  125. fcc.calling_scope = object->ce;
  126. fcc.called_scope = object->ce;
  127. fcc.object = object;
  128. zend_call_function(&fci, &fcc);
  129. }
  130. zend_catch {
  131. v8js_terminate_execution(isolate);
  132. V8JSG(fatal_error_abort) = 1;
  133. }
  134. zend_end_try();
  135. }
  136. isolate->Enter();
  137. failure:
  138. /* Cleanup */
  139. if (argc) {
  140. for (i = 0; i < fci.param_count; i++) {
  141. zval_ptr_dtor(&fci.params[i]);
  142. }
  143. efree(fci.params);
  144. }
  145. if(EG(exception)) {
  146. if(ctx->flags & V8JS_FLAG_PROPAGATE_PHP_EXCEPTIONS) {
  147. zval tmp_zv;
  148. ZVAL_OBJ(&tmp_zv, EG(exception));
  149. return_value = isolate->ThrowException(zval_to_v8js(&tmp_zv, isolate));
  150. zend_clear_exception();
  151. } else {
  152. v8js_terminate_execution(isolate);
  153. }
  154. } else if (Z_TYPE(retval) == IS_OBJECT && Z_OBJ(retval) == object) {
  155. // special case: "return $this"
  156. return_value = info.Holder();
  157. } else {
  158. return_value = zval_to_v8js(&retval, isolate);
  159. }
  160. zval_ptr_dtor(&retval);
  161. zval_ptr_dtor(&fname);
  162. info.GetReturnValue().Set(return_value);
  163. }
  164. /* }}} */
  165. /* Callback for PHP methods and functions */
  166. void v8js_php_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
  167. {
  168. v8::Isolate *isolate = info.GetIsolate();
  169. v8::Local<v8::Object> self = info.Holder();
  170. zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
  171. zend_function *method_ptr;
  172. /* Set method_ptr from v8::External or fetch the closure invoker */
  173. if (!info.Data().IsEmpty() && info.Data()->IsExternal()) {
  174. method_ptr = static_cast<zend_function *>(v8::External::Cast(*info.Data())->Value());
  175. } else {
  176. method_ptr = zend_get_closure_invoke_method(object);
  177. }
  178. return v8js_call_php_func(object, method_ptr, isolate, info);
  179. }
  180. /* Callback for PHP constructor calls */
  181. static void v8js_construct_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
  182. {
  183. v8::Isolate *isolate = info.GetIsolate();
  184. info.GetReturnValue().Set(V8JS_UNDEFINED);
  185. v8::Local<v8::Object> newobj = info.This();
  186. zval value;
  187. if (!info.IsConstructCall()) {
  188. return;
  189. }
  190. v8::Local<v8::Array> cons_data = v8::Local<v8::Array>::Cast(info.Data());
  191. v8::Local<v8::External> ext_tmpl = v8::Local<v8::External>::Cast(cons_data->Get(0));
  192. v8::Local<v8::External> ext_ce = v8::Local<v8::External>::Cast(cons_data->Get(1));
  193. v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
  194. if (info[0]->IsExternal()) {
  195. // Object created by v8js in v8js_hash_to_jsobj, PHP object passed as v8::External.
  196. v8::Local<v8::External> php_object = v8::Local<v8::External>::Cast(info[0]);
  197. zend_object *object = reinterpret_cast<zend_object *>(php_object->Value());
  198. ZVAL_OBJ(&value, object);
  199. if(ctx->weak_objects.count(object)) {
  200. // We already exported this object, hence no need to add another
  201. // ref, v8 won't give us a second weak-object callback anyways.
  202. newobj->SetAlignedPointerInInternalField(0, ext_tmpl->Value());
  203. newobj->SetAlignedPointerInInternalField(1, object);
  204. return;
  205. }
  206. // Increase the reference count of this value because we're storing it internally for use later
  207. // See https://github.com/phpv8/v8js/issues/6
  208. Z_ADDREF_P(&value);
  209. } else {
  210. // Object created from JavaScript context. Need to create PHP object first.
  211. zend_class_entry *ce = static_cast<zend_class_entry *>(ext_ce->Value());
  212. zend_function *ctor_ptr = ce->constructor;
  213. // Check access on __construct function, if any
  214. if (ctor_ptr != NULL && (ctor_ptr->common.fn_flags & ZEND_ACC_PUBLIC) == 0) {
  215. info.GetReturnValue().Set(isolate->ThrowException(V8JS_SYM("Call to protected __construct() not allowed")));
  216. return;
  217. }
  218. object_init_ex(&value, ce);
  219. // Call __construct function
  220. if (ctor_ptr != NULL) {
  221. v8js_call_php_func(Z_OBJ(value), ctor_ptr, isolate, info);
  222. }
  223. }
  224. newobj->SetAlignedPointerInInternalField(0, ext_tmpl->Value());
  225. newobj->SetAlignedPointerInInternalField(1, Z_OBJ(value));
  226. // Since we got to decrease the reference count again, in case v8 garbage collector
  227. // decides to dispose the JS object, we add a weak persistent handle and register
  228. // a callback function that removes the reference.
  229. ctx->weak_objects[Z_OBJ(value)].Reset(isolate, newobj);
  230. ctx->weak_objects[Z_OBJ(value)].SetWeak(Z_OBJ(value), v8js_weak_object_callback, v8::WeakCallbackType::kParameter);
  231. // Just tell v8 that we're allocating some external memory
  232. // (for the moment we just always tell 1k instead of trying to find out actual values)
  233. isolate->AdjustAmountOfExternalAllocatedMemory(ctx->average_object_size);
  234. }
  235. /* }}} */
  236. static void v8js_weak_object_callback(const v8::WeakCallbackInfo<zend_object> &data) {
  237. v8::Isolate *isolate = data.GetIsolate();
  238. zend_object *object = data.GetParameter();
  239. zval value;
  240. ZVAL_OBJ(&value, object);
  241. zval_ptr_dtor(&value);
  242. v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
  243. ctx->weak_objects.at(object).Reset();
  244. ctx->weak_objects.erase(object);
  245. isolate->AdjustAmountOfExternalAllocatedMemory(-ctx->average_object_size);
  246. }
  247. static void v8js_weak_closure_callback(const v8::WeakCallbackInfo<v8js_function_tmpl_t> &data) {
  248. v8::Isolate *isolate = data.GetIsolate();
  249. v8js_function_tmpl_t *persist_tpl_ = data.GetParameter();
  250. persist_tpl_->Reset();
  251. delete persist_tpl_;
  252. v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
  253. ctx->weak_closures.at(persist_tpl_).Reset();
  254. ctx->weak_closures.erase(persist_tpl_);
  255. };
  256. #define IS_MAGIC_FUNC(mname) \
  257. ((ZSTR_LEN(key) == sizeof(mname) - 1) && \
  258. !strncasecmp(ZSTR_VAL(key), mname, ZSTR_LEN(key)))
  259. #define PHP_V8JS_CALLBACK(isolate, mptr, tmpl) \
  260. v8::FunctionTemplate::New((isolate), v8js_php_callback, v8::External::New((isolate), mptr), v8::Signature::New((isolate), tmpl))->GetFunction()
  261. static void v8js_named_property_enumerator(const v8::PropertyCallbackInfo<v8::Array> &info) /* {{{ */
  262. {
  263. // note: 'special' properties like 'constructor' are not enumerated.
  264. v8::Isolate *isolate = info.GetIsolate();
  265. v8::Local<v8::Object> self = info.Holder();
  266. v8::Local<v8::Array> result = v8::Array::New(isolate, 0);
  267. uint32_t result_len = 0;
  268. zend_class_entry *ce;
  269. void *ptr;
  270. HashTable *proptable;
  271. zend_string *key;
  272. zend_ulong index;
  273. zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
  274. ce = object->ce;
  275. /* enumerate all methods */
  276. ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, key, ptr) {
  277. zend_function *method_ptr = reinterpret_cast<zend_function *>(ptr);
  278. if ((method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) == 0) {
  279. /* Allow only public methods */
  280. continue;
  281. }
  282. if ((method_ptr->common.fn_flags & (ZEND_ACC_CTOR|ZEND_ACC_DTOR)) != 0) {
  283. /* no __construct, __destruct(), or __clone() functions */
  284. continue;
  285. }
  286. // hide (do not enumerate) other PHP magic functions
  287. if (IS_MAGIC_FUNC(ZEND_CALLSTATIC_FUNC_NAME) ||
  288. IS_MAGIC_FUNC(ZEND_SLEEP_FUNC_NAME) ||
  289. IS_MAGIC_FUNC(ZEND_WAKEUP_FUNC_NAME) ||
  290. IS_MAGIC_FUNC(ZEND_SET_STATE_FUNC_NAME) ||
  291. IS_MAGIC_FUNC(ZEND_GET_FUNC_NAME) ||
  292. IS_MAGIC_FUNC(ZEND_SET_FUNC_NAME) ||
  293. IS_MAGIC_FUNC(ZEND_UNSET_FUNC_NAME) ||
  294. IS_MAGIC_FUNC(ZEND_CALL_FUNC_NAME) ||
  295. IS_MAGIC_FUNC(ZEND_INVOKE_FUNC_NAME) ||
  296. IS_MAGIC_FUNC(ZEND_ISSET_FUNC_NAME)) {
  297. continue;
  298. }
  299. v8::Local<v8::String> method_name;
  300. // rename PHP special method names to JS equivalents.
  301. if (IS_MAGIC_FUNC(ZEND_TOSTRING_FUNC_NAME)) {
  302. method_name = V8JS_SYM("toString");
  303. }
  304. else {
  305. if (ZSTR_LEN(method_ptr->common.function_name) > std::numeric_limits<int>::max()) {
  306. zend_throw_exception(php_ce_v8js_exception,
  307. "Method name length exceeds maximum supported length", 0);
  308. return;
  309. }
  310. method_name = V8JS_STRL(ZSTR_VAL(method_ptr->common.function_name), static_cast<int>(ZSTR_LEN(method_ptr->common.function_name)));
  311. }
  312. result->Set(result_len++, method_name);
  313. } ZEND_HASH_FOREACH_END();
  314. /* enumerate all properties */
  315. /* Z_OBJPROP uses the get_properties handler */
  316. zval tmp_zv;
  317. ZVAL_OBJ(&tmp_zv, object);
  318. proptable = Z_OBJPROP(tmp_zv);
  319. ZEND_HASH_FOREACH_KEY(proptable, index, key) {
  320. if(key) {
  321. /* skip protected and private members */
  322. if(ZSTR_VAL(key)[0] == '\0') {
  323. continue;
  324. }
  325. if (ZSTR_LEN(key) + 1 > std::numeric_limits<int>::max()) {
  326. zend_throw_exception(php_ce_v8js_exception,
  327. "Object key length exceeds maximum supported length", 0);
  328. continue;
  329. }
  330. // prefix enumerated property names with '$' so they can be
  331. // dereferenced unambiguously (ie, don't conflict with method
  332. // names)
  333. char *prefixed = static_cast<char *>(emalloc(ZSTR_LEN(key) + 2));
  334. prefixed[0] = '$';
  335. strncpy(prefixed + 1, ZSTR_VAL(key), ZSTR_LEN(key) + 1);
  336. result->Set(result_len++, V8JS_STRL(prefixed, static_cast<int>(ZSTR_LEN(key) + 1)));
  337. efree(prefixed);
  338. } else {
  339. // even numeric indices are enumerated as strings in JavaScript
  340. result->Set(result_len++, V8JS_FLOAT((double) index)->ToString());
  341. }
  342. } ZEND_HASH_FOREACH_END();
  343. /* done */
  344. info.GetReturnValue().Set(result);
  345. }
  346. /* }}} */
  347. static void v8js_invoke_callback(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
  348. {
  349. v8::Isolate *isolate = info.GetIsolate();
  350. v8::Local<v8::Object> self = info.Holder();
  351. v8::Local<v8::Function> cb = v8::Local<v8::Function>::Cast(info.Data());
  352. int argc = info.Length(), i;
  353. v8::Local<v8::Value> *argv = static_cast<v8::Local<v8::Value> *>(alloca(sizeof(v8::Local<v8::Value>) * argc));
  354. v8::Local<v8::Value> result;
  355. for (i=0; i<argc; i++) {
  356. new(&argv[i]) v8::Local<v8::Value>;
  357. argv[i] = info[i];
  358. }
  359. if (info.IsConstructCall()) {
  360. v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
  361. v8::Local<v8::String> str = self->GetConstructorName()->ToString();
  362. v8::String::Utf8Value str_value(str);
  363. zend_string *constructor_name = zend_string_init(ToCString(str_value), str->Utf8Length(), 0);
  364. zend_class_entry *ce = zend_lookup_class(constructor_name);
  365. zend_string_release(constructor_name);
  366. v8::Local<v8::FunctionTemplate> new_tpl;
  367. new_tpl = v8::Local<v8::FunctionTemplate>::New
  368. (isolate, ctx->template_cache.at(ce->name));
  369. v8::MaybeLocal<v8::Object> maybeResult = new_tpl->GetFunction()->NewInstance(isolate->GetEnteredContext(), argc, argv);
  370. if (!maybeResult.IsEmpty()) {
  371. result = maybeResult.ToLocalChecked();
  372. } else {
  373. result = V8JS_UNDEFINED;
  374. }
  375. } else {
  376. result = cb->Call(self, argc, argv);
  377. }
  378. info.GetReturnValue().Set(result);
  379. }
  380. /* }}} */
  381. // this is a magic '__call' implementation for PHP classes which don't actually
  382. // have a '__call' magic function. This way we can always force a method
  383. // call (as opposed to a property get) from JavaScript using __call.
  384. static void v8js_fake_call_impl(const v8::FunctionCallbackInfo<v8::Value>& info) /* {{{ */
  385. {
  386. v8::Isolate *isolate = info.GetIsolate();
  387. v8::Local<v8::Object> self = info.Holder();
  388. v8::Local<v8::Value> return_value = V8JS_NULL;
  389. char *error;
  390. size_t error_len;
  391. zend_class_entry *ce;
  392. zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
  393. ce = object->ce;
  394. // first arg is method name, second arg is array of args.
  395. if (info.Length() < 2) {
  396. error_len = spprintf(&error, 0,
  397. "%s::__call expects 2 parameters, %d given",
  398. ce->name, (int) info.Length());
  399. if (error_len > std::numeric_limits<int>::max()) {
  400. zend_throw_exception(php_ce_v8js_exception,
  401. "Generated error message length exceeds maximum supported length", 0);
  402. }
  403. else {
  404. return_value = V8JS_THROW(isolate, TypeError, error, static_cast<int>(error_len));
  405. }
  406. efree(error);
  407. info.GetReturnValue().Set(return_value);
  408. return;
  409. }
  410. if (!info[1]->IsArray()) {
  411. error_len = spprintf(&error, 0,
  412. "%s::__call expects 2nd parameter to be an array",
  413. ce->name);
  414. if (error_len > std::numeric_limits<int>::max()) {
  415. zend_throw_exception(php_ce_v8js_exception,
  416. "Generated error message length exceeds maximum supported length", 0);
  417. }
  418. else {
  419. return_value = V8JS_THROW(isolate, TypeError, error, static_cast<int>(error_len));
  420. }
  421. efree(error);
  422. info.GetReturnValue().Set(return_value);
  423. return;
  424. }
  425. v8::Local<v8::Array> args = v8::Local<v8::Array>::Cast(info[1]);
  426. if (args->Length() > 1000000) {
  427. // prevent overflow, since args->Length() is a uint32_t and args
  428. // in the Function->Call method below is a (signed) int.
  429. error_len = spprintf(&error, 0,
  430. "%s::__call expects fewer than a million arguments",
  431. ce->name);
  432. if (error_len > std::numeric_limits<int>::max()) {
  433. zend_throw_exception(php_ce_v8js_exception,
  434. "Generated error message length exceeds maximum supported length", 0);
  435. }
  436. else {
  437. return_value = V8JS_THROW(isolate, TypeError, error, static_cast<int>(error_len));
  438. }
  439. efree(error);
  440. info.GetReturnValue().Set(return_value);
  441. return;
  442. }
  443. v8::Local<v8::String> str = info[0]->ToString();
  444. v8::String::Utf8Value str_value(str);
  445. const char *method_c_name = ToCString(str_value);
  446. zend_string *method_name = zend_string_init(method_c_name, str->Utf8Length(), 0);
  447. // okay, look up the method name and manually invoke it.
  448. const zend_object_handlers *h = object->handlers;
  449. zend_function *method_ptr = h->get_method(&object, method_name, NULL);
  450. zend_string_release(method_name);
  451. if (method_ptr == NULL ||
  452. (method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) == 0 ||
  453. (method_ptr->common.fn_flags & (ZEND_ACC_CTOR|ZEND_ACC_DTOR)) != 0) {
  454. error_len = spprintf(&error, 0,
  455. "%s::__call to %s method %s", ce->name,
  456. (method_ptr == NULL) ? "undefined" : "non-public", method_name);
  457. if (error_len > std::numeric_limits<int>::max()) {
  458. zend_throw_exception(php_ce_v8js_exception,
  459. "Generated error message length exceeds maximum supported length", 0);
  460. }
  461. else {
  462. return_value = V8JS_THROW(isolate, TypeError, error, static_cast<int>(error_len));
  463. }
  464. efree(error);
  465. info.GetReturnValue().Set(return_value);
  466. return;
  467. }
  468. v8::Local<v8::FunctionTemplate> tmpl =
  469. v8::Local<v8::FunctionTemplate>::New
  470. (isolate, *reinterpret_cast<v8js_function_tmpl_t *>(self->GetAlignedPointerFromInternalField(0)));
  471. // use v8js_php_callback to actually execute the method
  472. v8::Local<v8::Function> cb = PHP_V8JS_CALLBACK(isolate, method_ptr, tmpl);
  473. uint32_t i, argc = args->Length();
  474. v8::Local<v8::Value> *argv = static_cast<v8::Local<v8::Value> *>(alloca(sizeof(v8::Local<v8::Value>) * argc));
  475. for (i=0; i<argc; i++) {
  476. new(&argv[i]) v8::Local<v8::Value>;
  477. argv[i] = args->Get(i);
  478. }
  479. return_value = cb->Call(info.This(), (int) argc, argv);
  480. info.GetReturnValue().Set(return_value);
  481. }
  482. /* }}} */
  483. /* This method handles named property and method get/set/query/delete. */
  484. template<typename T>
  485. v8::Local<v8::Value> v8js_named_property_callback(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<T> &info, property_op_t callback_type, v8::Local<v8::Value> set_value) /* {{{ */
  486. {
  487. v8::Isolate *isolate = info.GetIsolate();
  488. v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
  489. v8::String::Utf8Value cstr(property);
  490. const char *name = ToCString(cstr);
  491. uint name_len = property->Utf8Length();
  492. char *lower = estrndup(name, name_len);
  493. zend_string *method_name;
  494. v8::Local<v8::Object> self = info.Holder();
  495. v8::Local<v8::Value> ret_value;
  496. v8::Local<v8::Function> cb;
  497. zend_class_entry *scope, *ce;
  498. zend_function *method_ptr = NULL;
  499. zval php_value;
  500. zend_object *object = reinterpret_cast<zend_object *>(self->GetAlignedPointerFromInternalField(1));
  501. zval zobject;
  502. ZVAL_OBJ(&zobject, object);
  503. v8js_function_tmpl_t *tmpl_ptr = reinterpret_cast<v8js_function_tmpl_t *>(self->GetAlignedPointerFromInternalField(0));
  504. v8::Local<v8::FunctionTemplate> tmpl = v8::Local<v8::FunctionTemplate>::New(isolate, *tmpl_ptr);
  505. ce = scope = object->ce;
  506. /* First, check the (case-insensitive) method table */
  507. php_strtolower(lower, name_len);
  508. method_name = zend_string_init(lower, name_len, 0);
  509. // toString() -> __tostring()
  510. if (name_len == 8 && strcmp(name, "toString") == 0) {
  511. zend_string_release(method_name);
  512. method_name = zend_string_init(ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME) - 1, 0);
  513. }
  514. bool is_constructor = (name_len == 11 && strcmp(name, "constructor") == 0);
  515. bool is_magic_call = (ZSTR_LEN(method_name) == 6 && strcmp(ZSTR_VAL(method_name), "__call") == 0);
  516. if (is_constructor ||
  517. (name[0] != '$' /* leading '$' means property, not method */ &&
  518. (method_ptr = reinterpret_cast<zend_function *>
  519. (zend_hash_find_ptr(&ce->function_table, method_name))) &&
  520. ((method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) != 0) && /* Allow only public methods */
  521. ((method_ptr->common.fn_flags & (ZEND_ACC_CTOR|ZEND_ACC_DTOR)) == 0) /* no __construct, __destruct(), or __clone() functions */
  522. ) || (method_ptr=NULL, is_magic_call)
  523. ) {
  524. if (callback_type == V8JS_PROP_GETTER) {
  525. if (is_constructor) {
  526. // Don't set a return value here, i.e. indicate that we don't
  527. // have a special value. V8 "knows" the constructor anyways
  528. // (from the template) and will use that.
  529. } else {
  530. if (is_magic_call && method_ptr==NULL) {
  531. // Fake __call implementation
  532. // (only use this if method_ptr==NULL, which means
  533. // there is no actual PHP __call() implementation)
  534. v8::Local<v8::FunctionTemplate> ft;
  535. try {
  536. ft = v8::Local<v8::FunctionTemplate>::New
  537. (isolate, ctx->call_impls.at(tmpl_ptr));
  538. }
  539. catch (const std::out_of_range &) {
  540. ft = v8::FunctionTemplate::New(isolate,
  541. v8js_fake_call_impl, V8JS_NULL,
  542. v8::Signature::New(isolate, tmpl));
  543. v8js_function_tmpl_t *persistent_ft = &ctx->call_impls[tmpl_ptr];
  544. persistent_ft->Reset(isolate, ft);
  545. }
  546. v8::Local<v8::Function> cb = ft->GetFunction();
  547. cb->SetName(property);
  548. ret_value = cb;
  549. } else {
  550. v8::Local<v8::FunctionTemplate> ft;
  551. try {
  552. ft = v8::Local<v8::FunctionTemplate>::New
  553. (isolate, ctx->method_tmpls.at(method_ptr));
  554. }
  555. catch (const std::out_of_range &) {
  556. ft = v8::FunctionTemplate::New(isolate, v8js_php_callback,
  557. v8::External::New((isolate), method_ptr),
  558. v8::Signature::New((isolate), tmpl));
  559. v8js_function_tmpl_t *persistent_ft = &ctx->method_tmpls[method_ptr];
  560. persistent_ft->Reset(isolate, ft);
  561. }
  562. ret_value = ft->GetFunction();
  563. }
  564. }
  565. } else if (callback_type == V8JS_PROP_QUERY) {
  566. ret_value = V8JS_UINT(v8::ReadOnly|v8::DontDelete);
  567. } else if (callback_type == V8JS_PROP_SETTER) {
  568. ret_value = set_value; // lie. this field is read-only.
  569. } else if (callback_type == V8JS_PROP_DELETER) {
  570. ret_value = V8JS_BOOL(false);
  571. } else {
  572. /* shouldn't reach here! but bail safely */
  573. ret_value = v8::Local<v8::Value>();
  574. }
  575. } else {
  576. if (name[0]=='$') {
  577. // this is a property (not a method)
  578. name++; name_len--;
  579. }
  580. zval zname;
  581. ZVAL_STRINGL(&zname, name, name_len);
  582. if (callback_type == V8JS_PROP_GETTER) {
  583. /* Nope, not a method -- must be a (case-sensitive) property */
  584. zend_property_info *property_info = zend_get_property_info(ce, Z_STR(zname), 1);
  585. if(!property_info ||
  586. (property_info != ZEND_WRONG_PROPERTY_INFO &&
  587. property_info->flags & ZEND_ACC_PUBLIC)) {
  588. zval *property_val = zend_read_property(NULL, &zobject, name, name_len, true, &php_value);
  589. // special case uninitialized_zval_ptr and return an empty value
  590. // (indicating that we don't intercept this property) if the
  591. // property doesn't exist.
  592. if (property_val == &EG(uninitialized_zval)) {
  593. ret_value = v8::Local<v8::Value>();
  594. } else {
  595. // wrap it
  596. ret_value = zval_to_v8js(property_val, isolate);
  597. /* We don't own the reference to php_value... unless the
  598. * returned refcount was 0, in which case the below code
  599. * will free it. */
  600. zval_add_ref(property_val);
  601. zval_ptr_dtor(property_val);
  602. }
  603. }
  604. else if (ce->__get
  605. /* Allow only public methods */
  606. && ((ce->__get->common.fn_flags & ZEND_ACC_PUBLIC) != 0)) {
  607. /* Okay, let's call __get. */
  608. zend_call_method_with_1_params(&zobject, ce, &ce->__get, ZEND_GET_FUNC_NAME, &php_value, &zname);
  609. ret_value = zval_to_v8js(&php_value, isolate);
  610. zval_ptr_dtor(&php_value);
  611. }
  612. } else if (callback_type == V8JS_PROP_SETTER) {
  613. if (v8js_to_zval(set_value, &php_value, ctx->flags, isolate) != SUCCESS) {
  614. ret_value = v8::Local<v8::Value>();
  615. }
  616. else {
  617. zend_property_info *property_info = zend_get_property_info(ce, Z_STR(zname), 1);
  618. if(!property_info ||
  619. (property_info != ZEND_WRONG_PROPERTY_INFO &&
  620. property_info->flags & ZEND_ACC_PUBLIC)) {
  621. zend_update_property(scope, &zobject, name, name_len, &php_value);
  622. ret_value = set_value;
  623. }
  624. else if (ce->__set
  625. /* Allow only public methods */
  626. && ((ce->__set->common.fn_flags & ZEND_ACC_PUBLIC) != 0)) {
  627. /* Okay, let's call __set. */
  628. zval php_ret_value;
  629. zend_call_method_with_2_params(&zobject, ce, &ce->__set, ZEND_SET_FUNC_NAME, &php_ret_value, &zname, &php_value);
  630. ret_value = zval_to_v8js(&php_ret_value, isolate);
  631. zval_ptr_dtor(&php_ret_value);
  632. }
  633. }
  634. // if PHP wanted to hold on to this value, update_property would
  635. // have bumped the refcount
  636. zval_ptr_dtor(&php_value);
  637. } else if (callback_type == V8JS_PROP_QUERY ||
  638. callback_type == V8JS_PROP_DELETER) {
  639. const zend_object_handlers *h = object->handlers;
  640. if (callback_type == V8JS_PROP_QUERY) {
  641. if (h->has_property(&zobject, &zname, 0, NULL)) {
  642. ret_value = V8JS_UINT(v8::None);
  643. } else {
  644. ret_value = v8::Local<v8::Value>(); // empty handle
  645. }
  646. } else {
  647. zend_property_info *property_info = zend_get_property_info(ce, Z_STR(zname), 1);
  648. if(!property_info ||
  649. (property_info != ZEND_WRONG_PROPERTY_INFO &&
  650. property_info->flags & ZEND_ACC_PUBLIC)) {
  651. h->unset_property(&zobject, &zname, NULL);
  652. ret_value = V8JS_TRUE();
  653. }
  654. else {
  655. ret_value = v8::Local<v8::Value>(); // empty handle
  656. }
  657. }
  658. } else {
  659. /* shouldn't reach here! but bail safely */
  660. ret_value = v8::Local<v8::Value>();
  661. }
  662. zval_ptr_dtor(&zname);
  663. }
  664. zend_string_release(method_name);
  665. efree(lower);
  666. return ret_value;
  667. }
  668. /* }}} */
  669. static void v8js_named_property_getter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
  670. {
  671. info.GetReturnValue().Set(v8js_named_property_callback(property, info, V8JS_PROP_GETTER));
  672. }
  673. /* }}} */
  674. static void v8js_named_property_setter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<v8::Value> &info) /* {{{ */
  675. {
  676. info.GetReturnValue().Set(v8js_named_property_callback(property, info, V8JS_PROP_SETTER, value));
  677. }
  678. /* }}} */
  679. static void v8js_named_property_query(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Integer> &info) /* {{{ */
  680. {
  681. v8::Local<v8::Value> r = v8js_named_property_callback(property, info, V8JS_PROP_QUERY);
  682. if (!r.IsEmpty()) {
  683. info.GetReturnValue().Set(r->ToInteger());
  684. }
  685. }
  686. /* }}} */
  687. static void v8js_named_property_deleter(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Boolean> &info) /* {{{ */
  688. {
  689. v8::Local<v8::Value> r = v8js_named_property_callback(property, info, V8JS_PROP_DELETER);
  690. if (!r.IsEmpty()) {
  691. info.GetReturnValue().Set(r->ToBoolean());
  692. }
  693. }
  694. /* }}} */
  695. static v8::MaybeLocal<v8::Object> v8js_wrap_object(v8::Isolate *isolate, zend_class_entry *ce, zval *value) /* {{{ */
  696. {
  697. v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
  698. v8::Local<v8::FunctionTemplate> new_tpl;
  699. v8js_function_tmpl_t *persist_tpl_;
  700. try {
  701. new_tpl = v8::Local<v8::FunctionTemplate>::New
  702. (isolate, ctx->template_cache.at(ce->name));
  703. }
  704. catch (const std::out_of_range &) {
  705. /* No cached v8::FunctionTemplate available as of yet, create one. */
  706. new_tpl = v8::FunctionTemplate::New(isolate, 0);
  707. if (ZSTR_LEN(ce->name) > std::numeric_limits<int>::max()) {
  708. zend_throw_exception(php_ce_v8js_exception,
  709. "Class name length exceeds maximum supported length", 0);
  710. return v8::Local<v8::Object>();
  711. }
  712. new_tpl->SetClassName(V8JS_STRL(ZSTR_VAL(ce->name), static_cast<int>(ZSTR_LEN(ce->name))));
  713. new_tpl->InstanceTemplate()->SetInternalFieldCount(2);
  714. if (ce == zend_ce_closure) {
  715. /* Got a closure, mustn't cache ... */
  716. persist_tpl_ = new v8js_function_tmpl_t(isolate, new_tpl);
  717. /* We'll free persist_tpl_ via v8js_weak_closure_callback, below */
  718. new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(v8js_php_callback);
  719. } else {
  720. /* Add new v8::FunctionTemplate to tpl_map, as long as it is not a closure. */
  721. persist_tpl_ = &ctx->template_cache[ce->name];
  722. persist_tpl_->Reset(isolate, new_tpl);
  723. /* We'll free persist_tpl_ when template_cache is destroyed */
  724. v8::Local<v8::ObjectTemplate> inst_tpl = new_tpl->InstanceTemplate();
  725. v8::NamedPropertyGetterCallback getter = v8js_named_property_getter;
  726. v8::NamedPropertyEnumeratorCallback enumerator = v8js_named_property_enumerator;
  727. /* Check for ArrayAccess object */
  728. if (V8JSG(use_array_access) && ce) {
  729. bool has_array_access = false;
  730. bool has_countable = false;
  731. for (unsigned int i = 0; i < ce->num_interfaces; i ++) {
  732. if (strcmp (ZSTR_VAL(ce->interfaces[i]->name), "ArrayAccess") == 0) {
  733. has_array_access = true;
  734. }
  735. else if (strcmp (ZSTR_VAL(ce->interfaces[i]->name), "Countable") == 0) {
  736. has_countable = true;
  737. }
  738. }
  739. if(has_array_access && has_countable) {
  740. inst_tpl->SetIndexedPropertyHandler(v8js_array_access_getter,
  741. v8js_array_access_setter,
  742. v8js_array_access_query,
  743. v8js_array_access_deleter,
  744. v8js_array_access_enumerator);
  745. /* Switch to special ArrayAccess getter, which falls back to
  746. * v8js_named_property_getter, but possibly bridges the
  747. * call to Array.prototype functions. */
  748. getter = v8js_array_access_named_getter;
  749. /* Overwrite enumerator, since for(... in ...) loop should
  750. * not see the methods but iterate over the elements. */
  751. enumerator = 0;
  752. }
  753. }
  754. // Finish setup of new_tpl
  755. inst_tpl->SetNamedPropertyHandler
  756. (getter, /* getter */
  757. v8js_named_property_setter, /* setter */
  758. v8js_named_property_query, /* query */
  759. v8js_named_property_deleter, /* deleter */
  760. enumerator, /* enumerator */
  761. V8JS_NULL /* data */
  762. );
  763. // add __invoke() handler
  764. zend_string *invoke_str = zend_string_init
  765. (ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME) - 1, 0);
  766. zend_function *invoke_method_ptr = reinterpret_cast<zend_function *>
  767. (zend_hash_find_ptr(&ce->function_table, invoke_str));
  768. if (invoke_method_ptr &&
  769. invoke_method_ptr->common.fn_flags & ZEND_ACC_PUBLIC) {
  770. new_tpl->InstanceTemplate()->SetCallAsFunctionHandler(v8js_invoke_callback, PHP_V8JS_CALLBACK(isolate, invoke_method_ptr, new_tpl));
  771. }
  772. zend_string_release(invoke_str);
  773. }
  774. v8::Local<v8::Array> call_handler_data = v8::Array::New(isolate, 2);
  775. call_handler_data->Set(0, v8::External::New(isolate, persist_tpl_));
  776. call_handler_data->Set(1, v8::External::New(isolate, ce));
  777. new_tpl->SetCallHandler(v8js_construct_callback, call_handler_data);
  778. }
  779. // Create v8 wrapper object
  780. v8::Local<v8::Value> external = v8::External::New(isolate, Z_OBJ_P(value));
  781. v8::MaybeLocal<v8::Object> newobj = new_tpl->GetFunction()->NewInstance(isolate->GetEnteredContext(), 1, &external);
  782. if (ce == zend_ce_closure && !newobj.IsEmpty()) {
  783. // free uncached function template when object is freed
  784. ctx->weak_closures[persist_tpl_].Reset(isolate, newobj.ToLocalChecked());
  785. ctx->weak_closures[persist_tpl_].SetWeak(persist_tpl_, v8js_weak_closure_callback, v8::WeakCallbackType::kParameter);
  786. }
  787. return newobj;
  788. }
  789. /* }}} */
  790. static v8::Local<v8::Object> v8js_wrap_array_to_object(v8::Isolate *isolate, zval *value) /* {{{ */
  791. {
  792. int i;
  793. zend_string *key;
  794. zend_ulong index;
  795. v8js_ctx *ctx = (v8js_ctx *) isolate->GetData(0);
  796. v8::Local<v8::FunctionTemplate> new_tpl;
  797. if(ctx->array_tmpl.IsEmpty()) {
  798. new_tpl = v8::FunctionTemplate::New(isolate, 0);
  799. /* Call it Array, but it is not a native array, especially it doesn't have
  800. * have the typical Array.prototype functions. */
  801. new_tpl->SetClassName(V8JS_SYM("Array"));
  802. /* Store for later re-use */
  803. ctx->array_tmpl.Reset(isolate, new_tpl);
  804. }
  805. else {
  806. new_tpl = v8::Local<v8::FunctionTemplate>::New(isolate, ctx->array_tmpl);
  807. }
  808. v8::Local<v8::Object> newobj = new_tpl->InstanceTemplate()->NewInstance();
  809. HashTable *myht = HASH_OF(value);
  810. i = myht ? zend_hash_num_elements(myht) : 0;
  811. if (i > 0)
  812. {
  813. zval *data;
  814. #if PHP_VERSION_ID >= 70300
  815. if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) {
  816. #else
  817. if (myht) {
  818. #endif
  819. GC_PROTECT_RECURSION(myht);
  820. }
  821. ZEND_HASH_FOREACH_KEY_VAL(myht, index, key, data) {
  822. if (key) {
  823. if (ZSTR_VAL(key)[0] == '\0' && Z_TYPE_P(value) == IS_OBJECT) {
  824. /* Skip protected and private members. */
  825. continue;
  826. }
  827. if (ZSTR_LEN(key) > std::numeric_limits<int>::max()) {
  828. zend_throw_exception(php_ce_v8js_exception,
  829. "Object key length exceeds maximum supported length", 0);
  830. continue;
  831. }
  832. newobj->Set(V8JS_STRL(ZSTR_VAL(key), static_cast<int>(ZSTR_LEN(key))),
  833. zval_to_v8js(data, isolate));
  834. } else {
  835. if (index > std::numeric_limits<uint32_t>::max()) {
  836. zend_throw_exception(php_ce_v8js_exception,
  837. "Array index exceeds maximum supported bound", 0);
  838. continue;
  839. }
  840. newobj->Set(static_cast<uint32_t>(index), zval_to_v8js(data, isolate));
  841. }
  842. } ZEND_HASH_FOREACH_END();
  843. #if PHP_VERSION_ID >= 70300
  844. if (myht && !(GC_FLAGS(myht) & GC_IMMUTABLE)) {
  845. #else
  846. if (myht) {
  847. #endif
  848. GC_UNPROTECT_RECURSION(myht);
  849. }
  850. }
  851. return newobj;
  852. }
  853. /* }}} */
  854. v8::Local<v8::Value> v8js_hash_to_jsobj(zval *value, v8::Isolate *isolate) /* {{{ */
  855. {
  856. HashTable *myht;
  857. zend_class_entry *ce = NULL;
  858. if (Z_TYPE_P(value) == IS_ARRAY) {
  859. myht = HASH_OF(value);
  860. } else {
  861. myht = Z_OBJPROP_P(value);
  862. ce = Z_OBJCE_P(value);
  863. }
  864. /* Prevent recursion */
  865. #if PHP_VERSION_ID >= 70300
  866. if (myht && GC_IS_RECURSIVE(myht)) {
  867. #else
  868. if (myht && ZEND_HASH_GET_APPLY_COUNT(myht) > 1) {
  869. #endif
  870. return V8JS_NULL;
  871. }
  872. /* Special case, passing back object originating from JS to JS */
  873. if (ce == php_ce_v8function || ce == php_ce_v8object || ce == php_ce_v8generator) {
  874. v8js_v8object *c = Z_V8JS_V8OBJECT_OBJ_P(value);
  875. if(isolate != c->ctx->isolate) {
  876. php_error_docref(NULL, E_WARNING, "V8Function object passed to wrong V8Js instance");
  877. return V8JS_NULL;
  878. }
  879. return v8::Local<v8::Value>::New(isolate, c->v8obj);
  880. }
  881. /* If it's a PHP object, wrap it */
  882. if (ce) {
  883. v8::MaybeLocal<v8::Object> wrapped_object = v8js_wrap_object(isolate, ce, value);
  884. if (wrapped_object.IsEmpty()) {
  885. return V8JS_UNDEFINED;
  886. }
  887. if (ce == zend_ce_generator) {
  888. /* Wrap PHP Generator object in a wrapper function that provides
  889. * ES6 style behaviour. */
  890. return v8js_wrap_generator(isolate, wrapped_object.ToLocalChecked());
  891. }
  892. return wrapped_object.ToLocalChecked();
  893. }
  894. /* Associative PHP arrays cannot be wrapped to JS arrays, convert them to
  895. * JS objects and attach all their array keys as properties. */
  896. return v8js_wrap_array_to_object(isolate, value);
  897. }
  898. /* }}} */
  899. /*
  900. * Local variables:
  901. * tab-width: 4
  902. * c-basic-offset: 4
  903. * indent-tabs-mode: t
  904. * End:
  905. * vim600: noet sw=4 ts=4 fdm=marker
  906. * vim<600: noet sw=4 ts=4
  907. */