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
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. //! This crate provides raw bindings for the JavaScriptCore public //! API. It is a pretty direct mapping of the underlying C API //! provided by JavaScriptCore. #![allow(non_camel_case_types, non_snake_case)] use std::ptr; /// A group that associates JavaScript contexts with one another. /// Contexts in the same group may share and exchange JavaScript objects. #[doc(hidden)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct OpaqueJSContextGroup([u8; 0]); /// A group that associates JavaScript contexts with one another. /// Contexts in the same group may share and exchange JavaScript objects. pub type JSContextGroupRef = *const OpaqueJSContextGroup; /// A JavaScript execution context. Holds the global object and /// other execution state. #[doc(hidden)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct OpaqueJSContext([u8; 0]); /// A JavaScript execution context. Holds the global object and /// other execution state. pub type JSContextRef = *const OpaqueJSContext; /// A global JavaScript execution context. /// A `JSGlobalContext` is a `JSContext`. pub type JSGlobalContextRef = *mut OpaqueJSContext; /// A UTF16 character buffer. The fundamental string representation /// in JavaScript. #[doc(hidden)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct OpaqueJSString([u8; 0]); /// A UTF16 character buffer. The fundamental string representation /// in JavaScript. pub type JSStringRef = *mut OpaqueJSString; /// A JavaScript class. /// Used with `JSObjectMake` to construct objects with custom behavior. #[doc(hidden)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct OpaqueJSClass([u8; 0]); /// A JavaScript class. /// Used with `JSObjectMake` to construct objects with custom behavior. pub type JSClassRef = *mut OpaqueJSClass; /// An array of JavaScript property names. #[doc(hidden)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct OpaqueJSPropertyNameArray([u8; 0]); /// An array of JavaScript property names. /// /// Values of this type are obtained via [`JSObjectCopyPropertyNames`]. /// /// Operations: /// /// * [`JSPropertyNameArrayGetCount`] /// * [`JSPropertyNameArrayGetNameAtIndex`] /// * [`JSPropertyNameArrayRelease`] /// * [`JSPropertyNameArrayRetain`] /// /// [`JSObjectCopyPropertyNames`]: fn.JSObjectCopyPropertyNames.html /// [`JSPropertyNameArrayGetCount`]: fn.JSPropertyNameArrayGetCount.html /// [`JSPropertyNameArrayGetNameAtIndex`]: fn.JSPropertyNameArrayGetNameAtIndex.html /// [`JSPropertyNameArrayRelease`]: fn.JSPropertyNameArrayRelease.html /// [`JSPropertyNameArrayRetain`]: fn.JSPropertyNameArrayRetain.html pub type JSPropertyNameArrayRef = *mut OpaqueJSPropertyNameArray; /// An ordered set used to collect the names of /// a JavaScript object's properties. #[doc(hidden)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct OpaqueJSPropertyNameAccumulator([u8; 0]); /// An ordered set used to collect the names of /// a JavaScript object's properties. /// /// Values of this type are passed to the [getPropertyNames callback]. /// Names are added to the accumulator using [`JSPropertyNameAccumulatorAddName`]. /// /// [getPropertyNames callback]: type.JSObjectGetPropertyNamesCallback.html /// [`JSPropertyNameAccumulatorAddName`]: fn.JSPropertyNameAccumulatorAddName.html pub type JSPropertyNameAccumulatorRef = *mut OpaqueJSPropertyNameAccumulator; /// A function used to deallocate bytes passed to a Typed Array constructor. /// The function should take two arguments. The first is a pointer to /// the bytes that were originally passed to the Typed Array constructor. /// The second is a pointer to additional information desired at the time /// the bytes are to be freed. pub type JSTypedArrayBytesDeallocator = ::std::option::Option< unsafe extern "C" fn(bytes: *mut ::std::os::raw::c_void, deallocatorContext: *mut ::std::os::raw::c_void), >; /// A JavaScript value. /// The base type for all JavaScript values, and polymorphic functions on them. #[doc(hidden)] #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct OpaqueJSValue([u8; 0]); /// A JavaScript value. /// The base type for all JavaScript values, and polymorphic functions on them. pub type JSValueRef = *const OpaqueJSValue; /// A JavaScript object. A `JSObjectRef` is a `JSValueRef`. pub type JSObjectRef = *mut OpaqueJSValue; extern "C" { /// Evaluates a string of JavaScript. /// /// * `ctx`: The execution context to use. /// * `script`: A `JSString` containing the script to evaluate. /// * `thisObject`: The object to use as `this`, or `NULL` to /// use the global object as `this`. /// * `sourceURL`: A `JSString` containing a URL for the script's /// source file. This is used by debuggers and when reporting /// exceptions. Pass `NULL` if you do not care to include source /// file information. /// * `startingLineNumber`: An integer value specifying the script's /// starting line number in the file located at `sourceURL`. This /// is only used when reporting exceptions. The value is one-based, /// so the first line is line `1` and invalid values are clamped /// to `1`. /// * `exception`: A pointer to a `JSValueRef` in which to store an /// exception, if any. Pass `NULL` if you do not care to store an /// exception. /// /// The `JSValue` that results from evaluating script, or `NULL` if an exception is thrown. pub fn JSEvaluateScript( ctx: JSContextRef, script: JSStringRef, thisObject: JSObjectRef, sourceURL: JSStringRef, startingLineNumber: ::std::os::raw::c_int, exception: *mut JSValueRef, ) -> JSValueRef; /// Checks for syntax errors in a string of JavaScript. /// /// * `ctx`: The execution context to use. /// * `script`: A `JSString` containing the script to check for /// syntax errors. /// * `sourceURL`: A `JSString` containing a URL for the script's /// source file. This is only used when reporting exceptions. /// Pass `NULL` if you do not care to include source file /// information in exceptions. /// * `startingLineNumber`: An integer value specifying the script's /// starting line number in the file located at `sourceURL`. This /// is only used when reporting exceptions. The value is one-based, /// so the first line is line `1` and invalid values are clamped /// to `1`. /// * `exception`: A pointer to a `JSValueRef` in which to store a /// syntax error exception, if any. Pass `NULL` if you do not care /// to store a syntax error exception. /// /// Returns `true` if the script is syntactically correct, otherwise `false`. pub fn JSCheckScriptSyntax( ctx: JSContextRef, script: JSStringRef, sourceURL: JSStringRef, startingLineNumber: ::std::os::raw::c_int, exception: *mut JSValueRef, ) -> bool; /// Performs a JavaScript garbage collection. /// /// JavaScript values that are on the machine stack, in a register, /// protected by `JSValueProtect`, set as the global object of an /// execution context, or reachable from any such value will not /// be collected. /// /// During JavaScript execution, you are not required to call this /// function; the JavaScript engine will garbage collect as needed. /// JavaScript values created within a context group are automatically /// destroyed when the last reference to the context group is released. /// /// * `ctx`: The execution context to use. pub fn JSGarbageCollect(ctx: JSContextRef); } /// A constant identifying the type of a `JSValue`. #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSType { /// The unique `undefined` value. Undefined = 0, /// The unique `null` value. Null = 1, /// A primitive boolean value, one of `true` or `false`. Boolean = 2, /// A primitive number value. Number = 3, /// A primitive string value. String = 4, /// An object value (meaning that this `JSValueRef` is a `JSObjectRef`). Object = 5, } /// A constant identifying the Typed Array type of a `JSObjectRef`. #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum JSTypedArrayType { /// `Int8Array` Int8Array = 0, /// `Int16Array` Int16Array = 1, /// `Int32Array` Int32Array = 2, /// `Uint8Array` Uint8Array = 3, /// `Uint8ClampedArray` Uint8ClampedArray = 4, /// `Uint16Array` Uint16Array = 5, /// `Uint32Array` Uint32Array = 6, /// `Float32Array` Float32Array = 7, /// `Float64Array` Float64Array = 8, /// `ArrayBuffer` ArrayBuffer = 9, /// Not a Typed Array None = 10, } extern "C" { /// Returns a JavaScript value's type. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` whose type you want to obtain. /// /// Returns a value of type `JSType` that identifies `value`'s type. pub fn JSValueGetType(ctx: JSContextRef, arg1: JSValueRef) -> JSType; /// Tests whether a JavaScript value's type is the `undefined` type. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to test. /// /// Returns `true` if `value`'s type is the `undefined` type, otherwise `false`. pub fn JSValueIsUndefined(ctx: JSContextRef, value: JSValueRef) -> bool; /// Tests whether a JavaScript value's type is the `null` type. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to test. /// /// Returns `true` if `value`'s type is the `null` type, otherwise `false`. pub fn JSValueIsNull(ctx: JSContextRef, value: JSValueRef) -> bool; /// Tests whether a JavaScript value's type is the `boolean` type. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to test. /// /// Returns `true` if `value`'s type is the `boolean` type, otherwise `false`. pub fn JSValueIsBoolean(ctx: JSContextRef, value: JSValueRef) -> bool; /// Tests whether a JavaScript value's type is the `number` type. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to test. /// /// Returns `true` if `value`'s type is the `number` type, otherwise `false`. pub fn JSValueIsNumber(ctx: JSContextRef, value: JSValueRef) -> bool; /// Tests whether a JavaScript value's type is the `string` type. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to test. /// /// Returns `true` if `value`'s type is the `string` type, otherwise `false`. pub fn JSValueIsString(ctx: JSContextRef, value: JSValueRef) -> bool; /// Tests whether a JavaScript value's type is the `object` type. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to test. /// /// Returns `true` if `value`'s type is the `object` type, otherwise `false`. pub fn JSValueIsObject(ctx: JSContextRef, value: JSValueRef) -> bool; /// Tests whether a JavaScript value is an `object` with a given class in its class chain. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to test. /// * `jsClass`: The `JSClass` to test against. /// /// Returns `true` if `value` is an `object` and has `jsClass` in its /// class chain, otherwise `false`. pub fn JSValueIsObjectOfClass( ctx: JSContextRef, value: JSValueRef, jsClass: JSClassRef, ) -> bool; /// Tests whether a JavaScript value is an `array`. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to test. /// /// Returns `true` if `value` is an `array`, otherwise `false`. pub fn JSValueIsArray(ctx: JSContextRef, value: JSValueRef) -> bool; /// Tests whether a JavaScript value is a `date`. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to test. /// /// Returns `true` if `value` is a `date`, otherwise `false`. pub fn JSValueIsDate(ctx: JSContextRef, value: JSValueRef) -> bool; /// Returns a JavaScript value's Typed Array type. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` whose Typed Array type to return. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a value of type `JSTypedArrayType` that identifies /// value's Typed Array type, or `JSTypedArrayType::None` if the /// value is not a Typed Array object. pub fn JSValueGetTypedArrayType( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> JSTypedArrayType; /// Tests whether two JavaScript values are equal, as compared by the JS `==` operator. /// /// * `ctx`: The execution context to use. /// * `a`: The first value to test. /// * `b`: The second value to test. /// * `exception`: A pointer to a `JSValueRef` in which to /// store an exception, if any. Pass `NULL` if you do /// not care to store an exception. /// /// Returns `true` if the two values are equal, `false` if /// they are not equal or an exception is thrown. pub fn JSValueIsEqual( ctx: JSContextRef, a: JSValueRef, b: JSValueRef, exception: *mut JSValueRef, ) -> bool; /// Tests whether two JavaScript values are strict equal, as compared /// by the JS `===` operator. /// /// * `ctx`: The execution context to use. /// * `a`: The first value to test. /// * `b`: The second value to test. /// /// Returns `true` if the two values are strict equal, otherwise `false`. pub fn JSValueIsStrictEqual(ctx: JSContextRef, a: JSValueRef, b: JSValueRef) -> bool; /// Tests whether a JavaScript value is an object constructed by a /// given constructor, as compared by the JS `instanceof` operator. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to test. /// * `constructor`: The constructor to test against. /// * `exception`: A pointer to a `JSValueRef` in which to /// store an exception, if any. Pass `NULL` if you do /// not care to store an exception. /// /// Returns `true` if value is an object constructed by constructor, /// as compared by the JS `instanceof` operator, otherwise `false`. pub fn JSValueIsInstanceOfConstructor( ctx: JSContextRef, value: JSValueRef, constructor: JSObjectRef, exception: *mut JSValueRef, ) -> bool; /// Creates a JavaScript value of the `undefined` type. /// /// * `ctx`: The execution context to use. /// /// Returns the unique `undefined` value. pub fn JSValueMakeUndefined(ctx: JSContextRef) -> JSValueRef; /// Creates a JavaScript value of the `null` type. /// /// * `ctx`: The execution context to use. /// /// Returns the unique `null` value. pub fn JSValueMakeNull(ctx: JSContextRef) -> JSValueRef; /// Creates a JavaScript value of the `boolean` type. /// /// * `ctx`: The execution context to use. /// * `boolean`: The `bool` to assign to the newly created `JSValue`. /// /// Returns a `JSValue` of the `boolean` type, representing the value of `boolean`. pub fn JSValueMakeBoolean(ctx: JSContextRef, boolean: bool) -> JSValueRef; /// Creates a JavaScript value of the `number` type. /// /// * `ctx`: The execution context to use. /// * `number`: The `f64` to assign to the newly created `JSValue`. /// /// Returns a `JSValue` of the `number` type, representing the value of `number`. pub fn JSValueMakeNumber(ctx: JSContextRef, number: f64) -> JSValueRef; /// Creates a JavaScript value of the string type. /// /// * `ctx`: The execution context to use. /// * `string`: The `JSString` to assign to the newly created /// `JSValue`. The newly created `JSValue` retains string, and /// releases it upon garbage collection. /// /// Returns a `JSValue` of the `string` type, representing the value of `string`. pub fn JSValueMakeString(ctx: JSContextRef, string: JSStringRef) -> JSValueRef; /// Creates a JavaScript value from a JSON formatted string. /// /// * `ctx`: The execution context to use. /// * `string`: The `JSString` containing the JSON string to be parsed. /// /// Returns a `JSValue` containing the parsed value, or `NULL` if the input is invalid. pub fn JSValueMakeFromJSONString(ctx: JSContextRef, string: JSStringRef) -> JSValueRef; /// Creates a JavaScript string containing the JSON serialized representation of a JS value. /// /// * `ctx`: The execution context to use. /// * `value`: The value to serialize. /// * `indent`: The number of spaces to indent when nesting. /// If `0`, the resulting JSON will not contains newlines. /// The size of the indent is clamped to `10` spaces. /// * `exception`: A pointer to a `JSValueRef` in which to /// store an exception, if any. Pass `NULL` if you do not /// care to store an exception. /// /// Returns a `JSString` with the result of serialization, or `NULL` if an exception is thrown. pub fn JSValueCreateJSONString( ctx: JSContextRef, value: JSValueRef, indent: ::std::os::raw::c_uint, exception: *mut JSValueRef, ) -> JSStringRef; /// Converts a JavaScript value to boolean and returns the resulting boolean. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to convert. /// /// Returns the boolean result of conversion. pub fn JSValueToBoolean(ctx: JSContextRef, value: JSValueRef) -> bool; /// Converts a JavaScript value to number and returns the resulting number. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to convert. /// * `exception`: A pointer to a `JSValueRef` in which to store an /// exception, if any. Pass `NULL` if you do not care to store an /// exception. /// /// Returns the numeric result of conversion, or `NaN` if an exception is thrown. pub fn JSValueToNumber(ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef) -> f64; /// Converts a JavaScript value to string and copies the result into a JavaScript string. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to convert. /// * `exception`: A pointer to a `JSValueRef` in which to store an /// exception, if any. Pass `NULL` if you do not care to store an /// exception. /// /// Returns a `JSString` with the result of conversion, or `NULL` /// if an exception is thrown. Ownership follows the Create Rule. pub fn JSValueToStringCopy( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> JSStringRef; /// Converts a JavaScript value to object and returns the resulting object. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to convert. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to store /// an exception. /// /// Returns the `JSObject` result of conversion, or `NULL` if /// an exception is thrown. pub fn JSValueToObject( ctx: JSContextRef, value: JSValueRef, exception: *mut JSValueRef, ) -> JSObjectRef; /// Protects a JavaScript value from garbage collection. /// /// Use this method when you want to store a `JSValue` in a /// global or on the heap, where the garbage collector will /// not be able to discover your reference to it. /// /// A value may be protected multiple times and must be /// unprotected an equal number of times before becoming /// eligible for garbage collection. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to protect. pub fn JSValueProtect(ctx: JSContextRef, value: JSValueRef); /// Unprotects a JavaScript value from garbage collection. /// /// A value may be protected multiple times and must be unprotected /// an equal number of times before becoming eligible for garbage /// collection. /// /// * `ctx`: The execution context to use. /// * `value`: The `JSValue` to unprotect. pub fn JSValueUnprotect(ctx: JSContextRef, value: JSValueRef); } /// A set of `JSPropertyAttribute`s. /// /// Combine multiple attributes by logically ORing them together. pub type JSPropertyAttributes = ::std::os::raw::c_uint; /// A set of `JSClassAttribute`s. /// /// Combine multiple attributes by logically ORing them together. pub type JSClassAttributes = ::std::os::raw::c_uint; /// The callback invoked when an object is first created. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` being created. /// /// If you named your function `Initialize`, you would declare it like this: /// /// ```ignore /// void /// Initialize(JSContextRef ctx, JSObjectRef object); /// ``` /// /// Unlike the other object callbacks, the initialize callback is /// called on the least derived class (the parent class) first, /// and the most derived class last. pub type JSObjectInitializeCallback = ::std::option::Option<unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef)>; /// The callback invoked when an object is finalized (prepared /// for garbage collection). An object may be finalized on any thread. /// /// * `object`: The `JSObject` being finalized. /// /// If you named your function `Finalize`, you would declare it like this: /// /// ```ignore /// void /// Finalize(JSObjectRef object); /// ``` /// /// The finalize callback is called on the most derived class /// first, and the least derived class (the parent class) last. /// /// You must not call any function that may cause a garbage /// collection or an allocation of a garbage collected object /// from within a `JSObjectFinalizeCallback`. This includes /// all functions that have a `JSContextRef` parameter. pub type JSObjectFinalizeCallback = ::std::option::Option<unsafe extern "C" fn(object: JSObjectRef)>; /// The callback invoked when determining whether an object has a property. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` to search for the property. /// * `propertyName`: A `JSString` containing the name of the property look up. /// /// Returns `true` if object has the property, otherwise `false`. /// /// If you named your function `HasProperty`, you would declare it like this: /// /// ```ignore /// bool /// HasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); /// ``` /// /// If this function returns `false`, the `hasProperty` request /// forwards to object's statically declared properties, then /// its parent class chain (which includes the default object /// class), then its prototype chain. /// /// This callback enables optimization in cases where only a /// property's existence needs to be known, not its value, /// and computing its value would be expensive. /// /// If this callback is NULL, the getProperty callback will be used to service hasProperty requests. pub type JSObjectHasPropertyCallback = ::std::option::Option< unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef, propertyName: JSStringRef) -> bool, >; /// The callback invoked when getting a property's value. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` to search for the property. /// * `propertyName`: A `JSString` containing the name of the property to get. /// * `exception`: A pointer to a `JSValueRef` in which to return an exception, if any. /// /// Returns the property's value if object has the property, otherwise `NULL`. /// /// If you named your function `GetProperty`, you would declare it like this: /// /// ```ignore /// JSValueRef /// GetProperty(JSContextRef ctx, JSObjectRef object, /// JSStringRef propertyName, JSValueRef* exception); /// ``` /// /// If this function returns `NULL`, the get request forwards to `object`'s /// statically declared properties, then its parent class chain (which /// includes the default object class), then its prototype chain. pub type JSObjectGetPropertyCallback = ::std::option::Option< unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef, propertyName: JSStringRef, exception: *mut JSValueRef) -> *const OpaqueJSValue, >; /// The callback invoked when setting a property's value. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` on which to set the property's value. /// * `propertyName`: A `JSString` containing the name of the property to set. /// * `value`: A `JSValue` to use as the property's value. /// * `exception`: A pointer to a `JSValueRef` in which to return an exception, if any. /// /// Returns `true` if the property was set, otherwise `false`. /// /// If you named your function `SetProperty`, you would declare it like this: /// /// ```ignore /// bool /// SetProperty(JSContextRef ctx, JSObjectRef object, /// JSStringRef propertyName, JSValueRef value, /// JSValueRef* exception); /// ``` /// /// If this function returns `false`, the set request forwards to /// `object`'s statically declared properties, then its parent class /// chain (which includes the default object class). pub type JSObjectSetPropertyCallback = ::std::option::Option< unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef, propertyName: JSStringRef, value: JSValueRef, exception: *mut JSValueRef) -> bool, >; /// The callback invoked when deleting a property. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` in which to delete the property. /// * `propertyName`: A `JSString` containing the name of the property to delete. /// * `exception`: A pointer to a `JSValueRef` in which to return an exception, if any. /// /// Returns `true` if `propertyName` was successfully deleted, otherwise `false`. /// /// If you named your function `DeleteProperty`, you would declare it like this: /// /// ```ignore /// bool /// DeleteProperty(JSContextRef ctx, JSObjectRef object, /// JSStringRef propertyName, JSValueRef* exception); /// ``` /// /// If this function returns `false`, the delete request forwards to /// `object`'s statically declared properties, then its parent class /// chain (which includes the default object class). pub type JSObjectDeletePropertyCallback = ::std::option::Option< unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef, propertyName: JSStringRef, exception: *mut JSValueRef) -> bool, >; /// The callback invoked when collecting the names of an object's properties. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` whose property names are being collected. /// * `propertyNames`: A JavaScript property name accumulator in which to /// accumulate the names of object's properties. /// /// If you named your function `GetPropertyNames`, you would declare it like this: /// /// ```ignore /// void /// GetPropertyNames(JSContextRef ctx, JSObjectRef object, /// JSPropertyNameAccumulatorRef propertyNames); /// ``` /// /// Property name accumulators are used by `JSObjectCopyPropertyNames` /// and JavaScript `for...in` loops. /// /// Use [`JSPropertyNameAccumulatorAddName`] to add property names to /// accumulator. A class's `getPropertyNames` callback only needs to /// provide the names of properties that the class vends through a /// custom `getProperty` or `setProperty` callback. Other properties, /// including statically declared properties, properties vended by /// other classes, and properties belonging to object's prototype, /// are added independently. /// /// [`JSPropertyNameAccumulatorAddName`]: fn.JSPropertyNameAccumulatorAddName.html pub type JSObjectGetPropertyNamesCallback = ::std::option::Option< unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef, propertyNames: JSPropertyNameAccumulatorRef), >; /// The callback invoked when an object is called as a function. /// /// * `ctx`: The execution context to use. /// * `function`: A `JSObject` that is the function being called. /// * `thisObject`: A `JSObject` that is the `this` variable in the function's scope. /// * `argumentCount`: An integer count of the number of arguments in `arguments`. /// * `arguments`: A `JSValue` array of the arguments passed to the function. /// * `exception`: A pointer to a `JSValueRef` in which to return an exception, if any. /// /// Returns a `JSValue` that is the function's return value. /// /// If you named your function `CallAsFunction`, you would declare it like this: /// /// ```ignore /// JSValueRef /// CallAsFunction(JSContextRef ctx, JSObjectRef function, /// JSObjectRef thisObject, /// size_t argumentCount, const JSValueRef arguments[], /// JSValueRef* exception); /// ``` /// /// If your callback were invoked by the JavaScript expression /// `myObject.myFunction()`, function would be set to `myFunction`, /// and `thisObject` would be set to `myObject`. /// /// If this callback is `NULL`, calling your object as a function /// will throw an exception. pub type JSObjectCallAsFunctionCallback = ::std::option::Option< unsafe extern "C" fn(ctx: JSContextRef, function: JSObjectRef, thisObject: JSObjectRef, argumentCount: usize, arguments: *const JSValueRef, exception: *mut JSValueRef) -> *const OpaqueJSValue, >; /// The callback invoked when an object is used as a constructor in a `new` expression. /// /// * `ctx`: The execution context to use. /// * `constructor`: A `JSObject` that is the constructor being called. /// * `argumentCount`: An integer count of the number of arguments in `arguments`. /// * `arguments`: A `JSValue` array of the arguments passed to the function. /// * `exception`: A pointer to a `JSValueRef` in which to return an exception, if any. /// /// Returns a `JSObject` that is the constructor's return value. /// /// If you named your function `CallAsConstructor`, you would declare it like this: /// /// ```ignore /// JSObjectRef /// CallAsConstructor(JSContextRef ctx, JSObjectRef constructor, /// size_t argumentCount, const JSValueRef arguments[], /// JSValueRef* exception); /// ``` /// /// If your callback were invoked by the JavaScript expression /// `new myConstructor()`, constructor would be set to `myConstructor`. /// /// If this callback is `NULL`, using your object as a constructor in a /// `new` expression will throw an exception. pub type JSObjectCallAsConstructorCallback = ::std::option::Option< unsafe extern "C" fn(ctx: JSContextRef, constructor: JSObjectRef, argumentCount: usize, arguments: *const JSValueRef, exception: *mut JSValueRef) -> *mut OpaqueJSValue, >; /// The callback invoked when an object is used as the target /// of an `instanceof` expression. /// /// * `ctx`: The execution context to use. /// * `constructor`: The `JSObject` that is the target of the /// `instanceof` expression. /// * `possibleInstance`: The `JSValue` being tested to determine if it /// is an instance of `constructor`. /// * `exception`: A pointer to a `JSValueRef` in which to return an exception, if any. /// /// Returns `true` if `possibleInstance` is an instance of `constructor`, /// otherwise `false`. /// /// If you named your function `HasInstance`, you would declare it like this: /// /// ```ignore /// bool /// HasInstance(JSContextRef ctx, JSObjectRef constructor, /// JSValueRef possibleInstance, JSValueRef* exception); /// ``` /// /// If your callback were invoked by the JavaScript expression /// `someValue instanceof myObject`, constructor would be set /// to `myObject` and `possibleInstance` would be set to `someValue`. /// /// If this callback is `NULL`, `instanceof` expressions that target /// your object will return `false`. /// /// Standard JavaScript practice calls for objects that implement /// the `callAsConstructor` callback to implement the `hasInstance` /// callback as well. pub type JSObjectHasInstanceCallback = ::std::option::Option< unsafe extern "C" fn(ctx: JSContextRef, constructor: JSObjectRef, possibleInstance: JSValueRef, exception: *mut JSValueRef) -> bool, >; /// The callback invoked when converting an object to a particular /// JavaScript type. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` to convert. /// * `type`: A `JSType` specifying the JavaScript type to convert to. /// * `exception`: A pointer to a `JSValueRef` in which to return an exception, if any. /// ///Returns the objects's converted value, or `NULL` if the object was not converted. /// /// If you named your function `ConvertToType`, you would declare it like this: /// /// ```ignore /// JSValueRef /// ConvertToType(JSContextRef ctx, JSObjectRef object, JSType type, /// JSValueRef* exception); /// ``` /// /// If this function returns `false`, the conversion request forwards /// to object's parent class chain (which includes the default object /// class). /// /// This function is only invoked when converting an object to number /// or string. An object converted to boolean is `true`. An object /// converted to object is itself. pub type JSObjectConvertToTypeCallback = ::std::option::Option< unsafe extern "C" fn(ctx: JSContextRef, object: JSObjectRef, type_: JSType, exception: *mut JSValueRef) -> *const OpaqueJSValue, >; /// A statically declared value property. #[repr(C)] #[derive(Debug, Copy)] pub struct JSStaticValue { /// A null-terminated UTF8 string containing the property's name. pub name: *const ::std::os::raw::c_char, /// A `JSObjectGetPropertyCallback` to invoke when getting the property's value. pub getProperty: JSObjectGetPropertyCallback, /// A `JSObjectSetPropertyCallback` to invoke when setting the property's value. /// May be `NULL` if the `ReadOnly` attribute is set. pub setProperty: JSObjectSetPropertyCallback, /// A logically ORed set of `JSPropertyAttributes` to give to the property. pub attributes: JSPropertyAttributes, } impl Clone for JSStaticValue { fn clone(&self) -> Self { *self } } /// A statically declared function property. #[repr(C)] #[derive(Debug, Copy)] pub struct JSStaticFunction { /// A null-terminated UTF8 string containing the property's name. pub name: *const ::std::os::raw::c_char, /// A `JSObjectCallAsFunctionCallback` to invoke when the property /// is called as a function. pub callAsFunction: JSObjectCallAsFunctionCallback, /// A logically ORed set of `JSPropertyAttributes` to give to the property. pub attributes: JSPropertyAttributes, } impl Clone for JSStaticFunction { fn clone(&self) -> Self { *self } } /// Contains properties and callbacks that define a type of object. /// /// All fields other than the version field are optional. Any pointer may be `NULL`. /// /// The `staticValues` and `staticFunctions` arrays are the simplest and most /// efficient means for vending custom properties. Statically declared /// properties automatically service requests like `getProperty`, /// `setProperty`, and `getPropertyNames`. Property access callbacks /// are required only to implement unusual properties, like array /// indexes, whose names are not known at compile-time. /// /// If you named your getter function `GetX` and your setter function /// `SetX`, you would declare a `JSStaticValue` array containing `"X"` like this: /// /// ```ignore /// JSStaticValue StaticValueArray[] = { /// { "X", GetX, SetX, kJSPropertyAttributeNone }, /// { 0, 0, 0, 0 } /// }; /// ``` /// /// Standard JavaScript practice calls for storing function objects in /// prototypes, so they can be shared. The default `JSClass` created by /// `JSClassCreate` follows this idiom, instantiating objects with a /// shared, automatically generating prototype containing the class's /// function objects. The `kJSClassAttributeNoAutomaticPrototype` /// attribute specifies that a `JSClass` should not automatically /// generate such a prototype. The resulting `JSClass` instantiates /// objects with the default object prototype, and gives each instance /// object its own copy of the class's function objects. /// /// A `NULL` callback specifies that the default object callback /// should substitute, except in the case of `hasProperty`, where it /// specifies that `getProperty` should substitute. #[repr(C)] #[derive(Debug, Copy)] pub struct JSClassDefinition { /// The version number of this structure. The current version is 0. pub version: ::std::os::raw::c_int, /// A logically ORed set of `JSClassAttributes` to give to the class. pub attributes: JSClassAttributes, /// A null-terminated UTF8 string containing the class's name. pub className: *const ::std::os::raw::c_char, /// A `JSClass` to set as the class's parent class. Pass `NULL` use the default object class. pub parentClass: JSClassRef, /// A `JSStaticValue` array containing the class's statically declared /// value properties. Pass `NULL` to specify no statically declared /// value properties. The array must be terminated by a `JSStaticValue` /// whose name field is NULL. pub staticValues: *const JSStaticValue, /// A `JSStaticFunction` array containing the class's statically /// declared function properties. Pass `NULL` to specify no /// statically declared function properties. The array must be /// terminated by a `JSStaticFunction` whose name field is `NULL`. pub staticFunctions: *const JSStaticFunction, /// The callback invoked when an object is first created. Use this callback /// to initialize the object. pub initialize: JSObjectInitializeCallback, /// The callback invoked when an object is finalized (prepared for garbage /// collection). Use this callback to release resources allocated for the /// object, and perform other cleanup. pub finalize: JSObjectFinalizeCallback, /// The callback invoked when determining whether an object has a property. /// /// If this field is `NULL`, `getProperty` is called instead. The /// `hasProperty` callback enables optimization in cases where /// only a property's existence needs to be known, not its value, /// and computing its value is expensive. pub hasProperty: JSObjectHasPropertyCallback, /// The callback invoked when getting a property's value. pub getProperty: JSObjectGetPropertyCallback, /// The callback invoked when setting a property's value. pub setProperty: JSObjectSetPropertyCallback, /// The callback invoked when deleting a property. pub deleteProperty: JSObjectDeletePropertyCallback, /// The callback invoked when collecting the names of an object's properties. pub getPropertyNames: JSObjectGetPropertyNamesCallback, /// The callback invoked when an object is called as a function. pub callAsFunction: JSObjectCallAsFunctionCallback, /// The callback invoked when an object is used as a constructor in a `new` expression. pub callAsConstructor: JSObjectCallAsConstructorCallback, /// The callback invoked when an object is used as the target of an `instanceof` expression. pub hasInstance: JSObjectHasInstanceCallback, /// The callback invoked when converting an object to a particular JavaScript type. pub convertToType: JSObjectConvertToTypeCallback, } impl Clone for JSClassDefinition { fn clone(&self) -> Self { *self } } impl Default for JSClassDefinition { fn default() -> Self { JSClassDefinition { version: 0, attributes: 0, className: ptr::null(), parentClass: ptr::null_mut(), staticValues: ptr::null(), staticFunctions: ptr::null(), initialize: None, finalize: None, hasProperty: None, getProperty: None, setProperty: None, deleteProperty: None, getPropertyNames: None, callAsFunction: None, callAsConstructor: None, hasInstance: None, convertToType: None, } } } extern "C" { /// Creates a JavaScript class suitable for use with `JSObjectMake`. /// /// * `definition`: A `JSClassDefinition` that defines the class. /// /// Returns a `JSClass` with the given definition. Ownership follows /// the Create Rule. pub fn JSClassCreate(definition: *const JSClassDefinition) -> JSClassRef; /// Retains a JavaScript class. /// /// `jsClass`: The `JSClass` to retain. /// /// Returns a `JSClass` that is the same as `jsClass`. pub fn JSClassRetain(jsClass: JSClassRef) -> JSClassRef; /// Releases a JavaScript class. /// /// `jsClass`: The `JSClass` to release. pub fn JSClassRelease(jsClass: JSClassRef); /// Creates a JavaScript object. /// /// The default object class does not allocate storage for private data, /// so you must provide a non-`NULL` `jsClass` to `JSObjectMake` if you /// want your object to be able to store private data. /// /// `data` is set on the created object before the initialize methods in /// its class chain are called. This enables the initialize methods to /// retrieve and manipulate data through `JSObjectGetPrivate`. /// /// * `ctx`: The execution context to use. /// * `jsClass`: The `JSClass` to assign to the object. Pass `NULL` to use /// the default object class. /// * `data`: A `void*` to set as the object's private data. /// Pass NULL to specify no private data. /// /// Returns a `JSObject` with the given class and private data. pub fn JSObjectMake( ctx: JSContextRef, jsClass: JSClassRef, data: *mut ::std::os::raw::c_void, ) -> JSObjectRef; /// Convenience method for creating a JavaScript function with a given /// callback as its implementation. /// /// * `ctx`: The execution context to use. /// * `name`: A `JSString` containing the function's name. This will be /// used when converting the function to string. Pass `NULL` to create /// an anonymous function. /// * `callAsFunction`: The `JSObjectCallAsFunctionCallback` to invoke /// when the function is called. /// /// Returns a `JSObject` that is a function. The object's prototype will be /// the default function prototype. pub fn JSObjectMakeFunctionWithCallback( ctx: JSContextRef, name: JSStringRef, callAsFunction: JSObjectCallAsFunctionCallback, ) -> JSObjectRef; /// Convenience method for creating a JavaScript constructor. /// /// * `ctx`: The execution context to use. /// * `jsClass`: A `JSClass` that is the class your constructor /// will assign to the objects its constructs. `jsClass` will /// be used to set the constructor's `.prototype` property, and /// to evaluate `instanceof` expressions. Pass `NULL` to use /// the default object class. /// * `callAsConstructor` A `JSObjectCallAsConstructorCallback` to /// invoke when your constructor is used in a `new` expression. /// Pass `NULL` to use the default object constructor. /// /// Returns a `JSObject` that is a constructor. The object's /// prototype will be the default object prototype. /// /// The default object constructor takes no arguments and constructs /// an object of class `jsClass` with no private data. pub fn JSObjectMakeConstructor( ctx: JSContextRef, jsClass: JSClassRef, callAsConstructor: JSObjectCallAsConstructorCallback, ) -> JSObjectRef; /// Creates a JavaScript Array object. /// /// * `ctx`: The execution context to use. /// * `argumentCount`: An integer count of the number of /// arguments in `arguments`. /// * `arguments`: A `JSValue` array of data to populate the /// `Array` with. Pass `NULL` if `argumentCount` is `0`. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObject` that is an `Array`. /// /// The behavior of this function does not exactly match the behavior /// of the built-in `Array` constructor. Specifically, if one argument /// is supplied, this function returns an array with one element. pub fn JSObjectMakeArray( ctx: JSContextRef, argumentCount: usize, arguments: *const JSValueRef, exception: *mut JSValueRef, ) -> JSObjectRef; /// Creates a JavaScript `Date` object, as if by invoking the /// built-in `Date` constructor. /// /// * `ctx`: The execution context to use. /// * `argumentCount`: An integer count of the number of /// arguments in `arguments`. /// * `arguments`: A `JSValue` array of arguments to pass to /// the `Date` constructor. Pass `NULL` if `argumentCount` is `0`. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObject` that is a `Date`. pub fn JSObjectMakeDate( ctx: JSContextRef, argumentCount: usize, arguments: *const JSValueRef, exception: *mut JSValueRef, ) -> JSObjectRef; /// Creates a JavaScript `Error` object, as if by invoking the /// built-in `Error` constructor. /// /// * `ctx`: The execution context to use. /// * `argumentCount`: An integer count of the number of /// arguments in `arguments`. /// * `arguments`: A `JSValue` array of arguments to pass to /// the `Error` constructor. Pass `NULL` if `argumentCount` is `0`. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObject` that is a `Error`. pub fn JSObjectMakeError( ctx: JSContextRef, argumentCount: usize, arguments: *const JSValueRef, exception: *mut JSValueRef, ) -> JSObjectRef; /// Creates a JavaScript `RegExp` object, as if by invoking the /// built-in `RegExp` constructor. /// /// * `ctx`: The execution context to use. /// * `argumentCount`: An integer count of the number of /// arguments in `arguments`. /// * `arguments`: A `JSValue` array of arguments to pass to /// the `RegExp` constructor. Pass `NULL` if `argumentCount` is `0`. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObject` that is a `RegExp`. pub fn JSObjectMakeRegExp( ctx: JSContextRef, argumentCount: usize, arguments: *const JSValueRef, exception: *mut JSValueRef, ) -> JSObjectRef; /// Creates a function with a given script as its body. /// /// * `ctx`: The execution context to use. /// * `name`: A `JSString` containing the function's name. This /// will be used when converting the function to string. Pass /// `NULL` to create an anonymous function. /// * `parameterCount`: An integer count of the number of parameter /// names in `parameterNames`. /// * `parameterNames`: A `JSString` array containing the names of /// the function's parameters. Pass `NULL` if `parameterCount` is `0`. /// * `body`: A `JSString` containing the script to use as the /// function's body. /// * `sourceURL` A `JSString` containing a URL for the script's /// source file. This is only used when reporting exceptions. /// Pass `NULL` if you do not care to include source file /// information in exceptions. /// * `startingLineNumber`: An integer value specifying the /// script's starting line number in the file located at /// `sourceURL`. This is only used when reporting exceptions. /// The value is one-based, so the first line is line `1` /// and invalid values are clamped to `1`. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObject` that is a function, or `NULL` if either /// body or `parameterNames` contains a syntax error. The /// object's prototype will be the default function prototype. /// /// Use this method when you want to execute a script repeatedly, to /// avoid the cost of re-parsing the script before each execution. pub fn JSObjectMakeFunction( ctx: JSContextRef, name: JSStringRef, parameterCount: ::std::os::raw::c_uint, parameterNames: *const JSStringRef, body: JSStringRef, sourceURL: JSStringRef, startingLineNumber: ::std::os::raw::c_int, exception: *mut JSValueRef, ) -> JSObjectRef; /// Gets an object's prototype. /// /// * `ctx`: The execution context to use. /// * `object`: A `JSObject` whose prototype you want to get. /// /// Returns a `JSValue` that is the object's prototype. pub fn JSObjectGetPrototype(ctx: JSContextRef, object: JSObjectRef) -> JSValueRef; ///Sets an object's prototype. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` whose prototype you want to set. /// * `value`: A `JSValue` to set as the object's prototype. pub fn JSObjectSetPrototype(ctx: JSContextRef, object: JSObjectRef, value: JSValueRef); /// Tests whether an object has a given property. /// /// * `object`: The `JSObject` to test. /// * `propertyName`: A `JSString` containing the property's name. /// /// Returns `true` if the object has a property whose name matches /// `propertyName`, otherwise `false`. pub fn JSObjectHasProperty( ctx: JSContextRef, object: JSObjectRef, propertyName: JSStringRef, ) -> bool; /// Gets a property from an object. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` whose property you want to get. /// * `propertyName`: A `JSString` containing the property's name. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns the property's value if object has the property, otherwise /// the undefined value. pub fn JSObjectGetProperty( ctx: JSContextRef, object: JSObjectRef, propertyName: JSStringRef, exception: *mut JSValueRef, ) -> JSValueRef; /// Sets a property on an object. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` whose property you want to set. /// * `propertyName`: A `JSString` containing the property's name. /// * `value`: A `JSValue` to use as the property's value. /// * `attributes`: A logically ORed set of `JSPropertyAttributes` to give to the property. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. pub fn JSObjectSetProperty( ctx: JSContextRef, object: JSObjectRef, propertyName: JSStringRef, value: JSValueRef, attributes: JSPropertyAttributes, exception: *mut JSValueRef, ); /// Deletes a property from an object. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` whose property you want to delete. /// * `propertyName`: A `JSString` containing the property's name. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns `true` if the delete operation succeeds, otherwise `false` /// (for example, if the property has the `kJSPropertyAttributeDontDelete` /// attribute set). pub fn JSObjectDeleteProperty( ctx: JSContextRef, object: JSObjectRef, propertyName: JSStringRef, exception: *mut JSValueRef, ) -> bool; /// Gets a property from an object by numeric index. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` whose property you want to get. /// * `propertyIndex`: An integer value that is the property's name. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns the property's value if object has the property, /// otherwise the undefined value. /// /// Calling `JSObjectGetPropertyAtIndex` is equivalent to calling /// `JSObjectGetProperty` with a string containing `propertyIndex`, /// but `JSObjectGetPropertyAtIndex` provides optimized access to /// numeric properties. pub fn JSObjectGetPropertyAtIndex( ctx: JSContextRef, object: JSObjectRef, propertyIndex: ::std::os::raw::c_uint, exception: *mut JSValueRef, ) -> JSValueRef; /// Sets a property on an object by numeric index. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` whose property you want to set. /// * `propertyIndex`: The property's name as a number. /// * `value`: A `JSValue` to use as the property's value. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Calling `JSObjectSetPropertyAtIndex` is equivalent to calling /// `JSObjectSetProperty` with a string containing `propertyIndex`, /// but `JSObjectSetPropertyAtIndex` provides optimized access to /// numeric properties. pub fn JSObjectSetPropertyAtIndex( ctx: JSContextRef, object: JSObjectRef, propertyIndex: ::std::os::raw::c_uint, value: JSValueRef, exception: *mut JSValueRef, ); /// Gets an object's private data. /// /// * `object`: A `JSObject` whose private data you want to get. /// /// Returns a `void*` that is the object's private data, if the /// object has private data, otherwise `NULL`. pub fn JSObjectGetPrivate(object: JSObjectRef) -> *mut ::std::os::raw::c_void; /// Sets a pointer to private data on an object. /// /// * `object`: The `JSObject` whose private data you want to set. /// * `data`: A `void*` to set as the object's private data. /// /// Returns `true` if object can store private data, otherwise `false`. /// /// The default object class does not allocate storage for private data. /// Only objects created with a non-`NULL` `JSClass` can store private data. pub fn JSObjectSetPrivate(object: JSObjectRef, data: *mut ::std::os::raw::c_void) -> bool; /// Tests whether an object can be called as a function. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` to test. /// /// Returns `true` if the object can be called as a function, otherwise `false`. pub fn JSObjectIsFunction(ctx: JSContextRef, object: JSObjectRef) -> bool; /// Calls an object as a function. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` to call as a function. /// * `thisObject`: The object to use as `this`, or `NULL` to use the global object as `this`. /// * `argumentCount`: An integer count of the number of arguments in `arguments`. /// * `arguments`: A `JSValue` array of arguments to pass to the function. /// Pass `NULL` if `argumentCount` is `0`. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns the `JSValue` that results from calling `object` as a function, /// or `NULL` if an exception is thrown or `object` is not a function. pub fn JSObjectCallAsFunction( ctx: JSContextRef, object: JSObjectRef, thisObject: JSObjectRef, argumentCount: usize, arguments: *const JSValueRef, exception: *mut JSValueRef, ) -> JSValueRef; /// Tests whether an object can be called as a constructor. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` to test. /// /// Returns `true` if the object can be called as a constructor, otherwise `false`. pub fn JSObjectIsConstructor(ctx: JSContextRef, object: JSObjectRef) -> bool; /// Calls an object as a constructor. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObject` to call as a constructor. /// * `argumentCount`: An integer count of the number of arguments in `arguments`. /// * `arguments`: A `JSValue` array of arguments to pass to the constructor. /// Pass `NULL` if `argumentCount` is `0`. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns the `JSObject` that results from calling `object` as a constructor, /// or `NULL` if an exception is thrown or `object` is not a constructor. pub fn JSObjectCallAsConstructor( ctx: JSContextRef, object: JSObjectRef, argumentCount: usize, arguments: *const JSValueRef, exception: *mut JSValueRef, ) -> JSObjectRef; /// Gets the names of an object's enumerable properties. /// /// * `ctx`: The execution context to use. /// * `object`: The object whose property names you want to get. /// /// Returns a `JSPropertyNameArray` containing the names of `object`'s /// enumerable properties. Ownership follows the Create Rule. pub fn JSObjectCopyPropertyNames( ctx: JSContextRef, object: JSObjectRef, ) -> JSPropertyNameArrayRef; /// Retains a JavaScript property name array. /// /// * `array`: The `JSPropertyNameArray` to retain. /// /// Returns a `JSPropertyNameArray` that is the same as array. pub fn JSPropertyNameArrayRetain(array: JSPropertyNameArrayRef) -> JSPropertyNameArrayRef; /// Releases a JavaScript property name array. /// /// * `array` The `JSPropertyNameArray` to release. pub fn JSPropertyNameArrayRelease(array: JSPropertyNameArrayRef); /// Gets a count of the number of items in a JavaScript property name array. /// /// * `array`: The array from which to retrieve the count. /// /// Return an integer count of the number of names in `array`. /// /// See also: /// /// * [`JSPropertyNameArrayGetNameAtIndex`] /// /// [`JSPropertyNameArrayGetNameAtIndex`]: fn.JSPropertyNameArrayGetNameAtIndex.html pub fn JSPropertyNameArrayGetCount(array: JSPropertyNameArrayRef) -> usize; /// Gets a property name at a given index in a JavaScript property name array. /// /// * `array`: The array from which to retrieve the property name. /// * `index`: The index of the property name to retrieve. /// /// Returns a `JSStringRef` containing the property name. /// /// See also: /// /// * [`JSPropertyNameArrayGetCount`] /// /// [`JSPropertyNameArrayGetCount`]: fn.JSPropertyNameArrayGetCount.html pub fn JSPropertyNameArrayGetNameAtIndex( array: JSPropertyNameArrayRef, index: usize, ) -> JSStringRef; /// Adds a property name to a JavaScript property name accumulator. /// /// * `accumulator`: The accumulator object to which to add the property name. /// * `propertyName`: The property name to add. pub fn JSPropertyNameAccumulatorAddName( accumulator: JSPropertyNameAccumulatorRef, propertyName: JSStringRef, ); /// Creates a JavaScript context group. /// /// `JSContextGroup` associates JavaScript contexts with one another. /// Contexts in the same group may share and exchange JavaScript /// objects. Sharing and/or exchanging JavaScript objects between /// contexts in different groups will produce undefined behavior. /// When objects from the same context group are used in multiple threads, /// explicit synchronization is required. /// /// Returns the created `JSContextGroup`. pub fn JSContextGroupCreate() -> JSContextGroupRef; /// Retains a JavaScript context group. /// /// * `group`: The `JSContextGroup` to retain. /// /// Returns a `JSContextGroup` that is the same as group. pub fn JSContextGroupRetain(group: JSContextGroupRef) -> JSContextGroupRef; /// Releases a JavaScript context group. /// /// * `group`: The `JSContextGroup` to release. pub fn JSContextGroupRelease(group: JSContextGroupRef); /// Creates a global JavaScript execution context. /// /// `JSGlobalContextCreate` allocates a global object and populates /// it with all the built-in JavaScript objects, such as `Object`, /// `Function`, `String`, and `Array`. /// /// In WebKit version 4.0 and later, the context is created in a /// unique context group. Therefore, scripts may execute in it /// concurrently with scripts executing in other contexts. However, /// you may not use values created in the context in other contexts. /// /// * `globalObjectClass`: The class to use when creating the global /// object. Pass `NULL` to use the default object class. /// /// Returns a `JSGlobalContext` with a global object of /// class `globalObjectClass`. pub fn JSGlobalContextCreate(globalObjectClass: JSClassRef) -> JSGlobalContextRef; /// Creates a global JavaScript execution context in the context /// group provided. /// /// `JSGlobalContextCreateInGroup` allocates a global object and /// populates it with all the built-in JavaScript objects, such as /// `Object`, `Function`, `String`, and `Array`. /// /// * `group`: The context group to use. The created global context /// retains the group. Pass `NULL` to create a unique group for /// the context. /// * `globalObjectClass`: The class to use when creating the global /// object. Pass NULL to use the default object class. /// /// Returns a `JSGlobalContext` with a global object of class /// `globalObjectClass` and a context group equal to `group`. pub fn JSGlobalContextCreateInGroup( group: JSContextGroupRef, globalObjectClass: JSClassRef, ) -> JSGlobalContextRef; /// Retains a global JavaScript execution context. /// /// * `ctx`: The `JSGlobalContext` to retain. /// /// Returns a `JSGlobalContext` that is the same as `ctx`. pub fn JSGlobalContextRetain(ctx: JSGlobalContextRef) -> JSGlobalContextRef; /// Releases a global JavaScript execution context. /// /// * `ctx` The `JSGlobalContext` to release. pub fn JSGlobalContextRelease(ctx: JSGlobalContextRef); /// Gets the global object of a JavaScript execution context. /// /// * `ctx` The `JSContext` whose global object you want to get. /// /// Returns `ctx`'s global object. pub fn JSContextGetGlobalObject(ctx: JSContextRef) -> JSObjectRef; /// Gets the context group to which a JavaScript execution context belongs. /// /// * `ctx`: The `JSContext` whose group you want to get. /// /// Returns `ctx`'s group. pub fn JSContextGetGroup(ctx: JSContextRef) -> JSContextGroupRef; /// Gets the global context of a JavaScript execution context. /// /// * `ctx`: The `JSContext` whose global context you want to get. /// /// Returns `ctx`'s global context. pub fn JSContextGetGlobalContext(ctx: JSContextRef) -> JSGlobalContextRef; /// Gets a copy of the name of a context. /// /// A `JSGlobalContext`'s name is exposed for remote debugging /// to make it easier to identify the context you would like to /// attach to. /// /// * `ctx`: The `JSGlobalContext` whose name you want to get. /// /// Returns the name for `ctx`. pub fn JSGlobalContextCopyName(ctx: JSGlobalContextRef) -> JSStringRef; /// Sets the remote debugging name for a context. /// /// * `ctx`: The `JSGlobalContext` that you want to name. /// * `name`: The remote debugging name to set on `ctx`. pub fn JSGlobalContextSetName(ctx: JSGlobalContextRef, name: JSStringRef); } /// A UTF-16 code unit. /// /// One, or a sequence of two, can encode any Unicode character. As /// with all scalar types, endianness depends on the underlying /// architecture. pub type JSChar = ::std::os::raw::c_ushort; extern "C" { /// Creates a JavaScript string from a buffer of Unicode characters. /// /// * `chars`: The buffer of Unicode characters to copy into the /// new `JSString`. /// * `numChars`: The number of characters to copy from the buffer /// pointed to by `chars`. /// /// Returns a `JSString` containing `chars`. Ownership follows the /// Create Rule. pub fn JSStringCreateWithCharacters(chars: *const JSChar, numChars: usize) -> JSStringRef; /// Creates a JavaScript string from a null-terminated UTF8 string. /// /// * `string`: The null-terminated UTF8 string to copy into the /// new `JSString`. /// /// Returns a `JSString` containing `string`. Ownership follows the /// Create Rule. pub fn JSStringCreateWithUTF8CString(string: *const ::std::os::raw::c_char) -> JSStringRef; /// Retains a JavaScript string. /// /// * `string`: The `JSString` to retain. /// /// Returns a `JSString` that is the same as `string`. pub fn JSStringRetain(string: JSStringRef) -> JSStringRef; /// Releases a JavaScript string. /// /// * `string`: The `JSString` to release. pub fn JSStringRelease(string: JSStringRef); /// Returns the number of Unicode characters in a JavaScript string. /// /// * `string`: The `JSString` whose length (in Unicode characters) /// you want to know. /// /// Returns the number of Unicode characters stored in `string`. pub fn JSStringGetLength(string: JSStringRef) -> usize; /// Returns a pointer to the Unicode character buffer that /// serves as the backing store for a JavaScript string. /// /// * `string`: The `JSString` whose backing store you want to access. /// /// Returns a pointer to the Unicode character buffer that serves /// as `string`'s backing store, which will be deallocated when /// `string` is deallocated. pub fn JSStringGetCharactersPtr(string: JSStringRef) -> *const JSChar; /// Returns the maximum number of bytes a JavaScript string will /// take up if converted into a null-terminated UTF8 string. /// /// * `string`: The `JSString` whose maximum converted size (in bytes) /// you want to know. /// /// Returns the maximum number of bytes that could be required to /// convert `string` into a null-terminated UTF8 string. The number /// of bytes that the conversion actually ends up requiring could /// be less than this, but never more. pub fn JSStringGetMaximumUTF8CStringSize(string: JSStringRef) -> usize; /// Converts a JavaScript string into a null-terminated UTF8 string, /// and copies the result into an external byte buffer. /// /// * `string`: The source `JSString`. /// * `buffer`: The destination byte buffer into which to copy a /// null-terminated UTF8 representation of `string`. On return, /// `buffer` contains a UTF8 string representation of `string`. If /// `bufferSize` is too small, `buffer` will contain only /// partial results. If `buffer` is not at least `bufferSize` /// bytes in size, behavior is undefined. /// * `bufferSize`: The size of the external buffer in bytes. /// /// Returns the number of bytes written into buffer (including the null-terminator byte). pub fn JSStringGetUTF8CString( string: JSStringRef, buffer: *mut ::std::os::raw::c_char, bufferSize: usize, ) -> usize; /// Tests whether two JavaScript strings match. /// /// * `a`: The first `JSString` to test. /// * `b`: The second `JSString` to test. /// /// Returns `true` if the two strings match, otherwise `false`. pub fn JSStringIsEqual(a: JSStringRef, b: JSStringRef) -> bool; /// Tests whether a JavaScript string matches a null-terminated /// UTF8 string. /// /// * `a`: The `JSString` to test. /// * `b`: The null-terminated UTF8 string to test. /// /// Returns `true` if the two strings match, otherwise `false`. pub fn JSStringIsEqualToUTF8CString(a: JSStringRef, b: *const ::std::os::raw::c_char) -> bool; /// Creates a JavaScript Typed Array object with the given number of elements. /// /// * `ctx`: The execution context to use. /// * `arrayType`: A value identifying the type of array to /// create. If `arrayType` is `JSTypedArrayType::None` or /// `JSTypedArrayType::ArrayBuffer` then `NULL` will be returned. /// * `length`: The number of elements to be in the new Typed Array. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObjectRef` that is a Typed Array with all elements set to /// zero or `NULL` if there was an error. pub fn JSObjectMakeTypedArray( ctx: JSContextRef, arrayType: JSTypedArrayType, length: usize, exception: *mut JSValueRef, ) -> JSObjectRef; /// Creates a JavaScript Typed Array object from an existing pointer. /// /// * `ctx`: The execution context to use. /// * `arrayType`: A value identifying the type of array to /// create. If `arrayType` is `JSTypedArrayType::None` or /// `JSTypedArrayType::ArrayBuffer` then `NULL` will be returned. /// * `bytes`: A pointer to the byte buffer to be used as the backing store /// of the Typed Array object. /// * `byteLength`: The number of bytes pointed to by the parameter bytes. /// * `bytesDeallocator`: The allocator to use to deallocate the external /// buffer when the JSTypedArrayData object is deallocated. /// * `deallocatorContext A pointer to pass back to the deallocator. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObjectRef` Typed Array whose backing store is the same as /// the one pointed to by `bytes` or `NULL` if there was an error. /// /// If an exception is thrown during this function the `bytesDeallocator` /// will always be called. pub fn JSObjectMakeTypedArrayWithBytesNoCopy( ctx: JSContextRef, arrayType: JSTypedArrayType, bytes: *mut ::std::os::raw::c_void, byteLength: usize, bytesDeallocator: JSTypedArrayBytesDeallocator, deallocatorContext: *mut ::std::os::raw::c_void, exception: *mut JSValueRef, ) -> JSObjectRef; /// Creates a JavaScript Typed Array object from an existing /// JavaScript Array Buffer object. /// /// * `ctx`: The execution context to use. /// * `arrayType`: A value identifying the type of array to /// create. If `arrayType` is `JSTypedArrayType::None` or /// `JSTypedArrayType::ArrayBuffer` then `NULL` will be returned. /// * `buffer`: An Array Buffer object that should be used as the /// backing store for the created JavaScript Typed Array object. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObjectRef` that is a Typed Array or `NULL` if there /// was an error. The backing store of the Typed Array will be `buffer`. pub fn JSObjectMakeTypedArrayWithArrayBuffer( ctx: JSContextRef, arrayType: JSTypedArrayType, buffer: JSObjectRef, exception: *mut JSValueRef, ) -> JSObjectRef; /// Creates a JavaScript Typed Array object from an existing /// JavaScript Array Buffer object with the given offset and /// length. /// /// * `ctx`: The execution context to use. /// * `arrayType`: A value identifying the type of array to /// create. If `arrayType` is `JSTypedArrayType::None` or /// `JSTypedArrayType::ArrayBuffer` then `NULL` will be returned. /// * `buffer`: An Array Buffer object that should be used as the /// backing store for the created JavaScript Typed Array object. /// * `byteOffset`: The byte offset for the created Typed Array. /// `byteOffset` should aligned with the element size of `arrayType`. /// * `length`: The number of elements to include in the Typed Array. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObjectRef` that is a Typed Array or `NULL` if there /// was an error. The backing store of the Typed Array will be `buffer`. pub fn JSObjectMakeTypedArrayWithArrayBufferAndOffset( ctx: JSContextRef, arrayType: JSTypedArrayType, buffer: JSObjectRef, byteOffset: usize, length: usize, exception: *mut JSValueRef, ) -> JSObjectRef; /// Returns a temporary pointer to the backing store of a /// JavaScript Typed Array object. /// /// * `ctx`: The execution context to use. /// * `object`: The Typed Array object whose backing store pointer /// to return. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a pointer to the raw data buffer that serves as `object`'s /// backing store or `NULL` if object is not a Typed Array object. /// /// The pointer returned by this function is temporary and is not /// guaranteed to remain valid across JavaScriptCore API calls. pub fn JSObjectGetTypedArrayBytesPtr( ctx: JSContextRef, object: JSObjectRef, exception: *mut JSValueRef, ) -> *mut ::std::os::raw::c_void; /// Returns the length of a JavaScript Typed Array object. /// /// * `ctx`: The execution context to use. /// * `object`: The Typed Array object whose length to return. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns the length of the Typed Array object or `0` if the object /// is not a Typed Array object. pub fn JSObjectGetTypedArrayLength( ctx: JSContextRef, object: JSObjectRef, exception: *mut JSValueRef, ) -> usize; /// Returns the byte length of a JavaScript Typed Array object. /// /// * `ctx`: The execution context to use. /// * `object`: The Typed Array object whose byte length to return. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns the byte length of the Typed Array object or `0` if the /// object is not a Typed Array object. pub fn JSObjectGetTypedArrayByteLength( ctx: JSContextRef, object: JSObjectRef, exception: *mut JSValueRef, ) -> usize; /// Returns the byte offset of a JavaScript Typed Array object. /// /// * `ctx`: The execution context to use. /// * `object`: The Typed Array object whose byte offset to return. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns the byte offset of the Typed Array object or `0` if the /// object is not a Typed Array object. pub fn JSObjectGetTypedArrayByteOffset( ctx: JSContextRef, object: JSObjectRef, exception: *mut JSValueRef, ) -> usize; /// Returns the JavaScript Array Buffer object that is used as the /// backing of a JavaScript Typed Array object. /// /// * `ctx`: The execution context to use. /// * `object`: The `JSObjectRef` whose Typed Array type data pointer /// to obtain. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObjectRef` with a `JSTypedArrayType` of /// `JSTypedArrayType::ArrayBuffer` or `NULL` if object is not /// a Typed Array. pub fn JSObjectGetTypedArrayBuffer( ctx: JSContextRef, object: JSObjectRef, exception: *mut JSValueRef, ) -> JSObjectRef; /// Creates a JavaScript Array Buffer object from an existing pointer. /// /// * `ctx`: The execution context to use. /// * `bytes`: A pointer to the byte buffer to be used as the backing /// store of the Typed Array object. /// * `byteLength`: The number of bytes pointed to by the parameter `bytes`. /// * `bytesDeallocator`: The allocator to use to deallocate the /// external buffer when the Typed Array data object is deallocated. /// * `deallocatorContext`: A pointer to pass back to the deallocator. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a `JSObjectRef` Array Buffer whose backing store is /// the same as the one pointed to by `bytes` or `NULL` if there /// was an error. /// /// If an exception is thrown during this function the `bytesDeallocator` /// will always be called. pub fn JSObjectMakeArrayBufferWithBytesNoCopy( ctx: JSContextRef, bytes: *mut ::std::os::raw::c_void, byteLength: usize, bytesDeallocator: JSTypedArrayBytesDeallocator, deallocatorContext: *mut ::std::os::raw::c_void, exception: *mut JSValueRef, ) -> JSObjectRef; /// Returns a pointer to the data buffer that serves as the backing /// store for a JavaScript Typed Array object. /// /// * `ctx`: The execution context to use. /// * `object`: The Array Buffer object whose internal backing /// store pointer to return. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns a pointer to the raw data buffer that serves as /// `object`'s backing store or `NULL` if `object` is not an /// Array Buffer object. /// /// The pointer returned by this function is temporary and is not /// guaranteed to remain valid across JavaScriptCore API calls. pub fn JSObjectGetArrayBufferBytesPtr( ctx: JSContextRef, object: JSObjectRef, exception: *mut JSValueRef, ) -> *mut ::std::os::raw::c_void; /// Returns the number of bytes in a JavaScript data object. /// /// * `ctx`: The execution context to use. /// * `object`: The JS Arary Buffer object whose length in bytes to return. /// * `exception`: A pointer to a `JSValueRef` in which to store /// an exception, if any. Pass `NULL` if you do not care to /// store an exception. /// /// Returns the number of bytes stored in the data `object`. pub fn JSObjectGetArrayBufferByteLength( ctx: JSContextRef, object: JSObjectRef, exception: *mut JSValueRef, ) -> usize; }