Guest User

Untitled

a guest
Jan 11th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.76 KB | None | 0 0
  1. # HG changeset patch
  2. # User hongzhidao <hongzhidao@gmail.com>
  3. # Date 1546891911 -28800
  4. # Node ID 91b36548e0b136d95b504b8da1cff9405fcadbac
  5. # Parent c3f59a9933a0e62f02d4a1f7a027b156766361e0
  6. Introduced njs_function_frame_activate.
  7.  
  8. diff -r c3f59a9933a0 -r 91b36548e0b1 njs/njs.c
  9. --- a/njs/njs.c Tue Jan 08 04:04:02 2019 +0800
  10. +++ b/njs/njs.c Tue Jan 08 04:11:51 2019 +0800
  11. @@ -464,48 +464,20 @@
  12. u_char *current;
  13. njs_ret_t ret;
  14. njs_value_t *this;
  15. - njs_continuation_t *cont;
  16. -
  17. - static const njs_vmcode_stop_t stop[] = {
  18. - { .code = { .operation = njs_vmcode_stop,
  19. - .operands = NJS_VMCODE_1OPERAND,
  20. - .retval = NJS_VMCODE_NO_RETVAL },
  21. - .retval = NJS_INDEX_GLOBAL_RETVAL },
  22. - };
  23.  
  24. this = (njs_value_t *) &njs_value_void;
  25.  
  26. current = vm->current;
  27. +
  28. + vm->current = (u_char *) njs_continuation_nexus;
  29.  
  30. - if (function->native) {
  31. - ret = njs_function_native_frame(vm, function, this, &args[0],
  32. - nargs, NJS_CONTINUATION_SIZE, 0);
  33. - if (ret != NJS_OK) {
  34. - return NJS_ERROR;
  35. - }
  36. + ret = njs_function_frame_activate(vm, function, this, args, nargs,
  37. + NJS_INDEX_GLOBAL_RETVAL,
  38. + sizeof(njs_vmcode_generic_t));
  39.  
  40. - cont = njs_vm_continuation(vm);
  41. -
  42. - cont->function = function->u.native;
  43. - cont->args_types = function->args_types;
  44. - cont->retval = NJS_INDEX_GLOBAL_RETVAL;
  45. -
  46. - cont->return_address = (u_char *) stop;
  47. - vm->current = (u_char *) njs_continuation_nexus;
  48. -
  49. - } else {
  50. - ret = njs_function_frame(vm, function, this, args, nargs, 0);
  51. - if (nxt_slow_path(ret != NXT_OK)) {
  52. - return ret;
  53. - }
  54. -
  55. - vm->current = (u_char *) stop;
  56. -
  57. - ret = njs_function_call(vm, NJS_INDEX_GLOBAL_RETVAL, 0);
  58. - if (nxt_slow_path(ret == NXT_ERROR)) {
  59. - return ret;
  60. - }
  61. - }
  62. + if (nxt_slow_path(ret == NXT_ERROR)) {
  63. + return ret;
  64. + }
  65.  
  66. ret = njs_vmcode_interpreter(vm);
  67.  
  68. diff -r c3f59a9933a0 -r 91b36548e0b1 njs/njs_function.c
  69. --- a/njs/njs_function.c Tue Jan 08 04:04:02 2019 +0800
  70. +++ b/njs/njs_function.c Tue Jan 08 04:11:51 2019 +0800
  71. @@ -978,9 +978,9 @@
  72. }
  73.  
  74.  
  75. -static njs_ret_t
  76. -njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
  77. - njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
  78. +njs_ret_t
  79. +njs_function_frame_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
  80. + const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval, size_t advance)
  81. {
  82. njs_ret_t ret;
  83. njs_continuation_t *cont;
  84. @@ -992,17 +992,13 @@
  85. return ret;
  86. }
  87.  
  88. - /* Skip the "call/apply" method frame. */
  89. - vm->top_frame->previous->skip = 1;
  90. -
  91. cont = njs_vm_continuation(vm);
  92.  
  93. cont->function = function->u.native;
  94. cont->args_types = function->args_types;
  95. cont->retval = retval;
  96.  
  97. - cont->return_address = vm->current
  98. - + sizeof(njs_vmcode_function_call_t);
  99. + cont->return_address = vm->current + advance;
  100. vm->current = (u_char *) njs_continuation_nexus;
  101.  
  102. return NJS_APPLIED;
  103. @@ -1014,10 +1010,26 @@
  104. return ret;
  105. }
  106.  
  107. + return njs_function_call(vm, retval, advance);
  108. +}
  109. +
  110. +
  111. +static njs_ret_t
  112. +njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
  113. + njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
  114. +{
  115. + njs_ret_t ret;
  116. +
  117. + ret = njs_function_frame_activate(vm, function, this, args, nargs, retval,
  118. + sizeof(njs_vmcode_function_call_t));
  119. + if (nxt_slow_path(ret == NXT_ERROR)) {
  120. + return ret;
  121. + }
  122. +
  123. /* Skip the "call/apply" method frame. */
  124. vm->top_frame->previous->skip = 1;
  125.  
  126. - return njs_function_call(vm, retval, sizeof(njs_vmcode_function_call_t));
  127. + return NJS_APPLIED;
  128. }
  129.  
  130.  
  131. diff -r c3f59a9933a0 -r 91b36548e0b1 njs/njs_function.h
  132. --- a/njs/njs_function.h Tue Jan 08 04:04:02 2019 +0800
  133. +++ b/njs/njs_function.h Tue Jan 08 04:11:51 2019 +0800
  134. @@ -170,6 +170,9 @@
  135. njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
  136. const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  137. nxt_bool_t ctor);
  138. +njs_ret_t njs_function_frame_activate(njs_vm_t *vm, njs_function_t *function,
  139. + njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  140. + njs_index_t retval, size_t advance);
  141. njs_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
  142. void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
  143. njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
  144. diff -r c3f59a9933a0 -r 91b36548e0b1 njs/njs_vm.c
  145. --- a/njs/njs_vm.c Tue Jan 08 04:04:02 2019 +0800
  146. +++ b/njs/njs_vm.c Tue Jan 08 04:11:51 2019 +0800
  147. @@ -2280,10 +2280,15 @@
  148. }
  149.  
  150.  
  151. -const njs_vmcode_1addr_t njs_continuation_nexus[] = {
  152. +const njs_vmcode_generic_t njs_continuation_nexus[] = {
  153. { .code = { .operation = njs_vmcode_continuation,
  154. .operands = NJS_VMCODE_NO_OPERAND,
  155. .retval = NJS_VMCODE_NO_RETVAL } },
  156. +
  157. + { .code = { .operation = njs_vmcode_stop,
  158. + .operands = NJS_VMCODE_1OPERAND,
  159. + .retval = NJS_VMCODE_NO_RETVAL },
  160. + .operand1 = NJS_INDEX_GLOBAL_RETVAL },
  161. };
  162.  
  163.  
  164. diff -r c3f59a9933a0 -r 91b36548e0b1 njs/njs_vm.h
  165. --- a/njs/njs_vm.h Tue Jan 08 04:04:02 2019 +0800
  166. +++ b/njs/njs_vm.h Tue Jan 08 04:11:51 2019 +0800
  167. @@ -1304,7 +1304,7 @@
  168. extern const nxt_mem_proto_t njs_array_mem_proto;
  169. extern const nxt_lvlhsh_proto_t njs_object_hash_proto;
  170.  
  171. -extern const njs_vmcode_1addr_t njs_continuation_nexus[];
  172. +extern const njs_vmcode_generic_t njs_continuation_nexus[];
  173.  
  174.  
  175. #endif /* _NJS_VM_H_INCLUDED_ */
  176.  
  177. # HG changeset patch
  178. # User hongzhidao <hongzhidao@gmail.com>
  179. # Date 1546893308 -28800
  180. # Node ID 929990ce284c91fcd8d908b31267ea6e9a2c4b2c
  181. # Parent 91b36548e0b136d95b504b8da1cff9405fcadbac
  182. Replace njs_function_frame_activate as njs_function_activate.
  183.  
  184. diff -r 91b36548e0b1 -r 929990ce284c njs/njs.c
  185. --- a/njs/njs.c Tue Jan 08 04:11:51 2019 +0800
  186. +++ b/njs/njs.c Tue Jan 08 04:35:08 2019 +0800
  187. @@ -471,9 +471,9 @@
  188.  
  189. vm->current = (u_char *) njs_continuation_nexus;
  190.  
  191. - ret = njs_function_frame_activate(vm, function, this, args, nargs,
  192. - NJS_INDEX_GLOBAL_RETVAL,
  193. - sizeof(njs_vmcode_generic_t));
  194. + ret = njs_function_activate(vm, function, this, args, nargs,
  195. + NJS_INDEX_GLOBAL_RETVAL,
  196. + sizeof(njs_vmcode_generic_t));
  197.  
  198. if (nxt_slow_path(ret == NXT_ERROR)) {
  199. return ret;
  200. diff -r 91b36548e0b1 -r 929990ce284c njs/njs_function.c
  201. --- a/njs/njs_function.c Tue Jan 08 04:11:51 2019 +0800
  202. +++ b/njs/njs_function.c Tue Jan 08 04:35:08 2019 +0800
  203. @@ -8,10 +8,6 @@
  204. #include <string.h>
  205.  
  206.  
  207. -static njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
  208. - njs_value_t *this, njs_value_t *args, nxt_uint_t nargs, njs_index_t retval);
  209. -
  210. -
  211. njs_function_t *
  212. njs_function_alloc(njs_vm_t *vm)
  213. {
  214. @@ -917,6 +913,7 @@
  215. njs_function_prototype_call(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
  216. njs_index_t retval)
  217. {
  218. + njs_ret_t ret;
  219. njs_value_t *this;
  220. njs_function_t *function;
  221.  
  222. @@ -936,7 +933,16 @@
  223.  
  224. function = args[0].data.u.function;
  225.  
  226. - return njs_function_activate(vm, function, this, &args[2], nargs, retval);
  227. + ret = njs_function_activate(vm, function, this, &args[2], nargs, retval,
  228. + sizeof(njs_vmcode_function_call_t));
  229. + if (nxt_slow_path(ret == NXT_ERROR)) {
  230. + return ret;
  231. + }
  232. +
  233. + /* Skip the "call" method frame. */
  234. + vm->top_frame->previous->skip = 1;
  235. +
  236. + return NJS_APPLIED;
  237. }
  238.  
  239.  
  240. @@ -944,6 +950,7 @@
  241. njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
  242. njs_index_t retval)
  243. {
  244. + njs_ret_t ret;
  245. njs_array_t *array;
  246. njs_value_t *this;
  247. njs_function_t *function;
  248. @@ -974,12 +981,21 @@
  249. nargs = 0;
  250. }
  251.  
  252. - return njs_function_activate(vm, function, this, args, nargs, retval);
  253. + ret = njs_function_activate(vm, function, this, args, nargs, retval,
  254. + sizeof(njs_vmcode_function_call_t));
  255. + if (nxt_slow_path(ret == NXT_ERROR)) {
  256. + return ret;
  257. + }
  258. +
  259. + /* Skip the "apply" method frame. */
  260. + vm->top_frame->previous->skip = 1;
  261. +
  262. + return NJS_APPLIED;
  263. }
  264.  
  265.  
  266. njs_ret_t
  267. -njs_function_frame_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
  268. +njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
  269. const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval, size_t advance)
  270. {
  271. njs_ret_t ret;
  272. @@ -1015,25 +1031,6 @@
  273.  
  274.  
  275. static njs_ret_t
  276. -njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
  277. - njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
  278. -{
  279. - njs_ret_t ret;
  280. -
  281. - ret = njs_function_frame_activate(vm, function, this, args, nargs, retval,
  282. - sizeof(njs_vmcode_function_call_t));
  283. - if (nxt_slow_path(ret == NXT_ERROR)) {
  284. - return ret;
  285. - }
  286. -
  287. - /* Skip the "call/apply" method frame. */
  288. - vm->top_frame->previous->skip = 1;
  289. -
  290. - return NJS_APPLIED;
  291. -}
  292. -
  293. -
  294. -static njs_ret_t
  295. njs_function_prototype_bind(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
  296. njs_index_t unused)
  297. {
  298. diff -r 91b36548e0b1 -r 929990ce284c njs/njs_function.h
  299. --- a/njs/njs_function.h Tue Jan 08 04:11:51 2019 +0800
  300. +++ b/njs/njs_function.h Tue Jan 08 04:35:08 2019 +0800
  301. @@ -170,7 +170,7 @@
  302. njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
  303. const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  304. nxt_bool_t ctor);
  305. -njs_ret_t njs_function_frame_activate(njs_vm_t *vm, njs_function_t *function,
  306. +njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
  307. njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  308. njs_index_t retval, size_t advance);
  309. njs_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
  310.  
  311. # HG changeset patch
  312. # User hongzhidao <hongzhidao@gmail.com>
  313. # Date 1546894940 -28800
  314. # Node ID 14f1b7a9748bec226c9b9e9711d273e96ffb69de
  315. # Parent 929990ce284c91fcd8d908b31267ea6e9a2c4b2c
  316. Style
  317.  
  318. diff -r 929990ce284c -r 14f1b7a9748b njs/njs.c
  319. --- a/njs/njs.c Tue Jan 08 04:35:08 2019 +0800
  320. +++ b/njs/njs.c Tue Jan 08 05:02:20 2019 +0800
  321. @@ -479,14 +479,10 @@
  322. return ret;
  323. }
  324.  
  325. - ret = njs_vmcode_interpreter(vm);
  326. + ret = njs_vm_start(vm);
  327.  
  328. vm->current = current;
  329.  
  330. - if (ret == NJS_STOP) {
  331. - ret = NXT_OK;
  332. - }
  333. -
  334. return ret;
  335. }
  336.  
  337. # HG changeset patch
  338. # User hongzhidao <hongzhidao@gmail.com>
  339. # Date 1546899276 -28800
  340. # Node ID 5e16c477ae3df08db0f146e540a62ea390e12b68
  341. # Parent 14f1b7a9748bec226c9b9e9711d273e96ffb69de
  342. 1) Fixed njs_vm_call.
  343. 2) Refactored njs_function_apply.
  344. 3) Style.
  345.  
  346. diff -r 14f1b7a9748b -r 5e16c477ae3d njs/njs.c
  347. --- a/njs/njs.c Tue Jan 08 05:02:20 2019 +0800
  348. +++ b/njs/njs.c Tue Jan 08 06:14:36 2019 +0800
  349. @@ -461,9 +461,9 @@
  350. njs_vm_call(njs_vm_t *vm, njs_function_t *function, const njs_value_t *args,
  351. nxt_uint_t nargs)
  352. {
  353. - u_char *current;
  354. - njs_ret_t ret;
  355. - njs_value_t *this;
  356. + u_char *current;
  357. + njs_ret_t ret;
  358. + njs_value_t *this;
  359.  
  360. this = (njs_value_t *) &njs_value_void;
  361.  
  362. @@ -476,11 +476,13 @@
  363. sizeof(njs_vmcode_generic_t));
  364.  
  365. if (nxt_slow_path(ret == NXT_ERROR)) {
  366. - return ret;
  367. - }
  368. + goto restore;
  369. + }
  370.  
  371. ret = njs_vm_start(vm);
  372.  
  373. +restore:
  374. +
  375. vm->current = current;
  376.  
  377. return ret;
  378. diff -r 14f1b7a9748b -r 5e16c477ae3d njs/njs_function.c
  379. --- a/njs/njs_function.c Tue Jan 08 05:02:20 2019 +0800
  380. +++ b/njs/njs_function.c Tue Jan 08 06:14:36 2019 +0800
  381. @@ -425,42 +425,6 @@
  382.  
  383.  
  384. nxt_noinline njs_ret_t
  385. -njs_function_apply(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
  386. - nxt_uint_t nargs, njs_index_t retval)
  387. -{
  388. - njs_ret_t ret;
  389. - njs_continuation_t *cont;
  390. -
  391. - if (function->native) {
  392. - ret = njs_function_native_frame(vm, function, &args[0], &args[1],
  393. - nargs - 1, NJS_CONTINUATION_SIZE, 0);
  394. - if (ret != NJS_OK) {
  395. - return ret;
  396. - }
  397. -
  398. - cont = njs_vm_continuation(vm);
  399. -
  400. - cont->function = function->u.native;
  401. - cont->args_types = function->args_types;
  402. - cont->retval = retval;
  403. -
  404. - cont->return_address = vm->current;
  405. - vm->current = (u_char *) njs_continuation_nexus;
  406. -
  407. - return NJS_APPLIED;
  408. - }
  409. -
  410. - ret = njs_function_frame(vm, function, &args[0], &args[1], nargs - 1, 0);
  411. -
  412. - if (nxt_fast_path(ret == NXT_OK)) {
  413. - return njs_function_call(vm, retval, 0);
  414. - }
  415. -
  416. - return ret;
  417. -}
  418. -
  419. -
  420. -nxt_noinline njs_ret_t
  421. njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
  422. {
  423. size_t size;
  424. @@ -995,8 +959,9 @@
  425.  
  426.  
  427. njs_ret_t
  428. -njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
  429. - const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval, size_t advance)
  430. +njs_function_activate(njs_vm_t *vm, njs_function_t *function,
  431. + njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  432. + njs_index_t retval, size_t advance)
  433. {
  434. njs_ret_t ret;
  435. njs_continuation_t *cont;
  436. diff -r 14f1b7a9748b -r 5e16c477ae3d njs/njs_function.h
  437. --- a/njs/njs_function.h Tue Jan 08 05:02:20 2019 +0800
  438. +++ b/njs/njs_function.h Tue Jan 08 06:14:36 2019 +0800
  439. @@ -162,8 +162,6 @@
  440. njs_value_t *value);
  441. njs_ret_t njs_function_constructor(njs_vm_t *vm, njs_value_t *args,
  442. nxt_uint_t nargs, njs_index_t unused);
  443. -njs_ret_t njs_function_apply(njs_vm_t *vm, njs_function_t *function,
  444. - njs_value_t *args, nxt_uint_t nargs, njs_index_t retval);
  445. njs_ret_t njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
  446. const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  447. size_t reserve, nxt_bool_t ctor);
  448. @@ -177,7 +175,8 @@
  449. void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
  450. njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
  451. njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
  452. - njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs, njs_index_t retval);
  453. + njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
  454. + njs_index_t retval);
  455.  
  456. extern const njs_object_init_t njs_function_constructor_init;
  457. extern const njs_object_init_t njs_function_prototype_init;
  458. @@ -188,4 +187,10 @@
  459. extern const njs_object_init_t njs_eval_function_init;
  460.  
  461.  
  462. +#define \
  463. +njs_function_apply(vm, function, args, nargs, retval) \
  464. + njs_function_activate(vm, function, &(args)[0], &(args)[1], (nargs - 1), \
  465. + retval, 0)
  466. +
  467. +
  468. #endif /* _NJS_FUNCTION_H_INCLUDED_ */
  469. diff -r 14f1b7a9748b -r 5e16c477ae3d njs/njs_vm.c
  470. --- a/njs/njs_vm.c Tue Jan 08 05:02:20 2019 +0800
  471. +++ b/njs/njs_vm.c Tue Jan 08 06:14:36 2019 +0800
  472. @@ -2055,8 +2055,9 @@
  473. return 0;
  474. }
  475.  
  476. - ret = njs_function_native_call(vm, function->u.native, args, function->args_types,
  477. - nargs, (njs_index_t ) retval);
  478. + ret = njs_function_native_call(vm, function->u.native, args,
  479. + function->args_types, nargs,
  480. + (njs_index_t ) retval);
  481.  
  482. switch (ret) {
  483. case NXT_OK:
  484. @@ -2286,9 +2287,9 @@
  485. .retval = NJS_VMCODE_NO_RETVAL } },
  486.  
  487. { .code = { .operation = njs_vmcode_stop,
  488. - .operands = NJS_VMCODE_1OPERAND,
  489. - .retval = NJS_VMCODE_NO_RETVAL },
  490. - .operand1 = NJS_INDEX_GLOBAL_RETVAL },
  491. + .operands = NJS_VMCODE_1OPERAND,
  492. + .retval = NJS_VMCODE_NO_RETVAL },
  493. + .operand1 = NJS_INDEX_GLOBAL_RETVAL },
  494. };
  495.  
  496. # HG changeset patch
  497. # User hongzhidao <hongzhidao@gmail.com>
  498. # Date 1546902264 -28800
  499. # Node ID 79ab6dfeb51be7b35b9bbb5d76ed443f5399305a
  500. # Parent 5e16c477ae3df08db0f146e540a62ea390e12b68
  501. Refactored function.
  502.  
  503. diff -r 5e16c477ae3d -r 79ab6dfeb51b njs/njs_function.c
  504. --- a/njs/njs_function.c Tue Jan 08 06:14:36 2019 +0800
  505. +++ b/njs/njs_function.c Tue Jan 08 07:04:24 2019 +0800
  506. @@ -262,7 +262,7 @@
  507.  
  508.  
  509. nxt_noinline njs_ret_t
  510. -njs_function_frame(njs_vm_t *vm, njs_function_t *function,
  511. +njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
  512. const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  513. nxt_bool_t ctor)
  514. {
  515. @@ -425,7 +425,7 @@
  516.  
  517.  
  518. nxt_noinline njs_ret_t
  519. -njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
  520. +njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
  521. {
  522. size_t size;
  523. njs_ret_t ret;
  524. @@ -985,13 +985,13 @@
  525. return NJS_APPLIED;
  526. }
  527.  
  528. - ret = njs_function_frame(vm, function, this, args, nargs, 0);
  529. + ret = njs_function_lambda_frame(vm, function, this, args, nargs, 0);
  530.  
  531. if (nxt_slow_path(ret != NXT_OK)) {
  532. return ret;
  533. }
  534.  
  535. - return njs_function_call(vm, retval, advance);
  536. + return njs_function_lambda_call(vm, retval, advance);
  537. }
  538.  
  539.  
  540. diff -r 5e16c477ae3d -r 79ab6dfeb51b njs/njs_function.h
  541. --- a/njs/njs_function.h Tue Jan 08 06:14:36 2019 +0800
  542. +++ b/njs/njs_function.h Tue Jan 08 07:04:24 2019 +0800
  543. @@ -162,21 +162,22 @@
  544. njs_value_t *value);
  545. njs_ret_t njs_function_constructor(njs_vm_t *vm, njs_value_t *args,
  546. nxt_uint_t nargs, njs_index_t unused);
  547. +
  548. +njs_ret_t njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
  549. + const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  550. + nxt_bool_t ctor);
  551. njs_ret_t njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
  552. const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  553. size_t reserve, nxt_bool_t ctor);
  554. -njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
  555. - const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  556. - nxt_bool_t ctor);
  557. njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
  558. njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  559. njs_index_t retval, size_t advance);
  560. -njs_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
  561. -void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
  562. -njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
  563. +njs_ret_t njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
  564. njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
  565. njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
  566. njs_index_t retval);
  567. +njs_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
  568. +void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
  569.  
  570. extern const njs_object_init_t njs_function_constructor_init;
  571. extern const njs_object_init_t njs_function_prototype_init;
  572. diff -r 5e16c477ae3d -r 79ab6dfeb51b njs/njs_vm.c
  573. --- a/njs/njs_vm.c Tue Jan 08 06:14:36 2019 +0800
  574. +++ b/njs/njs_vm.c Tue Jan 08 07:04:24 2019 +0800
  575. @@ -1878,7 +1878,8 @@
  576. this = &val;
  577. }
  578.  
  579. - return njs_function_frame(vm, function, this, NULL, nargs, ctor);
  580. + return njs_function_lambda_frame(vm, function, this, NULL,
  581. + nargs, ctor);
  582. }
  583.  
  584. if (!ctor || function->ctor) {
  585. @@ -2029,7 +2030,7 @@
  586. function = frame->function;
  587.  
  588. if (!function->native) {
  589. - ret = njs_function_call(vm, (njs_index_t) retval,
  590. + ret = njs_function_lambda_call(vm, (njs_index_t) retval,
  591. sizeof(njs_vmcode_function_call_t));
  592.  
  593. if (nxt_fast_path(ret != NJS_ERROR)) {
  594.  
  595. # HG changeset patch
  596. # User hongzhidao <hongzhidao@gmail.com>
  597. # Date 1546908100 -28800
  598. # Node ID 77baa7be10923e84058fddfb04b174d68ac33145
  599. # Parent 79ab6dfeb51be7b35b9bbb5d76ed443f5399305a
  600. Introduced njs_function_call.
  601.  
  602. diff -r 79ab6dfeb51b -r 77baa7be1092 njs/njs_function.c
  603. --- a/njs/njs_function.c Tue Jan 08 07:04:24 2019 +0800
  604. +++ b/njs/njs_function.c Tue Jan 08 08:41:40 2019 +0800
  605. @@ -8,6 +8,9 @@
  606. #include <string.h>
  607.  
  608.  
  609. +static njs_native_frame_t *njs_function_frame_alloc(njs_vm_t *vm, size_t size);
  610. +
  611. +
  612. njs_function_t *
  613. njs_function_alloc(njs_vm_t *vm)
  614. {
  615. @@ -208,59 +211,6 @@
  616. }
  617.  
  618.  
  619. -njs_ret_t
  620. -njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
  621. - const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  622. - size_t reserve, nxt_bool_t ctor)
  623. -{
  624. - size_t size;
  625. - nxt_uint_t n;
  626. - njs_value_t *value, *bound;
  627. - njs_native_frame_t *frame;
  628. -
  629. - reserve = nxt_max(reserve, function->continuation_size);
  630. -
  631. - size = NJS_NATIVE_FRAME_SIZE + reserve
  632. - + (function->args_offset + nargs) * sizeof(njs_value_t);
  633. -
  634. - frame = njs_function_frame_alloc(vm, size);
  635. - if (nxt_slow_path(frame == NULL)) {
  636. - return NXT_ERROR;
  637. - }
  638. -
  639. - frame->function = function;
  640. - frame->nargs = function->args_offset + nargs;
  641. - frame->ctor = ctor;
  642. -
  643. - value = (njs_value_t *) (njs_continuation(frame) + reserve);
  644. - frame->arguments = value;
  645. -
  646. - bound = function->bound;
  647. -
  648. - if (bound == NULL) {
  649. - /* GC: njs_retain(this); */
  650. - *value++ = *this;
  651. -
  652. - } else {
  653. - n = function->args_offset;
  654. -
  655. - do {
  656. - /* GC: njs_retain(bound); */
  657. - *value++ = *bound++;
  658. - n--;
  659. - } while (n != 0);
  660. - }
  661. -
  662. - vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = value;
  663. -
  664. - if (args != NULL) {
  665. - memcpy(value, args, nargs * sizeof(njs_value_t));
  666. - }
  667. -
  668. - return NXT_OK;
  669. -}
  670. -
  671. -
  672. nxt_noinline njs_ret_t
  673. njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
  674. const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  675. @@ -335,7 +285,60 @@
  676. }
  677.  
  678.  
  679. -nxt_noinline njs_native_frame_t *
  680. +njs_ret_t
  681. +njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
  682. + const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
  683. + size_t reserve, nxt_bool_t ctor)
  684. +{
  685. + size_t size;
  686. + nxt_uint_t n;
  687. + njs_value_t *value, *bound;
  688. + njs_native_frame_t *frame;
  689. +
  690. + reserve = nxt_max(reserve, function->continuation_size);
  691. +
  692. + size = NJS_NATIVE_FRAME_SIZE + reserve
  693. + + (function->args_offset + nargs) * sizeof(njs_value_t);
  694. +
  695. + frame = njs_function_frame_alloc(vm, size);
  696. + if (nxt_slow_path(frame == NULL)) {
  697. + return NXT_ERROR;
  698. + }
  699. +
  700. + frame->function = function;
  701. + frame->nargs = function->args_offset + nargs;
  702. + frame->ctor = ctor;
  703. +
  704. + value = (njs_value_t *) (njs_continuation(frame) + reserve);
  705. + frame->arguments = value;
  706. +
  707. + bound = function->bound;
  708. +
  709. + if (bound == NULL) {
  710. + /* GC: njs_retain(this); */
  711. + *value++ = *this;
  712. +
  713. + } else {
  714. + n = function->args_offset;
  715. +
  716. + do {
  717. + /* GC: njs_retain(bound); */
  718. + *value++ = *bound++;
  719. + n--;
  720. + } while (n != 0);
  721. + }
  722. +
  723. + vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = value;
  724. +
  725. + if (args != NULL) {
  726. + memcpy(value, args, nargs * sizeof(njs_value_t));
  727. + }
  728. +
  729. + return NXT_OK;
  730. +}
  731. +
  732. +
  733. +static njs_native_frame_t *
  734. njs_function_frame_alloc(njs_vm_t *vm, size_t size)
  735. {
  736. size_t spare_size, chunk_size;
  737. @@ -966,13 +969,14 @@
  738. njs_ret_t ret;
  739. njs_continuation_t *cont;
  740.  
  741. + ret = njs_function_frame(vm, function, this, args, nargs,
  742. + NJS_CONTINUATION_SIZE, 0);
  743. +
  744. + if (nxt_slow_path(ret != NXT_OK)) {
  745. + return ret;
  746. + }
  747. +
  748. if (function->native) {
  749. - ret = njs_function_native_frame(vm, function, this, args, nargs,
  750. - NJS_CONTINUATION_SIZE, 0);
  751. - if (nxt_slow_path(ret != NXT_OK)) {
  752. - return ret;
  753. - }
  754. -
  755. cont = njs_vm_continuation(vm);
  756.  
  757. cont->function = function->u.native;
  758. @@ -985,12 +989,6 @@
  759. return NJS_APPLIED;
  760. }
  761.  
  762. - ret = njs_function_lambda_frame(vm, function, this, args, nargs, 0);
  763. -
  764. - if (nxt_slow_path(ret != NXT_OK)) {
  765. - return ret;
  766. - }
  767. -
  768. return njs_function_lambda_call(vm, retval, advance);
  769. }
  770.  
  771. diff -r 79ab6dfeb51b -r 77baa7be1092 njs/njs_function.h
  772. --- a/njs/njs_function.h Tue Jan 08 07:04:24 2019 +0800
  773. +++ b/njs/njs_function.h Tue Jan 08 08:41:40 2019 +0800
  774. @@ -149,7 +149,6 @@
  775.  
  776. njs_function_t *njs_function_alloc(njs_vm_t *vm);
  777. njs_function_t *njs_function_value_copy(njs_vm_t *vm, njs_value_t *value);
  778. -njs_native_frame_t *njs_function_frame_alloc(njs_vm_t *vm, size_t size);
  779. njs_ret_t njs_function_arguments_object_init(njs_vm_t *vm,
  780. njs_native_frame_t *frame);
  781. njs_ret_t njs_function_rest_parameters_init(njs_vm_t *vm,
  782. @@ -194,4 +193,11 @@
  783. retval, 0)
  784.  
  785.  
  786. +#define \
  787. +njs_function_frame(vm, function, this, args, nargs, reserve, ctor) \
  788. + ((function)->native ? \
  789. + njs_function_native_frame(vm, function, this, args, nargs, reserve, ctor) \
  790. + : njs_function_lambda_frame(vm, function, this, args, nargs, ctor))
  791. +
  792. +
  793. #endif /* _NJS_FUNCTION_H_INCLUDED_ */
  794. diff -r 79ab6dfeb51b -r 77baa7be1092 njs/njs_vm.c
  795. --- a/njs/njs_vm.c Tue Jan 08 07:04:24 2019 +0800
  796. +++ b/njs/njs_vm.c Tue Jan 08 08:41:40 2019 +0800
  797. @@ -1864,9 +1864,15 @@
  798.  
  799. function = value->data.u.function;
  800.  
  801. - if (!function->native) {
  802. -
  803. - if (ctor) {
  804. + if (ctor) {
  805. + if (function->native) {
  806. + if (!function->ctor) {
  807. + njs_type_error(vm, "%s is not a constructor",
  808. + njs_type_string(value->type));
  809. + return NXT_ERROR;
  810. + }
  811. +
  812. + } else {
  813. object = njs_function_new_object(vm, value);
  814. if (nxt_slow_path(object == NULL)) {
  815. return NXT_ERROR;
  816. @@ -1877,20 +1883,9 @@
  817. val.data.truth = 1;
  818. this = &val;
  819. }
  820. -
  821. - return njs_function_lambda_frame(vm, function, this, NULL,
  822. - nargs, ctor);
  823. }
  824.  
  825. - if (!ctor || function->ctor) {
  826. - return njs_function_native_frame(vm, function, this, NULL,
  827. - nargs, 0, ctor);
  828. - }
  829. -
  830. - njs_type_error(vm, "%s is not a constructor",
  831. - njs_type_string(value->type));
  832. -
  833. - return NXT_ERROR;
  834. + return njs_function_frame(vm, function, this, NULL, nargs, 0, ctor);
  835. }
  836.  
  837. njs_type_error(vm, "%s is not a function", njs_type_string(value->type));
Add Comment
Please, Sign In to add comment