DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Header

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * The contents of this file are subject to the Netscape Public License
 * Version 1.0 (the "NPL"); you may not use this file except in
 * compliance with the NPL.  You may obtain a copy of the NPL at
 * http://www.mozilla.org/NPL/
 *
 * Software distributed under the NPL is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
 * for the specific language governing rights and limitations under the
 * NPL.
 *
 * The Initial Developer of this code under the NPL is Netscape
 * Communications Corporation.  Portions created by Netscape are
 * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
 * Reserved.
 */

/*
 * JavaScript bytecode interpreter.
 */
#include "jsstddef.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "jstypes.h"
#include "jsarena.h" /* Added by JSIFY */
#include "jsutil.h" /* Added by JSIFY */
#include "jsprf.h"
#include "jsapi.h"
#include "jsarray.h"
#include "jsatom.h"
#include "jsbool.h"
#include "jscntxt.h"
#include "jsconfig.h"
#include "jsdbgapi.h"
#include "jsfun.h"
#include "jsgc.h"
#include "jsinterp.h"
#include "jslock.h"
#include "jsnum.h"
#include "jsobj.h"
#include "jsopcode.h"
#include "jsscope.h"
#include "jsscript.h"
#include "jsstr.h"

void
js_FlushPropertyCache(JSContext *cx)
{
    JSPropertyCache *cache;

    cache = &cx->runtime->propertyCache;
    if (cache->empty)
	return;
    memset(cache->table, 0, sizeof cache->table);
    cache->empty = JS_TRUE;
    cache->flushes++;
}

void
js_FlushPropertyCacheByProp(JSContext *cx, JSProperty *prop)
{
    JSPropertyCache *cache;
    JSBool empty;
    JSPropertyCacheEntry *end, *pce, entry;
    JSProperty *pce_prop;

    cache = &cx->runtime->propertyCache;
    if (cache->empty)
	return;

    empty = JS_TRUE;
    end = &cache->table[PROPERTY_CACHE_SIZE];
    for (pce = &cache->table[0]; pce < end; pce++) {
	PCE_LOAD(cache, pce, entry);
	pce_prop = PCE_PROPERTY(entry);
	if (pce_prop) {
	    if (pce_prop == prop) {
		PCE_OBJECT(entry) = NULL;
		PCE_PROPERTY(entry) = NULL;
		PCE_STORE(cache, pce, entry);
	    } else {
		empty = JS_FALSE;
	    }
	}
    }
    cache->empty = empty;
}

/*
 * Class for for/in loop property iterator objects.
 */
#define JSSLOT_ITR_STATE    (JSSLOT_START)

static void
prop_iterator_finalize(JSContext *cx, JSObject *obj)
{
    jsval iter_state;

    /* Protect against stillborn iterators. */
    iter_state = obj->slots[JSSLOT_ITR_STATE];
    if (iter_state != JSVAL_NULL)
	OBJ_ENUMERATE(cx, obj, JSENUMERATE_DESTROY, &iter_state, NULL);
}

static JSClass prop_iterator_class = {
    "PropertyIterator",
    0,
    JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,  JS_PropertyStub,
    JS_EnumerateStub, JS_ResolveStub,   JS_ConvertStub,   prop_iterator_finalize
};

/*
 * Stack macros and functions.  These all use a local variable, jsval *sp, to
 * point to the next free stack slot.  SAVE_SP must be called before any call
 * to a function that may invoke the interpreter.  RESTORE_SP must be called
 * only after return from js_Invoke, because only js_Invoke changes fp->sp.
 */
#define PUSH(v)         (*sp++ = (v))
#define POP()           (*--sp)
#define SAVE_SP(fp)     ((fp)->sp = sp)
#define RESTORE_SP(fp)  (sp = (fp)->sp)

/*
 * Push the generating bytecode's pc onto the parallel pc stack that runs
 * depth slots below the operands.
 *
 * NB: PUSH_OPND uses sp, depth, and pc from its lexical environment.  See
 * Interpret for these local variables' declarations and uses.
 */
#define PUSH_OPND(v)    (sp[-depth] = (jsval)pc, PUSH(v))

/*
 * Push the jsdouble d using sp, depth, and pc from the lexical environment.
 * Try to convert d to a jsint that fits in a jsval, otherwise GC-alloc space
 * for it and push a reference.
 */
#define PUSH_NUMBER(cx, d)                                                    \
    JS_BEGIN_MACRO                                                            \
	jsint _i;                                                             \
	jsval _v;                                                             \
									      \
	if (JSDOUBLE_IS_INT(d, _i) && INT_FITS_IN_JSVAL(_i)) {                \
	    _v = INT_TO_JSVAL(_i);                                            \
	} else {                                                              \
	    ok = js_NewDoubleValue(cx, d, &_v);                               \
	    if (!ok)                                                          \
		goto out;                                                     \
	}                                                                     \
	PUSH_OPND(_v);                                                        \
    JS_END_MACRO

#define POP_NUMBER(cx, d)                                                     \
    JS_BEGIN_MACRO                                                            \
	jsval _v;                                                             \
									      \
	_v = POP();                                                           \
	VALUE_TO_NUMBER(cx, _v, d);                                           \
    JS_END_MACRO

/*
 * This POP variant is called only for bitwise operators, so we don't bother
 * to inline it.  The calls in Interpret must therefore SAVE_SP first!
 */
static JSBool
PopInt(JSContext *cx, jsint *ip)
{
    JSStackFrame *fp;
    jsval *sp, v;

    fp = cx->fp;
    RESTORE_SP(fp);
    v = POP();
    SAVE_SP(fp);
    if (JSVAL_IS_INT(v)) {
	*ip = JSVAL_TO_INT(v);
	return JS_TRUE;
    }
    return js_ValueToECMAInt32(cx, v, (int32 *)ip);
}

static JSBool
PopUint(JSContext *cx, jsuint *ip)
{
    JSStackFrame *fp;
    jsval *sp, v;
    jsint i;

    fp = cx->fp;
    RESTORE_SP(fp);
    v = POP();
    SAVE_SP(fp);
    if (JSVAL_IS_INT(v) && (i = JSVAL_TO_INT(v)) >= 0) {
	*ip = i;
	return JS_TRUE;
    }
    return js_ValueToECMAUint32(cx, v, (uint32 *)ip);
}

/*
 * Optimized conversion macros that test for the desired type in v before
 * homing sp and calling a conversion function.
 */
#define VALUE_TO_NUMBER(cx, v, d)                                             \
    JS_BEGIN_MACRO                                                            \
	if (JSVAL_IS_INT(v)) {                                                \
	    d = (jsdouble)JSVAL_TO_INT(v);                                    \
	} else if (JSVAL_IS_DOUBLE(v)) {                                      \
	    d = *JSVAL_TO_DOUBLE(v);                                          \
	} else {                                                              \
	    SAVE_SP(fp);                                                      \
	    ok = js_ValueToNumber(cx, v, &d);                                 \
	    if (!ok)                                                          \
		goto out;                                                     \
	}                                                                     \
    JS_END_MACRO

#define POP_BOOLEAN(cx, v, b)                                                 \
    JS_BEGIN_MACRO                                                            \
	v = POP();                                                            \
	if (v == JSVAL_NULL) {                                                \
	    b = JS_FALSE;                                                     \
	} else if (JSVAL_IS_BOOLEAN(v)) {                                     \
	    b = JSVAL_TO_BOOLEAN(v);                                          \
	} else {                                                              \
	    SAVE_SP(fp);                                                      \
	    ok = js_ValueToBoolean(cx, v, &b);                                \
	    if (!ok)                                                          \
		goto out;                                                     \
	}                                                                     \
    JS_END_MACRO

#define VALUE_TO_OBJECT(cx, v, obj)                                           \
    JS_BEGIN_MACRO                                                            \
	if (JSVAL_IS_OBJECT(v) && v != JSVAL_NULL) {                          \
	    obj = JSVAL_TO_OBJECT(v);                                         \
	} else {                                                              \
	    SAVE_SP(fp);                                                      \
	    obj = js_ValueToNonNullObject(cx, v);                             \
	    if (!obj) {                                                       \
		ok = JS_FALSE;                                                \
		goto out;                                                     \
	    }                                                                 \
	}                                                                     \
    JS_END_MACRO

#if JS_BUG_VOID_TOSTRING
#define CHECK_VOID_TOSTRING(cx, v)                                            \
    if (JSVAL_IS_VOID(v)) {                                                   \
	JSString *_str;                                                       \
	_str = ATOM_TO_STRING(cx->runtime->atomState.typeAtoms[JSTYPE_VOID]); \
	v = STRING_TO_JSVAL(_str);                                            \
    }
#else
#define CHECK_VOID_TOSTRING(cx, v)  ((void)0)
#endif

#if JS_BUG_EAGER_TOSTRING
#define CHECK_EAGER_TOSTRING(hint)  (hint = JSTYPE_STRING)
#else
#define CHECK_EAGER_TOSTRING(hint)  ((void)0)
#endif

#define VALUE_TO_PRIMITIVE(cx, v, hint, vp)                                   \
    JS_BEGIN_MACRO                                                            \
	if (JSVAL_IS_PRIMITIVE(v)) {                                          \
	    CHECK_VOID_TOSTRING(cx, v);                                       \
	    *vp = v;                                                          \
	} else {                                                              \
	    SAVE_SP(fp);                                                      \
	    CHECK_EAGER_TOSTRING(hint);                                       \
	    ok = OBJ_DEFAULT_VALUE(cx, JSVAL_TO_OBJECT(v), hint, vp);         \
	    if (!ok)                                                          \
		goto out;                                                     \
	}                                                                     \
    JS_END_MACRO

jsval *
js_AllocStack(JSContext *cx, uintN nslots, void **markp)
{
    jsval *sp;

    if (markp)
	*markp = JS_ARENA_MARK(&cx->stackPool);
    JS_ARENA_ALLOCATE(sp, &cx->stackPool, nslots * sizeof(jsval));
    if (!sp) {
	JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_STACK_OVERFLOW,
			     (cx->fp && cx->fp->fun)
			     ? JS_GetFunctionName(cx->fp->fun)
			     : "script");
    }
    return sp;
}

void
js_FreeStack(JSContext *cx, void *mark)
{
    JS_ARENA_RELEASE(&cx->stackPool, mark);
}

JSBool
js_GetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    JSFunction *fun;
    JSStackFrame *fp;

    JS_ASSERT(OBJ_GET_CLASS(cx, obj) == &js_FunctionClass);
    fun = JS_GetPrivate(cx, obj);
    for (fp = cx->fp; fp; fp = fp->down) {
	/* Find most recent non-native function frame. */
	if (fp->fun && !fp->fun->call) {
	    if (fp->fun == fun) {
		JS_ASSERT((uintN)JSVAL_TO_INT(id) < fp->fun->nargs);
		*vp = fp->argv[JSVAL_TO_INT(id)];
	    }
	    return JS_TRUE;
	}
    }
    return JS_TRUE;
}

JSBool
js_SetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    JSFunction *fun;
    JSStackFrame *fp;

    JS_ASSERT(OBJ_GET_CLASS(cx, obj) == &js_FunctionClass);
    fun = JS_GetPrivate(cx, obj);
    for (fp = cx->fp; fp; fp = fp->down) {
	/* Find most recent non-native function frame. */
	if (fp->fun && !fp->fun->call) {
	    if (fp->fun == fun) {
		JS_ASSERT((uintN)JSVAL_TO_INT(id) < fp->fun->nargs);
		fp->argv[JSVAL_TO_INT(id)] = *vp;
	    }
	    return JS_TRUE;
	}
    }
    return JS_TRUE;
}

JSBool
js_GetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    JSFunction *fun;
    JSStackFrame *fp;
    jsint slot;

    JS_ASSERT(OBJ_GET_CLASS(cx, obj) == &js_FunctionClass);
    fun = JS_GetPrivate(cx, obj);
    for (fp = cx->fp; fp; fp = fp->down) {
	/* Find most recent non-native function frame. */
	if (fp->fun && !fp->fun->call) {
	    if (fp->fun == fun) {
		slot = JSVAL_TO_INT(id);
		JS_ASSERT((uintN)slot < fp->fun->nvars);
		if ((uintN)slot < fp->nvars)
		    *vp = fp->vars[slot];
	    }
	    return JS_TRUE;
	}
    }
    return JS_TRUE;
}

JSBool
js_SetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
    JSFunction *fun;
    JSStackFrame *fp;
    jsint slot;

    JS_ASSERT(OBJ_GET_CLASS(cx, obj) == &js_FunctionClass);
    fun = JS_GetPrivate(cx, obj);
    for (fp = cx->fp; fp; fp = fp->down) {
	/* Find most recent non-native function frame. */
	if (fp->fun && !fp->fun->call) {
	    if (fp->fun == fun) {
		slot = JSVAL_TO_INT(id);
		JS_ASSERT((uintN)slot < fp->fun->nvars);
		if ((uintN)slot < fp->nvars)
		    fp->vars[slot] = *vp;
	    }
	    return JS_TRUE;
	}
    }
    return JS_TRUE;

}


/*
 * Find a function reference and its 'this' object implicit first parameter
 * under argc arguments on cx's stack, and call the function.  Push missing
 * required arguments, allocate declared local variables, and pop everything
 * when done.  Then push the return value.
 */
JSBool
js_Invoke(JSContext *cx, uintN argc, JSBool constructing)
{
    JSStackFrame *fp, frame;
    jsval *sp, *newsp;
    jsval *vp, v;
    JSObject *funobj, *parent, *thisp;
    JSClass *clasp;
    JSObjectOps *ops;
    JSNative native;
    JSFunction *fun;
    JSScript *script;
    uintN minargs, nvars;
    void *mark;
    intN nslots, nalloc, surplus;
    JSBool ok;
    JSInterpreterHook hook;
    void *hookData;

    /* Reach under args and this to find the callable on the stack. */
    fp = cx->fp;
    sp = fp->sp;

    /*
     * Set vp to the callable value's stack slot (it's where rval goes).
     * Once vp is set, control must flow through label out2: to return.
     * Set frame.rval early so native class and object ops can throw and
     * return false, causing a goto out2 with ok set to false.
     */
    vp = sp - (2 + argc);
    v = *vp;
    frame.rval = JSVAL_VOID;

    /* A callable must be an object reference. */
    if (JSVAL_IS_PRIMITIVE(v))
	goto bad;
    funobj = JSVAL_TO_OBJECT(v);

    /* Load callable parent and this parameter for later. */
    parent = OBJ_GET_PARENT(cx, funobj);
    thisp = JSVAL_TO_OBJECT(vp[1]);

    clasp = OBJ_GET_CLASS(cx, funobj);
    if (clasp != &js_FunctionClass) {
	/* Function is inlined, all other classes use object ops. */
	ops = funobj->map->ops;

	/* Try converting to function, for closure and API compatibility. */
	ok = clasp->convert(cx, funobj, JSTYPE_FUNCTION, &v);
	if (!ok)
	    goto out2;
	if (!JSVAL_IS_FUNCTION(cx, v)) {
	    fun = NULL;
	    script = NULL;
	    minargs = nvars = 0;
	} else {
	    funobj = JSVAL_TO_OBJECT(v);
	    parent = OBJ_GET_PARENT(cx, funobj);

	    fun = JS_GetPrivate(cx, funobj);
	    if (clasp != &js_ClosureClass) {
		/* Make vp refer to funobj to keep it available as argv[-2]. */
		*vp = v;
		goto have_fun;
	    }

	    /* Closure invocation may need extra arg and local var slots. */
	    script = fun->script;
	    minargs = fun->nargs + fun->extra;
	    nvars = fun->nvars;
	}

	/* Try a call or construct native object op, using fun as fallback. */
	native = constructing ? ops->construct : ops->call;
	if (!native)
	    goto bad;
    } else {
	/* Get private data and set derived locals from it. */
	fun = JS_GetPrivate(cx, funobj);
have_fun:
	native = fun->call;
	script = fun->script;
	minargs = fun->nargs + fun->extra;
	nvars = fun->nvars;

	/* Handle bound method and dynamic scope special cases. */
	if (fun->flags) {
	    if (fun->flags & JSFUN_BOUND_METHOD)
		thisp = parent;
	    else
		parent = NULL;
	}
    }

    /* Initialize most of frame, except for thisp and scopeChain. */
    frame.callobj = frame.argsobj = NULL;
    frame.script = script;
    frame.fun = fun;
    frame.argc = argc;
    frame.argv = sp - argc;
    frame.nvars = nvars;
    frame.vars = sp;
    frame.down = fp;
    frame.annotation = NULL;
    frame.pc = NULL;
    frame.sp = sp;
    frame.sharpDepth = 0;
    frame.sharpArray = NULL;
    frame.constructing = constructing;
    frame.overrides = 0;
    frame.debugging = JS_FALSE;
    frame.dormantNext = NULL;

    /*
     * Compute the 'this' parameter and store it in frame.
     * Activation objects ("Call" objects not created with "new Call", i.e.,
     * "Call" objects with private data) may not be referred to by 'this'
     * as dictated by ECMA.
     */
    if (thisp && !(OBJ_GET_CLASS(cx, thisp) == &js_CallClass &&
		   JS_GetPrivate(cx, thisp) != NULL))
    {
	/* Some objects (e.g., With) delegate 'this' to another object. */
	thisp = OBJ_THIS_OBJECT(cx, thisp);
	if (!thisp) {
	    ok = JS_FALSE;
	    goto out2;
	}

	/* Default return value for a constructor is the new object. */
	if (constructing)
	    frame.rval = OBJECT_TO_JSVAL(thisp);
    } else {
	/*
	 * ECMA requires "the global object", but in the presence of multiple
	 * top-level objects (windows, frames, or certain layers in the client
	 * object model), we prefer fun's parent.  An example that causes this
	 * code to run:
	 *
	 *   // in window w1
	 *   function f() { return this }
	 *   function g() { return f }
	 *
	 *   // in window w2
	 *   var h = w1.g()
	 *   alert(h() == w1)
	 *
	 * The alert should display "true".
	 */
	JS_ASSERT(!constructing);
	if (parent == NULL) {
	    parent = cx->globalObject;
	} else {
	    /* walk up to find the top-level object */
	    JSObject *tmp;
	    thisp = parent;
	    while ((tmp = OBJ_GET_PARENT(cx, thisp)) != NULL)
		thisp = tmp;
	}
    }
    frame.thisp = thisp;

    /* From here on, control must flow through label out: to return. */
    cx->fp = &frame;
    mark = JS_ARENA_MARK(&cx->stackPool);
    /* init these now in case we goto out before first hook call */
    hook = cx->runtime->callHook;
    hookData = NULL;

    /* Check for missing arguments expected by the function. */
    nslots = (intN)((argc < minargs) ? minargs - argc : 0);
    if (nslots) {
	/* All arguments must be contiguous, so we may have to copy actuals. */
	nalloc = nslots;
	if ((jsuword)(sp + nslots) > cx->stackPool.current->limit)
	    nalloc += argc;

	/* Take advantage of the surplus slots in the caller's frame depth. */
	surplus = (jsval *)mark - sp;
	JS_ASSERT(surplus >= 0);
	nalloc -= surplus;

	/* Check whether we have enough space in the caller's frame. */
	if (nalloc > 0) {
	    /* Need space for actuals plus missing formals minus surplus. */
	    newsp = js_AllocStack(cx, (uintN)nalloc, NULL);
	    if (!newsp) {
		ok = JS_FALSE;
		goto out;
	    }

	    /* If we couldn't allocate contiguous args, copy actuals now. */
	    if (newsp != mark) {
		if (argc)
		    memcpy(newsp, frame.argv, argc * sizeof(jsval));
		frame.argv = newsp;
		frame.vars = frame.sp = newsp + argc;
		RESTORE_SP(&frame);
	    }
	}

	/* Advance frame.vars to make room for the missing args. */
	frame.vars += nslots;

	/* Push void to initialize missing args. */
	while (--nslots >= 0)
	    PUSH(JSVAL_VOID);
    }

    /* Now allocate stack space for local variables. */
    nslots = (intN)frame.nvars;
    if (nslots) {
	surplus = (intN)((jsval *)cx->stackPool.current->avail - frame.vars);
	if (surplus < nslots) {
	    newsp = js_AllocStack(cx, (uintN)nslots, NULL);
	    if (!newsp) {
		ok = JS_FALSE;
		goto out;
	    }
	    if (newsp != sp) {
		/* NB: Discontinuity between argv and vars. */
		frame.vars = frame.sp = newsp;
		RESTORE_SP(&frame);
	    }
	}

	/* Push void to initialize local variables. */
	while (--nslots >= 0)
	    PUSH(JSVAL_VOID);
    }

    /* Store the current sp in frame before calling fun. */
    SAVE_SP(&frame);

    /* call the hook if present */
    if (hook && (native || script))
        hookData = hook(cx, &frame, JS_TRUE, 0, cx->runtime->callHookData);

    /* Call the function, either a native method or an interpreted script. */
    if (native) {
	frame.scopeChain = fp->scopeChain;
	ok = native(cx, thisp, argc, frame.argv, &frame.rval);
    } else if (script) {
	frame.scopeChain = funobj;
	if (!parent) {
#if JS_HAS_CALL_OBJECT
	    /* Scope with a call object parented by cx's global object. */
	    funobj = js_GetCallObject(cx, &frame, cx->globalObject, NULL);
	    if (!funobj) {
		ok = JS_FALSE;
		goto out;
	    }
#else
	    /* Bad old code slams globalObject directly into funobj. */
	    OBJ_SET_PARENT(funobj, cx->globalObject);
#endif
	}
	ok = js_Interpret(cx, &v);
#if !JS_HAS_CALL_OBJECT
	if (!parent)
	    OBJ_SET_PARENT(funobj, NULL);
#endif
    } else {
	/* fun might be onerror trying to report a syntax error in itself. */
	frame.scopeChain = NULL;
	ok = JS_TRUE;
    }

out:
    if (hook && hookData)
        hook(cx, &frame, JS_FALSE, &ok, hookData);
#if JS_HAS_CALL_OBJECT
    /* If frame has a call object, sync values and clear back-pointer. */
    if (frame.callobj)
	ok &= js_PutCallObject(cx, &frame);
#endif
#if JS_HAS_ARGS_OBJECT
    /* If frame has an arguments object, sync values clear back-pointer. */
    if (frame.argsobj)
	ok &= js_PutArgsObject(cx, &frame);
#endif

    /* Pop everything off the stack and restore cx->fp. */
    JS_ARENA_RELEASE(&cx->stackPool, mark);
    cx->fp = fp;

out2:
    /* Store the return value and restore sp just above it. */
    *vp = frame.rval;
    fp->sp = vp + 1;
    return ok;

bad:
    js_ReportIsNotFunction(cx, vp, constructing);
    ok = JS_FALSE;
    goto out2;
}

JSBool
js_CallFunctionValue(JSContext *cx, JSObject *obj, jsval fval,
		     uintN argc, jsval *argv, jsval *rval)
{
    JSStackFrame *fp, *oldfp, frame;
    jsval *oldsp, *sp;
    void *mark;
    uintN i;
    JSBool ok;

    fp = oldfp = cx->fp;
    if (!fp) {
	memset(&frame, 0, sizeof frame);
	cx->fp = fp = &frame;
    }
    oldsp = fp->sp;
    sp = js_AllocStack(cx, 2 + argc, &mark);
    if (!sp) {
	ok = JS_FALSE;
	goto out;
    }
    fp->sp = sp;

    PUSH(fval);
    PUSH(OBJECT_TO_JSVAL(obj));
    for (i = 0; i < argc; i++)
	PUSH(argv[i]);
    SAVE_SP(fp);
    ok = js_Invoke(cx, argc, JS_FALSE);
    if (ok) {
	RESTORE_SP(fp);
	*rval = POP();
    }

    js_FreeStack(cx, mark);
out:
    fp->sp = oldsp;
    if (oldfp != fp)
	cx->fp = oldfp;

    return ok;
}

JSBool
js_Execute(JSContext *cx, JSObject *chain, JSScript *script, JSFunction *fun,
	   JSStackFrame *down, JSBool debugging, jsval *result)
{
    JSStackFrame *oldfp, frame;
    JSBool ok;
    JSInterpreterHook hook;
    void *hookData;

    hook = cx->runtime->executeHook;
    oldfp = cx->fp;
    frame.callobj = frame.argsobj = NULL;
    frame.script = script;
    frame.fun = fun;
    if (down) {
	/* Propagate arg/var state for eval and the debugger API. */
	frame.thisp = down->thisp;
	frame.argc = down->argc;
	frame.argv = down->argv;
	frame.nvars = down->nvars;
	frame.vars = down->vars;
	frame.annotation = down->annotation;
	frame.sharpArray = down->sharpArray;
    } else {
	frame.thisp = chain;
	frame.argc = frame.nvars = 0;
	frame.argv = frame.vars = NULL;
	frame.annotation = NULL;
	frame.sharpArray = NULL;
    }
    frame.rval = JSVAL_VOID;
    frame.down = down;
    frame.scopeChain = chain;
    frame.pc = NULL;
    frame.sp = oldfp ? oldfp->sp : NULL;
    frame.sharpDepth = 0;
    frame.constructing = JS_FALSE;
    frame.overrides = 0;
    frame.debugging = debugging;
    frame.dormantNext = NULL;

    /*
     * Here we wrap the call to js_Interpret with code to (conditionally)
     * save and restore the old stack frame chain into a chain of 'dormant'
     * frame chains. Since we are replacing cx->fp we were running into the
     * problem that if gc was called, then some of the objects associated
     * with the old frame chain (stored here in the C stack as 'oldfp') were
     * not rooted and were being collected. This was bad. So, now we
     * preserve the links to these 'dormant' frame chains in cx before
     * calling js_Interpret and cleanup afterwards. gc walks these dormant
     * chains and marks objects in the same way that it marks object in the
     * primary cx->fp chain.
     */

    if (oldfp && oldfp != down) {
	JS_ASSERT(!oldfp->dormantNext);
	oldfp->dormantNext = cx->dormantFrameChain;
	cx->dormantFrameChain = oldfp;
    }

    cx->fp = &frame;
    if (hook)
        hookData = hook(cx, &frame, JS_TRUE, 0, cx->runtime->executeHookData);

    ok = js_Interpret(cx, result);

    if (hook && hookData)
        hook(cx, &frame, JS_FALSE, &ok, hookData);
    cx->fp = oldfp;

    if (oldfp && oldfp != down) {
	JS_ASSERT(cx->dormantFrameChain == oldfp);
	cx->dormantFrameChain = oldfp->dormantNext;
	oldfp->dormantNext = NULL;
    }

    return ok;
}

#if JS_HAS_EXPORT_IMPORT
/*
 * If id is JSVAL_VOID, import all exported properties from obj.
 */
static JSBool
ImportProperty(JSContext *cx, JSObject *obj, jsid id)
{
    JSBool ok;
    JSIdArray *ida;
    JSProperty *prop;
    JSObject *obj2, *target, *funobj, *closure;
    JSString *str;
    uintN attrs;
    jsint i;
    JSFunction *fun;
    jsval value;

    if (JSVAL_IS_VOID(id)) {
	ida = JS_Enumerate(cx, obj);
	if (!ida)
	    return JS_FALSE;
	if (ida->length == 0)
	    goto out;
	ok = JS_TRUE;
    } else {
	ida = NULL;
	if (!OBJ_LOOKUP_PROPERTY(cx, obj, id, &obj2, &prop))
	    return JS_FALSE;
	if (!prop) {
	    str = js_DecompileValueGenerator(cx, js_IdToValue(id), NULL);
	    if (str)
		js_ReportIsNotDefined(cx, JS_GetStringBytes(str));
	    return JS_FALSE;
	}
	ok = OBJ_GET_ATTRIBUTES(cx, obj, id, prop, &attrs);
	OBJ_DROP_PROPERTY(cx, obj2, prop);
	if (!ok)
	    return JS_FALSE;
	if (!(attrs & JSPROP_EXPORTED)) {
	    str = js_DecompileValueGenerator(cx, js_IdToValue(id), NULL);
	    if (str) {
		JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
				     JSMSG_NOT_EXPORTED,
				     JS_GetStringBytes(str));
	    }
	    return JS_FALSE;
	}
    }

    target = js_FindVariableScope(cx, &fun);
    if (!target) {
	ok = JS_FALSE;
	goto out;
    }

    i = 0;
    do {
	if (ida) {
	    id = ida->vector[i];
	    ok = OBJ_GET_ATTRIBUTES(cx, obj, id, NULL, &attrs);
	    if (!ok)
		goto out;
	    if (!(attrs & JSPROP_EXPORTED))
		continue;
	}
	ok = OBJ_CHECK_ACCESS(cx, obj, id, JSACC_IMPORT, &value, &attrs);
	if (!ok)
	    goto out;
	if (JSVAL_IS_FUNCTION(cx, value)) {
	    funobj = JSVAL_TO_OBJECT(value);
	    closure = js_ConstructObject(cx, &js_ClosureClass, funobj, obj);
	    if (!closure) {
		ok = JS_FALSE;
		goto out;
	    }
	    /*
	     * The Closure() constructor resets the closure object's parent
	     * to be the current scope chain.  Set it to the object that the
	     * imported function is being defined in.
	     */
	    OBJ_SET_PARENT(cx, closure, obj);
	    value = OBJECT_TO_JSVAL(closure);
	}

	/*
	 * Handle the case of importing a property that refers to a local
	 * variable or formal parameter of a function activation.  Those
	 * properties are accessed by opcodes using stack slot numbers
	 * generated by the compiler rather than runtime name-lookup. These
	 * local references, therefore, bypass the normal scope chain lookup.
	 * So, instead of defining a new property in the activation object,
	 * modify the existing value in the stack slot.
	 */
	if (OBJ_GET_CLASS(cx, target) == &js_CallClass) {
	    ok = OBJ_LOOKUP_PROPERTY(cx, target, id, &obj2, &prop);
	    if (!ok)
		goto out;
	} else {
	    prop = NULL;
	}
	if (prop && (target == obj2)) {
	    ok = OBJ_SET_PROPERTY(cx, target, id, &value);
	} else {
	    ok = OBJ_DEFINE_PROPERTY(cx, target, id, value, NULL, NULL,
				     attrs & ~JSPROP_EXPORTED,
				     NULL);
	}
	if (prop)
	    OBJ_DROP_PROPERTY(cx, obj2, prop);
	if (!ok)
	    goto out;
    } while (ida && ++i < ida->length);

out:
    if (ida)
	JS_DestroyIdArray(cx, ida);
    return ok;
}
#endif /* JS_HAS_EXPORT_IMPORT */

#if !defined XP_PC || !defined _MSC_VER || _MSC_VER > 800
#define MAX_INTERP_LEVEL 1000
#else
#define MAX_INTERP_LEVEL 30
#endif

JSBool
js_Interpret(JSContext *cx, jsval *result)
{
    JSRuntime *rt;
    JSStackFrame *fp;
    JSScript *script;
    JSObject *obj, *obj2, *proto, *parent;
    JSBranchCallback onbranch;
    JSBool ok, cond;
    ptrdiff_t depth, len;
    jsval *sp, *newsp;
    void *mark;
    jsbytecode *pc, *pc2, *endpc;
    JSOp op, op2;
    JSCodeSpec *cs;
    JSAtom *atom;
    uintN argc, slot;
    jsval *vp, lval, rval, ltmp, rtmp;
    jsid id;
    JSObject *withobj, *origobj, *propobj;
    JSIdArray *ida;
    jsval iter_state;
    JSProperty *prop;
    JSScopeProperty *sprop;
    JSString *str, *str2, *str3;
    size_t length, length2, length3;
    jschar *chars;
    jsint i, j;
    jsdouble d, d2;
    JSClass *clasp;
    JSFunction *fun;
    JSType type;
#ifdef DEBUG
    FILE *tracefp;
#endif
#if JS_HAS_SWITCH_STATEMENT
    jsint low, high;
    uintN off, npairs;
    JSBool match;
#endif
#if JS_HAS_LEXICAL_CLOSURE
    JSFunction *fun2;
    JSObject *closure;
#endif
#if JS_HAS_EXPORT_IMPORT
    uintN attrs;
#endif
#if JS_HAS_EXCEPTIONS
    JSTryNote *tn;
    ptrdiff_t offset;
#endif

    if (cx->interpLevel == MAX_INTERP_LEVEL) {
	JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_OVER_RECURSED);
	return JS_FALSE;
    }
    cx->interpLevel++;
    *result = JSVAL_VOID;
    rt = cx->runtime;

    /*
     * Set registerized frame pointer and derived pointers.
     */
    fp = cx->fp;
    script = fp->script;
    obj = fp->scopeChain;

    /*
     * Prepare to call a user-supplied branch handler, and abort the script
     * if it returns false.
     */
    onbranch = cx->branchCallback;
    ok = JS_TRUE;
#define CHECK_BRANCH(len) {                                                   \
    if (len < 0 && onbranch) {                                                \
	SAVE_SP(fp);                                                          \
	if (!(ok = (*onbranch)(cx, script)))                                  \
	    goto out;                                                         \
    }                                                                         \
}

    /*
     * Allocate operand and pc stack slots for the script's worst-case depth.
     */
    depth = (ptrdiff_t)script->depth;
    newsp = js_AllocStack(cx, (uintN)(2 * depth), &mark);
    if (!newsp) {
	ok = JS_FALSE;
	goto out;
    }
    newsp += depth;
    fp->sp = sp = newsp;

    pc = script->code;
    endpc = pc + script->length;

    while (pc < endpc) {
	fp->pc = pc;
	op = (JSOp)*pc;
      do_op:
	cs = &js_CodeSpec[op];
	len = cs->length;

#ifdef DEBUG
	tracefp = cx->tracefp;
	if (tracefp) {
	    intN nuses, n;

	    fprintf(tracefp, "%4u: ", js_PCToLineNumber(script, pc));
	    js_Disassemble1(cx, script, pc, pc - script->code, JS_FALSE,
			    tracefp);
	    nuses = cs->nuses;
	    if (nuses) {
		fp->sp = sp - nuses;
		for (n = 0; n < nuses; n++) {
		    str = js_DecompileValueGenerator(cx, *fp->sp, NULL);
		    if (str != NULL) {
			fprintf(tracefp, "%s %s",
				(n == 0) ? "  inputs:" : ",",
				JS_GetStringBytes(str));
		    }
		    fp->sp++;
		}
		putc('\n', tracefp);
	    }
	}
#endif

	if (rt->interruptHandler) {
	    JSTrapHandler handler = (JSTrapHandler) rt->interruptHandler;
	    /* check copy of pointer for safety in multithreaded situation */
	    if (handler) {
		switch (handler(cx, script, pc, &rval,
				rt->interruptHandlerData)) {
		  case JSTRAP_ERROR:
		    ok = JS_FALSE;
		    goto out;
		  case JSTRAP_CONTINUE:
		    break;
		  case JSTRAP_RETURN:
		    fp->rval = rval;
		    goto out;
#if JS_HAS_EXCEPTIONS
		  case JSTRAP_THROW:
                    cx->throwing = JS_TRUE;
                    cx->exception = rval;
                    ok = JS_FALSE;
		    goto out;
#endif /* JS_HAS_EXCEPTIONS */
		  default:;
		}
	    }
	}

	switch (op) {
	  case JSOP_NOP:
	    break;

	  case JSOP_PUSH:
	    PUSH_OPND(JSVAL_VOID);
	    break;

	  case JSOP_POP:
	    sp--;
	    break;

	  case JSOP_POP2:
	    sp -= 2;
	    break;

	  case JSOP_POPV:
	    *result = POP();
	    break;

	  case JSOP_ENTERWITH:
	    rval = POP();
	    VALUE_TO_OBJECT(cx, rval, obj);
	    withobj = js_NewObject(cx, &js_WithClass, obj, fp->scopeChain);
	    if (!withobj)
		goto out;
	    fp->scopeChain = withobj;
	    PUSH_OPND(OBJECT_TO_JSVAL(withobj));
	    break;

	  case JSOP_LEAVEWITH:
	    rval = POP();
	    JS_ASSERT(JSVAL_IS_OBJECT(rval));
	    withobj = JSVAL_TO_OBJECT(rval);
	    JS_ASSERT(OBJ_GET_CLASS(cx, withobj) == &js_WithClass);

	    rval = OBJ_GET_SLOT(cx, withobj, JSSLOT_PARENT);
	    JS_ASSERT(JSVAL_IS_OBJECT(rval));
	    fp->scopeChain = JSVAL_TO_OBJECT(rval);
	    break;

	  case JSOP_RETURN:
	    CHECK_BRANCH(-1);
	    fp->rval = POP();
	    goto out;

#if JS_HAS_SWITCH_STATEMENT
	  case JSOP_DEFAULT:
	    (void) POP();
	    /* fall through */
#endif
	  case JSOP_GOTO:
	    len = GET_JUMP_OFFSET(pc);
	    CHECK_BRANCH(len);
	    break;

	  case JSOP_IFEQ:
	    POP_BOOLEAN(cx, rval, cond);
	    if (cond == JS_FALSE) {
		len = GET_JUMP_OFFSET(pc);
		CHECK_BRANCH(len);
	    }
	    break;

	  case JSOP_IFNE:
	    POP_BOOLEAN(cx, rval, cond);
	    if (cond != JS_FALSE) {
		len = GET_JUMP_OFFSET(pc);
		CHECK_BRANCH(len);
	    }
	    break;

#if !JS_BUG_SHORT_CIRCUIT
	  case JSOP_OR:
	    POP_BOOLEAN(cx, rval, cond);
	    if (cond == JS_TRUE) {
		len = GET_JUMP_OFFSET(pc);
		PUSH_OPND(rval);
	    }
	    break;

	  case JSOP_AND:
	    POP_BOOLEAN(cx, rval, cond);
	    if (cond == JS_FALSE) {
		len = GET_JUMP_OFFSET(pc);
		PUSH_OPND(rval);
	    }
	    break;
#endif

	  case JSOP_TOOBJECT:
	    rval = POP();
	    SAVE_SP(fp);
	    ok = js_ValueToObject(cx, rval, &obj);
	    if (!ok)
		goto out;
	    PUSH(OBJECT_TO_JSVAL(obj));
	    break;

#define POP_ELEMENT_ID(id) {                                                  \
    /* If the index is not a jsint, atomize it. */                            \
    id = (jsid) POP();                                                        \
    if (JSVAL_IS_INT(id)) {                                                   \
	atom = NULL;                                                          \
    } else {                                                                  \
	atom = js_ValueToStringAtom(cx, (jsval)id);                           \
	if (!atom) {                                                          \
	    ok = JS_FALSE;                                                    \
	    goto out;                                                         \
	}                                                                     \
	id = (jsid)atom;                                                      \
    }                                                                         \
}

#if JS_HAS_IN_OPERATOR
	  case JSOP_IN:
	    rval = POP();
	    if (!JSVAL_IS_OBJECT(rval) || rval == JSVAL_NULL) {
		JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
				     JSMSG_IN_NOT_OBJECT);
		ok = JS_FALSE;
		goto out;
	    }
	    obj = JSVAL_TO_OBJECT(rval);
	    POP_ELEMENT_ID(id);
	    ok = OBJ_LOOKUP_PROPERTY(cx, obj, id, &obj2, &prop);
	    if (!ok)
		goto out;
	    PUSH_OPND(BOOLEAN_TO_JSVAL(prop != NULL));
	    break;
#endif /* JS_HAS_IN_OPERATOR */

	  case JSOP_FORNAME:
	    rval = POP();
	    /* FALL THROUGH */
	  case JSOP_FORNAME2:
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;

	    SAVE_SP(fp);
	    ok = js_FindVariable(cx, id, &obj, &obj2, &prop);
	    if (!ok)
		goto out;
	    JS_ASSERT(prop);
	    OBJ_DROP_PROPERTY(cx, obj2, prop);
	    lval = OBJECT_TO_JSVAL(obj);
	    goto do_forinloop;

	  case JSOP_FORPROP:
	    rval = POP();
	    /* FALL THROUGH */
	  case JSOP_FORPROP2:
	    lval = POP();
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;
	    goto do_forinloop;

	  case JSOP_FORELEM:
	    rval = POP();
	    /* FALL THROUGH */
	  case JSOP_FORELEM2:
	    POP_ELEMENT_ID(id);
	    lval = POP();

	  do_forinloop:
	    /*
	     * ECMA-compatible for/in evals the object just once, before loop.
	     */
	    if (cs->format & JOF_FOR2) {
		obj = JSVAL_TO_OBJECT(sp[-1]);
		vp = sp - 2;
	    } else {
		/* Old-style (pre-ECMA) JSOPs */
		SAVE_SP(fp);
		ok = js_ValueToObject(cx, rval, &obj);
		if (!ok)
		    goto out;
		vp = sp - 1;
	    }

	    /* If the thing to the right of 'in' has no properties, break. */
	    if (!obj) {
		rval = JSVAL_FALSE;
		goto end_forinloop;
	    }

	    /*
	     * Save the thing to the right of 'in' as origobj.  Later on we use
	     * this variable to suppress enumeration of shadowed prototype
	     * properties.
	     */
	    origobj = obj;

	    /*
	     * Reach under the top of stack to find our property iterator, a
	     * JSObject that contains the iteration state.  (An object is used
	     * rather than a native struct so that the iteration state is
	     * cleaned up via GC if the for-in loop terminates abruptly.)
	     */
	    rval = *vp;

	    /* Is this the first iteration ? */
	    if (JSVAL_IS_VOID(rval)) {
		/* Yes, create a new JSObject to hold the iterator state */
		propobj = js_NewObject(cx, &prop_iterator_class, NULL, NULL);
		if (!propobj) {
		    ok = JS_FALSE;
		    goto out;
		}

		/*
		 * Rewrite the iterator so we know to do the next case.
		 * Do this before calling the enumerator, which could
		 * displace cx->newborn and cause GC.
		 */
		*vp = OBJECT_TO_JSVAL(propobj);

		ok = OBJ_ENUMERATE(cx, obj, JSENUMERATE_INIT, &iter_state, 0);
		propobj->slots[JSSLOT_ITR_STATE] = iter_state;
		if (!ok)
		    goto out;

		/*
		 * Stash private iteration state into property iterator object.
		 * NB: This code knows that the first slots are pre-allocated.
		 */
		JS_ASSERT(JS_INITIAL_NSLOTS >= 5);
		propobj->slots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(obj);
	    } else {
		/* This is not the first iteration. Recover iterator state. */
		propobj = JSVAL_TO_OBJECT(rval);
		obj = JSVAL_TO_OBJECT(propobj->slots[JSSLOT_PARENT]);
		iter_state = propobj->slots[JSSLOT_ITR_STATE];
	    }

	  enum_next_property:
	    /* Get the next jsid to be enumerated and store it in rval */
	    OBJ_ENUMERATE(cx, obj, JSENUMERATE_NEXT, &iter_state, &rval);
	    propobj->slots[JSSLOT_ITR_STATE] = iter_state;

	    /* No more jsids to iterate in obj ? */
	    if (iter_state == JSVAL_NULL) {
		/* Enumerate the properties on obj's prototype chain */
		obj = OBJ_GET_PROTO(cx, obj);
		if (!obj) {
		    /* End of property list -- terminate loop. */
		    rval = JSVAL_FALSE;
		    goto end_forinloop;
		}

		ok = OBJ_ENUMERATE(cx, obj, JSENUMERATE_INIT, &iter_state, 0);
		propobj->slots[JSSLOT_ITR_STATE] = iter_state;
		if (!ok)
		    goto out;

		/* Stash private iteration state into iterator JSObject. */
		propobj->slots[JSSLOT_PARENT] = OBJECT_TO_JSVAL(obj);
		goto enum_next_property;
	    }

	    /* Skip deleted and shadowed properties, leave next id in rval. */
	    if (obj != origobj) {
		/* Have we already enumerated a clone of this property? */
		ok = OBJ_LOOKUP_PROPERTY(cx, origobj, rval, &obj2, &prop);
		if (!ok)
		    goto out;
		if (prop) {
		    OBJ_DROP_PROPERTY(cx, obj2, prop);

		    /* Yes, don't enumerate again.  Go to the next property */
		    if (obj2 != obj)
			goto enum_next_property;
		}
	    }

	    /* Convert lval to a non-null object containing id. */
	    VALUE_TO_OBJECT(cx, lval, obj);

	    /* Make sure rval is a string for uniformity and compatibility. */
	    if (!JSVAL_IS_INT(rval)) {
		rval = ATOM_KEY((JSAtom *)rval);
	    } else if ((cx->version <= JSVERSION_1_1) &&
		       (cx->version >= JSVERSION_1_0)) {
		str = js_NumberToString(cx, (jsdouble) JSVAL_TO_INT(rval));
		if (!str) {
		    ok = JS_FALSE;
		    goto out;
		}

		/* Hold via sp[0] in case the GC runs under OBJ_SET_PROPERTY. */
		rval = sp[0] = STRING_TO_JSVAL(str);
	    }

	    /* Set the variable obj[id] to refer to rval. */
	    ok = OBJ_SET_PROPERTY(cx, obj, id, &rval);
	    if (!ok)
		goto out;

	    /* Push true to keep looping through properties. */
	    rval = JSVAL_TRUE;

	  end_forinloop:
	    PUSH_OPND(rval);
	    break;

	  case JSOP_DUP:
	    JS_ASSERT(sp > newsp);
	    rval = sp[-1];
	    PUSH_OPND(rval);
	    break;

	  case JSOP_DUP2:
	    JS_ASSERT(sp - 1 > newsp);
	    lval = sp[-2];
	    rval = sp[-1];
	    PUSH_OPND(lval);
	    PUSH_OPND(rval);
	    break;

#define PROPERTY_OP(call) {                                                   \
    /* Pop the left part and resolve it to a non-null object. */              \
    lval = POP();                                                             \
    VALUE_TO_OBJECT(cx, lval, obj);                                           \
									      \
    /* Get or set the property, set ok false if error, true if success. */    \
    call;                                                                     \
    if (!ok)                                                                  \
	goto out;                                                             \
}

#define ELEMENT_OP(call) {                                                    \
    POP_ELEMENT_ID(id);                                                       \
    PROPERTY_OP(call);                                                        \
}

#define CACHED_GET(call) {                                                    \
    PROPERTY_CACHE_TEST(&rt->propertyCache, obj, id, prop);                   \
    if (PROP_FOUND(prop)) {                                                   \
	sprop = (JSScopeProperty *)prop;                                      \
	slot = (uintN)sprop->slot;                                            \
	rval = OBJ_GET_SLOT(cx, obj, slot);                                   \
	ok = SPROP_GET(cx, sprop, obj, obj, &rval);                           \
	if (ok)                                                               \
	    OBJ_SET_SLOT(cx, obj, slot, rval);                                \
    } else {                                                                  \
	SAVE_SP(fp);                                                          \
	ok = call;                                                            \
	/* No fill here: js_GetProperty fills the cache. */                   \
    }                                                                         \
}

#if JS_BUG_SET_ENUMERATE
#define SET_ENUMERATE_ATTR(sprop) ((sprop)->attrs |= JSPROP_ENUMERATE)
#else
#define SET_ENUMERATE_ATTR(sprop) ((void)0)
#endif

#define CACHED_SET(call) {                                                    \
    PROPERTY_CACHE_TEST(&rt->propertyCache, obj, id, prop);                   \
    if (PROP_FOUND(prop) &&                                                   \
	!(sprop = (JSScopeProperty *)prop,                                    \
	  sprop->attrs & (JSPROP_READONLY | JSPROP_ASSIGNHACK))) {            \
	ok = SPROP_SET(cx, sprop, obj, obj, &rval);                           \
	if (ok) {                                                             \
	    SET_ENUMERATE_ATTR(sprop);                                        \
	    OBJ_SET_SLOT(cx, obj, sprop->slot, rval);                         \
	}                                                                     \
    } else {                                                                  \
	SAVE_SP(fp);                                                          \
	ok = call;                                                            \
	/* No fill here: js_SetProperty writes through the cache. */          \
    }                                                                         \
}

	  case JSOP_SETNAME:
	    /* Get an immediate atom naming the variable to set. */
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;

	    SAVE_SP(fp);
	    ok = js_FindVariable(cx, id, &obj, &obj2, &prop);
	    if (!ok)
		goto out;
	    JS_ASSERT(prop);

	    OBJ_DROP_PROPERTY(cx, obj2, prop);

	    /* Pop the right-hand side and set obj[id] to it. */
	    rval = POP();

	    /* Try to hit the property cache, FindVariable primes it. */
	    CACHED_SET(OBJ_SET_PROPERTY(cx, obj, id, &rval));
	    if (!ok)
		goto out;

	    /* Push the right-hand side as our result. */
	    PUSH_OPND(rval);
	    break;

	  case JSOP_BINDNAME:
	    atom = GET_ATOM(cx, script, pc);
	    SAVE_SP(fp);
	    ok = js_FindVariable(cx, (jsid)atom, &obj, &obj2, &prop);
	    if (!ok)
		goto out;
	    OBJ_DROP_PROPERTY(cx, obj2, prop);
	    PUSH_OPND(OBJECT_TO_JSVAL(obj));
	    break;

	  case JSOP_SETNAME2:
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;
	    rval = POP();
	    lval = POP();
	    JS_ASSERT(!JSVAL_IS_PRIMITIVE(lval));
	    obj  = JSVAL_TO_OBJECT(lval);
	    CACHED_SET(OBJ_SET_PROPERTY(cx, obj, id, &rval));
	    if (!ok)
		goto out;
	    PUSH_OPND(rval);
	    break;

#define INTEGER_OP(OP, EXTRA_CODE) {                                          \
    SAVE_SP(fp);                                                              \
    ok = PopInt(cx, &j) && PopInt(cx, &i);                                    \
    RESTORE_SP(fp);                                                           \
    if (!ok)                                                                  \
	goto out;                                                             \
    EXTRA_CODE                                                                \
    i = i OP j;                                                               \
    PUSH_NUMBER(cx, i);                                                       \
}

#define BITWISE_OP(OP)          INTEGER_OP(OP, (void) 0;)
#define SIGNED_SHIFT_OP(OP)     INTEGER_OP(OP, j &= 31;)

	  case JSOP_BITOR:
	    BITWISE_OP(|);
	    break;

	  case JSOP_BITXOR:
	    BITWISE_OP(^);
	    break;

	  case JSOP_BITAND:
	    BITWISE_OP(&);
	    break;

#ifdef XP_PC
#define COMPARE_DOUBLES(LVAL, OP, RVAL, IFNAN)                                \
    ((JSDOUBLE_IS_NaN(LVAL) || JSDOUBLE_IS_NaN(RVAL))                         \
     ? (IFNAN)                                                                \
     : (LVAL) OP (RVAL))
#else
#define COMPARE_DOUBLES(LVAL, OP, RVAL, IFNAN) ((LVAL) OP (RVAL))
#endif

#define RELATIONAL_OP(OP) {                                                   \
    rval = POP();                                                             \
    lval = POP();                                                             \
    /* Optimize for two int-tagged operands (typical loop control). */        \
    if ((lval & rval) & JSVAL_INT) {                                          \
	ltmp = lval ^ JSVAL_VOID;                                             \
	rtmp = rval ^ JSVAL_VOID;                                             \
	if (ltmp && rtmp) {                                                   \
	    cond = JSVAL_TO_INT(lval) OP JSVAL_TO_INT(rval);                  \
	} else {                                                              \
	    d  = ltmp ? JSVAL_TO_INT(lval) : *rt->jsNaN;                      \
	    d2 = rtmp ? JSVAL_TO_INT(rval) : *rt->jsNaN;                      \
	    cond = COMPARE_DOUBLES(d, OP, d2, JS_FALSE);                      \
	}                                                                     \
    } else {                                                                  \
	VALUE_TO_PRIMITIVE(cx, lval, JSTYPE_NUMBER, &lval);                   \
	/* Need lval for strcmp or ToNumber later, so root it via sp[0]. */   \
	sp[0] = lval;                                                         \
	VALUE_TO_PRIMITIVE(cx, rval, JSTYPE_NUMBER, &rval);                   \
	if (JSVAL_IS_STRING(lval) && JSVAL_IS_STRING(rval)) {                 \
	    str  = JSVAL_TO_STRING(lval);                                     \
	    str2 = JSVAL_TO_STRING(rval);                                     \
	    cond = js_CompareStrings(str, str2) OP 0;                         \
	} else {                                                              \
	    /* Need rval after ToNumber(lval), so root it via sp[1]. */       \
	    sp[1] = rval;                                                     \
	    VALUE_TO_NUMBER(cx, lval, d);                                     \
	    VALUE_TO_NUMBER(cx, rval, d2);                                    \
	    cond = COMPARE_DOUBLES(d, OP, d2, JS_FALSE);                      \
	}                                                                     \
    }                                                                         \
    PUSH_OPND(BOOLEAN_TO_JSVAL(cond));                                        \
}

#define EQUALITY_OP(OP, IFNAN) {                                              \
    rval = POP();                                                             \
    lval = POP();                                                             \
    ltmp = JSVAL_TAG(lval);                                                   \
    rtmp = JSVAL_TAG(rval);                                                   \
    if (ltmp == rtmp) {                                                       \
	if (ltmp == JSVAL_STRING) {                                           \
	    str  = JSVAL_TO_STRING(lval);                                     \
	    str2 = JSVAL_TO_STRING(rval);                                     \
	    cond = js_CompareStrings(str, str2) OP 0;                         \
	} else if (ltmp == JSVAL_DOUBLE) {                                    \
	    d  = *JSVAL_TO_DOUBLE(lval);                                      \
	    d2 = *JSVAL_TO_DOUBLE(rval);                                      \
	    cond = COMPARE_DOUBLES(d, OP, d2, IFNAN);                         \
	} else {                                                              \
	    /* Handle all undefined (=>NaN) and int combinations. */          \
	    cond = lval OP rval;                                              \
	}                                                                     \
    } else {                                                                  \
	if (JSVAL_IS_NULL(lval) || JSVAL_IS_VOID(lval)) {                     \
	    cond = (JSVAL_IS_NULL(rval) || JSVAL_IS_VOID(rval)) OP 1;         \
	} else if (JSVAL_IS_NULL(rval) || JSVAL_IS_VOID(rval)) {              \
	    cond = 1 OP 0;                                                    \
	} else {                                                              \
	    if (ltmp == JSVAL_OBJECT) {                                       \
		VALUE_TO_PRIMITIVE(cx, lval, JSTYPE_VOID, &lval);             \
		ltmp = JSVAL_TAG(lval);                                       \
	    } else if (rtmp == JSVAL_OBJECT) {                                \
		VALUE_TO_PRIMITIVE(cx, rval, JSTYPE_VOID, &rval);             \
		rtmp = JSVAL_TAG(rval);                                       \
	    }                                                                 \
	    if (ltmp == JSVAL_STRING && rtmp == JSVAL_STRING) {               \
		str  = JSVAL_TO_STRING(lval);                                 \
		str2 = JSVAL_TO_STRING(rval);                                 \
		cond = js_CompareStrings(str, str2) OP 0;                     \
	    } else {                                                          \
		/* Need rval after ToNumber(lval), so root it via sp[1]. */   \
		sp[1] = rval;                                                 \
		VALUE_TO_NUMBER(cx, lval, d);                                 \
		VALUE_TO_NUMBER(cx, rval, d2);                                \
		cond = COMPARE_DOUBLES(d, OP, d2, IFNAN);                     \
	    }                                                                 \
	}                                                                     \
    }                                                                         \
    PUSH_OPND(BOOLEAN_TO_JSVAL(cond));                                        \
}

	  case JSOP_EQ:
	    EQUALITY_OP(==, JS_FALSE);
	    break;

	  case JSOP_NE:
	    EQUALITY_OP(!=, JS_TRUE);
	    break;

#if !JS_BUG_FALLIBLE_EQOPS
#define NEW_EQUALITY_OP(OP, IFNAN) {                                          \
    rval = POP();                                                             \
    lval = POP();                                                             \
    ltmp = JSVAL_TAG(lval);                                                   \
    rtmp = JSVAL_TAG(rval);                                                   \
    if (ltmp == rtmp) {                                                       \
	if (ltmp == JSVAL_STRING) {                                           \
	    str  = JSVAL_TO_STRING(lval);                                     \
	    str2 = JSVAL_TO_STRING(rval);                                     \
	    cond = js_CompareStrings(str, str2) OP 0;                         \
	} else if (ltmp == JSVAL_DOUBLE) {                                    \
	    d  = *JSVAL_TO_DOUBLE(lval);                                      \
	    d2 = *JSVAL_TO_DOUBLE(rval);                                      \
	    cond = COMPARE_DOUBLES(d, OP, d2, IFNAN);                         \
	} else {                                                              \
	    cond = lval OP rval;                                              \
	}                                                                     \
    } else {                                                                  \
	if (ltmp == JSVAL_DOUBLE && JSVAL_IS_INT(rval)) {                     \
	    d  = *JSVAL_TO_DOUBLE(lval);                                      \
	    d2 = JSVAL_TO_INT(rval);                                          \
	    cond = COMPARE_DOUBLES(d, OP, d2, IFNAN);                         \
	} else if (JSVAL_IS_INT(lval) && rtmp == JSVAL_DOUBLE) {              \
	    d  = JSVAL_TO_INT(lval);                                          \
	    d2 = *JSVAL_TO_DOUBLE(rval);                                      \
	    cond = COMPARE_DOUBLES(d, OP, d2, IFNAN);                         \
	} else {                                                              \
	    cond = lval OP rval;                                              \
	}                                                                     \
    }                                                                         \
    PUSH_OPND(BOOLEAN_TO_JSVAL(cond));                                        \
}

	  case JSOP_NEW_EQ:
	    NEW_EQUALITY_OP(==, JS_FALSE);
	    break;

	  case JSOP_NEW_NE:
	    NEW_EQUALITY_OP(!=, JS_TRUE);
	    break;

#if JS_HAS_SWITCH_STATEMENT
	  case JSOP_CASE:
	    NEW_EQUALITY_OP(==, JS_FALSE);
	    (void) POP();
	    if (cond) {
		len = GET_JUMP_OFFSET(pc);
		CHECK_BRANCH(len);
	    } else {
		PUSH(lval);
	    }
	    break;
#endif

#endif /* !JS_BUG_FALLIBLE_EQOPS */

	  case JSOP_LT:
	    RELATIONAL_OP(<);
	    break;

	  case JSOP_LE:
	    RELATIONAL_OP(<=);
	    break;

	  case JSOP_GT:
	    RELATIONAL_OP(>);
	    break;

	  case JSOP_GE:
	    RELATIONAL_OP(>=);
	    break;

#undef EQUALITY_OP
#undef RELATIONAL_OP

	  case JSOP_LSH:
	    SIGNED_SHIFT_OP(<<);
	    break;

	  case JSOP_RSH:
	    SIGNED_SHIFT_OP(>>);
	    break;

	  case JSOP_URSH:
	  {
	    uint32 u;

	    SAVE_SP(fp);
	    ok = PopInt(cx, &j) && PopUint(cx, &u);
	    RESTORE_SP(fp);
	    if (!ok)
		goto out;
	    j &= 31;
	    d = u >> j;
	    PUSH_NUMBER(cx, d);
	    break;
	  }

#undef INTEGER_OP
#undef BITWISE_OP
#undef SIGNED_SHIFT_OP

	  case JSOP_ADD:
	    rval = rtmp = POP();
	    lval = ltmp = POP();
	    VALUE_TO_PRIMITIVE(cx, lval, JSTYPE_VOID, &lval);
	    if ((cond = JSVAL_IS_STRING(lval)) != 0) {
		/*
		 * Keep lval on the stack so it isn't GC'd during either the
		 * next VALUE_TO_PRIMITIVE or the js_ValueToString(cx, rval).
		 */
		sp[0] = lval;
	    }
	    VALUE_TO_PRIMITIVE(cx, rval, JSTYPE_VOID, &rval);
	    if (cond || JSVAL_IS_STRING(rval)) {
		if (cond) {
		    str = JSVAL_TO_STRING(lval);
		    SAVE_SP(fp);
		    ok = (str2 = js_ValueToString(cx, rval)) != NULL;
		} else {
		    /*
		     * Keep rval on the stack so it isn't GC'd during the next
		     * js_ValueToString.
		     */
		    sp[1] = rval;
		    str2 = JSVAL_TO_STRING(rval);
		    SAVE_SP(fp);
		    ok = (str = js_ValueToString(cx, lval)) != NULL;
		}
		if (!ok)
		    goto out;
		if ((length = str->length) == 0) {
		    str3 = str2;
		} else if ((length2 = str2->length) == 0) {
		    str3 = str;
		} else {
		    length3 = length + length2;
		    chars = JS_malloc(cx, (length3 + 1) * sizeof(jschar));
		    if (!chars) {
			ok = JS_FALSE;
			goto out;
		    }
		    js_strncpy(chars, str->chars, length);
		    js_strncpy(chars + length, str2->chars, length2);
		    chars[length3] = 0;
		    str3 = js_NewString(cx, chars, length3, 0);
		    if (!str3) {
			JS_free(cx, chars);
			ok = JS_FALSE;
			goto out;
		    }
		}
		PUSH_OPND(STRING_TO_JSVAL(str3));
	    } else {
		VALUE_TO_NUMBER(cx, ltmp, d);
		VALUE_TO_NUMBER(cx, rtmp, d2);
		d += d2;
		PUSH_NUMBER(cx, d);
	    }
	    break;

#define BINARY_OP(OP) {                                                       \
    POP_NUMBER(cx, d2);                                                       \
    POP_NUMBER(cx, d);                                                        \
    d = d OP d2;                                                              \
    PUSH_NUMBER(cx, d);                                                       \
}

	  case JSOP_SUB:
	    BINARY_OP(-);
	    break;

	  case JSOP_MUL:
	    BINARY_OP(*);
	    break;

	  case JSOP_DIV:
	    POP_NUMBER(cx, d2);
	    POP_NUMBER(cx, d);
	    if (d2 == 0) {
#ifdef XP_PC
		/* XXX MSVC miscompiles such that (NaN == 0) */
		if (JSDOUBLE_IS_NaN(d2))
		    rval = DOUBLE_TO_JSVAL(rt->jsNaN);
		else
#endif
		if (d == 0 || JSDOUBLE_IS_NaN(d))
		    rval = DOUBLE_TO_JSVAL(rt->jsNaN);
		else if ((JSDOUBLE_HI32(d) ^ JSDOUBLE_HI32(d2)) >> 31)
		    rval = DOUBLE_TO_JSVAL(rt->jsNegativeInfinity);
		else
		    rval = DOUBLE_TO_JSVAL(rt->jsPositiveInfinity);
		PUSH_OPND(rval);
	    } else {
		d /= d2;
		PUSH_NUMBER(cx, d);
	    }
	    break;

	  case JSOP_MOD:
	    POP_NUMBER(cx, d2);
	    POP_NUMBER(cx, d);
	    if (d2 == 0) {
		PUSH_OPND(DOUBLE_TO_JSVAL(rt->jsNaN));
	    } else {
#ifdef XP_PC
	      /* Workaround MS fmod bug where 42 % (1/0) => NaN, not 42. */
	      if (!(JSDOUBLE_IS_FINITE(d) && JSDOUBLE_IS_INFINITE(d2)))
#endif
		d = fmod(d, d2);
		PUSH_NUMBER(cx, d);
	    }
	    break;

	  case JSOP_NOT:
	    POP_BOOLEAN(cx, rval, cond);
	    PUSH_OPND(BOOLEAN_TO_JSVAL(!cond));
	    break;

	  case JSOP_BITNOT:
	    SAVE_SP(fp);
	    ok = PopInt(cx, &i);
	    RESTORE_SP(fp);
	    if (!ok)
		goto out;
	    i = ~i;
	    PUSH_NUMBER(cx, i);
	    break;

	  case JSOP_NEG:
	    POP_NUMBER(cx, d);
#ifdef HPUX
            /* 
             * Negation of a zero doesn't produce a negative
             * zero on HPUX. Perform the operation by bit
             * twiddling.
             */
            JSDOUBLE_HI32(d) ^= JSDOUBLE_HI32_SIGNBIT;
#else
	    d = -d;
#endif
	    PUSH_NUMBER(cx, d);
	    break;

	  case JSOP_POS:
	    POP_NUMBER(cx, d);
	    PUSH_NUMBER(cx, d);
	    break;

	  case JSOP_NEW:
	    /* Get immediate argc and find the constructor function. */
	    argc = GET_ARGC(pc);

	  do_new:
	    vp = sp - (2 + argc);
	    JS_ASSERT(vp >= newsp);

	    fun = NULL;
	    obj2 = NULL;
	    lval = *vp;
	    if (!JSVAL_IS_OBJECT(lval) ||
		(obj2 = JSVAL_TO_OBJECT(lval)) == NULL ||
		/* XXX clean up to avoid special cases above ObjectOps layer */
		(clasp = OBJ_GET_CLASS(cx, obj2),
		 clasp == &js_FunctionClass || clasp == &js_ClosureClass) ||
                 !obj2->map->ops->construct) 
            {
		fun = js_ValueToFunction(cx, vp, JS_TRUE);
		if (!fun) {
		    ok = JS_FALSE;
		    goto out;
		}
		obj2 = fun->object;
	    }

	    if (!obj2) {
		proto = parent = NULL;
		fun = NULL;
	    } else {
		/* Get the constructor prototype object for this function. */
		ok = OBJ_GET_PROPERTY(cx, obj2,
				      (jsid)rt->atomState.classPrototypeAtom,
				      &rval);
		if (!ok)
		    goto out;
		proto = JSVAL_IS_OBJECT(rval) ? JSVAL_TO_OBJECT(rval) : NULL;
		parent = OBJ_GET_PARENT(cx, obj2);
	    }

#if 1
	    /* If there is no class prototype, use js_ObjectClass. */
	    if (!proto)
		obj = js_NewObject(cx, &js_ObjectClass, NULL, parent);
	    else
		obj = js_NewObject(cx, OBJ_GET_CLASS(cx, proto), proto, parent);
#else
            clasp = &js_ObjectClass;
            if (!JSVAL_IS_PRIMITIVE(lval)) {
                /* 
                 * Use prototype's class iff we are calling the class's
                 * constuctor.
                 */
                JSObject *funobj;

                funobj = JSVAL_TO_OBJECT(lval);
                clasp = OBJ_GET_CLASS(cx, funobj);
                if (clasp == &js_FunctionClass &&
                    ((JSFunction *)JS_GetPrivate(cx, funobj))->call == 
                        OBJ_GET_CLASS(cx, proto)->construct)
                {
                    clasp = OBJ_GET_CLASS(cx, proto);
                }
            }
	    obj = js_NewObject(cx, clasp, proto, parent);
#endif
	    if (!obj) {
		ok = JS_FALSE;
		goto out;
	    }

	    /* Now we have an object with a constructor method; call it. */
	    vp[1] = OBJECT_TO_JSVAL(obj);
	    SAVE_SP(fp);
	    ok = js_Invoke(cx, argc, JS_TRUE);
	    RESTORE_SP(fp);
	    if (!ok) {
		cx->newborn[GCX_OBJECT] = NULL;
		goto out;
	    }

	    /* Check the return value and update obj from it. */
	    rval = *vp;
	    if (JSVAL_IS_PRIMITIVE(rval)) {
		if (fun || !JSVERSION_IS_ECMA(cx->version)) {
		    *vp = OBJECT_TO_JSVAL(obj);
		    break;
		}
		/* native [[Construct]] returning primitive is error */
		str = js_ValueToString(cx, rval);
		if (str) {
		    JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
					 JSMSG_BAD_NEW_RESULT,
					 JS_GetStringBytes(str));
		}
		ok = JS_FALSE;
		goto out;
	    }
	    obj = JSVAL_TO_OBJECT(rval);
	    break;

	  case JSOP_DELNAME:
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;

	    ok = js_FindProperty(cx, id, &obj, &obj2, &prop);
	    if (!ok)
		goto out;

	    /* ECMA says to return true if name is undefined or inherited. */
	    rval = JSVAL_TRUE;
	    if (prop) {
		OBJ_DROP_PROPERTY(cx, obj2, prop);
		ok = OBJ_DELETE_PROPERTY(cx, obj, id, &rval);
		if (!ok)
		    goto out;
	    }
	    PUSH_OPND(rval);
	    break;

	  case JSOP_DELPROP:
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;
	    SAVE_SP(fp);
	    PROPERTY_OP(ok = OBJ_DELETE_PROPERTY(cx, obj, id, &rval));
	    PUSH_OPND(rval);
	    break;

	  case JSOP_DELELEM:
	    SAVE_SP(fp);
	    ELEMENT_OP(ok = OBJ_DELETE_PROPERTY(cx, obj, id, &rval));
	    PUSH_OPND(rval);
	    break;

	  case JSOP_TYPEOF:
	    rval = POP();
	    type = JS_TypeOfValue(cx, rval);
	    atom = rt->atomState.typeAtoms[type];
	    str  = ATOM_TO_STRING(atom);
	    PUSH_OPND(STRING_TO_JSVAL(str));
	    break;

	  case JSOP_VOID:
	    (void) POP();
	    PUSH_OPND(JSVAL_VOID);
	    break;

	  case JSOP_INCNAME:
	  case JSOP_DECNAME:
	  case JSOP_NAMEINC:
	  case JSOP_NAMEDEC:
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;

	    SAVE_SP(fp);
	    ok = js_FindProperty(cx, id, &obj, &obj2, &prop);
	    if (!ok)
		goto out;
	    if (!prop) {
		js_ReportIsNotDefined(cx, ATOM_BYTES(atom));
		ok = JS_FALSE;
		goto out;
	    }

	    OBJ_DROP_PROPERTY(cx, obj2, prop);
	    lval = OBJECT_TO_JSVAL(obj);
	    goto do_incop;

	  case JSOP_INCPROP:
	  case JSOP_DECPROP:
	  case JSOP_PROPINC:
	  case JSOP_PROPDEC:
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;
	    lval = POP();
	    goto do_incop;

	  case JSOP_INCELEM:
	  case JSOP_DECELEM:
	  case JSOP_ELEMINC:
	  case JSOP_ELEMDEC:
	    POP_ELEMENT_ID(id);
	    lval = POP();

	  do_incop:
	    VALUE_TO_OBJECT(cx, lval, obj);

	    /* The operand must contain a number. */
	    CACHED_GET(OBJ_GET_PROPERTY(cx, obj, id, &rval));
	    if (!ok)
		goto out;
	    VALUE_TO_NUMBER(cx, rval, d);

	    /* Compute the post- or pre-incremented value. */
	    if (cs->format & JOF_INC)
		d2 = (cs->format & JOF_POST) ? d++ : ++d;
	    else
		d2 = (cs->format & JOF_POST) ? d-- : --d;

	    /* Set obj[id] to the resulting number. */
	    ok = js_NewNumberValue(cx, d, &rval);
	    if (!ok)
		goto out;
	    CACHED_SET(OBJ_SET_PROPERTY(cx, obj, id, &rval));
	    if (!ok)
		goto out;
	    PUSH_NUMBER(cx, d2);
	    break;

	  case JSOP_INCARG:
	  case JSOP_DECARG:
	  case JSOP_ARGINC:
	  case JSOP_ARGDEC:
	    slot = (uintN)GET_ARGNO(pc);
	    JS_ASSERT(slot < fp->fun->nargs);
	    rval = fp->argv[slot];
	    VALUE_TO_NUMBER(cx, rval, d);

	    /* Compute the post- or pre-incremented value. */
	    if (cs->format & JOF_INC)
		d2 = (cs->format & JOF_POST) ? d++ : ++d;
	    else
		d2 = (cs->format & JOF_POST) ? d-- : --d;

	    ok = js_NewNumberValue(cx, d, &rval);
	    if (!ok)
		goto out;
	    fp->argv[slot] = rval;
	    PUSH_NUMBER(cx, d2);
	    break;

	  case JSOP_INCVAR:
	  case JSOP_DECVAR:
	  case JSOP_VARINC:
	  case JSOP_VARDEC:
	    slot = (uintN)GET_VARNO(pc);
	    JS_ASSERT(slot < fp->fun->nvars);
	    rval = fp->vars[slot];
	    VALUE_TO_NUMBER(cx, rval, d);

	    /* Compute the post- or pre-incremented value. */
	    if (cs->format & JOF_INC)
		d2 = (cs->format & JOF_POST) ? d++ : ++d;
	    else
		d2 = (cs->format & JOF_POST) ? d-- : --d;

	    ok = js_NewNumberValue(cx, d, &rval);
	    if (!ok)
		goto out;
	    fp->vars[slot] = rval;
	    PUSH_NUMBER(cx, d2);
	    break;

	  case JSOP_GETPROP:
	    /* Get an immediate atom naming the property. */
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;
	    PROPERTY_OP(CACHED_GET(OBJ_GET_PROPERTY(cx, obj, id, &rval)));
	    PUSH_OPND(rval);
	    break;

	  case JSOP_SETPROP:
	    /* Pop the right-hand side into rval for OBJ_SET_PROPERTY. */
	    rval = POP();

	    /* Get an immediate atom naming the property. */
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;
	    PROPERTY_OP(CACHED_SET(OBJ_SET_PROPERTY(cx, obj, id, &rval)));
	    PUSH_OPND(rval);
	    break;

	  case JSOP_GETELEM:
	    ELEMENT_OP(CACHED_GET(OBJ_GET_PROPERTY(cx, obj, id, &rval)));
	    PUSH_OPND(rval);
	    break;

	  case JSOP_SETELEM:
	    rval = POP();
	    ELEMENT_OP(CACHED_SET(OBJ_SET_PROPERTY(cx, obj, id, &rval)));
	    PUSH_OPND(rval);
	    break;

	  case JSOP_PUSHOBJ:
	    PUSH_OPND(OBJECT_TO_JSVAL(obj));
	    break;

	  case JSOP_CALLSPECIAL:
	  case JSOP_CALL:
	    argc = GET_ARGC(pc);
	    SAVE_SP(fp);
	    ok = js_Invoke(cx, argc, JS_FALSE);
	    RESTORE_SP(fp);
	    if (!ok) {
		goto out;
	    }
	    obj = NULL;
	    break;

	  case JSOP_NAME:
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;

	    ok = js_FindProperty(cx, id, &obj, &obj2, &prop);
	    if (!ok)
		goto out;
	    if (!prop) {
		/* Kludge to allow (typeof foo == "undefined") tests. */
		for (pc2 = pc + len; pc2 < endpc; pc2++) {
		    op2 = (JSOp)*pc2;
		    if (op2 == JSOP_TYPEOF) {
			PUSH_OPND(JSVAL_VOID);
			goto advance_pc;
		    }
		    if (op2 != JSOP_NOP)
			break;
		}
		js_ReportIsNotDefined(cx, ATOM_BYTES(atom));
		ok = JS_FALSE;
		goto out;
	    }

	    /* Take the slow path if prop was not found in a native object. */
	    if (!OBJ_IS_NATIVE(obj) || !OBJ_IS_NATIVE(obj2)) {
		OBJ_DROP_PROPERTY(cx, obj2, prop);
		ok = OBJ_GET_PROPERTY(cx, obj, id, &rval);
		if (!ok)
		    goto out;
		PUSH_OPND(rval);
		break;
	    }

	    /* Get and push the obj[id] property's value. */
	    sprop = (JSScopeProperty *)prop;
	    slot = (uintN)sprop->slot;
	    rval = LOCKED_OBJ_GET_SLOT(obj2, slot);
	    JS_UNLOCK_OBJ(cx, obj2);
	    ok = SPROP_GET(cx, sprop, obj, obj2, &rval);
	    JS_LOCK_OBJ(cx, obj2);
	    if (!ok) {
		OBJ_DROP_PROPERTY(cx, obj2, prop);
		goto out;
	    }
	    LOCKED_OBJ_SET_SLOT(obj2, slot, rval);
	    OBJ_DROP_PROPERTY(cx, obj2, prop);
	    PUSH_OPND(rval);
	    break;

	  case JSOP_UINT16:
	    i = (jsint) GET_ATOM_INDEX(pc);
	    rval = INT_TO_JSVAL(i);
	    PUSH_OPND(rval);
	    break;

	  case JSOP_NUMBER:
	  case JSOP_STRING:
	    atom = GET_ATOM(cx, script, pc);
	    PUSH_OPND(ATOM_KEY(atom));
	    break;

	  case JSOP_OBJECT:
	    atom = GET_ATOM(cx, script, pc);
	    rval = ATOM_KEY(atom);
	    JS_ASSERT(JSVAL_IS_OBJECT(rval));
	    PUSH_OPND(rval);
	    break;

	  case JSOP_ZERO:
	    PUSH_OPND(JSVAL_ZERO);
	    break;

	  case JSOP_ONE:
	    PUSH_OPND(JSVAL_ONE);
	    break;

	  case JSOP_NULL:
	    PUSH_OPND(JSVAL_NULL);
	    break;

	  case JSOP_THIS:
	    PUSH_OPND(OBJECT_TO_JSVAL(fp->thisp));
	    break;

	  case JSOP_FALSE:
	    PUSH_OPND(JSVAL_FALSE);
	    break;

	  case JSOP_TRUE:
	    PUSH_OPND(JSVAL_TRUE);
	    break;

#if JS_HAS_SWITCH_STATEMENT
	  case JSOP_TABLESWITCH:
	    pc2 = pc;
	    len = GET_JUMP_OFFSET(pc2);

	    /*
	     * ECMAv2 forbids conversion of discriminant, so we will skip to
	     * the default case if the discriminant isn't an int jsval.
	     * (This opcode is emitted only for dense jsint-domain switches.)
	     */
	    if (cx->version == JSVERSION_DEFAULT ||
		cx->version >= JSVERSION_1_4) {
		rval = POP();
		if (!JSVAL_IS_INT(rval))
		    break;
		i = JSVAL_TO_INT(rval);
	    } else {
		SAVE_SP(fp);
		ok = PopInt(cx, &i);
		RESTORE_SP(fp);
		if (!ok)
		    goto out;
	    }

	    pc2 += 2;
	    low = GET_JUMP_OFFSET(pc2);
	    pc2 += 2;
	    high = GET_JUMP_OFFSET(pc2);

	    i -= low;
	    if ((jsuint)i <= (jsuint)(high - low)) {
		pc2 += 2 + 2 * i;
		off = GET_JUMP_OFFSET(pc2);
		if (off)
		    len = off;
	    }
	    break;

	  case JSOP_LOOKUPSWITCH:
	    lval = POP();
	    pc2 = pc;
	    len = GET_JUMP_OFFSET(pc2);

	    if (!JSVAL_IS_NUMBER(lval) &&
		!JSVAL_IS_STRING(lval) &&
		!JSVAL_IS_BOOLEAN(lval)) {
		goto advance_pc;
	    }

	    pc2 += 2;
	    npairs = GET_ATOM_INDEX(pc2);
	    pc2 += 2;

#define SEARCH_PAIRS(MATCH_CODE)                                              \
    while (npairs) {                                                          \
	atom = GET_ATOM(cx, script, pc2);                                     \
	rval = ATOM_KEY(atom);                                                \
	MATCH_CODE                                                            \
	if (match) {                                                          \
	    pc2 += 2;                                                         \
	    len = GET_JUMP_OFFSET(pc2);                                       \
	    goto advance_pc;                                                  \
	}                                                                     \
	pc2 += 4;                                                             \
	npairs--;                                                             \
    }
	    if (JSVAL_IS_STRING(lval)) {
		str  = JSVAL_TO_STRING(lval);
		SEARCH_PAIRS(
		    match = (JSVAL_IS_STRING(rval) &&
			     ((str2 = JSVAL_TO_STRING(rval)) == str ||
			      !js_CompareStrings(str2, str)));
		)
	    } else if (JSVAL_IS_DOUBLE(lval)) {
		d = *JSVAL_TO_DOUBLE(lval);
		SEARCH_PAIRS(
		    match = (JSVAL_IS_DOUBLE(rval) &&
			     *JSVAL_TO_DOUBLE(rval) == d);
		)
	    } else {
		SEARCH_PAIRS(
		    match = (lval == rval);
		)
	    }
#undef SEARCH_PAIRS
	    break;

	  case JSOP_CONDSWITCH:
	    break;

#endif /* JS_HAS_SWITCH_STATEMENT */

#if JS_HAS_LEXICAL_CLOSURE
	  case JSOP_CLOSURE:
	    /*
	     * If the nearest variable scope is a function, not a call object,
	     * replace it in the scope chain with its call object.
	     */
	    obj = js_FindVariableScope(cx, &fun);
	    if (!obj) {
		ok = JS_FALSE;
		goto out;
	    }

	    /*
	     * If in a with statement, set obj to the With object's prototype,
	     * i.e., the object specified in the with statement head.
	     */
	    if (fp->scopeChain != obj) {
		obj = fp->scopeChain;
		JS_ASSERT(OBJ_GET_CLASS(cx, obj) == &js_WithClass);
#if JS_BUG_WITH_CLOSURE
		while (OBJ_GET_CLASS(cx, obj) == &js_WithClass) {
		    proto = OBJ_GET_PROTO(cx, obj);
		    if (!proto)
			break;
		    obj = proto;
		}
#endif
	    }

	    /*
	     * Get immediate operand atom, which is a function object literal.
	     * From it, get the function to close.
	     */
	    atom = GET_ATOM(cx, script, pc);
	    JS_ASSERT(ATOM_IS_OBJECT(atom));
	    obj2 = ATOM_TO_OBJECT(atom);
	    fun2 = JS_GetPrivate(cx, obj2);

	    /*
	     * Let closure = new Closure(obj2).
	     * NB: js_ConstructObject does not use the "constructor" property
	     * of the new object it creates, because in this case and others
	     * such as js_WithClass, that property refers to the prototype's
	     * constructor function.
	     */
	    closure = js_ConstructObject(cx, &js_ClosureClass, obj2,
					 fp->scopeChain);
	    if (!closure) {
		ok = JS_FALSE;
		goto out;
	    }

	    /*
	     * Define a property in obj with id fun2->atom and value closure,
	     * but only if fun2 is not anonymous.
	     */
	    if (fun2->atom) {
		ok = OBJ_DEFINE_PROPERTY(cx, obj, (jsid)fun2->atom,
					 OBJECT_TO_JSVAL(closure),
					 NULL, NULL, JSPROP_ENUMERATE,
					 NULL);
		if (!ok) {
		    cx->newborn[GCX_OBJECT] = NULL;
		    goto out;
		}
	    }
	    PUSH_OPND(OBJECT_TO_JSVAL(closure));
	    break;
#endif /* JS_HAS_LEXICAL_CLOSURE */

#if JS_HAS_EXPORT_IMPORT
	  case JSOP_EXPORTALL:
	    obj = js_FindVariableScope(cx, &fun);
	    if (!obj) {
		ok = JS_FALSE;
	    } else {
		ida = JS_Enumerate(cx, obj);
		if (!ida) {
		    ok = JS_FALSE;
		} else {
		    for (i = 0, j = ida->length; i < j; i++) {
			id = ida->vector[i];
			ok = OBJ_LOOKUP_PROPERTY(cx, obj, id, &obj2, &prop);
			if (!ok)
			    break;
			if (!prop)
			    continue;
			ok = OBJ_GET_ATTRIBUTES(cx, obj, id, prop, &attrs);
			if (ok) {
			    attrs |= JSPROP_EXPORTED;
			    ok = OBJ_SET_ATTRIBUTES(cx, obj, id, prop, &attrs);
			}
			OBJ_DROP_PROPERTY(cx, obj2, prop);
			if (!ok)
			    break;
		    }
		    JS_DestroyIdArray(cx, ida);
		}
	    }
	    break;

	  case JSOP_EXPORTNAME:
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;
	    obj  = js_FindVariableScope(cx, &fun);
	    if (!obj) {
		ok = JS_FALSE;
		goto out;
	    }
	    ok = OBJ_LOOKUP_PROPERTY(cx, obj, id, &obj2, &prop);
	    if (!ok)
		goto out;
	    if (!prop) {
		ok = OBJ_DEFINE_PROPERTY(cx, obj, id, JSVAL_VOID, NULL, NULL,
					 JSPROP_EXPORTED, NULL);
	    } else {
		ok = OBJ_GET_ATTRIBUTES(cx, obj, id, prop, &attrs);
		if (ok) {
		    attrs |= JSPROP_EXPORTED;
		    ok = OBJ_SET_ATTRIBUTES(cx, obj, id, prop, &attrs);
		}
		OBJ_DROP_PROPERTY(cx, obj2, prop);
	    }
	    if (!ok)
		goto out;
	    break;

	  case JSOP_IMPORTALL:
	    id = (jsid)JSVAL_VOID;
	    PROPERTY_OP(ok = ImportProperty(cx, obj, id));
	    break;

	  case JSOP_IMPORTPROP:
	    /* Get an immediate atom naming the property. */
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;
	    PROPERTY_OP(ok = ImportProperty(cx, obj, id));
	    break;

	  case JSOP_IMPORTELEM:
	    ELEMENT_OP(ok = ImportProperty(cx, obj, id));
	    break;
#endif /* JS_HAS_EXPORT_IMPORT */

	  case JSOP_TRAP:
	    switch (JS_HandleTrap(cx, script, pc, &rval)) {
	      case JSTRAP_ERROR:
		ok = JS_FALSE;
		goto out;
	      case JSTRAP_CONTINUE:
		JS_ASSERT(JSVAL_IS_INT(rval));
		op = (JSOp) JSVAL_TO_INT(rval);
		JS_ASSERT((uintN)op < (uintN)JSOP_LIMIT);
		goto do_op;
	      case JSTRAP_RETURN:
		fp->rval = rval;
		goto out;
#if JS_HAS_EXCEPTIONS
	      case JSTRAP_THROW:
                cx->throwing = JS_TRUE;
                cx->exception = rval;
                ok = JS_FALSE;
	        goto out;
#endif /* JS_HAS_EXCEPTIONS */
	      default:;
	    }
	    break;

	  case JSOP_GETARG:
	    obj = NULL;
	    slot = (uintN)GET_ARGNO(pc);
	    JS_ASSERT(slot < fp->fun->nargs);
	    PUSH_OPND(fp->argv[slot]);
	    break;

	  case JSOP_SETARG:
	    obj = NULL;
	    slot = (uintN)GET_ARGNO(pc);
	    JS_ASSERT(slot < fp->fun->nargs);
	    vp = &fp->argv[slot];
	    GC_POKE(cx, *vp);
	    *vp = sp[-1];
	    break;

	  case JSOP_GETVAR:
	    obj = NULL;
	    slot = (uintN)GET_VARNO(pc);
	    JS_ASSERT(slot < fp->fun->nvars);
	    PUSH_OPND(fp->vars[slot]);
	    break;

	  case JSOP_SETVAR:
	    obj = NULL;
	    slot = (uintN)GET_VARNO(pc);
	    JS_ASSERT(slot < fp->fun->nvars);
	    vp = &fp->vars[slot];
	    GC_POKE(cx, *vp);
	    *vp = sp[-1];
	    break;

#if JS_HAS_INITIALIZERS
	  case JSOP_NEWINIT:
	    argc = 0;
	    fp->sharpDepth++;
	    goto do_new;

	  case JSOP_ENDINIT:
	    if (--fp->sharpDepth == 0)
		fp->sharpArray = NULL;
	    break;

	  case JSOP_INITPROP:
	    /* Pop the property's value into rval. */
	    JS_ASSERT(sp - newsp >= 2);
	    rval = POP();

	    /* Get the immediate property name into id. */
	    atom = GET_ATOM(cx, script, pc);
	    id   = (jsid)atom;
	    goto do_init;

	  case JSOP_INITELEM:
	    /* Pop the element's value into rval. */
	    JS_ASSERT(sp - newsp >= 3);
	    rval = POP();

	    /* Pop and conditionally atomize the element id. */
	    POP_ELEMENT_ID(id);

	  do_init:
	    /* Find the object being initialized at top of stack. */
	    lval = sp[-1];
	    JS_ASSERT(JSVAL_IS_OBJECT(lval));
	    obj = JSVAL_TO_OBJECT(lval);

	    /* Set the property named by obj[id] to rval. */
	    ok = OBJ_SET_PROPERTY(cx, obj, id, &rval);
	    if (!ok)
		goto out;
	    break;

#if JS_HAS_SHARP_VARS
	  case JSOP_DEFSHARP:
	    obj = fp->sharpArray;
	    if (!obj) {
		obj = js_NewArrayObject(cx, 0, NULL);
		if (!obj) {
		    ok = JS_FALSE;
		    goto out;
		}
		fp->sharpArray = obj;
	    }
	    i = (jsint) GET_ATOM_INDEX(pc);
	    id = (jsid) INT_TO_JSVAL(i);
	    rval = sp[-1];
	    if (JSVAL_IS_PRIMITIVE(rval)) {
		char numBuf[12];
		JS_snprintf(numBuf, sizeof numBuf, "%u", (unsigned) i);
		JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
				     JSMSG_BAD_SHARP_DEF, numBuf);
		ok = JS_FALSE;
		goto out;
	    }
	    ok = OBJ_SET_PROPERTY(cx, obj, id, &rval);
	    if (!ok)
		goto out;
	    break;

	  case JSOP_USESHARP:
	    i = (jsint) GET_ATOM_INDEX(pc);
	    id = (jsid) INT_TO_JSVAL(i);
	    obj = fp->sharpArray;
	    if (!obj) {
		rval = JSVAL_VOID;
	    } else {
		ok = OBJ_GET_PROPERTY(cx, obj, id, &rval);
		if (!ok)
		    goto out;
	    }
	    if (!JSVAL_IS_OBJECT(rval)) {
		char numBuf[12];
		JS_snprintf(numBuf, sizeof numBuf, "%u", (unsigned) i);
		JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
				     JSMSG_BAD_SHARP_USE, numBuf);
		ok = JS_FALSE;
		goto out;
	    }
	    PUSH_OPND(rval);
	    break;
#endif /* JS_HAS_SHARP_VARS */
#endif /* JS_HAS_INITIALIZERS */

#if JS_HAS_EXCEPTIONS
	  /* reset the stack to the given depth */
	  case JSOP_SETSP:
	    i = (jsint) GET_ATOM_INDEX(pc);
	    JS_ASSERT(i >= 0);
	    sp = newsp + i;
	    break;

	  case JSOP_GOSUB:
	    len = GET_JUMP_OFFSET(pc);
	    JS_ASSERT(js_CodeSpec[JSOP_GOSUB].length == 3);
	    i = pc - script->code + 3;
	    PUSH(INT_TO_JSVAL(i));
	    break;

	  case JSOP_RETSUB:
	    rval = POP();
	    JS_ASSERT(JSVAL_IS_INT(rval));
	    i = JSVAL_TO_INT(rval);
	    pc = script->code + i;
	    len = 0;
	    break;

	  case JSOP_EXCEPTION:
	    PUSH(cx->exception);
	    break;

	  case JSOP_THROW:
	    cx->throwing = JS_TRUE;
	    cx->exception = POP();
	    ok = JS_FALSE;
            /* let the code at out try to catch the exception. */
	    goto out;
#endif /* JS_HAS_EXCEPTIONS */

#if JS_HAS_INSTANCEOF
	  case JSOP_INSTANCEOF:
	    rval = POP();
	    if (JSVAL_IS_PRIMITIVE(rval)) {
		str = js_DecompileValueGenerator(cx, rval, NULL);
		if (str) {
		    JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
					 JSMSG_BAD_INSTANCEOF_RHS,
					 JS_GetStringBytes(str));
		}
		ok = JS_FALSE;
		goto out;
	    }
	    obj = JSVAL_TO_OBJECT(rval);
	    lval = POP();
	    cond = JS_FALSE;
	    if (obj->map->ops->hasInstance) {
		SAVE_SP(fp);
		ok = obj->map->ops->hasInstance(cx, obj, lval, &cond);
		if (!ok)
		    goto out;
	    }
	    PUSH_OPND(BOOLEAN_TO_JSVAL(cond));
	    break;
#endif /* JS_HAS_INSTANCEOF */

#if JS_HAS_DEBUGGER_KEYWORD
	  case JSOP_DEBUGGER:
	    if (rt->debuggerHandler) {
		JSTrapHandler handler = (JSTrapHandler) rt->debuggerHandler;
		/* check copy of pointer for safety in multithread situation */
		if (handler) {
		    switch (handler(cx, script, pc, &rval,
				    rt->debuggerHandlerData)) {
		      case JSTRAP_ERROR:
			ok = JS_FALSE;
			goto out;
		      case JSTRAP_CONTINUE:
			break;
		      case JSTRAP_RETURN:
			fp->rval = rval;
			goto out;
#if JS_HAS_EXCEPTIONS
		      case JSTRAP_THROW:
                        cx->throwing = JS_TRUE;
                        cx->exception = rval;
                        ok = JS_FALSE;
		        goto out;
#endif /* JS_HAS_EXCEPTIONS */
		      default:;
		    }
		}
	    }
	    break;
#endif /* JS_HAS_DEBUGGER_KEYWORD */

	  default: {
	    char numBuf[12];
	    JS_snprintf(numBuf, sizeof numBuf, "%d", op);
	    JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL,
				 JSMSG_BAD_BYTECODE, numBuf);
	    ok = JS_FALSE;
	    goto out;
	  }
	}

    advance_pc:
	pc += len;

#ifdef DEBUG
	if (tracefp) {
	    intN ndefs, n;

	    ndefs = cs->ndefs;
	    if (ndefs) {
		fp->sp = sp - ndefs;
		for (n = 0; n < ndefs; n++) {
		    str = js_DecompileValueGenerator(cx, *fp->sp, NULL);
		    if (str) {
			fprintf(tracefp, "%s %s",
				(n == 0) ? "  output:" : ",",
				JS_GetStringBytes(str));
		    }
		    fp->sp++;
		}
		putc('\n', tracefp);
	    }
	}
#endif
    }
out:

#if JS_HAS_EXCEPTIONS
    if (!ok && cx->throwing) {
        /*
         * Check if an exception has been raised.  If so, there may be
         * a try block within this frame that can catch the exception.
         */ 
        tn = script->trynotes;
        if (tn) {
            offset = PTRDIFF(pc, script->code, jsbytecode);
            while (JS_UPTRDIFF(offset, tn->start) >= (jsuword)tn->length)
                tn++;
            if (tn->catchStart) {
                pc = script->code + tn->catchStart;
                len = 0;
                cx->throwing = JS_FALSE; /* caught */
                ok = JS_TRUE;
                goto advance_pc;
            }
        }
    }
#endif

    /*
     * Restore the previous frame's execution state.
     */
    js_FreeStack(cx, mark);
    cx->interpLevel--;
    return ok;
}