Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.38 KB | None | 0 0
  1. diff -r 0cfc9e7f4b68 njs/njs_value.c
  2. --- a/njs/njs_value.c Fri Jul 05 21:45:28 2019 +0300
  3. +++ b/njs/njs_value.c Wed Jul 10 04:52:37 2019 -0400
  4. @@ -173,7 +173,7 @@ njs_value_to_primitive(njs_vm_t *vm, njs
  5. nxt_uint_t hint)
  6. {
  7. njs_ret_t ret;
  8. - nxt_uint_t trap_tries;
  9. + nxt_uint_t tries;
  10. njs_value_t retval;
  11. njs_object_prop_t *prop;
  12. nxt_lvlhsh_query_t lhq;
  13. @@ -195,13 +195,13 @@ njs_value_to_primitive(njs_vm_t *vm, njs
  14. return NXT_OK;
  15. }
  16.  
  17. - trap_tries = 0;
  18. + tries = 0;
  19.  
  20. for ( ;; ) {
  21. ret = NXT_ERROR;
  22.  
  23. - if (njs_is_object(value) && trap_tries < 2) {
  24. - hint ^= trap_tries++;
  25. + if (njs_is_object(value) && tries < 2) {
  26. + hint ^= tries++;
  27.  
  28. lhq.key_hash = hashes[hint];
  29. lhq.key = names[hint];
  30. diff -r 0cfc9e7f4b68 njs/njs_vm.c
  31. --- a/njs/njs_vm.c Fri Jul 05 21:45:28 2019 +0300
  32. +++ b/njs/njs_vm.c Wed Jul 10 04:52:37 2019 -0400
  33. @@ -127,6 +127,8 @@ start:
  34.  
  35. for ( ;; ) {
  36. frame = (njs_frame_t *) vm->top_frame;
  37. +
  38. + call = frame->native.call;
  39. catch = frame->native.exception.catch;
  40.  
  41. if (catch != NULL) {
  42. @@ -152,8 +154,6 @@ start:
  43.  
  44. njs_vm_scopes_restore(vm, frame, previous);
  45.  
  46. - call = frame->native.call;
  47. -
  48. if (frame->native.size != 0) {
  49. vm->stack_size -= frame->native.size;
  50. nxt_mp_free(vm->mem_pool, frame);
  51. @@ -162,7 +162,6 @@ start:
  52. if (call) {
  53. return NXT_ERROR;
  54. }
  55. -
  56. }
  57. }
  58.  
  59. @@ -852,13 +851,6 @@ njs_vmcode_instance_of(njs_vm_t *vm, njs
  60. }
  61.  
  62.  
  63. -/*
  64. - * The increment and decrement operations require only one value parameter.
  65. - * However, if the value is not numeric, then the trap is generated and
  66. - * value parameter points to a trap frame value converted to a numeric.
  67. - * So the additional reference parameter points to the original value.
  68. - */
  69. -
  70. njs_ret_t
  71. njs_vmcode_increment(njs_vm_t *vm, njs_value_t *reference, njs_value_t *value)
  72. {
  73. @@ -1188,28 +1180,43 @@ njs_string_concat(njs_vm_t *vm, njs_valu
  74. }
  75.  
  76.  
  77. +nxt_inline njs_ret_t
  78. +njs_values_to_numberic(njs_vm_t *vm, njs_value_t *numeric1, njs_value_t **val1,
  79. + njs_value_t *numeric2, njs_value_t **val2)
  80. +{
  81. + njs_ret_t ret;
  82. +
  83. + if (nxt_slow_path(!njs_is_numeric(*val1))) {
  84. + ret = njs_value_to_numeric(vm, numeric1, *val1);
  85. + if (ret != NXT_OK) {
  86. + return ret;
  87. + }
  88. +
  89. + *val1 = numeric1;
  90. + }
  91. +
  92. + if (nxt_slow_path(!njs_is_numeric(*val2))) {
  93. + ret = njs_value_to_numeric(vm, numeric2, *val2);
  94. + if (ret != NXT_OK) {
  95. + return ret;
  96. + }
  97. +
  98. + *val2 = numeric2;
  99. + }
  100. +
  101. + return NXT_OK;
  102. +}
  103. +
  104. +
  105. njs_ret_t
  106. njs_vmcode_substraction(njs_vm_t *vm, njs_value_t *val1, njs_value_t *val2)
  107. {
  108. njs_ret_t ret;
  109. njs_value_t numeric1, numeric2;
  110.  
  111. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  112. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  113. - if (ret != NXT_OK) {
  114. - return ret;
  115. - }
  116. -
  117. - val1 = &numeric1;
  118. - }
  119. -
  120. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  121. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  122. - if (ret != NXT_OK) {
  123. - return ret;
  124. - }
  125. -
  126. - val2 = &numeric2;
  127. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  128. + if (ret != NXT_OK) {
  129. + return ret;
  130. }
  131.  
  132. njs_set_number(&vm->retval, njs_number(val1) - njs_number(val2));
  133. @@ -1224,22 +1231,9 @@ njs_vmcode_multiplication(njs_vm_t *vm,
  134. njs_ret_t ret;
  135. njs_value_t numeric1, numeric2;
  136.  
  137. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  138. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  139. - if (ret != NXT_OK) {
  140. - return ret;
  141. - }
  142. -
  143. - val1 = &numeric1;
  144. - }
  145. -
  146. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  147. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  148. - if (ret != NXT_OK) {
  149. - return ret;
  150. - }
  151. -
  152. - val2 = &numeric2;
  153. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  154. + if (ret != NXT_OK) {
  155. + return ret;
  156. }
  157.  
  158. njs_set_number(&vm->retval, njs_number(val1) * njs_number(val2));
  159. @@ -1256,22 +1250,9 @@ njs_vmcode_exponentiation(njs_vm_t *vm,
  160. nxt_bool_t valid;
  161. njs_value_t numeric1, numeric2;
  162.  
  163. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  164. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  165. - if (ret != NXT_OK) {
  166. - return ret;
  167. - }
  168. -
  169. - val1 = &numeric1;
  170. - }
  171. -
  172. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  173. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  174. - if (ret != NXT_OK) {
  175. - return ret;
  176. - }
  177. -
  178. - val2 = &numeric2;
  179. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  180. + if (ret != NXT_OK) {
  181. + return ret;
  182. }
  183.  
  184. base = njs_number(val1);
  185. @@ -1304,22 +1285,9 @@ njs_vmcode_division(njs_vm_t *vm, njs_va
  186. njs_ret_t ret;
  187. njs_value_t numeric1, numeric2;
  188.  
  189. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  190. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  191. - if (ret != NXT_OK) {
  192. - return ret;
  193. - }
  194. -
  195. - val1 = &numeric1;
  196. - }
  197. -
  198. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  199. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  200. - if (ret != NXT_OK) {
  201. - return ret;
  202. - }
  203. -
  204. - val2 = &numeric2;
  205. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  206. + if (ret != NXT_OK) {
  207. + return ret;
  208. }
  209.  
  210. njs_set_number(&vm->retval, njs_number(val1) / njs_number(val2));
  211. @@ -1331,28 +1299,17 @@ njs_vmcode_division(njs_vm_t *vm, njs_va
  212. njs_ret_t
  213. njs_vmcode_remainder(njs_vm_t *vm, njs_value_t *val1, njs_value_t *val2)
  214. {
  215. + double num;
  216. njs_ret_t ret;
  217. njs_value_t numeric1, numeric2;
  218.  
  219. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  220. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  221. - if (ret != NXT_OK) {
  222. - return ret;
  223. - }
  224. -
  225. - val1 = &numeric1;
  226. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  227. + if (ret != NXT_OK) {
  228. + return ret;
  229. }
  230.  
  231. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  232. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  233. - if (ret != NXT_OK) {
  234. - return ret;
  235. - }
  236. -
  237. - val2 = &numeric2;
  238. - }
  239. -
  240. - njs_set_number(&vm->retval, fmod(njs_number(val1), njs_number(val2)));
  241. + num = fmod(njs_number(val1), njs_number(val2));
  242. + njs_set_number(&vm->retval, num);
  243.  
  244. return sizeof(njs_vmcode_3addr_t);
  245. }
  246. @@ -1366,22 +1323,9 @@ njs_vmcode_left_shift(njs_vm_t *vm, njs_
  247. njs_ret_t ret;
  248. njs_value_t numeric1, numeric2;
  249.  
  250. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  251. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  252. - if (ret != NXT_OK) {
  253. - return ret;
  254. - }
  255. -
  256. - val1 = &numeric1;
  257. - }
  258. -
  259. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  260. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  261. - if (ret != NXT_OK) {
  262. - return ret;
  263. - }
  264. -
  265. - val2 = &numeric2;
  266. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  267. + if (ret != NXT_OK) {
  268. + return ret;
  269. }
  270.  
  271. num1 = njs_number_to_int32(njs_number(val1));
  272. @@ -1400,22 +1344,9 @@ njs_vmcode_right_shift(njs_vm_t *vm, njs
  273. njs_ret_t ret;
  274. njs_value_t numeric1, numeric2;
  275.  
  276. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  277. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  278. - if (ret != NXT_OK) {
  279. - return ret;
  280. - }
  281. -
  282. - val1 = &numeric1;
  283. - }
  284. -
  285. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  286. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  287. - if (ret != NXT_OK) {
  288. - return ret;
  289. - }
  290. -
  291. - val2 = &numeric2;
  292. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  293. + if (ret != NXT_OK) {
  294. + return ret;
  295. }
  296.  
  297. num1 = njs_number_to_int32(njs_number(val1));
  298. @@ -1434,22 +1365,9 @@ njs_vmcode_unsigned_right_shift(njs_vm_t
  299. njs_ret_t ret;
  300. njs_value_t numeric1, numeric2;
  301.  
  302. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  303. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  304. - if (ret != NXT_OK) {
  305. - return ret;
  306. - }
  307. -
  308. - val1 = &numeric1;
  309. - }
  310. -
  311. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  312. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  313. - if (ret != NXT_OK) {
  314. - return ret;
  315. - }
  316. -
  317. - val2 = &numeric2;
  318. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  319. + if (ret != NXT_OK) {
  320. + return ret;
  321. }
  322.  
  323. num1 = njs_number_to_uint32(njs_number(val1));
  324. @@ -1529,22 +1447,9 @@ njs_vmcode_bitwise_and(njs_vm_t *vm, njs
  325. njs_ret_t ret;
  326. njs_value_t numeric1, numeric2;
  327.  
  328. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  329. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  330. - if (ret != NXT_OK) {
  331. - return ret;
  332. - }
  333. -
  334. - val1 = &numeric1;
  335. - }
  336. -
  337. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  338. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  339. - if (ret != NXT_OK) {
  340. - return ret;
  341. - }
  342. -
  343. - val2 = &numeric2;
  344. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  345. + if (ret != NXT_OK) {
  346. + return ret;
  347. }
  348.  
  349. num1 = njs_number_to_integer(njs_number(val1));
  350. @@ -1562,22 +1467,9 @@ njs_vmcode_bitwise_xor(njs_vm_t *vm, njs
  351. njs_ret_t ret;
  352. njs_value_t numeric1, numeric2;
  353.  
  354. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  355. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  356. - if (ret != NXT_OK) {
  357. - return ret;
  358. - }
  359. -
  360. - val1 = &numeric1;
  361. - }
  362. -
  363. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  364. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  365. - if (ret != NXT_OK) {
  366. - return ret;
  367. - }
  368. -
  369. - val2 = &numeric2;
  370. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  371. + if (ret != NXT_OK) {
  372. + return ret;
  373. }
  374.  
  375. num1 = njs_number_to_integer(njs_number(val1));
  376. @@ -1595,22 +1487,9 @@ njs_vmcode_bitwise_or(njs_vm_t *vm, njs_
  377. njs_ret_t ret;
  378. njs_value_t numeric1, numeric2;
  379.  
  380. - if (nxt_slow_path(!njs_is_numeric(val1))) {
  381. - ret = njs_value_to_numeric(vm, &numeric1, val1);
  382. - if (ret != NXT_OK) {
  383. - return ret;
  384. - }
  385. -
  386. - val1 = &numeric1;
  387. - }
  388. -
  389. - if (nxt_slow_path(!njs_is_numeric(val2))) {
  390. - ret = njs_value_to_numeric(vm, &numeric2, val2);
  391. - if (ret != NXT_OK) {
  392. - return ret;
  393. - }
  394. -
  395. - val2 = &numeric2;
  396. + ret = njs_values_to_numberic(vm, &numeric1, &val1, &numeric2, &val2);
  397. + if (ret != NXT_OK) {
  398. + return ret;
  399. }
  400.  
  401. num1 = njs_number_to_integer(njs_number(val1));
  402. @@ -2137,7 +2016,7 @@ njs_vmcode_function_call(njs_vm_t *vm, n
  403. njs_ret_t
  404. njs_vmcode_return(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
  405. {
  406. - uint8_t call;
  407. + nxt_int_t ret;
  408. njs_value_t *value;
  409. njs_frame_t *frame;
  410. njs_native_frame_t *previous;
  411. @@ -2170,11 +2049,11 @@ njs_vmcode_return(njs_vm_t *vm, njs_valu
  412.  
  413. vm->current = frame->return_address;
  414.  
  415. - call = frame->native.call;
  416. + ret = frame->native.call ? NJS_STOP : 0;
  417.  
  418. njs_function_frame_free(vm, &frame->native);
  419.  
  420. - return call ? NJS_STOP : 0;
  421. + return ret;
  422. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement