mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-22 10:01:50 +00:00
Compare commits
555 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bab3a57975 | ||
|
|
181019c0c3 | ||
|
|
c37e2b4851 | ||
|
|
2dee22f5c7 | ||
|
|
5e3b91b052 | ||
|
|
e7221f4211 | ||
|
|
b30b63fc63 | ||
|
|
60b1202a72 | ||
|
|
0a2fcaaf5e | ||
|
|
09f0a10bba | ||
|
|
7e2b3292fd | ||
|
|
8fd141b29c | ||
|
|
c80623fc00 | ||
|
|
92ee65bc0c | ||
|
|
07cdae7850 | ||
|
|
ef525f337f | ||
|
|
29fdbc741f | ||
|
|
ebe3761308 | ||
|
|
c423a4bfa0 | ||
|
|
4b40f92aba | ||
|
|
779f6bedf5 | ||
|
|
d581b27af6 | ||
|
|
3b43994a7d | ||
|
|
299a7ff451 | ||
|
|
36f5fb5836 | ||
|
|
d6aae0777f | ||
|
|
590345cc62 | ||
|
|
c02c6595be | ||
|
|
166fa7c66b | ||
|
|
3cf7d60b43 | ||
|
|
2bbd27caac | ||
|
|
78e5e333b9 | ||
|
|
22bedcec9e | ||
|
|
aa727d22a1 | ||
|
|
121d2fefca | ||
|
|
2e9a6393b9 | ||
|
|
685a71c3d1 | ||
|
|
78576a5af9 | ||
|
|
c8588c323c | ||
|
|
2cc649c97e | ||
|
|
98f54274d1 | ||
|
|
0a79d6c1f7 | ||
|
|
634fe864d7 | ||
|
|
475149426f | ||
|
|
7683468efb | ||
|
|
48eb4b6af9 | ||
|
|
e9833cd791 | ||
|
|
769e86e32a | ||
|
|
ad3844437e | ||
|
|
633fe63795 | ||
|
|
e52f0ce0cf | ||
|
|
2624608567 | ||
|
|
0ac274d1fc | ||
|
|
ab7a13e089 | ||
|
|
f25f05faca | ||
|
|
a7f9695bf3 | ||
|
|
50215a5ce8 | ||
|
|
13e3a62312 | ||
|
|
2156cfa5b8 | ||
|
|
b4f2b24e4a | ||
|
|
97e8115ab1 | ||
|
|
989e6922b6 | ||
|
|
6ebbd22c06 | ||
|
|
069fba1151 | ||
|
|
9819a8de49 | ||
|
|
f41ec3426b | ||
|
|
1b36b95006 | ||
|
|
c69b8ada67 | ||
|
|
f6e0b04be4 | ||
|
|
4d4cded5be | ||
|
|
5c16ae5d84 | ||
|
|
12a37ed4d1 | ||
|
|
fb8b241655 | ||
|
|
339a5d1838 | ||
|
|
bb00312798 | ||
|
|
c9f13d0730 | ||
|
|
e35a8cb14d | ||
|
|
af4c67a706 | ||
|
|
c90e358e2f | ||
|
|
17bdb07cc6 | ||
|
|
eeea83ef3e | ||
|
|
d50bb8897a | ||
|
|
a3abf7e40a | ||
|
|
32281e3d22 | ||
|
|
ea826db76a | ||
|
|
7bd328b5df | ||
|
|
20c7641b16 | ||
|
|
e44005a1d2 | ||
|
|
a130b108a5 | ||
|
|
fb2ad1eb04 | ||
|
|
32e9a72156 | ||
|
|
2a3447dc1c | ||
|
|
3b242a2e6e | ||
|
|
95036c339e | ||
|
|
50f1d7a2f1 | ||
|
|
3f07b5696c | ||
|
|
a138441b98 | ||
|
|
a474595528 | ||
|
|
75394413ac | ||
|
|
1ab58f5470 | ||
|
|
a622791f6e | ||
|
|
142cf01ad4 | ||
|
|
c231374c38 | ||
|
|
ec0d3f1c61 | ||
|
|
982f15c83d | ||
|
|
23b88e0d3d | ||
|
|
94abd9142c | ||
|
|
bf4d55e27a | ||
|
|
f5ae276846 | ||
|
|
ef4b1ef414 | ||
|
|
5537c312dc | ||
|
|
b66f1f6678 | ||
|
|
d49aece60c | ||
|
|
be331e04c3 | ||
|
|
c7a1b4154b | ||
|
|
e74404b9a2 | ||
|
|
8aae441360 | ||
|
|
c54390bf2e | ||
|
|
c599abdc60 | ||
|
|
8f24498310 | ||
|
|
7bb1e520a5 | ||
|
|
82924e7db5 | ||
|
|
f541c5c63f | ||
|
|
2f42f070f3 | ||
|
|
5c64d63fd1 | ||
|
|
2b7a5657ef | ||
|
|
345a295cba | ||
|
|
ce0d795280 | ||
|
|
4e589b1a52 | ||
|
|
15d86aeeb9 | ||
|
|
71706514f4 | ||
|
|
ee64383623 | ||
|
|
e6417b8ed8 | ||
|
|
7667784d79 | ||
|
|
b1dd07f05c | ||
|
|
2325f6fc64 | ||
|
|
1175bb303b | ||
|
|
d06a31a1a2 | ||
|
|
369278e640 | ||
|
|
7dd0c1821e | ||
|
|
33d32009da | ||
|
|
c3841a7176 | ||
|
|
0a2eec0e85 | ||
|
|
75cdb470ba | ||
|
|
45313ea2ce | ||
|
|
66e105e9f8 | ||
|
|
4a4f8a6d7e | ||
|
|
ef5ef0b9b4 | ||
|
|
18d3f010a0 | ||
|
|
297162133e | ||
|
|
ba05eaec99 | ||
|
|
5bbfa73dcd | ||
|
|
5240b9cbec | ||
|
|
72172f6c47 | ||
|
|
d017677d54 | ||
|
|
98de57bc8a | ||
|
|
fdac7ae1c3 | ||
|
|
dccf2f9256 | ||
|
|
83c9e9a50a | ||
|
|
0c41944316 | ||
|
|
3844dced3f | ||
|
|
0249b5efb5 | ||
|
|
1c3248ce35 | ||
|
|
ef617652dc | ||
|
|
bb3c62e2cc | ||
|
|
acd242f7df | ||
|
|
5618ae6f7b | ||
|
|
dc7640a152 | ||
|
|
5e5eb5d631 | ||
|
|
fa3432f1d6 | ||
|
|
9d634be004 | ||
|
|
cb01142c4c | ||
|
|
f9ca29d5cb | ||
|
|
c3c3bca85e | ||
|
|
600fa1a906 | ||
|
|
b9041e60b7 | ||
|
|
70e0721082 | ||
|
|
36e4562e68 | ||
|
|
77a3b8554f | ||
|
|
77741e8d13 | ||
|
|
4f0a1cff00 | ||
|
|
9e414f3933 | ||
|
|
641e3813c4 | ||
|
|
8b39a2c3ff | ||
|
|
8e5636c198 | ||
|
|
5b74588aa1 | ||
|
|
141797871f | ||
|
|
90d8da7fe8 | ||
|
|
d7c2db8f3f | ||
|
|
84a305785a | ||
|
|
293729c869 | ||
|
|
40e54ebead | ||
|
|
8d140c3c0f | ||
|
|
7135cbaefe | ||
|
|
34c2f0a20e | ||
|
|
5711241b99 | ||
|
|
96beab3416 | ||
|
|
06e356f15a | ||
|
|
6175024ffc | ||
|
|
3c1ddaaa50 | ||
|
|
52bbc7a9bc | ||
|
|
fc47134b6e | ||
|
|
2482f40fe2 | ||
|
|
25a5bf17c3 | ||
|
|
6cfdea8169 | ||
|
|
1577634b8f |
||
|
|
7993469edf | ||
|
|
d8e2610f90 | ||
|
|
39b990ed7a | ||
|
|
c3fadf767b | ||
|
|
fff09af8c3 | ||
|
|
4a372c5b01 | ||
|
|
26a2d9d39c | ||
|
|
98c145bdff | ||
|
|
954b5bc77f | ||
|
|
b2ba17408c | ||
|
|
b50bda684b | ||
|
|
1e11e1d668 | ||
|
|
a11e806c20 | ||
|
|
152bd60e3a | ||
|
|
108b0a2d87 | ||
|
|
e8b7538e24 | ||
|
|
c31d8d6fdb | ||
|
|
c543b17857 | ||
|
|
b1e87e6801 | ||
|
|
989e924b49 | ||
|
|
a526fc2ad8 | ||
|
|
39be7b7d97 | ||
|
|
e5fe9d44c6 | ||
|
|
a058a43145 | ||
|
|
3d230333be | ||
|
|
7454b14725 | ||
|
|
54b0cf8f65 | ||
|
|
c2083928a7 | ||
|
|
f00b8128a9 | ||
|
|
db0badf787 | ||
|
|
05553d2264 | ||
|
|
2e33b02111 | ||
|
|
5de198e3a7 | ||
|
|
50299f0b15 | ||
|
|
6242f0977e | ||
|
|
6d0874b866 | ||
|
|
ae94df12b7 | ||
|
|
383f275ad9 | ||
|
|
8d890f97ec | ||
|
|
953fb9163d | ||
|
|
47d09c2a5f | ||
|
|
4be0de65b9 | ||
|
|
e640af3007 | ||
|
|
0f55e4461a | ||
|
|
b2ecf54887 | ||
|
|
a264ee2026 | ||
|
|
7b71600aa7 | ||
|
|
edbdfc7888 | ||
|
|
0daf586b6e | ||
|
|
f15ce4357a | ||
|
|
4da625eeee | ||
|
|
eb69692309 | ||
|
|
1d1abe1e69 | ||
|
|
5632e3f811 | ||
|
|
6cae4dc1e2 | ||
|
|
8582684c0b | ||
|
|
e488659903 | ||
|
|
dfeec6e03b | ||
|
|
f2b6d3d5e0 | ||
|
|
2405fac873 | ||
|
|
bf59245ee0 | ||
|
|
49984a0247 | ||
|
|
9528f75cba | ||
|
|
5c53d26131 | ||
|
|
6ecf44ae02 | ||
|
|
84f5d459cf | ||
|
|
3274c456bd | ||
|
|
6d2208a3e6 | ||
|
|
9b2f4723e8 | ||
|
|
048b6e1d17 | ||
|
|
cebb533875 | ||
|
|
8b2b02439f | ||
|
|
dc5ae66e0e | ||
|
|
d9792ddaf1 | ||
|
|
2bcc19e587 | ||
|
|
901d29e3bb | ||
|
|
7a47be7877 | ||
|
|
4c7cd64424 | ||
|
|
157a309f97 | ||
|
|
2986b98885 | ||
|
|
d92a795390 | ||
|
|
67198fc8b0 | ||
|
|
87a09becd9 | ||
|
|
2c80cd43f1 | ||
|
|
8ae1f976d9 | ||
|
|
6a00b188d8 | ||
|
|
422dd0bc61 | ||
|
|
dfed47ebb9 | ||
|
|
39d284b2b2 | ||
|
|
8984acc04f | ||
|
|
04f9d99f13 | ||
|
|
53058a0d45 | ||
|
|
a9a2335ef5 | ||
|
|
64db935469 | ||
|
|
595a85757e | ||
|
|
a4021a97f4 | ||
|
|
9f59be13c2 | ||
|
|
4c6220f22c | ||
|
|
21f6cd3f73 | ||
|
|
18a470f3f8 | ||
|
|
8ea4218205 | ||
|
|
72fc9d0680 | ||
|
|
fd133c5868 | ||
|
|
ef7441c412 | ||
|
|
302a6ecd44 | ||
|
|
f1a7274e95 | ||
|
|
f3b070f91d | ||
|
|
9ae947d83b | ||
|
|
5611aca4e1 | ||
|
|
895052f59e | ||
|
|
932d82cbf9 | ||
|
|
81e5797483 | ||
|
|
595971175c | ||
|
|
ccf80322c8 | ||
|
|
72205bb381 | ||
|
|
795aa354f1 | ||
|
|
b1a3ccc12e | ||
|
|
0e5925f7b0 | ||
|
|
62e6e01ed1 | ||
|
|
80141b3e71 | ||
|
|
268306b456 | ||
|
|
58c0a0bb0a | ||
|
|
50d31696d9 | ||
|
|
be859fdcee | ||
|
|
edb0346d4e | ||
|
|
9f985fb1dc | ||
|
|
2a00a728ca | ||
|
|
2c0c041c9a | ||
|
|
e575d34387 | ||
|
|
e4c132d591 | ||
|
|
aa14a49a70 | ||
|
|
c2ef5b9e12 | ||
|
|
adcd8025b7 | ||
|
|
ebe450e623 | ||
|
|
560cd36c21 | ||
|
|
7b95d4e9b8 | ||
|
|
3aff294c29 | ||
|
|
4a952115d0 | ||
|
|
ecf2a586b7 | ||
|
|
782269345c | ||
|
|
2b84e6b800 | ||
|
|
e89d796bb1 | ||
|
|
4ebb3a229d | ||
|
|
b51cb6ff2e | ||
|
|
5a7f8d6114 | ||
|
|
13990e9538 | ||
|
|
e78a2432cd | ||
|
|
5f9aefa716 | ||
|
|
a57df7576b | ||
|
|
19498b41b4 | ||
|
|
5b935ec247 | ||
|
|
5cdf638814 | ||
|
|
58536d0ea0 | ||
|
|
e4287d5f6b | ||
|
|
fdec6267da | ||
|
|
037a748d22 | ||
|
|
a02c48d286 | ||
|
|
204295833b | ||
|
|
c7623e41ce | ||
|
|
5c22c9f32d | ||
|
|
6d2dd5ecec | ||
|
|
d70a651c56 | ||
|
|
9df6de10a2 | ||
|
|
92602e2ca2 | ||
|
|
081e241c2f | ||
|
|
ff7b02722d | ||
|
|
98a7eaf95d | ||
|
|
2f3ba80a08 | ||
|
|
cf0ef1247b | ||
|
|
f388c52797 | ||
|
|
cd4b7ddbea | ||
|
|
7365c2ae4b | ||
|
|
32f1ebbd26 | ||
|
|
91eef62f47 | ||
|
|
1e1599aa09 | ||
|
|
0434ba9237 | ||
|
|
0eac4dcff9 | ||
|
|
55d3c17718 | ||
|
|
6a0087c6cb | ||
|
|
e801bb623f | ||
|
|
5fcdf4e101 | ||
|
|
7589396230 | ||
|
|
d398f1ece3 | ||
|
|
cadbad68b9 | ||
|
|
2ec730bed4 | ||
|
|
23ef57997a | ||
|
|
fff4e2fdd4 | ||
|
|
3045a8ef7e | ||
|
|
dd479c42bb | ||
|
|
0f6ea4612a | ||
|
|
96d165ff5a | ||
|
|
adf735966f | ||
|
|
023bb16baa | ||
|
|
902d76f0dd | ||
|
|
246ecf6456 | ||
|
|
b7a70c5c33 | ||
|
|
9b1076d5c6 | ||
|
|
21903f956e | ||
|
|
7762be63d1 | ||
|
|
6374a4857d | ||
|
|
a66b725ce4 | ||
|
|
eda2f8d4fa | ||
|
|
7fc59b7171 | ||
|
|
f07651568b | ||
|
|
19f32213ee | ||
|
|
0fbacc3b2e | ||
|
|
b95ae71b67 | ||
|
|
6c0926c4c0 | ||
|
|
bddd8a8fe2 | ||
|
|
b3deb87407 | ||
|
|
9c09d721af | ||
|
|
9876b4c852 | ||
|
|
4c2efa224e | ||
|
|
3d4d9a9f2b | ||
|
|
8ac5782dec | ||
|
|
72cb18b19b | ||
|
|
4b8024efb7 | ||
|
|
01bfe58f7f | ||
|
|
e2423b2428 | ||
|
|
d59154a794 | ||
|
|
18ec8bc1fc | ||
|
|
d9bfe96623 | ||
|
|
23d21fd7ec | ||
|
|
277738e347 | ||
|
|
db24c809c8 | ||
|
|
3024cb7065 | ||
|
|
1053742b3d | ||
|
|
000a19868f | ||
|
|
f646e364a7 | ||
|
|
1050ee4f5b | ||
|
|
25fe6b8d5a | ||
|
|
5d5e89f6d8 | ||
|
|
91c83757e5 | ||
|
|
b692b277d0 | ||
|
|
23d203b7b2 | ||
|
|
47cc02e8d8 | ||
|
|
696cff8d27 | ||
|
|
f5a08722e9 | ||
|
|
52e3239f63 | ||
|
|
57c23d62f0 | ||
|
|
77f0c49ad5 | ||
|
|
a34205a555 | ||
|
|
af5ac14862 | ||
|
|
f039511557 | ||
|
|
2c36e6eb67 | ||
|
|
08eb095b3c | ||
|
|
5ec3d007fa | ||
|
|
fdda755329 | ||
|
|
29ea705677 | ||
|
|
05d1dadbe4 | ||
|
|
fa209656d5 | ||
|
|
28451a704f | ||
|
|
5a5238049c | ||
|
|
99f7a16312 | ||
|
|
33037e20d8 | ||
|
|
5f918f17e6 | ||
|
|
46cd288264 | ||
|
|
870bc3991a | ||
|
|
232a555df2 | ||
|
|
2bde2b91e3 | ||
|
|
babcedce95 | ||
|
|
01c132434c | ||
|
|
23cbadecad | ||
|
|
5ee4a5bd4e | ||
|
|
bccdc4225e | ||
|
|
86525d1000 | ||
|
|
5275ce42e3 | ||
|
|
023b7ea014 | ||
|
|
65558531f8 | ||
|
|
6218b1bafc | ||
|
|
c4ab1cf57d | ||
|
|
55a36a294a | ||
|
|
c884c0605b | ||
|
|
2b6e3fcc7d | ||
|
|
9a5c1b57a9 | ||
|
|
bd95de3c46 | ||
|
|
ded2d1145e | ||
|
|
70a5bf444a | ||
|
|
f09fe2a4c0 | ||
|
|
3aac2156a9 | ||
|
|
47b9fb1074 | ||
|
|
364b5f4717 | ||
|
|
1749160613 | ||
|
|
9dc7a55cbe | ||
|
|
ac75d5c715 | ||
|
|
ca43b39174 | ||
|
|
86f230325f | ||
|
|
1982e20d42 | ||
|
|
96762b2187 | ||
|
|
9e87e85dc7 | ||
|
|
a4afdefbf2 | ||
|
|
5170135d7b | ||
|
|
1b9be45708 | ||
|
|
b0543cfe9c | ||
|
|
c12763a4df | ||
|
|
282cd3f359 | ||
|
|
698b932878 | ||
|
|
3026aab3ca | ||
|
|
a3fa9d7ef0 | ||
|
|
dcbcd7dac5 | ||
|
|
9bc09564f4 | ||
|
|
4121b297fc | ||
|
|
b50e5fcf8c | ||
|
|
93d4648908 | ||
|
|
59a626b871 | ||
|
|
5d59757208 | ||
|
|
b117b8b205 | ||
|
|
8aa918e372 | ||
|
|
799bc4fcc9 | ||
|
|
184295ccb6 | ||
|
|
41206722f0 | ||
|
|
f04616e4a5 | ||
|
|
2c070415ba | ||
|
|
5bc5fc7876 | ||
|
|
1a5b10b821 | ||
|
|
11d9427bb8 | ||
|
|
e9cec1d0b4 | ||
|
|
fcc35d22bf | ||
|
|
195039d901 | ||
|
|
48150217a8 | ||
|
|
4f8582ec25 | ||
|
|
4581040747 | ||
|
|
e706ea6e4a | ||
|
|
4053e103a5 | ||
|
|
2ecb52c9cd | ||
|
|
d7cf6a58ce | ||
|
|
5c797fa5ac | ||
|
|
2bd31a2136 | ||
|
|
5b91e4bb2d | ||
|
|
bd4b29364b | ||
|
|
f33168c6f6 | ||
|
|
49fd86eae8 | ||
|
|
28f1f0fb0b | ||
|
|
f77f28fa84 | ||
|
|
97e698db34 | ||
|
|
7f7d8c336d | ||
|
|
cdb47df97f | ||
|
|
98133d2206 | ||
|
|
463d73023a | ||
|
|
f41a422302 | ||
|
|
7697c00fef | ||
|
|
27f44f396d | ||
|
|
ae1ba12763 | ||
|
|
f79cdc8f0c | ||
|
|
e7ab0df730 | ||
|
|
730853fecb | ||
|
|
ccb11a6ce1 | ||
|
|
f6cdc00259 | ||
|
|
2141345fc0 |
496 changed files with 226580 additions and 41234 deletions
52
.github/workflows/analysis-actions.yml
vendored
52
.github/workflows/analysis-actions.yml
vendored
|
|
@ -4,24 +4,23 @@ on:
|
|||
schedule:
|
||||
# trigger on every monday, wednesday and friday
|
||||
- cron: '30 22 * * 1,3,5'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
coverity-scan:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
submodules: recursive
|
||||
- name: Build ICU(64)
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build
|
||||
- name: Patch WABT
|
||||
working-directory: ./third_party/wasm/wabt
|
||||
run: |
|
||||
cp ../../../tools/test/wasm-js/wabt_patch .
|
||||
patch -p0 < wabt_patch
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu64-build/
|
||||
cd $GITHUB_WORKSPACE/icu64-build/icu4c/source
|
||||
LDFLAGS="-Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib/" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu64/"
|
||||
make -j8
|
||||
make install
|
||||
- name: Download Coverity Tool
|
||||
env:
|
||||
TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
|
||||
|
|
@ -31,10 +30,10 @@ jobs:
|
|||
tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64
|
||||
- name: Build
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_CODE_CACHE=ON -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_CODE_CACHE=ON -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
export PATH=$GITHUB_WORKSPACE/cov-analysis-linux64/bin:$PATH
|
||||
cmake -H. -Bout/coverity_scan $BUILD_OPTIONS
|
||||
LDFLAGS="-L$GITHUB_WORKSPACE/icu64/lib/ -Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib/" PKG_CONFIG_PATH="$GITHUB_WORKSPACE/icu64/lib/pkgconfig/" cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/coverity_scan $BUILD_OPTIONS
|
||||
cov-build --dir cov-int ninja -Cout/coverity_scan
|
||||
- name: Submit
|
||||
env:
|
||||
|
|
@ -46,28 +45,26 @@ jobs:
|
|||
--form token=$TOKEN \
|
||||
--form email=$NOTI_MAIL \
|
||||
--form file=@escargot.tgz \
|
||||
--form version="4.0.0" \
|
||||
--form version="4.3.0" \
|
||||
--form description="escargot coverity scan" \
|
||||
https://scan.coverity.com/builds?project=Samsung%2Fescargot
|
||||
|
||||
coverage-scan:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
# ubuntu version fixed
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: [self-hosted, linux, x64, test]
|
||||
timeout-minutes: 600
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y pypy ninja-build libicu-dev gcovr
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_COVERAGE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_COVERAGE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
cmake -H. -Bout/coverage $BUILD_OPTIONS
|
||||
ninja -Cout/coverage
|
||||
LDFLAGS=" -L/usr/icu78-64/lib/ -Wl,-rpath=/usr/icu78-64/lib/" PKG_CONFIG_PATH="/usr/icu78-64/lib/pkgconfig/" cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/coverage64 -DESCARGOT_ARCH=x64 $BUILD_OPTIONS
|
||||
ninja -Cout/coverage64
|
||||
LDFLAGS=" -L/usr/icu78-32/lib/ -Wl,-rpath=/usr/icu78-32/lib/" PKG_CONFIG_PATH="/usr/icu78-32/lib/pkgconfig/" cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/coverage32 -DESCARGOT_ARCH=x86 $BUILD_OPTIONS
|
||||
ninja -Cout/coverage32
|
||||
- name: Run test262 and collect coverage data
|
||||
# test262 is unstable in actions env, but coverage data will be accumulated
|
||||
continue-on-error: true
|
||||
|
|
@ -76,12 +73,13 @@ jobs:
|
|||
sudo locale-gen en_US.UTF-8
|
||||
export LANG=en_US.UTF-8
|
||||
locale
|
||||
tools/run-tests.py --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/coverage/escargot" new-es test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-64/lib/ GC_FREE_SPACE_DIVISOR=1 tools/run-tests.py --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/coverage64/escargot" new-es regression-tests test262 octane chakracore sunspider-js modifiedVendorTest jsc-stress v8 spidermonkey intl jetstream-only-cdjs
|
||||
LD_LIBRARY_PATH=/usr/icu78-32/lib/ GC_FREE_SPACE_DIVISOR=1 tools/run-tests.py --arch=x86 --engine="$GITHUB_WORKSPACE/out/coverage32/escargot" new-es regression-tests test262 octane chakracore sunspider-js modifiedVendorTest jsc-stress v8 spidermonkey intl jetstream-only-cdjs
|
||||
- name: Generate coverage report
|
||||
run: |
|
||||
gcovr --gcov-ignore-parse-errors --exclude-unreachable-branches --exclude-throw-branches --exclude third_party --exclude src/api -r . --xml coverage.xml
|
||||
gcovr --gcov-ignore-parse-errors --exclude-unreachable-branches --exclude-throw-branches --exclude '.*third_party/' --exclude '.*shell/' --exclude '.*api/' -r . --xml coverage.xml
|
||||
- name: Upload coverage reports to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
fail_ci_if_error: true
|
||||
|
|
|
|||
97
.github/workflows/android-release.yml
vendored
Normal file
97
.github/workflows/android-release.yml
vendored
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
name: Android-Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
jobs:
|
||||
build-android-on-ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4.1.0
|
||||
with:
|
||||
distribution: "zulu"
|
||||
java-version: 17
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
- name: Build with Gradle
|
||||
working-directory: ./build/android
|
||||
run: |
|
||||
./gradlew bundleHostJar
|
||||
./gradlew javadocJar
|
||||
./gradlew sourcesJar
|
||||
./gradlew :escargot:testDebugUnitTest
|
||||
mv ./escargot/build/libs/escargot.jar ./escargot/build/libs/escargot-ubuntu.jar
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-ubuntu
|
||||
path: |
|
||||
./build/android/escargot/build/**/escargot-*.aar
|
||||
./build/android/escargot/build/**/escargot-*.jar
|
||||
!./build/android/escargot/build/**/escargot-*Shell.aar
|
||||
if-no-files-found: error
|
||||
|
||||
build-android-on-macos:
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
brew update
|
||||
brew install ninja icu4c
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4.1.0
|
||||
with:
|
||||
distribution: "zulu"
|
||||
java-version: 17
|
||||
- name: Setup Gradle
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
- name: Build with Gradle
|
||||
working-directory: ./build/android
|
||||
run: |
|
||||
./gradlew bundleHostJar
|
||||
./gradlew :escargot:testDebugUnitTest
|
||||
mv ./escargot/build/libs/escargot.jar ./escargot/build/libs/escargot-mac.jar
|
||||
- name: Upload build artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-mac
|
||||
path: |
|
||||
./build/android/escargot/build/libs/escargot-mac.jar
|
||||
if-no-files-found: error
|
||||
|
||||
merge-update-release:
|
||||
needs: [build-android-on-ubuntu, build-android-on-macos]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: build-artifact-*
|
||||
merge-multiple: true
|
||||
- name: Set release date
|
||||
run: |
|
||||
echo "RELEASE_DATE=$(date --rfc-3339=date)" >> $GITHUB_ENV
|
||||
- name: Merge build artifacts
|
||||
working-directory: ./artifacts
|
||||
run: |
|
||||
ls -R ./
|
||||
echo ${RELEASE_DATE}
|
||||
find . -type f -name "escargot-*.aar" -exec mv {} . \;
|
||||
find . -type f -name "escargot-*.jar" -exec mv {} . \;
|
||||
ls -R ./
|
||||
find ./ -type f -name "escargot-*.aar" -o -name "escargot-*.jar" | zip Android-Release-${{ env.RELEASE_DATE }}.zip -@
|
||||
- name: Upload to release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
artifacts/Android-Release-${{ env.RELEASE_DATE }}.zip
|
||||
110
.github/workflows/code-review.yml
vendored
Normal file
110
.github/workflows/code-review.yml
vendored
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
name: Review Bot (PR)
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened, synchronize, reopened]
|
||||
branches: [ "master" ]
|
||||
|
||||
concurrency:
|
||||
group: review-${{ github.event.pull_request.number }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
|
||||
jobs:
|
||||
review:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: [self-hosted, escargot-review]
|
||||
|
||||
steps:
|
||||
- name: Compute diff range (incremental on synchronize)
|
||||
id: shas
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const action = context.payload.action;
|
||||
const pr = context.payload.pull_request.number;
|
||||
const baseSha = context.payload.pull_request.base.sha;
|
||||
const headSha = context.payload.pull_request.head.sha;
|
||||
|
||||
let base = baseSha;
|
||||
let skip = false;
|
||||
if (action === 'synchronize') {
|
||||
const before = context.payload.before;
|
||||
if (before) {
|
||||
base = before;
|
||||
} else {
|
||||
skip = true;
|
||||
}
|
||||
}
|
||||
|
||||
core.setOutput('base', base);
|
||||
core.setOutput('head', headSha);
|
||||
core.setOutput('pr', pr);
|
||||
core.setOutput('skip', String(skip));
|
||||
- name: Skip review (no before on synchronize)
|
||||
if: ${{ steps.shas.outputs.skip == 'true' }}
|
||||
run: |
|
||||
echo "[Review Bot] Skipping review: 'before' SHA missing on synchronize event."
|
||||
- name: Call review server
|
||||
id: call
|
||||
if: ${{ steps.shas.outputs.skip != 'true' }}
|
||||
env:
|
||||
REVIEW_SERVER: ${{ secrets.REVIEW_SERVER }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
REVIEW_SERVER="${REVIEW_SERVER}"
|
||||
BASE_SHA="${{ steps.shas.outputs.base }}"
|
||||
HEAD_SHA="${{ steps.shas.outputs.head }}"
|
||||
PR_NUMBER="${{ steps.shas.outputs.pr }}"
|
||||
|
||||
curl -sS --fail-with-body --show-error \
|
||||
--connect-timeout 10 --max-time 7200 \
|
||||
-X POST "${REVIEW_SERVER}/review" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"base_sha\":\"${BASE_SHA}\",\"head_sha\":\"${HEAD_SHA}\",\"pull_request_number\":${PR_NUMBER}}" \
|
||||
-o review.json
|
||||
|
||||
echo "==== review.json ===="
|
||||
cat review.json
|
||||
|
||||
- name: Post review comments
|
||||
if: ${{ steps.shas.outputs.skip != 'true' }}
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const fs = require('fs');
|
||||
const pr = context.payload.pull_request.number;
|
||||
let raw;
|
||||
try {
|
||||
raw = fs.readFileSync('review.json', 'utf8');
|
||||
} catch (e) {
|
||||
core.warning(`review.json not found: ${e}`);
|
||||
return;
|
||||
}
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(raw);
|
||||
} catch (e) {
|
||||
core.warning(`Failed to parse review.json as JSON: ${e}`);
|
||||
return;
|
||||
}
|
||||
const comments = Array.isArray(data.comments) ? data.comments : [];
|
||||
|
||||
for (const c of comments) {
|
||||
await github.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/comments', {
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: pr,
|
||||
body: c.body,
|
||||
commit_id: c.commit_id,
|
||||
path: c.path,
|
||||
line: c.line,
|
||||
side: c.side,
|
||||
headers: { 'accept': 'application/vnd.github+json' }
|
||||
});
|
||||
|
||||
await new Promise(r => setTimeout(r, 200));
|
||||
}
|
||||
577
.github/workflows/es-actions.yml
vendored
577
.github/workflows/es-actions.yml
vendored
|
|
@ -5,121 +5,126 @@ on:
|
|||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
RUNNER: tools/run-tests.py
|
||||
|
||||
jobs:
|
||||
check-tidy:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo add-apt-repository "deb http://mirrors.kernel.org/ubuntu/ focal main universe"
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
|
||||
sudo add-apt-repository "deb [trusted=yes] http://apt.llvm.org/noble/ llvm-toolchain-noble-20 main"
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y clang-format-6.0
|
||||
sudo apt-get install -y clang-format-20
|
||||
- name: Test
|
||||
run: tools/check_tidy.py
|
||||
|
||||
build-on-macos:
|
||||
runs-on: macos-12
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
submodules: recursive
|
||||
- name: Install Packages
|
||||
run: |
|
||||
brew update
|
||||
brew install cmake ninja pkg-config icu4c
|
||||
brew install ninja icu4c
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig"
|
||||
cmake -H. -Bout/mac/x64 $BUILD_OPTIONS
|
||||
ninja -Cout/mac/x64
|
||||
./tools/run-tests.py --engine="./out/mac/x64/escargot" new-es
|
||||
# check cpu
|
||||
sysctl -a | grep machdep.cpu
|
||||
# add icu path to pkg_config_path
|
||||
export PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig"
|
||||
echo $PKG_CONFIG_PATH
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.10 -H. -Bout/debug/ -DESCARGOT_MODE=debug $BUILD_OPTIONS
|
||||
ninja -Cout/debug/
|
||||
$RUNNER --engine="./out/debug/escargot" new-es
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.10 -H. -Bout/release/ -DESCARGOT_MODE=release $BUILD_OPTIONS
|
||||
ninja -Cout/release/
|
||||
cp test/octane/*.js .
|
||||
./out/release/escargot run.js
|
||||
|
||||
build-on-macos-arm64:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install Packages
|
||||
run: |
|
||||
brew update
|
||||
brew install ninja icu4c
|
||||
- name: Build arm64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
# check cpu
|
||||
sysctl -a | grep machdep.cpu
|
||||
# add icu path to pkg_config_path
|
||||
export PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig"
|
||||
echo $PKG_CONFIG_PATH
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.10 -H. -Bout/debug/ -DESCARGOT_MODE=debug $BUILD_OPTIONS
|
||||
ninja -Cout/debug/
|
||||
$RUNNER --engine="./out/debug/escargot" new-es
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.10 -H. -Bout/release/ -DESCARGOT_MODE=release $BUILD_OPTIONS
|
||||
ninja -Cout/release/
|
||||
cp test/octane/*.js .
|
||||
./out/release/escargot run.js
|
||||
|
||||
build-test-on-android:
|
||||
runs-on: macos-12
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [x86, x86_64]
|
||||
api: [28]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
- name: Enable KVM
|
||||
run: |
|
||||
brew update
|
||||
brew install cmake pkg-config
|
||||
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger --name-match=kvm
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v4.1.0
|
||||
with:
|
||||
distribution: "zulu"
|
||||
java-version: 17
|
||||
- name: Gradle cache
|
||||
uses: gradle/gradle-build-action@v2
|
||||
- name: AVD cache
|
||||
uses: actions/cache@v3
|
||||
id: avd-cache
|
||||
with:
|
||||
path: |
|
||||
~/.android/avd/*
|
||||
~/.android/adb*
|
||||
key: avd-${{ matrix.api }}-${{ matrix.arch }}
|
||||
- name: Create AVD and generate snapshot for caching
|
||||
if: steps.avd-cache.outputs.cache-hit != 'true'
|
||||
uses: gradle/actions/setup-gradle@v3
|
||||
- name: Create AVD and run tests
|
||||
uses: reactivecircus/android-emulator-runner@v2
|
||||
with:
|
||||
api-level: ${{ matrix.api }}
|
||||
arch: ${{ matrix.arch }}
|
||||
force-avd-creation: false
|
||||
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
|
||||
disable-animations: false
|
||||
script: echo "Generated AVD snapshot for caching."
|
||||
- name: Run tests
|
||||
uses: reactivecircus/android-emulator-runner@v2
|
||||
with:
|
||||
api-level: ${{ matrix.api }}
|
||||
arch: ${{ matrix.arch }}
|
||||
force-avd-creation: false
|
||||
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
|
||||
emulator-options: -no-window -gpu swiftshader_indirect -camera-back none -no-snapshot-save -gpu swiftshader_indirect -noaudio -no-boot-anim
|
||||
disable-animations: true
|
||||
script: cd build/android/;./gradlew connectedDebugAndroidTest
|
||||
script: cd build/android/;./gradlew connectedDebugAndroidTest -DESCARGOT_BUILD_TLS_ACCESS_BY_PTHREAD_KEY=ON
|
||||
|
||||
build-by-clang:
|
||||
runs-on: ubuntu-latest
|
||||
build-test-tizen:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
submodules: recursive
|
||||
- name: prepare deb sources for GBS
|
||||
run: echo "deb [trusted=yes] http://download.tizen.org/tools/latest-release/Ubuntu_24.04/ /" | sudo tee /etc/apt/sources.list.d/tizen.list
|
||||
- name: install GBS
|
||||
run: sudo apt-get update && sudo apt-get install -y gbs
|
||||
- name: build
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib libicu-dev
|
||||
- name: Patch WABT
|
||||
working-directory: ./third_party/wasm/wabt
|
||||
run: |
|
||||
cp ../../../tools/test/wasm-js/wabt_patch .
|
||||
patch -p0 < wabt_patch
|
||||
- name: Build x86
|
||||
env:
|
||||
BUILD_OPTIONS: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
CC=clang CXX=clang++ cmake -H. -Bout/clang/x86 $BUILD_OPTIONS
|
||||
ninja -Cout/clang/x86
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
CC=clang CXX=clang++ cmake -H. -Bout/clang/x64 $BUILD_OPTIONS
|
||||
ninja -Cout/clang/x64
|
||||
./tools/run-tests.py --engine="./out/clang/x64/escargot" new-es
|
||||
gbs -c .github/workflows/gbs.conf build -A armv7l -P profile.tizen --incremental --define "enable_shell 1"
|
||||
|
||||
test-on-windows-clang-cl:
|
||||
runs-on: windows-2022
|
||||
|
|
@ -127,39 +132,61 @@ jobs:
|
|||
matrix:
|
||||
# clang-cl with cannot generate c++ exception code well
|
||||
# if clang-cl bug fixed, we can add x64
|
||||
# clang version and STL version are sometimes not matched in github actions,
|
||||
# so I add -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH
|
||||
arch: [
|
||||
{cpu: "x86", flag: "-m32"}
|
||||
# , {cpu: "x64", flag: ""}
|
||||
{cpu: "x86", flag: "-m32 -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH"}
|
||||
#, {cpu: "x64", flag: "-D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH"}
|
||||
]
|
||||
steps:
|
||||
- name: Set git cllf config
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
git config --global core.eol lf
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- uses: szenius/set-timezone@v1.2
|
||||
- uses: szenius/set-timezone@v2.0
|
||||
with:
|
||||
timezoneWindows: "Pacific Standard Time"
|
||||
- uses: lukka/get-cmake@latest
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v1.11
|
||||
with:
|
||||
sdk-version: 20348
|
||||
- uses: actions/setup-python@v4
|
||||
cmakeVersion: "~3.25.0"
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
|
||||
with:
|
||||
sdk-version: 26100
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Install msvc redist package
|
||||
- name: Download and Install Visual C++ Redistributable
|
||||
shell: powershell
|
||||
run: |
|
||||
(new-object System.Net.WebClient).DownloadFile('https://github.com/abbodi1406/vcredist/releases/download/v0.73.0/VisualCppRedist_AIO_x86_x64.exe','VisualCppRedist_AIO_x86_x64.exe')
|
||||
.\VisualCppRedist_AIO_x86_x64.exe /y
|
||||
- uses: ilammy/msvc-dev-cmd@v1.12.1
|
||||
$vcRedistUrl64 = "https://aka.ms/vs/17/release/vc_redist.x64.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath64 = "$env:TEMP\vc_redist.x64.exe"
|
||||
$vcRedistUrl32 = "https://aka.ms/vs/17/release/vc_redist.x86.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath32 = "$env:TEMP\vc_redist.x86.exe"
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl64"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl64 -OutFile $vcRedistPath64
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl32"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl32 -OutFile $vcRedistPath32
|
||||
|
||||
Write-Host "Installing Visual C++ Redistributable silently"
|
||||
Start-Process -FilePath $vcRedistPath64 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Start-Process -FilePath $vcRedistPath32 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Write-Host "Visual C++ Redistributable installation complete."
|
||||
- uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
with:
|
||||
arch: ${{ matrix.arch.cpu }}
|
||||
sdk: "10.0.20348.0"
|
||||
sdk: "10.0.26100.0"
|
||||
- uses: egor-tensin/setup-clang@v1
|
||||
with:
|
||||
version: 19.1.7
|
||||
platform: ${{ matrix.arch.cpu }}
|
||||
- name: Build ${{ matrix.arch.cpu }} Release
|
||||
run: |
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch.cpu }} -Bout/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=NO -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -G Ninja -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_BUILD_TYPE=release -DCMAKE_C_FLAGS="${{ matrix.arch.flag }}" -DCMAKE_CXX_FLAGS="${{ matrix.arch.flag }}"
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch.cpu }} -Bout/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -G Ninja -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_BUILD_TYPE=release -DCMAKE_C_FLAGS="${{ matrix.arch.flag }}" -DCMAKE_CXX_FLAGS="${{ matrix.arch.flag }}"
|
||||
CMake --build out/ --config Release
|
||||
- name: Run octane
|
||||
run: |
|
||||
|
|
@ -169,9 +196,9 @@ jobs:
|
|||
# clang-cl with cannot generate c++ exception code well. if clang-cl bug fixed, we can enable test262
|
||||
# - name: Run test262
|
||||
# run: |
|
||||
# set GC_FREE_SPACE_DIVISOR=1
|
||||
# pip install chardet
|
||||
# python tools\run-tests.py --engine=%cd%\out\escargot.exe test262 --extra-arg="--skip Temporal --skip intl402 --skip Atomics"
|
||||
# set GC_FREE_SPACE_DIVISOR=1
|
||||
# pip install chardet
|
||||
# python tools\run-tests.py --engine=%cd%\out\escargot.exe test262 --test262-extra-arg="--skip Temporal --skip intl402 --skip Atomics"
|
||||
# shell: cmd
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
|
|
@ -187,30 +214,46 @@ jobs:
|
|||
run: |
|
||||
git config --global core.autocrlf input
|
||||
git config --global core.eol lf
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- uses: szenius/set-timezone@v1.2
|
||||
submodules: recursive
|
||||
- uses: szenius/set-timezone@v2.0
|
||||
with:
|
||||
timezoneWindows: "Pacific Standard Time"
|
||||
- uses: lukka/get-cmake@latest
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v1.11
|
||||
with:
|
||||
sdk-version: 20348
|
||||
- uses: actions/setup-python@v4
|
||||
cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
|
||||
with:
|
||||
sdk-version: 26100
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Install msvc redist package
|
||||
- name: Download and Install Visual C++ Redistributable
|
||||
shell: powershell
|
||||
run: |
|
||||
(new-object System.Net.WebClient).DownloadFile('https://github.com/abbodi1406/vcredist/releases/download/v0.73.0/VisualCppRedist_AIO_x86_x64.exe','VisualCppRedist_AIO_x86_x64.exe')
|
||||
.\VisualCppRedist_AIO_x86_x64.exe /y
|
||||
- uses: ilammy/msvc-dev-cmd@v1.12.1
|
||||
$vcRedistUrl64 = "https://aka.ms/vs/17/release/vc_redist.x64.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath64 = "$env:TEMP\vc_redist.x64.exe"
|
||||
$vcRedistUrl32 = "https://aka.ms/vs/17/release/vc_redist.x86.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath32 = "$env:TEMP\vc_redist.x86.exe"
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl64"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl64 -OutFile $vcRedistPath64
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl32"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl32 -OutFile $vcRedistPath32
|
||||
|
||||
Write-Host "Installing Visual C++ Redistributable silently"
|
||||
Start-Process -FilePath $vcRedistPath64 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Start-Process -FilePath $vcRedistPath32 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Write-Host "Visual C++ Redistributable installation complete."
|
||||
- uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
with:
|
||||
arch: ${{ matrix.arch }}
|
||||
sdk: "10.0.20348.0"
|
||||
sdk: "10.0.26100.0"
|
||||
- name: Build ${{ matrix.arch }} Release
|
||||
run: |
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch }} -DESCARGOT_ARCH=${{ matrix.arch }} -Bout/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=release
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch }} -DESCARGOT_ARCH=${{ matrix.arch }} -Bout/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_WASM=ON -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=release
|
||||
CMake --build out/ --config Release
|
||||
# windows internal ICU doesn't support Temporal and intl402 well
|
||||
# github action windows runner only have 2 CPUs. that's why I disable Atomics(timeout occured with some tests)
|
||||
|
|
@ -218,7 +261,7 @@ jobs:
|
|||
run: |
|
||||
set GC_FREE_SPACE_DIVISOR=1
|
||||
pip install chardet
|
||||
python tools\run-tests.py --engine=%cd%\out\escargot.exe test262 --extra-arg="--skip Temporal --skip intl402 --skip Atomics"
|
||||
python tools\run-tests.py --engine=%cd%\out\escargot.exe test262 --test262-extra-arg="--skip Temporal --skip intl402 --skip Atomics --skip sm"
|
||||
shell: cmd
|
||||
- name: Run octane
|
||||
run: |
|
||||
|
|
@ -236,30 +279,32 @@ jobs:
|
|||
run: |
|
||||
git config --global core.autocrlf input
|
||||
git config --global core.eol lf
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- uses: lukka/get-cmake@latest
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v1.11
|
||||
with:
|
||||
sdk-version: 20348
|
||||
- uses: ilammy/msvc-dev-cmd@v1.12.1
|
||||
cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
|
||||
with:
|
||||
sdk-version: 26100
|
||||
- uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
with:
|
||||
arch: x64
|
||||
sdk: "10.0.20348.0"
|
||||
sdk: "10.0.26100.0"
|
||||
uwp: true
|
||||
- name: Build x64 UWP Release
|
||||
run: |
|
||||
CMake -G "Visual Studio 17 2022" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=x64 -Bout/win64_release_uwp/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_TEST=ON
|
||||
cmake --build out\win64_release_uwp --config Release
|
||||
CMake -G "Visual Studio 17 2022" -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=x64 -Bout/win64_release_uwp/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON
|
||||
CMake --build out\win64_release_uwp --config Release
|
||||
shell: cmd
|
||||
- uses: ilammy/msvc-dev-cmd@v1.12.1
|
||||
- uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
with:
|
||||
arch: x86
|
||||
sdk: "10.0.20348.0"
|
||||
sdk: "10.0.26100.0"
|
||||
- name: Build x86 DLL Release
|
||||
run: |
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=x86 -Bout/win32_release_shared/ -DESCARGOT_OUTPUT=shared_lib -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=release
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=x86 -Bout/win32_release_shared/ -DESCARGOT_OUTPUT=shared_lib -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=release
|
||||
CMake --build out/win32_release_shared --config Release
|
||||
shell: cmd
|
||||
- if: ${{ failure() }}
|
||||
|
|
@ -267,112 +312,254 @@ jobs:
|
|||
timeout-minutes: 15
|
||||
|
||||
build-test-on-x86-release:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
tc: ['octane', 'v8 chakracore spidermonkey', 'jetstream-only-simple-parallel-1', 'jetstream-only-simple-parallel-2 jsc-stress', 'jetstream-only-simple-parallel-3 jetstream-only-cdjs']
|
||||
tc: ['new-es octane', 'v8 chakracore spidermonkey', 'jetstream-only-simple-parallel-1', 'jetstream-only-simple-parallel-2 jsc-stress', 'jetstream-only-simple-parallel-3 jetstream-only-cdjs']
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib python2
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
|
||||
- name: Install ICU
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib make g++ pkg-config automake libtool git build-essential checkinstall libncurses-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
|
||||
- name: Build python2
|
||||
run: |
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_70.1-2ubuntu1_i386.deb
|
||||
dpkg -X libicu-dev_70.1-2ubuntu1_i386.deb $GITHUB_WORKSPACE/icu32
|
||||
mkdir $GITHUB_WORKSPACE/python2-build/
|
||||
cd $GITHUB_WORKSPACE/python2-build/
|
||||
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
|
||||
tar xzf Python-2.7.18.tgz
|
||||
cd Python-2.7.18
|
||||
./configure --prefix=/usr/local/python2.7
|
||||
make -j8
|
||||
sudo make install
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/local/python2.7/bin/python2.7 1
|
||||
- name: Build ICU
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu-build/
|
||||
cd $GITHUB_WORKSPACE/icu-build/icu4c/source
|
||||
LDFLAGS="-m32 -Wl,-rpath=$GITHUB_WORKSPACE/icu32/lib/" CFLAGS="-m32" CXXFLAGS="-m32" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu32/"
|
||||
make -j8
|
||||
make install
|
||||
ls $GITHUB_WORKSPACE/icu32/lib/
|
||||
- name: Build x86
|
||||
env:
|
||||
BUILD_OPTIONS: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_THREADING=ON -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/release/x86 $BUILD_OPTIONS
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/lib/ -Wl,-rpath=$GITHUB_WORKSPACE/icu32/lib/"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu32/lib/pkgconfig
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/release/x86 $BUILD_OPTIONS
|
||||
ninja -Cout/release/x86
|
||||
- name: Run release-x86 test
|
||||
env:
|
||||
GC_FREE_SPACE_DIVISOR: 1
|
||||
run: $RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/release/x86/escargot" ${{ matrix.tc }}
|
||||
run: LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu32/lib $RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/release/x86/escargot" ${{ matrix.tc }}
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 15
|
||||
|
||||
build-test-on-x64-release:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
tc: ['new-es octane v8', 'chakracore spidermonkey']
|
||||
tc: ['octane v8 web-tooling-benchmark', 'chakracore spidermonkey new-es']
|
||||
build_opt: ['', '-DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON', '-DESCARGOT_SMALL_CONFIG=ON -DESCARGOT_USE_CUSTOM_LOGGING=ON']
|
||||
exclude:
|
||||
# exclude octane, v8 due to low performance incurred by SMALL_CONFIG
|
||||
- tc: 'new-es octane v8'
|
||||
# exclude octane, v8, web-tooling-benchmark due to low performance incurred by SMALL_CONFIG
|
||||
- tc: 'octane v8 web-tooling-benchmark'
|
||||
build_opt: '-DESCARGOT_SMALL_CONFIG=ON -DESCARGOT_USE_CUSTOM_LOGGING=ON'
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build libicu-dev python2
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
|
||||
sudo apt-get install -y ninja-build g++ pkg-config automake libtool git build-essential checkinstall libncurses-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
|
||||
- name: Build ICU(64)
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu64-build/
|
||||
cd $GITHUB_WORKSPACE/icu64-build/icu4c/source
|
||||
LDFLAGS="-Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib/" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu64/"
|
||||
make -j8
|
||||
make install
|
||||
- name: Build python2
|
||||
run: |
|
||||
mkdir $GITHUB_WORKSPACE/python2-build/
|
||||
cd $GITHUB_WORKSPACE/python2-build/
|
||||
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
|
||||
tar xzf Python-2.7.18.tgz
|
||||
cd Python-2.7.18
|
||||
./configure --prefix=/usr/local/python2.7
|
||||
make -j8
|
||||
sudo make install
|
||||
sudo update-alternatives --install /usr/bin/python python /usr/local/python2.7/bin/python2.7 1
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
cmake -H. -Bout/release/x64 $BUILD_OPTIONS ${{ matrix.build_opt }}
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu64/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu64/lib -Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu64/lib/pkgconfig
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/release/x64 $BUILD_OPTIONS ${{ matrix.build_opt }}
|
||||
ninja -Cout/release/x64
|
||||
- name: Run release-x64 test
|
||||
env:
|
||||
GC_FREE_SPACE_DIVISOR: 1
|
||||
run: |
|
||||
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu64/lib
|
||||
# set locale
|
||||
sudo locale-gen en_US.UTF-8
|
||||
export LANG=en_US.UTF-8
|
||||
locale
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/release/x64/escargot" ${{ matrix.tc }}
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 15
|
||||
|
||||
build-test-on-x86-x64-debug:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib
|
||||
- name: Install ICU
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib make g++ pkg-config automake libtool git build-essential checkinstall libncurses-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
|
||||
- name: Build ICU(32)
|
||||
run: |
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_70.1-2ubuntu1_i386.deb
|
||||
dpkg -X libicu-dev_70.1-2ubuntu1_i386.deb $GITHUB_WORKSPACE/icu32
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_70.1-2ubuntu1_amd64.deb
|
||||
dpkg -X libicu-dev_70.1-2ubuntu1_amd64.deb $GITHUB_WORKSPACE/icu64
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu32-build/
|
||||
cd $GITHUB_WORKSPACE/icu32-build/icu4c/source
|
||||
LDFLAGS="-m32 -Wl,-rpath=$GITHUB_WORKSPACE/icu32/lib/" CFLAGS="-m32" CXXFLAGS="-m32" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu32/"
|
||||
make -j8
|
||||
make install
|
||||
- name: Build ICU(64)
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu64-build/
|
||||
cd $GITHUB_WORKSPACE/icu64-build/icu4c/source
|
||||
LDFLAGS="-Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib/" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu64/"
|
||||
make -j8
|
||||
make install
|
||||
- name: Build x86/x64
|
||||
env:
|
||||
BUILD_OPTIONS_X86: -DESCARGOT_MODE=debug -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS_X64: -DESCARGOT_MODE=debug -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS_X86: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS_X64: -DESCARGOT_MODE=debug -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/debug/x86 $BUILD_OPTIONS_X86
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu64/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/debug/x64 $BUILD_OPTIONS_X64
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/debug/x86 $BUILD_OPTIONS_X86
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/debug/x64 $BUILD_OPTIONS_X64
|
||||
ninja -Cout/debug/x86
|
||||
ninja -Cout/debug/x64
|
||||
- name: Run debug-mode test
|
||||
run: |
|
||||
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu32/lib
|
||||
$RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/debug/x86/escargot" modifiedVendorTest regression-tests new-es intl sunspider-js
|
||||
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu64/lib
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/debug/x64/escargot" modifiedVendorTest regression-tests new-es intl sunspider-js
|
||||
|
||||
build-test-on-self-hosted-linux:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: [self-hosted, linux, x64, test]
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Build
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
LDFLAGS=" -L/usr/icu78-32/lib/ -Wl,-rpath=/usr/icu78-32/lib/" PKG_CONFIG_PATH="/usr/icu78-32/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=debug -DESCARGOT_TCO_DEBUG=ON $BUILD_OPTIONS
|
||||
LDFLAGS=" -L/usr/icu78-32/lib/ -Wl,-rpath=/usr/icu78-32/lib/" PKG_CONFIG_PATH="/usr/icu78-32/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux_release -DESCARGOT_ARCH=x86 $BUILD_OPTIONS
|
||||
LDFLAGS=" -L/usr/icu78-32/lib/ -Wl,-rpath=/usr/icu78-32/lib/" PKG_CONFIG_PATH="/usr/icu78-32/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux_release_clang -DESCARGOT_ARCH=x86 $BUILD_OPTIONS
|
||||
gcc -shared -m32 -fPIC -o backtrace-hooking-32.so tools/test/test262/backtrace-hooking.c
|
||||
LDFLAGS=" -L/usr/icu78-64/lib/ -Wl,-rpath=/usr/icu78-64/lib/" PKG_CONFIG_PATH="/usr/icu78-64/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux64 -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=debug -DESCARGOT_TCO_DEBUG=ON $BUILD_OPTIONS
|
||||
LDFLAGS=" -L/usr/icu78-64/lib/ -Wl,-rpath=/usr/icu78-64/lib/" PKG_CONFIG_PATH="/usr/icu78-64/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux64_release -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release $BUILD_OPTIONS
|
||||
LDFLAGS=" -L/usr/icu78-64/lib/ -Wl,-rpath=/usr/icu78-64/lib/" PKG_CONFIG_PATH="/usr/icu78-64/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bbuild/out_linux64_release_clang -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release $BUILD_OPTIONS
|
||||
cmake --build build/out_linux/
|
||||
cmake --build build/out_linux64/
|
||||
cmake --build build/out_linux_release/
|
||||
cmake --build build/out_linux_release_clang/
|
||||
cmake --build build/out_linux64_release/
|
||||
cmake --build build/out_linux64_release_clang/
|
||||
- name: Test
|
||||
run: |
|
||||
LD_LIBRARY_PATH=/usr/icu78-32/lib/ GC_FREE_SPACE_DIVISOR=1 $RUNNER --arch=x86 --engine="${{ github.workspace }}/build/out_linux_release/escargot" test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-32/lib/ GC_FREE_SPACE_DIVISOR=1 $RUNNER --arch=x86 --engine="${{ github.workspace }}/build/out_linux_release_clang/escargot" test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-32/lib/ GC_FREE_SPACE_DIVISOR=1 ESCARGOT_LD_PRELOAD=${{ github.workspace }}/backtrace-hooking-32.so $RUNNER --arch=x86 --engine="${{ github.workspace }}/build/out_linux/escargot" test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-64/lib/ GC_FREE_SPACE_DIVISOR=1 $RUNNER --arch=x86_64 --engine="${{ github.workspace }}/build/out_linux64_release/escargot" test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-64/lib/ GC_FREE_SPACE_DIVISOR=1 $RUNNER --arch=x86_64 --engine="${{ github.workspace }}/build/out_linux64_release_clang/escargot" test262
|
||||
LD_LIBRARY_PATH=/usr/icu78-64/lib/ python tools/kangax/run-kangax.py --engine="${{ github.workspace }}/build/out_linux64/escargot"
|
||||
|
||||
build-test-on-self-hosted-arm-linux:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: [self-hosted, linux, arm, test]
|
||||
strategy:
|
||||
matrix:
|
||||
compiler: [ {cxx: g++, cc: gcc}, {cxx: clang++, cc: clang} ]
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Build
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bout -DCMAKE_C_COMPILER=${{ matrix.compiler.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }} -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=arm32 -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=OFF -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=${{ matrix.compiler.tls }} -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
cmake --build ./out/
|
||||
- name: Test
|
||||
run: |
|
||||
GC_FREE_SPACE_DIVISOR=1 $RUNNER --engine="${{ github.workspace }}/out/escargot" --test262-extra-arg="--skip intl402 --skip sm --skip Temporal" new-es v8 spidermonkey chakracore test262
|
||||
|
||||
build-test-on-self-hosted-arm64-linux:
|
||||
if: github.repository == 'Samsung/escargot'
|
||||
runs-on: [self-hosted, linux, arm64, test]
|
||||
strategy:
|
||||
matrix:
|
||||
compiler: [ {cxx: g++-11, cc: gcc-11}, {cxx: clang++, cc: clang} ]
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Build
|
||||
run: |
|
||||
LDFLAGS=" -L/usr/icu78-64/lib/ -Wl,-rpath=/usr/icu78-64/lib/" PKG_CONFIG_PATH="/usr/icu78-64/lib/pkgconfig/" cmake -DCMAKE_C_COMPILER=${{ matrix.compiler.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }} -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H./ -Bout -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
cmake --build ./out/
|
||||
- name: Test
|
||||
run: |
|
||||
export LD_LIBRARY_PATH=/usr/icu78-64/lib/
|
||||
GC_FREE_SPACE_DIVISOR=1 $RUNNER --engine="${{ github.workspace }}/out/escargot" --test262-extra-arg="--skip intl402 --skip sm" test262 chakracore spidermonkey v8 new-es
|
||||
|
||||
build-test-on-riscv64-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Build in riscv64 container
|
||||
uses: uraimo/run-on-arch-action@v3
|
||||
with:
|
||||
arch: riscv64
|
||||
distro: ubuntu22.04
|
||||
|
||||
# Install deps into the container. With the token, the container will be cached
|
||||
# The image is cached publically like a package
|
||||
githubToken: ${{ github.token }}
|
||||
|
||||
install: |
|
||||
apt-get update
|
||||
apt-get install -y cmake build-essential ninja-build pkg-config python3 git libicu-dev
|
||||
run: |
|
||||
cmake -H. -Bout/riscv64 -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
ninja -Cout/riscv64
|
||||
python3 ./tools/run-tests.py --engine="./out/riscv64/escargot" new-es intl sunspider-js
|
||||
|
||||
build-test-debugger:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
|
|
@ -381,9 +568,9 @@ jobs:
|
|||
sudo apt-get install -y ninja-build
|
||||
- name: Build
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_DEBUGGER=1 -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_DEBUGGER=1 -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
cmake -H. -Bout/debugger $BUILD_OPTIONS
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/debugger $BUILD_OPTIONS
|
||||
ninja -Cout/debugger
|
||||
- name: Debugger Test
|
||||
run: |
|
||||
|
|
@ -393,7 +580,7 @@ jobs:
|
|||
build-test-api:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
|
|
@ -402,12 +589,12 @@ jobs:
|
|||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib
|
||||
- name: Build x86/x64
|
||||
env:
|
||||
BUILD_OPTIONS_X86: -DCMAKE_SYSTEM_PROCSEEOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=ON -DESCARGOT_DEBUGGER=1 -DESCARGOT_OUTPUT=cctest -GNinja
|
||||
BUILD_OPTIONS_X64: -DESCARGOT_MODE=debug -DESCARGOT_THREADING=1 -DESCARGOT_DEBUGGER=1 -DESCARGOT_OUTPUT=cctest -GNinja
|
||||
BUILD_OPTIONS_X86: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=ON -DESCARGOT_DEBUGGER=1 -DESCARGOT_USE_EXTENDED_API=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=cctest -GNinja
|
||||
BUILD_OPTIONS_X64: -DESCARGOT_MODE=debug -DESCARGOT_THREADING=1 -DESCARGOT_DEBUGGER=1 -DESCARGOT_USE_EXTENDED_API=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=cctest -GNinja
|
||||
run: |
|
||||
cmake -H. -Bout/cctest/x86 $BUILD_OPTIONS_X86
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/cctest/x86 $BUILD_OPTIONS_X86
|
||||
ninja -Cout/cctest/x86
|
||||
cmake -H. -Bout/cctest/x64 $BUILD_OPTIONS_X64
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/cctest/x64 $BUILD_OPTIONS_X64
|
||||
ninja -Cout/cctest/x64
|
||||
- name: Run Test
|
||||
run: |
|
||||
|
|
@ -417,37 +604,34 @@ jobs:
|
|||
build-test-codecache:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
# for i386 ICU
|
||||
sudo dpkg --add-architecture i386
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib
|
||||
- name: Install ICU
|
||||
run: |
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_70.1-2ubuntu1_i386.deb
|
||||
dpkg -X libicu-dev_70.1-2ubuntu1_i386.deb $GITHUB_WORKSPACE/icu32
|
||||
wget http://mirrors.kernel.org/ubuntu/pool/main/i/icu/libicu-dev_70.1-2ubuntu1_amd64.deb
|
||||
dpkg -X libicu-dev_70.1-2ubuntu1_amd64.deb $GITHUB_WORKSPACE/icu64
|
||||
sudo apt-get install -y libicu-dev:i386 # install i386 ICU
|
||||
- name: Build x86
|
||||
env:
|
||||
BUILD_OPTIONS: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_CODE_CACHE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_CODE_CACHE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu32/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu32/usr/lib/i386-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/codecache/x86 $BUILD_OPTIONS
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/codecache/x86 $BUILD_OPTIONS
|
||||
ninja -Cout/codecache/x86
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_CODE_CACHE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_CODE_CACHE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
export CXXFLAGS="-I$GITHUB_WORKSPACE/icu64/usr/include"
|
||||
export LDFLAGS="-L$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu -Wl,-rpath=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu"
|
||||
export PKG_CONFIG_PATH=$GITHUB_WORKSPACE/icu64/usr/lib/x86_64-linux-gnu/pkgconfig
|
||||
cmake -H. -Bout/codecache/x64 $BUILD_OPTIONS
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/codecache/x64 $BUILD_OPTIONS
|
||||
ninja -Cout/codecache/x64
|
||||
- name: Build x64 Release Mode
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=release -DESCARGOT_CODE_CACHE=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/codecache/release/x64 $BUILD_OPTIONS
|
||||
ninja -Cout/codecache/release/x64
|
||||
- name: Run x86 test
|
||||
run: |
|
||||
$RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/codecache/x86/escargot" sunspider-js
|
||||
|
|
@ -466,44 +650,67 @@ jobs:
|
|||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" octane-loading
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" octane-loading
|
||||
rm -rf $HOME/Escargot-cache/
|
||||
- name: Run x64 release test
|
||||
run: |
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/release/x64/escargot" web-tooling-benchmark
|
||||
rm -rf $HOME/Escargot-cache/
|
||||
- name: Handle error cases
|
||||
run: |
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" sunspider-js
|
||||
rm $HOME/Escargot-cache/3217641879501852439
|
||||
rm $HOME/Escargot-cache/2728638815_17149
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" sunspider-js
|
||||
ls -1q $HOME/Escargot-cache/ | wc -l
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" sunspider-js
|
||||
rm $HOME/Escargot-cache/cache_list
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/codecache/x64/escargot" sunspider-js
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 15
|
||||
|
||||
build-test-wasmjs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
submodules: recursive
|
||||
- name: Install Packages
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib
|
||||
- name: Patch WABT
|
||||
working-directory: ./third_party/wasm/wabt
|
||||
sudo apt-get install -y ninja-build gcc-multilib g++-multilib make g++ pkg-config automake libtool git build-essential checkinstall libncurses-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
|
||||
- name: Build ICU(32)
|
||||
run: |
|
||||
cp ../../../tools/test/wasm-js/wabt_patch .
|
||||
patch -p0 < wabt_patch
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu-build/
|
||||
cd $GITHUB_WORKSPACE/icu-build/icu4c/source
|
||||
LDFLAGS="-m32 -Wl,-rpath=$GITHUB_WORKSPACE/icu32/lib/" CFLAGS="-m32" CXXFLAGS="-m32" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu32/"
|
||||
make -j8
|
||||
make install
|
||||
- name: Build ICU(64)
|
||||
run: |
|
||||
git clone --depth 1 --single-branch -b release-78.1 https://github.com/unicode-org/icu.git $GITHUB_WORKSPACE/icu64-build/
|
||||
cd $GITHUB_WORKSPACE/icu64-build/icu4c/source
|
||||
LDFLAGS="-Wl,-rpath=$GITHUB_WORKSPACE/icu64/lib/" ./runConfigureICU Linux/gcc --prefix="$GITHUB_WORKSPACE/icu64/"
|
||||
make -j8
|
||||
make install
|
||||
- name: Build x86
|
||||
env:
|
||||
BUILD_OPTIONS: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
cmake -H. -Bout/wasm/x86 $BUILD_OPTIONS
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/wasm/x86 $BUILD_OPTIONS
|
||||
ninja -Cout/wasm/x86
|
||||
- name: Build x64
|
||||
env:
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=debug -DESCARGOT_WASM=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
run: |
|
||||
cmake -H. -Bout/wasm/x64 $BUILD_OPTIONS
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/wasm/x64 $BUILD_OPTIONS
|
||||
ninja -Cout/wasm/x64
|
||||
- name: Run x86 test
|
||||
run: $RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/wasm/x86/escargot" wasm-js
|
||||
run: |
|
||||
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu32/lib
|
||||
$RUNNER --arch=x86 --engine="$GITHUB_WORKSPACE/out/wasm/x86/escargot" wasm-js
|
||||
- name: Run x64 test
|
||||
run: $RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/wasm/x64/escargot" wasm-js
|
||||
run: |
|
||||
export LD_LIBRARY_PATH=$GITHUB_WORKSPACE/icu64/lib
|
||||
$RUNNER --arch=x86_64 --engine="$GITHUB_WORKSPACE/out/wasm/x64/escargot" wasm-js
|
||||
- if: ${{ failure() }}
|
||||
uses: mxschmitt/action-tmate@v3
|
||||
timeout-minutes: 60
|
||||
|
|
|
|||
11
.github/workflows/gbs.conf
vendored
Normal file
11
.github/workflows/gbs.conf
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[general]
|
||||
profile = profile.tizen
|
||||
|
||||
[profile.tizen]
|
||||
repos = repo.tizen_base_reference,repo.tizen_reference
|
||||
|
||||
[repo.tizen_reference]
|
||||
url = https://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Unified/reference/repos/standard/packages/
|
||||
|
||||
[repo.tizen_base_reference]
|
||||
url = https://download.tizen.org/snapshots/TIZEN/Tizen/Tizen-Base/reference/repos/standard/packages/
|
||||
322
.github/workflows/release.yml
vendored
Normal file
322
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,322 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
RUNNER: tools/run-tests.py
|
||||
BUILD_OPTIONS: -DESCARGOT_MODE=release -DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF -DESCARGOT_DEPLOY=ON -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja
|
||||
|
||||
jobs:
|
||||
build-macOS:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos-15, macos-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
brew update
|
||||
brew install ninja icu4c zip
|
||||
- name: Build x64
|
||||
run: |
|
||||
# check cpu
|
||||
sysctl -a | grep machdep.cpu
|
||||
# add icu path to pkg_config_path
|
||||
export PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig"
|
||||
echo $PKG_CONFIG_PATH
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.10 -H. -Bout/ $BUILD_OPTIONS
|
||||
ninja -Cout/
|
||||
- name: Check
|
||||
run: |
|
||||
file out/escargot
|
||||
strip out/escargot
|
||||
|
||||
# set deploy directory
|
||||
mkdir -p deploy
|
||||
|
||||
# set escargot
|
||||
cp out/escargot ./deploy/.
|
||||
LIBS=$(otool -L ./deploy/escargot | grep "icu" | awk '{print $1}')
|
||||
for LIB in $LIBS; do
|
||||
BASENAME=$(basename "$LIB")
|
||||
install_name_tool -change "$LIB" "@executable_path/$BASENAME" deploy/escargot
|
||||
done
|
||||
|
||||
# set icu libs
|
||||
ICU_LIBS=("libicuuc" "libicui18n" "libicudata")
|
||||
ICU_SOURCE_PATH="$(brew --prefix icu4c)/lib"
|
||||
ICU_VERSION=$(find "$ICU_SOURCE_PATH" -name "libicuuc.*.dylib" | grep -oE '\.[0-9]+\.' | head -n 1 | tr -d '.')
|
||||
|
||||
if [ -z "$ICU_VERSION" ]; then
|
||||
echo "ICU version could not be detected."
|
||||
exit 1
|
||||
else
|
||||
echo "Detected ICU Version: $ICU_VERSION"
|
||||
fi
|
||||
|
||||
for LIB in "${ICU_LIBS[@]}"; do
|
||||
cp -a $ICU_SOURCE_PATH/$LIB.*.dylib ./deploy/.
|
||||
install_name_tool -id "@loader_path/$LIB.$ICU_VERSION.dylib" "./deploy/$LIB.$ICU_VERSION.dylib"
|
||||
done
|
||||
|
||||
# check results
|
||||
echo "Check results..."
|
||||
ls ./deploy
|
||||
otool -L ./deploy/escargot
|
||||
otool -L ./deploy/libicu*.dylib
|
||||
|
||||
# Ad-hoc sign
|
||||
set -e
|
||||
cd deploy
|
||||
for f in libicu*.dylib; do [ -e "$f" ] || continue; codesign -f -s - "$f"; done
|
||||
codesign --force --deep -s - ./escargot
|
||||
for f in ./escargot libicu*.dylib; do [ -e "$f" ] || continue; codesign --verify --strict --verbose=6 "$f"; done
|
||||
cd ..
|
||||
|
||||
# run test
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/deploy/escargot" new-es
|
||||
|
||||
# zip results
|
||||
if [ "${{ matrix.os }}" == "macos-15" ]; then
|
||||
zip -j escargot-mac64.zip deploy/*
|
||||
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
|
||||
zip -j escargot-mac64arm.zip deploy/*
|
||||
fi
|
||||
- name: Upload mac64
|
||||
if: ${{ matrix.os == 'macos-15' }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-mac64
|
||||
path: ./escargot-mac64.zip
|
||||
- name: Upload mac64arm
|
||||
if: ${{ matrix.os == 'macos-latest' }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-mac64arm
|
||||
path: ./escargot-mac64arm.zip
|
||||
|
||||
build-linux:
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Install Packages
|
||||
run: |
|
||||
# for i386 ICU
|
||||
sudo dpkg --add-architecture i386
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build libicu-dev gcc-multilib g++-multilib zip patchelf
|
||||
sudo apt-get install -y libicu-dev:i386 # install i386 ICU
|
||||
- name: Build x86/x64
|
||||
run: |
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/x86 -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DESCARGOT_TEMPORAL=ON $BUILD_OPTIONS
|
||||
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -H. -Bout/x64 -DESCARGOT_TEMPORAL=ON $BUILD_OPTIONS
|
||||
ninja -Cout/x86
|
||||
ninja -Cout/x64
|
||||
- name: Check
|
||||
run: |
|
||||
file out/x86/escargot
|
||||
file out/x64/escargot
|
||||
strip out/x86/escargot
|
||||
strip out/x64/escargot
|
||||
# set locale
|
||||
sudo locale-gen en_US.UTF-8
|
||||
export LANG=en_US.UTF-8
|
||||
locale
|
||||
|
||||
# set deploy directory and copy escargot binary
|
||||
mkdir -p deploy-x86
|
||||
mkdir -p deploy-x64
|
||||
cp out/x86/escargot ./deploy-x86/.
|
||||
cp out/x64/escargot ./deploy-x64/.
|
||||
|
||||
# set icu libs
|
||||
ldd deploy-x86/escargot | grep "icu" | grep "=>" | awk '{print $3}' | xargs -I '{}' cp '{}' deploy-x86/
|
||||
ldd deploy-x64/escargot | grep "icu" | grep "=>" | awk '{print $3}' | xargs -I '{}' cp '{}' deploy-x64/
|
||||
for LIB in ./deploy-x86/libicu*; do
|
||||
patchelf --set-rpath '$ORIGIN' "$LIB"
|
||||
done
|
||||
for LIB in ./deploy-x64/libicu*; do
|
||||
patchelf --set-rpath '$ORIGIN' "$LIB"
|
||||
done
|
||||
|
||||
# check results
|
||||
echo "Check results..."
|
||||
ls ./deploy-x86
|
||||
ldd deploy-x86/escargot
|
||||
ldd deploy-x86/libicu*
|
||||
ls ./deploy-x64
|
||||
ldd deploy-x64/escargot
|
||||
ldd deploy-x64/libicu*
|
||||
|
||||
# run test
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/deploy-x86/escargot" new-es
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/deploy-x64/escargot" new-es
|
||||
|
||||
# zip results
|
||||
zip -j escargot-linux-x86.zip deploy-x86/*
|
||||
zip -j escargot-linux-x64.zip deploy-x64/*
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-linux
|
||||
path: escargot-linux-*.zip
|
||||
|
||||
build-windows:
|
||||
runs-on: windows-2022
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [x86, x64]
|
||||
steps:
|
||||
- name: Set git cllf config
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
git config --global core.eol lf
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: szenius/set-timezone@v2.0
|
||||
with:
|
||||
timezoneWindows: "Pacific Standard Time"
|
||||
- uses: lukka/get-cmake@latest
|
||||
with:
|
||||
cmakeVersion: "~3.25.0"
|
||||
- uses: GuillaumeFalourd/setup-windows10-sdk-action@v2
|
||||
with:
|
||||
sdk-version: 26100
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.11'
|
||||
- name: Download and Install Visual C++ Redistributable
|
||||
shell: powershell
|
||||
run: |
|
||||
$vcRedistUrl64 = "https://aka.ms/vs/17/release/vc_redist.x64.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath64 = "$env:TEMP\vc_redist.x64.exe"
|
||||
$vcRedistUrl32 = "https://aka.ms/vs/17/release/vc_redist.x86.exe" # Or the appropriate URL for your target architecture/version
|
||||
$vcRedistPath32 = "$env:TEMP\vc_redist.x86.exe"
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl64"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl64 -OutFile $vcRedistPath64
|
||||
|
||||
Write-Host "Downloading Visual C++ Redistributable from $vcRedistUrl32"
|
||||
Invoke-WebRequest -Uri $vcRedistUrl32 -OutFile $vcRedistPath32
|
||||
|
||||
Write-Host "Installing Visual C++ Redistributable silently"
|
||||
Start-Process -FilePath $vcRedistPath64 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Start-Process -FilePath $vcRedistPath32 -ArgumentList "/install /quiet /norestart" -Wait
|
||||
Write-Host "Visual C++ Redistributable installation complete."
|
||||
- uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
with:
|
||||
arch: ${{ matrix.arch }}
|
||||
sdk: "10.0.26100.0"
|
||||
- name: Install zip if not available
|
||||
run: |
|
||||
if (-Not (Get-Command zip -ErrorAction SilentlyContinue)) {
|
||||
choco install zip -y
|
||||
}
|
||||
- name: Build ${{ matrix.arch }}
|
||||
run: |
|
||||
CMake -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch }} -DESCARGOT_ARCH=${{ matrix.arch }} -Bout/ -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_WASM=ON -DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_SHADOWREALM=ON -G Ninja -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_BUILD_TYPE=release
|
||||
CMake --build out/ --config Release
|
||||
- name: Check
|
||||
run: |
|
||||
python tools\run-tests.py --engine=%cd%\out\escargot.exe new-es
|
||||
rename out\escargot.exe escargot-win-${{ matrix.arch }}.exe
|
||||
zip -j escargot-win-${{ matrix.arch}}.zip out\escargot-win-${{ matrix.arch }}.exe
|
||||
shell: cmd
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-artifact-win-${{ matrix.arch }}
|
||||
path: escargot-win-${{ matrix.arch }}.zip
|
||||
|
||||
check-build-mac64:
|
||||
needs: [build-macOS]
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: build-artifact-mac64
|
||||
merge-multiple: true
|
||||
- name: Check
|
||||
run: |
|
||||
unzip artifacts/escargot-mac64.zip -d artifacts
|
||||
otool -L artifacts/escargot
|
||||
otool -L artifacts/*.dylib
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/artifacts/escargot" new-es
|
||||
|
||||
check-build-mac64arm:
|
||||
needs: [build-macOS]
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: build-artifact-mac64arm
|
||||
merge-multiple: true
|
||||
- name: Check
|
||||
run: |
|
||||
unzip artifacts/escargot-mac64arm.zip -d artifacts
|
||||
otool -L artifacts/escargot
|
||||
otool -L artifacts/*.dylib
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/artifacts/escargot" new-es
|
||||
|
||||
check-build-linux:
|
||||
needs: [build-linux]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: build-artifact-linux
|
||||
merge-multiple: true
|
||||
- name: Check
|
||||
run: |
|
||||
dpkg -l | grep libicu-dev
|
||||
mkdir -p result-x86
|
||||
mkdir -p result-x64
|
||||
unzip artifacts/escargot-linux-x86.zip -d result-x86
|
||||
unzip artifacts/escargot-linux-x64.zip -d result-x64
|
||||
ldd result-x86/escargot
|
||||
ldd result-x86/libicu*
|
||||
ldd result-x64/escargot
|
||||
ldd result-x64/libicu*
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/result-x86/escargot" new-es
|
||||
$RUNNER --engine="$GITHUB_WORKSPACE/result-x64/escargot" new-es
|
||||
|
||||
update-release:
|
||||
needs: [check-build-mac64, check-build-mac64arm, check-build-linux, build-windows]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Download build artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
pattern: build-artifact-*
|
||||
merge-multiple: true
|
||||
- name: Upload to release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: |
|
||||
artifacts/escargot-*
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -1,5 +1,5 @@
|
|||
#error_report
|
||||
escargot
|
||||
/escargot
|
||||
escargot.x*
|
||||
.project
|
||||
.cproject
|
||||
|
|
@ -18,7 +18,7 @@ cscope.out
|
|||
#memps
|
||||
escargot.asm
|
||||
escargot.elf
|
||||
out
|
||||
out/*
|
||||
build.ninja
|
||||
rules.ninja
|
||||
.ninja_deps
|
||||
|
|
@ -38,5 +38,6 @@ cmake_install.cmake
|
|||
#etc
|
||||
.vscode
|
||||
EscargotInfo.h
|
||||
third_party/wasm/config.h
|
||||
escargot.pc
|
||||
escargot_generated/*
|
||||
.vs/*
|
||||
19
.gitmodules
vendored
19
.gitmodules
vendored
|
|
@ -15,17 +15,18 @@
|
|||
url = https://github.com/chromium/octane.git
|
||||
ignore = untracked
|
||||
[submodule "test/kangax"]
|
||||
path = test/kangax
|
||||
url = https://github.com/kangax/compat-table.git
|
||||
path = test/kangax
|
||||
url = https://github.com/kangax/compat-table.git
|
||||
ignore = untracked
|
||||
[submodule "third_party/googletest"]
|
||||
path = third_party/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
path = third_party/googletest
|
||||
url = https://github.com/google/googletest.git
|
||||
ignore = untracked
|
||||
[submodule "third_party/wasm/wabt"]
|
||||
path = third_party/wasm/wabt
|
||||
url = https://github.com/WebAssembly/wabt
|
||||
[submodule "third_party/walrus"]
|
||||
path = third_party/walrus
|
||||
url = https://github.com/Samsung/walrus.git
|
||||
ignore = untracked
|
||||
[submodule "test/web-tooling-benchmark"]
|
||||
path = test/web-tooling-benchmark
|
||||
url = https://github.com/v8/web-tooling-benchmark
|
||||
path = test/web-tooling-benchmark
|
||||
url = https://github.com/v8/web-tooling-benchmark
|
||||
ignore = untracked
|
||||
|
|
|
|||
88
.jenkins/Jenkinsfile
vendored
88
.jenkins/Jenkinsfile
vendored
|
|
@ -1,88 +0,0 @@
|
|||
def isPr() {
|
||||
env.CHANGE_ID != null
|
||||
}
|
||||
node {
|
||||
currentBuild.displayName = "Escargot test on x86"
|
||||
try {
|
||||
stage("Get source") {
|
||||
def url = 'https://github.com/Samsung/escargot.git'
|
||||
|
||||
if (isPr()) {
|
||||
def refspec = "+refs/pull/${env.CHANGE_ID}/head:refs/remotes/origin/PR-${env.CHANGE_ID} +refs/heads/master:refs/remotes/origin/master"
|
||||
def extensions = [[$class: 'PreBuildMerge', options: [mergeRemote: "refs/remotes/origin", mergeTarget: "PR-${env.CHANGE_ID}"]]]
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: extensions,
|
||||
submoduleCfg: [],
|
||||
userRemoteConfigs: [[
|
||||
refspec: refspec,
|
||||
url: url
|
||||
]]
|
||||
])
|
||||
} else {
|
||||
def refspec = "+refs/heads/master:refs/remotes/origin/master"
|
||||
def extensions = []
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: [[$class: 'WipeWorkspace']],
|
||||
submoduleCfg: [],
|
||||
userRemoteConfigs: [[
|
||||
refspec: refspec,
|
||||
url: url
|
||||
]]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
stage('Submodule update') {
|
||||
sh 'git submodule update --init test third_party/GCutil'
|
||||
}
|
||||
|
||||
stage('Prepare build(gcc)') {
|
||||
sh 'LDFLAGS=" -L/usr/icu32/lib/ -Wl,-rpath=/usr/icu32/lib/" PKG_CONFIG_PATH="/usr/icu32/lib/pkgconfig/" cmake -H./ -Bbuild/out_linux -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja'
|
||||
sh 'LDFLAGS=" -L/usr/icu32/lib/ -Wl,-rpath=/usr/icu32/lib/" PKG_CONFIG_PATH="/usr/icu32/lib/pkgconfig/" cmake -H./ -Bbuild/out_linux_release -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x86 -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja'
|
||||
sh 'gcc -shared -m32 -fPIC -o backtrace-hooking-32.so tools/test/test262/backtrace-hooking.c'
|
||||
sh 'LDFLAGS=" -L/usr/icu64/lib/ -Wl,-rpath=/usr/icu64/lib/" PKG_CONFIG_PATH="/usr/icu64/lib/pkgconfig/" cmake -H./ -Bbuild/out_linux64 -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=debug -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja'
|
||||
sh 'LDFLAGS=" -L/usr/icu64/lib/ -Wl,-rpath=/usr/icu64/lib/" PKG_CONFIG_PATH="/usr/icu64/lib/pkgconfig/" cmake -H./ -Bbuild/out_linux64_release -DESCARGOT_HOST=linux -DESCARGOT_ARCH=x64 -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja'
|
||||
}
|
||||
|
||||
stage('Build(gcc)') {
|
||||
parallel (
|
||||
'release-build' : {
|
||||
sh 'cd build/out_linux/; ninja '
|
||||
sh 'cd build/out_linux64/; ninja'
|
||||
},
|
||||
'debug-build' : {
|
||||
sh 'cd build/out_linux_release/; ninja'
|
||||
sh 'cd build/out_linux64_release/; ninja'
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
stage('Running test') {
|
||||
timeout(30) {
|
||||
parallel (
|
||||
'release-32bit-test262' : {
|
||||
sh 'GC_FREE_SPACE_DIVISOR=1 tools/run-tests.py --arch=x86 --engine="${WORKSPACE}/build/out_linux_release/escargot" test262'
|
||||
},
|
||||
'debug-32bit-test262' : {
|
||||
sh 'GC_FREE_SPACE_DIVISOR=1 ESCARGOT_LD_PRELOAD=${WORKSPACE}/backtrace-hooking-32.so tools/run-tests.py --arch=x86 --engine="${WORKSPACE}/build/out_linux/escargot" test262'
|
||||
},
|
||||
'release-64bit-test262' : {
|
||||
sh 'GC_FREE_SPACE_DIVISOR=1 tools/run-tests.py --arch=x86_64 --engine="${WORKSPACE}/build/out_linux64_release/escargot" test262'
|
||||
},
|
||||
'kangax test-suites' : {
|
||||
sh 'python tools/kangax/run-kangax.py --engine="${WORKSPACE}/build/out_linux64/escargot"'
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
throw e
|
||||
} finally {
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
def isPr() {
|
||||
env.CHANGE_ID != null
|
||||
}
|
||||
node {
|
||||
currentBuild.displayName = "Escargot test on Arm"
|
||||
try {
|
||||
stage("Get source") {
|
||||
def url = 'https://github.com/Samsung/escargot.git'
|
||||
if (isPr()) {
|
||||
def refspec = "+refs/pull/${env.CHANGE_ID}/head:refs/remotes/origin/PR-${env.CHANGE_ID} +refs/heads/master:refs/remotes/origin/master"
|
||||
def extensions = [[$class: 'PreBuildMerge', options: [mergeRemote: "refs/remotes/origin", mergeTarget: "PR-${env.CHANGE_ID}"]]]
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: extensions,
|
||||
submoduleCfg: [],
|
||||
userRemoteConfigs: [[
|
||||
refspec: refspec,
|
||||
url: url
|
||||
]]
|
||||
])
|
||||
} else {
|
||||
def refspec = "+refs/heads/master:refs/remotes/origin/master"
|
||||
def extensions = []
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: [[$class: 'WipeWorkspace']],
|
||||
submoduleCfg: [],
|
||||
userRemoteConfigs: [[
|
||||
refspec: refspec,
|
||||
url: url
|
||||
]]
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
stage('Submodule update') {
|
||||
sh 'git submodule update --init test third_party/GCutil'
|
||||
}
|
||||
|
||||
def arm32RemoteInfo = [:]
|
||||
arm32RemoteInfo.name = 'arm32-docker'
|
||||
arm32RemoteInfo.host = 'localhost'
|
||||
arm32RemoteInfo.port = 11111
|
||||
arm32RemoteInfo.allowAnyHosts = true
|
||||
withCredentials([usernamePassword(credentialsId: 'arm32docker', passwordVariable: 'passwordVariable', usernameVariable: 'usernameVariable')]) {
|
||||
arm32RemoteInfo.user = usernameVariable
|
||||
arm32RemoteInfo.password = passwordVariable
|
||||
}
|
||||
stage('prepare arm32 workspace') {
|
||||
sshCommand remote: arm32RemoteInfo, command: "rm -rf escargot escargot.zip"
|
||||
sshCommand remote: arm32RemoteInfo, command: "pwd"
|
||||
sh "zip -r escargot.zip ./*"
|
||||
sshPut remote: arm32RemoteInfo, from: "escargot.zip", into: "./"
|
||||
sshCommand remote: arm32RemoteInfo, command: "unzip escargot.zip -d escargot"
|
||||
}
|
||||
|
||||
stage('Build arm32') {
|
||||
sshCommand remote: arm32RemoteInfo, command: "\
|
||||
cd escargot;\
|
||||
cmake -H./ -Bout -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=arm32 -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja;\
|
||||
cmake --build ./out/;\
|
||||
"
|
||||
}
|
||||
|
||||
stage('Build aarch64') {
|
||||
sh 'cmake -H./ -Bout -DESCARGOT_MODE=release -DESCARGOT_THREADING=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TEST=ON -DESCARGOT_OUTPUT=shell -GNinja'
|
||||
sh 'cmake --build ./out/'
|
||||
}
|
||||
|
||||
stage('Running test') {
|
||||
timeout(60) {
|
||||
parallel (
|
||||
'arm32' : {
|
||||
sshCommand remote: arm32RemoteInfo, command: "\
|
||||
cd escargot;\
|
||||
GC_FREE_SPACE_DIVISOR=1 tools/run-tests.py --engine='/root/escargot/out/escargot' --extra-arg='--skip intl402' new-es v8 spidermonkey chakracore test262"
|
||||
},
|
||||
'aarch64' : {
|
||||
sh '#!/bin/bash\nGC_FREE_SPACE_DIVISOR=1 tools/run-tests.py --engine="${WORKSPACE}/out/escargot" --extra-arg="--skip intl402" new-es v8 spidermonkey chakracore test262'
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
throw e
|
||||
} finally {
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ PROJECT (ESCARGOT)
|
|||
|
||||
# CONFIGURATION
|
||||
SET (CMAKE_VERBOSE_MAKEFILE true)
|
||||
SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
|
||||
MESSAGE(STATUS "CMAKE_SYSTEM_NAME: " ${CMAKE_SYSTEM_NAME})
|
||||
MESSAGE(STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR})
|
||||
|
|
@ -43,12 +44,9 @@ ENDIF()
|
|||
IF (NOT DEFINED ESCARGOT_OUTPUT)
|
||||
SET (ESCARGOT_OUTPUT "shell")
|
||||
ENDIF()
|
||||
|
||||
|
||||
MESSAGE(STATUS "Escargot Arch: " ${ESCARGOT_ARCH})
|
||||
MESSAGE(STATUS "Escargot Host: " ${ESCARGOT_HOST})
|
||||
MESSAGE(STATUS "Escargot Mode: " ${ESCARGOT_MODE})
|
||||
MESSAGE(STATUS "Escargot Output: " ${ESCARGOT_OUTPUT})
|
||||
IF (NOT DEFINED ESCARGOT_THREADING)
|
||||
SET (ESCARGOT_THREADING ON)
|
||||
ENDIF()
|
||||
|
||||
SET (ESCARGOT_TARGET escargot)
|
||||
SET (ESCARGOT_CCTEST_TARGET cctest)
|
||||
|
|
@ -62,3 +60,31 @@ INCLUDE (${PROJECT_SOURCE_DIR}/build/escargot.cmake)
|
|||
|
||||
# Pkgconfig
|
||||
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/packaging/escargot.pc.in ${CMAKE_BINARY_DIR}/escargot.pc @ONLY)
|
||||
|
||||
IF (ESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY AND ESCARGOT_TLS_ACCESS_BY_ADDRESS)
|
||||
MESSAGE(FATAL_ERROR "You cannot enable ESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY and ESCARGOT_TLS_ACCESS_BY_ADDRESS at same time")
|
||||
ENDIF()
|
||||
|
||||
MESSAGE(STATUS "Escargot Arch: " ${ESCARGOT_ARCH})
|
||||
MESSAGE(STATUS "Escargot Host: " ${ESCARGOT_HOST})
|
||||
MESSAGE(STATUS "Escargot Mode: " ${ESCARGOT_MODE})
|
||||
MESSAGE(STATUS "Escargot Output: " ${ESCARGOT_OUTPUT})
|
||||
MESSAGE(STATUS "--------------------------------------------------------------------------------")
|
||||
MESSAGE(STATUS "ESCARGOT_DEFINITIONS: " ${ESCARGOT_DEFINITIONS})
|
||||
MESSAGE(STATUS "ESCARGOT_CXXFLAGS: " ${ESCARGOT_CXXFLAGS})
|
||||
MESSAGE(STATUS "ESCARGOT_LDFLAGS: " ${ESCARGOT_LDFLAGS})
|
||||
MESSAGE(STATUS "ESCARGOT_INCDIRS: " ${ESCARGOT_INCDIRS})
|
||||
MESSAGE(STATUS "ESCARGOT_LIBRARIES: " ${ESCARGOT_LIBRARIES})
|
||||
MESSAGE(STATUS "ESCARGOT_LIBICU_SUPPORT: " ${ESCARGOT_LIBICU_SUPPORT})
|
||||
MESSAGE(STATUS "ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN: " ${ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN})
|
||||
MESSAGE(STATUS "ESCARGOT_SMALL_CONFIG: " ${ESCARGOT_SMALL_CONFIG})
|
||||
MESSAGE(STATUS "ESCARGOT_CODE_CACHE: " ${ESCARGOT_CODE_CACHE})
|
||||
MESSAGE(STATUS "ESCARGOT_WASM: " ${ESCARGOT_WASM})
|
||||
MESSAGE(STATUS "ESCARGOT_THREADING: " ${ESCARGOT_THREADING})
|
||||
MESSAGE(STATUS "ESCARGOT_TLS_ACCESS_BY_ADDRESS: " ${ESCARGOT_TLS_ACCESS_BY_ADDRESS})
|
||||
MESSAGE(STATUS "ESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY: " ${ESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY})
|
||||
MESSAGE(STATUS "ESCARGOT_EXPORT_ALL: " ${ESCARGOT_EXPORT_ALL})
|
||||
MESSAGE(STATUS "ESCARGOT_TCO: " ${ESCARGOT_TCO})
|
||||
MESSAGE(STATUS "ESCARGOT_TEMPORAL: " ${ESCARGOT_TEMPORAL})
|
||||
MESSAGE(STATUS "ESCARGOT_SHADOWREALM: " ${ESCARGOT_SHADOWREALM})
|
||||
MESSAGE(STATUS "ESCARGOT_TEST: " ${ESCARGOT_TEST})
|
||||
|
|
|
|||
33
LICENSE.BOEHM-GC
Normal file
33
LICENSE.BOEHM-GC
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
MIT-style License
|
||||
|
||||
Copyright (c) 1988-1989 Hans-J. Boehm, Alan J. Demers
|
||||
Copyright (c) 1991-1996 by Xerox Corporation. All rights reserved.
|
||||
Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
|
||||
Copyright (c) 1998 by Fergus Henderson. All rights reserved.
|
||||
Copyright (c) 1999-2001 by Red Hat, Inc. All rights reserved.
|
||||
Copyright (c) 1999-2011 Hewlett-Packard Development Company, L.P.
|
||||
Copyright (c) 2004-2005 Andrei Polushin
|
||||
Copyright (c) 2007 Free Software Foundation, Inc.
|
||||
Copyright (c) 2008-2022 Ivan Maidanski
|
||||
Copyright (c) 2011 Ludovic Courtes
|
||||
Copyright (c) 2018 Petter A. Urkedal
|
||||
|
||||
|
||||
THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
|
||||
OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
||||
|
||||
Permission is hereby granted to use or copy this program
|
||||
for any purpose, provided the above notices are retained on all copies.
|
||||
Permission to modify the code and to distribute modified code is granted,
|
||||
provided the above notices are retained, and a notice that the code was
|
||||
modified is included with the above copyright notice.
|
||||
|
||||
|
||||
Several files (gc/gc_allocator.h, extra/msvc_dbg.c) come with slightly
|
||||
different licenses, though they are all similar in spirit (the exact
|
||||
licensing terms are given at the beginning of the corresponding source file).
|
||||
|
||||
A few of the files needed to use the GNU-style build procedure come with
|
||||
a modified GPL license that appears not to significantly restrict use of
|
||||
the collector, though use of those files for a purpose other than building
|
||||
the collector may require the resulting code to be covered by the GPL.
|
||||
199
README.md
199
README.md
|
|
@ -1,12 +1,72 @@
|
|||
# Try-Catch Version of Escargot (Origin)
|
||||
# Escargot
|
||||
|
||||
## Prerequisites
|
||||
[](LICENSE)
|
||||
[](https://github.com/Samsung/escargot/releases)
|
||||
[](https://github.com/Samsung/escargot/actions/workflows/es-actions.yml)
|
||||
[](https://scan.coverity.com/projects/samsung-escargot)
|
||||
[](https://codecov.io/gh/Samsung/escargot)
|
||||
|
||||
#### On Ubuntu Linux
|
||||
|
||||
Escargot is a lightweight JavaScript engine developed by [Samsung](https://github.com/Samsung), designed specifically for resource-constrained environments. It is optimized for performance and low memory usage, making it ideal for use in embedded systems, IoT devices, and other applications where resources are limited.
|
||||
|
||||
Key features of Escargot include:
|
||||
* **ECMAScript Compliance**: Escargot supports a significant portion of the latest ECMAScript version ([ECMAScript 2025](https://262.ecma-international.org/16.0/)), ensuring compatibility with modern JavaScript standards while maintaining a lightweight footprint.
|
||||
* **Memory Efficiency**: The engine is designed with memory constraints in mind, making it suitable for devices with limited RAM and storage.
|
||||
* **Performance Optimization**: Escargot implements various optimization techniques to ensure fast execution of JavaScript code, even on low-power devices.
|
||||
* **Extensibility**: The engine can be customized and extended to meet the specific needs of different applications, providing flexibility for developers.
|
||||
|
||||
Escargot is an open-source project that allows developers to contribute to its development or use it in their own projects, while also powering several services in Samsung products. The engine's design prioritizes simplicity and efficiency, making it an excellent choice for developers working in embedded or resource-limited environments.
|
||||
|
||||
|
||||
## Contents 📋
|
||||
* [Building](#Building-)
|
||||
* [Linux](#Linux)
|
||||
* [macOS](#macOS)
|
||||
* [Android](#Android)
|
||||
* [Windows](#Windows)
|
||||
* [Testing](#Testing-)
|
||||
* [Contributing](#Contributing-)
|
||||
* [Research Papers](#Research-Papers-)
|
||||
* [License](#License-)
|
||||
|
||||
## Building 🛠️
|
||||
|
||||
### Supported Platforms and Architectures
|
||||
| **OS** | **Architecture** |
|
||||
|-|-|
|
||||
| **Linux(Ubuntu)** | x86/x64/arm/aarch64 |
|
||||
| macOS | x64/aarch64 |
|
||||
| Windows | Win32/x64 |
|
||||
| Android | x86/x64/arm/aarch64 |
|
||||
|
||||
### Build Options
|
||||
|
||||
The following build options are supported when generating build rules using cmake.
|
||||
|
||||
| **Option** | **Description** | **Flag** | **Value** | **Default** |
|
||||
|-|-|-|-|-|
|
||||
| **HOST** | Choose target platform | -DESCARGOT_HOST | linux/darwin/android/windows | |
|
||||
| **ARCH** | Choose target architecture | -DESCARGOT_ARCH | x64/x86/arm/aarch64 | |
|
||||
| **MODE** | Choose release/debug mode | -DESCARGOT_MODE | release/debug | release |
|
||||
| **OUTPUT** | Choose build output type | -DESCARGOT_OUTPUT | shared_lib/static_lib/shell/cctest | shell |
|
||||
| **LIBICU** | Include libicu library | -DESCARGOT_LIBICU_SUPPORT | ON/OFF | ON |
|
||||
| **WASM** | Enable WebAssembly support | -DESCARGOT_WASM | ON/OFF | OFF |
|
||||
| **CODE_CACHE** | Enable code cache | -DESCARGOT_CODE_CACHE | ON/OFF | OFF |
|
||||
| **TCO** | Enable tail call optimization | -DESCARGOT_TCO | ON/OFF | OFF |
|
||||
| **THREADING** | Enable threading features (e.g. Atomics, SharedArrayBuffer) | -DESCARGOT_THREADING | ON/OFF | ON |
|
||||
| **TLS_ADDRESS_OFFSET** | Enable thread local storge access optimization(offset) | -DESCARGOT_TLS_ACCESS_BY_ADDRESS | ON/OFF | OFF |
|
||||
| **TLS_PTHREAD_KEY** | Enable thread local storge access optimization(pthread_key) | -DESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY | ON/OFF | OFF |
|
||||
| **TEMPORAL** | Enable Temporal support | -ESCARGOT_TEMPORAL | ON/OFF | OFF |
|
||||
| **SHADOWREALM** | Enable ShadowRealm support | -ESCARGOT_SHADOWREALM | ON/OFF | OFF |
|
||||
| **SMALL_CONFIG** | Enable aggressive memory optimizations for tiny devices | -DESCARGOT_SMALL_CONFIG | ON/OFF | OFF |
|
||||
| **TEST** | Enable additional features used only for testing | -DESCARGOT_TEST | ON/OFF | OFF |
|
||||
| **DEBUGGER** | Enable Debug server | -DESCARGOT_DEBUGGER | ON/OFF | OFF |
|
||||
|
||||
### Linux
|
||||
|
||||
General build prerequisites:
|
||||
```sh
|
||||
sudo apt-get install autoconf automake cmake libtool libicu-dev ninja-build
|
||||
sudo apt-get install autoconf automake cmake libtool libicu-dev ninja-build pkg-config
|
||||
```
|
||||
|
||||
Prerequisites for x86-64-to-x86 compilation:
|
||||
|
|
@ -15,47 +75,120 @@ sudo apt-get install gcc-multilib g++-multilib
|
|||
sudo apt-get install libicu-dev:i386
|
||||
```
|
||||
|
||||
## Build Escargot
|
||||
|
||||
build core runtime of Escargot engine (excluding intl, temporal etc)
|
||||
Build Escargot:
|
||||
```sh
|
||||
git clone https://github.com/Samsung/escargot.git -b try-catch
|
||||
cd escargot
|
||||
git submodule update --init third_party
|
||||
cmake -H. -Bout/test/release -DESCARGOT_HOST=linux -DESCARGOT_ARCH=[x86|x64|arm|aarch64] -DESCARGOT_MODE=release -DESCARGOT_OUTPUT=shell -DESCARGOT_THREADING=ON -DESCARGOT_TEST=ON -GNinja
|
||||
ninja -Cout/test/release
|
||||
git submodule update --init third_party # update submodules
|
||||
cmake -DESCARGOT_MODE=release -DESCARGOT_OUTPUT=shell -GNinja
|
||||
ninja
|
||||
```
|
||||
|
||||
## Testing
|
||||
### macOS
|
||||
|
||||
#### octane
|
||||
|
||||
Using test runner
|
||||
General build prerequisites:
|
||||
```sh
|
||||
tools/run-tests.py --engine=ESCARGOT_BINARY_PATH octane
|
||||
brew install autoconf automake cmake icu4c libtool ninja pkg-config
|
||||
|
||||
# add icu path to pkg_config_path (x64)
|
||||
export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig:$PKG_CONFIG_PATH"
|
||||
# add icu path to pkg_config_path (arm64)
|
||||
export PKG_CONFIG_PATH="/opt/homebrew/opt/icu4c/lib/pkgconfig:$PKG_CONFIG_PATH"
|
||||
```
|
||||
|
||||
Or directly run octane benchmarks
|
||||
Build Escargot:
|
||||
```sh
|
||||
cd test/octane/
|
||||
./escargot run.js
|
||||
```
|
||||
#### sunspider
|
||||
|
||||
Using test runner
|
||||
```sh
|
||||
tools/run-tests.py --engine=ESCARGOT_BINARY_PATH sunspider-js
|
||||
git submodule update --init third_party # update submodules
|
||||
cmake -DESCARGOT_MODE=release -DESCARGOT_OUTPUT=shell -GNinja
|
||||
ninja
|
||||
```
|
||||
|
||||
#### kraken
|
||||
### Android
|
||||
|
||||
download kraken benchmark
|
||||
Build prerequisites on Ubuntu:
|
||||
```sh
|
||||
git clone https://github.com/mozilla-it/krakenbenchmark.mozilla.org.git
|
||||
sudo apt install openjdk-17-jdk # require java 17
|
||||
```
|
||||
run kraken benchmark
|
||||
|
||||
Build Escargot using gradle:
|
||||
```sh
|
||||
cd krakenbenchmark.mozilla.org
|
||||
./sunspider --shell ESCARGOT_BINARY_PATH --suite kraken-1.1
|
||||
git submodule update --init third_party # update submodules
|
||||
export ANDROID_SDK_ROOT=.... # set your android SDK root first
|
||||
cd build/android/
|
||||
./gradlew bundleReleaseAar # build escargot AAR
|
||||
./gradlew bundleHostJar # bundle jar for host
|
||||
./gradlew javadocJar # create java doc
|
||||
./gradlew sourcesJar # create sources jar
|
||||
|
||||
./gradlew assembleDebug # build debug test shell
|
||||
./gradlew :escargot:connectedDebugAndroidTest # run escargot-jni tests on android device
|
||||
./gradlew :escargot:testDebugUnitTest # run escargot-jni tests on host
|
||||
```
|
||||
results would be stored in `kraken-1.1-results` directory
|
||||
|
||||
### Windows
|
||||
|
||||
Install VS2022 with cmake and ninja.
|
||||
Open [ x86 Native Tools Command Prompt for VS 2022 | x64 Native Tools Command Prompt for VS 2022 ]
|
||||
|
||||
```sh
|
||||
git submodule update --init third_party # update submodules
|
||||
|
||||
CMake -G "Visual Studio 17 2022" -DCMAKE_SYSTEM_NAME=[ Windows | WindowsStore ] -DCMAKE_SYSTEM_VERSION:STRING="10.0" -DCMAKE_SYSTEM_PROCESSOR=[ x86 | x64 ] -DCMAKE_GENERATOR_PLATFORM=[ Win32 | x64 ],version=10.0.18362.0 -DESCARGOT_ARCH=[ x86 | x64 ] -DESCARGOT_MODE=release -Bout -DESCARGOT_HOST=windows -DESCARGOT_OUTPUT=shell -DESCARGOT_LIBICU_SUPPORT=ON -DESCARGOT_THREADING=ON
|
||||
cd out
|
||||
msbuild ESCARGOT.sln /property:Configuration=Release /p:platform=[ Win32 | x64 ]
|
||||
```
|
||||
|
||||
## Debugger
|
||||
|
||||
Make sure Escargot is built with the `-DESCARGOT_DEBUGGER=1` flag (off by default) enabled;
|
||||
then start Escargot with the `--start-debug-server` option.
|
||||
|
||||
### Connect using a debugger client
|
||||
|
||||
- Escargot python debugger
|
||||
- run `./tools/debugger/debugger.py`; It will automatically connect to a debug server on the default port `6501`
|
||||
- run `./tools/debugger/debugger.py --help` for a list of options
|
||||
- [Visual Studio Code extension](https://github.com/Samsung/escargot-vscode-extension/?tab=readme-ov-file#how-to-use)
|
||||
- Chrome Devtools `⚠️ Early in development ⚠️`
|
||||
- Initial setup:
|
||||
- Navigate to [chrome://inspect](chrome://inspect)
|
||||
- Make sure *Discover network targets* is enabled; click configure
|
||||
- Add `localhost:6501` as a target; click Done
|
||||
- Usage:
|
||||
- The started debug server will be listed in the *Remote Target* list (If it is not, the page may need to be reloaded using the browser reload button)
|
||||
- Click `inspect`
|
||||
- A new window with the Chrome Devtools debugger UI will open
|
||||
|
||||
## Testing ✅
|
||||
|
||||
Escargot supports various benchmark sets, which can be run using the [tools/run-tests.py](https://github.com/Samsung/escargot/blob/master/tools/run-tests.py) script.
|
||||
|
||||
| Benchmark | flag |
|
||||
| --- | --- |
|
||||
| SunSpider 1.0.2 | `sunspider` |
|
||||
| [Octane 2.0](https://github.com/chromium/octane.git) | `octane` |
|
||||
| [test262](https://github.com/tc39/test262.git) | `test262` |
|
||||
| [Web Tooling Benchmark](https://github.com/v8/web-tooling-benchmark) | `web-tooling-benchmark` |
|
||||
| SpiderMonkey (vendor-made) | `spidermonkey` |
|
||||
| ChakraCore (vendor-made) | `chakracore` |
|
||||
| V8 (vendor-made) | `v8` |
|
||||
|
||||
Run each benchmark separately or all together as shown below:
|
||||
```sh
|
||||
tools/run-tests.py --engine=./out/linux/x64/release/escargot web-tooling-benchmark
|
||||
tools/run-tests.py --engine=./out/linux/x64/release/escargot spidermonkey test262 v8
|
||||
```
|
||||
|
||||
## Contributing 💡
|
||||
Escargot welcomes contributions from developers in any form, wheter it's code, documentation, bug reports, or suggestions. By contributing to the project, you agree to license your contributions under the [LGPL-2.1](https://github.com/Samsung/escargot/blob/master/LICENSE) license.
|
||||
|
||||
#### ❗ Vulnerability Reporting
|
||||
⚠️ If you identify any vulnerabilities, please report them through the [Issues page](https://github.com/Samsung/escargot/issues). *Reports sent via other channels may not be considered or may be processed with delays*. Please note that our project assumes the execution of valid JavaScript source code only. Handling of invalid source code is not within the main scope of this project and might not be addressed.
|
||||
|
||||
## Research Papers 📝
|
||||
* [Dynamic code compression for JavaScript engine](https://doi.org/10.1002/spe.3186)
|
||||
Software: Practice and Experience Vol. 53 (5), pp. 1196-1217, 2023
|
||||
|
||||
* [Tail Call Optimization Tailored for Native Stack Utilization in JavaScript Runtimes](https://doi.org/10.1109/ACCESS.2024.3441750)
|
||||
IEEE Access Vol. 12, pp. 111801-111817, 2024
|
||||
|
||||
## License 📜
|
||||
Escargot is open-source software primarily licensed under [LGPL-2.1](https://github.com/Samsung/escargot/blob/master/LICENSE), with some components covered by other licenses. Complete license and copyright information can be found in the source code.
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
v4.0.1
|
||||
v4.3.0
|
||||
|
|
|
|||
7
build/android/.gitignore
vendored
7
build/android/.gitignore
vendored
|
|
@ -1,12 +1,7 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/caches
|
||||
/.idea/libraries
|
||||
/.idea/modules.xml
|
||||
/.idea/workspace.xml
|
||||
/.idea/navEditor.xml
|
||||
/.idea/assetWizardSettings.xml
|
||||
/.idea/*
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
|
|
|
|||
2
build/android/.idea/compiler.xml
generated
2
build/android/.idea/compiler.xml
generated
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
<bytecodeTargetLevel target="21" />
|
||||
</component>
|
||||
</project>
|
||||
4
build/android/.idea/gradle.xml
generated
4
build/android/.idea/gradle.xml
generated
|
|
@ -4,9 +4,9 @@
|
|||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="testRunner" value="CHOOSE_PER_TEST" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
|
|
|||
2
build/android/.idea/misc.xml
generated
2
build/android/.idea/misc.xml
generated
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
|||
12
build/android/.idea/vcs.xml
generated
12
build/android/.idea/vcs.xml
generated
|
|
@ -2,5 +2,17 @@
|
|||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../test/kangax" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../test/octane" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../test/test262" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../test/vendortest" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../test/web-tooling-benchmark" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/GCutil" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/googletest" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/walrus" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/walrus/third_party/sljit" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/walrus/third_party/uvwasi" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/walrus/third_party/wasm-c-api" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../third_party/wasm/wabt" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -4,12 +4,12 @@ plugins {
|
|||
|
||||
android {
|
||||
namespace 'com.samsung.lwe.escargot.shell'
|
||||
compileSdk 33
|
||||
compileSdk 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.samsung.lwe.escargot.shell"
|
||||
minSdk 28
|
||||
targetSdk 33
|
||||
targetSdk 34
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
|
|
|
|||
|
|
@ -5,29 +5,37 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||
import android.content.res.AssetManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.samsung.lwe.escargot.Bridge;
|
||||
import com.samsung.lwe.escargot.Context;
|
||||
import com.samsung.lwe.escargot.Evaluator;
|
||||
import com.samsung.lwe.escargot.Globals;
|
||||
import com.samsung.lwe.escargot.JavaScriptArrayObject;
|
||||
import com.samsung.lwe.escargot.JavaScriptJavaCallbackFunctionObject;
|
||||
import com.samsung.lwe.escargot.JavaScriptString;
|
||||
import com.samsung.lwe.escargot.JavaScriptValue;
|
||||
import com.samsung.lwe.escargot.Memory;
|
||||
import com.samsung.lwe.escargot.VMInstance;
|
||||
import com.samsung.lwe.escargot.util.MultiThreadExecutor;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
|
@ -82,9 +90,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
{
|
||||
Context finalContext = context;
|
||||
context.getGlobalObject().set(context, JavaScriptValue.create("print"), JavaScriptJavaCallbackFunctionObject.create(context, "print", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("print"), JavaScriptJavaCallbackFunctionObject.create(context, "print", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(str);
|
||||
sb.append('\n');
|
||||
|
|
@ -118,9 +126,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
}));
|
||||
|
||||
context.getGlobalObject().set(context, JavaScriptValue.create("load"), JavaScriptJavaCallbackFunctionObject.create(context, "run", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("load"), JavaScriptJavaCallbackFunctionObject.create(context, "run", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
Optional<JavaScriptString> s = javaScriptValues[0].toString(finalContext);
|
||||
if (s.isPresent()) {
|
||||
try {
|
||||
|
|
@ -137,9 +145,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
}));
|
||||
|
||||
context.getGlobalObject().set(context, JavaScriptValue.create("run"), JavaScriptJavaCallbackFunctionObject.create(context, "run", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("run"), JavaScriptJavaCallbackFunctionObject.create(context, "run", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
long sm = System.currentTimeMillis();
|
||||
Optional<JavaScriptString> s = javaScriptValues[0].toString(finalContext);
|
||||
if (s.isPresent()) {
|
||||
|
|
@ -149,16 +157,16 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
}));
|
||||
|
||||
context.getGlobalObject().set(context, JavaScriptValue.create("read"), JavaScriptJavaCallbackFunctionObject.create(context, "read", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("read"), JavaScriptJavaCallbackFunctionObject.create(context, "read", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue javaScriptValue, JavaScriptValue[] javaScriptValues) {
|
||||
Optional<JavaScriptString> s = javaScriptValues[0].toString(finalContext);
|
||||
if (s.isPresent()) {
|
||||
FileReader in = null;
|
||||
try {
|
||||
byte[] chars = Files.readAllBytes(Paths.get(s.get().toJavaString()));
|
||||
String fileContent = new String(chars);
|
||||
return Optional.of(JavaScriptValue.create(fileContent));
|
||||
return Optional.of(JavaScriptString.create(fileContent));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return Optional.empty();
|
||||
|
|
@ -188,6 +196,116 @@ public class MainActivity extends AppCompatActivity {
|
|||
}).start();
|
||||
}
|
||||
|
||||
public void runExample()
|
||||
{
|
||||
new Thread(() -> {
|
||||
Looper.prepare();
|
||||
Handler handler = new Handler(Looper.myLooper());
|
||||
|
||||
Globals.initializeGlobals();
|
||||
|
||||
VMInstance vmInstance = VMInstance.create(Optional.empty(), Optional.empty());
|
||||
Context context = Context.create(vmInstance);
|
||||
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("print"), JavaScriptJavaCallbackFunctionObject.create(context, "", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue receiverValue, JavaScriptValue[] arguments) {
|
||||
System.out.println(arguments[0].toString(context).get().toJavaString());
|
||||
return Optional.empty();
|
||||
}
|
||||
}));
|
||||
|
||||
context.getGlobalObject().set(context, JavaScriptString.create("end"), JavaScriptJavaCallbackFunctionObject.create(context, "", 1, false, new JavaScriptJavaCallbackFunctionObject.Callback() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(Context context, JavaScriptValue receiverValue, JavaScriptValue[] arguments) {
|
||||
Looper.myLooper().quitSafely();
|
||||
return Optional.empty();
|
||||
}
|
||||
}));
|
||||
|
||||
MultiThreadExecutor executor = new MultiThreadExecutor(vmInstance, new MultiThreadExecutor.WorkerThreadEndNotifier() {
|
||||
@Override
|
||||
public void notify(MultiThreadExecutor executor, MultiThreadExecutor.ExecutorInstance instance) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
executor.pumpEventsFromThreadIfNeeds();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
Bridge.register(context, "HTTP", "get", new Bridge.Adapter() {
|
||||
@Override
|
||||
public Optional<JavaScriptValue> callback(Context context, Optional<JavaScriptValue> data) {
|
||||
String url = "";
|
||||
if (data.isPresent()) {
|
||||
Optional<JavaScriptString> mayBeString = data.get().toString(context);
|
||||
if (mayBeString.isPresent()) {
|
||||
url = mayBeString.get().toJavaString();
|
||||
}
|
||||
}
|
||||
final String finalURL = url;
|
||||
MultiThreadExecutor.ExecutorInstance instance = executor.startWorker(context, new MultiThreadExecutor.Executor() {
|
||||
@Override
|
||||
public MultiThreadExecutor.ResultBuilderContext run() {
|
||||
try {
|
||||
HttpURLConnection connection = (HttpURLConnection)new URL(finalURL).openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
int responseCode = connection.getResponseCode();
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String inputLine;
|
||||
StringBuffer response = new StringBuffer();
|
||||
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
return new MultiThreadExecutor.ResultBuilderContext(true, response.toString());
|
||||
} else {
|
||||
return new MultiThreadExecutor.ResultBuilderContext(false, "error HTTP return code:" + responseCode);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return new MultiThreadExecutor.ResultBuilderContext(false, e.toString());
|
||||
}
|
||||
}
|
||||
}, new MultiThreadExecutor.ResultBuilder() {
|
||||
@Override
|
||||
public JavaScriptValue build(Context scriptContext, MultiThreadExecutor.ResultBuilderContext builderContext) {
|
||||
return JavaScriptString.create((String)builderContext.data());
|
||||
}
|
||||
});
|
||||
return Optional.of(instance.promise());
|
||||
}
|
||||
});
|
||||
|
||||
Evaluator.evalScript(context, "" +
|
||||
"let promise1 = HTTP.get('https://httpbin.org/get');" +
|
||||
"let promise2 = HTTP.get('http://google.com');" +
|
||||
"Promise.allSettled([promise1, promise2]).then(function(v) {" +
|
||||
"print(JSON.stringify(v));" +
|
||||
"print('http all end!');" +
|
||||
"end();" +
|
||||
"});", "", false);
|
||||
|
||||
|
||||
Looper.loop();
|
||||
Looper.myLooper().quit();
|
||||
|
||||
context = null;
|
||||
vmInstance = null;
|
||||
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
Memory.gc();
|
||||
|
||||
Globals.finalizeGlobals();
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -205,11 +323,11 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
(new Handler()).postDelayed(new Runnable() {
|
||||
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void run() {
|
||||
findViewById(R.id.button).callOnClick();
|
||||
public void onClick(View v) {
|
||||
runExample();
|
||||
}
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,12 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="run"/>
|
||||
<Button
|
||||
android:id="@+id/button2"
|
||||
android:layout_toRightOf="@id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="mt example"/>
|
||||
<TextView
|
||||
android:layout_below="@+id/button"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '7.3.1' apply false
|
||||
id 'com.android.library' version '7.3.1' apply false
|
||||
id 'com.android.application' version '8.10.1' apply false
|
||||
id 'com.android.library' version '8.10.1' apply false
|
||||
}
|
||||
|
|
@ -1,26 +1,29 @@
|
|||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'jacoco'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
ext {
|
||||
force64Option = System.getProperty("ESCARGOT_BUILD_64BIT_FORCE_LARGE", "OFF")
|
||||
force64Option = System.getProperty("ESCARGOT_BUILD_64BIT_FORCE_LARGE", "ON")
|
||||
pthreadKeyOption = System.getProperty("ESCARGOT_BUILD_TLS_ACCESS_BY_PTHREAD_KEY", "OFF")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace 'com.samsung.lwe.escargot'
|
||||
compileSdk 33
|
||||
compileSdk 36
|
||||
ndkVersion '28.1.13356709'
|
||||
|
||||
defaultConfig {
|
||||
minSdk 28
|
||||
targetSdk 33
|
||||
targetSdk 36
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
arguments "-DCMAKE_VERBOSE_MAKEFILE=ON", "-DESCARGOT_HOST=android", "-DESCARGOT_OUTPUT=static_lib", "-DENABLE_SHELL=OFF",
|
||||
"-DESCARGOT_BUILD_64BIT_FORCE_LARGE="+project.ext.force64Option
|
||||
arguments "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON", "-DCMAKE_VERBOSE_MAKEFILE=ON", "-DESCARGOT_HOST=android", "-DESCARGOT_OUTPUT=static_lib", "-DENABLE_SHELL=OFF",
|
||||
"-DESCARGOT_BUILD_64BIT_FORCE_LARGE="+project.ext.force64Option, "-DESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY="+project.ext.pthreadKeyOption
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +40,6 @@ android {
|
|||
|
||||
debug {
|
||||
testCoverageEnabled true
|
||||
debuggable = true
|
||||
jniDebuggable = true
|
||||
ndk {
|
||||
debuggable = true
|
||||
|
|
@ -55,7 +57,6 @@ android {
|
|||
|
||||
releaseShell {
|
||||
initWith(buildTypes.release)
|
||||
debuggable = true
|
||||
jniDebuggable = true
|
||||
ndk {
|
||||
debuggable = true
|
||||
|
|
@ -78,16 +79,42 @@ android {
|
|||
externalNativeBuild {
|
||||
cmake {
|
||||
path "src/main/cpp/CMakeLists.txt"
|
||||
version "3.18.1"
|
||||
}
|
||||
}
|
||||
|
||||
ndkVersion '25.2.9519653'
|
||||
ndkVersion '27.0.12077973'
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
publishing {
|
||||
singleVariant("release") {
|
||||
// if you don't want sources/javadoc, remove these lines
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
release(MavenPublication) {
|
||||
afterEvaluate {
|
||||
from components.release
|
||||
}
|
||||
artifactId "escargot-android"
|
||||
groupId "com.samsung.lwe.escargot"
|
||||
version "X.X.X.20XXXXXX.X.XXXXXXXX"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url "/XXXXXX/android/releases/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def dirForNativeNoNDK = project.layout.buildDirectory.get().dir("native_nondk")
|
||||
|
|
@ -101,7 +128,9 @@ task buildCMakeNativeNoNDK(type: Exec) {
|
|||
dependsOn createNativeNoNDK
|
||||
workingDir dirForNativeNoNDK
|
||||
if (org.gradle.internal.os.OperatingSystem.current().isLinux()) {
|
||||
commandLine "/usr/bin/env", "cmake", "-DESCARGOT_HOST=linux", "-DESCARGOT_ARCH=x64", "-DESCARGOT_OUTPUT=static_lib", "-DUNDER_NDK=OFF", srcForNativeNoNDK.absolutePath
|
||||
commandLine "/usr/bin/env", "cmake", "-DESCARGOT_HOST=linux", "-DESCARGOT_ARCH=x64", "-DESCARGOT_OUTPUT=static_lib",
|
||||
"-DESCARGOT_BUILD_64BIT_FORCE_LARGE="+project.ext.force64Option,
|
||||
"-DUNDER_NDK=OFF", srcForNativeNoNDK.absolutePath
|
||||
} else if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
|
||||
var javaHome = new ByteArrayOutputStream().withStream { os ->
|
||||
exec {
|
||||
|
|
@ -111,8 +140,18 @@ task buildCMakeNativeNoNDK(type: Exec) {
|
|||
}
|
||||
os.toString().trim()
|
||||
}
|
||||
environment("PKG_CONFIG_PATH", "/usr/local/opt/icu4c/lib/pkgconfig")
|
||||
commandLine "/usr/bin/env", "cmake", "-DESCARGOT_HOST=darwin", "-DESCARGOT_ARCH=x64", "-DESCARGOT_OUTPUT=static_lib", "-DUNDER_NDK=OFF", "-DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF",
|
||||
var icu4cPath = new ByteArrayOutputStream().withStream { os ->
|
||||
exec {
|
||||
commandLine "sh", "-c", "brew --prefix icu4c"
|
||||
standardOutput = os
|
||||
}
|
||||
os.toString().trim()
|
||||
}
|
||||
var pkgConfigPath = icu4cPath + "/lib/pkgconfig"
|
||||
environment("PKG_CONFIG_PATH", pkgConfigPath)
|
||||
commandLine "/usr/bin/env", "cmake", "-DESCARGOT_HOST=darwin", "-DESCARGOT_ARCH=x64", "-DESCARGOT_OUTPUT=static_lib", "-DUNDER_NDK=OFF",
|
||||
"-DESCARGOT_BUILD_64BIT_FORCE_LARGE="+project.ext.force64Option,
|
||||
"-DESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN=OFF",
|
||||
"-DJAVA_HOME=" + javaHome, "-DJAVA_INCLUDE_PATH=" + javaHome + "/include",
|
||||
"-DJAVA_INCLUDE_PATH2=" + javaHome + "/include/darwin", "-DJAVA_AWT_INCLUDE_PATH=" + javaHome + "/include",
|
||||
srcForNativeNoNDK.absolutePath
|
||||
|
|
@ -129,10 +168,9 @@ task buildGMakeNativeNoNDK(type: Exec) {
|
|||
|
||||
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
|
||||
reports {
|
||||
xml.enabled = true
|
||||
html.enabled = true
|
||||
xml.required = true
|
||||
html.required = true
|
||||
}
|
||||
|
||||
def mainSrc = "${project.projectDir}/src/main/java"
|
||||
sourceDirectories.setFrom(files([mainSrc]))
|
||||
|
||||
|
|
@ -159,13 +197,13 @@ project.afterEvaluate {
|
|||
}
|
||||
|
||||
task clearHostJar(type: Delete) {
|
||||
delete 'build/outputs/escargot.jar'
|
||||
delete 'build/libs/escargot.jar'
|
||||
}
|
||||
|
||||
task bundleHostJar(type: Jar) {
|
||||
dependsOn buildGMakeNativeNoNDK
|
||||
dependsOn assemble
|
||||
from(zipTree('build/intermediates/aar_main_jar/debug/classes.jar'))
|
||||
from(zipTree('build/intermediates/aar_main_jar/release/syncReleaseLibJars/classes.jar'))
|
||||
from(dirForNativeNoNDK.asFile.toString() + "/libescargot-jni.so")
|
||||
from(dirForNativeNoNDK.asFile.toString() + "/libescargot-jni.dylib")
|
||||
rename("libescargot-jni.dylib", "libescargot-jni.so")
|
||||
|
|
@ -179,7 +217,6 @@ task sourcesJar(type: Jar) {
|
|||
|
||||
task javadoc(type: Javadoc) {
|
||||
source = android.sourceSets.main.java.sourceFiles
|
||||
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
|
||||
android.libraryVariants.all { variant ->
|
||||
if (variant.name == 'release') {
|
||||
owner.classpath += variant.javaCompileProvider.get().classpath
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
-keep class com.samsung.lwe.escargot.* { *; }
|
||||
-keep enum com.samsung.lwe.escargot.* { *; }
|
||||
|
|
|
|||
1
build/android/escargot/proguard-rules.pro
vendored
1
build/android/escargot/proguard-rules.pro
vendored
|
|
@ -21,3 +21,4 @@
|
|||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-keep class com.samsung.lwe.escargot.* { *; }
|
||||
-keep enum com.samsung.lwe.escargot.* { *; }
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -5,7 +5,8 @@ project(escargot-jni)
|
|||
option(UNDER_NDK "Build under the Android NDK" ON)
|
||||
option(ENABLE_SHELL "Enable shell" OFF)
|
||||
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fexceptions")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fexceptions -Wno-conversion-null -fPIC -ftls-model=local-dynamic ")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -ftls-model=local-dynamic ")
|
||||
|
||||
if (NOT UNDER_NDK)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -g3")
|
||||
|
|
@ -23,7 +24,9 @@ if (ENABLE_SHELL)
|
|||
endif ()
|
||||
ADD_SUBDIRECTORY (${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../ escargot)
|
||||
|
||||
ADD_LIBRARY (escargot-jni SHARED escargot.cpp)
|
||||
FILE (GLOB_RECURSE JNI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
|
||||
ADD_LIBRARY (escargot-jni SHARED ${JNI_SRC})
|
||||
|
||||
SET(LOG_LIBRARY "")
|
||||
if (NOT UNDER_NDK)
|
||||
ADD_DEFINITIONS(-DNDEBUG)
|
||||
|
|
@ -31,7 +34,10 @@ endif ()
|
|||
|
||||
if (UNDER_NDK)
|
||||
FIND_LIBRARY(LOG_LIBRARY log)
|
||||
else (UNDER_NDK)
|
||||
# enable 16KB page size (require version of Android NDK >= 27)
|
||||
TARGET_LINK_OPTIONS(escargot PRIVATE "-Wl,-z,max-page-size=16384")
|
||||
TARGET_LINK_OPTIONS(escargot-jni PRIVATE "-Wl,-z,max-page-size=16384")
|
||||
else ()
|
||||
FIND_PACKAGE(JNI REQUIRED)
|
||||
INCLUDE_DIRECTORIES(${JNI_INCLUDE_DIRS})
|
||||
endif ()
|
||||
|
|
@ -40,15 +46,14 @@ TARGET_LINK_LIBRARIES (escargot-jni PRIVATE escargot ${LOG_LIBRARY})
|
|||
|
||||
if (ENABLE_SHELL)
|
||||
SET(CMAKE_EXE_LINKER_FLAGS -Wl,-export-dynamic) # export symbol of Shell.cpp
|
||||
ADD_COMPILE_OPTIONS(-DNDEBUG -g3 -DESCARGOT_ENABLE_TEST)
|
||||
ADD_COMPILE_OPTIONS(-DNDEBUG -g3 -DESCARGOT_ENABLE_TEST -fPIC)
|
||||
ADD_LINK_OPTIONS(-static-libstdc++)
|
||||
ADD_EXECUTABLE(escargot-shell ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src/shell/Shell.cpp)
|
||||
TARGET_INCLUDE_DIRECTORIES(escargot-shell PRIVATE ADD_SUBDIRECTORY
|
||||
(${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party/GCutil/)
|
||||
(${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party/GCutil/bdwgc/include)
|
||||
(${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../third_party/GCutil/include)
|
||||
(${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../src))
|
||||
TARGET_LINK_LIBRARIES (escargot-shell PRIVATE escargot ${LOG_LIBRARY})
|
||||
|
||||
ADD_EXECUTABLE(test-data-runner ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../tools/test/test-data-runner/test-data-runner.cpp)
|
||||
TARGET_COMPILE_OPTIONS(test-data-runner PRIVATE -std=c++11)
|
||||
endif ()
|
||||
TARGET_COMPILE_OPTIONS(test-data-runner PRIVATE -std=c++11 -fPIC)
|
||||
endif ()
|
||||
|
|
|
|||
350
build/android/escargot/src/main/cpp/EscargotJNI.cpp
Normal file
350
build/android/escargot/src/main/cpp/EscargotJNI.cpp
Normal file
|
|
@ -0,0 +1,350 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
JavaVM* g_jvm;
|
||||
size_t g_nonPointerValueLast = reinterpret_cast<size_t>(ValueRef::createUndefined());
|
||||
thread_local std::vector<ExecutionStateRef*> ExecutionStateRefTracker::g_lastExecutionStateVector;
|
||||
|
||||
jobject createJavaValueObject(JNIEnv* env, jclass clazz, ValueRef* value)
|
||||
{
|
||||
jobject valueObject;
|
||||
if (!value->isStoredInHeap()) {
|
||||
valueObject = env->NewObject(clazz, env->GetMethodID(clazz, "<init>", "(JZ)V"), reinterpret_cast<jlong>(value), jboolean(false));
|
||||
} else {
|
||||
PersistentRefHolder<ValueRef>* pRef = new PersistentRefHolder<ValueRef>(value);
|
||||
jlong ptr = reinterpret_cast<size_t>(pRef);
|
||||
valueObject = env->NewObject(clazz, env->GetMethodID(clazz, "<init>", "(J)V"), ptr);
|
||||
}
|
||||
return valueObject;
|
||||
}
|
||||
|
||||
jobject createJavaValueObject(JNIEnv* env, const char* className, ValueRef* value)
|
||||
{
|
||||
return createJavaValueObject(env, env->FindClass(className), value);
|
||||
}
|
||||
|
||||
ValueRef* unwrapValueRefFromValue(JNIEnv* env, jclass clazz, jobject object)
|
||||
{
|
||||
auto ptr = env->GetLongField(object, env->GetFieldID(clazz, "m_nativePointer", "J"));
|
||||
if (static_cast<size_t>(ptr) <= g_nonPointerValueLast || (static_cast<size_t>(ptr) & 1)) {
|
||||
return reinterpret_cast<ValueRef*>(ptr);
|
||||
} else {
|
||||
PersistentRefHolder<ValueRef>* ref = reinterpret_cast<PersistentRefHolder<ValueRef>*>(ptr);
|
||||
return ref->get();
|
||||
}
|
||||
}
|
||||
|
||||
jobject createJavaObjectFromValue(JNIEnv* env, ValueRef* value)
|
||||
{
|
||||
if (!value->isStoredInHeap() || value->isNumber()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptValue", value);
|
||||
} else if (value->isString()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptString", value);
|
||||
} else if (value->isSymbol()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptSymbol", value);
|
||||
} else if (value->isBigInt()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptBigInt", value);
|
||||
} else if (value->isObject()) {
|
||||
if (value->isArrayObject()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptArrayObject", value);
|
||||
} else if (value->isGlobalObject()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptGlobalObject", value);
|
||||
} else if (value->isFunctionObject()) {
|
||||
if (value->asFunctionObject()->extraData()) {
|
||||
ScriptObjectExtraData* data = reinterpret_cast<ScriptObjectExtraData*>(value->asFunctionObject()->extraData());
|
||||
if (data->implementSideData) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptJavaCallbackFunctionObject", value);
|
||||
}
|
||||
}
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptFunctionObject", value);
|
||||
} else if (value->isPromiseObject()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptPromiseObject", value);
|
||||
} else if (value->isErrorObject()) {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptErrorObject", value);
|
||||
} else {
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptObject", value);
|
||||
}
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
jobject createJavaObject(JNIEnv* env, VMInstanceRef* value)
|
||||
{
|
||||
PersistentRefHolder<VMInstanceRef>* pRef = new PersistentRefHolder<VMInstanceRef>(value);
|
||||
jlong ptr = reinterpret_cast<size_t>(pRef);
|
||||
jclass clazz = env->FindClass("com/samsung/lwe/escargot/VMInstance");
|
||||
return env->NewObject(clazz, env->GetMethodID(clazz, "<init>", "(J)V"), ptr);
|
||||
}
|
||||
|
||||
jobject createJavaObject(JNIEnv* env, ContextRef* value)
|
||||
{
|
||||
PersistentRefHolder<ContextRef>* pRef = new PersistentRefHolder<ContextRef>(value);
|
||||
jlong ptr = reinterpret_cast<size_t>(pRef);
|
||||
jclass clazz = env->FindClass("com/samsung/lwe/escargot/Context");
|
||||
return env->NewObject(clazz, env->GetMethodID(clazz, "<init>", "(J)V"), ptr);
|
||||
}
|
||||
|
||||
OptionalRef<JNIEnv> fetchJNIEnvFromCallback()
|
||||
{
|
||||
JNIEnv* env = nullptr;
|
||||
if (g_jvm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) == JNI_EDETACHED) {
|
||||
#if defined(_JAVASOFT_JNI_H_) // oraclejdk or openjdk
|
||||
if (g_jvm->AttachCurrentThread(reinterpret_cast<void **>(&env), NULL) != 0) {
|
||||
#else
|
||||
if (g_jvm->AttachCurrentThread(reinterpret_cast<JNIEnv **>(&env), NULL) != 0) {
|
||||
#endif
|
||||
// give up
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Escargot_init(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
thread_local static bool inited = false;
|
||||
if (!inited) {
|
||||
if (!g_jvm) {
|
||||
env->GetJavaVM(&g_jvm);
|
||||
}
|
||||
inited = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::string fetchStringFromJavaOptionalString(JNIEnv *env, jobject optional)
|
||||
{
|
||||
auto classOptionalString = env->GetObjectClass(optional);
|
||||
auto methodIsPresent = env->GetMethodID(classOptionalString, "isPresent", "()Z");
|
||||
if (env->CallBooleanMethod(optional, methodIsPresent)) {
|
||||
auto methodGet = env->GetMethodID(classOptionalString, "get", "()Ljava/lang/Object;");
|
||||
jboolean isSucceed;
|
||||
jstring value = static_cast<jstring>(env->CallObjectMethod(optional, methodGet));
|
||||
const char* str = env->GetStringUTFChars(
|
||||
value, &isSucceed);
|
||||
auto length = env->GetStringUTFLength(value);
|
||||
auto ret = std::string(str, length);
|
||||
env->ReleaseStringUTFChars(value, str);
|
||||
return ret;
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
||||
StringRef* createJSStringFromJava(JNIEnv* env, jstring str)
|
||||
{
|
||||
if (!str) {
|
||||
return StringRef::emptyString();
|
||||
}
|
||||
jboolean isSucceed;
|
||||
const char* cString = env->GetStringUTFChars(str, &isSucceed);
|
||||
StringRef* code = StringRef::createFromUTF8(cString, env->GetStringUTFLength(str));
|
||||
env->ReleaseStringUTFChars(str, cString);
|
||||
return code;
|
||||
}
|
||||
|
||||
std::string createStringFromJava(JNIEnv* env, jstring str)
|
||||
{
|
||||
if (!str) {
|
||||
return std::string();
|
||||
}
|
||||
jboolean isSucceed;
|
||||
const char* cString = env->GetStringUTFChars(str, &isSucceed);
|
||||
std::string ret = std::string(cString, env->GetStringUTFLength(str));
|
||||
env->ReleaseStringUTFChars(str, cString);
|
||||
return ret;
|
||||
}
|
||||
|
||||
jstring createJavaStringFromJS(JNIEnv* env, StringRef* string)
|
||||
{
|
||||
std::basic_string<uint16_t> buf;
|
||||
auto bad = string->stringBufferAccessData();
|
||||
buf.reserve(bad.length);
|
||||
|
||||
for (size_t i = 0; i < bad.length ; i ++) {
|
||||
buf.push_back(bad.charAt(i));
|
||||
}
|
||||
|
||||
return env->NewString(buf.data(), buf.length());
|
||||
}
|
||||
|
||||
void throwJavaRuntimeException(ExecutionStateRef* state)
|
||||
{
|
||||
state->throwException(ErrorObjectRef::create(state, ErrorObjectRef::None, StringRef::createFromASCII("Java runtime exception")));
|
||||
}
|
||||
|
||||
bool hasJavaScriptRuntimeExceptionOnEnv(JNIEnv* env)
|
||||
{
|
||||
if (env->ExceptionCheck()) {
|
||||
jthrowable exception = env->ExceptionOccurred();
|
||||
env->ExceptionClear();
|
||||
bool ret = env->IsInstanceOf(exception, env->FindClass("com/samsung/lwe/escargot/internal/JavaScriptRuntimeException"));
|
||||
env->Throw(exception);
|
||||
return ret;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
OptionalRef<ValueRef> extractExceptionFromEnv(JNIEnv* env)
|
||||
{
|
||||
if (env->ExceptionCheck()) {
|
||||
jthrowable exception = env->ExceptionOccurred();
|
||||
env->ExceptionClear();
|
||||
bool ret = env->IsInstanceOf(exception, env->FindClass("com/samsung/lwe/escargot/internal/JavaScriptRuntimeException"));
|
||||
if (ret) {
|
||||
jclass clz = env->FindClass("com/samsung/lwe/escargot/internal/JavaScriptRuntimeException");
|
||||
jobject jv = env->CallObjectMethod(exception, env->GetMethodID(clz, "exception", "()Lcom/samsung/lwe/escargot/JavaScriptValue;"));
|
||||
ValueRef* v = unwrapValueRefFromValue(env, env->GetObjectClass(jv), jv);
|
||||
return v;
|
||||
} else {
|
||||
env->Throw(exception);
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool hasJavaExcpetion(JNIEnv* env)
|
||||
{
|
||||
if (env->ExceptionCheck() && !hasJavaScriptRuntimeExceptionOnEnv(env)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
jobject storeExceptionOnContextAndReturnsIt(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult)
|
||||
{
|
||||
if (hasJavaExcpetion(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
auto exceptionOnEnv = extractExceptionFromEnv(env);
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
// store exception to context
|
||||
auto fieldId = env->GetFieldID(env->GetObjectClass(contextObject), "m_lastThrownException", "Ljava/util/Optional;");
|
||||
ValueRef* exception = exceptionOnEnv ? exceptionOnEnv.get() : evaluatorResult.error.value();
|
||||
auto fieldValue = env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
createJavaObjectFromValue(env, exception));
|
||||
env->SetObjectField(contextObject, fieldId, fieldValue);
|
||||
|
||||
return env->CallStaticObjectMethod(optionalClazz, env->GetStaticMethodID(optionalClazz, "empty",
|
||||
"()Ljava/util/Optional;"));
|
||||
}
|
||||
|
||||
jobject createOptionalValueFromEvaluatorJavaScriptValueResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult)
|
||||
{
|
||||
if (hasJavaExcpetion(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (evaluatorResult.isSuccessful()) {
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
createJavaObjectFromValue(env, evaluatorResult.result));
|
||||
}
|
||||
|
||||
return storeExceptionOnContextAndReturnsIt(env, contextObject, context, evaluatorResult);
|
||||
}
|
||||
|
||||
jobject createOptionalValueFromEvaluatorBooleanResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult)
|
||||
{
|
||||
if (hasJavaExcpetion(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (evaluatorResult.isSuccessful()) {
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
auto booleanClazz = env->FindClass("java/lang/Boolean");
|
||||
auto valueOfMethodId = env->GetStaticMethodID(booleanClazz, "valueOf", "(Z)Ljava/lang/Boolean;");
|
||||
auto javaBoolean = env->CallStaticObjectMethod(booleanClazz, valueOfMethodId, (jboolean)evaluatorResult.result->asBoolean());
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
javaBoolean);
|
||||
}
|
||||
|
||||
return storeExceptionOnContextAndReturnsIt(env, contextObject, context, evaluatorResult);
|
||||
}
|
||||
|
||||
jobject createOptionalValueFromEvaluatorIntegerResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult)
|
||||
{
|
||||
if (hasJavaExcpetion(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (evaluatorResult.isSuccessful()) {
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
auto containerClass = env->FindClass("java/lang/Integer");
|
||||
auto valueOfMethodId = env->GetStaticMethodID(containerClass, "valueOf", "(I)Ljava/lang/Integer;");
|
||||
auto javaValue = env->CallStaticObjectMethod(containerClass, valueOfMethodId, (jint)evaluatorResult.result->asInt32());
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
javaValue);
|
||||
}
|
||||
|
||||
return storeExceptionOnContextAndReturnsIt(env, contextObject, context, evaluatorResult);
|
||||
}
|
||||
|
||||
jobject createOptionalValueFromEvaluatorDoubleResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult)
|
||||
{
|
||||
if (hasJavaExcpetion(env)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (evaluatorResult.isSuccessful()) {
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
auto containerClass = env->FindClass("java/lang/Double");
|
||||
auto valueOfMethodId = env->GetStaticMethodID(containerClass, "valueOf", "(D)Ljava/lang/Double;");
|
||||
auto javaValue = env->CallStaticObjectMethod(containerClass, valueOfMethodId, (jdouble)evaluatorResult.result->asNumber());
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
javaValue);
|
||||
}
|
||||
|
||||
return storeExceptionOnContextAndReturnsIt(env, contextObject, context, evaluatorResult);
|
||||
}
|
||||
|
||||
ScriptObjectExtraData* ensureScriptObjectExtraData(ObjectRef* ref)
|
||||
{
|
||||
ScriptObjectExtraData* data = reinterpret_cast<ScriptObjectExtraData*>(ref->extraData());
|
||||
if (!data) {
|
||||
data = new ScriptObjectExtraData;
|
||||
ref->setExtraData(data);
|
||||
|
||||
Memory::gcRegisterFinalizer(ref, [](void* self, void* data) {
|
||||
ScriptObjectExtraData* extraData = reinterpret_cast<ScriptObjectExtraData*>(reinterpret_cast<ObjectRef*>(self)->extraData());
|
||||
auto env = fetchJNIEnvFromCallback();
|
||||
if (env) {
|
||||
if (extraData->implementSideData) {
|
||||
env->DeleteGlobalRef(extraData->implementSideData);
|
||||
extraData->implementSideData = nullptr;
|
||||
}
|
||||
if (extraData->userData) {
|
||||
env->DeleteGlobalRef(extraData->userData);
|
||||
extraData->userData = nullptr;
|
||||
}
|
||||
}
|
||||
}, nullptr);
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
185
build/android/escargot/src/main/cpp/EscargotJNI.h
Normal file
185
build/android/escargot/src/main/cpp/EscargotJNI.h
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
#ifndef ESCARGOT_ANDROID_ESCARGOTJNI_H
|
||||
#define ESCARGOT_ANDROID_ESCARGOTJNI_H
|
||||
|
||||
#include <jni.h>
|
||||
#include <EscargotPublic.h>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <cassert>
|
||||
|
||||
using namespace Escargot;
|
||||
|
||||
#if defined(ANDROID)
|
||||
#include <android/log.h>
|
||||
#define LOG_TAG "Escargot"
|
||||
#define LOGUNK(...) __android_log_print(ANDROID_LOG_UNKNOWN,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGDEF(...) __android_log_print(ANDROID_LOG_DEFAULT,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGF(...) __android_log_print(ANDROID_FATAL_ERROR,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGS(...) __android_log_print(ANDROID_SILENT_ERROR,LOG_TAG,__VA_ARGS__)
|
||||
#else
|
||||
#define LOGUNK(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGDEF(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGV(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGD(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGI(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGW(...) fprintf(stdout,__VA_ARGS__)
|
||||
#define LOGE(...) fprintf(stderr,__VA_ARGS__)
|
||||
#define LOGF(...) fprintf(stderr,__VA_ARGS__)
|
||||
#define LOGS(...) fprintf(stderr,__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#define THROW_NPE_RETURN_NULL(param, paramType) \
|
||||
if (env->ExceptionCheck()) { \
|
||||
return 0; \
|
||||
} \
|
||||
if (!param) { \
|
||||
env->ThrowNew(env->FindClass("java/lang/NullPointerException"), paramType" cannot be null"); \
|
||||
return 0; \
|
||||
}
|
||||
|
||||
#define THROW_NPE_RETURN_VOID(param, paramType) \
|
||||
if (env->ExceptionCheck()) { \
|
||||
return; \
|
||||
} \
|
||||
if (!param) { \
|
||||
env->ThrowNew(env->FindClass("java/lang/NullPointerException"), paramType" cannot be null"); \
|
||||
return; \
|
||||
}
|
||||
|
||||
#define THROW_CAST_EXCEPTION_IF_NEEDS(param, value, typeName) \
|
||||
if (env->ExceptionCheck()) { \
|
||||
return NULL; \
|
||||
} \
|
||||
if (!value->is##typeName()) { \
|
||||
env->ThrowNew(env->FindClass("java/lang/ClassCastException"), "Can not cast to " #typeName); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
extern JavaVM* g_jvm;
|
||||
extern size_t g_nonPointerValueLast;
|
||||
|
||||
jobject createJavaValueObject(JNIEnv* env, jclass clazz, ValueRef* value);
|
||||
jobject createJavaValueObject(JNIEnv* env, const char* className, ValueRef* value);
|
||||
jobject createJavaObject(JNIEnv* env, VMInstanceRef* value);
|
||||
jobject createJavaObject(JNIEnv* env, ContextRef* value);
|
||||
|
||||
ValueRef* unwrapValueRefFromValue(JNIEnv* env, jclass clazz, jobject object);
|
||||
jobject createJavaObjectFromValue(JNIEnv* env, ValueRef* value);
|
||||
ValueRef* unwrapValueRefFromValue(JNIEnv* env, jclass clazz, jobject object);
|
||||
OptionalRef<JNIEnv> fetchJNIEnvFromCallback();
|
||||
|
||||
std::string fetchStringFromJavaOptionalString(JNIEnv *env, jobject optional);
|
||||
StringRef* createJSStringFromJava(JNIEnv* env, jstring str);
|
||||
std::string createStringFromJava(JNIEnv* env, jstring str);
|
||||
jstring createJavaStringFromJS(JNIEnv* env, StringRef* string);
|
||||
void throwJavaRuntimeException(ExecutionStateRef* state);
|
||||
OptionalRef<ValueRef> extractExceptionFromEnv(JNIEnv* env);
|
||||
jobject storeExceptionOnContextAndReturnsIt(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult);
|
||||
jobject createOptionalValueFromEvaluatorJavaScriptValueResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult);
|
||||
jobject createOptionalValueFromEvaluatorBooleanResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult);
|
||||
jobject createOptionalValueFromEvaluatorIntegerResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult);
|
||||
jobject createOptionalValueFromEvaluatorDoubleResult(JNIEnv* env, jobject contextObject, ContextRef* context, Evaluator::EvaluatorResult& evaluatorResult);
|
||||
|
||||
struct ScriptObjectExtraData {
|
||||
jobject userData;
|
||||
jobject implementSideData;
|
||||
|
||||
ScriptObjectExtraData()
|
||||
: userData(nullptr)
|
||||
, implementSideData(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void* operator new(size_t t)
|
||||
{
|
||||
return Memory::gcMallocAtomic(sizeof(ScriptObjectExtraData));
|
||||
}
|
||||
};
|
||||
|
||||
ScriptObjectExtraData* ensureScriptObjectExtraData(ObjectRef* ref);
|
||||
|
||||
template<typename T>
|
||||
jobject nativeOptionalValueIntoJavaOptionalValue(JNIEnv* env, OptionalRef<T> ref)
|
||||
{
|
||||
if (env->ExceptionCheck()) {
|
||||
return nullptr;
|
||||
}
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
if (ref) {
|
||||
jmethodID ctorMethod = env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;");
|
||||
return env->CallStaticObjectMethod(optionalClazz, ctorMethod, createJavaObjectFromValue(env, ref.value()));
|
||||
}
|
||||
|
||||
return env->CallStaticObjectMethod(optionalClazz, env->GetStaticMethodID(optionalClazz, "empty",
|
||||
"()Ljava/util/Optional;"));
|
||||
}
|
||||
|
||||
template<typename NativeType>
|
||||
PersistentRefHolder<NativeType>* getPersistentPointerFromJava(JNIEnv *env, jclass clazz, jobject object)
|
||||
{
|
||||
auto ptr = env->GetLongField(object, env->GetFieldID(clazz, "m_nativePointer", "J"));
|
||||
PersistentRefHolder<NativeType>* pVMRef = reinterpret_cast<PersistentRefHolder<NativeType>*>(ptr);
|
||||
return pVMRef;
|
||||
}
|
||||
|
||||
class ExecutionStateRefTracker {
|
||||
public:
|
||||
ExecutionStateRefTracker(ExecutionStateRef* newValue)
|
||||
{
|
||||
g_lastExecutionStateVector.push_back(newValue);
|
||||
}
|
||||
|
||||
~ExecutionStateRefTracker()
|
||||
{
|
||||
g_lastExecutionStateVector.pop_back();
|
||||
}
|
||||
private:
|
||||
friend class ScriptEvaluator;
|
||||
static thread_local std::vector<ExecutionStateRef*> g_lastExecutionStateVector;
|
||||
};
|
||||
|
||||
class ScriptEvaluator {
|
||||
public:
|
||||
template <typename... Args, typename F>
|
||||
static Evaluator::EvaluatorResult execute(ContextRef* ctx, F&& closure, Args... args)
|
||||
{
|
||||
typedef ValueRef* (*Closure)(ExecutionStateRef * state, Args...);
|
||||
if (ExecutionStateRefTracker::g_lastExecutionStateVector.size()) {
|
||||
return Evaluator::execute(ExecutionStateRefTracker::g_lastExecutionStateVector.back(), [](ExecutionStateRef * state, Closure closure, Args... args) -> ValueRef* {
|
||||
ExecutionStateRefTracker tracker(state);
|
||||
return closure(state, args...);
|
||||
}, Closure(closure), args...);
|
||||
} else {
|
||||
return Evaluator::execute(ctx, [](ExecutionStateRef * state, Closure closure, Args... args) -> ValueRef* {
|
||||
ExecutionStateRefTracker tracker(state);
|
||||
return closure(state, args...);
|
||||
}, Closure(closure), args...);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif //ESCARGOT_ANDROID_ESCARGOTJNI_H
|
||||
74
build/android/escargot/src/main/cpp/JNIArrayObject.cpp
Normal file
74
build/android/escargot/src/main/cpp/JNIArrayObject.cpp
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptArrayObject_create(JNIEnv* env, jclass clazz,
|
||||
jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state) -> ValueRef* {
|
||||
return ArrayObjectRef::create(state);
|
||||
});
|
||||
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
return createJavaObjectFromValue(env, evaluatorResult.result->asArrayObject());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptArrayObject_length(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ArrayObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asArrayObject();
|
||||
|
||||
int64_t length = 0;
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ArrayObjectRef* thisValueRef, int64_t* pLength) -> ValueRef* {
|
||||
*pLength = static_cast<int64_t>(thisValueRef->length(state));
|
||||
return ValueRef::createUndefined();
|
||||
}, thisValueRef, &length);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptArrayObject_setLength(JNIEnv* env, jobject thiz,
|
||||
jobject context, jlong newLength)
|
||||
{
|
||||
THROW_NPE_RETURN_VOID(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ArrayObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asArrayObject();
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ArrayObjectRef* thisValueRef, jlong pLength) -> ValueRef* {
|
||||
if (pLength >= 0) {
|
||||
thisValueRef->setLength(state, static_cast<uint64_t>(pLength));
|
||||
} else {
|
||||
thisValueRef->set(state, AtomicStringRef::create(state->context(), "length")->string(), ValueRef::create(pLength));
|
||||
}
|
||||
return ValueRef::createUndefined();
|
||||
}, thisValueRef, newLength);
|
||||
}
|
||||
80
build/android/escargot/src/main/cpp/JNIBigInt.cpp
Normal file
80
build/android/escargot/src/main/cpp/JNIBigInt.cpp
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_create__I(JNIEnv* env, jclass clazz, jint num)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, BigIntRef::create(static_cast<int64_t>(num)));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_create__J(JNIEnv* env, jclass clazz, jlong num)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, BigIntRef::create(static_cast<int64_t>(num)));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_create__Ljava_lang_String_2I(JNIEnv* env,
|
||||
jclass clazz,
|
||||
jstring numString,
|
||||
jint radix)
|
||||
{
|
||||
return createJavaValueObject(env, clazz,
|
||||
BigIntRef::create(createJSStringFromJava(env, numString), radix));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_create__Lcom_samsung_lwe_escargot_JavaScriptString_2I(
|
||||
JNIEnv* env, jclass clazz, jobject numString, jint radix)
|
||||
{
|
||||
if (numString) {
|
||||
return createJavaValueObject(env, clazz,
|
||||
BigIntRef::create(unwrapValueRefFromValue(env, env->GetObjectClass(
|
||||
numString), numString)->asString(), radix));
|
||||
} else {
|
||||
return createJavaValueObject(env, clazz, BigIntRef::create(static_cast<int64_t>(0)));
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_toString(JNIEnv* env, jobject thiz, jint radix)
|
||||
{
|
||||
return createJavaObjectFromValue(env, unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asBigInt()->toString(radix));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_toNumber(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asBigInt()->toNumber();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptBigInt_toInt64(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asBigInt()->toInt64();
|
||||
}
|
||||
153
build/android/escargot/src/main/cpp/JNIBridge.cpp
Normal file
153
build/android/escargot/src/main/cpp/JNIBridge.cpp
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_Bridge_register(JNIEnv* env, jclass clazz, jobject context,
|
||||
jstring objectName, jstring propertyName,
|
||||
jobject adapter)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(adapter, "Adapter");
|
||||
|
||||
auto contextPtr = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context),
|
||||
context);
|
||||
auto jsObjectName = createJSStringFromJava(env, objectName);
|
||||
auto jsPropertyName = createJSStringFromJava(env, propertyName);
|
||||
|
||||
if (!jsObjectName->length() || !jsPropertyName->length()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
adapter = env->NewGlobalRef(adapter);
|
||||
|
||||
auto evalResult = ScriptEvaluator::execute(contextPtr->get(),
|
||||
[](ExecutionStateRef* state, JNIEnv* env, jobject adapter,
|
||||
StringRef* jsObjectName,
|
||||
StringRef* jsPropertyName) -> ValueRef* {
|
||||
auto globalObject = state->context()->globalObject();
|
||||
ObjectRef* targetObject;
|
||||
|
||||
ValueRef* willBeTargetObject = globalObject->getOwnProperty(
|
||||
state, jsObjectName);
|
||||
if (willBeTargetObject->isObject()) {
|
||||
targetObject = willBeTargetObject->asObject();
|
||||
} else {
|
||||
targetObject = ObjectRef::create(state);
|
||||
globalObject->defineDataProperty(state,
|
||||
jsObjectName,
|
||||
targetObject,
|
||||
true, true, true);
|
||||
}
|
||||
|
||||
FunctionObjectRef::NativeFunctionInfo info(
|
||||
AtomicStringRef::create(state->context(), jsPropertyName),
|
||||
[](ExecutionStateRef* state,
|
||||
ValueRef* thisValue, size_t argc,
|
||||
ValueRef** argv,
|
||||
bool isConstructorCall) -> ValueRef* {
|
||||
ExecutionStateRefTracker tracker(state);
|
||||
FunctionObjectRef* callee = state->resolveCallee().get();
|
||||
|
||||
jobject jo = ensureScriptObjectExtraData(
|
||||
reinterpret_cast<FunctionObjectRef*>(callee))->implementSideData;
|
||||
auto env = fetchJNIEnvFromCallback();
|
||||
if (!env) {
|
||||
// give up
|
||||
LOGE("could not fetch env from callback");
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
throwJavaRuntimeException(state);
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
env->PushLocalFrame(32);
|
||||
|
||||
jobject callbackArg;
|
||||
jclass optionalClazz = env->FindClass(
|
||||
"java/util/Optional");
|
||||
if (argc) {
|
||||
callbackArg = env->CallStaticObjectMethod(
|
||||
optionalClazz,
|
||||
env->GetStaticMethodID(
|
||||
optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
createJavaObjectFromValue(env.get(), argv[0]));
|
||||
} else {
|
||||
callbackArg = env->CallStaticObjectMethod(
|
||||
optionalClazz,
|
||||
env->GetStaticMethodID(
|
||||
optionalClazz, "empty",
|
||||
"()Ljava/util/Optional;"));
|
||||
}
|
||||
auto javaReturnValue = env->CallObjectMethod(
|
||||
jo,
|
||||
env->GetMethodID(
|
||||
env->GetObjectClass(jo),
|
||||
"callback",
|
||||
"(Lcom/samsung/lwe/escargot/Context;Ljava/util/Optional;)Ljava/util/Optional;"),
|
||||
createJavaObject(env.get(), callee->context()),
|
||||
callbackArg);
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
env->PopLocalFrame(NULL);
|
||||
throwJavaRuntimeException(state);
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
auto methodIsPresent = env->GetMethodID(
|
||||
optionalClazz, "isPresent", "()Z");
|
||||
ValueRef* nativeReturnValue = ValueRef::createUndefined();
|
||||
if (javaReturnValue && env->CallBooleanMethod(javaReturnValue,
|
||||
methodIsPresent)) {
|
||||
auto methodGet = env->GetMethodID(
|
||||
optionalClazz, "get",
|
||||
"()Ljava/lang/Object;");
|
||||
jobject value = env->CallObjectMethod(
|
||||
javaReturnValue, methodGet);
|
||||
nativeReturnValue = unwrapValueRefFromValue(
|
||||
env.get(),
|
||||
env->GetObjectClass(value),
|
||||
value);
|
||||
}
|
||||
|
||||
env->PopLocalFrame(NULL);
|
||||
return nativeReturnValue;
|
||||
}, 1, true, false);
|
||||
FunctionObjectRef* callback = FunctionObjectRef::create(
|
||||
state, info);
|
||||
targetObject->defineDataProperty(state, jsPropertyName,
|
||||
callback, true, true,
|
||||
true);
|
||||
return callback;
|
||||
}, env, adapter, jsObjectName, jsPropertyName);
|
||||
|
||||
if (evalResult.isSuccessful()) {
|
||||
FunctionObjectRef* callback = evalResult.result->asFunctionObject();
|
||||
ensureScriptObjectExtraData(callback)->implementSideData = adapter;
|
||||
} else {
|
||||
env->DeleteGlobalRef(adapter);
|
||||
}
|
||||
|
||||
return evalResult.isSuccessful();
|
||||
}
|
||||
61
build/android/escargot/src/main/cpp/JNIContext.cpp
Normal file
61
build/android/escargot/src/main/cpp/JNIContext.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_Context_create(JNIEnv* env, jclass clazz, jobject vmInstance)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(vmInstance, "VMInstance");
|
||||
|
||||
auto vmPtr = getPersistentPointerFromJava<VMInstanceRef>(env, env->GetObjectClass(vmInstance),
|
||||
vmInstance);
|
||||
auto contextRef = ContextRef::create(vmPtr->get());
|
||||
return createJavaObject(env, contextRef.get());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_Context_getGlobalObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(thiz), thiz);
|
||||
return createJavaObjectFromValue(env, contextRef->get()->globalObject());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_Context_throwException(JNIEnv* env, jobject thiz, jobject exception)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(exception, "JavaScriptValue");
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(thiz), thiz);
|
||||
if (contextRef->get()->canThrowException()) {
|
||||
ValueRef* exceptionRef = unwrapValueRefFromValue(env, env->GetObjectClass(exception), exception);
|
||||
if (exceptionRef->isErrorObject()) {
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* exceptionRef) -> ValueRef* {
|
||||
exceptionRef->asErrorObject()->updateStackTraceData(state);
|
||||
return ValueRef::createUndefined();
|
||||
}, exceptionRef);
|
||||
}
|
||||
jclass clz = env->FindClass("com/samsung/lwe/escargot/internal/JavaScriptRuntimeException");
|
||||
jobject obj = env->NewObject(clz, env->GetMethodID(clz, "<init>", "(Lcom/samsung/lwe/escargot/JavaScriptValue;)V"), exception);
|
||||
env->Throw(static_cast<jthrowable>(obj));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
80
build/android/escargot/src/main/cpp/JNIErrorObject.cpp
Normal file
80
build/android/escargot/src/main/cpp/JNIErrorObject.cpp
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptErrorObject_create(JNIEnv* env, jclass clazz,
|
||||
jobject context, jobject kind,
|
||||
jstring message)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(kind, "ErrorKind");
|
||||
THROW_NPE_RETURN_NULL(message, "String");
|
||||
|
||||
auto nameMethod = env->GetMethodID(env->GetObjectClass(kind), "name", "()Ljava/lang/String;");
|
||||
auto kindName = (jstring)env->CallObjectMethod(kind, nameMethod);
|
||||
auto string = createStringFromJava(env, kindName);
|
||||
|
||||
ErrorObjectRef::Code code = Escargot::ErrorObjectRef::None;
|
||||
if (string == "ReferenceError") {
|
||||
code = Escargot::ErrorObjectRef::ReferenceError;
|
||||
} else if (string == "TypeError") {
|
||||
code = Escargot::ErrorObjectRef::TypeError;
|
||||
} else if (string == "SyntaxError") {
|
||||
code = Escargot::ErrorObjectRef::SyntaxError;
|
||||
} else if (string == "RangeError") {
|
||||
code = Escargot::ErrorObjectRef::RangeError;
|
||||
} else if (string == "URIError") {
|
||||
code = Escargot::ErrorObjectRef::URIError;
|
||||
} else if (string == "EvalError") {
|
||||
code = Escargot::ErrorObjectRef::EvalError;
|
||||
} else if (string == "AggregateError") {
|
||||
code = Escargot::ErrorObjectRef::AggregateError;
|
||||
}
|
||||
|
||||
StringRef* jsMessage = createJSStringFromJava(env, message);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state,
|
||||
ErrorObjectRef::Code code, StringRef* jsMessage) -> ValueRef* {
|
||||
return ErrorObjectRef::create(state, code, jsMessage);
|
||||
}, code, jsMessage);
|
||||
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
return createJavaObjectFromValue(env, evaluatorResult.result->asErrorObject());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptErrorObject_stack(JNIEnv* env, jobject thiz,
|
||||
jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ErrorObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asErrorObject();
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ErrorObjectRef* thisValueRef) -> ValueRef* {
|
||||
return thisValueRef->getOwnProperty(state, StringRef::createFromASCII("stack"))->toString(state);
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(), evaluatorResult);
|
||||
}
|
||||
118
build/android/escargot/src/main/cpp/JNIEvaluator.cpp
Normal file
118
build/android/escargot/src/main/cpp/JNIEvaluator.cpp
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
static bool stringEndsWith(const std::string& str, const std::string& suffix)
|
||||
{
|
||||
return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
|
||||
}
|
||||
|
||||
static Evaluator::EvaluatorResult evalScript(ContextRef* context, StringRef* source, StringRef* srcName, bool shouldPrintScriptResult, bool shouldExecutePendingJobsAtEnd, bool isModule)
|
||||
{
|
||||
if (stringEndsWith(srcName->toStdUTF8String(), "mjs")) {
|
||||
isModule = isModule || true;
|
||||
}
|
||||
|
||||
auto scriptInitializeResult = context->scriptParser()->initializeScript(source, srcName, isModule);
|
||||
if (!scriptInitializeResult.script) {
|
||||
LOGD("Script parsing error: ");
|
||||
switch (scriptInitializeResult.parseErrorCode) {
|
||||
case Escargot::ErrorObjectRef::Code::SyntaxError:
|
||||
LOGD("SyntaxError");
|
||||
break;
|
||||
case Escargot::ErrorObjectRef::Code::EvalError:
|
||||
LOGD("EvalError");
|
||||
break;
|
||||
case Escargot::ErrorObjectRef::Code::RangeError:
|
||||
LOGD("RangeError");
|
||||
break;
|
||||
case Escargot::ErrorObjectRef::Code::ReferenceError:
|
||||
LOGD("ReferenceError");
|
||||
break;
|
||||
case Escargot::ErrorObjectRef::Code::TypeError:
|
||||
LOGD("TypeError");
|
||||
break;
|
||||
case Escargot::ErrorObjectRef::Code::URIError:
|
||||
LOGD("URIError");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
LOGD(": %s\n", scriptInitializeResult.parseErrorMessage->toStdUTF8String().data());
|
||||
Evaluator::EvaluatorResult evalResult;
|
||||
evalResult.error = StringRef::createFromASCII("script parsing error");
|
||||
return evalResult;
|
||||
}
|
||||
|
||||
auto evalResult = ScriptEvaluator::execute(context, [](ExecutionStateRef* state, ScriptRef* script) -> ValueRef* {
|
||||
return script->execute(state);
|
||||
},
|
||||
scriptInitializeResult.script.get());
|
||||
|
||||
if (!evalResult.isSuccessful()) {
|
||||
if (shouldPrintScriptResult) {
|
||||
LOGD("Uncaught %s:\n", evalResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
for (size_t i = 0; i < evalResult.stackTrace.size(); i++) {
|
||||
LOGD("%s (%d:%d)\n", evalResult.stackTrace[i].srcName->toStdUTF8String().data(), (int)evalResult.stackTrace[i].loc.line, (int)evalResult.stackTrace[i].loc.column);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (shouldPrintScriptResult) {
|
||||
LOGD("%s", evalResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldExecutePendingJobsAtEnd) {
|
||||
while (context->vmInstance()->hasPendingJob() || context->vmInstance()->hasPendingJobFromAnotherThread()) {
|
||||
if (context->vmInstance()->waitEventFromAnotherThread(10)) {
|
||||
context->vmInstance()->executePendingJobFromAnotherThread();
|
||||
}
|
||||
if (context->vmInstance()->hasPendingJob()) {
|
||||
auto jobResult = context->vmInstance()->executePendingJob();
|
||||
if (shouldPrintScriptResult) {
|
||||
if (jobResult.error) {
|
||||
LOGD("Uncaught %s:(in promise job)\n", jobResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
} else {
|
||||
LOGD("%s(in promise job)\n", jobResult.resultOrErrorToString(context)->toStdUTF8String().data());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return evalResult;
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_Evaluator_evalScript(JNIEnv* env, jclass clazz, jobject context,
|
||||
jstring source, jstring sourceFileName,
|
||||
jboolean shouldPrintScriptResult,
|
||||
jboolean shouldExecutePendingJobsAtEnd)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto ptr = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
Evaluator::EvaluatorResult result = evalScript(ptr->get(), createJSStringFromJava(env, source),
|
||||
createJSStringFromJava(env, sourceFileName), shouldPrintScriptResult,
|
||||
shouldExecutePendingJobsAtEnd, false);
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, ptr->get(), result);
|
||||
}
|
||||
113
build/android/escargot/src/main/cpp/JNIFunctionObject.cpp
Normal file
113
build/android/escargot/src/main/cpp/JNIFunctionObject.cpp
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptFunctionObject_context(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
FunctionObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asFunctionObject();
|
||||
return createJavaObject(env, thisValueRef->context());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptJavaCallbackFunctionObject_create(JNIEnv* env, jclass clazz,
|
||||
jobject context,
|
||||
jstring functionName,
|
||||
jint argumentCount,
|
||||
jboolean isConstructor,
|
||||
jobject callback)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(callback, "Callback");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context),
|
||||
context);
|
||||
|
||||
FunctionObjectRef::NativeFunctionInfo info(
|
||||
AtomicStringRef::create(contextRef->get(), createJSStringFromJava(env, functionName)),
|
||||
[](ExecutionStateRef* state, ValueRef* thisValue, size_t argc, ValueRef** argv, bool isConstructorCall) -> ValueRef* {
|
||||
auto env = fetchJNIEnvFromCallback();
|
||||
if (!env) {
|
||||
LOGE("failed to fetch env from function callback");
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
throwJavaRuntimeException(state);
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
ExecutionStateRefTracker tracker(state);
|
||||
env->PushLocalFrame(32);
|
||||
jobject callback = ensureScriptObjectExtraData(state->resolveCallee().get())->implementSideData;
|
||||
auto callbackMethodId = env->GetMethodID(env->GetObjectClass(callback), "callback",
|
||||
"(Lcom/samsung/lwe/escargot/Context;Lcom/samsung/lwe/escargot/JavaScriptValue;[Lcom/samsung/lwe/escargot/JavaScriptValue;)Ljava/util/Optional;");
|
||||
|
||||
jobjectArray javaArgv = env->NewObjectArray(argc, env->FindClass("com/samsung/lwe/escargot/JavaScriptValue"), nullptr);
|
||||
|
||||
for (size_t i = 0; i < argc; i ++) {
|
||||
auto ref = createJavaObjectFromValue(env.get(), argv[i]);
|
||||
env->SetObjectArrayElement(javaArgv, i, ref);
|
||||
env->DeleteLocalRef(ref);
|
||||
}
|
||||
jobject returnValue = env->CallObjectMethod(
|
||||
callback,
|
||||
callbackMethodId,
|
||||
createJavaObject(env.get(), state->resolveCallee()->context()),
|
||||
createJavaObjectFromValue(env.get(), thisValue),
|
||||
javaArgv
|
||||
);
|
||||
|
||||
if (env->ExceptionCheck()) {
|
||||
env->PopLocalFrame(NULL);
|
||||
throwJavaRuntimeException(state);
|
||||
return ValueRef::createUndefined();
|
||||
}
|
||||
|
||||
ValueRef* nativeReturnValue = ValueRef::createUndefined();
|
||||
if (returnValue) {
|
||||
auto classOptional = env->GetObjectClass(returnValue);
|
||||
auto methodIsPresent = env->GetMethodID(classOptional, "isPresent", "()Z");
|
||||
if (env->CallBooleanMethod(returnValue, methodIsPresent)) {
|
||||
auto methodGet = env->GetMethodID(classOptional, "get", "()Ljava/lang/Object;");
|
||||
jobject callbackReturnValue = env->CallObjectMethod(returnValue, methodGet);
|
||||
nativeReturnValue = unwrapValueRefFromValue(env.get(), env->GetObjectClass(callbackReturnValue), callbackReturnValue);
|
||||
}
|
||||
}
|
||||
env->PopLocalFrame(NULL);
|
||||
return nativeReturnValue;
|
||||
},
|
||||
argumentCount,
|
||||
isConstructor);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(),
|
||||
[](ExecutionStateRef* state, FunctionObjectRef::NativeFunctionInfo info) -> ValueRef* {
|
||||
return FunctionObjectRef::create(state, info);
|
||||
}, info);
|
||||
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
|
||||
callback = env->NewGlobalRef(callback);
|
||||
FunctionObjectRef* fn = evaluatorResult.result->asFunctionObject();
|
||||
ensureScriptObjectExtraData(fn)->implementSideData = callback;
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptJavaCallbackFunctionObject", fn);
|
||||
}
|
||||
137
build/android/escargot/src/main/cpp/JNIGlobalObject.cpp
Normal file
137
build/android/escargot/src/main/cpp/JNIGlobalObject.cpp
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_jsonStringify(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject input)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(input, "JavaScriptValue");
|
||||
|
||||
auto globalObjectRef = getPersistentPointerFromJava<GlobalObjectRef>(env, env->GetObjectClass(context), thiz);
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* inputValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(input), input);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* inputValueRef) -> ValueRef* {
|
||||
return globalObject->jsonStringify()->call(state, globalObject->json(), 1, &inputValueRef);
|
||||
}, globalObjectRef->get(), inputValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_jsonParse(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject input)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(input, "JavaScriptValue");
|
||||
|
||||
auto globalObjectRef = getPersistentPointerFromJava<GlobalObjectRef>(env, env->GetObjectClass(context), thiz);
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* inputValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(input), input);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* inputValueRef) -> ValueRef* {
|
||||
return globalObject->jsonParse()->call(state, globalObject->json(), 1, &inputValueRef);
|
||||
}, globalObjectRef->get(), inputValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
static jobject callPromiseBuiltinFunction(JNIEnv* env, jobject thiz, jobject context, jobject iterable,
|
||||
ValueRef* (*closure)(ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef))
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(iterable, "JavaScriptValue");
|
||||
|
||||
auto globalObjectRef = getPersistentPointerFromJava<GlobalObjectRef>(env, env->GetObjectClass(context), thiz);
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* iterableValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(iterable), iterable);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), closure, globalObjectRef->get(), iterableValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseAll(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseAll()->call(state, globalObject->promise(), 1, &iterableValueRef);
|
||||
});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseAllSettled(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseAllSettled()->call(state, globalObject->promise(), 1, &iterableValueRef);
|
||||
});
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseAny(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseAny()->call(state, globalObject->promise(), 1, &iterableValueRef);
|
||||
});
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseRace(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseRace()->call(state, globalObject->promise(), 1, &iterableValueRef);
|
||||
});
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseReject(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseReject()->call(state, globalObject->promise(), 1, &iterableValueRef);
|
||||
});
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptGlobalObject_promiseResolve(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject iterable)
|
||||
{
|
||||
return callPromiseBuiltinFunction(env, thiz, context, iterable, [](ExecutionStateRef* state, GlobalObjectRef* globalObject, ValueRef* iterableValueRef) -> ValueRef* {
|
||||
return globalObject->promiseResolve()->call(state, globalObject->promise(), 1,
|
||||
&iterableValueRef);
|
||||
});
|
||||
}
|
||||
319
build/android/escargot/src/main/cpp/JNIGlobals.cpp
Normal file
319
build/android/escargot/src/main/cpp/JNIGlobals.cpp
Normal file
|
|
@ -0,0 +1,319 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
static void gcCallback(void* data)
|
||||
{
|
||||
auto env = fetchJNIEnvFromCallback();
|
||||
if (!env) {
|
||||
LOGE("failed to fetch env from gc event callback");
|
||||
return;
|
||||
}
|
||||
if (!env->ExceptionCheck()) {
|
||||
env->PushLocalFrame(32);
|
||||
jclass clazz = env->FindClass("com/samsung/lwe/escargot/NativePointerHolder");
|
||||
jmethodID mId = env->GetStaticMethodID(clazz, "cleanUp", "()V");
|
||||
env->CallStaticVoidMethod(clazz, mId);
|
||||
env->PopLocalFrame(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static OptionalRef<StringRef> builtinHelperFileRead(OptionalRef<ExecutionStateRef> state, const char* fileName, const char* builtinName)
|
||||
{
|
||||
FILE* fp = fopen(fileName, "r");
|
||||
if (fp) {
|
||||
StringRef* src = StringRef::emptyString();
|
||||
std::string utf8Str;
|
||||
std::basic_string<unsigned char, std::char_traits<unsigned char>> str;
|
||||
char buf[512];
|
||||
bool hasNonLatin1Content = false;
|
||||
size_t readLen;
|
||||
while ((readLen = fread(buf, 1, sizeof buf, fp))) {
|
||||
if (!hasNonLatin1Content) {
|
||||
for (size_t i = 0; i < readLen; i++) {
|
||||
unsigned char ch = buf[i];
|
||||
if (ch & 0x80) {
|
||||
// check non-latin1 character
|
||||
hasNonLatin1Content = true;
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
break;
|
||||
}
|
||||
str += ch;
|
||||
}
|
||||
} else {
|
||||
utf8Str.append(buf, readLen);
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
if (StringRef::isCompressibleStringEnabled()) {
|
||||
if (state) {
|
||||
if (hasNonLatin1Content) {
|
||||
src = StringRef::createFromUTF8ToCompressibleString(state->context()->vmInstance(), utf8Str.data(), utf8Str.length(), false);
|
||||
} else {
|
||||
src = StringRef::createFromLatin1ToCompressibleString(state->context()->vmInstance(), str.data(), str.length());
|
||||
}
|
||||
} else {
|
||||
if (hasNonLatin1Content) {
|
||||
src = StringRef::createFromUTF8(utf8Str.data(), utf8Str.length(), false);
|
||||
} else {
|
||||
src = StringRef::createFromLatin1(str.data(), str.length());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hasNonLatin1Content) {
|
||||
src = StringRef::createFromUTF8(utf8Str.data(), utf8Str.length(), false);
|
||||
} else {
|
||||
src = StringRef::createFromLatin1(str.data(), str.length());
|
||||
}
|
||||
}
|
||||
return src;
|
||||
} else {
|
||||
if (state) {
|
||||
const size_t maxNameLength = 980;
|
||||
if ((strnlen(builtinName, maxNameLength) + strnlen(fileName, maxNameLength)) < maxNameLength) {
|
||||
char msg[1024];
|
||||
snprintf(msg, sizeof(msg), "GlobalObject.%s: cannot open file %s", builtinName, fileName);
|
||||
state->throwException(URIErrorObjectRef::create(state.get(), StringRef::createFromUTF8(msg, strnlen(msg, sizeof msg))));
|
||||
} else {
|
||||
state->throwException(URIErrorObjectRef::create(state.get(), StringRef::createFromASCII("invalid file name")));
|
||||
}
|
||||
} else {
|
||||
LOGE("%s", fileName);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
class ShellPlatform : public PlatformRef {
|
||||
public:
|
||||
bool m_canBlock;
|
||||
|
||||
ShellPlatform()
|
||||
: m_canBlock(true)
|
||||
{
|
||||
}
|
||||
|
||||
void setCanBlock(bool b)
|
||||
{
|
||||
m_canBlock = b;
|
||||
}
|
||||
|
||||
virtual void markJSJobEnqueued(ContextRef* relatedContext) override
|
||||
{
|
||||
// ignore. we always check pending job after eval script
|
||||
}
|
||||
|
||||
virtual void markJSJobFromAnotherThreadExists(ContextRef* relatedContext) override
|
||||
{
|
||||
// ignore. we always check pending job after eval script
|
||||
}
|
||||
|
||||
virtual LoadModuleResult onLoadModule(ContextRef* relatedContext, ScriptRef* whereRequestFrom, StringRef* moduleSrc, ModuleType type) override
|
||||
{
|
||||
std::string referrerPath = whereRequestFrom->src()->toStdUTF8String();
|
||||
auto& loadedModules = *reinterpret_cast<std::vector<std::tuple<std::string, ContextRef*, PersistentRefHolder<ScriptRef>>>*>(threadLocalCustomData());
|
||||
|
||||
for (size_t i = 0; i < loadedModules.size(); i++) {
|
||||
if (std::get<2>(loadedModules[i]) == whereRequestFrom) {
|
||||
referrerPath = std::get<0>(loadedModules[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string absPath = absolutePath(referrerPath, moduleSrc->toStdUTF8String());
|
||||
if (absPath.length() == 0) {
|
||||
std::string s = "Error reading : " + moduleSrc->toStdUTF8String();
|
||||
return LoadModuleResult(ErrorObjectRef::Code::None, StringRef::createFromUTF8(s.data(), s.length()));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < loadedModules.size(); i++) {
|
||||
if (std::get<0>(loadedModules[i]) == absPath && std::get<1>(loadedModules[i]) == relatedContext) {
|
||||
return LoadModuleResult(std::get<2>(loadedModules[i]));
|
||||
}
|
||||
}
|
||||
|
||||
OptionalRef<StringRef> source = builtinHelperFileRead(nullptr, absPath.data(), "");
|
||||
if (!source) {
|
||||
std::string s = "Error reading : " + absPath;
|
||||
return LoadModuleResult(ErrorObjectRef::Code::None, StringRef::createFromUTF8(s.data(), s.length()));
|
||||
}
|
||||
|
||||
ScriptParserRef::InitializeScriptResult parseResult;
|
||||
StringRef* srcName = StringRef::createFromUTF8(absPath.data(), absPath.size());
|
||||
|
||||
if (type == ModuleJSON) {
|
||||
parseResult = relatedContext->scriptParser()->initializeJSONModule(source.value(), srcName);
|
||||
} else {
|
||||
parseResult = relatedContext->scriptParser()->initializeScript(source.value(), srcName, true);
|
||||
}
|
||||
|
||||
if (!parseResult.isSuccessful()) {
|
||||
return LoadModuleResult(parseResult.parseErrorCode, parseResult.parseErrorMessage);
|
||||
}
|
||||
|
||||
return LoadModuleResult(parseResult.script.get());
|
||||
}
|
||||
|
||||
virtual void didLoadModule(ContextRef* relatedContext, OptionalRef<ScriptRef> referrer, ScriptRef* loadedModule) override
|
||||
{
|
||||
std::string path;
|
||||
if (referrer && loadedModule->src()->length() && loadedModule->src()->charAt(0) != '/') {
|
||||
path = absolutePath(referrer->src()->toStdUTF8String(), loadedModule->src()->toStdUTF8String());
|
||||
} else {
|
||||
path = absolutePath(loadedModule->src()->toStdUTF8String());
|
||||
}
|
||||
auto& loadedModules = *reinterpret_cast<std::vector<std::tuple<std::string, ContextRef*, PersistentRefHolder<ScriptRef>>>*>(threadLocalCustomData());
|
||||
loadedModules.push_back(std::make_tuple(path, relatedContext, PersistentRefHolder<ScriptRef>(loadedModule)));
|
||||
}
|
||||
|
||||
virtual void hostImportModuleDynamically(ContextRef* relatedContext, ScriptRef* referrer, StringRef* src, ModuleType type, PromiseObjectRef* promise) override
|
||||
{
|
||||
LoadModuleResult loadedModuleResult = onLoadModule(relatedContext, referrer, src, type);
|
||||
notifyHostImportModuleDynamicallyResult(relatedContext, referrer, src, promise, loadedModuleResult);
|
||||
}
|
||||
|
||||
virtual bool canBlockExecution(ContextRef* relatedContext) override
|
||||
{
|
||||
return m_canBlock;
|
||||
}
|
||||
|
||||
virtual void* allocateThreadLocalCustomData() override
|
||||
{
|
||||
return new std::vector<std::tuple<std::string /* abs path */, ContextRef*, PersistentRefHolder<ScriptRef>>>();
|
||||
}
|
||||
|
||||
virtual void deallocateThreadLocalCustomData() override
|
||||
{
|
||||
delete reinterpret_cast<std::vector<std::tuple<std::string, ContextRef*, PersistentRefHolder<ScriptRef>>>*>(threadLocalCustomData());
|
||||
}
|
||||
|
||||
private:
|
||||
std::string dirnameOf(const std::string& fname)
|
||||
{
|
||||
size_t pos = fname.find_last_of("/");
|
||||
if (std::string::npos == pos) {
|
||||
pos = fname.find_last_of("\\/");
|
||||
}
|
||||
return (std::string::npos == pos)
|
||||
? ""
|
||||
: fname.substr(0, pos);
|
||||
}
|
||||
|
||||
std::string absolutePath(const std::string& referrerPath, const std::string& src)
|
||||
{
|
||||
std::string utf8MayRelativePath = dirnameOf(referrerPath) + "/" + src;
|
||||
auto absPath = realpath(utf8MayRelativePath.data(), nullptr);
|
||||
if (!absPath) {
|
||||
return std::string();
|
||||
}
|
||||
std::string utf8AbsolutePath = absPath;
|
||||
free(absPath);
|
||||
|
||||
return utf8AbsolutePath;
|
||||
}
|
||||
|
||||
std::string absolutePath(const std::string& src)
|
||||
{
|
||||
auto absPath = realpath(src.data(), nullptr);
|
||||
if (!absPath) {
|
||||
return std::string();
|
||||
}
|
||||
std::string utf8AbsolutePath = absPath;
|
||||
free(absPath);
|
||||
|
||||
return utf8AbsolutePath;
|
||||
}
|
||||
};
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_initializeGlobals(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
if (!Globals::isInitialized()) {
|
||||
Globals::initialize(new ShellPlatform());
|
||||
Memory::addGCEventListener(Memory::MARK_START, gcCallback, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_finalizeGlobals(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
if (Globals::isInitialized()) {
|
||||
// java object cleanup
|
||||
gcCallback(nullptr);
|
||||
|
||||
Memory::removeGCEventListener(Memory::MARK_START, gcCallback, nullptr);
|
||||
Globals::finalize();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_initializeThread(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
if (!Globals::isInitialized()) {
|
||||
Globals::initializeThread();
|
||||
}
|
||||
}
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_finalizeThread(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
if (Globals::isInitialized()) {
|
||||
Globals::finalizeThread();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_isInitialized(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
return Globals::isInitialized();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_version(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
std::string version = Globals::version();
|
||||
std::basic_string<uint16_t> u16Version;
|
||||
|
||||
for (auto c: version) {
|
||||
u16Version.push_back(c);
|
||||
}
|
||||
|
||||
return env->NewString(u16Version.data(), u16Version.length());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_samsung_lwe_escargot_Globals_buildDate(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
std::string version = Globals::buildDate();
|
||||
std::basic_string<uint16_t> u16Version;
|
||||
|
||||
for (auto c: version) {
|
||||
u16Version.push_back(c);
|
||||
}
|
||||
|
||||
return env->NewString(u16Version.data(), u16Version.length());
|
||||
}
|
||||
48
build/android/escargot/src/main/cpp/JNIMemory.cpp
Normal file
48
build/android/escargot/src/main/cpp/JNIMemory.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Memory_gc(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
Memory::gc();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_samsung_lwe_escargot_Memory_heapSize(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
return Memory::heapSize();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_samsung_lwe_escargot_Memory_totalSize(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
return Memory::totalSize();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_Memory_setGCFrequency(JNIEnv* env, jclass clazz, jint value)
|
||||
{
|
||||
Memory::setGCFrequency(value);
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_NativePointerHolder_releaseNativePointerMemory(JNIEnv* env,
|
||||
jclass clazz, jlong pointer)
|
||||
{
|
||||
uint64_t ptrInNumber = (uint64_t)(pointer);
|
||||
if (ptrInNumber > g_nonPointerValueLast && !(pointer & 1)) {
|
||||
PersistentRefHolder<void>* pRef = reinterpret_cast<PersistentRefHolder<void>*>(pointer);
|
||||
delete pRef;
|
||||
}
|
||||
}
|
||||
173
build/android/escargot/src/main/cpp/JNIObject.cpp
Normal file
173
build/android/escargot/src/main/cpp/JNIObject.cpp
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_create(JNIEnv* env, jclass clazz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state) -> ValueRef* {
|
||||
return ObjectRef::create(state);
|
||||
});
|
||||
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
return createJavaObjectFromValue(env, evaluatorResult.result->asObject());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_get(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobject propertyName)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(propertyName, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
ValueRef* propertyNameValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(propertyName), propertyName);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ObjectRef* thisValueRef, ValueRef* propertyNameValueRef) -> ValueRef* {
|
||||
return thisValueRef->get(state, propertyNameValueRef);
|
||||
}, thisValueRef, propertyNameValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_set(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobject propertyName, jobject value)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(propertyName, "JavaScriptValue");
|
||||
THROW_NPE_RETURN_NULL(value, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
ValueRef* propertyNameValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(propertyName), propertyName);
|
||||
ValueRef* valueRef = unwrapValueRefFromValue(env, env->GetObjectClass(value), value);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ObjectRef* thisValueRef, ValueRef* propertyNameValueRef, ValueRef* valueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->set(state, propertyNameValueRef, valueRef));
|
||||
}, thisValueRef, propertyNameValueRef, valueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_defineDataProperty(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject propertyName,
|
||||
jobject value,
|
||||
jboolean isWritable,
|
||||
jboolean isEnumerable,
|
||||
jboolean isConfigurable)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(propertyName, "JavaScriptValue");
|
||||
THROW_NPE_RETURN_NULL(value, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
ValueRef* propertyNameValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(propertyName), propertyName);
|
||||
ValueRef* valueRef = unwrapValueRefFromValue(env, env->GetObjectClass(value), value);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ObjectRef* thisValueRef, ValueRef* propertyNameValueRef, ValueRef* valueRef,
|
||||
jboolean isWritable,
|
||||
jboolean isEnumerable,
|
||||
jboolean isConfigurable) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->defineDataProperty(state, propertyNameValueRef, valueRef, isWritable, isEnumerable, isConfigurable));
|
||||
}, thisValueRef, propertyNameValueRef, valueRef, isWritable, isEnumerable, isConfigurable);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_getOwnProperty(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject propertyName)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(propertyName, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
ValueRef* propertyNameValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(propertyName), propertyName);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ObjectRef* thisValueRef, ValueRef* propertyNameValueRef) -> ValueRef* {
|
||||
return thisValueRef->getOwnProperty(state, propertyNameValueRef);
|
||||
}, thisValueRef, propertyNameValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_setExtraData(JNIEnv* env, jobject thiz,
|
||||
jobject object)
|
||||
{
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
jobject extraData = nullptr;
|
||||
|
||||
if (object) {
|
||||
auto classOptional = env->GetObjectClass(object);
|
||||
auto methodIsPresent = env->GetMethodID(classOptional, "isPresent", "()Z");
|
||||
if (env->CallBooleanMethod(object, methodIsPresent)) {
|
||||
auto methodGet = env->GetMethodID(classOptional, "get", "()Ljava/lang/Object;");
|
||||
jboolean isSucceed;
|
||||
extraData = env->CallObjectMethod(object, methodGet);
|
||||
extraData = env->NewGlobalRef(extraData);
|
||||
}
|
||||
}
|
||||
|
||||
ensureScriptObjectExtraData(thisValueRef)->userData = extraData;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptObject_extraData(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asObject();
|
||||
jobject extraData = nullptr;
|
||||
if (thisValueRef->extraData()) {
|
||||
extraData = ensureScriptObjectExtraData(thisValueRef)->userData;
|
||||
}
|
||||
|
||||
jclass optionalClazz = env->FindClass("java/util/Optional");
|
||||
if (extraData) {
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "of",
|
||||
"(Ljava/lang/Object;)Ljava/util/Optional;"),
|
||||
extraData);
|
||||
} else {
|
||||
return env->CallStaticObjectMethod(optionalClazz,
|
||||
env->GetStaticMethodID(optionalClazz, "empty",
|
||||
"()Ljava/util/Optional;"));
|
||||
}
|
||||
}
|
||||
172
build/android/escargot/src/main/cpp/JNIPromiseObject.cpp
Normal file
172
build/android/escargot/src/main/cpp/JNIPromiseObject.cpp
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_create(JNIEnv* env, jclass clazz,
|
||||
jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state) -> ValueRef* {
|
||||
return PromiseObjectRef::create(state);
|
||||
});
|
||||
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
return createJavaObjectFromValue(env, evaluatorResult.result->asPromiseObject());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_state(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
|
||||
jclass enumClass = env->FindClass(
|
||||
"com/samsung/lwe/escargot/JavaScriptPromiseObject$PromiseState");
|
||||
jfieldID enumFieldID;
|
||||
PromiseObjectRef::PromiseState state = thisValueRef->state();
|
||||
if (state == PromiseObjectRef::Pending) {
|
||||
enumFieldID = env->GetStaticFieldID(enumClass, "Pending",
|
||||
"Lcom/samsung/lwe/escargot/JavaScriptPromiseObject$PromiseState;");
|
||||
} else if (state == PromiseObjectRef::FulFilled) {
|
||||
enumFieldID = env->GetStaticFieldID(enumClass, "FulFilled",
|
||||
"Lcom/samsung/lwe/escargot/JavaScriptPromiseObject$PromiseState;");
|
||||
} else {
|
||||
enumFieldID = env->GetStaticFieldID(enumClass, "Rejected",
|
||||
"Lcom/samsung/lwe/escargot/JavaScriptPromiseObject$PromiseState;");
|
||||
}
|
||||
return env->GetStaticObjectField(enumClass, enumFieldID);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_promiseResult(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
return createJavaObjectFromValue(env, thisValueRef->promiseResult());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_then__Lcom_samsung_lwe_escargot_Context_2Lcom_samsung_lwe_escargot_JavaScriptValue_2(
|
||||
JNIEnv* env, jobject thiz, jobject context, jobject handler)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(handler, "JavaScriptValue");
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
ValueRef* handlerRef = unwrapValueRefFromValue(env, env->GetObjectClass(handler), handler);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, PromiseObjectRef* promiseObject, ValueRef* handlerRef) -> ValueRef* {
|
||||
return promiseObject->then(state, handlerRef);
|
||||
}, thisValueRef, handlerRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_then__Lcom_samsung_lwe_escargot_Context_2Lcom_samsung_lwe_escargot_JavaScriptValue_2Lcom_samsung_lwe_escargot_JavaScriptValue_2(
|
||||
JNIEnv* env, jobject thiz, jobject context, jobject onFulfilled, jobject onRejected)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(onFulfilled, "JavaScriptValue");
|
||||
THROW_NPE_RETURN_NULL(onRejected, "JavaScriptValue");
|
||||
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
ValueRef* onFulfilledRef = unwrapValueRefFromValue(env, env->GetObjectClass(onFulfilled), onFulfilled);
|
||||
ValueRef* onRejectedRef = unwrapValueRefFromValue(env, env->GetObjectClass(onRejected), onRejected);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, PromiseObjectRef* promiseObject, ValueRef* onFulfilledRef, ValueRef* onRejectedRef) -> ValueRef* {
|
||||
return promiseObject->then(state, onFulfilledRef, onRejectedRef);
|
||||
}, thisValueRef, onFulfilledRef, onRejectedRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_catchOperation(JNIEnv* env, jobject thiz,
|
||||
jobject context,
|
||||
jobject handler)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(handler, "JavaScriptValue");
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
ValueRef* handlerRef = unwrapValueRefFromValue(env, env->GetObjectClass(handler), handler);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, PromiseObjectRef* promiseObject, ValueRef* handlerRef) -> ValueRef* {
|
||||
return promiseObject->catchOperation(state, handlerRef);
|
||||
}, thisValueRef, handlerRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_fulfill(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject value)
|
||||
{
|
||||
THROW_NPE_RETURN_VOID(context, "Context");
|
||||
THROW_NPE_RETURN_VOID(value, "JavaScriptValue");
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
ValueRef* valueRef = unwrapValueRefFromValue(env, env->GetObjectClass(value), value);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, PromiseObjectRef* promiseObject, ValueRef* valueRef) -> ValueRef* {
|
||||
promiseObject->fulfill(state, valueRef);
|
||||
return ValueRef::createUndefined();
|
||||
}, thisValueRef, valueRef);
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_reject(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject reason)
|
||||
{
|
||||
THROW_NPE_RETURN_VOID(context, "Context");
|
||||
THROW_NPE_RETURN_VOID(reason, "JavaScriptValue");
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
ValueRef* reasonRef = unwrapValueRefFromValue(env, env->GetObjectClass(reason), reason);
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, PromiseObjectRef* promiseObject, ValueRef* reasonRef) -> ValueRef* {
|
||||
promiseObject->reject(state, reasonRef);
|
||||
return ValueRef::createUndefined();
|
||||
}, thisValueRef, reasonRef);
|
||||
assert(evaluatorResult.isSuccessful());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptPromiseObject_hasHandler(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
PromiseObjectRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asPromiseObject();
|
||||
return thisValueRef->hasResolveHandlers() || thisValueRef->hasRejectHandlers();
|
||||
}
|
||||
35
build/android/escargot/src/main/cpp/JNIString.cpp
Normal file
35
build/android/escargot/src/main/cpp/JNIString.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptString_create(JNIEnv* env, jclass clazz, jstring value)
|
||||
{
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptString", createJSStringFromJava(env, value));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptString_toJavaString(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
StringRef* string = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asString();
|
||||
return createJavaStringFromJS(env, string);
|
||||
}
|
||||
79
build/android/escargot/src/main/cpp/JNISymbol.cpp
Normal file
79
build/android/escargot/src/main/cpp/JNISymbol.cpp
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptSymbol_create(JNIEnv* env, jclass clazz, jobject value)
|
||||
{
|
||||
OptionalRef<StringRef> descString;
|
||||
if (value) {
|
||||
auto classOptionalJavaScriptString = env->GetObjectClass(value);
|
||||
auto methodIsPresent = env->GetMethodID(classOptionalJavaScriptString, "isPresent", "()Z");
|
||||
if (env->CallBooleanMethod(value, methodIsPresent)) {
|
||||
auto methodGet = env->GetMethodID(classOptionalJavaScriptString, "get", "()Ljava/lang/Object;");
|
||||
jboolean isSucceed;
|
||||
jobject javaObjectValue = env->CallObjectMethod(value, methodGet);
|
||||
descString = unwrapValueRefFromValue(env, env->GetObjectClass(javaObjectValue), javaObjectValue)->asString();
|
||||
}
|
||||
}
|
||||
|
||||
return createJavaValueObject(env, "com/samsung/lwe/escargot/JavaScriptSymbol", SymbolRef::create(descString));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptSymbol_fromGlobalSymbolRegistry(JNIEnv* env, jclass clazz,
|
||||
jobject vm,
|
||||
jobject stringKey)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(vm, "VMInstance");
|
||||
THROW_NPE_RETURN_NULL(stringKey, "JavaScriptString");
|
||||
|
||||
auto ptr = getPersistentPointerFromJava<VMInstanceRef>(env, env->GetObjectClass(vm), vm);
|
||||
auto key = unwrapValueRefFromValue(env, env->GetObjectClass(stringKey), stringKey);
|
||||
|
||||
auto symbol = SymbolRef::fromGlobalSymbolRegistry(ptr->get(), key->asString());
|
||||
return createJavaObjectFromValue(env, symbol);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptSymbol_descriptionString(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto desc = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asSymbol()->descriptionString();
|
||||
return createJavaObjectFromValue(env, desc);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptSymbol_descriptionValue(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto desc = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asSymbol()->descriptionValue();
|
||||
return createJavaObjectFromValue(env, desc);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptSymbol_symbolDescriptiveString(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto desc = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->asSymbol()->symbolDescriptiveString();
|
||||
return createJavaObjectFromValue(env, desc);
|
||||
}
|
||||
56
build/android/escargot/src/main/cpp/JNIVMInstance.cpp
Normal file
56
build/android/escargot/src/main/cpp/JNIVMInstance.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_VMInstance_create(JNIEnv *env, jclass clazz, jobject locale,
|
||||
jobject timezone)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(locale, "Optional<String>");
|
||||
THROW_NPE_RETURN_NULL(timezone, "Optional<String>");
|
||||
|
||||
std::string localeString = fetchStringFromJavaOptionalString(env, locale);
|
||||
std::string timezoneString = fetchStringFromJavaOptionalString(env, timezone);
|
||||
|
||||
auto vmRef = VMInstanceRef::create(localeString.length() ? localeString.data() : nullptr,
|
||||
timezoneString.length() ? timezoneString.data() : nullptr);
|
||||
return createJavaObject(env, vmRef.get());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_VMInstance_hasPendingJob(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto vmPtr = getPersistentPointerFromJava<VMInstanceRef>(env, env->GetObjectClass(thiz),
|
||||
thiz);
|
||||
return vmPtr->get()->hasPendingJob();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_samsung_lwe_escargot_VMInstance_executePendingJob(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
auto vmPtr = getPersistentPointerFromJava<VMInstanceRef>(env, env->GetObjectClass(thiz),
|
||||
thiz);
|
||||
if (vmPtr->get()->hasPendingJob()) {
|
||||
vmPtr->get()->executePendingJob();
|
||||
}
|
||||
}
|
||||
500
build/android/escargot/src/main/cpp/JNIValue.cpp
Normal file
500
build/android/escargot/src/main/cpp/JNIValue.cpp
Normal file
|
|
@ -0,0 +1,500 @@
|
|||
/*
|
||||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
||||
* USA
|
||||
*/
|
||||
|
||||
#include "EscargotJNI.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_createUndefined(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, ValueRef::createUndefined());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_createNull(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, ValueRef::createNull());
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_create__I(JNIEnv* env, jclass clazz, jint value)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, ValueRef::create(value));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_create__D(JNIEnv* env, jclass clazz, jdouble value)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, ValueRef::create(value));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_create__Z(JNIEnv* env, jclass clazz, jboolean value)
|
||||
{
|
||||
return createJavaValueObject(env, clazz, ValueRef::create(static_cast<bool>(value)));
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isUndefined(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isUndefined();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isNull(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isNull();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isUndefinedOrNull(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isUndefinedOrNull();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isNumber(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isNumber();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isInt32(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isInt32();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isBoolean(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isBoolean();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isTrue(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isTrue();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isFalse(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isFalse();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isString(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isString();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isSymbol(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isSymbol();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isBigInt(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isBigInt();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isCallable(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isCallable();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isObject();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isArrayObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isArrayObject();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isFunctionObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isFunctionObject();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isPromiseObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isPromiseObject();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_isErrorObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
return unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz)->isErrorObject();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asBoolean(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, Boolean);
|
||||
return ref->asBoolean();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asInt32(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, Int32);
|
||||
return ref->asInt32();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jdouble JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asNumber(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, Number);
|
||||
return ref->asNumber();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptString(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, String);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptSymbol(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, Symbol);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptBigInt(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, BigInt);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, Object);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptArrayObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, ArrayObject);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptFunctionObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, FunctionObject);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptPromiseObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, PromiseObject);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_asScriptErrorObject(JNIEnv* env, jobject thiz)
|
||||
{
|
||||
ValueRef* ref = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
THROW_CAST_EXCEPTION_IF_NEEDS(env, ref, ErrorObject);
|
||||
return thiz;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toString(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return thisValueRef->toString(state);
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toNumber(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->toNumber(state));
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorDoubleResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toInteger(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->toInteger(state));
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorDoubleResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toInt32(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->toInt32(state));
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorIntegerResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toBoolean(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->toBoolean(state));
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_toObject(JNIEnv* env, jobject thiz, jobject context)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef) -> ValueRef* {
|
||||
return thisValueRef->toObject(state);
|
||||
}, thisValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_abstractEqualsTo(JNIEnv* env, jobject thiz,
|
||||
jobject context, jobject other)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(other, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
ValueRef* otherValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(other), other);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef, ValueRef* otherValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->abstractEqualsTo(state, otherValueRef));
|
||||
}, thisValueRef, otherValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_equalsTo(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobject other)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(other, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
ValueRef* otherValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(other), other);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef, ValueRef* otherValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->equalsTo(state, otherValueRef));
|
||||
}, thisValueRef, otherValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_instanceOf(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobject other)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(other, "JavaScriptValue");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
ValueRef* otherValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(other), other);
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(), [](ExecutionStateRef* state, ValueRef* thisValueRef, ValueRef* otherValueRef) -> ValueRef* {
|
||||
return ValueRef::create(thisValueRef->instanceOf(state, otherValueRef));
|
||||
}, thisValueRef, otherValueRef);
|
||||
|
||||
return createOptionalValueFromEvaluatorBooleanResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_call(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobject receiver, jobjectArray argv)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(receiver, "JavaScriptValue");
|
||||
THROW_NPE_RETURN_NULL(argv, "JavaScriptValue[]");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
ValueRef* receiverValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(receiver), receiver);
|
||||
|
||||
auto argvLength = env->GetArrayLength(argv);
|
||||
ValueRef** argVector = reinterpret_cast<ValueRef**>(Memory::gcMalloc(argvLength * sizeof(ValueRef*)));
|
||||
|
||||
for (jsize i = 0; i < argvLength; i++) {
|
||||
jobject e = env->GetObjectArrayElement(argv, i);
|
||||
argVector[i] = unwrapValueRefFromValue(env, env->GetObjectClass(e), e);
|
||||
env->DeleteLocalRef(e);
|
||||
}
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(),
|
||||
[](ExecutionStateRef* state, ValueRef* thisValueRef, ValueRef* receiverValueRef, ValueRef** argVector, int argvLength) -> ValueRef* {
|
||||
return thisValueRef->call(state, receiverValueRef, argvLength, argVector);
|
||||
}, thisValueRef, receiverValueRef, argVector, argvLength);
|
||||
|
||||
Memory::gcFree(argVector);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_com_samsung_lwe_escargot_JavaScriptValue_construct(JNIEnv* env, jobject thiz, jobject context,
|
||||
jobjectArray argv)
|
||||
{
|
||||
THROW_NPE_RETURN_NULL(context, "Context");
|
||||
THROW_NPE_RETURN_NULL(argv, "JavaScriptValue[]");
|
||||
|
||||
auto contextRef = getPersistentPointerFromJava<ContextRef>(env, env->GetObjectClass(context), context);
|
||||
ValueRef* thisValueRef = unwrapValueRefFromValue(env, env->GetObjectClass(thiz), thiz);
|
||||
|
||||
auto argvLength = env->GetArrayLength(argv);
|
||||
ValueRef** argVector = reinterpret_cast<ValueRef**>(Memory::gcMalloc(argvLength * sizeof(ValueRef*)));
|
||||
|
||||
for (jsize i = 0; i < argvLength; i++) {
|
||||
jobject e = env->GetObjectArrayElement(argv, i);
|
||||
argVector[i] = unwrapValueRefFromValue(env, env->GetObjectClass(e), e);
|
||||
env->DeleteLocalRef(e);
|
||||
}
|
||||
|
||||
auto evaluatorResult = ScriptEvaluator::execute(contextRef->get(),
|
||||
[](ExecutionStateRef* state, ValueRef* thisValueRef, ValueRef** argVector, int argvLength) -> ValueRef* {
|
||||
return thisValueRef->construct(state, argvLength, argVector);
|
||||
}, thisValueRef, argVector, argvLength);
|
||||
|
||||
Memory::gcFree(argVector);
|
||||
|
||||
return createOptionalValueFromEvaluatorJavaScriptValueResult(env, context, contextRef->get(),
|
||||
evaluatorResult);
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -9,10 +9,11 @@ final public class Bridge {
|
|||
|
||||
public abstract static class Adapter {
|
||||
/**
|
||||
* @param context Context from callee
|
||||
* @param data the data parameter contains value when call this function from JavaScript
|
||||
* @return if want to return data to JavaScript callback, you can return value from this callback.
|
||||
*/
|
||||
public abstract Optional<JavaScriptValue> callback(Optional<JavaScriptValue> data);
|
||||
public abstract Optional<JavaScriptValue> callback(Context context, Optional<JavaScriptValue> data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public class Context extends NativePointerHolder {
|
|||
return lastThrownException;
|
||||
}
|
||||
public native JavaScriptGlobalObject getGlobalObject();
|
||||
public native boolean throwException(JavaScriptValue exception);
|
||||
|
||||
protected Optional<JavaScriptValue> m_lastThrownException = Optional.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,19 @@ final public class Evaluator {
|
|||
private Evaluator() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param source
|
||||
* @param sourceFileName
|
||||
* @return return result if eval was successful
|
||||
*/
|
||||
static public Optional<JavaScriptValue> evalScript(Context context, String source, String sourceFileName)
|
||||
{
|
||||
return evalScript(context, source, sourceFileName, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param source
|
||||
|
|
@ -14,5 +27,20 @@ final public class Evaluator {
|
|||
* @param shouldPrintScriptResult
|
||||
* @return return result if eval was successful
|
||||
*/
|
||||
static native public Optional<JavaScriptValue> evalScript(Context context, String source, String sourceFileName, boolean shouldPrintScriptResult);
|
||||
static public Optional<JavaScriptValue> evalScript(Context context, String source, String sourceFileName,
|
||||
boolean shouldPrintScriptResult)
|
||||
{
|
||||
return evalScript(context, source, sourceFileName, shouldPrintScriptResult, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* @param source
|
||||
* @param sourceFileName
|
||||
* @param shouldPrintScriptResult
|
||||
* @param shouldExecutePendingJobsAtEnd
|
||||
* @return return result if eval was successful
|
||||
*/
|
||||
static native public Optional<JavaScriptValue> evalScript(Context context, String source, String sourceFileName,
|
||||
boolean shouldPrintScriptResult, boolean shouldExecutePendingJobsAtEnd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,31 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptArrayObject extends JavaScriptObject {
|
||||
protected JavaScriptArrayObject(long nativePointer)
|
||||
{
|
||||
super(nativePointer);
|
||||
}
|
||||
static public native JavaScriptArrayObject create(Context context);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param from
|
||||
* @return
|
||||
*/
|
||||
static public Optional<JavaScriptArrayObject> create(Context context, JavaScriptValue[] from)
|
||||
{
|
||||
JavaScriptArrayObject ret = JavaScriptArrayObject.create(context);
|
||||
ret.setLength(context, from.length);
|
||||
for (int i = 0; i < from.length; i ++) {
|
||||
Optional<Boolean> b = ret.set(context, JavaScriptValue.create(i), from[i]);
|
||||
if (!b.isPresent() || !b.get())
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(ret);
|
||||
}
|
||||
public native long length(Context context);
|
||||
public native void setLength(Context context, long newLength);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptErrorObject extends JavaScriptObject {
|
||||
protected JavaScriptErrorObject(long nativePointer)
|
||||
{
|
||||
super(nativePointer);
|
||||
}
|
||||
|
||||
public enum ErrorKind {
|
||||
None,
|
||||
ReferenceError,
|
||||
TypeError,
|
||||
SyntaxError,
|
||||
RangeError,
|
||||
URIError,
|
||||
EvalError,
|
||||
AggregateError
|
||||
}
|
||||
static public native JavaScriptErrorObject create(Context context, ErrorKind kind, String message);
|
||||
public native Optional<JavaScriptString> stack(Context context);
|
||||
}
|
||||
|
|
@ -5,4 +5,5 @@ public class JavaScriptFunctionObject extends JavaScriptObject {
|
|||
{
|
||||
super(nativePointer);
|
||||
}
|
||||
public native Context context();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,4 +22,52 @@ public class JavaScriptGlobalObject extends JavaScriptObject {
|
|||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> jsonParse(Context context, JavaScriptValue input);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseAll(Context context, JavaScriptValue iterable);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseAllSettled(Context context, JavaScriptValue iterable);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseAny(Context context, JavaScriptValue iterable);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseRace(Context context, JavaScriptValue iterable);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseReject(Context context, JavaScriptValue iterable);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param iterable
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptValue> promiseResolve(Context context, JavaScriptValue iterable);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@ public class JavaScriptJavaCallbackFunctionObject extends JavaScriptFunctionObje
|
|||
public abstract static class Callback {
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param receiverValue
|
||||
* @param arguments
|
||||
* @return
|
||||
*/
|
||||
public abstract Optional<JavaScriptValue> callback(JavaScriptValue receiverValue, JavaScriptValue arguments[]);
|
||||
public abstract Optional<JavaScriptValue> callback(Context context, JavaScriptValue receiverValue, JavaScriptValue arguments[]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -54,4 +54,17 @@ public class JavaScriptObject extends JavaScriptValue {
|
|||
* @return JavaScriptValue or Optional.empty if there was a exception while executing getOwnProperty function
|
||||
*/
|
||||
public native Optional<JavaScriptValue> getOwnProperty(Context context, JavaScriptValue propertyName);
|
||||
|
||||
/**
|
||||
* store Java Object in JavaScriptObject
|
||||
* @param object
|
||||
*/
|
||||
public native void setExtraData(Optional<Object> object);
|
||||
|
||||
/**
|
||||
* returns stored Java object in JavaScriptObject
|
||||
* this function returns `Optional with Object` or `empty Optional`
|
||||
* @return
|
||||
*/
|
||||
public native Optional<Object> extraData();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
package com.samsung.lwe.escargot;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class JavaScriptPromiseObject extends JavaScriptObject {
|
||||
protected JavaScriptPromiseObject(long nativePointer)
|
||||
{
|
||||
super(nativePointer);
|
||||
}
|
||||
static public native JavaScriptPromiseObject create(Context context);
|
||||
|
||||
enum PromiseState {
|
||||
Pending,
|
||||
FulFilled,
|
||||
Rejected
|
||||
};
|
||||
public native PromiseState state();
|
||||
public native JavaScriptValue promiseResult();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param handler
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptObject> then(Context context, JavaScriptValue handler);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param onFulfilled
|
||||
* @param onRejected
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptObject> then(Context context, JavaScriptValue onFulfilled, JavaScriptValue onRejected);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param handler
|
||||
* @return
|
||||
*/
|
||||
public native Optional<JavaScriptObject> catchOperation(Context context, JavaScriptValue handler);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param value
|
||||
*/
|
||||
public native void fulfill(Context context, JavaScriptValue value);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param reason
|
||||
*/
|
||||
public native void reject(Context context, JavaScriptValue reason);
|
||||
|
||||
public native boolean hasHandler();
|
||||
}
|
||||
|
|
@ -5,5 +5,6 @@ public class JavaScriptString extends JavaScriptValue {
|
|||
{
|
||||
super(nativePointer, true);
|
||||
}
|
||||
native static public JavaScriptString create(String value);
|
||||
native public String toJavaString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,10 @@ public class JavaScriptSymbol extends JavaScriptValue {
|
|||
{
|
||||
super(nativePointer, true);
|
||||
}
|
||||
native public Optional<JavaScriptString> description();
|
||||
|
||||
native static public JavaScriptSymbol create(Optional<JavaScriptString> value);
|
||||
native public JavaScriptString descriptionString();
|
||||
native public JavaScriptValue descriptionValue();
|
||||
native public JavaScriptString symbolDescriptiveString();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ public class JavaScriptValue extends NativePointerHolder {
|
|||
native static public JavaScriptValue create(boolean value);
|
||||
native static public JavaScriptValue create(int value);
|
||||
native static public JavaScriptValue create(double value);
|
||||
native static public JavaScriptString create(String value);
|
||||
native static public JavaScriptSymbol create(Optional<JavaScriptString> value);
|
||||
|
||||
native public boolean isUndefined();
|
||||
native public boolean isNull();
|
||||
|
|
@ -36,10 +34,9 @@ public class JavaScriptValue extends NativePointerHolder {
|
|||
native public boolean isObject();
|
||||
native public boolean isArrayObject();
|
||||
native public boolean isFunctionObject();
|
||||
native public boolean isPromiseObject();
|
||||
native public boolean isErrorObject();
|
||||
|
||||
// as{ .. } methods don't check type is correct
|
||||
// if you want to use these as{ .. } methods
|
||||
// you must check type before use!
|
||||
native public boolean asBoolean();
|
||||
native public int asInt32();
|
||||
native public double asNumber();
|
||||
|
|
@ -49,6 +46,8 @@ public class JavaScriptValue extends NativePointerHolder {
|
|||
native public JavaScriptObject asScriptObject();
|
||||
native public JavaScriptArrayObject asScriptArrayObject();
|
||||
native public JavaScriptFunctionObject asScriptFunctionObject();
|
||||
native public JavaScriptPromiseObject asScriptPromiseObject();
|
||||
native public JavaScriptErrorObject asScriptErrorObject();
|
||||
|
||||
native public Optional<JavaScriptString> toString(Context context);
|
||||
native public Optional<Boolean> toBoolean(Context context);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package com.samsung.lwe.escargot.internal;
|
||||
|
||||
import com.samsung.lwe.escargot.JavaScriptValue;
|
||||
|
||||
public class JavaScriptRuntimeException extends RuntimeException {
|
||||
public JavaScriptRuntimeException(JavaScriptValue exception)
|
||||
{
|
||||
this.m_exception = exception;
|
||||
}
|
||||
|
||||
public JavaScriptValue exception() {
|
||||
return m_exception;
|
||||
}
|
||||
|
||||
private JavaScriptValue m_exception;
|
||||
}
|
||||
|
|
@ -0,0 +1,239 @@
|
|||
package com.samsung.lwe.escargot.util;
|
||||
|
||||
|
||||
import com.samsung.lwe.escargot.Context;
|
||||
import com.samsung.lwe.escargot.JavaScriptPromiseObject;
|
||||
import com.samsung.lwe.escargot.JavaScriptValue;
|
||||
import com.samsung.lwe.escargot.VMInstance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class MultiThreadExecutor {
|
||||
public static interface WorkerThreadEndNotifier {
|
||||
/**
|
||||
* called by worker thread before thread exiting
|
||||
* @param instance
|
||||
*/
|
||||
public abstract void notify(MultiThreadExecutor executor, ExecutorInstance instance);
|
||||
}
|
||||
|
||||
VMInstance m_vmInstance;
|
||||
Thread m_javaScriptThread;
|
||||
ArrayList<ExecutorInstance> m_activeInstances = new ArrayList<>();
|
||||
ArrayList<ExecutorInstance> m_endedInstances = new ArrayList<>();
|
||||
WorkerThreadEndNotifier m_workerThreadEndNotifier;
|
||||
|
||||
/**
|
||||
* init with current thread as JavaScript Thread
|
||||
* and manual threadEndNotifier
|
||||
* @param vmInstance
|
||||
*/
|
||||
public MultiThreadExecutor(VMInstance vmInstance)
|
||||
{
|
||||
this(vmInstance, (executor, instance) -> {
|
||||
}, Thread.currentThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* init with manual threadEndNotifier
|
||||
* @param vmInstance
|
||||
* @param javaScriptThread
|
||||
*/
|
||||
public MultiThreadExecutor(VMInstance vmInstance, Thread javaScriptThread)
|
||||
{
|
||||
this(vmInstance, (executor, instance) -> {
|
||||
}, javaScriptThread);
|
||||
}
|
||||
|
||||
/**
|
||||
* init with current thread as JavaScript Thread
|
||||
* and manual threadEndNotifier
|
||||
* @param vmInstance
|
||||
* @param threadEndNotifier
|
||||
*/
|
||||
public MultiThreadExecutor(VMInstance vmInstance, WorkerThreadEndNotifier threadEndNotifier)
|
||||
{
|
||||
this(vmInstance, threadEndNotifier, Thread.currentThread());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param vmInstance
|
||||
* @param threadEndNotifier
|
||||
* @param javaScriptThread
|
||||
*/
|
||||
public MultiThreadExecutor(VMInstance vmInstance, WorkerThreadEndNotifier threadEndNotifier, Thread javaScriptThread)
|
||||
{
|
||||
if (vmInstance == null || threadEndNotifier == null || javaScriptThread == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
m_javaScriptThread = javaScriptThread;
|
||||
m_vmInstance = vmInstance;
|
||||
m_workerThreadEndNotifier = threadEndNotifier;
|
||||
}
|
||||
|
||||
public static abstract class ResultBuilder {
|
||||
public abstract JavaScriptValue build(Context scriptContext, ResultBuilderContext builderContext);
|
||||
}
|
||||
|
||||
public static class ResultBuilderContext {
|
||||
private boolean m_wasSuccessful;
|
||||
private Object m_data;
|
||||
|
||||
public ResultBuilderContext(boolean wasSuccessful, Object data) {
|
||||
m_wasSuccessful = wasSuccessful;
|
||||
m_data = data;
|
||||
}
|
||||
|
||||
public Object data() {
|
||||
return m_data;
|
||||
}
|
||||
|
||||
public boolean wasSuccessful() {
|
||||
return m_wasSuccessful;
|
||||
}
|
||||
}
|
||||
public static abstract class Executor {
|
||||
public abstract ResultBuilderContext run();
|
||||
}
|
||||
|
||||
public static class ExecutorInstance {
|
||||
private Context m_context;
|
||||
private JavaScriptPromiseObject m_promise;
|
||||
private Thread m_thread;
|
||||
private ResultBuilderContext m_builderContext;
|
||||
private ResultBuilder m_resultBuilder;
|
||||
|
||||
private ExecutorInstance(Context context, JavaScriptPromiseObject promise,
|
||||
ResultBuilder resultBuilder)
|
||||
{
|
||||
this.m_context = context;
|
||||
this.m_promise = promise;
|
||||
this.m_resultBuilder = resultBuilder;
|
||||
}
|
||||
|
||||
public Context context() {
|
||||
return m_context;
|
||||
}
|
||||
|
||||
public JavaScriptPromiseObject promise() {
|
||||
return m_promise;
|
||||
}
|
||||
|
||||
public Thread thread() {
|
||||
return m_thread;
|
||||
}
|
||||
|
||||
public ResultBuilderContext builderContext() {
|
||||
return m_builderContext;
|
||||
}
|
||||
|
||||
public ResultBuilder resultBuilder() {
|
||||
return m_resultBuilder;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context
|
||||
* @param executor
|
||||
* @param resultBuilder
|
||||
* @return
|
||||
*/
|
||||
public ExecutorInstance startWorker(Context context, Executor executor, ResultBuilder resultBuilder)
|
||||
{
|
||||
if (Thread.currentThread() != m_javaScriptThread) {
|
||||
throw new RuntimeException("You should call this function on JavaScriptThread");
|
||||
}
|
||||
if (context == null || executor == null || resultBuilder == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
JavaScriptPromiseObject promise = JavaScriptPromiseObject.create(context);
|
||||
|
||||
ExecutorInstance instance = new ExecutorInstance(context, promise, resultBuilder);
|
||||
class ExecutorRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
instance.m_builderContext = executor.run();
|
||||
if (instance.m_builderContext == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
synchronized (m_endedInstances) {
|
||||
m_endedInstances.add(instance);
|
||||
}
|
||||
synchronized (m_activeInstances) {
|
||||
m_activeInstances.remove(instance);
|
||||
}
|
||||
m_workerThreadEndNotifier.notify(MultiThreadExecutor.this, instance);
|
||||
}
|
||||
}
|
||||
|
||||
Thread thread = new Thread(new ExecutorRunnable());
|
||||
instance.m_thread = thread;
|
||||
|
||||
synchronized (m_activeInstances) {
|
||||
m_activeInstances.add(instance);
|
||||
}
|
||||
|
||||
thread.start();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean hasPendingEvent()
|
||||
{
|
||||
synchronized (m_endedInstances) {
|
||||
return !m_endedInstances.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPendingWorker()
|
||||
{
|
||||
synchronized (m_activeInstances) {
|
||||
return !m_activeInstances.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPendingEventOrWorker()
|
||||
{
|
||||
return hasPendingWorker() || hasPendingEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* must call this function from main thread(JS thread)
|
||||
*/
|
||||
public void pumpEventsFromThreadIfNeeds(boolean executePendingJavaScriptJobs)
|
||||
{
|
||||
if (Thread.currentThread() != m_javaScriptThread) {
|
||||
throw new RuntimeException("You should call this function on JavaScriptThread");
|
||||
}
|
||||
|
||||
Object[] instances;
|
||||
synchronized (m_endedInstances) {
|
||||
instances = m_endedInstances.toArray();
|
||||
m_endedInstances.clear();
|
||||
}
|
||||
|
||||
for (int i = 0; i < instances.length; i ++) {
|
||||
ExecutorInstance e = (ExecutorInstance)instances[i];
|
||||
JavaScriptValue value = e.resultBuilder().build(e.context(), e.builderContext());
|
||||
if (e.builderContext().wasSuccessful()) {
|
||||
e.promise().fulfill(e.context(), value);
|
||||
} else {
|
||||
e.promise().reject(e.context(), value);
|
||||
}
|
||||
}
|
||||
|
||||
if (executePendingJavaScriptJobs) {
|
||||
m_vmInstance.executeEveryPendingJobIfExists();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* must call this function from main thread(JS thread)
|
||||
*/
|
||||
public void pumpEventsFromThreadIfNeeds()
|
||||
{
|
||||
pumpEventsFromThreadIfNeeds(true);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#Wed Jan 25 15:38:01 KST 2023
|
||||
#Fri May 30 15:07:57 KST 2025
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
|||
1
build/android/publish/android-example
Normal file
1
build/android/publish/android-example
Normal file
|
|
@ -0,0 +1 @@
|
|||
./gradlew publish
|
||||
2
build/android/publish/mac-example
Normal file
2
build/android/publish/mac-example
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
./gradlew bundleHostJar
|
||||
MAVEN_OPTS="-Dmaven.repo.local=${MAVEN_LOCAL_PATH}/mac/releases/" mvn install:install-file -Dfile=${PWD}/escargot/build/libs/escargot.jar -DgroupId=com.samsung.lwe.escargot -DartifactId=escargot-mac -Dversion=X.X.X.20XXXXXX.X.XXXXXXX -Dpackaging=jar
|
||||
2
build/android/publish/ubuntu-example
Normal file
2
build/android/publish/ubuntu-example
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
./gradlew bundleHostJar
|
||||
MAVEN_OPTS="-Dmaven.repo.local=${MAVEN_LOCAL_PATH}/ubuntu/releases/" mvn install:install-file -Dfile=${PWD}/escargot/build/libs/escargot.jar -DgroupId=com.samsung.lwe.escargot -DartifactId=escargot-ubuntu -Dversion=X.X.X.20XXXXXX.X.XXXXXXX -Dpackaging=jar
|
||||
|
|
@ -3,6 +3,9 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12 FATAL_ERROR)
|
|||
#######################################################
|
||||
# CONFIGURATION
|
||||
#######################################################
|
||||
SET (ESCARGOT_LIBRARIES)
|
||||
SET (ESCARGOT_INCDIRS)
|
||||
|
||||
# CONFIGURE ESCARGOT VERSION
|
||||
FIND_PACKAGE(Git)
|
||||
IF (GIT_FOUND)
|
||||
|
|
@ -17,7 +20,8 @@ IF ((NOT DEFINED ESCARGOT_BUILD_VERSION) OR (ESCARGOT_BUILD_VERSION STREQUAL "")
|
|||
FILE (STRINGS "${PROJECT_SOURCE_DIR}/RELEASE_VERSION" ESCARGOT_BUILD_VERSION)
|
||||
ENDIF()
|
||||
MESSAGE(STATUS "Escargot Build Version: ${ESCARGOT_BUILD_VERSION}")
|
||||
CONFIGURE_FILE (${PROJECT_SOURCE_DIR}/src/EscargotInfo.h.in ${PROJECT_SOURCE_DIR}/src/EscargotInfo.h @ONLY)
|
||||
CONFIGURE_FILE (${PROJECT_SOURCE_DIR}/src/EscargotInfo.h.in ${CMAKE_BINARY_DIR}/escargot_generated/EscargotInfo.h @ONLY)
|
||||
SET (ESCARGOT_INCDIRS ${ESCARGOT_INCDIRS} ${CMAKE_BINARY_DIR}/escargot_generated)
|
||||
|
||||
#######################################################
|
||||
# PATH
|
||||
|
|
@ -29,8 +33,6 @@ SET (GCUTIL_ROOT ${ESCARGOT_THIRD_PARTY_ROOT}/GCutil)
|
|||
#######################################################
|
||||
# FLAGS FOR TARGET
|
||||
#######################################################
|
||||
SET (ESCARGOT_LIBRARIES)
|
||||
SET (ESCARGOT_INCDIRS)
|
||||
INCLUDE (${ESCARGOT_ROOT}/build/target.cmake)
|
||||
|
||||
#######################################################
|
||||
|
|
@ -46,14 +48,14 @@ SET (CXXFLAGS_FROM_ENV $ENV{CXXFLAGS})
|
|||
SEPARATE_ARGUMENTS(CXXFLAGS_FROM_ENV)
|
||||
SET (CFLAGS_FROM_ENV $ENV{CFLAGS})
|
||||
SEPARATE_ARGUMENTS(CFLAGS_FROM_ENV)
|
||||
|
||||
SET (ESCARGOT_CXXFLAGS
|
||||
${CXXFLAGS_FROM_ENV}
|
||||
${ESCARGOT_CXXFLAGS})
|
||||
|
||||
SET (LDFLAGS_FROM_ENV $ENV{LDFLAGS})
|
||||
SEPARATE_ARGUMENTS(LDFLAGS_FROM_ENV)
|
||||
|
||||
# these flags assigned from external should have the highest priority
|
||||
SET (CXXFLAGS_FROM_ENV ${CXXFLAGS_FROM_ENV} ${ESCARGOT_CXXFLAGS_FROM_EXTERNAL})
|
||||
SET (CFLAGS_FROM_ENV ${CFLAGS_FROM_ENV} ${ESCARGOT_CFLAGS_FROM_EXTERNAL})
|
||||
SET (LDFLAGS_FROM_ENV ${LDFLAGS_FROM_ENV} ${ESCARGOT_LDFLAGS_FROM_EXTERNAL})
|
||||
|
||||
# ESCARGOT COMMON LDFLAGS
|
||||
SET (ESCARGOT_LDFLAGS ${ESCARGOT_LDFLAGS} -fvisibility=hidden)
|
||||
|
||||
|
|
@ -71,45 +73,50 @@ IF (ESCARGOT_SMALL_CONFIG)
|
|||
ENDIF()
|
||||
|
||||
IF (NOT DEFINED ESCARGOT_LIBICU_SUPPORT)
|
||||
SET (ESCARGOT_LIBICU_SUPPORT OFF)
|
||||
SET (ESCARGOT_LIBICU_SUPPORT ON)
|
||||
ENDIF()
|
||||
|
||||
IF (NOT DEFINED ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN)
|
||||
SET (ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN OFF)
|
||||
SET (ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN ON)
|
||||
ENDIF()
|
||||
|
||||
#######################################################
|
||||
# FLAGS FOR ADDITIONAL FUNCTION
|
||||
#######################################################
|
||||
IF (ESCARGOT_LIBICU_SUPPORT)
|
||||
IF (ESCARGOT_DEPLOY)
|
||||
# Build for deployment (include ICU library)
|
||||
SET (CMAKE_INSTALL_RPATH "$ORIGIN")
|
||||
SET (CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||
SET (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
ENDIF()
|
||||
|
||||
IF (ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_ICU -DENABLE_INTL -DENABLE_RUNTIME_ICU_BINDER)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_INTL_DISPLAYNAMES -DENABLE_INTL_NUMBERFORMAT -DENABLE_INTL_PLURALRULES)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_INTL_RELATIVETIMEFORMAT -DENABLE_INTL_LISTFORMAT)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_INTL_RELATIVETIMEFORMAT -DENABLE_INTL_LISTFORMAT -DENABLE_INTL_DURATIONFORMAT)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_INTL_SEGMENTER)
|
||||
ELSE()
|
||||
IF (NOT ${ESCARGOT_HOST} STREQUAL "windows")
|
||||
# windows icu cannot support these feature yet.(~10.0.18362)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_INTL_DISPLAYNAMES -DENABLE_INTL_NUMBERFORMAT -DENABLE_INTL_PLURALRULES)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_INTL_RELATIVETIMEFORMAT -DENABLE_INTL_LISTFORMAT)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_INTL_RELATIVETIMEFORMAT -DENABLE_INTL_LISTFORMAT -DENABLE_INTL_DURATIONFORMAT)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_INTL_SEGMENTER)
|
||||
|
||||
PKG_CHECK_MODULES (ICUI18N REQUIRED icu-i18n)
|
||||
PKG_CHECK_MODULES (ICUUC REQUIRED icu-uc)
|
||||
PKG_CHECK_MODULES(ICU REQUIRED icu-uc icu-i18n)
|
||||
ENDIF()
|
||||
|
||||
MESSAGE(STATUS "ICU Libraries: ${ICU_LIBRARIES}")
|
||||
SET (ESCARGOT_LDFLAGS ${ESCARGOT_LDFLAGS} ${ICU_LDFLAGS})
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_ICU -DENABLE_INTL)
|
||||
|
||||
IF (${ESCARGOT_HOST} STREQUAL "darwin")
|
||||
FOREACH (ICU_LDFLAG ${ICUI18N_LDFLAGS} ${ICUUC_LDFLAGS})
|
||||
SET (ESCARGOT_LDFLAGS ${ESCARGOT_LDFLAGS} ${ICU_LDFLAG})
|
||||
ENDFOREACH()
|
||||
ELSE()
|
||||
SET (ESCARGOT_LIBRARIES ${ESCARGOT_LIBRARIES} ${ICUI18N_LIBRARIES} ${ICUUC_LIBRARIES})
|
||||
ENDIF()
|
||||
SET (ESCARGOT_INCDIRS ${ESCARGOT_INCDIRS} ${ICUI18N_INCLUDE_DIRS} ${ICUUC_INCLUDE_DIRS})
|
||||
SET (ESCARGOT_CXXFLAGS ${ESCARGOT_CXXFLAGS} ${ICUI18N_CFLAGS_OTHER} ${ICUUC_CFLAGS_OTHER})
|
||||
SET (ESCARGOT_INCDIRS ${ESCARGOT_INCDIRS} ${ICU_INCLUDE_DIRS})
|
||||
SET (ESCARGOT_LIBRARIES ${ESCARGOT_LIBRARIES} ${ICU_LIBRARIES})
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
IF (ESCARGOT_USE_EXTENDED_API)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_EXTENDED_API)
|
||||
ENDIF()
|
||||
|
||||
IF (ESCARGOT_USE_CUSTOM_LOGGING)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_CUSTOM_LOGGING)
|
||||
ELSEIF (${ESCARGOT_HOST} STREQUAL "tizen" OR ${ESCARGOT_HOST} STREQUAL "tizen_obs")
|
||||
|
|
@ -132,6 +139,10 @@ ENDIF()
|
|||
|
||||
IF (ESCARGOT_WASM)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_WASM)
|
||||
IF (NOT DEFINED ESCARGOT_THREADING)
|
||||
# threading should be enabled for WASM (WASM threading feature)
|
||||
SET (ESCARGOT_THREADING ON)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
IF (ESCARGOT_THREADING)
|
||||
|
|
@ -144,14 +155,40 @@ ENDIF()
|
|||
|
||||
IF (ESCARGOT_TCO)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_TCO)
|
||||
IF (ESCARGOT_TCO_DEBUG)
|
||||
IF (NOT ${ESCARGOT_MODE} STREQUAL "debug")
|
||||
MESSAGE (FATAL_ERROR "ESCARGOT_TCO_DEBUG is enabled only for debug mode")
|
||||
ENDIF()
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_TCO_DEBUG)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
IF (ESCARGOT_TEMPORAL)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_TEMPORAL)
|
||||
IF (NOT ESCARGOT_LIBICU_SUPPORT)
|
||||
MESSAGE (FATAL_ERROR "Temporal feature needs ICU")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
IF (ESCARGOT_SHADOWREALM)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_SHADOWREALM)
|
||||
ENDIF()
|
||||
|
||||
IF (ESCARGOT_TLS_ACCESS_BY_ADDRESS)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_TLS_ACCESS_BY_ADDRESS)
|
||||
ENDIF()
|
||||
|
||||
IF (ESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DENABLE_TLS_ACCESS_BY_PTHREAD_KEY)
|
||||
ENDIF()
|
||||
|
||||
IF (ESCARGOT_TEST)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DESCARGOT_ENABLE_TEST)
|
||||
IF (ESCARGOT_CODE_CACHE)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DCODE_CACHE_MIN_SOURCE_LENGTH=1024)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DCODE_CACHE_MAX_CACHE_COUNT=128)
|
||||
SET (ESCARGOT_DEFINITIONS ${ESCARGOT_DEFINITIONS} -DCODE_CACHE_SHOULD_LOAD_FUNCTIONS_ON_SCRIPT_LOADING=true)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
#######################################################
|
||||
|
|
@ -174,7 +211,7 @@ SET (ESCARGOT_CXXFLAGS_STATICLIB -fPIC -DESCARGOT_EXPORT=)
|
|||
SET (ESCARGOT_CXXFLAGS_SHELL -DESCARGOT_EXPORT=)
|
||||
|
||||
#######################################################
|
||||
# FLAGS FOR MEMORY PROFILING
|
||||
# FLAGS FOR PROFILING
|
||||
#######################################################
|
||||
SET (PROFILER_FLAGS)
|
||||
|
||||
|
|
@ -190,6 +227,11 @@ IF (ESCARGOT_VALGRIND)
|
|||
SET (PROFILER_FLAGS ${PROFILER_FLAGS} -DESCARGOT_VALGRIND)
|
||||
ENDIF()
|
||||
|
||||
IF (ESARGOT_GOOGLE_PERF)
|
||||
SET (PROFILER_FLAGS ${PROFILER_FLAGS} -DESCARGOT_GOOGLE_PERF)
|
||||
SET (ESCARGOT_LDFLAGS ${ESCARGOT_LDFLAGS} -lprofiler -lunwind -llzma)
|
||||
ENDIF()
|
||||
|
||||
#######################################################
|
||||
# FLAGS FOR DEBUGGER
|
||||
#######################################################
|
||||
|
|
|
|||
|
|
@ -3,12 +3,15 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12 FATAL_ERROR)
|
|||
SET (ESCARGOT_INCDIRS
|
||||
${ESCARGOT_INCDIRS}
|
||||
${ESCARGOT_ROOT}/src/
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/checked_arithmetic/
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/double_conversion/
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/lz4/
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/rapidjson/include/
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/yarr/
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/runtime_icu_binder/
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/robin_map/include/
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/xsum/
|
||||
)
|
||||
|
||||
IF (${ESCARGOT_MODE} STREQUAL "debug")
|
||||
|
|
@ -52,6 +55,7 @@ FILE (GLOB_RECURSE ESCARGOT_SRC ${ESCARGOT_ROOT}/src/*.cpp)
|
|||
FILE (GLOB YARR_SRC ${ESCARGOT_THIRD_PARTY_ROOT}/yarr/*.cpp)
|
||||
FILE (GLOB DOUBLE_CONVERSION_SRC ${ESCARGOT_THIRD_PARTY_ROOT}/double_conversion/*.cc)
|
||||
FILE (GLOB LZ4_SRC ${ESCARGOT_THIRD_PARTY_ROOT}/lz4/*.cpp)
|
||||
FILE (GLOB XSUM_SRC ${ESCARGOT_THIRD_PARTY_ROOT}/xsum/*.cpp)
|
||||
|
||||
IF (NOT ${ESCARGOT_OUTPUT} MATCHES "shell")
|
||||
LIST (REMOVE_ITEM ESCARGOT_SRC ${ESCARGOT_ROOT}/src/shell/Shell.cpp)
|
||||
|
|
@ -70,39 +74,83 @@ SET (ESCARGOT_SRC_LIST
|
|||
${YARR_SRC}
|
||||
${DOUBLE_CONVERSION_SRC}
|
||||
${LZ4_SRC}
|
||||
${XSUM_SRC}
|
||||
${CCTEST_SRC}
|
||||
)
|
||||
|
||||
#######################################################
|
||||
# GCUTIL
|
||||
#######################################################
|
||||
IF (${ESCARGOT_OUTPUT} STREQUAL "shared_lib")
|
||||
SET (ESCARGOT_THIRDPARTY_CFLAGS ${ESCARGOT_THIRDPARTY_CFLAGS} ${ESCARGOT_CXXFLAGS_SHAREDLIB})
|
||||
ELSEIF (${ESCARGOT_OUTPUT} STREQUAL "static_lib")
|
||||
SET (ESCARGOT_THIRDPARTY_CFLAGS ${ESCARGOT_THIRDPARTY_CFLAGS} ${ESCARGOT_CXXFLAGS_STATICLIB})
|
||||
ENDIF()
|
||||
|
||||
SET (GCUTIL_CFLAGS ${ESCARGOT_THIRDPARTY_CFLAGS})
|
||||
SET (GCUTIL_CFLAGS ${ESCARGOT_THIRDPARTY_CFLAGS} ${PROFILER_FLAGS})
|
||||
SET (GCUTIL_CFLAGS_FROM_EXTERNAL ${ESCARGOT_CFLAGS_FROM_EXTERNAL})
|
||||
|
||||
IF (ESCARGOT_SMALL_CONFIG)
|
||||
SET (GCUTIL_CFLAGS ${GCUTIL_CFLAGS} -DSMALL_CONFIG -DMAX_HEAP_SECTS=512)
|
||||
SET (GCUTIL_CFLAGS ${GCUTIL_CFLAGS} -DSMALL_CONFIG)
|
||||
ENDIF()
|
||||
IF (ESCARGOT_THREADING)
|
||||
SET (GCUTIL_ENABLE_THREADING ON)
|
||||
ENDIF()
|
||||
IF (ESCARGOT_TLS_ACCESS_BY_ADDRESS)
|
||||
SET (GCUTIL_ENABLE_TLS_ACCESS_BY_ADDRESS ON)
|
||||
ENDIF()
|
||||
IF (ESCARGOT_TLS_ACCESS_BY_PTHREAD_KEY)
|
||||
SET (GCUTIL_ENABLE_TLS_ACCESS_BY_PTHREAD_KEY ON)
|
||||
ENDIF()
|
||||
|
||||
SET (GCUTIL_MODE ${ESCARGOT_MODE})
|
||||
|
||||
ADD_SUBDIRECTORY (third_party/GCutil)
|
||||
|
||||
SET (ESCARGOT_LIBRARIES ${ESCARGOT_LIBRARIES} gc-lib)
|
||||
|
||||
#######################################################
|
||||
# SIMDUTF
|
||||
#######################################################
|
||||
ADD_LIBRARY (libsimdutf STATIC
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/simdutf/simdutf.cpp)
|
||||
TARGET_INCLUDE_DIRECTORIES (libsimdutf PUBLIC ${ESCARGOT_THIRD_PARTY_ROOT}/simdutf)
|
||||
SET (LIBSIMDUTF_CXXFLAGS
|
||||
${ESCARGOT_CXXFLAGS}
|
||||
${ESCARGOT_THIRDPARTY_CFLAGS}
|
||||
${CXXFLAGS_FROM_ENV}
|
||||
# disable simd optimization
|
||||
-DSIMDUTF_IMPLEMENTATION_ARM64=0
|
||||
-DSIMDUTF_IMPLEMENTATION_ICELAKE=0
|
||||
-DSIMDUTF_IMPLEMENTATION_HASWELL=0
|
||||
-DSIMDUTF_IMPLEMENTATION_WESTMERE=0
|
||||
-DSIMDUTF_IMPLEMENTATION_PPC64=0
|
||||
-DSIMDUTF_IMPLEMENTATION_RVV=0
|
||||
-DSIMDUTF_IMPLEMENTATION_LSX=0
|
||||
-DSIMDUTF_IMPLEMENTATION_FALLBACK=1
|
||||
# ${ESCARGOT_CXXFLAGS_FROM_EXTERNAL} already included in ${CXXFLAGS_FROM_ENV}
|
||||
)
|
||||
|
||||
IF (${ESCARGOT_MODE} STREQUAL "debug")
|
||||
SET (LIBSIMDUTF_CXXFLAGS ${ESCARGOT_CXXFLAGS_DEBUG} ${LIBSIMDUTF_CXXFLAGS})
|
||||
ELSEIF (${ESCARGOT_MODE} STREQUAL "release")
|
||||
SET (LIBSIMDUTF_CXXFLAGS ${ESCARGOT_CXXFLAGS_RELEASE} ${LIBSIMDUTF_CXXFLAGS})
|
||||
ENDIF()
|
||||
|
||||
TARGET_COMPILE_OPTIONS (libsimdutf PRIVATE ${LIBSIMDUTF_CXXFLAGS})
|
||||
|
||||
SET (ESCARGOT_LIBRARIES ${ESCARGOT_LIBRARIES} libsimdutf)
|
||||
|
||||
#######################################################
|
||||
# LIBBF
|
||||
#######################################################
|
||||
ADD_LIBRARY (libbf STATIC
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/libbf/libbf.c
|
||||
${ESCARGOT_THIRD_PARTY_ROOT}/libbf/cutils.c)
|
||||
TARGET_INCLUDE_DIRECTORIES (libbf PUBLIC ${ESCARGOT_THIRD_PARTY_ROOT}/libbf)
|
||||
SET (LIBBF_CFLAGS
|
||||
${ESCARGOT_THIRDPARTY_CFLAGS} # we can share flags with gcutil
|
||||
${ESCARGOT_THIRDPARTY_CFLAGS}
|
||||
${CFLAGS_FROM_ENV}
|
||||
# ${ESCARGOT_CFLAGS_FROM_EXTERNAL} already included in ${CFLAGS_FROM_ENV}
|
||||
)
|
||||
|
||||
IF (${ESCARGOT_MODE} STREQUAL "debug")
|
||||
|
|
@ -115,42 +163,157 @@ TARGET_COMPILE_OPTIONS (libbf PRIVATE ${LIBBF_CFLAGS})
|
|||
|
||||
SET (ESCARGOT_LIBRARIES ${ESCARGOT_LIBRARIES} libbf)
|
||||
|
||||
# ROBIN MAP
|
||||
ADD_SUBDIRECTORY(third_party/robin_map)
|
||||
SET (ESCARGOT_LIBRARIES ${ESCARGOT_LIBRARIES} tsl::robin_map)
|
||||
#######################################################
|
||||
# RUNTIME ICU BINDER
|
||||
#######################################################
|
||||
SET (RIB_CFLAGS ${ESCARGOT_THIRDPARTY_CFLAGS})
|
||||
SET (RIB_MODE ${ESCARGOT_MODE})
|
||||
SET (RIB_CFLAGS_FROM_EXTERNAL ${ESCARGOT_CFLAGS_FROM_EXTERNAL})
|
||||
ADD_SUBDIRECTORY (third_party/runtime_icu_binder)
|
||||
|
||||
IF (ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN)
|
||||
# RUNTIME ICU BINDER
|
||||
SET (RIB_CFLAGS ${ESCARGOT_CXXFLAGS})
|
||||
|
||||
IF (${ESCARGOT_OUTPUT} STREQUAL "shared_lib")
|
||||
SET (RIB_CFLAGS ${RIB_CFLAGS} ${ESCARGOT_CXXFLAGS_SHAREDLIB})
|
||||
ELSEIF (${ESCARGOT_OUTPUT} STREQUAL "static_lib")
|
||||
SET (RIB_CFLAGS ${RIB_CFLAGS} ${ESCARGOT_CXXFLAGS_STATICLIB})
|
||||
ENDIF()
|
||||
|
||||
SET (RIB_MODE ${ESCARGOT_MODE})
|
||||
|
||||
ADD_SUBDIRECTORY (third_party/runtime_icu_binder)
|
||||
SET (ESCARGOT_LIBRARIES ${ESCARGOT_LIBRARIES} runtime-icu-binder-static)
|
||||
ENDIF()
|
||||
|
||||
# WebAssembly (wabt)
|
||||
#######################################################
|
||||
# WebAssembly (walrus)
|
||||
#######################################################
|
||||
IF (ESCARGOT_WASM)
|
||||
SET (WASM_CXX_FLAGS
|
||||
${ESCARGOT_THIRDPARTY_CFLAGS} # we can share flags with gcutil
|
||||
)
|
||||
SET (WALRUS_CXXFLAGS
|
||||
${ESCARGOT_THIRDPARTY_CFLAGS}
|
||||
-g3)
|
||||
SET (WASM_ARCH ${ESCARGOT_ARCH})
|
||||
SET (WALRUS_HOST ${ESCARGOT_HOST})
|
||||
SET (WALRUS_ARCH ${ESCARGOT_ARCH})
|
||||
SET (WALRUS_MODE ${ESCARGOT_MODE})
|
||||
SET (WALRUS_OUTPUT "shared_lib")
|
||||
SET (WALRUS_WASI OFF) # WASI should be OFF
|
||||
SET (WALRUS_EXTENDED_FEATURES ON) # enable extended features
|
||||
|
||||
IF (${ESCARGOT_MODE} STREQUAL "release")
|
||||
SET (WASM_CXX_FLAGS ${WASM_CXX_FLAGS} ${ESCARGOT_CXXFLAGS_RELEASE})
|
||||
SET (WALRUS_CXXFLAGS ${WALRUS_CXXFLAGS} ${ESCARGOT_CXXFLAGS_RELEASE})
|
||||
ENDIF()
|
||||
SET (WALRUS_CXXFLAGS_FROM_EXTERNAL ${ESCARGOT_CXXFLAGS_FROM_EXTERNAL})
|
||||
SET (WALRUS_LDFLAGS_FROM_EXTERNAL ${ESCARGOT_LDFLAGS_FROM_EXTERNAL})
|
||||
|
||||
ADD_SUBDIRECTORY (third_party/wasm)
|
||||
|
||||
SET (ESCARGOT_LIBRARIES ${ESCARGOT_LIBRARIES} wasm)
|
||||
ADD_SUBDIRECTORY (third_party/walrus)
|
||||
SET (ESCARGOT_LIBRARIES ${ESCARGOT_LIBRARIES} walrus)
|
||||
ENDIF()
|
||||
|
||||
MAKE_DIRECTORY(${CMAKE_BINARY_DIR}/escargot_generated/tmp)
|
||||
|
||||
# Generate UnicodeIdentifierTables.cpp
|
||||
MAKE_DIRECTORY(${CMAKE_BINARY_DIR}/escargot_generated/parser)
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND python3 ${PROJECT_SOURCE_DIR}/tools/code_generators/gen_unicode.py --derived_core_properties ${PROJECT_SOURCE_DIR}/tools/unicode_data/DerivedCoreProperties.txt --dst ${CMAKE_BINARY_DIR}/escargot_generated/tmp/UnicodeIdentifierTables.cpp
|
||||
RESULT_VARIABLE GENERATE_RESULT
|
||||
OUTPUT_VARIABLE GENERATE_OUTPUT
|
||||
ERROR_VARIABLE GENERATE_ERROR
|
||||
)
|
||||
|
||||
IF (NOT GENERATE_RESULT EQUAL 0)
|
||||
MESSAGE(STATUS "Output:\n${GENERATE_OUTPUT}")
|
||||
MESSAGE(FATAL_ERROR "${GENERATE_ERROR}")
|
||||
ENDIF()
|
||||
|
||||
EXECUTE_PROCESS (COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_BINARY_DIR}/escargot_generated/tmp/UnicodeIdentifierTables.cpp ${CMAKE_BINARY_DIR}/escargot_generated/parser/UnicodeIdentifierTables.cpp
|
||||
RESULT_VARIABLE COMPARE_RESULT
|
||||
OUTPUT_VARIABLE COMPARE_OUTPUT
|
||||
ERROR_VARIABLE COMPARE_ERROR
|
||||
)
|
||||
|
||||
IF (NOT ${COMPARE_RESULT} EQUAL 0)
|
||||
FILE (COPY ${CMAKE_BINARY_DIR}/escargot_generated/tmp/UnicodeIdentifierTables.cpp DESTINATION ${CMAKE_BINARY_DIR}/escargot_generated/parser/)
|
||||
ENDIF()
|
||||
|
||||
SET (ESCARGOT_SRC_LIST ${ESCARGOT_SRC_LIST} ${CMAKE_BINARY_DIR}/escargot_generated/parser/UnicodeIdentifierTables.cpp)
|
||||
|
||||
# Generate YarrCanonicalizeUnicode.cpp
|
||||
MAKE_DIRECTORY(${CMAKE_BINARY_DIR}/escargot_generated/yarr)
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND python3 ${PROJECT_SOURCE_DIR}/tools/code_generators/generateYarrCanonicalizeUnicode.py ${PROJECT_SOURCE_DIR}/tools/unicode_data/CaseFolding.txt ${CMAKE_BINARY_DIR}/escargot_generated/tmp/YarrCanonicalizeUnicode.cpp
|
||||
RESULT_VARIABLE GENERATE_RESULT
|
||||
OUTPUT_VARIABLE GENERATE_OUTPUT
|
||||
ERROR_VARIABLE GENERATE_ERROR
|
||||
)
|
||||
|
||||
IF (NOT GENERATE_RESULT EQUAL 0)
|
||||
MESSAGE(STATUS "Output:\n${GENERATE_OUTPUT}")
|
||||
MESSAGE(FATAL_ERROR "${GENERATE_ERROR}")
|
||||
ENDIF()
|
||||
|
||||
FILE(READ ${CMAKE_BINARY_DIR}/escargot_generated/tmp/YarrCanonicalizeUnicode.cpp UNICODE_FILE_CONTENTS)
|
||||
STRING(REPLACE "config.h" "WTFBridge.h" UNICODE_FILE_CONTENTS "${UNICODE_FILE_CONTENTS}")
|
||||
STRING(REPLACE "constexpr const" "const" UNICODE_FILE_CONTENTS "${UNICODE_FILE_CONTENTS}")
|
||||
STRING(REPLACE "constexpr size_t UNICODE" "const size_t UNICODE" UNICODE_FILE_CONTENTS "${UNICODE_FILE_CONTENTS}")
|
||||
STRING(REPLACE "constexpr CanonicalizationRange unicodeRangeInfo" "const CanonicalizationRange unicodeRangeInfo" UNICODE_FILE_CONTENTS "${UNICODE_FILE_CONTENTS}")
|
||||
FILE(WRITE ${CMAKE_BINARY_DIR}/escargot_generated/tmp/YarrCanonicalizeUnicode.cpp "${UNICODE_FILE_CONTENTS}")
|
||||
|
||||
EXECUTE_PROCESS (COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_BINARY_DIR}/escargot_generated/tmp/YarrCanonicalizeUnicode.cpp ${CMAKE_BINARY_DIR}/escargot_generated/yarr/YarrCanonicalizeUnicode.cpp
|
||||
RESULT_VARIABLE COMPARE_RESULT
|
||||
OUTPUT_VARIABLE COMPARE_OUTPUT
|
||||
ERROR_VARIABLE COMPARE_ERROR
|
||||
)
|
||||
|
||||
IF (NOT ${COMPARE_RESULT} EQUAL 0)
|
||||
FILE (COPY ${CMAKE_BINARY_DIR}/escargot_generated/tmp/YarrCanonicalizeUnicode.cpp DESTINATION ${CMAKE_BINARY_DIR}/escargot_generated/yarr/)
|
||||
ENDIF()
|
||||
|
||||
SET(ESCARGOT_SRC_LIST ${ESCARGOT_SRC_LIST} ${CMAKE_BINARY_DIR}/escargot_generated/yarr/YarrCanonicalizeUnicode.cpp)
|
||||
|
||||
# yarr/UnicodePatternTables.h
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND python3 ${PROJECT_SOURCE_DIR}/tools/code_generators/generateYarrUnicodePropertyTables.py ${PROJECT_SOURCE_DIR}/tools/unicode_data ${CMAKE_BINARY_DIR}/escargot_generated/tmp/UnicodePatternTables.h
|
||||
RESULT_VARIABLE GENERATE_RESULT
|
||||
OUTPUT_VARIABLE GENERATE_OUTPUT
|
||||
ERROR_VARIABLE GENERATE_ERROR
|
||||
)
|
||||
|
||||
IF (NOT GENERATE_RESULT EQUAL 0)
|
||||
MESSAGE(STATUS "Output:\n${GENERATE_OUTPUT}")
|
||||
MESSAGE(FATAL_ERROR "${GENERATE_ERROR}")
|
||||
ENDIF()
|
||||
|
||||
EXECUTE_PROCESS (COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_BINARY_DIR}/escargot_generated/tmp/UnicodePatternTables.h ${CMAKE_BINARY_DIR}/escargot_generated/yarr/UnicodePatternTables.h
|
||||
RESULT_VARIABLE COMPARE_RESULT
|
||||
OUTPUT_VARIABLE COMPARE_OUTPUT
|
||||
ERROR_VARIABLE COMPARE_ERROR
|
||||
)
|
||||
|
||||
IF (NOT ${COMPARE_RESULT} EQUAL 0)
|
||||
FILE (COPY ${CMAKE_BINARY_DIR}/escargot_generated/tmp/UnicodePatternTables.h DESTINATION ${CMAKE_BINARY_DIR}/escargot_generated/yarr/)
|
||||
ENDIF()
|
||||
|
||||
SET (ESCARGOT_INCDIRS
|
||||
${ESCARGOT_INCDIRS}
|
||||
${CMAKE_BINARY_DIR}/escargot_generated/yarr/
|
||||
)
|
||||
|
||||
# YarrCanonicalizeUCS2.cpp
|
||||
EXECUTE_PROCESS(
|
||||
COMMAND python3 ${PROJECT_SOURCE_DIR}/tools/code_generators/generateYarrCanonicalizeUCS2.py ${PROJECT_SOURCE_DIR}/tools/unicode_data/UnicodeData.txt ${CMAKE_BINARY_DIR}/escargot_generated/tmp/YarrCanonicalizeUCS2.cpp
|
||||
RESULT_VARIABLE GENERATE_RESULT
|
||||
OUTPUT_VARIABLE GENERATE_OUTPUT
|
||||
ERROR_VARIABLE GENERATE_ERROR
|
||||
)
|
||||
|
||||
IF (NOT GENERATE_RESULT EQUAL 0)
|
||||
MESSAGE(STATUS "Output:\n${GENERATE_OUTPUT}")
|
||||
MESSAGE(FATAL_ERROR "${GENERATE_ERROR}")
|
||||
ENDIF()
|
||||
|
||||
EXECUTE_PROCESS (COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_BINARY_DIR}/escargot_generated/tmp/YarrCanonicalizeUCS2.cpp ${CMAKE_BINARY_DIR}/escargot_generated/yarr/YarrCanonicalizeUCS2.cpp
|
||||
RESULT_VARIABLE COMPARE_RESULT
|
||||
OUTPUT_VARIABLE COMPARE_OUTPUT
|
||||
ERROR_VARIABLE COMPARE_ERROR
|
||||
)
|
||||
|
||||
IF (NOT ${COMPARE_RESULT} EQUAL 0)
|
||||
FILE (COPY ${CMAKE_BINARY_DIR}/escargot_generated/tmp/YarrCanonicalizeUCS2.cpp DESTINATION ${CMAKE_BINARY_DIR}/escargot_generated/yarr/)
|
||||
ENDIF()
|
||||
|
||||
SET(ESCARGOT_SRC_LIST ${ESCARGOT_SRC_LIST} ${CMAKE_BINARY_DIR}/escargot_generated/yarr/YarrCanonicalizeUCS2.cpp)
|
||||
|
||||
# BUILD
|
||||
IF (${ESCARGOT_OUTPUT} STREQUAL "shell")
|
||||
ADD_EXECUTABLE (${ESCARGOT_TARGET} ${ESCARGOT_SRC_LIST})
|
||||
|
|
|
|||
|
|
@ -9,12 +9,15 @@ SET (ESCARGOT_THIRDPARTY_CFLAGS)
|
|||
SET (ESCARGOT_BUILD_32BIT OFF)
|
||||
SET (ESCARGOT_BUILD_64BIT OFF)
|
||||
SET (ESCARGOT_BUILD_64BIT_LARGE OFF)
|
||||
IF (ESCARGOT_ASAN)
|
||||
SET (ESCARGOT_BUILD_64BIT_LARGE ON)
|
||||
ENDIF()
|
||||
|
||||
# clang-cl defines ${CMAKE_CXX_COMPILER_ID} "Clang" and ${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} "MSVC"
|
||||
SET (COMPILER_CLANG_CL OFF)
|
||||
IF (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||
IF (DEFINED CMAKE_CXX_COMPILER_FRONTEND_VARIANT)
|
||||
IF (${CMAKE_CXX_COMPILER_FRONTEND_VARIANT} STREQUAL "MSVC")
|
||||
IF ("${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
|
||||
SET (COMPILER_CLANG_CL ON)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
|
@ -22,13 +25,18 @@ ENDIF()
|
|||
|
||||
# Default options per compiler
|
||||
IF (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" OR ${COMPILER_CLANG_CL})
|
||||
SET (ESCARGOT_CXXFLAGS /std:c++17 /fp:strict /Zc:__cplusplus /EHs /source-charset:utf-8 /D_CRT_SECURE_NO_WARNINGS /DGC_NOT_DLL /D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING /wd4244 /wd4267 /wd4805 /wd4018 /wd4172)
|
||||
SET (ESCARGOT_COMPILER_ID "MSVC")
|
||||
SET (ESCARGOT_CXXFLAGS /std:c++17 /fp:strict /Zc:__cplusplus /EHs /source-charset:utf-8 /MP /D_CRT_SECURE_NO_WARNINGS /DGC_NOT_DLL /D_SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING /wd4244 /wd4267 /wd4805 /wd4018 /wd4172 /wd4146)
|
||||
SET (ESCARGOT_CXXFLAGS_RELEASE /O2 /Oy-)
|
||||
SET (ESCARGOT_THIRDPARTY_CFLAGS /D_CRT_SECURE_NO_WARNINGS /DGC_NOT_DLL /Oy- /wd4146 /EHs)
|
||||
IF (${COMPILER_CLANG_CL})
|
||||
SET (ESCARGOT_CXXFLAGS ${ESCARGOT_CXXFLAGS} /EHs -Wno-invalid-offsetof -Wno-inline-new-delete -fintegrated-cc1)
|
||||
ENDIF()
|
||||
IF (ESCARGOT_SMALL_CONFIG)
|
||||
SET (ESCARGOT_CXXFLAGS_RELEASE ${ESCARGOT_CXXFLAGS_RELEASE} /Os)
|
||||
ENDIF()
|
||||
ELSEIF (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
||||
SET (ESCARGOT_COMPILER_ID "GCC")
|
||||
SET (ESCARGOT_CXXFLAGS
|
||||
${ESCARGOT_CXXFLAGS}
|
||||
-std=c++11 -g3
|
||||
|
|
@ -43,13 +51,26 @@ ELSEIF (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
|||
-Wno-unused-but-set-variable -Wno-unused-but-set-parameter
|
||||
-Wno-deprecated-declarations -Wno-unused-function
|
||||
)
|
||||
|
||||
IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16)
|
||||
SET (ESCARGOT_CXXFLAGS ${ESCARGOT_CXXFLAGS} -Wno-maybe-uninitialized)
|
||||
ENDIF()
|
||||
|
||||
IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9)
|
||||
SET (ESCARGOT_CXXFLAGS ${ESCARGOT_CXXFLAGS} -Wno-attributes -Wno-class-memaccess -Wno-deprecated-copy -Wno-cast-function-type -Wno-stringop-truncation -Wno-pessimizing-move -Wno-mismatched-new-delete -Wno-overloaded-virtual -Wno-dangling-pointer)
|
||||
endif()
|
||||
SET (ESCARGOT_CXXFLAGS_DEBUG -O0 -Wall -Wextra -Werror)
|
||||
SET (ESCARGOT_CXXFLAGS_RELEASE -O2 -fno-stack-protector -fno-omit-frame-pointer)
|
||||
IF (ESCARGOT_SMALL_CONFIG)
|
||||
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS_EQUAL 9)
|
||||
# BUG?) -Os option has unknown memory conflicts (might be related with gcc version)
|
||||
# enable this option only for old gcc version
|
||||
SET (ESCARGOT_CXXFLAGS_RELEASE ${ESCARGOT_CXXFLAGS_RELEASE} -Os)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
SET (ESCARGOT_THIRDPARTY_CFLAGS -w -g3 -fdata-sections -ffunction-sections -fno-omit-frame-pointer -fvisibility=hidden)
|
||||
ELSEIF (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||
ELSEIF (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") #include Clang and AppleClang both
|
||||
SET (ESCARGOT_COMPILER_ID "CLANG")
|
||||
SET (ESCARGOT_CXXFLAGS
|
||||
${ESCARGOT_CXXFLAGS}
|
||||
-std=c++11 -g3
|
||||
|
|
@ -60,12 +81,20 @@ ELSEIF (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
|||
-fvisibility=hidden
|
||||
-fno-fast-math -fno-unsafe-math-optimizations -fdenormal-fp-math=ieee
|
||||
-Wno-type-limits -Wno-unused-result -Wno-unused-variable -Wno-invalid-offsetof -Wno-unused-function
|
||||
-Wno-deprecated-declarations -Wno-unsupported-floating-point-opt -Wno-parentheses-equality -Wno-dynamic-class-memaccess -Wno-deprecated-register
|
||||
-Wno-deprecated-declarations -Wno-parentheses-equality -Wno-dynamic-class-memaccess -Wno-deprecated-register
|
||||
-Wno-expansion-to-defined -Wno-return-type -Wno-overloaded-virtual -Wno-unused-private-field -Wno-deprecated-copy -Wno-atomic-alignment
|
||||
-Wno-ambiguous-reversed-operator -Wno-deprecated-enum-enum-conversion -Wno-deprecated-enum-float-conversion -Wno-braced-scalar-init -Wno-unused-parameter
|
||||
-Wno-ambiguous-reversed-operator -Wno-deprecated-enum-enum-conversion -Wno-deprecated-enum-float-conversion -Wno-braced-scalar-init -Wno-unused-parameter -Wno-deprecated-literal-operator -Wno-cast-function-type-mismatch
|
||||
-Wno-unknown-warning-option
|
||||
)
|
||||
IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 10)
|
||||
# this feature supported after clang version 11
|
||||
SET (ESCARGOT_CXXFLAGS ${ESCARGOT_CXXFLAGS} -Wno-unsupported-floating-point-opt)
|
||||
endif()
|
||||
SET (ESCARGOT_CXXFLAGS_DEBUG -O0 -Wall -Wextra -Werror)
|
||||
SET (ESCARGOT_CXXFLAGS_RELEASE -O2 -fno-stack-protector -fno-omit-frame-pointer)
|
||||
IF (ESCARGOT_SMALL_CONFIG)
|
||||
SET (ESCARGOT_CXXFLAGS_RELEASE ${ESCARGOT_CXXFLAGS_RELEASE} -Os)
|
||||
ENDIF()
|
||||
SET (ESCARGOT_THIRDPARTY_CFLAGS -w -g3 -fdata-sections -ffunction-sections -fno-omit-frame-pointer -fvisibility=hidden)
|
||||
ELSE()
|
||||
MESSAGE (FATAL_ERROR ${CMAKE_CXX_COMPILER_ID} " is Unsupported Compiler")
|
||||
|
|
@ -148,15 +177,23 @@ ELSEIF (${ESCARGOT_HOST} STREQUAL "android")
|
|||
# bdwgc android amd64 cannot support keeping back ptrs
|
||||
SET (ESCARGOT_THIRDPARTY_CFLAGS ${ESCARGOT_THIRDPARTY_CFLAGS} -UKEEP_BACK_PTRS -USAVE_CALL_COUNT -UDBG_HDRS_ALL)
|
||||
ENDIF()
|
||||
ELSEIF (${ESCARGOT_HOST} STREQUAL "darwin" AND ${ESCARGOT_ARCH} STREQUAL "x64")
|
||||
ELSEIF (${ESCARGOT_HOST} STREQUAL "darwin")
|
||||
FIND_PACKAGE (PkgConfig REQUIRED)
|
||||
IF ((NOT ${ESCARGOT_ARCH} STREQUAL "x64") AND (NOT ${ESCARGOT_ARCH} STREQUAL "aarch64"))
|
||||
MESSAGE (FATAL_ERROR ${ESCARGOT_ARCH} " is unsupported")
|
||||
ENDIF()
|
||||
# recent macOS supports only ICU version 75 that requires c++17 or above
|
||||
SET (ESCARGOT_CXXFLAGS ${ESCARGOT_CXXFLAGS} -std=c++17)
|
||||
SET (ESCARGOT_LDFLAGS -lpthread -Wl,-dead_strip)
|
||||
SET (ESCARGOT_BUILD_64BIT_LARGE ON)
|
||||
# bdwgc mac cannot support pthread_getattr_np
|
||||
SET (ESCARGOT_THIRDPARTY_CFLAGS ${ESCARGOT_THIRDPARTY_CFLAGS} -UHAVE_PTHREAD_GETATTR_NP)
|
||||
# dlopen version not working correctly on mac
|
||||
IF (NOT DEFINED ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN)
|
||||
SET (ESCARGOT_LIBICU_SUPPORT_WITH_DLOPEN OFF)
|
||||
ENDIF()
|
||||
ELSEIF (${ESCARGOT_HOST} STREQUAL "windows")
|
||||
SET (ESCARGOT_LDFLAGS ${ESCARGOT_LDFLAGS} icu.lib)
|
||||
SET (ESCARGOT_CXXFLAGS ${ESCARGOT_CXXFLAGS} -DSTACK_LIMIT_FROM_BASE=1048576) # in windows, default stack limit is 1MB
|
||||
IF ((${ESCARGOT_ARCH} STREQUAL "x64") OR (${ESCARGOT_ARCH} STREQUAL "x86_64"))
|
||||
SET (ESCARGOT_BUILD_64BIT ON)
|
||||
SET (ESCARGOT_BUILD_64BIT_LARGE ON)
|
||||
|
|
|
|||
10
codecov.yml
Normal file
10
codecov.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
coverage:
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
target: 80%
|
||||
threshold: 1%
|
||||
|
||||
ignore:
|
||||
- "third_party"
|
||||
- "src/api"
|
||||
|
|
@ -115,9 +115,15 @@ Requires(postun): /sbin/ldconfig
|
|||
%define enable_shell 0
|
||||
%endif
|
||||
|
||||
%if 0%{?enable_small_config:1}
|
||||
%else
|
||||
%define enable_small_config 0
|
||||
%endif
|
||||
|
||||
# build requirements
|
||||
BuildRequires: cmake
|
||||
BuildRequires: ninja
|
||||
BuildRequires: python3
|
||||
BuildRequires: pkgconfig(dlog)
|
||||
BuildRequires: pkgconfig(bundle)
|
||||
|
||||
|
|
@ -254,14 +260,17 @@ CFLAGS+=' -Os '
|
|||
CXXFLAGS+=' -Os '
|
||||
%endif
|
||||
|
||||
CFLAGS+=' -Wno-shadow '
|
||||
CXXFLAGS+=' -Wno-shadow '
|
||||
|
||||
%if "%{?enable_test}" == "1"
|
||||
cmake CMakeLists.txt -H./ -Bbuild/out_tizen_%{rpm} -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir} -DTIZEN_MAJOR_VERSION='%{tizen_version_major}' \
|
||||
-DESCARGOT_ARCH='%{tizen_arch}' -DESCARGOT_WASM='%{enable_wasm}' -DESCARGOT_DEBUGGER='%{enable_debugger}' \
|
||||
-DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_MODE=release -DESCARGOT_HOST=tizen -DESCARGOT_OUTPUT=shared_lib -DESCARGOT_TEST=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -G Ninja
|
||||
-DESCARGOT_ARCH='%{tizen_arch}' -DESCARGOT_WASM='%{enable_wasm}' -DESCARGOT_DEBUGGER='%{enable_debugger}' -DESCARGOT_SMALL_CONFIG='%{enable_small_config}' \
|
||||
-DESCARGOT_THREADING=ON -DESCARGOT_TCO=ON -DESCARGOT_MODE=release -DESCARGOT_HOST=tizen -DESCARGOT_OUTPUT=shared_lib -DESCARGOT_TEST=ON -DESCARGOT_TEMPORAL=ON -DESCARGOT_TCO=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -G Ninja
|
||||
%else
|
||||
cmake CMakeLists.txt -H./ -Bbuild/out_tizen_%{rpm} -DLIBDIR=%{_libdir} -DINCLUDEDIR=%{_includedir} -DTIZEN_MAJOR_VERSION='%{tizen_version_major}' \
|
||||
-DESCARGOT_ARCH='%{tizen_arch}' -DESCARGOT_WASM='%{enable_wasm}' -DESCARGOT_DEBUGGER='%{enable_debugger}' \
|
||||
-DESCARGOT_THREADING=ON -DESCARGOT_MODE=release -DESCARGOT_HOST=tizen -DESCARGOT_OUTPUT=shared_lib -G Ninja
|
||||
-DESCARGOT_ARCH='%{tizen_arch}' -DESCARGOT_WASM='%{enable_wasm}' -DESCARGOT_DEBUGGER='%{enable_debugger}' -DESCARGOT_SMALL_CONFIG='%{enable_small_config}' \
|
||||
-DESCARGOT_THREADING=ON -DESCARGOT_TLS_ACCESS_BY_ADDRESS=ON -DESCARGOT_MODE=release -DESCARGOT_HOST=tizen -DESCARGOT_OUTPUT=shared_lib -G Ninja
|
||||
%endif
|
||||
|
||||
cmake --build build/out_tizen_%{rpm}
|
||||
|
|
@ -272,7 +281,7 @@ cmake --build build/out_tizen_%{rpm}
|
|||
CXXFLAGS+=' -DESCARGOT_ENABLE_TEST '
|
||||
%endif
|
||||
|
||||
g++ src/shell/Shell.cpp -std=c++11 -Lbuild/out_tizen_%{rpm} -Isrc/ -Ithird_party/GCutil -Ithird_party/GCutil/bdwgc/include -o build/out_tizen_%{rpm}/escargot -O2 -DNDEBUG -Wl,-rpath=\$ORIGIN ${CXXFLAGS} -lescargot -lpthread
|
||||
g++ src/shell/Shell.cpp -std=c++11 -Lbuild/out_tizen_%{rpm} -Isrc/ -Ithird_party/GCutil/include -o build/out_tizen_%{rpm}/escargot -O2 -DNDEBUG -Wl,-rpath=\$ORIGIN -Wl,-rpath=%{_libdir}/escargot ${CXXFLAGS} -lescargot -lpthread
|
||||
g++ tools/test/test-data-runner/test-data-runner.cpp -o build/out_tizen_%{rpm}/test-data-runner -std=c++11 ${CXXFLAGS} -lpthread
|
||||
%endif
|
||||
|
||||
|
|
@ -323,6 +332,7 @@ cp packaging/escargot.conf %{buildroot}%{_sysconfdir}/ld.so.conf.d/
|
|||
%files profile_tv
|
||||
%manifest packaging/%{name}.manifest
|
||||
%{_libdir}/escargot/libescargot.so*
|
||||
%{_sysconfdir}/ld.so.conf.d/*.conf
|
||||
%license LICENSE.BSD-2-Clause LICENSE.LGPL-2.1+ LICENSE.MPL-2.0 LICENSE.Apache-2.0 LICENSE.BSD-3-Clause LICENSE.MIT LICENSE.BOEHM-GC
|
||||
%endif
|
||||
|
||||
|
|
@ -330,6 +340,7 @@ cp packaging/escargot.conf %{buildroot}%{_sysconfdir}/ld.so.conf.d/
|
|||
%files profile_headless
|
||||
%manifest packaging/%{name}.manifest
|
||||
%{_libdir}/escargot/libescargot.so*
|
||||
%{_sysconfdir}/ld.so.conf.d/*.conf
|
||||
%license LICENSE.BSD-2-Clause LICENSE.LGPL-2.1+ LICENSE.MPL-2.0 LICENSE.Apache-2.0 LICENSE.BSD-3-Clause LICENSE.MIT LICENSE.BOEHM-GC
|
||||
%endif
|
||||
|
||||
|
|
|
|||
|
|
@ -264,6 +264,16 @@ if (f.type == Type::B) { puts("failed in msvc."); }
|
|||
#define HAVE_BUILTIN_ATOMIC_FUNCTIONS
|
||||
#endif
|
||||
|
||||
#if defined(COMPILER_CLANG)
|
||||
#if __has_feature(address_sanitizer)
|
||||
#define ASAN_ENABLED
|
||||
#endif
|
||||
#elif defined(COMPILER_GCC)
|
||||
#if defined(__SANITIZE_ADDRESS__)
|
||||
#define ASAN_ENABLED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(COMPILER_MSVC)
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
|
@ -285,14 +295,15 @@ extern "C" {
|
|||
|
||||
#ifdef ENABLE_ICU
|
||||
#if defined(ENABLE_RUNTIME_ICU_BINDER)
|
||||
typedef unsigned char LChar;
|
||||
#include "RuntimeICUBinder.h"
|
||||
#include "ICUPolyfill.h"
|
||||
#else
|
||||
|
||||
#define U_SHOW_CPLUSPLUS_API 0
|
||||
#define U_SHOW_CPLUSPLUS_HEADER_API 0
|
||||
#if defined(OS_WINDOWS)
|
||||
#include <icu.h>
|
||||
#else
|
||||
#include <unicode/utypes.h>
|
||||
#include <unicode/locid.h>
|
||||
#include <unicode/uchar.h>
|
||||
#include <unicode/ustring.h>
|
||||
|
|
@ -307,13 +318,16 @@ typedef unsigned char LChar;
|
|||
#include <unicode/unum.h> // for Intl
|
||||
#include <unicode/upluralrules.h> // for Intl
|
||||
#include <unicode/unumberformatter.h> // for Intl
|
||||
#include <unicode/unumberrangeformatter.h> // for Intl
|
||||
#include <unicode/ureldatefmt.h> // for Intl
|
||||
#include <unicode/uformattedvalue.h> // for Intl
|
||||
#include <unicode/ucurr.h> // for Intl
|
||||
#include <unicode/uloc.h> // for Intl
|
||||
#include <unicode/uldnames.h> // for Intl
|
||||
#include <unicode/ulistformatter.h> // for Intl
|
||||
|
||||
#include <unicode/ures.h> // for Intl
|
||||
#include <unicode/udateintervalformat.h> // for Intl
|
||||
#include <unicode/ubrk.h> // for Intl
|
||||
// FIXME replace these vzone decl into include
|
||||
// I declare vzone api because there is no header file in include folder
|
||||
extern "C" {
|
||||
|
|
@ -325,6 +339,11 @@ UBool vzone_getTZURL(VZone* zone, UChar*& url, int32_t& urlLength);
|
|||
void vzone_getOffset3(VZone* zone, UDate date, UBool local, int32_t& rawOffset,
|
||||
int32_t& dstOffset, UErrorCode& ec);
|
||||
int32_t vzone_getRawOffset(VZone* zone);
|
||||
|
||||
// uresimp.h
|
||||
U_CAPI UResourceBundle* U_EXPORT2
|
||||
ures_findResource(const char* pathToResource,
|
||||
UResourceBundle* fillIn, UErrorCode* status);
|
||||
}
|
||||
#endif // !defined(OS_WINDOWS_UWP)
|
||||
|
||||
|
|
@ -337,11 +356,13 @@ typedef unsigned char LChar;
|
|||
typedef int32_t UChar32;
|
||||
|
||||
// macros from icu
|
||||
#define U16_IS_LEAD(c) (((c)&0xfffffc00) == 0xd800)
|
||||
#define U16_IS_TRAIL(c) (((c)&0xfffffc00) == 0xdc00)
|
||||
#define U16_IS_LEAD(c) (((c) & 0xfffffc00) == 0xd800)
|
||||
#define U16_IS_TRAIL(c) (((c) & 0xfffffc00) == 0xdc00)
|
||||
#define U_IS_SURROGATE(c) (((c) & 0xfffff800) == 0xd800)
|
||||
#define U16_IS_SURROGATE(c) U_IS_SURROGATE(c)
|
||||
#define U16_SURROGATE_OFFSET ((0xd800 << 10UL) + 0xdc00 - 0x10000)
|
||||
#define U16_GET_SUPPLEMENTARY(lead, trail) \
|
||||
(((UChar32)(lead) << 10UL) + (UChar32)(trail)-U16_SURROGATE_OFFSET)
|
||||
(((UChar32)(lead) << 10UL) + (UChar32)(trail) - U16_SURROGATE_OFFSET)
|
||||
|
||||
#define U16_NEXT(s, i, length, c) \
|
||||
{ \
|
||||
|
|
@ -523,18 +544,26 @@ typedef uint16_t LexicalBlockIndex;
|
|||
#define STACK_GROWS_DOWN
|
||||
#endif
|
||||
|
||||
#ifndef STACK_LIMIT_FROM_BASE
|
||||
#define STACK_LIMIT_FROM_BASE (1024 * 1024 * 3) // 3MB
|
||||
#ifndef STACK_FREESPACE_FROM_LIMIT
|
||||
#define STACK_FREESPACE_FROM_LIMIT (1024 * 256) // 256KB
|
||||
#endif
|
||||
|
||||
#ifndef STACK_USAGE_LIMIT
|
||||
#ifdef ESCARGOT_ENABLE_TEST
|
||||
#define STACK_USAGE_LIMIT (1024 * 1024 * 2) // 2MB
|
||||
#else
|
||||
#define STACK_USAGE_LIMIT (1024 * 1024 * 4) // 4MB
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef STACK_GROWS_DOWN
|
||||
#define CHECK_STACK_OVERFLOW(state) \
|
||||
if (UNLIKELY(state.stackLimit() > (size_t)currentStackPointer())) { \
|
||||
if (UNLIKELY(ThreadLocal::stackLimit() > (size_t)currentStackPointer())) { \
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, "Maximum call stack size exceeded"); \
|
||||
}
|
||||
#else
|
||||
#define CHECK_STACK_OVERFLOW(state) \
|
||||
if (UNLIKELY(state.stackLimit() < (size_t)currentStackPointer())) { \
|
||||
if (UNLIKELY(ThreadLocal::stackLimit() < (size_t)currentStackPointer())) { \
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, "Maximum call stack size exceeded"); \
|
||||
}
|
||||
#endif
|
||||
|
|
@ -560,7 +589,31 @@ typedef uint16_t LexicalBlockIndex;
|
|||
#define REGEXP_CACHE_SIZE_MAX 64
|
||||
#endif
|
||||
|
||||
// maximum number of tail call arguments allowed
|
||||
#ifndef TCO_ARGUMENT_COUNT_LIMIT
|
||||
#define TCO_ARGUMENT_COUNT_LIMIT 8
|
||||
#endif
|
||||
|
||||
#include <tsl/robin_set.h>
|
||||
#include <tsl/robin_map.h>
|
||||
|
||||
namespace Escargot {
|
||||
|
||||
#if defined(ESCARGOT_SMALL_CONFIG)
|
||||
template <class Key, class Hash = std::hash<Key>,
|
||||
class KeyEqual = std::equal_to<Key>,
|
||||
class Allocator = std::allocator<Key>,
|
||||
bool StoreHash = false,
|
||||
class GrowthPolicy = tsl::rh::mod_growth_policy<std::ratio<5, 4>>>
|
||||
using HashSet = tsl::robin_set<Key, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy>;
|
||||
|
||||
template <class Key, class T, class Hash = std::hash<Key>,
|
||||
class KeyEqual = std::equal_to<Key>,
|
||||
class Allocator = std::allocator<std::pair<Key, T>>,
|
||||
bool StoreHash = false,
|
||||
class GrowthPolicy = tsl::rh::mod_growth_policy<std::ratio<5, 4>>>
|
||||
using HashMap = tsl::robin_map<Key, T, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy>;
|
||||
#else
|
||||
template <class Key, class Hash = std::hash<Key>,
|
||||
class KeyEqual = std::equal_to<Key>,
|
||||
class Allocator = std::allocator<Key>,
|
||||
|
|
@ -568,18 +621,21 @@ template <class Key, class Hash = std::hash<Key>,
|
|||
class GrowthPolicy = tsl::rh::power_of_two_growth_policy<2>>
|
||||
using HashSet = tsl::robin_set<Key, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy>;
|
||||
|
||||
#include <tsl/robin_map.h>
|
||||
template <class Key, class T, class Hash = std::hash<Key>,
|
||||
class KeyEqual = std::equal_to<Key>,
|
||||
class Allocator = std::allocator<std::pair<Key, T>>,
|
||||
bool StoreHash = false,
|
||||
class GrowthPolicy = tsl::rh::power_of_two_growth_policy<2>>
|
||||
using HashMap = tsl::robin_map<Key, T, Hash, KeyEqual, Allocator, StoreHash, GrowthPolicy>;
|
||||
#endif
|
||||
} // namespace Escargot
|
||||
|
||||
|
||||
#include "EscargotInfo.h"
|
||||
#include "heap/Heap.h"
|
||||
#include "util/Util.h"
|
||||
#include "util/Optional.h"
|
||||
#include "util/Variant.h"
|
||||
#include "runtime/ThreadLocal.h"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -84,12 +84,14 @@
|
|||
F(RangeErrorObject) \
|
||||
F(ReferenceErrorObject) \
|
||||
F(SyntaxErrorObject) \
|
||||
F(SuppressedErrorObject) \
|
||||
F(TypeErrorObject) \
|
||||
F(URIErrorObject)
|
||||
|
||||
#define ESCARGOT_TYPEDARRAY_REF_LIST(F) \
|
||||
F(BigInt64ArrayObject) \
|
||||
F(BigUint64ArrayObject) \
|
||||
F(Float16ArrayObject) \
|
||||
F(Float32ArrayObject) \
|
||||
F(Float64ArrayObject) \
|
||||
F(Int16ArrayObject) \
|
||||
|
|
@ -152,23 +154,42 @@ public:
|
|||
static void* gcMallocUncollectable(size_t siz); // allocate memory it can hold gc-allocated pointer & it is never collect by gc
|
||||
static void* gcMallocAtomicUncollectable(size_t siz); // allocate memory it can not hold gc-allocated pointer & it is never collect by gc
|
||||
static void gcFree(void* ptr);
|
||||
typedef void (*GCAllocatedMemoryFinalizer)(void* self);
|
||||
typedef void (*GCAllocatedMemoryFinalizer)(void* self, void* callbackData);
|
||||
|
||||
// gcRegisterFinalizer
|
||||
// 1. if you want to free memory explicitly, you must remove registered finalizer
|
||||
// if there was no finalizer, you can just free memory
|
||||
// ex) void* gcPointer;
|
||||
// gcRegisterFinalizer(gcPointer, ....);
|
||||
// Memory::gcRegisterFinalizer(gcPointer, callback...);
|
||||
// ......
|
||||
// gcRegisterFinalizer(gcPointer, nullptr); // this removes finalizer
|
||||
// Memory::gcUnregisterFinalizer(gcPointer, callback...); // this removes finalizer
|
||||
// Memory::gcFree(gcPointer);
|
||||
static void gcRegisterFinalizer(void* ptr, GCAllocatedMemoryFinalizer callback);
|
||||
// 2. the data parameter will be considered accessible by gc.
|
||||
static void gcRegisterFinalizer(void* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
static void gcUnregisterFinalizer(void* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
static bool gcHasFinalizer(void* ptr);
|
||||
static bool gcHasFinalizer(void* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
|
||||
static void gcRegisterFinalizer(ObjectRef* ptr, GCAllocatedMemoryFinalizer callback);
|
||||
static void gcUnregisterFinalizer(ObjectRef* ptr, GCAllocatedMemoryFinalizer callback);
|
||||
static void gcRegisterFinalizer(ValueRef* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
static void gcUnregisterFinalizer(ValueRef* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
static bool gcHasFinalizer(ValueRef* ptr);
|
||||
static bool gcHasFinalizer(ValueRef* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
|
||||
static void gcRegisterFinalizer(ObjectRef* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
static void gcUnregisterFinalizer(ObjectRef* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
static bool gcHasFinalizer(ObjectRef* ptr);
|
||||
static bool gcHasFinalizer(ObjectRef* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
|
||||
static void gcRegisterFinalizer(SymbolRef* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
static void gcUnregisterFinalizer(SymbolRef* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
static bool gcHasFinalizer(SymbolRef* ptr);
|
||||
static bool gcHasFinalizer(SymbolRef* ptr, GCAllocatedMemoryFinalizer callback, void* data);
|
||||
|
||||
static void gc();
|
||||
|
||||
static void disableGC();
|
||||
static void enableGC();
|
||||
|
||||
static size_t heapSize(); // Return the number of bytes in the heap. Excludes bdwgc private data structures. Excludes the unmapped memory
|
||||
static size_t totalSize(); // Return the total number of bytes allocated in this process
|
||||
|
||||
|
|
@ -189,9 +210,39 @@ public:
|
|||
static void setGCFrequency(size_t value = 1);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT PersistentRefHolderBase {
|
||||
public:
|
||||
void setWeak();
|
||||
void clearWeak();
|
||||
bool isWeak();
|
||||
|
||||
protected:
|
||||
PersistentRefHolderBase()
|
||||
{
|
||||
m_holder = nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void initHolderSpace(T* initialValue)
|
||||
{
|
||||
m_holder = reinterpret_cast<void**>(Memory::gcMallocUncollectable(sizeof(T*)));
|
||||
*(reinterpret_cast<T**>(m_holder)) = initialValue;
|
||||
}
|
||||
|
||||
void destoryHolderSpace()
|
||||
{
|
||||
if (m_holder) {
|
||||
Memory::gcFree(m_holder);
|
||||
}
|
||||
m_holder = nullptr;
|
||||
}
|
||||
|
||||
void** m_holder;
|
||||
};
|
||||
|
||||
// NOTE only {stack, kinds of PersistentHolders} are root set. if you store the data you need on other space, you may lost your data
|
||||
template <typename T>
|
||||
class ESCARGOT_EXPORT PersistentRefHolder {
|
||||
class ESCARGOT_EXPORT PersistentRefHolder : public PersistentRefHolderBase {
|
||||
public:
|
||||
~PersistentRefHolder()
|
||||
{
|
||||
|
|
@ -200,7 +251,6 @@ public:
|
|||
|
||||
PersistentRefHolder()
|
||||
{
|
||||
m_holder = nullptr;
|
||||
}
|
||||
|
||||
PersistentRefHolder(T* ptr)
|
||||
|
|
@ -240,18 +290,22 @@ public:
|
|||
|
||||
operator T*()
|
||||
{
|
||||
return *m_holder;
|
||||
return m_holder ? *(reinterpret_cast<T**>(m_holder)) : nullptr;
|
||||
}
|
||||
|
||||
T* get()
|
||||
{
|
||||
return *m_holder;
|
||||
if (m_holder) {
|
||||
return *(reinterpret_cast<T**>(m_holder));
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
T* release()
|
||||
{
|
||||
if (m_holder) {
|
||||
T* ptr = *m_holder;
|
||||
T* ptr = *(reinterpret_cast<T**>(m_holder));
|
||||
destoryHolderSpace();
|
||||
return ptr;
|
||||
}
|
||||
|
|
@ -260,25 +314,8 @@ public:
|
|||
|
||||
T* operator->()
|
||||
{
|
||||
return *m_holder;
|
||||
return *(reinterpret_cast<T**>(m_holder));
|
||||
}
|
||||
|
||||
private:
|
||||
void initHolderSpace(T* initialValue)
|
||||
{
|
||||
m_holder = (T**)Memory::gcMallocUncollectable(sizeof(T*));
|
||||
*m_holder = initialValue;
|
||||
}
|
||||
|
||||
void destoryHolderSpace()
|
||||
{
|
||||
if (m_holder) {
|
||||
Memory::gcFree(m_holder);
|
||||
}
|
||||
m_holder = nullptr;
|
||||
}
|
||||
|
||||
T** m_holder;
|
||||
};
|
||||
|
||||
class PersistentValueRefMap {
|
||||
|
|
@ -581,34 +618,40 @@ public:
|
|||
template <typename... Args, typename F>
|
||||
static EvaluatorResult execute(ContextRef* ctx, F&& closure, Args... args)
|
||||
{
|
||||
typedef ValueRef* (*Closure)(ExecutionStateRef * state, Args...);
|
||||
typedef ValueRef* (*Closure)(ExecutionStateRef* state, Args...);
|
||||
return executeImpl(ctx, Closure(closure), args...);
|
||||
}
|
||||
|
||||
template <typename... Args, typename F>
|
||||
static EvaluatorResult execute(ExecutionStateRef* parent, F&& closure, Args... args)
|
||||
{
|
||||
typedef ValueRef* (*Closure)(ExecutionStateRef* state, Args...);
|
||||
return executeImpl(parent, Closure(closure), args...);
|
||||
}
|
||||
|
||||
static EvaluatorResult executeFunction(ContextRef* ctx, ValueRef* (*runner)(ExecutionStateRef* state, void* passedData), void* data);
|
||||
static EvaluatorResult executeFunction(ContextRef* ctx, ValueRef* (*runner)(ExecutionStateRef* state, void* passedData, void* passedData2), void* data, void* data2);
|
||||
static EvaluatorResult executeFunction(ExecutionStateRef* parent, ValueRef* (*runner)(ExecutionStateRef* state, void* passedData, void* passedData2), void* data, void* data2);
|
||||
|
||||
private:
|
||||
template <typename... Args>
|
||||
static EvaluatorResult executeImpl(ContextRef* ctx, ValueRef* (*fn)(ExecutionStateRef* state, Args...), Args... args)
|
||||
template <typename P, typename... Args>
|
||||
static EvaluatorResult executeImpl(P* p, ValueRef* (*fn)(ExecutionStateRef* state, Args...), Args... args)
|
||||
{
|
||||
typedef ValueRef* (*Closure)(ExecutionStateRef * state, Args...);
|
||||
typedef ValueRef* (*Closure)(ExecutionStateRef* state, Args...);
|
||||
std::tuple<ExecutionStateRef*, Args...> tuple = std::tuple<ExecutionStateRef*, Args...>(nullptr, args...);
|
||||
|
||||
return executeFunction(ctx, [](ExecutionStateRef* state, void* tuplePtr, void* fnPtr) -> ValueRef* {
|
||||
return executeFunction(p, [](ExecutionStateRef* state, void* tuplePtr, void* fnPtr) -> ValueRef* {
|
||||
std::tuple<ExecutionStateRef*, Args...>* tuple = (std::tuple<ExecutionStateRef*, Args...>*)tuplePtr;
|
||||
Closure fn = (Closure)fnPtr;
|
||||
|
||||
std::get<0>(*tuple) = state;
|
||||
|
||||
return EvaluatorUtil::applyTupleIntoArgumentsOfVariadicTemplateFunction(fn, *tuple);
|
||||
},
|
||||
&tuple, (void*)fn);
|
||||
return EvaluatorUtil::applyTupleIntoArgumentsOfVariadicTemplateFunction(fn, *tuple); }, &tuple, (void*)fn);
|
||||
}
|
||||
};
|
||||
|
||||
// temporally disable StackOverflow check
|
||||
// StackOverflowDisabler only unlocks the predefined stack limit (STACK_LIMIT_FROM_BASE: 3MB)
|
||||
// StackOverflowDisabler only unlocks the predefined stack limit (STACK_USAGE_LIMIT: 4MB)
|
||||
// should be carefully used because it cannot prevent the system-stackoverflow exception
|
||||
class ESCARGOT_EXPORT StackOverflowDisabler {
|
||||
public:
|
||||
|
|
@ -628,6 +671,7 @@ public:
|
|||
GCManagedVector<FunctionObjectRef*> resolveCallstack(); // resolve list of callee
|
||||
GlobalObjectRef* resolveCallerLexicalGlobalObject(); // resolve caller's lexical global object
|
||||
|
||||
// only enabled when `ENABLE_EXTENDED_API` macro is set (default: disabled)
|
||||
bool onTry();
|
||||
bool onCatch();
|
||||
bool onFinally();
|
||||
|
|
@ -653,6 +697,8 @@ public:
|
|||
|
||||
// register ErrorCallback which is triggered when each Error constructor (e.g. new TypeError()) invoked or thrown
|
||||
// parameter `err` stands for the newly created ErrorObject
|
||||
// these functions are used only for third party usage
|
||||
// only enabled when `ENABLE_EXTENDED_API` macro is set (default: disabled)
|
||||
typedef void (*ErrorCallback)(ExecutionStateRef* state, ErrorObjectRef* err);
|
||||
void registerErrorCreationCallback(ErrorCallback cb);
|
||||
void registerErrorThrowCallback(ErrorCallback cb);
|
||||
|
|
@ -683,10 +729,21 @@ public:
|
|||
void registerPromiseRejectCallback(PromiseRejectCallback);
|
||||
void unregisterPromiseRejectCallback();
|
||||
|
||||
enum class ConfigFlag {
|
||||
CompressCompressibleStringsWhileGC = 1,
|
||||
PruneCompiledByteCodesWhileGC = 1 << 1,
|
||||
|
||||
CompressCompressibleStringsEnterIdle = 1 << 3,
|
||||
PruneCompiledByteCodesEnterIdle = 1 << 4,
|
||||
UnloadReloadableStringsEnterIdle = 1 << 5,
|
||||
};
|
||||
size_t config();
|
||||
void setConfig(size_t s);
|
||||
|
||||
// this function enforce do gc,
|
||||
// remove every compiled bytecodes,
|
||||
// remove every compiled bytecodes(if enabled),
|
||||
// remove regexp cache,
|
||||
// and compress every comressible strings if we can
|
||||
// and compress every comressible strings(if enabled) if we can
|
||||
void enterIdleMode();
|
||||
// force clear every caches related with context
|
||||
// you can call this function if you don't want to use every alive contexts
|
||||
|
|
@ -705,13 +762,28 @@ public:
|
|||
SymbolRef* replaceSymbol();
|
||||
SymbolRef* splitSymbol();
|
||||
SymbolRef* asyncIteratorSymbol();
|
||||
SymbolRef* disposeSymbol();
|
||||
SymbolRef* asyncDisposeSymbol();
|
||||
|
||||
bool hasPendingJob();
|
||||
Evaluator::EvaluatorResult executePendingJob();
|
||||
typedef ValueRef* (*EvaluateJobCallback)(ExecutionStateRef* state, void* data);
|
||||
void enqueueEvaluateJob(ContextRef* relatedContext, EvaluateJobCallback callback, void* data);
|
||||
|
||||
bool hasPendingJobFromAnotherThread();
|
||||
bool waitEventFromAnotherThread(unsigned timeoutInMillisecond = 0); // zero means infinity
|
||||
void executePendingJobFromAnotherThread();
|
||||
|
||||
size_t maxCompiledByteCodeSize();
|
||||
void setMaxCompiledByteCodeSize(size_t s);
|
||||
|
||||
bool isCodeCacheEnabled();
|
||||
size_t codeCacheMinSourceLength();
|
||||
void setCodeCacheMinSourceLength(size_t s);
|
||||
size_t codeCacheMaxCacheCount();
|
||||
void setCodeCacheMaxCacheCount(size_t s);
|
||||
bool codeCacheShouldLoadFunctionOnScriptLoading();
|
||||
void setCodeCacheShouldLoadFunctionOnScriptLoading(bool s);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT DebuggerOperationsRef {
|
||||
|
|
@ -848,6 +920,7 @@ public:
|
|||
// Base class for debugger callbacks
|
||||
class DebuggerClient {
|
||||
public:
|
||||
virtual ~DebuggerClient() {};
|
||||
virtual void parseCompleted(StringRef* source, StringRef* srcName, std::vector<DebuggerOperationsRef::BreakpointLocationsInfo*>& breakpointLocationsVector) = 0;
|
||||
virtual void parseError(StringRef* source, StringRef* srcName, StringRef* error) = 0;
|
||||
virtual void codeReleased(WeakCodeRef* weakCodeRef) = 0;
|
||||
|
|
@ -874,17 +947,21 @@ public:
|
|||
// this setter try to update `globalThis` value on GlobalObject
|
||||
void setGlobalObjectProxy(ObjectRef* newGlobalObjectProxy);
|
||||
|
||||
void throwException(ValueRef* exceptionValue); // if you use this function without Evaluator, your program will crash :(
|
||||
bool canThrowException();
|
||||
void throwException(ValueRef* exceptionValue);
|
||||
|
||||
bool initDebugger(DebuggerOperationsRef::DebuggerClient* debuggerClient);
|
||||
bool initDebuggerClient(DebuggerOperationsRef::DebuggerClient* debuggerClient);
|
||||
bool disableDebugger();
|
||||
// available options(separator is ';')
|
||||
// "--port=6501", default for TCP debugger
|
||||
bool initDebuggerRemote(const char* options);
|
||||
bool initDebugger(const char* options);
|
||||
bool isDebuggerRunning();
|
||||
bool isWaitBeforeExit();
|
||||
bool isDebuggerRestartTrue();
|
||||
void printDebugger(StringRef* output);
|
||||
void pumpDebuggerEvents();
|
||||
void setAsAlwaysStopState();
|
||||
void setDebuggerRestart();
|
||||
StringRef* getClientSource(StringRef** sourceName);
|
||||
|
||||
typedef OptionalRef<ValueRef> (*VirtualIdentifierCallback)(ExecutionStateRef* state, ValueRef* name);
|
||||
|
|
@ -1011,6 +1088,8 @@ public:
|
|||
bool instanceOf(ExecutionStateRef* state, const ValueRef* other) const;
|
||||
ValueRef* call(ExecutionStateRef* state, ValueRef* receiver, const size_t argc, ValueRef** argv);
|
||||
ValueRef* construct(ExecutionStateRef* state, const size_t argc, ValueRef** argv); // same with new expression in js
|
||||
// call constrictor with already created object
|
||||
void callConstructor(ExecutionStateRef* state, ObjectRef* receiver, const size_t argc, ValueRef** argv);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT ValueVectorRef {
|
||||
|
|
@ -1141,7 +1220,8 @@ class ESCARGOT_EXPORT SymbolRef : public PointerValueRef {
|
|||
public:
|
||||
static SymbolRef* create(OptionalRef<StringRef> desc);
|
||||
static SymbolRef* fromGlobalSymbolRegistry(VMInstanceRef* context, StringRef* desc); // this is same with Symbol.for
|
||||
OptionalRef<StringRef> description();
|
||||
StringRef* descriptionString();
|
||||
ValueRef* descriptionValue();
|
||||
StringRef* symbolDescriptiveString();
|
||||
};
|
||||
|
||||
|
|
@ -1377,6 +1457,7 @@ public:
|
|||
ValueRef* getPrototype(ExecutionStateRef* state);
|
||||
OptionalRef<ObjectRef> getPrototypeObject(ExecutionStateRef* state); // if __proto__ is not object(undefined or null), this function returns nullptr instead of orginal value.
|
||||
bool setPrototype(ExecutionStateRef* state, ValueRef* value);
|
||||
bool setObjectPrototype(ExecutionStateRef* state, ValueRef* value); // explicitly call Object::setPrototype
|
||||
|
||||
StringRef* constructorName(ExecutionStateRef* state);
|
||||
|
||||
|
|
@ -1389,6 +1470,11 @@ public:
|
|||
// get `length` property like ToLength(Get(obj, "length"))
|
||||
// it returns 0 for exceptional cases (e.g. undefined, nan)
|
||||
uint64_t length(ExecutionStateRef* state);
|
||||
void setLength(ExecutionStateRef* state, uint64_t newLength);
|
||||
|
||||
IteratorObjectRef* values(ExecutionStateRef* state);
|
||||
IteratorObjectRef* keys(ExecutionStateRef* state);
|
||||
IteratorObjectRef* entries(ExecutionStateRef* state);
|
||||
|
||||
bool isExtensible(ExecutionStateRef* state);
|
||||
bool preventExtensions(ExecutionStateRef* state);
|
||||
|
|
@ -1396,12 +1482,13 @@ public:
|
|||
|
||||
void* extraData();
|
||||
void setExtraData(void* e);
|
||||
#if defined(ESCARGOT_ENABLE_TEST)
|
||||
// this function is used only for test purpose
|
||||
void setIsHTMLDDA();
|
||||
#endif
|
||||
|
||||
void removeFromHiddenClassChain();
|
||||
|
||||
void preparePropertyStorageForPropertyAddition(size_t expandCount);
|
||||
|
||||
// DEPRECATED! this function will be removed
|
||||
void removeFromHiddenClassChain(ExecutionStateRef* state);
|
||||
};
|
||||
|
|
@ -1429,6 +1516,8 @@ public:
|
|||
ObjectRef* evalErrorPrototype();
|
||||
FunctionObjectRef* aggregateError();
|
||||
ObjectRef* aggregateErrorPrototype();
|
||||
FunctionObjectRef* suppressedError();
|
||||
ObjectRef* suppressedErrorPrototype();
|
||||
FunctionObjectRef* string();
|
||||
ObjectRef* stringPrototype();
|
||||
FunctionObjectRef* number();
|
||||
|
|
@ -1447,6 +1536,12 @@ public:
|
|||
FunctionObjectRef* jsonParse();
|
||||
|
||||
FunctionObjectRef* promise();
|
||||
FunctionObjectRef* promiseAll();
|
||||
FunctionObjectRef* promiseAllSettled();
|
||||
FunctionObjectRef* promiseAny();
|
||||
FunctionObjectRef* promiseRace();
|
||||
FunctionObjectRef* promiseReject();
|
||||
FunctionObjectRef* promiseResolve();
|
||||
ObjectRef* promisePrototype();
|
||||
|
||||
FunctionObjectRef* arrayBuffer();
|
||||
|
|
@ -1467,6 +1562,8 @@ public:
|
|||
ObjectRef* uint32ArrayPrototype();
|
||||
ObjectRef* uint8ClampedArray();
|
||||
ObjectRef* uint8ClampedArrayPrototype();
|
||||
ObjectRef* float16Array();
|
||||
ObjectRef* float16ArrayPrototype();
|
||||
ObjectRef* float32Array();
|
||||
ObjectRef* float32ArrayPrototype();
|
||||
ObjectRef* float64Array();
|
||||
|
|
@ -1544,6 +1641,9 @@ public:
|
|||
static FunctionObjectRef* create(ExecutionStateRef* state, AtomicStringRef* functionName, size_t argumentCount, ValueRef** argumentNameArray, ValueRef* body);
|
||||
static FunctionObjectRef* create(ExecutionStateRef* state, StringRef* sourceName, AtomicStringRef* functionName, size_t argumentCount, ValueRef** argumentNameArray, ValueRef* body);
|
||||
|
||||
// returns associate context
|
||||
ContextRef* context();
|
||||
|
||||
// get prototype property of constructible function(not [[prototype]])
|
||||
// this property is used for new object construction. see https://www.ecma-international.org/ecma-262/6.0/#sec-ordinarycreatefromconstructor
|
||||
ValueRef* getFunctionPrototype(ExecutionStateRef* state);
|
||||
|
|
@ -1577,9 +1677,6 @@ public:
|
|||
static ArrayObjectRef* create(ExecutionStateRef* state);
|
||||
static ArrayObjectRef* create(ExecutionStateRef* state, const uint64_t size);
|
||||
static ArrayObjectRef* create(ExecutionStateRef* state, ValueVectorRef* source);
|
||||
IteratorObjectRef* values(ExecutionStateRef* state);
|
||||
IteratorObjectRef* keys(ExecutionStateRef* state);
|
||||
IteratorObjectRef* entries(ExecutionStateRef* state);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT ErrorObjectRef : public ObjectRef {
|
||||
|
|
@ -1593,8 +1690,10 @@ public:
|
|||
URIError,
|
||||
EvalError,
|
||||
AggregateError,
|
||||
SuppressedError,
|
||||
};
|
||||
static ErrorObjectRef* create(ExecutionStateRef* state, ErrorObjectRef::Code code, StringRef* errorMessage);
|
||||
void updateStackTraceData(ExecutionStateRef* state); // update stacktrace data
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT ReferenceErrorObjectRef : public ErrorObjectRef {
|
||||
|
|
@ -1632,6 +1731,11 @@ public:
|
|||
static AggregateErrorObjectRef* create(ExecutionStateRef* state, StringRef* errorMessage);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT SuppressedErrorObjectRef : public ErrorObjectRef {
|
||||
public:
|
||||
static SuppressedErrorObjectRef* create(ExecutionStateRef* state, StringRef* errorMessage, ValueRef* error, ValueRef* suppressed);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT DateObjectRef : public ObjectRef {
|
||||
public:
|
||||
static DateObjectRef* create(ExecutionStateRef* state);
|
||||
|
|
@ -1686,12 +1790,14 @@ class ESCARGOT_EXPORT RegExpObjectRef : public ObjectRef {
|
|||
public:
|
||||
enum RegExpObjectOption {
|
||||
None = 0 << 0,
|
||||
Global = 1 << 0,
|
||||
IgnoreCase = 1 << 1,
|
||||
MultiLine = 1 << 2,
|
||||
Sticky = 1 << 3,
|
||||
Unicode = 1 << 4,
|
||||
DotAll = 1 << 5,
|
||||
HasIndices = 1 << 0,
|
||||
Global = 1 << 1,
|
||||
IgnoreCase = 1 << 2,
|
||||
MultiLine = 1 << 3,
|
||||
DotAll = 1 << 4,
|
||||
Unicode = 1 << 5,
|
||||
UnicodeSets = 1 << 6,
|
||||
Sticky = 1 << 7,
|
||||
};
|
||||
|
||||
struct ESCARGOT_EXPORT RegexMatchResult {
|
||||
|
|
@ -1810,6 +1916,11 @@ public:
|
|||
static Uint8ClampedArrayObjectRef* create(ExecutionStateRef* state);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT Float16ArrayObjectRef : public ArrayBufferViewRef {
|
||||
public:
|
||||
static Float16ArrayObjectRef* create(ExecutionStateRef* state);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT Float32ArrayObjectRef : public ArrayBufferViewRef {
|
||||
public:
|
||||
static Float32ArrayObjectRef* create(ExecutionStateRef* state);
|
||||
|
|
@ -1843,8 +1954,9 @@ public:
|
|||
ValueRef* promiseResult();
|
||||
|
||||
ObjectRef* then(ExecutionStateRef* state, ValueRef* handler);
|
||||
ObjectRef* catchOperation(ExecutionStateRef* state, ValueRef* handler);
|
||||
ObjectRef* then(ExecutionStateRef* state, ValueRef* onFulfilled, ValueRef* onRejected);
|
||||
ObjectRef* catchOperation(ExecutionStateRef* state, ValueRef* handler);
|
||||
|
||||
void fulfill(ExecutionStateRef* state, ValueRef* value);
|
||||
void reject(ExecutionStateRef* state, ValueRef* reason);
|
||||
|
||||
|
|
@ -1869,17 +1981,14 @@ public:
|
|||
bool deleteOperation(ExecutionStateRef* state, ValueRef* key);
|
||||
bool has(ExecutionStateRef* state, ValueRef* key);
|
||||
size_t size(ExecutionStateRef* state);
|
||||
IteratorObjectRef* values(ExecutionStateRef* state);
|
||||
IteratorObjectRef* keys(ExecutionStateRef* state);
|
||||
IteratorObjectRef* entries(ExecutionStateRef* state);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT WeakSetObjectRef : public ObjectRef {
|
||||
public:
|
||||
static WeakSetObjectRef* create(ExecutionStateRef* state);
|
||||
void add(ExecutionStateRef* state, ObjectRef* key);
|
||||
bool deleteOperation(ExecutionStateRef* state, ObjectRef* key);
|
||||
bool has(ExecutionStateRef* state, ObjectRef* key);
|
||||
bool add(ExecutionStateRef* state, ValueRef* key);
|
||||
bool deleteOperation(ExecutionStateRef* state, ValueRef* key);
|
||||
bool has(ExecutionStateRef* state, ValueRef* key);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT MapObjectRef : public ObjectRef {
|
||||
|
|
@ -1891,26 +2000,23 @@ public:
|
|||
bool has(ExecutionStateRef* state, ValueRef* key);
|
||||
void set(ExecutionStateRef* state, ValueRef* key, ValueRef* value);
|
||||
size_t size(ExecutionStateRef* state);
|
||||
IteratorObjectRef* values(ExecutionStateRef* state);
|
||||
IteratorObjectRef* keys(ExecutionStateRef* state);
|
||||
IteratorObjectRef* entries(ExecutionStateRef* state);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT WeakMapObjectRef : public ObjectRef {
|
||||
public:
|
||||
static WeakMapObjectRef* create(ExecutionStateRef* state);
|
||||
bool deleteOperation(ExecutionStateRef* state, ObjectRef* key);
|
||||
ValueRef* get(ExecutionStateRef* state, ObjectRef* key);
|
||||
bool has(ExecutionStateRef* state, ObjectRef* key);
|
||||
void set(ExecutionStateRef* state, ObjectRef* key, ValueRef* value);
|
||||
bool deleteOperation(ExecutionStateRef* state, ValueRef* key);
|
||||
ValueRef* get(ExecutionStateRef* state, ValueRef* key);
|
||||
bool has(ExecutionStateRef* state, ValueRef* key);
|
||||
void set(ExecutionStateRef* state, ValueRef* key, ValueRef* value);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT WeakRefObjectRef : public ObjectRef {
|
||||
public:
|
||||
static WeakRefObjectRef* create(ExecutionStateRef* state, ObjectRef* target);
|
||||
static OptionalRef<WeakRefObjectRef> create(ExecutionStateRef* state, ValueRef* target);
|
||||
// returns true if target is alive
|
||||
bool deleteOperation(ExecutionStateRef* state);
|
||||
OptionalRef<ObjectRef> deref();
|
||||
OptionalRef<PointerValueRef> deref();
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT FinalizationRegistryObjectRef : public ObjectRef {
|
||||
|
|
@ -1922,6 +2028,7 @@ public:
|
|||
// it is not intented operation
|
||||
// Note) only String or Symbol type is allowed for `propertyName`
|
||||
// because TemplateRef is set without ExecutionStateRef, so property name conversion is impossible.
|
||||
// only enabled when `ENABLE_EXTENDED_API` macro is set (default: disabled)
|
||||
class ESCARGOT_EXPORT TemplateRef {
|
||||
public:
|
||||
void set(ValueRef* propertyName, ValueRef* data, bool isWritable, bool isEnumerable, bool isConfigurable);
|
||||
|
|
@ -2005,13 +2112,7 @@ struct ESCARGOT_EXPORT ObjectTemplatePropertyHandlerConfiguration {
|
|||
}
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT SerializerRef {
|
||||
public:
|
||||
// returns the serialization was successful
|
||||
static bool serializeInto(ValueRef* value, std::ostringstream& output);
|
||||
static ValueRef* deserializeFrom(ContextRef* context, std::istringstream& input);
|
||||
};
|
||||
|
||||
// only enabled when `ENABLE_EXTENDED_API` macro is set (default: disabled)
|
||||
class ESCARGOT_EXPORT ObjectTemplateRef : public TemplateRef {
|
||||
public:
|
||||
static ObjectTemplateRef* create();
|
||||
|
|
@ -2028,6 +2129,7 @@ public:
|
|||
};
|
||||
|
||||
// FunctionTemplateRef returns the unique function instance in context.
|
||||
// only enabled when `ENABLE_EXTENDED_API` macro is set (default: disabled)
|
||||
class ESCARGOT_EXPORT FunctionTemplateRef : public TemplateRef {
|
||||
public:
|
||||
// in constructor call, thisValue is default consturcted object
|
||||
|
|
@ -2050,6 +2152,13 @@ public:
|
|||
OptionalRef<FunctionTemplateRef> parent();
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT SerializerRef {
|
||||
public:
|
||||
// returns the serialization was successful
|
||||
static bool serializeInto(ValueRef* value, std::ostringstream& output);
|
||||
static ValueRef* deserializeFrom(ContextRef* context, std::istringstream& input);
|
||||
};
|
||||
|
||||
class ESCARGOT_EXPORT ScriptParserRef {
|
||||
public:
|
||||
struct ESCARGOT_EXPORT InitializeScriptResult {
|
||||
|
|
@ -2128,7 +2237,7 @@ public:
|
|||
{
|
||||
return calloc(sizeInByte, 1);
|
||||
}
|
||||
virtual void onFreeArrayBufferObjectDataBuffer(void* buffer, size_t sizeInByte)
|
||||
virtual void onFreeArrayBufferObjectDataBuffer(void* buffer, size_t sizeInByte, void* deleterData)
|
||||
{
|
||||
return free(buffer);
|
||||
}
|
||||
|
|
@ -2216,7 +2325,6 @@ public:
|
|||
static ValueRef* copyStableBufferBytes(ExecutionStateRef* state, ValueRef* source);
|
||||
static ObjectRef* asyncCompileModule(ExecutionStateRef* state, ValueRef* source);
|
||||
static ObjectRef* instantiatePromiseOfModuleWithImportObject(ExecutionStateRef* state, PromiseObjectRef* promiseOfModule, ValueRef* importObj);
|
||||
static void collectHeap();
|
||||
};
|
||||
|
||||
} // namespace Escargot
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -36,7 +36,7 @@ static Value builtinArrayBufferConstructor(ExecutionState& state, Value thisValu
|
|||
|
||||
uint64_t byteLength = argv[0].toIndex(state);
|
||||
if (UNLIKELY(byteLength == Value::InvalidIndexValue)) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().ArrayBuffer.string(), false, String::emptyString, ErrorObject::Messages::GlobalObject_FirstArgumentInvalidLength);
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().ArrayBuffer.string(), false, String::emptyString(), ErrorObject::Messages::GlobalObject_FirstArgumentInvalidLength);
|
||||
return Value();
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ static Value builtinArrayBufferConstructor(ExecutionState& state, Value thisValu
|
|||
if (!maxLengthValue.isUndefined()) {
|
||||
maxByteLength = maxLengthValue.toIndex(state);
|
||||
if (UNLIKELY((maxByteLength.value() == Value::InvalidIndexValue) || (byteLength > maxByteLength.value()))) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().ArrayBuffer.string(), false, String::emptyString, ErrorObject::Messages::GlobalObject_FirstArgumentInvalidLength);
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().ArrayBuffer.string(), false, String::emptyString(), ErrorObject::Messages::GlobalObject_FirstArgumentInvalidLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -113,16 +113,22 @@ static Value builtinArrayBufferResizableGetter(ExecutionState& state, Value this
|
|||
return Value(obj->isResizableArrayBuffer());
|
||||
}
|
||||
|
||||
static Value builtinArrayBufferDetachedGetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_ARRAYBUFFER(obj, ArrayBuffer, getDetached);
|
||||
|
||||
return Value(obj->isDetachedBuffer());
|
||||
}
|
||||
|
||||
static Value builtinArrayBufferResize(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_ARRAYBUFFER(obj, ArrayBuffer, resize);
|
||||
obj->throwTypeErrorIfDetached(state);
|
||||
|
||||
if (!obj->isResizableArrayBuffer()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().ArrayBuffer.string(), true, state.context()->staticStrings().resize.string(), ErrorObject::Messages::GlobalObject_CalledOnIncompatibleReceiver);
|
||||
}
|
||||
|
||||
double newByteLength = argv[0].toInteger(state);
|
||||
obj->throwTypeErrorIfDetached(state);
|
||||
if (newByteLength < 0 || newByteLength > obj->maxByteLength()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().ArrayBuffer.string(), true, state.context()->staticStrings().resize.string(), ErrorObject::Messages::GlobalObject_FirstArgumentInvalidLength);
|
||||
}
|
||||
|
|
@ -137,17 +143,53 @@ static Value builtinArrayBufferTransfer(ExecutionState& state, Value thisValue,
|
|||
RESOLVE_THIS_BINDING_TO_ARRAYBUFFER(obj, ArrayBuffer, transfer);
|
||||
obj->throwTypeErrorIfDetached(state);
|
||||
|
||||
double newByteLength = obj->byteLength();
|
||||
uint64_t newByteLength = obj->byteLength();
|
||||
if (argc > 0 && !argv[0].isUndefined()) {
|
||||
newByteLength = argv[0].toInteger(state);
|
||||
newByteLength = argv[0].toIndex(state);
|
||||
if (UNLIKELY(newByteLength == Value::InvalidIndexValue)) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().ArrayBuffer.string(), true, state.context()->staticStrings().transfer.string(), ErrorObject::Messages::GlobalObject_FirstArgumentInvalidLength);
|
||||
}
|
||||
}
|
||||
|
||||
Value arguments[] = { Value(Value::DoubleToIntConvertibleTestNeeds, newByteLength) };
|
||||
ArrayBuffer* newValue = Object::construct(state, state.context()->globalObject()->arrayBuffer(), 1, arguments).asObject()->asArrayBuffer();
|
||||
obj->throwTypeErrorIfDetached(state);
|
||||
Optional<uint64_t> maxLength;
|
||||
if (obj->isResizableArrayBuffer()) {
|
||||
maxLength = obj->maxByteLength();
|
||||
if (newByteLength > maxLength.value()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().ArrayBuffer.string(), true, state.context()->staticStrings().transfer.string(), ErrorObject::Messages::GlobalObject_FirstArgumentInvalidLength);
|
||||
}
|
||||
} else {
|
||||
// For non-resizable ArrayBuffer, the new buffer should also be non-resizable
|
||||
maxLength = newByteLength;
|
||||
}
|
||||
ArrayBuffer* newValue = ArrayBufferObject::allocateArrayBuffer(state, state.context()->globalObject()->arrayBuffer(), newByteLength, maxLength, obj->isResizableArrayBuffer());
|
||||
|
||||
// Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
|
||||
// Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
|
||||
newValue->fillData(obj->data(), std::min(newByteLength, static_cast<double>(obj->byteLength())));
|
||||
newValue->fillData(obj->data(), std::min(newByteLength, static_cast<uint64_t>(obj->byteLength())));
|
||||
|
||||
obj->asArrayBufferObject()->detachArrayBuffer();
|
||||
|
||||
return newValue;
|
||||
}
|
||||
|
||||
static Value builtinArrayBufferTransferToFixedLength(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_ARRAYBUFFER(obj, ArrayBuffer, transferToFixedLength);
|
||||
obj->throwTypeErrorIfDetached(state);
|
||||
|
||||
uint64_t newByteLength = obj->byteLength();
|
||||
if (argc > 0 && !argv[0].isUndefined()) {
|
||||
newByteLength = argv[0].toIndex(state);
|
||||
if (UNLIKELY(newByteLength == Value::InvalidIndexValue)) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().ArrayBuffer.string(), true, state.context()->staticStrings().transferToFixedLength.string(), ErrorObject::Messages::GlobalObject_FirstArgumentInvalidLength);
|
||||
}
|
||||
}
|
||||
|
||||
ArrayBuffer* newValue = ArrayBufferObject::allocateArrayBuffer(state, state.context()->globalObject()->arrayBuffer(), newByteLength, newByteLength, false);
|
||||
// Let copyLength be min(newByteLength, O.[[ArrayBufferByteLength]]).
|
||||
// Perform CopyDataBlockBytes(toBlock, 0, fromBlock, 0, copyLength).
|
||||
newValue->fillData(obj->data(), std::min(newByteLength, static_cast<uint64_t>(obj->byteLength())));
|
||||
|
||||
obj->asArrayBufferObject()->detachArrayBuffer();
|
||||
|
||||
|
|
@ -193,12 +235,9 @@ static Value builtinArrayBufferSlice(ExecutionState& state, Value thisValue, siz
|
|||
|
||||
void GlobalObject::initializeArrayBuffer(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->arrayBuffer();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->arrayBuffer(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().ArrayBuffer), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
@ -244,6 +283,12 @@ void GlobalObject::installArrayBuffer(ExecutionState& state)
|
|||
Value(Value::EmptyValue));
|
||||
ObjectPropertyDescriptor resizableDesc(resizableGS, ObjectPropertyDescriptor::ConfigurablePresent);
|
||||
m_arrayBufferPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->resizable), resizableDesc);
|
||||
|
||||
JSGetterSetter detachedGS(
|
||||
new NativeFunctionObject(state, NativeFunctionInfo(strings->getDetached, builtinArrayBufferDetachedGetter, 0, NativeFunctionInfo::Strict)),
|
||||
Value(Value::EmptyValue));
|
||||
ObjectPropertyDescriptor detachedDesc(detachedGS, ObjectPropertyDescriptor::ConfigurablePresent);
|
||||
m_arrayBufferPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->detached), detachedDesc);
|
||||
}
|
||||
|
||||
m_arrayBufferPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->resize),
|
||||
|
|
@ -252,6 +297,9 @@ void GlobalObject::installArrayBuffer(ExecutionState& state)
|
|||
m_arrayBufferPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->transfer),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->transfer, builtinArrayBufferTransfer, 0, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_arrayBufferPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->transferToFixedLength),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->transferToFixedLength, builtinArrayBufferTransferToFixedLength, 0, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_arrayBufferPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->slice),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->slice, builtinArrayBufferSlice, 2, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Escargot {
|
|||
static Value builtinAsyncFunction(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
size_t argumentVectorCount = argc > 1 ? argc - 1 : 0;
|
||||
Value sourceValue = argc >= 1 ? argv[argc - 1] : Value(String::emptyString);
|
||||
Value sourceValue = argc >= 1 ? argv[argc - 1] : Value(String::emptyString());
|
||||
auto functionSource = FunctionObject::createDynamicFunctionScript(state, state.context()->staticStrings().anonymous, argumentVectorCount, argv, sourceValue, false, false, true, false);
|
||||
|
||||
// Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Escargot {
|
|||
static Value builtinAsyncGeneratorFunction(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
size_t argumentVectorCount = argc > 1 ? argc - 1 : 0;
|
||||
Value sourceValue = argc >= 1 ? argv[argc - 1] : Value(String::emptyString);
|
||||
Value sourceValue = argc >= 1 ? argv[argc - 1] : Value(String::emptyString());
|
||||
auto functionSource = FunctionObject::createDynamicFunctionScript(state, state.context()->staticStrings().anonymous, argumentVectorCount, argv, sourceValue, false, true, true, false);
|
||||
|
||||
// Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).
|
||||
|
|
@ -100,7 +100,7 @@ void GlobalObject::installAsyncGenerator(ExecutionState& state)
|
|||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().stringThrow, builtinAsyncGeneratorThrow, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_asyncGeneratorPrototype->directDefineOwnProperty(state, ObjectPropertyName(state, Value(state.context()->vmInstance()->globalSymbols().toStringTag)),
|
||||
ObjectPropertyDescriptor(Value(state.context()->staticStrings().AsyncGenerator.string()), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::NonWritablePresent | ObjectPropertyDescriptor::NonEnumerablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
ObjectPropertyDescriptor(state.context()->staticStrings().AsyncGenerator.string(), ObjectPropertyDescriptor::ConfigurablePresent));
|
||||
}
|
||||
|
||||
} // namespace Escargot
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@
|
|||
#include "runtime/Platform.h"
|
||||
#include "runtime/PromiseObject.h"
|
||||
|
||||
#include "util/Yield.h"
|
||||
|
||||
namespace Escargot {
|
||||
|
||||
#if defined(ENABLE_THREADING)
|
||||
|
|
@ -54,7 +56,7 @@ static ArrayBuffer* validateIntegerTypedArray(ExecutionState& state, Value typed
|
|||
if ((TA->typedArrayType() != TypedArrayType::Int32) && (TA->typedArrayType() != TypedArrayType::BigInt64)) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_IllegalFirstArgument);
|
||||
}
|
||||
} else if ((TA->typedArrayType() == TypedArrayType::Uint8Clamped) || (TA->typedArrayType() == TypedArrayType::Float32) || (TA->typedArrayType() == TypedArrayType::Float64)) {
|
||||
} else if ((TA->typedArrayType() == TypedArrayType::Uint8Clamped) || (TA->typedArrayType() == TypedArrayType::Float16) || (TA->typedArrayType() == TypedArrayType::Float32) || (TA->typedArrayType() == TypedArrayType::Float64)) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_IllegalFirstArgument);
|
||||
}
|
||||
|
||||
|
|
@ -63,8 +65,8 @@ static ArrayBuffer* validateIntegerTypedArray(ExecutionState& state, Value typed
|
|||
|
||||
static size_t validateAtomicAccess(ExecutionState& state, TypedArrayObject* typedArray, Value index)
|
||||
{
|
||||
uint64_t accessIndex = index.toIndex(state);
|
||||
size_t length = typedArray->arrayLength();
|
||||
uint64_t accessIndex = index.toIndex(state);
|
||||
if (UNLIKELY(accessIndex == Value::InvalidIndexValue || accessIndex >= (uint64_t)length)) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, ErrorObject::Messages::GlobalObject_RangeError);
|
||||
}
|
||||
|
|
@ -577,14 +579,30 @@ static Value builtinAtomicsIsLockFree(ExecutionState& state, Value thisValue, si
|
|||
#endif
|
||||
}
|
||||
|
||||
// https://tc39.es/proposal-atomics-microwait/#Atomics.pause
|
||||
static Value builtinAtomicsPause(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// 1. If N is neither undefined nor an integral Number, throw a TypeError exception.
|
||||
Value N = argc ? argv[0] : Value();
|
||||
if (!N.isUndefined() && (!N.isNumber() || !isIntegralNumber(N.asNumber()))) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_IllegalFirstArgument);
|
||||
}
|
||||
// 2. If the execution environment of the ECMAScript implementation supports signaling to the operating system or CPU that the current executing code is in a spin-wait loop,
|
||||
// such as executing a pause CPU instruction, send that signal. When N is not undefined, it determines the number of times that signal is sent.
|
||||
// The number of times the signal is sent for an integral Number N is less than or equal to the number times it is sent for N + 1 if both N and N + 1 have the same sign.
|
||||
|
||||
// TODO use number input
|
||||
YIELD_PROCESSOR;
|
||||
|
||||
// 3. Return undefined.
|
||||
return Value();
|
||||
}
|
||||
|
||||
void GlobalObject::initializeAtomics(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->atomics();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->atomics(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().Atomics), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
@ -636,6 +654,9 @@ void GlobalObject::installAtomics(ExecutionState& state)
|
|||
m_atomics->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().notify),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().notify, builtinAtomicsNotify, 3, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_atomics->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().pause),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().pause, builtinAtomicsPause, 0, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
redefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().Atomics),
|
||||
ObjectPropertyDescriptor(m_atomics, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ static Value builtinBigIntConstructor(ExecutionState& state, Value thisValue, si
|
|||
return new BigInt((int64_t)numValue);
|
||||
} else {
|
||||
// Otherwise, return ? ToBigInt(value).
|
||||
return argv[0].toBigInt(state);
|
||||
return prim.toBigInt(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -188,12 +188,9 @@ static Value builtinBigIntToLocaleString(ExecutionState& state, Value thisValue,
|
|||
|
||||
void GlobalObject::initializeBigInt(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->bigInt();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->bigInt(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().BigInt), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Escargot {
|
|||
|
||||
static Value builtinBooleanConstructor(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
bool primitiveVal = argv[0].toBoolean(state);
|
||||
bool primitiveVal = argv[0].toBoolean();
|
||||
if (!newTarget.hasValue()) {
|
||||
return Value(primitiveVal);
|
||||
} else {
|
||||
|
|
@ -63,12 +63,9 @@ static Value builtinBooleanToString(ExecutionState& state, Value thisValue, size
|
|||
|
||||
void GlobalObject::initializeBoolean(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->boolean();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->boolean(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().Boolean), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
namespace Escargot {
|
||||
|
||||
#define FOR_EACH_DATAVIEW_TYPES(F) \
|
||||
F(Float16) \
|
||||
F(Float32) \
|
||||
F(Float64) \
|
||||
F(Int8) \
|
||||
|
|
@ -40,60 +41,96 @@ namespace Escargot {
|
|||
|
||||
static Value builtinDataViewConstructor(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// If NewTarget is undefined, throw a TypeError exception.
|
||||
if (!newTarget.hasValue()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
|
||||
return Value();
|
||||
}
|
||||
// Perform ? RequireInternalSlot(buffer, [[ArrayBufferData]]).
|
||||
if (!(argv[0].isObject() && argv[0].asPointerValue()->isArrayBuffer())) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().DataView.string(), false, String::emptyString, ErrorObject::Messages::GlobalObject_ThisNotArrayBufferObject);
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().DataView.string(), false, String::emptyString(), ErrorObject::Messages::GlobalObject_ThisNotArrayBufferObject);
|
||||
}
|
||||
|
||||
ArrayBuffer* buffer = argv[0].asObject()->asArrayBuffer();
|
||||
double byteOffset = 0;
|
||||
// Let offset be ? ToIndex(byteOffset).
|
||||
double offset = 0;
|
||||
if (argc >= 2) {
|
||||
Value& val = argv[1];
|
||||
byteOffset = val.toIndex(state);
|
||||
if (byteOffset == Value::InvalidIndexValue) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().DataView.string(), false, String::emptyString, ErrorObject::Messages::GlobalObject_InvalidArrayBufferOffset);
|
||||
offset = argv[1].toIndex(state);
|
||||
if (offset == Value::InvalidIndexValue) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().DataView.string(), false, String::emptyString(), ErrorObject::Messages::GlobalObject_InvalidArrayBufferOffset);
|
||||
}
|
||||
}
|
||||
// If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if (buffer->isDetachedBuffer()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().DataView.string(), false, String::emptyString, "%s: ArrayBuffer is detached buffer");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().DataView.string(), false, String::emptyString(), "%s: ArrayBuffer is detached buffer");
|
||||
}
|
||||
double bufferByteLength = buffer->byteLength();
|
||||
|
||||
if (byteOffset > bufferByteLength) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().DataView.string(), false, String::emptyString, ErrorObject::Messages::GlobalObject_InvalidArrayBufferOffset);
|
||||
// Let bufferByteLength be ArrayBufferByteLength(buffer, seq-cst).
|
||||
auto bufferByteLegnth = buffer->byteLength();
|
||||
// If offset > bufferByteLength, throw a RangeError exception.
|
||||
if (offset > bufferByteLegnth) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().DataView.string(), false, String::emptyString(), ErrorObject::Messages::GlobalObject_InvalidArrayBufferOffset);
|
||||
}
|
||||
double byteLength = bufferByteLength - byteOffset;
|
||||
|
||||
if (argc >= 3) {
|
||||
Value& val = argv[2];
|
||||
if (!val.isUndefined()) {
|
||||
byteLength = val.toIndex(state);
|
||||
if (byteOffset + byteLength > bufferByteLength || byteLength == Value::InvalidIndexValue) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().DataView.string(), false, String::emptyString, ErrorObject::Messages::GlobalObject_InvalidArrayBufferOffset);
|
||||
}
|
||||
// Let bufferIsFixedLength be IsFixedLengthArrayBuffer(buffer).
|
||||
bool bufferIsFixedLength = buffer->isFixedLengthArrayBuffer();
|
||||
// If byteLength is undefined, then
|
||||
Optional<Value::ValueIndex> viewByteLength;
|
||||
if (argc < 3 || argv[2].isUndefined()) {
|
||||
// If bufferIsFixedLength is true, then
|
||||
if (bufferIsFixedLength) {
|
||||
// Let viewByteLength be bufferByteLength - offset.
|
||||
viewByteLength = bufferByteLegnth - offset;
|
||||
} else {
|
||||
// Else
|
||||
// Let viewByteLength be auto.
|
||||
}
|
||||
} else {
|
||||
// Else,
|
||||
// Let viewByteLength be ? ToIndex(byteLength).
|
||||
viewByteLength = argv[2].toIndex(state);
|
||||
if (viewByteLength.value() == Value::InvalidIndexValue) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().DataView.string(), false, String::emptyString(), ErrorObject::Messages::GlobalObject_InvalidArrayBufferSize);
|
||||
}
|
||||
// If offset + viewByteLength > bufferByteLength, throw a RangeError exception.
|
||||
if (offset + viewByteLength.value() > bufferByteLegnth) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().DataView.string(), false, String::emptyString(), ErrorObject::Messages::GlobalObject_InvalidArrayBufferSize);
|
||||
}
|
||||
}
|
||||
|
||||
// Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataView.prototype%", « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »).
|
||||
Object* proto = Object::getPrototypeFromConstructor(state, newTarget.value(), [](ExecutionState& state, Context* constructorRealm) -> Object* {
|
||||
return constructorRealm->globalObject()->dataViewPrototype();
|
||||
});
|
||||
ArrayBufferView* obj = new DataViewObject(state, proto);
|
||||
obj->setBuffer(buffer, byteOffset, byteLength);
|
||||
ArrayBufferView* O = new DataViewObject(state, proto);
|
||||
|
||||
if (obj->buffer()->isDetachedBuffer()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().DataView.string(), false, String::emptyString, ErrorObject::Messages::GlobalObject_DetachedBuffer);
|
||||
// If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if (buffer->isDetachedBuffer()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().DataView.string(), false, String::emptyString(), "%s: ArrayBuffer is detached buffer");
|
||||
}
|
||||
|
||||
return obj;
|
||||
// Set bufferByteLength to ArrayBufferByteLength(buffer, seq-cst).
|
||||
bufferByteLegnth = buffer->byteLength();
|
||||
// If offset > bufferByteLength, throw a RangeError exception.
|
||||
if (offset > bufferByteLegnth) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().DataView.string(), false, String::emptyString(), ErrorObject::Messages::GlobalObject_InvalidArrayBufferSize);
|
||||
}
|
||||
// If byteLength is not undefined, then
|
||||
if (argc >= 3 && !argv[2].isUndefined()) {
|
||||
// If offset + viewByteLength > bufferByteLength, throw a RangeError exception.
|
||||
if (offset + viewByteLength.value() > bufferByteLegnth) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::RangeError, state.context()->staticStrings().DataView.string(), false, String::emptyString(), ErrorObject::Messages::GlobalObject_InvalidArrayBufferSize);
|
||||
}
|
||||
}
|
||||
// Set O.[[ViewedArrayBuffer]] to buffer.
|
||||
// Set O.[[ByteLength]] to viewByteLength.
|
||||
// Set O.[[ByteOffset]] to offset.
|
||||
// Return O.
|
||||
O->setBuffer(buffer, offset, viewByteLength ? viewByteLength.value() : bufferByteLegnth - offset, 0, argc < 3);
|
||||
return O;
|
||||
}
|
||||
|
||||
#define DECLARE_DATAVIEW_GETTER(Name) \
|
||||
static Value builtinDataViewGet##Name(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget) \
|
||||
{ \
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, DataView, get##Name); \
|
||||
Object* thisObject = thisValue.toObject(state); \
|
||||
if (!(thisObject->isDataViewObject())) { \
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().DataView.string(), \
|
||||
true, state.context()->staticStrings().get##Name.string(), \
|
||||
|
|
@ -109,17 +146,18 @@ static Value builtinDataViewConstructor(ExecutionState& state, Value thisValue,
|
|||
#define DECLARE_DATAVIEW_SETTER(Name) \
|
||||
static Value builtinDataViewSet##Name(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget) \
|
||||
{ \
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, DataView, get##Name); \
|
||||
Object* thisObject = thisValue.toObject(state); \
|
||||
if (!(thisObject->isDataViewObject())) { \
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().DataView.string(), \
|
||||
true, state.context()->staticStrings().set##Name.string(), \
|
||||
ErrorObject::Messages::GlobalObject_ThisNotDataViewObject); \
|
||||
} \
|
||||
if (argc < 3) { \
|
||||
return thisObject->asDataViewObject()->setViewValue(state, argv[0], Value(false), TypedArrayType::Name, argv[1]); \
|
||||
thisObject->asDataViewObject()->setViewValue(state, argv[0], Value(false), TypedArrayType::Name, argv[1]); \
|
||||
} else { \
|
||||
return thisObject->asDataViewObject()->setViewValue(state, argv[0], argv[2], TypedArrayType::Name, argv[1]); \
|
||||
thisObject->asDataViewObject()->setViewValue(state, argv[0], argv[2], TypedArrayType::Name, argv[1]); \
|
||||
} \
|
||||
return Value(); \
|
||||
}
|
||||
|
||||
FOR_EACH_DATAVIEW_TYPES(DECLARE_DATAVIEW_GETTER);
|
||||
|
|
@ -139,7 +177,8 @@ static Value builtinDataViewBufferGetter(ExecutionState& state, Value thisValue,
|
|||
|
||||
static Value builtinDataViewByteLengthGetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
if (LIKELY(thisValue.isPointerValue() && thisValue.asPointerValue()->isDataViewObject() && thisValue.asObject()->asDataViewObject()->buffer() && !thisValue.asObject()->asDataViewObject()->buffer()->isDetachedBuffer())) {
|
||||
if (LIKELY(thisValue.isPointerValue() && thisValue.asPointerValue()->isDataViewObject() && thisValue.asObject()->asDataViewObject()->buffer())) {
|
||||
thisValue.asObject()->asDataViewObject()->throwTypeErrorIfDetached(state);
|
||||
return Value(thisValue.asObject()->asArrayBufferView()->byteLength());
|
||||
}
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "get DataView.prototype.byteLength called on incompatible receiver");
|
||||
|
|
@ -148,7 +187,8 @@ static Value builtinDataViewByteLengthGetter(ExecutionState& state, Value thisVa
|
|||
|
||||
static Value builtinDataViewByteOffsetGetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
if (LIKELY(thisValue.isPointerValue() && thisValue.asPointerValue()->isDataViewObject() && thisValue.asObject()->asDataViewObject()->buffer() && !thisValue.asObject()->asDataViewObject()->buffer()->isDetachedBuffer())) {
|
||||
if (LIKELY(thisValue.isPointerValue() && thisValue.asPointerValue()->isDataViewObject() && thisValue.asObject()->asDataViewObject()->buffer())) {
|
||||
thisValue.asObject()->asDataViewObject()->throwTypeErrorIfDetached(state);
|
||||
return Value(thisValue.asObject()->asArrayBufferView()->byteOffset());
|
||||
}
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "get DataView.prototype.byteOffset called on incompatible receiver");
|
||||
|
|
@ -157,12 +197,9 @@ static Value builtinDataViewByteOffsetGetter(ExecutionState& state, Value thisVa
|
|||
|
||||
void GlobalObject::initializeDataView(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->dataView();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->dataView(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().DataView), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@
|
|||
#include "intl/IntlDateTimeFormat.h"
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_TEMPORAL)
|
||||
#include "runtime/TemporalInstantObject.h"
|
||||
#endif
|
||||
|
||||
namespace Escargot {
|
||||
|
||||
#define FOR_EACH_DATE_VALUES(F) \
|
||||
|
|
@ -98,7 +102,7 @@ static Value builtinDateConstructor(ExecutionState& state, Value thisValue, size
|
|||
} else {
|
||||
// Let tv be ToNumber(v).
|
||||
double V = v.toNumber(state);
|
||||
thisObject->setTimeValue(DateObject::timeClip(state, V));
|
||||
thisObject->setTimeValue(DateObject::timeClipToTime64(state, V));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -216,21 +220,23 @@ static Value builtinDateToTimeString(ExecutionState& state, Value thisValue, siz
|
|||
}
|
||||
|
||||
#if defined(ENABLE_ICU) && defined(ENABLE_INTL)
|
||||
#define INTL_DATE_TIME_FORMAT_FORMAT(REQUIRED, DEFUALT) \
|
||||
double x = thisObject->primitiveValue(); \
|
||||
if (std::isnan(x)) { \
|
||||
return new ASCIIString("Invalid Date"); \
|
||||
} \
|
||||
Value locales, options; \
|
||||
if (argc >= 1) { \
|
||||
locales = argv[0]; \
|
||||
} \
|
||||
if (argc >= 2) { \
|
||||
options = argv[1]; \
|
||||
} \
|
||||
auto dateTimeOption = IntlDateTimeFormatObject::toDateTimeOptions(state, options, String::fromASCII(REQUIRED), String::fromASCII(DEFUALT)); \
|
||||
IntlDateTimeFormatObject* dateFormat = new IntlDateTimeFormatObject(state, locales, dateTimeOption); \
|
||||
auto result = dateFormat->format(state, x); \
|
||||
#define INTL_DATE_TIME_FORMAT_FORMAT(REQUIRED, DEFUALT) \
|
||||
double x = thisObject->primitiveValue(); \
|
||||
if (std::isnan(x)) { \
|
||||
return new ASCIIStringFromExternalMemory("Invalid Date"); \
|
||||
} \
|
||||
Value locales, options; \
|
||||
if (argc >= 1) { \
|
||||
locales = argv[0]; \
|
||||
} \
|
||||
if (argc >= 2) { \
|
||||
options = argv[1]; \
|
||||
} \
|
||||
auto dateTimeOption = IntlDateTimeFormatObject:: \
|
||||
toDateTimeOptions(state, options, String::fromASCII(REQUIRED), String::fromASCII(DEFUALT)) \
|
||||
.first; \
|
||||
IntlDateTimeFormatObject* dateFormat = new IntlDateTimeFormatObject(state, locales, dateTimeOption); \
|
||||
auto result = dateFormat->format(state, x); \
|
||||
return new UTF16String(result.data(), result.length());
|
||||
#endif
|
||||
|
||||
|
|
@ -278,7 +284,7 @@ static Value builtinDateToISOString(ExecutionState& state, Value thisValue, size
|
|||
|
||||
static Value builtinDateToJSON(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Date, toJSON);
|
||||
Object* thisObject = thisValue.toObject(state);
|
||||
|
||||
Value tv = Value(thisObject).toPrimitive(state, Value::PreferNumber);
|
||||
if (tv.isNumber() && (std::isnan(tv.asNumber()) || std::isinf(tv.asNumber()))) {
|
||||
|
|
@ -312,13 +318,19 @@ static Value builtinDateSetHelper(ExecutionState& state, DateSetterType setterTy
|
|||
RESOLVE_THIS_BINDING_TO_DATE(thisObject, Date, name);
|
||||
DateObject* d = thisObject;
|
||||
|
||||
// Read the current [[DateValue]] first (before any ToNumber conversions)
|
||||
// To keep a record of the original state
|
||||
double originalDateValue = d->primitiveValue();
|
||||
bool isOriginalDateValid = d->isValid();
|
||||
|
||||
if (setterType == DateSetterType::Day && length == 3) {
|
||||
// setFullYear, setUTCFullYear case
|
||||
if (!(d->isValid())) {
|
||||
d->setTimeValue(DateObject::timeClip(state, 0));
|
||||
d->setTimeValue(d->getTimezoneOffset(state) * const_Date_msPerMinute);
|
||||
if (!isOriginalDateValid) {
|
||||
d->setTimeValue(DateObject::timeClipToTime64(state, 0));
|
||||
d->setTimeValue(d->getTimezoneOffset(state) * TimeConstant::MsPerMinute);
|
||||
originalDateValue = d->primitiveValue();
|
||||
isOriginalDateValid = true;
|
||||
}
|
||||
ASSERT(d->isValid());
|
||||
}
|
||||
|
||||
if (argc < 1) {
|
||||
|
|
@ -326,9 +338,10 @@ static Value builtinDateSetHelper(ExecutionState& state, DateSetterType setterTy
|
|||
return Value(Value::NanInit);
|
||||
}
|
||||
|
||||
// Read date components from original state (before ToNumber calls)
|
||||
double year = 0, month = 0, date = 0, hour = 0, minute = 0, second = 0, millisecond = 0;
|
||||
|
||||
if (d->isValid()) {
|
||||
if (isOriginalDateValid) {
|
||||
if (!utc) {
|
||||
year = d->getFullYear(state);
|
||||
month = d->getMonth(state);
|
||||
|
|
@ -350,8 +363,7 @@ static Value builtinDateSetHelper(ExecutionState& state, DateSetterType setterTy
|
|||
}
|
||||
}
|
||||
|
||||
bool convertToUTC = !utc;
|
||||
|
||||
// Convert arguments to numbers (this may cause side effects)
|
||||
switch (setterType) {
|
||||
case DateSetterType::Day:
|
||||
if ((length >= 3) && (argc > length - 3))
|
||||
|
|
@ -375,9 +387,16 @@ static Value builtinDateSetHelper(ExecutionState& state, DateSetterType setterTy
|
|||
RELEASE_ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
// Check if original date value was NaN
|
||||
if (std::isnan(originalDateValue)) {
|
||||
return Value(Value::NanInit);
|
||||
}
|
||||
|
||||
bool convertToUTC = !utc;
|
||||
|
||||
if (UNLIKELY(!isInValidRange(year, month, date, hour, minute, second, millisecond))) {
|
||||
d->setTimeValueAsNaN();
|
||||
} else if (d->isValid()) {
|
||||
} else {
|
||||
d->setTimeValue(state, year, month, date, hour, minute, second, millisecond, convertToUTC);
|
||||
}
|
||||
|
||||
|
|
@ -396,7 +415,7 @@ static Value builtinDateSetTime(ExecutionState& state, Value thisValue, size_t a
|
|||
{
|
||||
RESOLVE_THIS_BINDING_TO_DATE(thisObject, Date, setTime);
|
||||
if (argc > 0) {
|
||||
thisObject->setTimeValue(DateObject::timeClip(state, argv[0].toNumber(state)));
|
||||
thisObject->setTimeValue(DateObject::timeClipToTime64(state, argv[0].toNumber(state)));
|
||||
return Value(Value::DoubleToIntConvertibleTestNeeds, thisObject->primitiveValue());
|
||||
} else {
|
||||
thisObject->setTimeValueAsNaN();
|
||||
|
|
@ -420,8 +439,8 @@ static Value builtinDateSetYear(ExecutionState& state, Value thisValue, size_t a
|
|||
DateObject* d = thisObject;
|
||||
|
||||
if (!(d->isValid())) {
|
||||
d->setTimeValue(DateObject::timeClip(state, 0));
|
||||
d->setTimeValue(d->getTimezoneOffset(state) * const_Date_msPerMinute);
|
||||
d->setTimeValue(DateObject::timeClipToTime64(state, 0));
|
||||
d->setTimeValue(d->getTimezoneOffset(state) * TimeConstant::MsPerMinute);
|
||||
}
|
||||
ASSERT(d->isValid());
|
||||
|
||||
|
|
@ -432,6 +451,12 @@ static Value builtinDateSetYear(ExecutionState& state, Value thisValue, size_t a
|
|||
|
||||
double y;
|
||||
int month, date, hour, minute, second, millisecond;
|
||||
month = d->getMonth(state);
|
||||
date = d->getDate(state);
|
||||
hour = d->getHours(state);
|
||||
minute = d->getMinutes(state);
|
||||
second = d->getSeconds(state);
|
||||
millisecond = d->getMilliseconds(state);
|
||||
|
||||
// Let y be ToNumber(year).
|
||||
y = argv[0].toNumber(state);
|
||||
|
|
@ -441,13 +466,6 @@ static Value builtinDateSetYear(ExecutionState& state, Value thisValue, size_t a
|
|||
return Value(Value::NanInit);
|
||||
}
|
||||
|
||||
month = d->getMonth(state);
|
||||
date = d->getDate(state);
|
||||
hour = d->getHours(state);
|
||||
minute = d->getMinutes(state);
|
||||
second = d->getSeconds(state);
|
||||
millisecond = d->getMilliseconds(state);
|
||||
|
||||
double yyyy;
|
||||
double yAsInteger = Value(Value::DoubleToIntConvertibleTestNeeds, y).toInteger(state);
|
||||
// If y is not NaN and 0 ≤ ToInteger(y) ≤ 99, let yyyy be ToInteger(y) + 1900.
|
||||
|
|
@ -458,9 +476,7 @@ static Value builtinDateSetYear(ExecutionState& state, Value thisValue, size_t a
|
|||
yyyy = y;
|
||||
}
|
||||
|
||||
if (d->isValid()) {
|
||||
d->setTimeValue(state, yyyy, month, date, hour, minute, second, millisecond);
|
||||
}
|
||||
d->setTimeValue(state, yyyy, month, date, hour, minute, second, millisecond);
|
||||
|
||||
return Value(Value::DoubleToIntConvertibleTestNeeds, d->primitiveValue());
|
||||
}
|
||||
|
|
@ -504,14 +520,19 @@ static Value builtinDateToPrimitive(ExecutionState& state, Value thisValue, size
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(ENABLE_TEMPORAL)
|
||||
static Value builtinDateToTemporalInstant(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_DATE(thisObject, Date, lazyToTemporalInstant());
|
||||
return thisObject->toTemporalInstant(state);
|
||||
}
|
||||
#endif
|
||||
|
||||
void GlobalObject::initializeDate(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->date();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->date(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().Date), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
@ -602,6 +623,12 @@ void GlobalObject::installDate(ExecutionState& state)
|
|||
|
||||
FOR_EACH_DATE_VALUES(DATE_DEFINE_SETTER);
|
||||
|
||||
#if defined(ENABLE_TEMPORAL)
|
||||
m_datePrototype->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().lazyToTemporalInstant()),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().lazyToTemporalInstant(), builtinDateToTemporalInstant, 0, NativeFunctionInfo::Strict)),
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
#endif
|
||||
|
||||
m_date->setFunctionPrototype(state, m_datePrototype);
|
||||
|
||||
redefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().Date),
|
||||
|
|
|
|||
|
|
@ -52,7 +52,12 @@ static Value builtinErrorConstructor(ExecutionState& state, Value thisValue, siz
|
|||
Object* proto = Object::getPrototypeFromConstructor(state, newTarget.value(), [](ExecutionState& state, Context* constructorRealm) -> Object* {
|
||||
return constructorRealm->globalObject()->errorPrototype();
|
||||
});
|
||||
ErrorObject* obj = new ErrorObject(state, proto, String::emptyString);
|
||||
|
||||
#if defined(ENABLE_EXTENDED_API)
|
||||
ErrorObject* obj = new ErrorObject(state, proto, String::emptyString(), true, state.context()->vmInstance()->isErrorCreationCallbackRegistered());
|
||||
#else
|
||||
ErrorObject* obj = new ErrorObject(state, proto, String::emptyString());
|
||||
#endif
|
||||
|
||||
Value message = argv[0];
|
||||
if (!message.isUndefined()) {
|
||||
|
|
@ -63,13 +68,10 @@ static Value builtinErrorConstructor(ExecutionState& state, Value thisValue, siz
|
|||
Value options = argc > 1 ? argv[1] : Value();
|
||||
installErrorCause(state, obj, options);
|
||||
|
||||
if (UNLIKELY(state.context()->vmInstance()->isErrorCreationCallbackRegistered())) {
|
||||
state.context()->vmInstance()->triggerErrorCreationCallback(state, obj);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
#if defined(ENABLE_EXTENDED_API)
|
||||
#define DEFINE_ERROR_CTOR(errorName, lowerCaseErrorName) \
|
||||
static Value builtin##errorName##ErrorConstructor(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget) \
|
||||
{ \
|
||||
|
|
@ -79,7 +81,7 @@ static Value builtinErrorConstructor(ExecutionState& state, Value thisValue, siz
|
|||
Object* proto = Object::getPrototypeFromConstructor(state, newTarget.value(), [](ExecutionState& state, Context* constructorRealm) -> Object* { \
|
||||
return constructorRealm->globalObject()->lowerCaseErrorName##ErrorPrototype(); \
|
||||
}); \
|
||||
ErrorObject* obj = new errorName##ErrorObject(state, proto, String::emptyString); \
|
||||
ErrorObject* obj = new errorName##ErrorObject(state, proto, String::emptyString(), true, state.context()->vmInstance()->isErrorCreationCallbackRegistered()); \
|
||||
Value message = argv[0]; \
|
||||
if (!message.isUndefined()) { \
|
||||
obj->defineOwnPropertyThrowsException(state, state.context()->staticStrings().message, \
|
||||
|
|
@ -87,11 +89,29 @@ static Value builtinErrorConstructor(ExecutionState& state, Value thisValue, siz
|
|||
} \
|
||||
Value options = argc > 1 ? argv[1] : Value(); \
|
||||
installErrorCause(state, obj, options); \
|
||||
if (UNLIKELY(state.context()->vmInstance()->isErrorCreationCallbackRegistered())) { \
|
||||
state.context()->vmInstance()->triggerErrorCreationCallback(state, obj); \
|
||||
} \
|
||||
return obj; \
|
||||
}
|
||||
#else
|
||||
#define DEFINE_ERROR_CTOR(errorName, lowerCaseErrorName) \
|
||||
static Value builtin##errorName##ErrorConstructor(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget) \
|
||||
{ \
|
||||
if (!newTarget.hasValue()) { \
|
||||
newTarget = state.resolveCallee(); \
|
||||
} \
|
||||
Object* proto = Object::getPrototypeFromConstructor(state, newTarget.value(), [](ExecutionState& state, Context* constructorRealm) -> Object* { \
|
||||
return constructorRealm->globalObject()->lowerCaseErrorName##ErrorPrototype(); \
|
||||
}); \
|
||||
ErrorObject* obj = new errorName##ErrorObject(state, proto, String::emptyString()); \
|
||||
Value message = argv[0]; \
|
||||
if (!message.isUndefined()) { \
|
||||
obj->defineOwnPropertyThrowsException(state, state.context()->staticStrings().message, \
|
||||
ObjectPropertyDescriptor(message.toString(state), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectStructurePropertyDescriptor::ConfigurablePresent))); \
|
||||
} \
|
||||
Value options = argc > 1 ? argv[1] : Value(); \
|
||||
installErrorCause(state, obj, options); \
|
||||
return obj; \
|
||||
}
|
||||
#endif
|
||||
|
||||
DEFINE_ERROR_CTOR(Reference, reference);
|
||||
DEFINE_ERROR_CTOR(Type, type);
|
||||
|
|
@ -110,7 +130,13 @@ static Value builtinAggregateErrorConstructor(ExecutionState& state, Value thisV
|
|||
Object* proto = Object::getPrototypeFromConstructor(state, newTarget.value(), [](ExecutionState& state, Context* constructorRealm) -> Object* {
|
||||
return constructorRealm->globalObject()->aggregateErrorPrototype();
|
||||
});
|
||||
ErrorObject* O = new AggregateErrorObject(state, proto, String::emptyString);
|
||||
|
||||
#if defined(ENABLE_EXTENDED_API)
|
||||
ErrorObject* O = new AggregateErrorObject(state, proto, String::emptyString(), true, state.context()->vmInstance()->isErrorCreationCallbackRegistered());
|
||||
#else
|
||||
ErrorObject* O = new AggregateErrorObject(state, proto, String::emptyString());
|
||||
#endif
|
||||
|
||||
Value message = argv[1];
|
||||
// If message is not undefined, then
|
||||
if (!message.isUndefined()) {
|
||||
|
|
@ -131,11 +157,35 @@ static Value builtinAggregateErrorConstructor(ExecutionState& state, Value thisV
|
|||
O->defineOwnPropertyThrowsException(state, ObjectPropertyName(state, String::fromASCII("errors")),
|
||||
ObjectPropertyDescriptor(Value(Object::createArrayFromList(state, errorsList.size(), errorsList.data())), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectStructurePropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
if (UNLIKELY(state.context()->vmInstance()->isErrorCreationCallbackRegistered())) {
|
||||
state.context()->vmInstance()->triggerErrorCreationCallback(state, O);
|
||||
// Return O.
|
||||
return O;
|
||||
}
|
||||
|
||||
static Value builtinSuppressedErrorConstructor(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
if (!newTarget.hasValue()) {
|
||||
newTarget = state.resolveCallee();
|
||||
}
|
||||
Object* proto = Object::getPrototypeFromConstructor(state, newTarget.value(), [](ExecutionState& state, Context* constructorRealm) -> Object* {
|
||||
return constructorRealm->globalObject()->suppressedErrorPrototype();
|
||||
});
|
||||
|
||||
String* message = String::emptyString();
|
||||
if (!argv[2].isUndefined()) {
|
||||
message = argv[2].toString(state);
|
||||
}
|
||||
|
||||
#if defined(ENABLE_EXTENDED_API)
|
||||
ErrorObject* O = new SuppressedErrorObject(state, proto, message, true, state.context()->vmInstance()->isErrorCreationCallbackRegistered(), argv[0], argv[1]);
|
||||
#else
|
||||
ErrorObject* O = new SuppressedErrorObject(state, proto, message, true, false, argv[0], argv[1]);
|
||||
#endif
|
||||
|
||||
// test/built-ins/NativeErrors/SuppressedError/message-undefined-no-prop.js
|
||||
if (argv[2].isUndefined()) {
|
||||
O->deleteOwnProperty(state, state.context()->staticStrings().message);
|
||||
}
|
||||
|
||||
// Return O.
|
||||
return O;
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +203,7 @@ static Value builtinErrorToString(ExecutionState& state, Value thisValue, size_t
|
|||
Object* o = thisValue.toObject(state);
|
||||
|
||||
if (!state.context()->toStringRecursionPreventer()->canInvokeToString(o)) {
|
||||
return String::emptyString;
|
||||
return String::emptyString();
|
||||
}
|
||||
ToStringRecursionPreventerItemAutoHolder holder(state, o);
|
||||
|
||||
|
|
@ -167,7 +217,7 @@ static Value builtinErrorToString(ExecutionState& state, Value thisValue, size_t
|
|||
Value message = o->get(state, state.context()->staticStrings().message).value(state, o);
|
||||
String* messageStr;
|
||||
if (message.isUndefined()) {
|
||||
messageStr = String::emptyString;
|
||||
messageStr = String::emptyString();
|
||||
} else {
|
||||
messageStr = message.toString(state);
|
||||
}
|
||||
|
|
@ -181,23 +231,32 @@ static Value builtinErrorToString(ExecutionState& state, Value thisValue, size_t
|
|||
}
|
||||
|
||||
StringBuilder builder;
|
||||
builder.appendString(nameStr);
|
||||
builder.appendString(": ");
|
||||
builder.appendString(messageStr);
|
||||
builder.appendString(nameStr, &state);
|
||||
builder.appendString(": ", &state);
|
||||
builder.appendString(messageStr, &state);
|
||||
return builder.finalize(&state);
|
||||
}
|
||||
|
||||
// https://tc39.es/ecma262/#sec-error.iserror
|
||||
static Value builtinErrorIsError(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// 1. If arg is not an Object, return false.
|
||||
// 2. If arg does not have an [[ErrorData]] internal slot, return false.
|
||||
if (!argv[0].isObject() || !argv[0].asObject()->isErrorObject()) {
|
||||
return Value(false);
|
||||
}
|
||||
// 3. Return true.
|
||||
return Value(true);
|
||||
}
|
||||
|
||||
void GlobalObject::initializeError(ExecutionState& state)
|
||||
{
|
||||
#define DEFINE_ERROR_INIT(errorname, bname) \
|
||||
{ \
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, \
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value { \
|
||||
#define DEFINE_ERROR_INIT(errorname, bname) \
|
||||
{ \
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value { \
|
||||
ASSERT(self->isGlobalObject()); \
|
||||
return self->asGlobalObject()->errorname##Error(); \
|
||||
}, \
|
||||
nullptr); \
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().bname##Error), nativeData, Value(Value::EmptyValue)); \
|
||||
return self->asGlobalObject()->errorname##Error(); }, nullptr); \
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().bname##Error), nativeData, Value(Value::EmptyValue)); \
|
||||
}
|
||||
|
||||
DEFINE_ERROR_INIT(reference, Reference);
|
||||
|
|
@ -207,14 +266,12 @@ void GlobalObject::initializeError(ExecutionState& state)
|
|||
DEFINE_ERROR_INIT(uri, URI);
|
||||
DEFINE_ERROR_INIT(eval, Eval);
|
||||
DEFINE_ERROR_INIT(aggregate, Aggregate);
|
||||
DEFINE_ERROR_INIT(suppressed, Suppressed);
|
||||
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->error();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->error(); }, nullptr);
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().Error), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
}
|
||||
|
|
@ -224,6 +281,10 @@ void GlobalObject::installError(ExecutionState& state)
|
|||
m_error = new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().Error, builtinErrorConstructor, 1), NativeFunctionObject::__ForBuiltinConstructor__);
|
||||
m_error->setGlobalIntrinsicObject(state);
|
||||
|
||||
m_error->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().isError),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().isError, builtinErrorIsError, 1, NativeFunctionInfo::Strict)),
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_errorPrototype = new PrototypeObject(state);
|
||||
m_errorPrototype->setGlobalIntrinsicObject(state, true);
|
||||
|
||||
|
|
@ -231,7 +292,7 @@ void GlobalObject::installError(ExecutionState& state)
|
|||
|
||||
m_errorPrototype->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().constructor), ObjectPropertyDescriptor(m_error, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_errorPrototype->directDefineOwnProperty(state, state.context()->staticStrings().message, ObjectPropertyDescriptor(String::emptyString, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
m_errorPrototype->directDefineOwnProperty(state, state.context()->staticStrings().message, ObjectPropertyDescriptor(String::emptyString(), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
m_errorPrototype->directDefineOwnProperty(state, state.context()->staticStrings().name, ObjectPropertyDescriptor(state.context()->staticStrings().Error.string(), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
auto errorToStringFn = new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().toString, builtinErrorToString, 0, NativeFunctionInfo::Strict));
|
||||
m_errorPrototype->directDefineOwnProperty(state, state.context()->staticStrings().toString, ObjectPropertyDescriptor(errorToStringFn, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
|
@ -244,7 +305,7 @@ void GlobalObject::installError(ExecutionState& state)
|
|||
m_throwTypeError->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().length),
|
||||
ObjectPropertyDescriptor(Value(0), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::NonWritablePresent | ObjectPropertyDescriptor::NonEnumerablePresent | ObjectPropertyDescriptor::NonConfigurablePresent)));
|
||||
m_throwTypeError->defineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().name),
|
||||
ObjectPropertyDescriptor(String::emptyString, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::NonWritablePresent | ObjectPropertyDescriptor::NonEnumerablePresent | ObjectPropertyDescriptor::NonConfigurablePresent)));
|
||||
ObjectPropertyDescriptor(String::emptyString(), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::NonWritablePresent | ObjectPropertyDescriptor::NonEnumerablePresent | ObjectPropertyDescriptor::NonConfigurablePresent)));
|
||||
m_throwTypeError->preventExtensions(state);
|
||||
|
||||
m_throwerGetterSetterData = new JSGetterSetter(m_throwTypeError, m_throwTypeError);
|
||||
|
|
@ -255,7 +316,7 @@ void GlobalObject::installError(ExecutionState& state)
|
|||
m_##errorname##ErrorPrototype = new PrototypeObject(state, m_errorPrototype); \
|
||||
m_##errorname##ErrorPrototype->setGlobalIntrinsicObject(state, true); \
|
||||
m_##errorname##ErrorPrototype->directDefineOwnProperty(state, state.context()->staticStrings().constructor, ObjectPropertyDescriptor(m_##errorname##Error, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectStructurePropertyDescriptor::ConfigurablePresent))); \
|
||||
m_##errorname##ErrorPrototype->directDefineOwnProperty(state, state.context()->staticStrings().message, ObjectPropertyDescriptor(String::emptyString, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectStructurePropertyDescriptor::ConfigurablePresent))); \
|
||||
m_##errorname##ErrorPrototype->directDefineOwnProperty(state, state.context()->staticStrings().message, ObjectPropertyDescriptor(String::emptyString(), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectStructurePropertyDescriptor::ConfigurablePresent))); \
|
||||
m_##errorname##ErrorPrototype->directDefineOwnProperty(state, state.context()->staticStrings().name, ObjectPropertyDescriptor(state.context()->staticStrings().bname##Error.string(), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectStructurePropertyDescriptor::ConfigurablePresent))); \
|
||||
m_##errorname##Error->setFunctionPrototype(state, m_##errorname##ErrorPrototype); \
|
||||
redefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().bname##Error), \
|
||||
|
|
@ -268,6 +329,7 @@ void GlobalObject::installError(ExecutionState& state)
|
|||
DEFINE_ERROR(uri, URI, 1);
|
||||
DEFINE_ERROR(eval, Eval, 1);
|
||||
DEFINE_ERROR(aggregate, Aggregate, 2);
|
||||
DEFINE_ERROR(suppressed, Suppressed, 3);
|
||||
|
||||
redefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().Error),
|
||||
ObjectPropertyDescriptor(m_error, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ static Value builtinFinalizationRegistryConstructor(ExecutionState& state, Value
|
|||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ConstructorRequiresNew);
|
||||
return Value();
|
||||
}
|
||||
if (argc == 0 || !argv[0].isCallable()) {
|
||||
if (!argv[0].isCallable()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "cleanup Callback is not callable");
|
||||
}
|
||||
|
||||
|
|
@ -54,32 +54,32 @@ static Value builtinfinalizationRegistryRegister(ExecutionState& state, Value th
|
|||
{
|
||||
RESOLVE_THIS_BINDING_TO_FINALIZATIONREGISTRY(finalRegistry, stringRegister);
|
||||
|
||||
if (argc == 0 || !argv[0].isObject()) {
|
||||
if (!argv[0].canBeHeldWeakly(state.context()->vmInstance())) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "target is not object");
|
||||
}
|
||||
if (argv[0] == argv[1]) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "target and heldValue is the same");
|
||||
}
|
||||
|
||||
Optional<Object*> unregisterToken;
|
||||
if (argc >= 3) {
|
||||
if (argv[2].isObject()) {
|
||||
unregisterToken = argv[2].asObject();
|
||||
} else if (!argv[2].isUndefined()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "unregisterToken is not undefined");
|
||||
}
|
||||
Optional<PointerValue*> unregisterToken;
|
||||
Value tokenValue = argc >= 3 ? argv[2] : Value();
|
||||
if (tokenValue.canBeHeldWeakly(state.context()->vmInstance())) {
|
||||
unregisterToken = argv[2].asPointerValue();
|
||||
} else if (!tokenValue.isUndefined()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "unregisterToken is not undefined");
|
||||
}
|
||||
finalRegistry->setCell(argv[0].asObject(), argv[1], unregisterToken);
|
||||
|
||||
finalRegistry->setCell(argv[0].asPointerValue(), argv[1], unregisterToken);
|
||||
return Value();
|
||||
}
|
||||
|
||||
static Value builtinfinalizationRegistryUnregister(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_FINALIZATIONREGISTRY(finalRegistry, unregister);
|
||||
if (argc == 0 || !argv[0].isObject()) {
|
||||
if (!argv[0].canBeHeldWeakly(state.context()->vmInstance())) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "unregisterToken is not object");
|
||||
}
|
||||
return Value(finalRegistry->deleteCell(argv[0].asObject()));
|
||||
return Value(finalRegistry->deleteCell(argv[0].asPointerValue()));
|
||||
}
|
||||
|
||||
static Value builtinfinalizationRegistryCleanupSome(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
|
|
@ -102,12 +102,9 @@ static Value builtinfinalizationRegistryCleanupSome(ExecutionState& state, Value
|
|||
|
||||
void GlobalObject::initializeFinalizationRegistry(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->finalizationRegistry();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->finalizationRegistry(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().FinalizationRegistry), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ static Value builtinFunctionConstructor(ExecutionState& state, Value thisValue,
|
|||
}
|
||||
|
||||
size_t argumentVectorCount = argc > 1 ? argc - 1 : 0;
|
||||
Value sourceValue = argc >= 1 ? argv[argc - 1] : Value(String::emptyString);
|
||||
Value sourceValue = argc >= 1 ? argv[argc - 1] : Value(String::emptyString());
|
||||
auto functionSource = FunctionObject::createDynamicFunctionScript(state, state.context()->staticStrings().anonymous, argumentVectorCount, argv, sourceValue, false, false, false, false);
|
||||
|
||||
// Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).
|
||||
|
|
@ -81,7 +81,7 @@ static Value builtinFunctionToString(ExecutionState& state, Value thisValue, siz
|
|||
while (length > 0 && EscargotLexer::isWhiteSpaceOrLineTerminator(src[length - 1])) {
|
||||
length--;
|
||||
}
|
||||
builder.appendString(new StringView(src, 0, length));
|
||||
builder.appendString(new StringView(src, 0, length), &state);
|
||||
} else {
|
||||
ASSERT(fn->isNativeFunctionObject());
|
||||
builder.appendString("function ");
|
||||
|
|
@ -155,7 +155,7 @@ static Value builtinFunctionBind(ExecutionState& state, Value thisValue, size_t
|
|||
Value boundThis = argv[0];
|
||||
size_t boundArgc = (argc > 0) ? argc - 1 : 0;
|
||||
Value* boundArgv = (boundArgc > 0) ? argv + 1 : nullptr;
|
||||
//BoundFunctionObject* F = new BoundFunctionObject(state, thisValue, boundThis, boundArgc, boundArgv);
|
||||
// BoundFunctionObject* F = new BoundFunctionObject(state, thisValue, boundThis, boundArgc, boundArgv);
|
||||
|
||||
// Let targetHasLength be HasOwnProperty(Target, "length").
|
||||
bool targetHasLength = target->hasOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().length));
|
||||
|
|
@ -179,14 +179,14 @@ static Value builtinFunctionBind(ExecutionState& state, Value thisValue, size_t
|
|||
Value targetName = target->get(state, ObjectPropertyName(state.context()->staticStrings().name)).value(state, target);
|
||||
// If Type(targetName) is not String, let targetName be the empty string.
|
||||
if (!targetName.isString()) {
|
||||
targetName = String::emptyString;
|
||||
targetName = String::emptyString();
|
||||
}
|
||||
|
||||
StringBuilder builder;
|
||||
builder.appendString("bound ");
|
||||
builder.appendString(targetName.asString());
|
||||
//F->defineOwnPropertyThrowsException(state, ObjectPropertyName(state.context()->staticStrings().name),
|
||||
// ObjectPropertyDescriptor(Value(builder.finalize(&state)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
// F->defineOwnPropertyThrowsException(state, ObjectPropertyName(state.context()->staticStrings().name),
|
||||
// ObjectPropertyDescriptor(Value(builder.finalize(&state)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
// Let F be BoundFunctionCreate(Target, thisArg, args).
|
||||
// Let status be DefinePropertyOrThrow(F, "length", PropertyDescriptor {[[Value]]: L, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true}).
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Escargot {
|
|||
static Value builtinGeneratorFunction(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
size_t argumentVectorCount = argc > 1 ? argc - 1 : 0;
|
||||
Value sourceValue = argc >= 1 ? argv[argc - 1] : Value(String::emptyString);
|
||||
Value sourceValue = argc >= 1 ? argv[argc - 1] : Value(String::emptyString());
|
||||
auto functionSource = FunctionObject::createDynamicFunctionScript(state, state.context()->staticStrings().anonymous, argumentVectorCount, argv, sourceValue, false, true, false, false);
|
||||
|
||||
// Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).
|
||||
|
|
@ -71,14 +71,15 @@ void GlobalObject::installGenerator(ExecutionState& state)
|
|||
// %GeneratorFunction% : The constructor of generator objects
|
||||
m_generatorFunction = new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().GeneratorFunction, builtinGeneratorFunction, 1), NativeFunctionObject::__ForBuiltinConstructor__);
|
||||
m_generatorFunction->setGlobalIntrinsicObject(state);
|
||||
m_generatorFunction->setPrototype(state, m_function);
|
||||
|
||||
// %Generator% : The initial value of the prototype property of %GeneratorFunction%
|
||||
m_generator = new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().GeneratorFunction, nullptr, 0, NativeFunctionInfo::Strict));
|
||||
m_generator = new PrototypeObject(state, m_functionPrototype);
|
||||
m_generator->setGlobalIntrinsicObject(state, true);
|
||||
m_generatorFunction->setFunctionPrototype(state, m_generator);
|
||||
|
||||
// 25.2.3.1 The initial value of GeneratorFunction.prototype.constructor is the intrinsic object %GeneratorFunction%.
|
||||
m_generator->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().constructor), ObjectPropertyDescriptor(m_generatorFunction, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::NonWritablePresent | ObjectPropertyDescriptor::NonEnumerablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
m_generator->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().constructor), ObjectPropertyDescriptor(m_generatorFunction, ObjectPropertyDescriptor::ConfigurablePresent));
|
||||
|
||||
{
|
||||
ASSERT(!!m_callerAndArgumentsGetterSetter);
|
||||
|
|
@ -99,7 +100,7 @@ void GlobalObject::installGenerator(ExecutionState& state)
|
|||
// The initial value of the @@toStringTag property is the String value "GeneratorFunction"..
|
||||
// This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
|
||||
m_generator->directDefineOwnProperty(state, ObjectPropertyName(state, Value(state.context()->vmInstance()->globalSymbols().toStringTag)),
|
||||
ObjectPropertyDescriptor(Value(state.context()->staticStrings().GeneratorFunction.string()), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::NonWritablePresent | ObjectPropertyDescriptor::NonEnumerablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
ObjectPropertyDescriptor(state.context()->staticStrings().GeneratorFunction.string(), ObjectPropertyDescriptor::ConfigurablePresent));
|
||||
|
||||
// The initial value of Generator.prototype.constructor is the intrinsic object %Generator%.
|
||||
m_generatorPrototype->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().constructor), ObjectPropertyDescriptor(m_generator, ObjectPropertyDescriptor::ConfigurablePresent));
|
||||
|
|
@ -112,6 +113,6 @@ void GlobalObject::installGenerator(ExecutionState& state)
|
|||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().stringThrow, builtinGeneratorThrow, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
// http://www.ecma-international.org/ecma-262/6.0/#sec-generatorfunction.prototype-@@tostringtag
|
||||
m_generatorPrototype->directDefineOwnProperty(state, ObjectPropertyName(state, Value(state.context()->vmInstance()->globalSymbols().toStringTag)),
|
||||
ObjectPropertyDescriptor(Value(state.context()->staticStrings().Generator.string()), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::NonWritablePresent | ObjectPropertyDescriptor::NonEnumerablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
ObjectPropertyDescriptor(state.context()->staticStrings().Generator.string(), ObjectPropertyDescriptor::ConfigurablePresent));
|
||||
}
|
||||
} // namespace Escargot
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
1189
src/builtins/BuiltinIterator.cpp
Normal file
1189
src/builtins/BuiltinIterator.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -21,9 +21,9 @@
|
|||
#include "runtime/Context.h"
|
||||
#include "runtime/GlobalObject.h"
|
||||
#include "runtime/JSON.h"
|
||||
#include "runtime/RawJSONObject.h"
|
||||
#include "runtime/NativeFunctionObject.h"
|
||||
#include "runtime/VMInstance.h"
|
||||
#include "runtime/Value.h"
|
||||
|
||||
namespace Escargot {
|
||||
|
||||
|
|
@ -37,14 +37,63 @@ static Value builtinJSONStringify(ExecutionState& state, Value thisValue, size_t
|
|||
return JSON::stringify(state, argv[0], argv[1], argv[2]);
|
||||
}
|
||||
|
||||
// https://tc39.es/proposal-json-parse-with-source/#sec-json.rawjson
|
||||
static Value builtinJSONRawJSON(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// 1. Let jsonString be ? ToString(text).
|
||||
String* jsonString = argv[0].toString(state);
|
||||
// 2. Throw a SyntaxError exception if jsonString is the empty String, or
|
||||
// if either the first or last code unit of jsonString is any of 0x0009 (CHARACTER TABULATION), 0x000A (LINE FEED), 0x000D (CARRIAGE RETURN), or 0x0020 (SPACE).
|
||||
// 3. Parse StringToCodePoints(jsonString) as a JSON text as specified in ECMA-404.
|
||||
// Throw a SyntaxError exception if it is not a valid JSON text as defined in that specification,
|
||||
// or if its outermost value is an object or array as defined in that specification.
|
||||
auto msg = "input value is not valid JSON text";
|
||||
if (jsonString->length() == 0) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::SyntaxError, msg);
|
||||
}
|
||||
auto isWrongCodePoint = [](char32_t cp) -> bool {
|
||||
if (cp == 0x9 || cp == 0xa || cp == 0xd || cp == 0x20) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
if (isWrongCodePoint(jsonString->codePointAt(0).codePoint) || isWrongCodePoint(jsonString->codePointAt(jsonString->length() - 1).codePoint)) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::SyntaxError, msg);
|
||||
}
|
||||
|
||||
Value jsonParseResult;
|
||||
try {
|
||||
jsonParseResult = JSON::parse(state, jsonString, Value());
|
||||
} catch (const Value& e) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::SyntaxError, msg);
|
||||
}
|
||||
if (jsonParseResult.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::SyntaxError, msg);
|
||||
}
|
||||
// 4. Let internalSlotsList be « [[IsRawJSON]] ».
|
||||
// 5. Let obj be OrdinaryObjectCreate(null, internalSlotsList).
|
||||
// 6. Perform ! CreateDataPropertyOrThrow(obj, "rawJSON", jsonString).
|
||||
// 7. Perform ! SetIntegrityLevel(obj, frozen).
|
||||
// 8. Return obj.
|
||||
return new RawJSONObject(state, jsonString);
|
||||
}
|
||||
|
||||
// https://tc39.es/proposal-json-parse-with-source/#sec-json.israwjson
|
||||
static Value builtinJSONIsRawJSON(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// 1. If Type(O) is Object and O has an [[IsRawJSON]] internal slot, return true.
|
||||
if (argv[0].isObject() && argv[0].asObject()->isRawJSONObject()) {
|
||||
return Value(true);
|
||||
}
|
||||
// 2. Return false.
|
||||
return Value(false);
|
||||
}
|
||||
|
||||
void GlobalObject::initializeJSON(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->json();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->json(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().JSON), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
@ -69,5 +118,15 @@ void GlobalObject::installJSON(ExecutionState& state)
|
|||
m_json->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().stringify),
|
||||
ObjectPropertyDescriptor(m_jsonStringify,
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
auto rawJSON = new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().rawJSON, builtinJSONRawJSON, 1, NativeFunctionInfo::Strict));
|
||||
m_json->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().rawJSON),
|
||||
ObjectPropertyDescriptor(rawJSON,
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
auto isRawJSON = new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().isRawJSON, builtinJSONIsRawJSON, 1, NativeFunctionInfo::Strict));
|
||||
m_json->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().isRawJSON),
|
||||
ObjectPropertyDescriptor(isRawJSON,
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
}
|
||||
} // namespace Escargot
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include "runtime/Context.h"
|
||||
#include "runtime/VMInstance.h"
|
||||
#include "runtime/MapObject.h"
|
||||
#include "runtime/ArrayObject.h"
|
||||
#include "runtime/IteratorObject.h"
|
||||
#include "runtime/NativeFunctionObject.h"
|
||||
|
||||
|
|
@ -65,7 +66,8 @@ static Value builtinMapConstructor(ExecutionState& state, Value thisValue, size_
|
|||
|
||||
Value nextItem = IteratorObject::iteratorValue(state, next.value());
|
||||
if (!nextItem.isObject()) {
|
||||
ErrorObject* errorobj = ErrorObject::createError(state, ErrorCode::TypeError, new ASCIIString("TypeError"));
|
||||
ErrorObject* errorobj = ErrorObject::createError(state, ErrorCode::TypeError,
|
||||
new ASCIIStringFromExternalMemory("Invalid iterator value"));
|
||||
return IteratorObject::iteratorClose(state, iteratorRecord, errorobj, true);
|
||||
}
|
||||
|
||||
|
|
@ -116,6 +118,18 @@ static Value builtinMapGet(ExecutionState& state, Value thisValue, size_t argc,
|
|||
return M->get(state, argv[0]);
|
||||
}
|
||||
|
||||
static Value builtinMapGetOrInsert(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_MAP(M, Map, getOrInsert);
|
||||
return M->getOrInsert(state, argv[0], argv[1]);
|
||||
}
|
||||
|
||||
static Value builtinMapGetOrInsertComputed(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_MAP(M, Map, getOrInsertComputed);
|
||||
return M->getOrInsertComputed(state, argv[0], argv[1]);
|
||||
}
|
||||
|
||||
static Value builtinMapHas(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_MAP(M, Map, has);
|
||||
|
|
@ -194,14 +208,29 @@ static Value builtinMapIteratorNext(ExecutionState& state, Value thisValue, size
|
|||
return iter->next(state);
|
||||
}
|
||||
|
||||
// https://tc39.es/ecma262/multipage/keyed-collections.html#sec-map.groupby
|
||||
static Value builtinMapGroupBy(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// Let groups be ? GroupBy(items, callbackfn, COLLECTION).
|
||||
auto groups = IteratorObject::groupBy(state, argv[0], argv[1], IteratorObject::GroupByKeyCoercion::Collection);
|
||||
// Let map be ! Construct(%Map%).
|
||||
auto map = new MapObject(state);
|
||||
// For each Record { [[Key]], [[Elements]] } g of groups, do
|
||||
for (size_t i = 0; i < groups.size(); i++) {
|
||||
// Let elements be CreateArrayFromList(g.[[Elements]]).
|
||||
// Let entry be the Record { [[Key]]: g.[[Key]], [[Value]]: elements }.
|
||||
// Append entry to map.[[MapData]].
|
||||
map->set(state, groups[i]->key, Value(Object::createArrayFromList(state, groups[i]->elements)));
|
||||
}
|
||||
// Return map.
|
||||
return map;
|
||||
}
|
||||
|
||||
void GlobalObject::initializeMap(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->map();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->map(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().Map), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
@ -220,6 +249,10 @@ void GlobalObject::installMap(ExecutionState& state)
|
|||
m_map->directDefineOwnProperty(state, ObjectPropertyName(state.context()->vmInstance()->globalSymbols().species), desc);
|
||||
}
|
||||
|
||||
// Map.groupBy
|
||||
m_map->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().groupBy),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().groupBy, builtinMapGroupBy, 2, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_mapPrototype = new MapObject(state, m_objectPrototype);
|
||||
m_mapPrototype->setGlobalIntrinsicObject(state, true);
|
||||
m_mapPrototype->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().constructor), ObjectPropertyDescriptor(m_map, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
|
@ -233,6 +266,12 @@ void GlobalObject::installMap(ExecutionState& state)
|
|||
m_mapPrototype->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().get),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().get, builtinMapGet, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_mapPrototype->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().getOrInsert),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().getOrInsert, builtinMapGetOrInsert, 2, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_mapPrototype->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().getOrInsertComputed),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().getOrInsertComputed, builtinMapGetOrInsertComputed, 2, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_mapPrototype->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().has),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().has, builtinMapHas, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
|
|
|
|||
|
|
@ -24,10 +24,13 @@
|
|||
#include "runtime/ThreadLocal.h"
|
||||
#include "runtime/StringObject.h"
|
||||
#include "runtime/NativeFunctionObject.h"
|
||||
#include "runtime/IteratorObject.h"
|
||||
|
||||
#include "runtime/IEEE754.h"
|
||||
#include <math.h>
|
||||
|
||||
#include "xsum.h"
|
||||
|
||||
namespace Escargot {
|
||||
|
||||
static Value builtinMathAbs(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
|
|
@ -320,6 +323,142 @@ static Value builtinMathFround(ExecutionState& state, Value thisValue, size_t ar
|
|||
return Value(Value::DoubleToIntConvertibleTestNeeds, static_cast<double>(static_cast<float>(x)));
|
||||
}
|
||||
|
||||
// This is extracted from Version 2.2.0 of the half library by Christian Rau.
|
||||
// See https://sourceforge.net/projects/half/.
|
||||
// The original copyright and MIT license are reproduced below:
|
||||
|
||||
// half - IEEE 754-based half-precision floating-point library.
|
||||
//
|
||||
// Copyright (c) 2012-2021 Christian Rau <rauy@users.sourceforge.net>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
/// Type traits for floating-point bits.
|
||||
template <typename T>
|
||||
struct bits {
|
||||
using type = unsigned char;
|
||||
};
|
||||
template <typename T>
|
||||
struct bits<const T> : bits<T> {};
|
||||
template <typename T>
|
||||
struct bits<volatile T> : bits<T> {};
|
||||
template <typename T>
|
||||
struct bits<const volatile T> : bits<T> {};
|
||||
|
||||
/// Unsigned integer of (at least) 64 bits width.
|
||||
template <>
|
||||
struct bits<double> {
|
||||
using type = std::uint_least64_t;
|
||||
};
|
||||
|
||||
|
||||
/// Fastest unsigned integer of (at least) 32 bits width.
|
||||
using uint32 = std::uint_fast32_t;
|
||||
|
||||
/// Half-precision overflow.
|
||||
/// \param sign half-precision value with sign bit only
|
||||
/// \return rounded overflowing half-precision value
|
||||
constexpr unsigned int overflow(unsigned int sign = 0) { return sign | 0x7C00; }
|
||||
|
||||
/// Half-precision underflow.
|
||||
/// \param sign half-precision value with sign bit only
|
||||
/// \return rounded underflowing half-precision value
|
||||
constexpr unsigned int underflow(unsigned int sign = 0) { return sign; }
|
||||
|
||||
/// Round half-precision number.
|
||||
/// \param value finite half-precision number to round
|
||||
/// \param g guard bit (most significant discarded bit)
|
||||
/// \param s sticky bit (or of all but the most significant discarded bits)
|
||||
/// \return rounded half-precision value
|
||||
constexpr unsigned int rounded(unsigned int value, int g, int s)
|
||||
{
|
||||
return value + (g & (s | value));
|
||||
}
|
||||
|
||||
/// Convert IEEE double-precision to half-precision.
|
||||
/// \param value double-precision value to convert
|
||||
/// \return rounded half-precision value
|
||||
inline unsigned int float2half_impl(double value)
|
||||
{
|
||||
bits<double>::type dbits;
|
||||
std::memcpy(&dbits, &value, sizeof(double));
|
||||
uint32 hi = dbits >> 32, lo = dbits & 0xFFFFFFFF;
|
||||
unsigned int sign = (hi >> 16) & 0x8000;
|
||||
hi &= 0x7FFFFFFF;
|
||||
if (hi >= 0x7FF00000)
|
||||
return sign | 0x7C00 | ((dbits & 0xFFFFFFFFFFFFF) ? (0x200 | ((hi >> 10) & 0x3FF)) : 0);
|
||||
if (hi >= 0x40F00000)
|
||||
return overflow(sign);
|
||||
if (hi >= 0x3F100000)
|
||||
return rounded(sign | (((hi >> 20) - 1008) << 10) | ((hi >> 10) & 0x3FF),
|
||||
(hi >> 9) & 1, ((hi & 0x1FF) | lo) != 0);
|
||||
if (hi >= 0x3E600000) {
|
||||
int i = 1018 - (hi >> 20);
|
||||
hi = (hi & 0xFFFFF) | 0x100000;
|
||||
return rounded(sign | (hi >> (i + 1)), (hi >> i) & 1,
|
||||
((hi & ((static_cast<uint32>(1) << i) - 1)) | lo) != 0);
|
||||
}
|
||||
if ((hi | lo) != 0)
|
||||
return underflow(sign);
|
||||
return sign;
|
||||
}
|
||||
|
||||
/// Convert half-precision to IEEE double-precision.
|
||||
/// \param value half-precision value to convert
|
||||
/// \return double-precision value
|
||||
inline double half2float_impl(unsigned int value)
|
||||
{
|
||||
uint32 hi = static_cast<uint32>(value & 0x8000) << 16;
|
||||
unsigned int abs = value & 0x7FFF;
|
||||
if (abs) {
|
||||
hi |= 0x3F000000 << static_cast<unsigned>(abs >= 0x7C00);
|
||||
for (; abs < 0x400; abs <<= 1, hi -= 0x100000)
|
||||
;
|
||||
hi += static_cast<uint32>(abs) << 10;
|
||||
}
|
||||
bits<double>::type dbits = static_cast<bits<double>::type>(hi) << 32;
|
||||
double out;
|
||||
std::memcpy(&out, &dbits, sizeof(double));
|
||||
return out;
|
||||
}
|
||||
|
||||
// End of the half library extraction.
|
||||
|
||||
// \brief Conversion from float/double to half round number.
|
||||
// \details For the specification, see https://tc39.es/proposal-float16array/#sec-function-properties-of-the-math-object.
|
||||
// \author Anwar Fuadi
|
||||
// \date 2025-present
|
||||
static auto builtinMathF16round(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget) -> Value
|
||||
{
|
||||
// 1. Let n be ? ToNumber(x).
|
||||
auto x = double{ argv[0].toNumber(state) };
|
||||
|
||||
// 2. If n is NaN, return NaN.
|
||||
// 3. If n is one of +0𝔽, -0𝔽, +∞𝔽, or -∞𝔽, return n.
|
||||
// 4. Let n16 be the result of converting n to IEEE 754-2019 binary16 format using roundTiesToEven mode.
|
||||
auto f16 = float2half_impl(x);
|
||||
x = half2float_impl(f16);
|
||||
// 5. Let n64 be the result of converting n16 to IEEE 754-2019 binary64 format.
|
||||
// 6. Return the ECMAScript Number value corresponding to n64.
|
||||
return Value(Value::DoubleToIntConvertibleTestNeeds, x);
|
||||
}
|
||||
|
||||
static Value builtinMathHypot(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
double maxValue = 0;
|
||||
|
|
@ -409,14 +548,133 @@ static Value builtinMathExpm1(ExecutionState& state, Value thisValue, size_t arg
|
|||
return Value(Value::DoubleToIntConvertibleTestNeeds, ieee754::expm1(x));
|
||||
}
|
||||
|
||||
enum class SumPreciseState {
|
||||
MinusZero,
|
||||
NotANumber,
|
||||
MinusInfinity,
|
||||
PlusInfinity,
|
||||
Finite
|
||||
};
|
||||
|
||||
// https://tc39.es/proposal-math-sum/#sec-math.sumprecise
|
||||
static Value builtinMathSumPrecise(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
const Value& items = argv[0];
|
||||
|
||||
// 1. Perform ? RequireObjectCoercible(items).
|
||||
if (items.isUndefinedOrNull()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "sumPrecise called on undefined or null");
|
||||
}
|
||||
|
||||
xsum_small_accumulator sacc;
|
||||
xsum_small_init(&sacc);
|
||||
|
||||
// 2. Let iteratorRecord be ? GetIterator(items, sync).
|
||||
auto iteratorRecord = IteratorObject::getIterator(state, items, true);
|
||||
// 3. Let state be minus-zero.
|
||||
SumPreciseState sumPreciseState = SumPreciseState::MinusZero;
|
||||
// 4. Let sum be 0.
|
||||
// 5. Let count be 0.
|
||||
// 6. Let next be not-started.
|
||||
uint64_t count = 0;
|
||||
// 7. Repeat, while next is not done,
|
||||
while (true) {
|
||||
// a. Set next to ? IteratorStepValue(iteratorRecord).
|
||||
auto next = IteratorObject::iteratorStepValue(state, iteratorRecord);
|
||||
// b. If next is not done, then
|
||||
if (next) {
|
||||
// i. Set count to count + 1.
|
||||
count++;
|
||||
// ii. If count ≥ 2**53, then
|
||||
if (count >= (1LL << 53LL)) {
|
||||
// 1. Let error be ThrowCompletion(a newly created RangeError object).
|
||||
Value error = ErrorObject::createError(state, ErrorCode::TypeError, new ASCIIStringFromExternalMemory("Too many result on sumPrecise function"));
|
||||
// 2. Return ? IteratorClose(iteratorRecord, error).
|
||||
IteratorObject::iteratorClose(state, iteratorRecord, error, true);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
// iii. NOTE: The above case is not expected to be reached in practice and is included only so that implementations may rely on inputs being "reasonably sized" without violating this specification.
|
||||
// iv. If next is not a Number, then
|
||||
if (!next.value().isNumber()) {
|
||||
// 1. Let error be ThrowCompletion(a newly created TypeError object).
|
||||
Value error = ErrorObject::createError(state, ErrorCode::TypeError, new ASCIIStringFromExternalMemory("sumPrecise function needs number value"));
|
||||
// 2. Return ? IteratorClose(iteratorRecord, error).
|
||||
IteratorObject::iteratorClose(state, iteratorRecord, error, true);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
// v. Let n be next.
|
||||
double n = next.value().asNumber();
|
||||
// vi. If state is not not-a-number, then
|
||||
if (sumPreciseState != SumPreciseState::NotANumber) {
|
||||
// 1. If n is NaN, then
|
||||
if (std::isnan(n)) {
|
||||
// a. Set state to not-a-number.
|
||||
sumPreciseState = SumPreciseState::NotANumber;
|
||||
} else if (std::isinf(n) && std::signbit(n) == 0) {
|
||||
// 2. Else if n is +∞𝔽, then
|
||||
// a. If state is minus-infinity, set state to not-a-number.
|
||||
if (sumPreciseState == SumPreciseState::MinusInfinity) {
|
||||
sumPreciseState = SumPreciseState::NotANumber;
|
||||
} else {
|
||||
// b. Else, set state to plus-infinity.
|
||||
sumPreciseState = SumPreciseState::PlusInfinity;
|
||||
}
|
||||
} else if (std::isinf(n) && std::signbit(n) == 1) {
|
||||
// 3. Else if n is -∞𝔽, then
|
||||
// a. If state is plus-infinity, set state to not-a-number.
|
||||
if (sumPreciseState == SumPreciseState::PlusInfinity) {
|
||||
sumPreciseState = SumPreciseState::NotANumber;
|
||||
} else {
|
||||
// b. Else, set state to minus-infinity.
|
||||
sumPreciseState = SumPreciseState::MinusInfinity;
|
||||
}
|
||||
} else if (!(n == 0 && std::signbit(n)) && (sumPreciseState == SumPreciseState::MinusZero || sumPreciseState == SumPreciseState::Finite)) {
|
||||
// 4. Else if n is not -0𝔽 and state is either minus-zero or finite, then
|
||||
// a. Set state to finite.
|
||||
sumPreciseState = SumPreciseState::Finite;
|
||||
// b. Set sum to sum + ℝ(n).
|
||||
xsum_small_add1(&sacc, n);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 8. If state is not-a-number, return NaN.
|
||||
// 9. If state is plus-infinity, return +∞𝔽.
|
||||
// 10. If state is minus-infinity, return -∞𝔽.
|
||||
// 11. If state is minus-zero, return -0𝔽.
|
||||
// 12. Return 𝔽(sum).
|
||||
double result = 0;
|
||||
switch (sumPreciseState) {
|
||||
case SumPreciseState::NotANumber:
|
||||
result = std::numeric_limits<double>::quiet_NaN();
|
||||
break;
|
||||
case SumPreciseState::PlusInfinity:
|
||||
result = std::numeric_limits<double>::infinity();
|
||||
break;
|
||||
case SumPreciseState::MinusInfinity:
|
||||
result = -std::numeric_limits<double>::infinity();
|
||||
break;
|
||||
case SumPreciseState::MinusZero:
|
||||
result = -0.0;
|
||||
break;
|
||||
case SumPreciseState::Finite:
|
||||
result = xsum_small_round(&sacc);
|
||||
break;
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
return Value(Value::DoubleToIntConvertibleTestNeeds, result);
|
||||
}
|
||||
|
||||
void GlobalObject::initializeMath(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->math();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->math(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().Math), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
@ -553,6 +811,13 @@ void GlobalObject::installMath(ExecutionState& state)
|
|||
m_math->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().trunc),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().trunc, builtinMathTrunc, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_math->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().sumPrecise),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().sumPrecise, builtinMathSumPrecise, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_math->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().f16round),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().f16round, builtinMathF16round, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
|
||||
redefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().Math),
|
||||
ObjectPropertyDescriptor(m_math, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,24 +251,26 @@ static Value builtinNumberToString(ExecutionState& state, Value thisValue, size_
|
|||
bool minusFlag = (number < 0) ? 1 : 0;
|
||||
number = (number < 0) ? (-1 * number) : number;
|
||||
char buffer[256];
|
||||
size_t len;
|
||||
if (minusFlag) {
|
||||
buffer[0] = '-';
|
||||
itoa(static_cast<int64_t>(number), &buffer[1], radix);
|
||||
len = itoa(static_cast<int64_t>(number), &buffer[1], radix);
|
||||
len += 1;
|
||||
} else {
|
||||
itoa(static_cast<int64_t>(number), buffer, radix);
|
||||
len = itoa(static_cast<int64_t>(number), buffer, radix);
|
||||
}
|
||||
return String::fromASCII(buffer, strlen(buffer));
|
||||
return String::fromASCII(buffer, len);
|
||||
} else {
|
||||
ASSERT(Value(Value::DoubleToIntConvertibleTestNeeds, number).isDouble());
|
||||
NumberObject::RadixBuffer s;
|
||||
const char* str = NumberObject::toStringWithRadix(state, s, number, radix);
|
||||
return String::fromASCII(str, strlen(str));
|
||||
return String::fromASCII(str, strnlen(str, sizeof(NumberObject::RadixBuffer)));
|
||||
}
|
||||
}
|
||||
|
||||
static Value builtinNumberToLocaleString(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, Number, toLocaleString);
|
||||
Object* thisObject = thisValue.toObject(state);
|
||||
if (!thisObject->isNumberObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ThisNotNumber);
|
||||
}
|
||||
|
|
@ -384,12 +386,9 @@ static Value builtinNumberIsSafeInteger(ExecutionState& state, Value thisValue,
|
|||
|
||||
void GlobalObject::initializeNumber(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->number();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->number(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().Number), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,8 +71,7 @@ static Value builtinObjectConstructor(ExecutionState& state, Value thisValue, si
|
|||
|
||||
static Value builtinObjectValueOf(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(ret, Object, valueOf);
|
||||
return ret;
|
||||
return thisValue.toObject(state);
|
||||
}
|
||||
|
||||
static Value builtinObjectPreventExtensions(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
|
|
@ -271,7 +270,7 @@ static Value builtinObjectIsPrototypeOf(ExecutionState& state, Value thisValue,
|
|||
Value V = argv[0];
|
||||
|
||||
// Let O be the result of calling ToObject passing the this value as the argument.
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(O, Object, isPrototypeOf);
|
||||
Object* O = thisValue.toObject(state);
|
||||
|
||||
// Repeat
|
||||
while (true) {
|
||||
|
|
@ -293,7 +292,7 @@ static Value builtinObjectPropertyIsEnumerable(ExecutionState& state, Value this
|
|||
ObjectPropertyName P(state, argv[0]);
|
||||
|
||||
// Let O be the result of calling ToObject passing the this value as the argument.
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(O, Object, propertyIsEnumerable);
|
||||
Object* O = thisValue.toObject(state);
|
||||
|
||||
// Let desc be the result of calling the [[GetOwnProperty]] internal method of O with argument name.
|
||||
ObjectGetResult desc = O->getOwnProperty(state, P);
|
||||
|
|
@ -311,7 +310,7 @@ static Value builtinObjectToLocaleString(ExecutionState& state, Value thisValue,
|
|||
// https://www.ecma-international.org/ecma-262/#sec-object.prototype.tolocalestring
|
||||
// Let O be the this value.
|
||||
// Return ? Invoke(O, "toString").
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(O, Object, toLocaleString);
|
||||
Object* O = thisValue.toObject(state);
|
||||
Value toString = O->get(state, ObjectPropertyName(state.context()->staticStrings().toString)).value(state, thisValue);
|
||||
return Object::call(state, toString, thisValue, 0, nullptr);
|
||||
}
|
||||
|
|
@ -348,10 +347,9 @@ static Value builtinObjectSetPrototypeOf(ExecutionState& state, Value thisValue,
|
|||
|
||||
// 5. Let status be O.[[SetPrototypeOf]](proto).
|
||||
Object* obj = object.toObject(state);
|
||||
bool status = obj->setPrototype(state, proto);
|
||||
|
||||
// 7. If status is false, throw a TypeError exception.
|
||||
if (!status) {
|
||||
if (!obj->setPrototype(state, proto)) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().Object.string(), false, state.context()->staticStrings().setPrototypeOf.string(), "can't set prototype of this object");
|
||||
return Value();
|
||||
}
|
||||
|
|
@ -395,7 +393,8 @@ static Value builtinObjectFromEntries(ExecutionState& state, Value thisValue, si
|
|||
|
||||
Value nextItem = IteratorObject::iteratorValue(state, next.value());
|
||||
if (!nextItem.isObject()) {
|
||||
ErrorObject* errorobj = ErrorObject::createError(state, ErrorCode::TypeError, new ASCIIString("TypeError"));
|
||||
ErrorObject* errorobj = ErrorObject::createError(state, ErrorCode::TypeError,
|
||||
new ASCIIStringFromExternalMemory("Invalid iterator value"));
|
||||
return IteratorObject::iteratorClose(state, iteratorRecord, errorobj, true);
|
||||
}
|
||||
|
||||
|
|
@ -642,7 +641,7 @@ static Value builtinDefineGetter(ExecutionState& state, Value thisValue, size_t
|
|||
Object* O = thisValue.toObject(state);
|
||||
// If IsCallable(getter) is false, throw a TypeError exception.
|
||||
if (!argv[1].isCallable()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, String::emptyString, true, state.context()->staticStrings().__defineGetter__.string(), ErrorObject::Messages::GlobalObject_CallbackNotCallable);
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, String::emptyString(), true, state.context()->staticStrings().__defineGetter__.string(), ErrorObject::Messages::GlobalObject_CallbackNotCallable);
|
||||
}
|
||||
// Let desc be PropertyDescriptor{[[Get]]: getter, [[Enumerable]]: true, [[Configurable]]: true}.
|
||||
ObjectPropertyDescriptor desc(JSGetterSetter(argv[1].asObject(), Value(Value::EmptyValue)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::EnumerablePresent | ObjectPropertyDescriptor::ConfigurablePresent));
|
||||
|
|
@ -668,7 +667,7 @@ static Value builtinDefineSetter(ExecutionState& state, Value thisValue, size_t
|
|||
Object* O = thisValue.toObject(state);
|
||||
// If IsCallable(getter) is false, throw a TypeError exception.
|
||||
if (!argv[1].isCallable()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, String::emptyString, true, state.context()->staticStrings().__defineSetter__.string(), ErrorObject::Messages::GlobalObject_CallbackNotCallable);
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, String::emptyString(), true, state.context()->staticStrings().__defineSetter__.string(), ErrorObject::Messages::GlobalObject_CallbackNotCallable);
|
||||
}
|
||||
// Let desc be PropertyDescriptor{[[Get]]: getter, [[Enumerable]]: true, [[Configurable]]: true}.
|
||||
ObjectPropertyDescriptor desc(JSGetterSetter(Value(Value::EmptyValue), argv[1].asObject()), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::EnumerablePresent | ObjectPropertyDescriptor::ConfigurablePresent));
|
||||
|
|
@ -745,6 +744,24 @@ static Value builtinLookupSetter(ExecutionState& state, Value thisValue, size_t
|
|||
return Value();
|
||||
}
|
||||
|
||||
// https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-object.groupby
|
||||
static Value builtinObjectGroupBy(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// Let groups be ? GroupBy(items, callbackfn, PROPERTY).
|
||||
auto groups = IteratorObject::groupBy(state, argv[0], argv[1], IteratorObject::GroupByKeyCoercion::Property);
|
||||
// Let obj be OrdinaryObjectCreate(null).
|
||||
auto obj = new Object(state, Object::PrototypeIsNull);
|
||||
// For each Record { [[Key]], [[Elements]] } g of groups, do
|
||||
for (size_t i = 0; i < groups.size(); i++) {
|
||||
// Let elements be CreateArrayFromList(g.[[Elements]]).
|
||||
// Perform ! CreateDataPropertyOrThrow(obj, g.[[Key]], elements).
|
||||
obj->defineOwnPropertyThrowsException(state, ObjectPropertyName(state, groups[i]->key),
|
||||
ObjectPropertyDescriptor(Object::createArrayFromList(state, groups[i]->elements), ObjectPropertyDescriptor::AllPresent));
|
||||
}
|
||||
// Return obj.
|
||||
return obj;
|
||||
}
|
||||
|
||||
void GlobalObject::initializeObject(ExecutionState& state)
|
||||
{
|
||||
// Object should be installed at the start time
|
||||
|
|
@ -879,6 +896,10 @@ void GlobalObject::installObject(ExecutionState& state)
|
|||
m_object->directDefineOwnProperty(state, ObjectPropertyName(strings.hasOwn),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings.hasOwn, builtinObjectHasOwn, 2, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
// Object.groupBy
|
||||
m_object->directDefineOwnProperty(state, ObjectPropertyName(strings.groupBy),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings.groupBy, builtinObjectGroupBy, 2, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
// $19.1.3.2 Object.prototype.hasOwnProperty(V)
|
||||
m_objectPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings.hasOwnProperty),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings.hasOwnProperty, builtinObjectHasOwnProperty, 1, NativeFunctionInfo::Strict)), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
|
|
|||
|
|
@ -36,13 +36,13 @@ static Value builtinPromiseConstructor(ExecutionState& state, Value thisValue, s
|
|||
{
|
||||
auto strings = &state.context()->staticStrings();
|
||||
if (!newTarget.hasValue()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Promise.string(), false, String::emptyString, "%s: Promise constructor should be called with new Promise()");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Promise.string(), false, String::emptyString(), "%s: Promise constructor should be called with new Promise()");
|
||||
return Value();
|
||||
}
|
||||
|
||||
Value executor = argv[0];
|
||||
if (!executor.isCallable()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Promise.string(), false, String::emptyString, "%s: Promise executor is not a function object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Promise.string(), false, String::emptyString(), "%s: Promise executor is not a function object");
|
||||
}
|
||||
|
||||
// Let promise be ? OrdinaryCreateFromConstructor(NewTarget, "%PromisePrototype%", « [[PromiseState]], [[PromiseResult]], [[PromiseFulfillReactions]], [[PromiseRejectReactions]], [[PromiseIsHandled]] »).
|
||||
|
|
@ -216,7 +216,7 @@ static Value builtinPromiseAll(ExecutionState& state, Value thisValue, size_t ar
|
|||
result = IteratorObject::iteratorClose(state, iteratorRecord, exceptionValue, true);
|
||||
}
|
||||
} catch (const Value& v) {
|
||||
exceptionValue = v;
|
||||
// ignore error value
|
||||
}
|
||||
|
||||
// If value is an abrupt completion,
|
||||
|
|
@ -323,7 +323,7 @@ static Value builtinPromiseRace(ExecutionState& state, Value thisValue, size_t a
|
|||
result = IteratorObject::iteratorClose(state, record, exceptionValue, true);
|
||||
}
|
||||
} catch (const Value& v) {
|
||||
exceptionValue = v;
|
||||
// ignore error here
|
||||
}
|
||||
// If value is an abrupt completion,
|
||||
// Perform ? Call(capability.[[Reject]], undefined, « value.[[Value]] »).
|
||||
|
|
@ -565,7 +565,7 @@ static Value builtinPromiseAllSettled(ExecutionState& state, Value thisValue, si
|
|||
try {
|
||||
result = IteratorObject::iteratorClose(state, iteratorRecord, exceptionValue, true);
|
||||
} catch (const Value& v) {
|
||||
exceptionValue = v;
|
||||
// ignore error value
|
||||
// IfAbruptRejectPromise(result, promiseCapability).
|
||||
// If value is an abrupt completion,
|
||||
// Perform ? Call(capability.[[Reject]], undefined, « value.[[Value]] »).
|
||||
|
|
@ -731,7 +731,7 @@ static Value builtinPromiseAny(ExecutionState& state, Value thisValue, size_t ar
|
|||
IteratorObject::iteratorClose(state, iteratorRecord, thrownValue, true);
|
||||
}
|
||||
} catch (const Value& v) {
|
||||
thrownValue = v;
|
||||
// ignore error here
|
||||
}
|
||||
// IfAbruptRejectPromise(result, promiseCapability).
|
||||
Object::call(state, promiseCapability.m_rejectFunction, Value(), 1, &thrownValue);
|
||||
|
|
@ -741,14 +741,74 @@ static Value builtinPromiseAny(ExecutionState& state, Value thisValue, size_t ar
|
|||
return result;
|
||||
}
|
||||
|
||||
// https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-promise.withResolvers
|
||||
static Value builtinPromiseWithResolvers(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// Let C be the this value.
|
||||
const Value& C = thisValue;
|
||||
// Let promiseCapability be ? NewPromiseCapability(C).
|
||||
if (!C.isObject()) {
|
||||
// NOTE: isConstructor will be checked on PromiseObject::newPromiseCapability function
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::Not_Constructor);
|
||||
}
|
||||
auto promiseCapability = PromiseObject::newPromiseCapability(state, C.asObject());
|
||||
// Let obj be OrdinaryObjectCreate(%Object.prototype%).
|
||||
Object* obj = new Object(state);
|
||||
|
||||
StaticStrings* strings = &state.context()->staticStrings();
|
||||
// Perform ! CreateDataPropertyOrThrow(obj, "promise", promiseCapability.[[Promise]]).
|
||||
obj->defineOwnPropertyThrowsException(state, ObjectPropertyName(strings->lazyPromise()),
|
||||
ObjectPropertyDescriptor(promiseCapability.m_promise, ObjectPropertyDescriptor::AllPresent));
|
||||
// Perform ! CreateDataPropertyOrThrow(obj, "resolve", promiseCapability.[[Resolve]]).
|
||||
obj->defineOwnPropertyThrowsException(state, ObjectPropertyName(strings->resolve),
|
||||
ObjectPropertyDescriptor(promiseCapability.m_resolveFunction, ObjectPropertyDescriptor::AllPresent));
|
||||
// Perform ! CreateDataPropertyOrThrow(obj, "reject", promiseCapability.[[Reject]]).
|
||||
obj->defineOwnPropertyThrowsException(state, ObjectPropertyName(strings->reject),
|
||||
ObjectPropertyDescriptor(promiseCapability.m_rejectFunction, ObjectPropertyDescriptor::AllPresent));
|
||||
// Return obj.
|
||||
return obj;
|
||||
}
|
||||
|
||||
// https://tc39.es/ecma262/#sec-promise.try
|
||||
static Value builtinPromiseTry(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// 1. Let C be the this value.
|
||||
const Value& C = thisValue;
|
||||
// 2. If C is not an Object, throw a TypeError exception.
|
||||
if (!C.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::Not_Constructor);
|
||||
}
|
||||
// 3. Let promiseCapability be ? NewPromiseCapability(C).
|
||||
auto promiseCapability = PromiseObject::newPromiseCapability(state, C.asObject());
|
||||
|
||||
// 4. Let status be Completion(Call(callback, undefined, args)).
|
||||
Value exception = Value(Value::EmptyValue);
|
||||
Value result;
|
||||
try {
|
||||
result = Object::call(state, argv[0], Value(), argc - 1, argv + 1);
|
||||
} catch (const Value& error) {
|
||||
exception = error;
|
||||
}
|
||||
|
||||
// 5. If status is an abrupt completion, then
|
||||
if (!exception.isEmpty()) {
|
||||
// a. Perform ? Call(promiseCapability.[[Reject]], undefined, « status.[[Value]] »).
|
||||
Object::call(state, promiseCapability.m_rejectFunction, Value(), 1, &exception);
|
||||
} else {
|
||||
// 6. Else,
|
||||
// a. Perform ? Call(promiseCapability.[[Resolve]], undefined, « status.[[Value]] »).
|
||||
Object::call(state, promiseCapability.m_resolveFunction, Value(), 1, &result);
|
||||
}
|
||||
|
||||
// 7. Return promiseCapability.[[Promise]].
|
||||
return promiseCapability.m_promise;
|
||||
}
|
||||
|
||||
void GlobalObject::initializePromise(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->promise();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->promise(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().Promise), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
@ -774,20 +834,24 @@ void GlobalObject::installPromise(ExecutionState& state)
|
|||
ObjectPropertyDescriptor(Value(state.context()->staticStrings().Promise.string()), (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
// $25.4.4.1 Promise.all(iterable);
|
||||
m_promiseAll = new NativeFunctionObject(state, NativeFunctionInfo(strings->all, builtinPromiseAll, 1, NativeFunctionInfo::Strict));
|
||||
m_promise->directDefineOwnProperty(state, ObjectPropertyName(strings->all),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->all, builtinPromiseAll, 1, NativeFunctionInfo::Strict)),
|
||||
ObjectPropertyDescriptor(m_promiseAll,
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
// $25.4.4.3 Promise.race(iterable)
|
||||
m_promiseRace = new NativeFunctionObject(state, NativeFunctionInfo(strings->race, builtinPromiseRace, 1, NativeFunctionInfo::Strict));
|
||||
m_promise->directDefineOwnProperty(state, ObjectPropertyName(strings->race),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->race, builtinPromiseRace, 1, NativeFunctionInfo::Strict)),
|
||||
ObjectPropertyDescriptor(m_promiseRace,
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
// $25.4.4.4 Promise.reject(r)
|
||||
m_promiseReject = new NativeFunctionObject(state, NativeFunctionInfo(strings->reject, builtinPromiseReject, 1, NativeFunctionInfo::Strict));
|
||||
m_promise->directDefineOwnProperty(state, ObjectPropertyName(strings->reject),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->reject, builtinPromiseReject, 1, NativeFunctionInfo::Strict)),
|
||||
ObjectPropertyDescriptor(m_promiseReject,
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
// $25.4.4.5 Promise.resolve(r)
|
||||
m_promiseResolve = new NativeFunctionObject(state, NativeFunctionInfo(strings->resolve, builtinPromiseResolve, 1, NativeFunctionInfo::Strict));
|
||||
m_promise->directDefineOwnProperty(state, ObjectPropertyName(strings->resolve),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->resolve, builtinPromiseResolve, 1, NativeFunctionInfo::Strict)),
|
||||
ObjectPropertyDescriptor(m_promiseResolve,
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
// $25.4.5.1 Promise.prototype.catch(onRejected)
|
||||
m_promisePrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->stringCatch),
|
||||
|
|
@ -805,12 +869,24 @@ void GlobalObject::installPromise(ExecutionState& state)
|
|||
m_promise->setFunctionPrototype(state, m_promisePrototype);
|
||||
|
||||
// Promise.allSettled ( iterable )
|
||||
m_promiseAllSettled = new NativeFunctionObject(state, NativeFunctionInfo(strings->allSettled, builtinPromiseAllSettled, 1, NativeFunctionInfo::Strict));
|
||||
m_promise->directDefineOwnProperty(state, ObjectPropertyName(strings->allSettled),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->allSettled, builtinPromiseAllSettled, 1, NativeFunctionInfo::Strict)),
|
||||
ObjectPropertyDescriptor(m_promiseAllSettled,
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
// Promise.any ( iterable )
|
||||
m_promiseAny = new NativeFunctionObject(state, NativeFunctionInfo(strings->any, builtinPromiseAny, 1, NativeFunctionInfo::Strict));
|
||||
m_promise->directDefineOwnProperty(state, ObjectPropertyName(strings->any),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->any, builtinPromiseAny, 1, NativeFunctionInfo::Strict)),
|
||||
ObjectPropertyDescriptor(m_promiseAny,
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
// Promise.withResolvers()
|
||||
m_promise->directDefineOwnProperty(state, ObjectPropertyName(strings->withResolvers),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->withResolvers, builtinPromiseWithResolvers, 0, NativeFunctionInfo::Strict)),
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
// Promise.try()
|
||||
m_promise->directDefineOwnProperty(state, ObjectPropertyName(strings->stringTry),
|
||||
ObjectPropertyDescriptor(new NativeFunctionObject(state, NativeFunctionInfo(strings->stringTry, builtinPromiseTry, 1, NativeFunctionInfo::Strict)),
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ static Value builtinProxyConstructor(ExecutionState& state, Value thisValue, siz
|
|||
auto strings = &state.context()->staticStrings();
|
||||
|
||||
if (!newTarget.hasValue()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Proxy.string(), false, String::emptyString, "%s: calling a builtin Proxy constructor without new is forbidden");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Proxy.string(), false, String::emptyString(), "%s: calling a builtin Proxy constructor without new is forbidden");
|
||||
return Value();
|
||||
}
|
||||
|
||||
|
|
@ -107,12 +107,9 @@ static Value builtinProxyRevocable(ExecutionState& state, Value thisValue, size_
|
|||
|
||||
void GlobalObject::initializeProxy(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->proxy();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->proxy(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().Proxy), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ static Value builtinReflectApply(ExecutionState& state, Value thisValue, size_t
|
|||
|
||||
// 1. If IsCallable(target) is false, throw a TypeError exception.
|
||||
if (!target.isObject() || !target.asObject()->isCallable()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: calling a not-callable target in apply function is forbidden");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: calling a not-callable target in apply function is forbidden");
|
||||
}
|
||||
|
||||
// 2. Let args be CreateListFromArrayLike(argumentsList).
|
||||
|
|
@ -59,13 +59,13 @@ static Value builtinReflectConstruct(ExecutionState& state, Value thisValue, siz
|
|||
|
||||
// 1. If IsConstructor(target) is false, throw a TypeError exception.
|
||||
if (!target.isConstructor()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.construct should has a construct method");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.construct should has a construct method");
|
||||
}
|
||||
|
||||
// 2. If newTarget is not present, let newTarget be target.
|
||||
// 3. Else, if IsConstructor(newTarget) is false, throw a TypeError exception.
|
||||
if (!newTargetArg.isConstructor()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The new target of Reflect.construct should be a constructor");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The new target of Reflect.construct should be a constructor");
|
||||
}
|
||||
|
||||
// 4. Let args be CreateListFromArrayLike(argumentsList).
|
||||
|
|
@ -82,13 +82,16 @@ static Value builtinReflectDefineProperty(ExecutionState& state, Value thisValue
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.defineProperty should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.defineProperty should be an Object");
|
||||
}
|
||||
|
||||
// 2. Let key be ToPropertyKey(propertyKey).
|
||||
ObjectPropertyName key(state, argv[1]);
|
||||
|
||||
// 3. Let desc be ToPropertyDescriptor(attributes).
|
||||
if (!argv[2].isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The attributes of Reflect.defineProperty should be an Object");
|
||||
}
|
||||
ObjectPropertyDescriptor desc(state, argv[2].asObject());
|
||||
|
||||
// 6. Return target.[[DefineOwnProperty]](key, desc).
|
||||
|
|
@ -103,7 +106,7 @@ static Value builtinReflectDeleteProperty(ExecutionState& state, Value thisValue
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.deleteProperty should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.deleteProperty should be an Object");
|
||||
}
|
||||
|
||||
// 2. Let key be ToPropertyKey(propertyKey).
|
||||
|
|
@ -121,7 +124,7 @@ static Value builtinReflectGet(ExecutionState& state, Value thisValue, size_t ar
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.get should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.get should be an Object");
|
||||
}
|
||||
|
||||
// 2. Let key be ToPropertyKey(propertyKey).
|
||||
|
|
@ -143,7 +146,7 @@ static Value builtinReflectGetOwnPropertyDescriptor(ExecutionState& state, Value
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.getOwnPropertyDescriptor should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.getOwnPropertyDescriptor should be an Object");
|
||||
}
|
||||
|
||||
// 2. Let key be ToPropertyKey(propertyKey).
|
||||
|
|
@ -164,7 +167,7 @@ static Value builtinReflectGetPrototypeOf(ExecutionState& state, Value thisValue
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.getPrototypeOf should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.getPrototypeOf should be an Object");
|
||||
}
|
||||
|
||||
// 2. Return target.[[GetPrototypeOf]]().
|
||||
|
|
@ -179,7 +182,7 @@ static Value builtinReflectHas(ExecutionState& state, Value thisValue, size_t ar
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.has should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.has should be an Object");
|
||||
}
|
||||
|
||||
// 2. Let key be ToPropertyKey(propertyKey).
|
||||
|
|
@ -197,7 +200,7 @@ static Value builtinReflectIsExtensible(ExecutionState& state, Value thisValue,
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.isExtensible should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.isExtensible should be an Object");
|
||||
}
|
||||
|
||||
// 2. Return target.[[IsExtensible]]().
|
||||
|
|
@ -212,7 +215,7 @@ static Value builtinReflectPreventExtensions(ExecutionState& state, Value thisVa
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.preventExtension should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.preventExtension should be an Object");
|
||||
}
|
||||
|
||||
// 2. Return target.[[PreventExtensions]]().
|
||||
|
|
@ -227,7 +230,7 @@ static Value builtinReflectOwnKeys(ExecutionState& state, Value thisValue, size_
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.preventExtension should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.preventExtension should be an Object");
|
||||
}
|
||||
// 2. Let keys be target.[[OwnPropertyKeys]]().
|
||||
// 3. ReturnIfAbrupt(keys).
|
||||
|
|
@ -245,7 +248,7 @@ static Value builtinReflectSet(ExecutionState& state, Value thisValue, size_t ar
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.set should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.set should be an Object");
|
||||
}
|
||||
|
||||
// 2. Let key be ToPropertyKey(propertyKey).
|
||||
|
|
@ -268,12 +271,12 @@ static Value builtinReflectSetPrototypeOf(ExecutionState& state, Value thisValue
|
|||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!target.isObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The target of Reflect.setPrototypeOf should be an Object");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The target of Reflect.setPrototypeOf should be an Object");
|
||||
}
|
||||
|
||||
// 2. If Type(proto) is not Object and proto is not null, throw a TypeError exception
|
||||
if (!proto.isObject() && !proto.isNull()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString, "%s: The proto of Reflect.setPrototypeOf should be an Object or Null");
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, strings->Reflect.string(), false, String::emptyString(), "%s: The proto of Reflect.setPrototypeOf should be an Object or Null");
|
||||
}
|
||||
|
||||
// 3. Return target.[[SetPrototypeOf]](proto).
|
||||
|
|
@ -282,12 +285,9 @@ static Value builtinReflectSetPrototypeOf(ExecutionState& state, Value thisValue
|
|||
|
||||
void GlobalObject::initializeReflect(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->reflect();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->reflect(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().Reflect), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include "runtime/RegExpObject.h"
|
||||
#include "runtime/ArrayObject.h"
|
||||
#include "runtime/NativeFunctionObject.h"
|
||||
#include "parser/Lexer.h"
|
||||
|
||||
namespace Escargot {
|
||||
|
||||
|
|
@ -31,8 +32,8 @@ static Value builtinRegExpConstructor(ExecutionState& state, Value thisValue, si
|
|||
{
|
||||
Value pattern = argv[0];
|
||||
Value flags = argv[1];
|
||||
String* source = pattern.isUndefined() ? String::emptyString : pattern.toString(state);
|
||||
String* option = flags.isUndefined() ? String::emptyString : flags.toString(state);
|
||||
String* source = pattern.isUndefined() ? String::emptyString() : pattern.toString(state);
|
||||
String* option = flags.isUndefined() ? String::emptyString() : flags.toString(state);
|
||||
|
||||
// Let patternIsRegExp be IsRegExp(pattern).
|
||||
bool patternIsRegExp = argv[0].isObject() && argv[0].asObject()->isRegExp(state);
|
||||
|
|
@ -61,10 +62,10 @@ static Value builtinRegExpConstructor(ExecutionState& state, Value thisValue, si
|
|||
option = flags.isUndefined() ? RegExpObject::computeRegExpOptionString(state, patternRegExp) : flags.toString(state);
|
||||
} else if (patternIsRegExp) {
|
||||
Value P = pattern.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().source)).value(state, pattern);
|
||||
source = P.isUndefined() ? String::emptyString : P.toString(state);
|
||||
source = P.isUndefined() ? String::emptyString() : P.toString(state);
|
||||
if (flags.isUndefined()) {
|
||||
Value F = pattern.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().flags)).value(state, pattern);
|
||||
option = F.isUndefined() ? String::emptyString : F.toString(state);
|
||||
option = F.isUndefined() ? String::emptyString() : F.toString(state);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +84,7 @@ static Value builtinRegExpConstructor(ExecutionState& state, Value thisValue, si
|
|||
|
||||
static Value builtinRegExpExec(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, RegExp, exec);
|
||||
Object* thisObject = thisValue.toObject(state);
|
||||
if (!thisObject->isRegExpObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().RegExp.string(), true, state.context()->staticStrings().exec.string(), ErrorObject::Messages::GlobalObject_ThisNotRegExpObject);
|
||||
}
|
||||
|
|
@ -106,13 +107,11 @@ static Value builtinRegExpExec(ExecutionState& state, Value thisValue, size_t ar
|
|||
if (regexp->matchNonGlobally(state, str, result, false, lastIndex)) {
|
||||
int e = result.m_matchResults[0][0].m_end;
|
||||
if (option & RegExpObject::Option::Unicode) {
|
||||
char16_t utfRes = str->charAt(e);
|
||||
char16_t utfRes = (static_cast<size_t>(e) == str->length()) ? 0 : str->charAt(e);
|
||||
const char* buf = reinterpret_cast<const char*>(&utfRes);
|
||||
size_t len = strnlen(buf, 2);
|
||||
size_t eUTF = str->find(buf, len, 0);
|
||||
if (eUTF >= str->length()) {
|
||||
e = str->length();
|
||||
} else if ((int)eUTF > e || e == (int)str->length()) {
|
||||
size_t eUTF = len == 0 ? str->length() : (str->find(buf, len, 0));
|
||||
if ((int)eUTF > e || e == (int)str->length()) {
|
||||
e = eUTF;
|
||||
}
|
||||
}
|
||||
|
|
@ -149,7 +148,7 @@ static Value regExpExec(ExecutionState& state, Object* R, String* S)
|
|||
|
||||
static Value builtinRegExpTest(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(thisObject, RegExp, test);
|
||||
Object* thisObject = thisValue.toObject(state);
|
||||
if (!thisObject->isRegExpObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, state.context()->staticStrings().RegExp.string(), true, state.context()->staticStrings().test.string(), ErrorObject::Messages::GlobalObject_ThisNotRegExpObject);
|
||||
}
|
||||
|
|
@ -181,14 +180,14 @@ static Value builtinRegExpToString(ExecutionState& state, Value thisValue, size_
|
|||
String* pattern = RegExpObject::regexpSourceValue(state, thisObject);
|
||||
Value flagsValue = RegExpObject::regexpFlagsValue(state, thisObject);
|
||||
|
||||
builder.appendString("/");
|
||||
builder.appendString(pattern);
|
||||
builder.appendString("/");
|
||||
builder.appendString("/", &state);
|
||||
builder.appendString(pattern, &state);
|
||||
builder.appendString("/", &state);
|
||||
|
||||
if (!flagsValue.isUndefined()) {
|
||||
builder.appendString(flagsValue.toString(state));
|
||||
builder.appendString(flagsValue.toString(state), &state);
|
||||
} else {
|
||||
builder.appendString("\0");
|
||||
builder.appendString("\0", &state);
|
||||
}
|
||||
|
||||
return builder.finalize(&state);
|
||||
|
|
@ -200,6 +199,29 @@ static Value builtinRegExpCompile(ExecutionState& state, Value thisValue, size_t
|
|||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ThisNotRegExpObject);
|
||||
}
|
||||
|
||||
Optional<Object*> proto = thisValue.asObject()->getPrototypeObject(state);
|
||||
Context* calleeContext = state.resolveCallee()->codeBlock()->context();
|
||||
|
||||
if (!proto || !proto->isRegExpPrototypeObject()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::GlobalObject_ThisNotRegExpObject);
|
||||
}
|
||||
|
||||
bool match = false;
|
||||
while (proto) {
|
||||
Value c = proto->getOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().constructor)).value(state, proto.value());
|
||||
if (c.isFunction()) {
|
||||
if (c.asFunction()->codeBlock()->context() == calleeContext) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
proto = proto->getPrototypeObject(state);
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "Cannot use compile function with another Realm");
|
||||
}
|
||||
|
||||
if (argv[0].isObject() && argv[0].asObject()->isRegExpObject()) {
|
||||
if (!argv[1].isUndefined()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "Cannot supply flags when constructing one RegExp from another");
|
||||
|
|
@ -216,15 +238,15 @@ static Value builtinRegExpCompile(ExecutionState& state, Value thisValue, size_t
|
|||
}
|
||||
|
||||
RegExpObject* retVal = thisValue.asPointerValue()->asObject()->asRegExpObject();
|
||||
String* pattern_str = argv[0].isUndefined() ? String::emptyString : argv[0].toString(state);
|
||||
String* flags_str = argv[1].isUndefined() ? String::emptyString : argv[1].toString(state);
|
||||
retVal->init(state, pattern_str, flags_str);
|
||||
String* patternStr = argv[0].isUndefined() ? String::emptyString() : argv[0].toString(state);
|
||||
String* flagsStr = argv[1].isUndefined() ? String::emptyString() : argv[1].toString(state);
|
||||
retVal->init(state, patternStr, flagsStr);
|
||||
return retVal;
|
||||
}
|
||||
static Value builtinRegExpSearch(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// $21.2.5.9 RegExp.prototype[@@search]
|
||||
RESOLVE_THIS_BINDING_TO_OBJECT(rx, Object, search);
|
||||
Object* rx = thisValue.toObject(state);
|
||||
String* s = argv[0].toString(state);
|
||||
Value previousLastIndex = rx->get(state, ObjectPropertyName(state.context()->staticStrings().lastIndex)).value(state, thisValue);
|
||||
if (!previousLastIndex.equalsToByTheSameValueAlgorithm(state, Value(0))) {
|
||||
|
|
@ -399,16 +421,19 @@ static Value builtinRegExpReplace(ExecutionState& state, Value thisValue, size_t
|
|||
size_t lengthStr = str->length();
|
||||
bool functionalReplace = replaceValue.isCallable();
|
||||
bool fullUnicode = false;
|
||||
String* replacement = String::emptyString;
|
||||
String* replacement = String::emptyString();
|
||||
size_t nextSourcePosition = 0;
|
||||
StringBuilder builder;
|
||||
|
||||
if (!functionalReplace) {
|
||||
replaceValue = replaceValue.toString(state);
|
||||
}
|
||||
bool global = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().global)).value(state, rx).toBoolean(state);
|
||||
|
||||
String* flags = rx.asObject()->get(state, ObjectPropertyName(state.context()->staticStrings().flags)).value(state, rx).toString(state);
|
||||
|
||||
bool global = flags->contains("g");
|
||||
if (global) {
|
||||
fullUnicode = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().unicode)).value(state, rx).toBoolean(state);
|
||||
fullUnicode = flags->contains("u");
|
||||
rx.asObject()->setThrowsException(state, ObjectPropertyName(state, state.context()->staticStrings().lastIndex), Value(0), rx);
|
||||
}
|
||||
ValueVectorWithInlineStorage results;
|
||||
|
|
@ -468,7 +493,7 @@ static Value builtinRegExpReplace(ExecutionState& state, Value thisValue, size_t
|
|||
if (!capN.isUndefined()) {
|
||||
captures.push_back(capN.toString(state));
|
||||
} else {
|
||||
captures.push_back(String::emptyString);
|
||||
captures.push_back(String::emptyString());
|
||||
}
|
||||
if (functionalReplace) {
|
||||
replacerArgs[n] = capN;
|
||||
|
|
@ -508,34 +533,35 @@ static Value builtinRegExpMatch(ExecutionState& state, Value thisValue, size_t a
|
|||
String* str = argv[0].toString(state);
|
||||
ASSERT(str != nullptr);
|
||||
|
||||
//21.2.5.6.8
|
||||
bool global = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().global)).value(state, rx).toBoolean(state);
|
||||
// 21.2.5.6.8
|
||||
String* flags = rx.asObject()->get(state, ObjectPropertyName(state.context()->staticStrings().flags)).value(state, rx).toString(state);
|
||||
bool global = flags->contains("g");
|
||||
|
||||
if (!global) {
|
||||
return regExpExec(state, rx.asObject(), str);
|
||||
}
|
||||
|
||||
bool fullUnicode = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().unicode)).value(state, rx).toBoolean(state);
|
||||
bool fullUnicode = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().unicode)).value(state, rx).toBoolean();
|
||||
rx.asObject()->setThrowsException(state, ObjectPropertyName(state, state.context()->staticStrings().lastIndex), Value(0), rx);
|
||||
ArrayObject* A = new ArrayObject(state);
|
||||
size_t n = 0;
|
||||
|
||||
//21.2.5.6.8.g.i
|
||||
// 21.2.5.6.8.g.i
|
||||
while (true) {
|
||||
//21.2.5.6.8.g.i
|
||||
// 21.2.5.6.8.g.i
|
||||
Value result = regExpExec(state, rx.asObject(), str);
|
||||
//21.2.5.6.8.g.iii
|
||||
// 21.2.5.6.8.g.iii
|
||||
if (result.isNull()) {
|
||||
if (n == 0) {
|
||||
return Value(Value::Null);
|
||||
}
|
||||
return A;
|
||||
} else {
|
||||
//21.2.5.6.8.g.iv
|
||||
// 21.2.5.6.8.g.iv
|
||||
Value matchStr = result.asObject()->get(state, ObjectPropertyName(state, Value(0))).value(state, result).toString(state);
|
||||
A->defineOwnProperty(state, ObjectPropertyName(state, Value(n).toString(state)), ObjectPropertyDescriptor(Value(matchStr), (ObjectPropertyDescriptor::PresentAttribute::AllPresent)));
|
||||
if (matchStr.asString()->length() == 0) {
|
||||
//21.2.5.6.8.g.iv.5
|
||||
// 21.2.5.6.8.g.iv.5
|
||||
uint64_t thisIndex = rx.asObject()->get(state, ObjectPropertyName(state, state.context()->staticStrings().lastIndex)).value(state, rx).toLength(state);
|
||||
uint64_t nextIndex = str->advanceStringIndex(thisIndex, fullUnicode);
|
||||
rx.asObject()->setThrowsException(state, state.context()->staticStrings().lastIndex, Value(nextIndex), rx);
|
||||
|
|
@ -567,7 +593,7 @@ static Value builtinRegExpMatchAll(ExecutionState& state, Value thisValue, size_
|
|||
if (flags->find("g") != SIZE_MAX) {
|
||||
global = true;
|
||||
}
|
||||
if (flags->find("u") != SIZE_MAX) {
|
||||
if (flags->find("u") != SIZE_MAX || flags->find("v") != SIZE_MAX) {
|
||||
unicode = true;
|
||||
}
|
||||
return new RegExpStringIteratorObject(state, global, unicode, matcher->asRegExpObject(), s);
|
||||
|
|
@ -620,6 +646,11 @@ static Value builtinRegExpMultiLineGetter(ExecutionState& state, Value thisValue
|
|||
return builtinRegExpOptionGetterHelper(state, thisValue, RegExpObject::Option::MultiLine);
|
||||
}
|
||||
|
||||
static Value builtinRegExpHasIndicesGetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
return builtinRegExpOptionGetterHelper(state, thisValue, RegExpObject::Option::HasIndices);
|
||||
}
|
||||
|
||||
static Value builtinRegExpSourceGetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
if (!thisValue.isObject()) {
|
||||
|
|
@ -647,6 +678,11 @@ static Value builtinRegExpUnicodeGetter(ExecutionState& state, Value thisValue,
|
|||
return builtinRegExpOptionGetterHelper(state, thisValue, RegExpObject::Option::Unicode);
|
||||
}
|
||||
|
||||
static Value builtinRegExpUnicodeSetsGetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
return builtinRegExpOptionGetterHelper(state, thisValue, RegExpObject::Option::UnicodeSets);
|
||||
}
|
||||
|
||||
|
||||
// Legacy RegExp Features (non-standard)
|
||||
static Value builtinRegExpInputGetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
|
|
@ -711,12 +747,229 @@ static Value builtinRegExpInputSetter(ExecutionState& state, Value thisValue, si
|
|||
if (!status.isValid()) { \
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, ErrorObject::Messages::String_InvalidStringLength); \
|
||||
} \
|
||||
return (status.dollarCount < number) ? String::emptyString : new StringView(status.dollars[number - 1]); \
|
||||
return (status.dollarCount < number) ? String::emptyString() : new StringView(status.dollars[number - 1]); \
|
||||
}
|
||||
|
||||
REGEXP_LEGACY_FEATURES(DEFINE_LEGACY_FEATURE_GETTER);
|
||||
REGEXP_LEGACY_DOLLAR_NUMBER_FEATURES(DEFINE_LEGACY_DOLLAR_NUMBER_FEATURE_GETTER);
|
||||
|
||||
// https://tc39.es/ecma262/#prod-SyntaxCharacter
|
||||
static bool isSyntaxChar(char32_t cp)
|
||||
{
|
||||
switch (cp) {
|
||||
case '^':
|
||||
case '$':
|
||||
case '\\':
|
||||
case '.':
|
||||
case '*':
|
||||
case '+':
|
||||
case '?':
|
||||
case '(':
|
||||
case ')':
|
||||
case '[':
|
||||
case ']':
|
||||
case '{':
|
||||
case '}':
|
||||
case '|':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void utf16EncodeCodePoint(ExecutionState& state, char32_t cp, LargeStringBuilder& builder)
|
||||
{
|
||||
auto r = utf16EncodeCodePoint(cp);
|
||||
if (r.second) {
|
||||
char16_t cu1 = floor((cp - 65536) / 1024) + 0xD800;
|
||||
char16_t cu2 = ((cp - 65536) % 1024) + 0xDC00;
|
||||
|
||||
builder.appendChar(cu1, &state);
|
||||
builder.appendChar(cu2, &state);
|
||||
} else {
|
||||
builder.appendChar(r.first, &state);
|
||||
}
|
||||
}
|
||||
|
||||
static bool isOtherPunctuators(char32_t cp)
|
||||
{
|
||||
// ",-=<>#&!%:;@~'`" and the code unit 0x0022 (QUOTATION MARK).
|
||||
switch (cp) {
|
||||
case ',':
|
||||
case '-':
|
||||
case '=':
|
||||
case '<':
|
||||
case '>':
|
||||
case '#':
|
||||
case '&':
|
||||
case '!':
|
||||
case '%':
|
||||
case ':':
|
||||
case ';':
|
||||
case '@':
|
||||
case '~':
|
||||
case '\'':
|
||||
case '`':
|
||||
case 0x22:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static std::pair<std::array<char, 12>, size_t> itoa(char32_t v)
|
||||
{
|
||||
std::array<char, 12> result;
|
||||
char* tp = result.data();
|
||||
while (v || tp == result.data()) {
|
||||
int i = v % 16;
|
||||
v /= 16;
|
||||
if (i < 10) {
|
||||
*tp++ = i + '0';
|
||||
} else {
|
||||
*tp++ = i + 'a' - 10;
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair(result, tp - result.data());
|
||||
}
|
||||
|
||||
// https://tc39.es/ecma262/#sec-unicodeescape
|
||||
static void unicodeEscape(ExecutionState& state, char32_t cp, LargeStringBuilder& builder)
|
||||
{
|
||||
ASSERT(cp <= 0x10FFFF);
|
||||
builder.appendChar(static_cast<char>(0x5C), &state);
|
||||
builder.appendChar('u', &state);
|
||||
|
||||
auto a = itoa(cp);
|
||||
int pad = 4 - a.second;
|
||||
while (pad > 0) {
|
||||
builder.appendChar('0', &state);
|
||||
pad--;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < a.second; i++) {
|
||||
builder.appendChar(a.first.at(a.second - i - 1), &state);
|
||||
}
|
||||
}
|
||||
|
||||
// https://tc39.es/ecma262/#sec-encodeforregexpescape
|
||||
static void encodeForRegExpEscape(ExecutionState& state, char32_t cp, LargeStringBuilder& builder)
|
||||
{
|
||||
// If cp is matched by SyntaxCharacter or cp is U+002F (SOLIDUS), then
|
||||
if (isSyntaxChar(cp) || cp == 0x02f) {
|
||||
// a. Return the string-concatenation of 0x005C (REVERSE SOLIDUS) and UTF16EncodeCodePoint(cp).
|
||||
builder.appendChar(static_cast<char>(0x5C), &state);
|
||||
utf16EncodeCodePoint(state, cp, builder);
|
||||
return;
|
||||
} else if (cp >= 0x09 && cp <= 0x0d) {
|
||||
// 2. Else if cp is a code point listed in the “Code Point” column of Table 67, then
|
||||
// a. Return the string-concatenation of 0x005C (REVERSE SOLIDUS) and the string in the “ControlEscape” column of the row whose “Code Point” column contains cp.
|
||||
builder.appendChar(static_cast<char>(0x5C), &state);
|
||||
switch (cp) {
|
||||
case 0x9:
|
||||
builder.appendChar('t', &state);
|
||||
break;
|
||||
case 0xa:
|
||||
builder.appendChar('n', &state);
|
||||
break;
|
||||
case 0xb:
|
||||
builder.appendChar('v', &state);
|
||||
break;
|
||||
case 0xc:
|
||||
builder.appendChar('f', &state);
|
||||
break;
|
||||
case 0xd:
|
||||
builder.appendChar('r', &state);
|
||||
break;
|
||||
default:
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Let otherPunctuators be the string-concatenation of ",-=<>#&!%:;@~'`" and the code unit 0x0022 (QUOTATION MARK).
|
||||
// 4. Let toEscape be StringToCodePoints(otherPunctuators).
|
||||
// 5. If toEscape contains cp, cp is matched by either WhiteSpace or LineTerminator, or cp has the same numeric value as a leading surrogate or trailing surrogate, then
|
||||
if (isOtherPunctuators(cp) || EscargotLexer::isWhiteSpaceOrLineTerminator(cp) || U16_IS_LEAD(cp) || U16_IS_TRAIL(cp)) {
|
||||
// a. Let cpNum be the numeric value of cp.
|
||||
// b. If cpNum ≤ 0xFF, then
|
||||
if (cp < 0xff) {
|
||||
// i. Let hex be Number::toString(𝔽(cpNum), 16).
|
||||
// ii. Return the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS), "x", and StringPad(hex, 2, "0", start).
|
||||
auto cd = charToHexCode(static_cast<char>(cp), false);
|
||||
builder.appendChar(static_cast<char>(0x5C), &state);
|
||||
builder.appendChar('x', &state);
|
||||
if (cd.first) {
|
||||
builder.appendChar(cd.first, &state);
|
||||
} else {
|
||||
// check
|
||||
builder.appendChar('0', &state);
|
||||
}
|
||||
builder.appendChar(cd.second, &state);
|
||||
return;
|
||||
}
|
||||
// c. Let escaped be the empty String.
|
||||
// d. Let codeUnits be UTF16EncodeCodePoint(cp).
|
||||
// e. For each code unit cu of codeUnits, do
|
||||
// i. Set escaped to the string-concatenation of escaped and UnicodeEscape(cu).
|
||||
// f. Return escaped.
|
||||
|
||||
auto r = utf16EncodeCodePoint(cp);
|
||||
if (r.second) {
|
||||
unicodeEscape(state, r.first, builder);
|
||||
unicodeEscape(state, r.second, builder);
|
||||
} else {
|
||||
unicodeEscape(state, r.first, builder);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 6. Return UTF16EncodeCodePoint(cp).
|
||||
utf16EncodeCodePoint(state, cp, builder);
|
||||
}
|
||||
|
||||
// https://tc39.es/ecma262/#sec-regexp.escape
|
||||
static Value builtinRegExpEscape(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
// 1. If S is not a String, throw a TypeError exception.
|
||||
if (!argv[0].isString()) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "First parameter must be String");
|
||||
}
|
||||
String* S = argv[0].asString();
|
||||
// 2. Let escaped be the empty String.
|
||||
// 3. Let cpList be StringToCodePoints(S).
|
||||
// 4. For each code point cp of cpList, do
|
||||
size_t index = 0;
|
||||
LargeStringBuilder builder;
|
||||
while (index < S->length()) {
|
||||
auto cp = S->codePointAt(index);
|
||||
// a. If escaped is the empty String and cp is matched by either DecimalDigit or AsciiLetter, then
|
||||
if ((builder.contentLength() == 0) && cp.codePoint < 128 && isASCIIAlphanumeric(cp.codePoint)) {
|
||||
// i. NOTE: Escaping a leading digit ensures that output corresponds with pattern text which may be used after a \0 character escape or a DecimalEscape such as \1 and still match S rather than be interpreted as an extension of the preceding escape sequence. Escaping a leading ASCII letter does the same for the context after \c.
|
||||
// ii. Let numericValue be the numeric value of cp.
|
||||
char numericValue = static_cast<char>(cp.codePoint);
|
||||
// iii. Let hex be Number::toString(𝔽(numericValue), 16).
|
||||
// iv. Assert: The length of hex is 2.
|
||||
// v. Set escaped to the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS), "x", and hex.
|
||||
auto cd = charToHexCode(numericValue, false);
|
||||
builder.appendChar(static_cast<char>(0x5C), &state);
|
||||
builder.appendChar('x', &state);
|
||||
builder.appendChar(cd.first, &state);
|
||||
builder.appendChar(cd.second, &state);
|
||||
} else {
|
||||
// b. Else,
|
||||
// i. Set escaped to the string-concatenation of escaped and EncodeForRegExpEscape(cp).
|
||||
encodeForRegExpEscape(state, cp.codePoint, builder);
|
||||
}
|
||||
|
||||
|
||||
index += cp.codeUnitCount;
|
||||
}
|
||||
// 5. Return escaped.
|
||||
return builder.finalize(&state);
|
||||
}
|
||||
|
||||
static Value builtinRegExpStringIteratorNext(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
|
||||
{
|
||||
if (!thisValue.isObject() || !thisValue.asObject()->isRegExpStringIteratorObject()) {
|
||||
|
|
@ -744,7 +997,7 @@ std::pair<Value, bool> RegExpStringIteratorObject::advance(ExecutionState& state
|
|||
if (global) {
|
||||
String* matchStr = match.asObject()->get(state, ObjectPropertyName(state, Value(0))).value(state, match).toString(state);
|
||||
if (matchStr->length() == 0) {
|
||||
//21.2.5.6.8.g.iv.5
|
||||
// 21.2.5.6.8.g.iv.5
|
||||
uint64_t thisIndex = r->get(state, ObjectPropertyName(state, state.context()->staticStrings().lastIndex)).value(state, r).toLength(state);
|
||||
uint64_t nextIndex = s->advanceStringIndex(thisIndex, unicode);
|
||||
r->setThrowsException(state, state.context()->staticStrings().lastIndex, Value(nextIndex), r);
|
||||
|
|
@ -757,12 +1010,9 @@ std::pair<Value, bool> RegExpStringIteratorObject::advance(ExecutionState& state
|
|||
|
||||
void GlobalObject::initializeRegExp(ExecutionState& state)
|
||||
{
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true,
|
||||
[](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ObjectPropertyNativeGetterSetterData* nativeData = new ObjectPropertyNativeGetterSetterData(true, false, true, [](ExecutionState& state, Object* self, const Value& receiver, const EncodedValue& privateDataFromObjectPrivateArea) -> Value {
|
||||
ASSERT(self->isGlobalObject());
|
||||
return self->asGlobalObject()->regexp();
|
||||
},
|
||||
nullptr);
|
||||
return self->asGlobalObject()->regexp(); }, nullptr);
|
||||
|
||||
defineNativeDataAccessorProperty(state, ObjectPropertyName(state.context()->staticStrings().RegExp), nativeData, Value(Value::EmptyValue));
|
||||
}
|
||||
|
|
@ -829,6 +1079,14 @@ void GlobalObject::installRegExp(ExecutionState& state)
|
|||
|
||||
REGEXP_LEGACY_DOLLAR_NUMBER_FEATURES(DEFINE_LEGACY_DOLLAR_NUMBER_ATTR);
|
||||
|
||||
|
||||
{
|
||||
auto fn = new NativeFunctionObject(state, NativeFunctionInfo(state.context()->staticStrings().escape, builtinRegExpEscape, 1, NativeFunctionInfo::Strict));
|
||||
m_regexp->directDefineOwnProperty(state, ObjectPropertyName(state.context()->staticStrings().escape),
|
||||
ObjectPropertyDescriptor(fn,
|
||||
(ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
}
|
||||
|
||||
m_regexpPrototype = new RegExpPrototypeObject(state);
|
||||
m_regexpPrototype->setGlobalIntrinsicObject(state, true);
|
||||
|
||||
|
|
@ -868,6 +1126,13 @@ void GlobalObject::installRegExp(ExecutionState& state)
|
|||
m_regexpPrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->multiline), desc);
|
||||
}
|
||||
|
||||
{
|
||||
Value getter = new NativeFunctionObject(state, NativeFunctionInfo(strings->getHasIndices, builtinRegExpHasIndicesGetter, 0, NativeFunctionInfo::Strict));
|
||||
JSGetterSetter gs(getter, Value());
|
||||
ObjectPropertyDescriptor desc(gs, ObjectPropertyDescriptor::ConfigurablePresent);
|
||||
m_regexpPrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->hasIndices), desc);
|
||||
}
|
||||
|
||||
{
|
||||
Value getter = new NativeFunctionObject(state, NativeFunctionInfo(strings->getSource, builtinRegExpSourceGetter, 0, NativeFunctionInfo::Strict));
|
||||
JSGetterSetter gs(getter, Value());
|
||||
|
|
@ -889,6 +1154,13 @@ void GlobalObject::installRegExp(ExecutionState& state)
|
|||
m_regexpPrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->unicode), desc);
|
||||
}
|
||||
|
||||
{
|
||||
Value getter = new NativeFunctionObject(state, NativeFunctionInfo(strings->getUnicodeSets, builtinRegExpUnicodeSetsGetter, 0, NativeFunctionInfo::Strict));
|
||||
JSGetterSetter gs(getter, Value());
|
||||
ObjectPropertyDescriptor desc(gs, ObjectPropertyDescriptor::ConfigurablePresent);
|
||||
m_regexpPrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->unicodeSets), desc);
|
||||
}
|
||||
|
||||
m_regexpPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->constructor), ObjectPropertyDescriptor(m_regexp, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));
|
||||
|
||||
m_regexp->setFunctionPrototype(state, m_regexpPrototype);
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue