zephyr_rb 1.0.1b → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3052 +0,0 @@
1
- /* # Notices for ruby.wasm
2
-
3
- This product has binary distribution forms and they may contain third party material from the projects listed below.
4
-
5
- ## Ruby
6
-
7
- https://www.ruby-lang.org/en/
8
-
9
- ### COPYING
10
-
11
- ```
12
- Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
13
- You can redistribute it and/or modify it under either the terms of the
14
- 2-clause BSDL (see the file BSDL), or the conditions below:
15
-
16
- 1. You may make and give away verbatim copies of the source form of the
17
- software without restriction, provided that you duplicate all of the
18
- original copyright notices and associated disclaimers.
19
-
20
- 2. You may modify your copy of the software in any way, provided that
21
- you do at least ONE of the following:
22
-
23
- a. place your modifications in the Public Domain or otherwise
24
- make them Freely Available, such as by posting said
25
- modifications to Usenet or an equivalent medium, or by allowing
26
- the author to include your modifications in the software.
27
-
28
- b. use the modified software only within your corporation or
29
- organization.
30
-
31
- c. give non-standard binaries non-standard names, with
32
- instructions on where to get the original software distribution.
33
-
34
- d. make other distribution arrangements with the author.
35
-
36
- 3. You may distribute the software in object code or binary form,
37
- provided that you do at least ONE of the following:
38
-
39
- a. distribute the binaries and library files of the software,
40
- together with instructions (in the manual page or equivalent)
41
- on where to get the original distribution.
42
-
43
- b. accompany the distribution with the machine-readable source of
44
- the software.
45
-
46
- c. give non-standard binaries non-standard names, with
47
- instructions on where to get the original software distribution.
48
-
49
- d. make other distribution arrangements with the author.
50
-
51
- 4. You may modify and include the part of the software into any other
52
- software (possibly commercial). But some files in the distribution
53
- are not written by the author, so that they are not under these terms.
54
-
55
- For the list of those files and their copying conditions, see the
56
- file LEGAL.
57
-
58
- 5. The scripts and library files supplied as input to or produced as
59
- output from the software do not automatically fall under the
60
- copyright of the software, but belong to whomever generated them,
61
- and may be sold commercially, and may be aggregated with this
62
- software.
63
-
64
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
65
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
66
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
67
- PURPOSE.
68
- ```
69
-
70
-
71
- ### LEGAL
72
-
73
- ```
74
- = LEGAL NOTICE INFORMATION
75
- --------------------------
76
-
77
- All the files in this distribution are covered under either the Ruby's
78
- license (see the file COPYING) or public-domain except some files
79
- mentioned below.
80
-
81
- [addr2line.c]
82
-
83
- A part of this file is from FreeBSD.
84
-
85
- >>>
86
- Copyright (c) 1986, 1988, 1991, 1993::
87
- The Regents of the University of California. All rights reserved.
88
-
89
- (c) UNIX System Laboratories, Inc.
90
-
91
- All or some portions of this file are derived from material licensed
92
- to the University of California by American Telephone and Telegraph
93
- Co. or Unix System Laboratories, Inc. and are reproduced herein with
94
- the permission of UNIX System Laboratories, Inc.
95
-
96
- Redistribution and use in source and binary forms, with or without
97
- modification, are permitted provided that the following conditions
98
- are met:
99
- 1. Redistributions of source code must retain the above copyright
100
- notice, this list of conditions and the following disclaimer.
101
- 2. Redistributions in binary form must reproduce the above copyright
102
- notice, this list of conditions and the following disclaimer in the
103
- documentation and/or other materials provided with the distribution.
104
- 4. Neither the name of the University nor the names of its contributors
105
- may be used to endorse or promote products derived from this software
106
- without specific prior written permission.
107
-
108
- THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
109
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
110
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
111
- ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
112
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
113
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
114
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
115
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
116
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
117
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
118
- SUCH DAMAGE.
119
-
120
- @(#)subr_prf.c 8.3 (Berkeley) 1/21/94
121
-
122
-
123
- [ccan/build_assert/build_assert.h]
124
- [ccan/check_type/check_type.h]
125
- [ccan/container_of/container_of.h]
126
- [ccan/str/str.h]
127
-
128
- These files are licensed under the {CC0}[https://creativecommons.org/choose/zero/].
129
-
130
- [ccan/list/list.h]
131
-
132
- This file is licensed under the {MIT License}[rdoc-label:label-MIT+License].
133
-
134
- [coroutine]
135
-
136
- Unless otherwise specified, these files are licensed under the
137
- {MIT License}[rdoc-label:label-MIT+License].
138
-
139
- [include/ruby/onigmo.h]
140
- [include/ruby/oniguruma.h]
141
- [regcomp.c]
142
- [regenc.c]
143
- [regenc.h]
144
- [regerror.c]
145
- [regexec.c]
146
- [regint.h]
147
- [regparse.c]
148
- [regparse.h]
149
- [enc/ascii.c]
150
- [enc/big5.c]
151
- [enc/cp949.c]
152
- [enc/emacs_mule.c]
153
- [enc/encdb.c]
154
- [enc/euc_jp.c]
155
- [enc/euc_kr.c]
156
- [enc/euc_tw.c]
157
- [enc/gb18030.c]
158
- [enc/gb2312.c]
159
- [enc/gbk.c]
160
- [enc/iso_8859_1.c]
161
- [enc/iso_8859_10.c]
162
- [enc/iso_8859_11.c]
163
- [enc/iso_8859_13.c]
164
- [enc/iso_8859_14.c]
165
- [enc/iso_8859_15.c]
166
- [enc/iso_8859_16.c]
167
- [enc/iso_8859_2.c]
168
- [enc/iso_8859_3.c]
169
- [enc/iso_8859_4.c]
170
- [enc/iso_8859_5.c]
171
- [enc/iso_8859_6.c]
172
- [enc/iso_8859_7.c]
173
- [enc/iso_8859_8.c]
174
- [enc/iso_8859_9.c]
175
- [enc/koi8_r.c]
176
- [enc/koi8_u.c]
177
- [enc/shift_jis.c]
178
- [enc/unicode.c]
179
- [enc/us_ascii.c]
180
- [enc/utf_16be.c]
181
- [enc/utf_16le.c]
182
- [enc/utf_32be.c]
183
- [enc/utf_32le.c]
184
- [enc/utf_8.c]
185
- [enc/windows_1251.c]
186
- [enc/windows_31j.c]
187
-
188
- Onigmo (Oniguruma-mod) LICENSE
189
-
190
- >>>
191
- Copyright (c) 2002-2009:: K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
192
- Copyright (c) 2011-2014:: K.Takata <kentkt AT csc DOT jp>
193
- All rights reserved.
194
-
195
- Redistribution and use in source and binary forms, with or without
196
- modification, are permitted provided that the following conditions
197
- are met:
198
- 1. Redistributions of source code must retain the above copyright
199
- notice, this list of conditions and the following disclaimer.
200
- 2. Redistributions in binary form must reproduce the above copyright
201
- notice, this list of conditions and the following disclaimer in the
202
- documentation and/or other materials provided with the distribution.
203
-
204
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
205
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
206
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
207
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
208
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
210
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
211
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
212
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
213
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
214
- SUCH DAMAGE.
215
-
216
- Oniguruma LICENSE
217
-
218
- >>>
219
- Copyright (c) 2002-2009:: K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
220
- All rights reserved.
221
-
222
- Redistribution and use in source and binary forms, with or without
223
- modification, are permitted provided that the following conditions
224
- are met:
225
- 1. Redistributions of source code must retain the above copyright
226
- notice, this list of conditions and the following disclaimer.
227
- 2. Redistributions in binary form must reproduce the above copyright
228
- notice, this list of conditions and the following disclaimer in the
229
- documentation and/or other materials provided with the distribution.
230
-
231
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
232
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
233
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
234
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
235
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
236
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
237
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
238
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
240
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
241
- SUCH DAMAGE.
242
-
243
- * https://github.com/k-takata/Onigmo/
244
- * https://github.com/kkos/oniguruma
245
- * https://svnweb.freebsd.org/ports/head/devel/oniguruma/
246
-
247
- When this software is partly used or it is distributed with Ruby,
248
- this of Ruby follows the license of Ruby.
249
-
250
- [enc/windows_1250.c]
251
- [enc/windows_1252.c]
252
-
253
- >>>
254
- Copyright (c) 2006-2007:: Byte <byte AT mail DOT kna DOT ru>
255
- K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
256
- All rights reserved.
257
-
258
- Redistribution and use in source and binary forms, with or without
259
- modification, are permitted provided that the following conditions
260
- are met:
261
- 1. Redistributions of source code must retain the above copyright
262
- notice, this list of conditions and the following disclaimer.
263
- 2. Redistributions in binary form must reproduce the above copyright
264
- notice, this list of conditions and the following disclaimer in the
265
- documentation and/or other materials provided with the distribution.
266
-
267
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
268
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
269
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
270
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
271
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
272
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
273
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
274
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
275
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
276
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
277
- SUCH DAMAGE.
278
-
279
- [enc/cesu_8.c]
280
- [enc/windows_1253.c]
281
- [enc/windows_1254.c]
282
- [enc/windows_1257.c]
283
-
284
- >>>
285
- Copyright (c) 2002-2007:: K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
286
- All rights reserved.
287
-
288
- Redistribution and use in source and binary forms, with or without
289
- modification, are permitted provided that the following conditions
290
- are met:
291
- 1. Redistributions of source code must retain the above copyright
292
- notice, this list of conditions and the following disclaimer.
293
- 2. Redistributions in binary form must reproduce the above copyright
294
- notice, this list of conditions and the following disclaimer in the
295
- documentation and/or other materials provided with the distribution.
296
-
297
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
298
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
299
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
300
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
301
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
302
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
303
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
304
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
305
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
306
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
307
- SUCH DAMAGE.
308
-
309
- [enc/trans/GB/GB12345%UCS.src]
310
- [enc/trans/GB/UCS%GB12345.src]
311
- [enc/trans/GB/GB2312%UCS.src]
312
- [enc/trans/GB/UCS%GB2312.src]
313
-
314
- These files have this explanatory texts.
315
-
316
- >>>
317
- This mapping data was created from files provided by Unicode, Inc.
318
- (The Unicode Consortium). The files were used to create a product supporting
319
- Unicode, as explicitly permitted in the files' copyright notices.
320
- Please note that Unicode, Inc. never made any claims as to fitness of these
321
- files for any particular purpose, and has ceased to publish the files many
322
- years ago.
323
-
324
- [enc/trans/JIS/JISX0201-KANA%UCS.src]
325
- [enc/trans/JIS/JISX0208\@1990%UCS.src]
326
- [enc/trans/JIS/JISX0212%UCS.src]
327
- [enc/trans/JIS/UCS%JISX0201-KANA.src]
328
- [enc/trans/JIS/UCS%JISX0208@1990.src]
329
- [enc/trans/JIS/UCS%JISX0212.src]
330
-
331
- These files are copyrighted as the following.
332
-
333
- >>>
334
- © 2015 Unicode®, Inc.
335
-
336
- For terms of use, see http://www.unicode.org/terms_of_use.html
337
-
338
- [enc/trans/JIS/JISX0213-1%UCS@BMP.src]
339
- [enc/trans/JIS/JISX0213-1%UCS@SIP.src]
340
- [enc/trans/JIS/JISX0213-2%UCS@BMP.src]
341
- [enc/trans/JIS/JISX0213-2%UCS@SIP.src]
342
-
343
- These files are copyrighted as the following.
344
-
345
- >>>
346
- Copyright (C) 2001:: earthian@tama.or.jp, All Rights Reserved.
347
- Copyright (C) 2001:: I'O, All Rights Reserved.
348
- Copyright (C) 2006:: Project X0213, All Rights Reserved.
349
- You can use, modify, distribute this table freely.
350
-
351
- [enc/trans/JIS/UCS@BMP%JISX0213-1.src]
352
- [enc/trans/JIS/UCS@BMP%JISX0213-2.src]
353
- [enc/trans/JIS/UCS@SIP%JISX0213-1.src]
354
- [enc/trans/JIS/UCS@SIP%JISX0213-2.src]
355
-
356
- These files are copyrighted as the following.
357
-
358
- >>>
359
- Copyright (C) 2001:: earthian@tama.or.jp, All Rights Reserved.
360
- Copyright (C) 2001:: I'O, All Rights Reserved.
361
- You can use, modify, distribute this table freely.
362
-
363
- [enc/trans/ucm/glibc-BIG5-2.3.3.ucm]
364
- [enc/trans/ucm/glibc-BIG5HKSCS-2.3.3.ucm]
365
-
366
- >>>
367
- Copyright (C) 2001-2005:: International Business Machines
368
- Corporation and others. All Rights Reserved.
369
-
370
- [enc/trans/ucm/windows-950-2000.ucm]
371
- [enc/trans/ucm/windows-950_hkscs-2001.ucm]
372
-
373
- >>>
374
- Copyright (C) 2001-2002:: International Business Machines
375
- Corporation and others. All Rights Reserved.
376
-
377
-
378
- [configure]
379
-
380
- This file is free software.
381
-
382
- >>>
383
- Copyright (C) 1992-1996, 1998-2012:: Free Software Foundation, Inc.
384
-
385
- This configure script is free software; the Free Software Foundation
386
- gives unlimited permission to copy, distribute and modify it.
387
-
388
- [tool/config.guess]
389
- [tool/config.sub]
390
-
391
- As long as you distribute these files with the file configure, they
392
- are covered under the Ruby's license.
393
-
394
- >>>
395
- Copyright 1992-2018:: Free Software Foundation, Inc.
396
-
397
- This file is free software; you can redistribute it and/or modify it
398
- under the terms of the GNU General Public License as published by
399
- the Free Software Foundation; either version 3 of the License, or
400
- (at your option) any later version.
401
-
402
- This program is distributed in the hope that it will be useful, but
403
- WITHOUT ANY WARRANTY; without even the implied warranty of
404
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
405
- General Public License for more details.
406
-
407
- You should have received a copy of the GNU General Public License
408
- along with this program; if not, see <https://www.gnu.org/licenses/>.
409
-
410
- As a special exception to the GNU General Public License, if you
411
- distribute this file as part of a program that contains a
412
- configuration script generated by Autoconf, you may include it under
413
- the same distribution terms that you use for the rest of that
414
- program. This Exception is an additional permission under section 7
415
- of the GNU General Public License, version 3 ("GPLv3").
416
-
417
- [tool/lib/test/*]
418
- [tool/lib/core_assertions.rb]
419
-
420
- Some of methods on these files are based on MiniTest 4. MiniTest 4 is
421
- distributed under the MIT License.
422
-
423
- >>>
424
- Copyright (c) Ryan Davis, seattle.rb
425
-
426
- Permission is hereby granted, free of charge, to any person obtaining
427
- a copy of this software and associated documentation files (the
428
- 'Software'), to deal in the Software without restriction, including
429
- without limitation the rights to use, copy, modify, merge, publish,
430
- distribute, sublicense, and/or sell copies of the Software, and to
431
- permit persons to whom the Software is furnished to do so, subject to
432
- the following conditions:
433
-
434
- The above copyright notice and this permission notice shall be
435
- included in all copies or substantial portions of the Software.
436
-
437
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
438
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
439
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
440
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
441
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
442
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
443
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
444
-
445
- [parse.c]
446
- [parse.h]
447
-
448
- These files are licensed under the GPL, but are incorporated into Ruby and
449
- redistributed under the terms of the Ruby license, as permitted by the
450
- exception to the GPL below.
451
-
452
- >>>
453
- Copyright (C) 1984, 1989-1990, 2000-2015, 2018:: Free Software Foundation, Inc.
454
-
455
- This program is free software: you can redistribute it and/or modify
456
- it under the terms of the GNU General Public License as published by
457
- the Free Software Foundation, either version 3 of the License, or
458
- (at your option) any later version.
459
-
460
- This program is distributed in the hope that it will be useful,
461
- but WITHOUT ANY WARRANTY; without even the implied warranty of
462
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
463
- GNU General Public License for more details.
464
-
465
- You should have received a copy of the GNU General Public License
466
- along with this program. If not, see <http://www.gnu.org/licenses/>.
467
-
468
- As a special exception, you may create a larger work that contains
469
- part or all of the Bison parser skeleton and distribute that work
470
- under terms of your choice, so long as that work isn't itself a
471
- parser generator using the skeleton or a modified version thereof
472
- as a parser skeleton. Alternatively, if you modify or redistribute
473
- the parser skeleton itself, you may (at your option) remove this
474
- special exception, which will cause the skeleton and the resulting
475
- Bison output files to be licensed under the GNU General Public
476
- License without this special exception.
477
-
478
- This special exception was added by the Free Software Foundation in
479
- version 2.2 of Bison.
480
-
481
- [missing/dtoa.c]
482
-
483
- This file is under these licenses.
484
-
485
- >>>
486
- Copyright (c) 1991, 2000, 2001:: by Lucent Technologies.
487
-
488
- Permission to use, copy, modify, and distribute this software for any
489
- purpose without fee is hereby granted, provided that this entire notice
490
- is included in all copies of any software which is or includes a copy
491
- or modification of this software and in all copies of the supporting
492
- documentation for such software.
493
-
494
- THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
495
- WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY
496
- REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
497
- OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
498
-
499
- >>>
500
- Copyright (c) 2004-2008:: David Schultz <das@FreeBSD.ORG>
501
- All rights reserved.
502
-
503
- Redistribution and use in source and binary forms, with or without
504
- modification, are permitted provided that the following conditions
505
- are met:
506
- 1. Redistributions of source code must retain the above copyright
507
- notice, this list of conditions and the following disclaimer.
508
- 2. Redistributions in binary form must reproduce the above copyright
509
- notice, this list of conditions and the following disclaimer in the
510
- documentation and/or other materials provided with the distribution.
511
-
512
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
513
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
514
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
515
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
516
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
517
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
518
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
519
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
520
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
521
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
522
- SUCH DAMAGE.
523
-
524
- [win32/win32.c]
525
- [include/ruby/win32.h]
526
-
527
- You can apply the Artistic License to these files. (or GPL,
528
- alternatively)
529
-
530
- >>>
531
- Copyright (c) 1993:: Intergraph Corporation
532
-
533
- You may distribute under the terms of either the GNU General Public
534
- License or the Artistic License, as specified in the perl README file.
535
-
536
- [missing/mt19937.c]
537
-
538
- This file is under the new-style BSD license.
539
-
540
- >>>
541
- A C-program for MT19937, with initialization improved 2002/2/10.::
542
- Coded by Takuji Nishimura and Makoto Matsumoto.
543
-
544
- This is a faster version by taking Shawn Cokus's optimization,
545
- Matthe Bellew's simplification, Isaku Wada's real version.
546
-
547
- Before using, initialize the state by using init_genrand(seed)
548
- or init_by_array(init_key, key_length).
549
-
550
- Copyright (C) 1997 - 2002:: Makoto Matsumoto and Takuji Nishimura,
551
- All rights reserved.
552
-
553
- Redistribution and use in source and binary forms, with or without
554
- modification, are permitted provided that the following conditions
555
- are met:
556
-
557
- 1. Redistributions of source code must retain the above copyright
558
- notice, this list of conditions and the following disclaimer.
559
-
560
- 2. Redistributions in binary form must reproduce the above copyright
561
- notice, this list of conditions and the following disclaimer in the
562
- documentation and/or other materials provided with the distribution.
563
-
564
- 3. The names of its contributors may not be used to endorse or promote
565
- products derived from this software without specific prior written
566
- permission.
567
-
568
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
569
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
570
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
571
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
572
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
573
- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
574
- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
575
- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
576
- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
577
- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
578
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
579
-
580
-
581
- Any feedback is very welcome.
582
- http://www.math.keio.ac.jp/matumoto/emt.html
583
- email: matumoto@math.keio.ac.jp
584
-
585
- The Wayback Machine url: http://web.archive.org/web/19990429082237/http://www.math.keio.ac.jp/matumoto/emt.html
586
-
587
- [missing/procstat_vm.c]
588
-
589
- This file is under the new-style BSD license.
590
-
591
- >>>
592
- Copyright (c) 2007:: Robert N. M. Watson
593
- All rights reserved.
594
-
595
- Redistribution and use in source and binary forms, with or without
596
- modification, are permitted provided that the following conditions
597
- are met:
598
- 1. Redistributions of source code must retain the above copyright
599
- notice, this list of conditions and the following disclaimer.
600
- 2. Redistributions in binary form must reproduce the above copyright
601
- notice, this list of conditions and the following disclaimer in the
602
- documentation and/or other materials provided with the distribution.
603
-
604
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
605
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
606
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
607
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
608
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
609
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
610
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
611
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
612
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
613
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
614
- SUCH DAMAGE.
615
-
616
- $FreeBSD: head/usr.bin/procstat/procstat_vm.c 261780 2014-02-11 21:57:37Z jhb $
617
-
618
- [vsnprintf.c]
619
-
620
- This file is under the {old-style BSD license}[rdoc-label:label-Old-style+BSD+license].
621
-
622
- >>>
623
- Copyright (c) 1990, 1993::
624
- The Regents of the University of California. All rights reserved.
625
-
626
- This code is derived from software contributed to Berkeley by
627
- Chris Torek.
628
-
629
- [st.c]
630
- [strftime.c]
631
- [include/ruby/st.h]
632
- [missing/acosh.c]
633
- [missing/alloca.c]
634
- [missing/erf.c]
635
- [missing/hypot.c]
636
- [missing/lgamma_r.c]
637
- [missing/memcmp.c]
638
- [missing/memmove.c]
639
- [missing/strchr.c]
640
- [missing/strerror.c]
641
- [missing/strstr.c]
642
- [missing/tgamma.c]
643
- [ext/date/date_strftime.c]
644
- [ext/digest/sha1/sha1.c]
645
- [ext/digest/sha1/sha1.h]
646
-
647
- These files are all under public domain.
648
-
649
- [missing/crypt.c]
650
-
651
- This file is under the {old-style BSD license}[rdoc-label:label-Old-style+BSD+license].
652
-
653
- >>>
654
- Copyright (c) 1989, 1993::
655
- The Regents of the University of California. All rights reserved.
656
-
657
- This code is derived from software contributed to Berkeley by
658
- Tom Truscott.
659
-
660
- [missing/setproctitle.c]
661
-
662
- This file is under the {old-style BSD license}[rdoc-label:label-Old-style+BSD+license].
663
-
664
- >>>
665
- Copyright 2003:: Damien Miller
666
- Copyright (c) 1983, 1995-1997:: Eric P. Allman
667
- Copyright (c) 1988, 1993::
668
- The Regents of the University of California. All rights reserved.
669
-
670
- [missing/strlcat.c]
671
- [missing/strlcpy.c]
672
-
673
- These files are under an ISC-style license.
674
-
675
- >>>
676
- Copyright (c) 1998, 2015:: Todd C. Miller <Todd.Miller@courtesan.com>
677
-
678
- Permission to use, copy, modify, and distribute this software for any
679
- purpose with or without fee is hereby granted, provided that the above
680
- copyright notice and this permission notice appear in all copies.
681
-
682
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
683
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
684
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
685
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
686
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
687
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
688
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
689
-
690
- [missing/langinfo.c]
691
-
692
- This file is from http://www.cl.cam.ac.uk/~mgk25/ucs/langinfo.c.
693
- Ruby uses a modified version. The file contains the following
694
- author/copyright notice:
695
-
696
- >>>
697
- Markus.Kuhn@cl.cam.ac.uk -- 2002-03-11::
698
- Permission to use, copy, modify, and distribute this software
699
- for any purpose and without fee is hereby granted. The author
700
- disclaims all warranties with regard to this software.
701
-
702
- [ext/digest/md5/md5.c]
703
- [ext/digest/md5/md5.h]
704
-
705
- These files are under the following license. Ruby uses modified
706
- versions of them.
707
-
708
- >>>
709
- Copyright (C) 1999, 2000:: Aladdin Enterprises. All rights reserved.
710
-
711
- This software is provided 'as-is', without any express or implied
712
- warranty. In no event will the authors be held liable for any damages
713
- arising from the use of this software.
714
-
715
- Permission is granted to anyone to use this software for any purpose,
716
- including commercial applications, and to alter it and redistribute it
717
- freely, subject to the following restrictions:
718
-
719
- 1. The origin of this software must not be misrepresented; you must not
720
- claim that you wrote the original software. If you use this software
721
- in a product, an acknowledgment in the product documentation would be
722
- appreciated but is not required.
723
- 2. Altered source versions must be plainly marked as such, and must not be
724
- misrepresented as being the original software.
725
- 3. This notice may not be removed or altered from any source distribution.
726
-
727
- L. Peter Deutsch
728
- ghost@aladdin.com
729
-
730
- [ext/digest/rmd160/rmd160.c]
731
- [ext/digest/rmd160/rmd160.h]
732
-
733
- These files have the following copyright information, and by the
734
- author we are allowed to use it under the new-style BSD license.
735
-
736
- >>>
737
- AUTHOR:: Antoon Bosselaers, ESAT-COSIC
738
- (Arranged for libc by Todd C. Miller)
739
- DATE:: 1 March 1996
740
-
741
- Copyright (c):: Katholieke Universiteit Leuven
742
- 1996, All Rights Reserved
743
-
744
- [ext/digest/sha2/sha2.c]
745
- [ext/digest/sha2/sha2.h]
746
-
747
- These files are under the new-style BSD license.
748
-
749
- >>>
750
- Copyright 2000:: Aaron D. Gifford. All rights reserved.
751
-
752
- Redistribution and use in source and binary forms, with or without
753
- modification, are permitted provided that the following conditions
754
- are met:
755
- 1. Redistributions of source code must retain the above copyright
756
- notice, this list of conditions and the following disclaimer.
757
- 2. Redistributions in binary form must reproduce the above copyright
758
- notice, this list of conditions and the following disclaimer in the
759
- documentation and/or other materials provided with the distribution.
760
- 3. Neither the name of the copyright holder nor the names of contributors
761
- may be used to endorse or promote products derived from this software
762
- without specific prior written permission.
763
-
764
- THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTOR(S) ``AS IS'' AND
765
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
766
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
767
- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE
768
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
769
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
770
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
771
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
772
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
773
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
774
- SUCH DAMAGE.
775
-
776
- [ext/json/generator/generator.c]
777
-
778
- The file contains the following copyright notice.
779
-
780
- >>>
781
- Copyright 2001-2004:: Unicode, Inc.
782
-
783
- Disclaimer::
784
-
785
- This source code is provided as is by Unicode, Inc. No claims are
786
- made as to fitness for any particular purpose. No warranties of any
787
- kind are expressed or implied. The recipient agrees to determine
788
- applicability of information provided. If this file has been
789
- purchased on magnetic or optical media from Unicode, Inc., the
790
- sole remedy for any claim will be exchange of defective media
791
- within 90 days of receipt.
792
-
793
- Limitations on Rights to Redistribute This Code::
794
-
795
- Unicode, Inc. hereby grants the right to freely use the information
796
- supplied in this file in the creation of products supporting the
797
- Unicode Standard, and to make copies of this file in any form
798
- for internal or external distribution as long as this notice
799
- remains attached.
800
-
801
- [ext/nkf/nkf-utf8/config.h]
802
- [ext/nkf/nkf-utf8/nkf.c]
803
- [ext/nkf/nkf-utf8/utf8tbl.c]
804
-
805
- These files are under the following license. So to speak, it is
806
- copyrighted semi-public-domain software.
807
-
808
- >>>
809
- Copyright (C) 1987:: Fujitsu LTD. (Itaru ICHIKAWA)
810
-
811
- Everyone is permitted to do anything on this program
812
- including copying, modifying, improving,
813
- as long as you don't try to pretend that you wrote it.
814
- i.e., the above copyright notice has to appear in all copies.
815
- Binary distribution requires original version messages.
816
- You don't have to ask before copying, redistribution or publishing.
817
- THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
818
-
819
- [ext/psych]
820
- [test/psych]
821
-
822
- The files under these directories are under the following license, except for
823
- ext/psych/yaml.
824
-
825
- >>>
826
- Copyright 2009:: Aaron Patterson, et al.
827
-
828
- Permission is hereby granted, free of charge, to any person obtaining a copy of
829
- this software and associated documentation files (the 'Software'), to deal in
830
- the Software without restriction, including without limitation the rights to
831
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
832
- of the Software, and to permit persons to whom the Software is furnished to do
833
- so, subject to the following conditions:
834
-
835
- The above copyright notice and this permission notice shall be included in all
836
- copies or substantial portions of the Software.
837
-
838
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
839
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
840
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
841
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
842
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
843
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
844
- SOFTWARE.
845
-
846
- [ext/psych/yaml]
847
-
848
- The files under this directory are under the following license.
849
-
850
- >>>
851
- Copyright (c) 2006:: Kirill Simonov
852
-
853
- Permission is hereby granted, free of charge, to any person obtaining a copy of
854
- this software and associated documentation files (the "Software"), to deal in
855
- the Software without restriction, including without limitation the rights to
856
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
857
- of the Software, and to permit persons to whom the Software is furnished to do
858
- so, subject to the following conditions:
859
-
860
- The above copyright notice and this permission notice shall be included in all
861
- copies or substantial portions of the Software.
862
-
863
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
864
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
865
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
866
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
867
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
868
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
869
- SOFTWARE.
870
-
871
- [ext/pty/pty.c]
872
-
873
- >>>
874
- C) Copyright 1998:: by Akinori Ito.
875
-
876
- This software may be redistributed freely for this purpose, in full
877
- or in part, provided that this entire copyright notice is included
878
- on any copies of this software and applications and derivations thereof.
879
-
880
- This software is provided on an "as is" basis, without warranty of any
881
- kind, either expressed or implied, as to any matter including, but not
882
- limited to warranty of fitness of purpose, or merchantability, or
883
- results obtained from use of this software.
884
-
885
- [ext/socket/addrinfo.h]
886
- [ext/socket/getaddrinfo.c]
887
- [ext/socket/getnameinfo.c]
888
-
889
- These files are under the new-style BSD license.
890
-
891
- >>>
892
- Copyright (C) 1995, 1996, 1997, 1998, and 1999:: WIDE Project.
893
- All rights reserved.
894
-
895
- Redistribution and use in source and binary forms, with or without
896
- modification, are permitted provided that the following conditions
897
- are met:
898
- 1. Redistributions of source code must retain the above copyright
899
- notice, this list of conditions and the following disclaimer.
900
- 2. Redistributions in binary form must reproduce the above copyright
901
- notice, this list of conditions and the following disclaimer in the
902
- documentation and/or other materials provided with the distribution.
903
- 3. Neither the name of the project nor the names of its contributors
904
- may be used to endorse or promote products derived from this software
905
- without specific prior written permission.
906
-
907
- THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
908
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
909
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
910
- ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
911
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
912
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
913
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
914
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
915
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
916
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
917
- SUCH DAMAGE.
918
-
919
- [ext/win32ole/win32ole.c]
920
-
921
- You can apply the Artistic License to this file. (or GPL,
922
- alternatively)
923
-
924
- >>>
925
- (c) 1995:: Microsoft Corporation. All rights reserved.
926
- Developed by ActiveWare Internet Corp., http://www.ActiveWare.com
927
-
928
- Other modifications Copyright (c) 1997, 1998:: by Gurusamy Sarathy
929
- <gsar@umich.edu> and Jan Dubois <jan.dubois@ibm.net>
930
-
931
- You may distribute under the terms of either the GNU General Public
932
- License or the Artistic License, as specified in the README file
933
- of the Perl distribution.
934
-
935
- The Wayback Machine url: http://web.archive.org/web/19970607104352/http://www.activeware.com:80/
936
-
937
- [lib/rdoc/generator/template/darkfish/css/fonts.css]
938
-
939
- This file is licensed under the {SIL Open Font License}[http://scripts.sil.org/OFL].
940
-
941
- [spec/mspec]
942
- [spec/ruby]
943
-
944
- The files under these directories are under the following license.
945
-
946
- >>>
947
- Copyright (c) 2008:: Engine Yard, Inc. All rights reserved.
948
-
949
- Permission is hereby granted, free of charge, to any person
950
- obtaining a copy of this software and associated documentation
951
- files (the "Software"), to deal in the Software without
952
- restriction, including without limitation the rights to use,
953
- copy, modify, merge, publish, distribute, sublicense, and/or sell
954
- copies of the Software, and to permit persons to whom the
955
- Software is furnished to do so, subject to the following
956
- conditions:
957
-
958
- The above copyright notice and this permission notice shall be
959
- included in all copies or substantial portions of the Software.
960
-
961
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
962
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
963
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
964
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
965
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
966
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
967
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
968
- OTHER DEALINGS IN THE SOFTWARE.
969
-
970
- [lib/rubygems.rb]
971
- [lib/rubygems]
972
- [test/rubygems]
973
-
974
- RubyGems is under the following license.
975
-
976
- >>>
977
- RubyGems is copyrighted free software by Chad Fowler, Rich Kilmer, Jim
978
- Weirich and others. You can redistribute it and/or modify it under
979
- either the terms of the {MIT license}[rdoc-label:label-MIT+License], or the conditions
980
- below:
981
-
982
- 1. You may make and give away verbatim copies of the source form of the
983
- software without restriction, provided that you duplicate all of the
984
- original copyright notices and associated disclaimers.
985
-
986
- 2. You may modify your copy of the software in any way, provided that
987
- you do at least ONE of the following:
988
-
989
- a. place your modifications in the Public Domain or otherwise
990
- make them Freely Available, such as by posting said
991
- modifications to Usenet or an equivalent medium, or by allowing
992
- the author to include your modifications in the software.
993
-
994
- b. use the modified software only within your corporation or
995
- organization.
996
-
997
- c. give non-standard executables non-standard names, with
998
- instructions on where to get the original software distribution.
999
-
1000
- d. make other distribution arrangements with the author.
1001
-
1002
- 3. You may distribute the software in object code or executable
1003
- form, provided that you do at least ONE of the following:
1004
-
1005
- a. distribute the executables and library files of the software,
1006
- together with instructions (in the manual page or equivalent)
1007
- on where to get the original distribution.
1008
-
1009
- b. accompany the distribution with the machine-readable source of
1010
- the software.
1011
-
1012
- c. give non-standard executables non-standard names, with
1013
- instructions on where to get the original software distribution.
1014
-
1015
- d. make other distribution arrangements with the author.
1016
-
1017
- 4. You may modify and include the part of the software into any other
1018
- software (possibly commercial).
1019
-
1020
- 5. The scripts and library files supplied as input to or produced as
1021
- output from the software do not automatically fall under the
1022
- copyright of the software, but belong to whomever generated them,
1023
- and may be sold commercially, and may be aggregated with this
1024
- software.
1025
-
1026
- 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
1027
- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1028
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1029
- PURPOSE.
1030
-
1031
- [lib/bundler]
1032
- [lib/bundler.rb]
1033
- [spec/bundler]
1034
-
1035
- Bundler is under the following license.
1036
-
1037
- >>>
1038
- Portions copyright (c) 2010:: Andre Arko
1039
- Portions copyright (c) 2009:: Engine Yard
1040
-
1041
- {MIT License}[rdoc-label:label-MIT+License]
1042
-
1043
- [lib/bundler/vendor/thor]
1044
-
1045
- Thor is under the following license.
1046
-
1047
- >>>
1048
- Copyright (c) 2008 Yehuda Katz, Eric Hodel, et al.
1049
-
1050
- {MIT License}[rdoc-label:label-MIT+License]
1051
-
1052
- [lib/rubygems/resolver/molinillo]
1053
- [lib/bundler/vendor/molinillo]
1054
-
1055
- molinillo is under the following license.
1056
-
1057
- >>>
1058
- Copyright (c) 2014 Samuel E. Giddins segiddins@segiddins.me
1059
-
1060
- {MIT License}[rdoc-label:label-MIT+License]
1061
-
1062
- [lib/bundler/vendor/connection_pool]
1063
-
1064
- connection_pool is under the following license.
1065
-
1066
- >>>
1067
- Copyright (c) 2011 Mike Perham
1068
-
1069
- {MIT License}[rdoc-label:label-MIT+License]
1070
-
1071
- [lib/bundler/vendor/net-http-persistent]
1072
-
1073
- net-http-persistent is under the following license.
1074
-
1075
- >>>
1076
- Copyright (c) Eric Hodel, Aaron Patterson
1077
-
1078
- {MIT License}[rdoc-label:label-MIT+License]
1079
-
1080
- [lib/did_you_mean]
1081
- [lib/did_you_mean.rb]
1082
- [test/did_you_mean]
1083
-
1084
- did_you_mean is under the following license.
1085
-
1086
- >>>
1087
- Copyright (c) 2014-2016 Yuki Nishijima
1088
-
1089
- {MIT License}[rdoc-label:label-MIT+License]
1090
-
1091
- [lib/error_highlight]
1092
- [lib/error_highlight.rb]
1093
- [test/error_highlight]
1094
-
1095
- error_highlight is under the following license.
1096
-
1097
- >>>
1098
- Copyright (c) 2021 Yusuke Endoh
1099
-
1100
- {MIT License}[rdoc-label:label-MIT+License]
1101
-
1102
- [benchmark/so_ackermann.rb]
1103
- [benchmark/so_array.rb]
1104
- [benchmark/so_binary_trees.rb]
1105
- [benchmark/so_concatenate.rb]
1106
- [benchmark/so_count_words.yml]
1107
- [benchmark/so_exception.rb]
1108
- [benchmark/so_fannkuch.rb]
1109
- [benchmark/so_fasta.rb]
1110
- [benchmark/so_k_nucleotide.yml]
1111
- [benchmark/so_lists.rb]
1112
- [benchmark/so_mandelbrot.rb]
1113
- [benchmark/so_matrix.rb]
1114
- [benchmark/so_meteor_contest.rb]
1115
- [benchmark/so_nbody.rb]
1116
- [benchmark/so_nested_loop.rb]
1117
- [benchmark/so_nsieve.rb]
1118
- [benchmark/so_nsieve_bits.rb]
1119
- [benchmark/so_object.rb]
1120
- [benchmark/so_partial_sums.rb]
1121
- [benchmark/so_pidigits.rb]
1122
- [benchmark/so_random.rb]
1123
- [benchmark/so_reverse_complement.yml]
1124
- [benchmark/so_sieve.rb]
1125
- [benchmark/so_spectralnorm.rb]
1126
-
1127
- These files are very old copy of then-called "The Great Computer Language
1128
- Shootout". LEGAL SITUATION OF THESE FILES ARE UNCLEAR because the original
1129
- site has been lost. Upstream diverged to delete several benchmarks listed
1130
- above.
1131
-
1132
- == MIT License
1133
- >>>
1134
- Permission is hereby granted, free of charge, to any person obtaining
1135
- a copy of this software and associated documentation files (the
1136
- "Software"), to deal in the Software without restriction, including
1137
- without limitation the rights to use, copy, modify, merge, publish,
1138
- distribute, sublicense, and/or sell copies of the Software, and to
1139
- permit persons to whom the Software is furnished to do so, subject to
1140
- the following conditions:
1141
-
1142
- The above copyright notice and this permission notice shall be
1143
- included in all copies or substantial portions of the Software.
1144
-
1145
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1146
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1147
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1148
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
1149
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
1150
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1151
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1152
-
1153
- == Old-style BSD license
1154
- >>>
1155
- Redistribution and use in source and binary forms, with or without
1156
- modification, are permitted provided that the following conditions
1157
- are met:
1158
- 1. Redistributions of source code must retain the above copyright
1159
- notice, this list of conditions and the following disclaimer.
1160
- 2. Redistributions in binary form must reproduce the above copyright
1161
- notice, this list of conditions and the following disclaimer in the
1162
- documentation and/or other materials provided with the distribution.
1163
- 3. Neither the name of the University nor the names of its contributors
1164
- may be used to endorse or promote products derived from this software
1165
- without specific prior written permission.
1166
-
1167
- THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1168
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1169
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1170
- ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1171
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1172
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1173
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1174
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1175
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1176
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1177
- SUCH DAMAGE.
1178
-
1179
- IMPORTANT NOTE::
1180
-
1181
- From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change
1182
- paragraph 3 above is now null and void.
1183
- ```
1184
-
1185
- Other bundled gems are licenced by their own license declared in their gemspecs.
1186
-
1187
- ## LibYAML
1188
-
1189
- https://github.com/yaml/libyaml
1190
-
1191
- ```
1192
- Copyright (c) 2017-2020 Ingy döt Net
1193
- Copyright (c) 2006-2016 Kirill Simonov
1194
- Licensed under the MIT License.
1195
- ```
1196
-
1197
-
1198
- ## Zlib
1199
-
1200
- https://www.zlib.net
1201
-
1202
- ```
1203
- zlib.h -- interface of the 'zlib' general purpose compression library
1204
- version 1.2.13, October 13th, 2022
1205
-
1206
- Copyright (C) 1995-2022 Jean-loup Gailly and Mark Adler
1207
-
1208
- This software is provided 'as-is', without any express or implied
1209
- warranty. In no event will the authors be held liable for any damages
1210
- arising from the use of this software.
1211
-
1212
- Permission is granted to anyone to use this software for any purpose,
1213
- including commercial applications, and to alter it and redistribute it
1214
- freely, subject to the following restrictions:
1215
-
1216
- 1. The origin of this software must not be misrepresented; you must not
1217
- claim that you wrote the original software. If you use this software
1218
- in a product, an acknowledgment in the product documentation would be
1219
- appreciated but is not required.
1220
- 2. Altered source versions must be plainly marked as such, and must not be
1221
- misrepresented as being the original software.
1222
- 3. This notice may not be removed or altered from any source distribution.
1223
-
1224
- Jean-loup Gailly Mark Adler
1225
- jloup@gzip.org madler@alumni.caltech.edu
1226
- ```
1227
-
1228
- ## wasi-libc
1229
-
1230
- https://github.com/WebAssembly/wasi-libc
1231
-
1232
- ```
1233
- wasi-libc as a whole is multi-licensed under the
1234
- Apache License v2.0 with LLVM Exceptions, the Apache License v2.0, and
1235
- the MIT License. See the LICENSE-APACHE-LLVM, LICENSE-APACHE and LICENSE-MIT
1236
- files, respectively, for details.
1237
-
1238
- Portions of this software are derived from third-party works covered by
1239
- their own licenses:
1240
-
1241
- dlmalloc/ - CC0; see the notice in malloc.c for details
1242
- emmalloc/ - MIT; see the notice in emmalloc.c for details
1243
- libc-bottom-half/cloudlibc/ - BSD-2-Clause; see the LICENSE file for details
1244
- libc-top-half/musl/ - MIT; see the COPYRIGHT file for details
1245
-
1246
- wasi-libc's changes to these files are multi-licensed under the
1247
- Apache License v2.0 with LLVM Exceptions, the Apache License v2.0,
1248
- the MIT License, and the original licenses of the third-party works.
1249
- ```
1250
-
1251
- Licensed under the MIT License
1252
-
1253
- ## OpenSSL
1254
-
1255
- https://www.openssl.org/
1256
-
1257
- ```
1258
- Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
1259
- Licensed under the Apache License 2.0 https://www.openssl.org/source/license.html
1260
- ```
1261
-
1262
- ## wasi-vfs
1263
-
1264
- https://github.com/kateinoigakukun/wasi-vfs
1265
-
1266
- ```
1267
- Licensed under the Apache License v2.0 with LLVM Exceptions
1268
- ```
1269
-
1270
- ---
1271
-
1272
- ## MIT License
1273
-
1274
- ```
1275
- Permission is hereby granted, free of charge, to any person obtaining a copy
1276
- of this software and associated documentation files (the "Software"), to deal
1277
- in the Software without restriction, including without limitation the rights
1278
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1279
- copies of the Software, and to permit persons to whom the Software is
1280
- furnished to do so, subject to the following conditions:
1281
-
1282
- The above copyright notice and this permission notice shall be included in all
1283
- copies or substantial portions of the Software.
1284
-
1285
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1286
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1287
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1288
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1289
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1290
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1291
- SOFTWARE.
1292
- ```
1293
- */
1294
- (function () {
1295
- 'use strict';
1296
-
1297
- /******************************************************************************
1298
- Copyright (c) Microsoft Corporation.
1299
-
1300
- Permission to use, copy, modify, and/or distribute this software for any
1301
- purpose with or without fee is hereby granted.
1302
-
1303
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1304
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1305
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1306
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1307
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1308
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1309
- PERFORMANCE OF THIS SOFTWARE.
1310
- ***************************************************************************** */
1311
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1312
-
1313
-
1314
- function __values(o) {
1315
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1316
- if (m) return m.call(o);
1317
- if (o && typeof o.length === "number") return {
1318
- next: function () {
1319
- if (o && i >= o.length) o = void 0;
1320
- return { value: o && o[i++], done: !o };
1321
- }
1322
- };
1323
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1324
- }
1325
-
1326
- function __asyncValues(o) {
1327
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1328
- var m = o[Symbol.asyncIterator], i;
1329
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
1330
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
1331
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
1332
- }
1333
-
1334
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1335
- var e = new Error(message);
1336
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1337
- };
1338
-
1339
- const CLOCKID_REALTIME=0;const CLOCKID_MONOTONIC=1;const ERRNO_SUCCESS=0;const ERRNO_BADF=8;const ERRNO_EXIST=20;const ERRNO_INVAL=28;const ERRNO_ISDIR=31;const ERRNO_NAMETOOLONG=37;const ERRNO_NOENT=44;const ERRNO_NOSYS=52;const ERRNO_NOTDIR=54;const ERRNO_NOTEMPTY=55;const ERRNO_NOTSUP=58;const ERRNO_PERM=63;const ERRNO_NOTCAPABLE=76;const RIGHTS_FD_WRITE=1<<6;class Iovec{static read_bytes(view,ptr){const iovec=new Iovec;iovec.buf=view.getUint32(ptr,true);iovec.buf_len=view.getUint32(ptr+4,true);return iovec}static read_bytes_array(view,ptr,len){const iovecs=[];for(let i=0;i<len;i++){iovecs.push(Iovec.read_bytes(view,ptr+8*i));}return iovecs}}class Ciovec{static read_bytes(view,ptr){const iovec=new Ciovec;iovec.buf=view.getUint32(ptr,true);iovec.buf_len=view.getUint32(ptr+4,true);return iovec}static read_bytes_array(view,ptr,len){const iovecs=[];for(let i=0;i<len;i++){iovecs.push(Ciovec.read_bytes(view,ptr+8*i));}return iovecs}}const WHENCE_SET=0;const WHENCE_CUR=1;const WHENCE_END=2;const FILETYPE_DIRECTORY=3;const FILETYPE_REGULAR_FILE=4;class Dirent{head_length(){return 24}name_length(){return this.dir_name.byteLength}write_head_bytes(view,ptr){view.setBigUint64(ptr,this.d_next,true);view.setBigUint64(ptr+8,this.d_ino,true);view.setUint32(ptr+16,this.dir_name.length,true);view.setUint8(ptr+20,this.d_type);}write_name_bytes(view8,ptr,buf_len){view8.set(this.dir_name.slice(0,Math.min(this.dir_name.byteLength,buf_len)),ptr);}constructor(next_cookie,name,type){this.d_ino=0n;const encoded_name=new TextEncoder().encode(name);this.d_next=next_cookie;this.d_namlen=encoded_name.byteLength;this.d_type=type;this.dir_name=encoded_name;}}const FDFLAGS_APPEND=1<<0;class Fdstat{write_bytes(view,ptr){view.setUint8(ptr,this.fs_filetype);view.setUint16(ptr+2,this.fs_flags,true);view.setBigUint64(ptr+8,this.fs_rights_base,true);view.setBigUint64(ptr+16,this.fs_rights_inherited,true);}constructor(filetype,flags){this.fs_rights_base=0n;this.fs_rights_inherited=0n;this.fs_filetype=filetype;this.fs_flags=flags;}}const OFLAGS_CREAT=1<<0;const OFLAGS_DIRECTORY=1<<1;const OFLAGS_EXCL=1<<2;const OFLAGS_TRUNC=1<<3;class Filestat{write_bytes(view,ptr){view.setBigUint64(ptr,this.dev,true);view.setBigUint64(ptr+8,this.ino,true);view.setUint8(ptr+16,this.filetype);view.setBigUint64(ptr+24,this.nlink,true);view.setBigUint64(ptr+32,this.size,true);view.setBigUint64(ptr+38,this.atim,true);view.setBigUint64(ptr+46,this.mtim,true);view.setBigUint64(ptr+52,this.ctim,true);}constructor(filetype,size){this.dev=0n;this.ino=0n;this.nlink=0n;this.atim=0n;this.mtim=0n;this.ctim=0n;this.filetype=filetype;this.size=size;}}const PREOPENTYPE_DIR=0;class PrestatDir{write_bytes(view,ptr){view.setUint32(ptr,this.pr_name.byteLength,true);}constructor(name){this.pr_name=new TextEncoder().encode(name);}}class Prestat{static dir(name){const prestat=new Prestat;prestat.tag=PREOPENTYPE_DIR;prestat.inner=new PrestatDir(name);return prestat}write_bytes(view,ptr){view.setUint32(ptr,this.tag,true);this.inner.write_bytes(view,ptr+4);}}
1340
-
1341
- let Debug=class Debug{enable(enabled){this.log=createLogger(enabled===undefined?true:enabled,this.prefix);}get enabled(){return this.isEnabled}constructor(isEnabled){this.isEnabled=isEnabled;this.prefix="wasi:";this.enable(isEnabled);}};function createLogger(enabled,prefix){if(enabled){const a=console.log.bind(console,"%c%s","color: #265BA0",prefix);return a}else {return ()=>{}}}const debug=new Debug(false);
1342
-
1343
- class WASIProcExit extends Error{constructor(code){super("exit with exit code "+code);this.code=code;}}let WASI=class WASI{start(instance){this.inst=instance;try{instance.exports._start();return 0}catch(e){if(e instanceof WASIProcExit){return e.code}else {throw e}}}initialize(instance){this.inst=instance;if(instance.exports._initialize){instance.exports._initialize();}}constructor(args,env,fds,options={}){this.args=[];this.env=[];this.fds=[];debug.enable(options.debug);this.args=args;this.env=env;this.fds=fds;const self=this;this.wasiImport={args_sizes_get(argc,argv_buf_size){const buffer=new DataView(self.inst.exports.memory.buffer);buffer.setUint32(argc,self.args.length,true);let buf_size=0;for(const arg of self.args){buf_size+=arg.length+1;}buffer.setUint32(argv_buf_size,buf_size,true);debug.log(buffer.getUint32(argc,true),buffer.getUint32(argv_buf_size,true));return 0},args_get(argv,argv_buf){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);const orig_argv_buf=argv_buf;for(let i=0;i<self.args.length;i++){buffer.setUint32(argv,argv_buf,true);argv+=4;const arg=new TextEncoder().encode(self.args[i]);buffer8.set(arg,argv_buf);buffer.setUint8(argv_buf+arg.length,0);argv_buf+=arg.length+1;}if(debug.enabled){debug.log(new TextDecoder("utf-8").decode(buffer8.slice(orig_argv_buf,argv_buf)));}return 0},environ_sizes_get(environ_count,environ_size){const buffer=new DataView(self.inst.exports.memory.buffer);buffer.setUint32(environ_count,self.env.length,true);let buf_size=0;for(const environ of self.env){buf_size+=environ.length+1;}buffer.setUint32(environ_size,buf_size,true);debug.log(buffer.getUint32(environ_count,true),buffer.getUint32(environ_size,true));return 0},environ_get(environ,environ_buf){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);const orig_environ_buf=environ_buf;for(let i=0;i<self.env.length;i++){buffer.setUint32(environ,environ_buf,true);environ+=4;const e=new TextEncoder().encode(self.env[i]);buffer8.set(e,environ_buf);buffer.setUint8(environ_buf+e.length,0);environ_buf+=e.length+1;}if(debug.enabled){debug.log(new TextDecoder("utf-8").decode(buffer8.slice(orig_environ_buf,environ_buf)));}return 0},clock_res_get(id,res_ptr){let resolutionValue;switch(id){case CLOCKID_MONOTONIC:{resolutionValue=5000n;break}case CLOCKID_REALTIME:{resolutionValue=1000000n;break}default:return ERRNO_NOSYS}const view=new DataView(self.inst.exports.memory.buffer);view.setBigUint64(res_ptr,resolutionValue,true);return ERRNO_SUCCESS},clock_time_get(id,precision,time){const buffer=new DataView(self.inst.exports.memory.buffer);if(id===CLOCKID_REALTIME){buffer.setBigUint64(time,BigInt(new Date().getTime())*1000000n,true);}else if(id==CLOCKID_MONOTONIC){let monotonic_time;try{monotonic_time=BigInt(Math.round(performance.now()*1e6));}catch(e){monotonic_time=0n;}buffer.setBigUint64(time,monotonic_time,true);}else {buffer.setBigUint64(time,0n,true);}return 0},fd_advise(fd,offset,len,advice){if(self.fds[fd]!=undefined){return ERRNO_SUCCESS}else {return ERRNO_BADF}},fd_allocate(fd,offset,len){if(self.fds[fd]!=undefined){return self.fds[fd].fd_allocate(offset,len)}else {return ERRNO_BADF}},fd_close(fd){if(self.fds[fd]!=undefined){const ret=self.fds[fd].fd_close();self.fds[fd]=undefined;return ret}else {return ERRNO_BADF}},fd_datasync(fd){if(self.fds[fd]!=undefined){return self.fds[fd].fd_sync()}else {return ERRNO_BADF}},fd_fdstat_get(fd,fdstat_ptr){if(self.fds[fd]!=undefined){const{ret,fdstat}=self.fds[fd].fd_fdstat_get();if(fdstat!=null){fdstat.write_bytes(new DataView(self.inst.exports.memory.buffer),fdstat_ptr);}return ret}else {return ERRNO_BADF}},fd_fdstat_set_flags(fd,flags){if(self.fds[fd]!=undefined){return self.fds[fd].fd_fdstat_set_flags(flags)}else {return ERRNO_BADF}},fd_fdstat_set_rights(fd,fs_rights_base,fs_rights_inheriting){if(self.fds[fd]!=undefined){return self.fds[fd].fd_fdstat_set_rights(fs_rights_base,fs_rights_inheriting)}else {return ERRNO_BADF}},fd_filestat_get(fd,filestat_ptr){if(self.fds[fd]!=undefined){const{ret,filestat}=self.fds[fd].fd_filestat_get();if(filestat!=null){filestat.write_bytes(new DataView(self.inst.exports.memory.buffer),filestat_ptr);}return ret}else {return ERRNO_BADF}},fd_filestat_set_size(fd,size){if(self.fds[fd]!=undefined){return self.fds[fd].fd_filestat_set_size(size)}else {return ERRNO_BADF}},fd_filestat_set_times(fd,atim,mtim,fst_flags){if(self.fds[fd]!=undefined){return self.fds[fd].fd_filestat_set_times(atim,mtim,fst_flags)}else {return ERRNO_BADF}},fd_pread(fd,iovs_ptr,iovs_len,offset,nread_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const iovecs=Iovec.read_bytes_array(buffer,iovs_ptr,iovs_len);let nread=0;for(const iovec of iovecs){const{ret,data}=self.fds[fd].fd_pread(iovec.buf_len,offset);if(ret!=ERRNO_SUCCESS){buffer.setUint32(nread_ptr,nread,true);return ret}buffer8.set(data,iovec.buf);nread+=data.length;offset+=BigInt(data.length);if(data.length!=iovec.buf_len){break}}buffer.setUint32(nread_ptr,nread,true);return ERRNO_SUCCESS}else {return ERRNO_BADF}},fd_prestat_get(fd,buf_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const{ret,prestat}=self.fds[fd].fd_prestat_get();if(prestat!=null){prestat.write_bytes(buffer,buf_ptr);}return ret}else {return ERRNO_BADF}},fd_prestat_dir_name(fd,path_ptr,path_len){if(self.fds[fd]!=undefined){const{ret,prestat}=self.fds[fd].fd_prestat_get();if(prestat==null){return ret}const prestat_dir_name=prestat.inner.pr_name;const buffer8=new Uint8Array(self.inst.exports.memory.buffer);buffer8.set(prestat_dir_name.slice(0,path_len),path_ptr);return prestat_dir_name.byteLength>path_len?ERRNO_NAMETOOLONG:ERRNO_SUCCESS}else {return ERRNO_BADF}},fd_pwrite(fd,iovs_ptr,iovs_len,offset,nwritten_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const iovecs=Ciovec.read_bytes_array(buffer,iovs_ptr,iovs_len);let nwritten=0;for(const iovec of iovecs){const data=buffer8.slice(iovec.buf,iovec.buf+iovec.buf_len);const{ret,nwritten:nwritten_part}=self.fds[fd].fd_pwrite(data,offset);if(ret!=ERRNO_SUCCESS){buffer.setUint32(nwritten_ptr,nwritten,true);return ret}nwritten+=nwritten_part;offset+=BigInt(nwritten_part);if(nwritten_part!=data.byteLength){break}}buffer.setUint32(nwritten_ptr,nwritten,true);return ERRNO_SUCCESS}else {return ERRNO_BADF}},fd_read(fd,iovs_ptr,iovs_len,nread_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const iovecs=Iovec.read_bytes_array(buffer,iovs_ptr,iovs_len);let nread=0;for(const iovec of iovecs){const{ret,data}=self.fds[fd].fd_read(iovec.buf_len);if(ret!=ERRNO_SUCCESS){buffer.setUint32(nread_ptr,nread,true);return ret}buffer8.set(data,iovec.buf);nread+=data.length;if(data.length!=iovec.buf_len){break}}buffer.setUint32(nread_ptr,nread,true);return ERRNO_SUCCESS}else {return ERRNO_BADF}},fd_readdir(fd,buf,buf_len,cookie,bufused_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){let bufused=0;while(true){const{ret,dirent}=self.fds[fd].fd_readdir_single(cookie);if(ret!=0){buffer.setUint32(bufused_ptr,bufused,true);return ret}if(dirent==null){break}if(buf_len-bufused<dirent.head_length()){bufused=buf_len;break}const head_bytes=new ArrayBuffer(dirent.head_length());dirent.write_head_bytes(new DataView(head_bytes),0);buffer8.set(new Uint8Array(head_bytes).slice(0,Math.min(head_bytes.byteLength,buf_len-bufused)),buf);buf+=dirent.head_length();bufused+=dirent.head_length();if(buf_len-bufused<dirent.name_length()){bufused=buf_len;break}dirent.write_name_bytes(buffer8,buf,buf_len-bufused);buf+=dirent.name_length();bufused+=dirent.name_length();cookie=dirent.d_next;}buffer.setUint32(bufused_ptr,bufused,true);return 0}else {return ERRNO_BADF}},fd_renumber(fd,to){if(self.fds[fd]!=undefined&&self.fds[to]!=undefined){const ret=self.fds[to].fd_close();if(ret!=0){return ret}self.fds[to]=self.fds[fd];self.fds[fd]=undefined;return 0}else {return ERRNO_BADF}},fd_seek(fd,offset,whence,offset_out_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const{ret,offset:offset_out}=self.fds[fd].fd_seek(offset,whence);buffer.setBigInt64(offset_out_ptr,offset_out,true);return ret}else {return ERRNO_BADF}},fd_sync(fd){if(self.fds[fd]!=undefined){return self.fds[fd].fd_sync()}else {return ERRNO_BADF}},fd_tell(fd,offset_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const{ret,offset}=self.fds[fd].fd_tell();buffer.setBigUint64(offset_ptr,offset,true);return ret}else {return ERRNO_BADF}},fd_write(fd,iovs_ptr,iovs_len,nwritten_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const iovecs=Ciovec.read_bytes_array(buffer,iovs_ptr,iovs_len);let nwritten=0;for(const iovec of iovecs){const data=buffer8.slice(iovec.buf,iovec.buf+iovec.buf_len);const{ret,nwritten:nwritten_part}=self.fds[fd].fd_write(data);if(ret!=ERRNO_SUCCESS){buffer.setUint32(nwritten_ptr,nwritten,true);return ret}nwritten+=nwritten_part;if(nwritten_part!=data.byteLength){break}}buffer.setUint32(nwritten_ptr,nwritten,true);return ERRNO_SUCCESS}else {return ERRNO_BADF}},path_create_directory(fd,path_ptr,path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_create_directory(path)}else {return ERRNO_BADF}},path_filestat_get(fd,flags,path_ptr,path_len,filestat_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));const{ret,filestat}=self.fds[fd].path_filestat_get(flags,path);if(filestat!=null){filestat.write_bytes(buffer,filestat_ptr);}return ret}else {return ERRNO_BADF}},path_filestat_set_times(fd,flags,path_ptr,path_len,atim,mtim,fst_flags){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_filestat_set_times(flags,path,atim,mtim,fst_flags)}else {return ERRNO_BADF}},path_link(old_fd,old_flags,old_path_ptr,old_path_len,new_fd,new_path_ptr,new_path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[old_fd]!=undefined&&self.fds[new_fd]!=undefined){const old_path=new TextDecoder("utf-8").decode(buffer8.slice(old_path_ptr,old_path_ptr+old_path_len));const new_path=new TextDecoder("utf-8").decode(buffer8.slice(new_path_ptr,new_path_ptr+new_path_len));const{ret,inode_obj}=self.fds[old_fd].path_lookup(old_path,old_flags);if(inode_obj==null){return ret}return self.fds[new_fd].path_link(new_path,inode_obj,false)}else {return ERRNO_BADF}},path_open(fd,dirflags,path_ptr,path_len,oflags,fs_rights_base,fs_rights_inheriting,fd_flags,opened_fd_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));debug.log(path);const{ret,fd_obj}=self.fds[fd].path_open(dirflags,path,oflags,fs_rights_base,fs_rights_inheriting,fd_flags);if(ret!=0){return ret}self.fds.push(fd_obj);const opened_fd=self.fds.length-1;buffer.setUint32(opened_fd_ptr,opened_fd,true);return 0}else {return ERRNO_BADF}},path_readlink(fd,path_ptr,path_len,buf_ptr,buf_len,nread_ptr){const buffer=new DataView(self.inst.exports.memory.buffer);const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));debug.log(path);const{ret,data}=self.fds[fd].path_readlink(path);if(data!=null){const data_buf=new TextEncoder().encode(data);if(data_buf.length>buf_len){buffer.setUint32(nread_ptr,0,true);return ERRNO_BADF}buffer8.set(data_buf,buf_ptr);buffer.setUint32(nread_ptr,data_buf.length,true);}return ret}else {return ERRNO_BADF}},path_remove_directory(fd,path_ptr,path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_remove_directory(path)}else {return ERRNO_BADF}},path_rename(fd,old_path_ptr,old_path_len,new_fd,new_path_ptr,new_path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined&&self.fds[new_fd]!=undefined){const old_path=new TextDecoder("utf-8").decode(buffer8.slice(old_path_ptr,old_path_ptr+old_path_len));const new_path=new TextDecoder("utf-8").decode(buffer8.slice(new_path_ptr,new_path_ptr+new_path_len));let{ret,inode_obj}=self.fds[fd].path_unlink(old_path);if(inode_obj==null){return ret}ret=self.fds[new_fd].path_link(new_path,inode_obj,true);if(ret!=ERRNO_SUCCESS){if(self.fds[fd].path_link(old_path,inode_obj,true)!=ERRNO_SUCCESS){throw "path_link should always return success when relinking an inode back to the original place"}}return ret}else {return ERRNO_BADF}},path_symlink(old_path_ptr,old_path_len,fd,new_path_ptr,new_path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){new TextDecoder("utf-8").decode(buffer8.slice(old_path_ptr,old_path_ptr+old_path_len));new TextDecoder("utf-8").decode(buffer8.slice(new_path_ptr,new_path_ptr+new_path_len));return ERRNO_NOTSUP}else {return ERRNO_BADF}},path_unlink_file(fd,path_ptr,path_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);if(self.fds[fd]!=undefined){const path=new TextDecoder("utf-8").decode(buffer8.slice(path_ptr,path_ptr+path_len));return self.fds[fd].path_unlink_file(path)}else {return ERRNO_BADF}},poll_oneoff(in_,out,nsubscriptions){throw "async io not supported"},proc_exit(exit_code){throw new WASIProcExit(exit_code)},proc_raise(sig){throw "raised signal "+sig},sched_yield(){},random_get(buf,buf_len){const buffer8=new Uint8Array(self.inst.exports.memory.buffer);for(let i=0;i<buf_len;i++){buffer8[buf+i]=Math.random()*256|0;}},sock_recv(fd,ri_data,ri_flags){throw "sockets not supported"},sock_send(fd,si_data,si_flags){throw "sockets not supported"},sock_shutdown(fd,how){throw "sockets not supported"},sock_accept(fd,flags){throw "sockets not supported"}};}};
1344
-
1345
- class Fd{fd_allocate(offset,len){return ERRNO_NOTSUP}fd_close(){return 0}fd_fdstat_get(){return {ret:ERRNO_NOTSUP,fdstat:null}}fd_fdstat_set_flags(flags){return ERRNO_NOTSUP}fd_fdstat_set_rights(fs_rights_base,fs_rights_inheriting){return ERRNO_NOTSUP}fd_filestat_get(){return {ret:ERRNO_NOTSUP,filestat:null}}fd_filestat_set_size(size){return ERRNO_NOTSUP}fd_filestat_set_times(atim,mtim,fst_flags){return ERRNO_NOTSUP}fd_pread(size,offset){return {ret:ERRNO_NOTSUP,data:new Uint8Array}}fd_prestat_get(){return {ret:ERRNO_NOTSUP,prestat:null}}fd_pwrite(data,offset){return {ret:ERRNO_NOTSUP,nwritten:0}}fd_read(size){return {ret:ERRNO_NOTSUP,data:new Uint8Array}}fd_readdir_single(cookie){return {ret:ERRNO_NOTSUP,dirent:null}}fd_seek(offset,whence){return {ret:ERRNO_NOTSUP,offset:0n}}fd_sync(){return 0}fd_tell(){return {ret:ERRNO_NOTSUP,offset:0n}}fd_write(data){return {ret:ERRNO_NOTSUP,nwritten:0}}path_create_directory(path){return ERRNO_NOTSUP}path_filestat_get(flags,path){return {ret:ERRNO_NOTSUP,filestat:null}}path_filestat_set_times(flags,path,atim,mtim,fst_flags){return ERRNO_NOTSUP}path_link(path,inode,allow_dir){return ERRNO_NOTSUP}path_unlink(path){return {ret:ERRNO_NOTSUP,inode_obj:null}}path_lookup(path,dirflags){return {ret:ERRNO_NOTSUP,inode_obj:null}}path_open(dirflags,path,oflags,fs_rights_base,fs_rights_inheriting,fd_flags){return {ret:ERRNO_NOTDIR,fd_obj:null}}path_readlink(path){return {ret:ERRNO_NOTSUP,data:null}}path_remove_directory(path){return ERRNO_NOTSUP}path_rename(old_path,new_fd,new_path){return ERRNO_NOTSUP}path_unlink_file(path){return ERRNO_NOTSUP}}class Inode{}
1346
-
1347
- class OpenFile extends Fd{fd_allocate(offset,len){if(this.file.size>offset+len);else {const new_data=new Uint8Array(Number(offset+len));new_data.set(this.file.data,0);this.file.data=new_data;}return ERRNO_SUCCESS}fd_fdstat_get(){return {ret:0,fdstat:new Fdstat(FILETYPE_REGULAR_FILE,0)}}fd_filestat_set_size(size){if(this.file.size>size){this.file.data=new Uint8Array(this.file.data.buffer.slice(0,Number(size)));}else {const new_data=new Uint8Array(Number(size));new_data.set(this.file.data,0);this.file.data=new_data;}return ERRNO_SUCCESS}fd_read(size){const slice=this.file.data.slice(Number(this.file_pos),Number(this.file_pos+BigInt(size)));this.file_pos+=BigInt(slice.length);return {ret:0,data:slice}}fd_pread(size,offset){const slice=this.file.data.slice(Number(offset),Number(offset+BigInt(size)));return {ret:0,data:slice}}fd_seek(offset,whence){let calculated_offset;switch(whence){case WHENCE_SET:calculated_offset=offset;break;case WHENCE_CUR:calculated_offset=this.file_pos+offset;break;case WHENCE_END:calculated_offset=BigInt(this.file.data.byteLength)+offset;break;default:return {ret:ERRNO_INVAL,offset:0n}}if(calculated_offset<0){return {ret:ERRNO_INVAL,offset:0n}}this.file_pos=calculated_offset;return {ret:0,offset:this.file_pos}}fd_tell(){return {ret:0,offset:this.file_pos}}fd_write(data){if(this.file.readonly)return {ret:ERRNO_BADF,nwritten:0};if(this.file_pos+BigInt(data.byteLength)>this.file.size){const old=this.file.data;this.file.data=new Uint8Array(Number(this.file_pos+BigInt(data.byteLength)));this.file.data.set(old);}this.file.data.set(data,Number(this.file_pos));this.file_pos+=BigInt(data.byteLength);return {ret:0,nwritten:data.byteLength}}fd_pwrite(data,offset){if(this.file.readonly)return {ret:ERRNO_BADF,nwritten:0};if(offset+BigInt(data.byteLength)>this.file.size){const old=this.file.data;this.file.data=new Uint8Array(Number(offset+BigInt(data.byteLength)));this.file.data.set(old);}this.file.data.set(data,Number(offset));return {ret:0,nwritten:data.byteLength}}fd_filestat_get(){return {ret:0,filestat:this.file.stat()}}constructor(file){super();this.file_pos=0n;this.file=file;}}class OpenDirectory extends Fd{fd_seek(offset,whence){return {ret:ERRNO_BADF,offset:0n}}fd_tell(){return {ret:ERRNO_BADF,offset:0n}}fd_allocate(offset,len){return ERRNO_BADF}fd_fdstat_get(){return {ret:0,fdstat:new Fdstat(FILETYPE_DIRECTORY,0)}}fd_readdir_single(cookie){if(debug.enabled){debug.log("readdir_single",cookie);debug.log(cookie,this.dir.contents.keys());}if(cookie==0n){return {ret:ERRNO_SUCCESS,dirent:new Dirent(1n,".",FILETYPE_DIRECTORY)}}else if(cookie==1n){return {ret:ERRNO_SUCCESS,dirent:new Dirent(2n,"..",FILETYPE_DIRECTORY)}}if(cookie>=BigInt(this.dir.contents.size)+2n){return {ret:0,dirent:null}}const[name,entry]=Array.from(this.dir.contents.entries())[Number(cookie-2n)];return {ret:0,dirent:new Dirent(cookie+1n,name,entry.stat().filetype)}}path_filestat_get(flags,path_str){const{ret:path_err,path}=Path.from(path_str);if(path==null){return {ret:path_err,filestat:null}}const{ret,entry}=this.dir.get_entry_for_path(path);if(entry==null){return {ret,filestat:null}}return {ret:0,filestat:entry.stat()}}path_lookup(path_str,dirflags){const{ret:path_ret,path}=Path.from(path_str);if(path==null){return {ret:path_ret,inode_obj:null}}const{ret,entry}=this.dir.get_entry_for_path(path);if(entry==null){return {ret,inode_obj:null}}return {ret:ERRNO_SUCCESS,inode_obj:entry}}path_open(dirflags,path_str,oflags,fs_rights_base,fs_rights_inheriting,fd_flags){const{ret:path_ret,path}=Path.from(path_str);if(path==null){return {ret:path_ret,fd_obj:null}}let{ret,entry}=this.dir.get_entry_for_path(path);if(entry==null){if(ret!=ERRNO_NOENT){return {ret,fd_obj:null}}if((oflags&OFLAGS_CREAT)==OFLAGS_CREAT){const{ret,entry:new_entry}=this.dir.create_entry_for_path(path_str,(oflags&OFLAGS_DIRECTORY)==OFLAGS_DIRECTORY);if(new_entry==null){return {ret,fd_obj:null}}entry=new_entry;}else {return {ret:ERRNO_NOENT,fd_obj:null}}}else if((oflags&OFLAGS_EXCL)==OFLAGS_EXCL){return {ret:ERRNO_EXIST,fd_obj:null}}if((oflags&OFLAGS_DIRECTORY)==OFLAGS_DIRECTORY&&entry.stat().filetype!==FILETYPE_DIRECTORY){return {ret:ERRNO_NOTDIR,fd_obj:null}}return entry.path_open(oflags,fs_rights_base,fd_flags)}path_create_directory(path){return this.path_open(0,path,OFLAGS_CREAT|OFLAGS_DIRECTORY,0n,0n,0).ret}path_link(path_str,inode,allow_dir){const{ret:path_ret,path}=Path.from(path_str);if(path==null){return path_ret}if(path.is_dir){return ERRNO_NOENT}const{ret:parent_ret,parent_entry,filename,entry}=this.dir.get_parent_dir_and_entry_for_path(path,true);if(parent_entry==null||filename==null){return parent_ret}if(entry!=null){const source_is_dir=inode.stat().filetype==FILETYPE_DIRECTORY;const target_is_dir=entry.stat().filetype==FILETYPE_DIRECTORY;if(source_is_dir&&target_is_dir){if(allow_dir&&entry instanceof Directory){if(entry.contents.size==0);else {return ERRNO_NOTEMPTY}}else {return ERRNO_EXIST}}else if(source_is_dir&&!target_is_dir){return ERRNO_NOTDIR}else if(!source_is_dir&&target_is_dir){return ERRNO_ISDIR}else if(inode.stat().filetype==FILETYPE_REGULAR_FILE&&entry.stat().filetype==FILETYPE_REGULAR_FILE);else {return ERRNO_EXIST}}if(!allow_dir&&inode.stat().filetype==FILETYPE_DIRECTORY){return ERRNO_PERM}parent_entry.contents.set(filename,inode);return ERRNO_SUCCESS}path_unlink(path_str){const{ret:path_ret,path}=Path.from(path_str);if(path==null){return {ret:path_ret,inode_obj:null}}const{ret:parent_ret,parent_entry,filename,entry}=this.dir.get_parent_dir_and_entry_for_path(path,true);if(parent_entry==null||filename==null){return {ret:parent_ret,inode_obj:null}}if(entry==null){return {ret:ERRNO_NOENT,inode_obj:null}}parent_entry.contents.delete(filename);return {ret:ERRNO_SUCCESS,inode_obj:entry}}path_unlink_file(path_str){const{ret:path_ret,path}=Path.from(path_str);if(path==null){return path_ret}const{ret:parent_ret,parent_entry,filename,entry}=this.dir.get_parent_dir_and_entry_for_path(path,false);if(parent_entry==null||filename==null||entry==null){return parent_ret}if(entry.stat().filetype===FILETYPE_DIRECTORY){return ERRNO_ISDIR}parent_entry.contents.delete(filename);return ERRNO_SUCCESS}path_remove_directory(path_str){const{ret:path_ret,path}=Path.from(path_str);if(path==null){return path_ret}const{ret:parent_ret,parent_entry,filename,entry}=this.dir.get_parent_dir_and_entry_for_path(path,false);if(parent_entry==null||filename==null||entry==null){return parent_ret}if(!(entry instanceof Directory)||entry.stat().filetype!==FILETYPE_DIRECTORY){return ERRNO_NOTDIR}if(entry.contents.size!==0){return ERRNO_NOTEMPTY}if(!parent_entry.contents.delete(filename)){return ERRNO_NOENT}return ERRNO_SUCCESS}fd_filestat_get(){return {ret:0,filestat:this.dir.stat()}}fd_filestat_set_size(size){return ERRNO_BADF}fd_read(size){return {ret:ERRNO_BADF,data:new Uint8Array}}fd_pread(size,offset){return {ret:ERRNO_BADF,data:new Uint8Array}}fd_write(data){return {ret:ERRNO_BADF,nwritten:0}}fd_pwrite(data,offset){return {ret:ERRNO_BADF,nwritten:0}}constructor(dir){super();this.dir=dir;}}class PreopenDirectory extends OpenDirectory{fd_prestat_get(){return {ret:0,prestat:Prestat.dir(this.prestat_name)}}constructor(name,contents){super(new Directory(contents));this.prestat_name=name;}}class File extends Inode{path_open(oflags,fs_rights_base,fd_flags){if(this.readonly&&(fs_rights_base&BigInt(RIGHTS_FD_WRITE))==BigInt(RIGHTS_FD_WRITE)){return {ret:ERRNO_PERM,fd_obj:null}}if((oflags&OFLAGS_TRUNC)==OFLAGS_TRUNC){if(this.readonly)return {ret:ERRNO_PERM,fd_obj:null};this.data=new Uint8Array([]);}const file=new OpenFile(this);if(fd_flags&FDFLAGS_APPEND)file.fd_seek(0n,WHENCE_END);return {ret:ERRNO_SUCCESS,fd_obj:file}}get size(){return BigInt(this.data.byteLength)}stat(){return new Filestat(FILETYPE_REGULAR_FILE,this.size)}constructor(data,options){super();this.data=new Uint8Array(data);this.readonly=!!options?.readonly;}}let Path=class Path{static from(path){const self=new Path;self.is_dir=path.endsWith("/");if(path.startsWith("/")){return {ret:ERRNO_NOTCAPABLE,path:null}}if(path.includes("\x00")){return {ret:ERRNO_INVAL,path:null}}for(const component of path.split("/")){if(component===""||component==="."){continue}if(component===".."){if(self.parts.pop()==undefined){return {ret:ERRNO_NOTCAPABLE,path:null}}continue}self.parts.push(component);}return {ret:ERRNO_SUCCESS,path:self}}to_path_string(){let s=this.parts.join("/");if(this.is_dir){s+="/";}return s}constructor(){this.parts=[];this.is_dir=false;}};class Directory extends Inode{path_open(oflags,fs_rights_base,fd_flags){return {ret:ERRNO_SUCCESS,fd_obj:new OpenDirectory(this)}}stat(){return new Filestat(FILETYPE_DIRECTORY,0n)}get_entry_for_path(path){let entry=this;for(const component of path.parts){if(!(entry instanceof Directory)){return {ret:ERRNO_NOTDIR,entry:null}}const child=entry.contents.get(component);if(child!==undefined){entry=child;}else {debug.log(component);return {ret:ERRNO_NOENT,entry:null}}}if(path.is_dir){if(entry.stat().filetype!=FILETYPE_DIRECTORY){return {ret:ERRNO_NOTDIR,entry:null}}}return {ret:ERRNO_SUCCESS,entry}}get_parent_dir_and_entry_for_path(path,allow_undefined){const filename=path.parts.pop();if(filename===undefined){return {ret:ERRNO_INVAL,parent_entry:null,filename:null,entry:null}}const{ret:entry_ret,entry:parent_entry}=this.get_entry_for_path(path);if(parent_entry==null){return {ret:entry_ret,parent_entry:null,filename:null,entry:null}}if(!(parent_entry instanceof Directory)){return {ret:ERRNO_NOTDIR,parent_entry:null,filename:null,entry:null}}const entry=parent_entry.contents.get(filename);if(entry===undefined){if(!allow_undefined){return {ret:ERRNO_NOENT,parent_entry:null,filename:null,entry:null}}else {return {ret:ERRNO_SUCCESS,parent_entry,filename,entry:null}}}if(path.is_dir){if(entry.stat().filetype!=FILETYPE_DIRECTORY){return {ret:ERRNO_NOTDIR,parent_entry:null,filename:null,entry:null}}}return {ret:ERRNO_SUCCESS,parent_entry,filename,entry}}create_entry_for_path(path_str,is_dir){const{ret:path_ret,path}=Path.from(path_str);if(path==null){return {ret:path_ret,entry:null}}let{ret:parent_ret,parent_entry,filename,entry}=this.get_parent_dir_and_entry_for_path(path,true);if(parent_entry==null||filename==null){return {ret:parent_ret,entry:null}}if(entry!=null){return {ret:ERRNO_EXIST,entry:null}}debug.log("create",path);let new_child;if(!is_dir){new_child=new File(new ArrayBuffer(0));}else {new_child=new Directory(new Map);}parent_entry.contents.set(filename,new_child);entry=new_child;return {ret:ERRNO_SUCCESS,entry}}constructor(contents){super();if(contents instanceof Array){this.contents=new Map(contents);}else {this.contents=contents;}}}
1348
-
1349
- /**
1350
- * Create a console printer that can be used as an overlay of WASI imports.
1351
- * See the example below for how to use it.
1352
- *
1353
- * ```javascript
1354
- * const imports = {
1355
- * "wasi_snapshot_preview1": wasi.wasiImport,
1356
- * }
1357
- * const printer = consolePrinter();
1358
- * printer.addToImports(imports);
1359
- *
1360
- * const instance = await WebAssembly.instantiate(module, imports);
1361
- * printer.setMemory(instance.exports.memory);
1362
- * ```
1363
- *
1364
- * Note that the `stdout` and `stderr` functions are called with text, not
1365
- * bytes. This means that bytes written to stdout/stderr will be decoded as
1366
- * UTF-8 and then passed to the `stdout`/`stderr` functions every time a write
1367
- * occurs without buffering.
1368
- *
1369
- * @param stdout A function that will be called when stdout is written to.
1370
- * Defaults to `console.log`.
1371
- * @param stderr A function that will be called when stderr is written to.
1372
- * Defaults to `console.warn`.
1373
- * @returns An object that can be used as an overlay of WASI imports.
1374
- */
1375
- function consolePrinter({ stdout, stderr, } = {
1376
- stdout: console.log,
1377
- stderr: console.warn,
1378
- }) {
1379
- let memory = undefined;
1380
- let _view = undefined;
1381
- function getMemoryView() {
1382
- if (typeof memory === "undefined") {
1383
- throw new Error("Memory is not set");
1384
- }
1385
- if (_view === undefined || _view.buffer.byteLength === 0) {
1386
- _view = new DataView(memory.buffer);
1387
- }
1388
- return _view;
1389
- }
1390
- const decoder = new TextDecoder();
1391
- return {
1392
- addToImports(imports) {
1393
- const wasiImport = imports.wasi_snapshot_preview1;
1394
- const original_fd_write = wasiImport.fd_write;
1395
- wasiImport.fd_write = (fd, iovs, iovsLen, nwritten) => {
1396
- if (fd !== 1 && fd !== 2) {
1397
- return original_fd_write(fd, iovs, iovsLen, nwritten);
1398
- }
1399
- const view = getMemoryView();
1400
- const buffers = Array.from({ length: iovsLen }, (_, i) => {
1401
- const ptr = iovs + i * 8;
1402
- const buf = view.getUint32(ptr, true);
1403
- const bufLen = view.getUint32(ptr + 4, true);
1404
- return new Uint8Array(memory.buffer, buf, bufLen);
1405
- });
1406
- let written = 0;
1407
- let str = "";
1408
- for (const buffer of buffers) {
1409
- str += decoder.decode(buffer);
1410
- written += buffer.byteLength;
1411
- }
1412
- view.setUint32(nwritten, written, true);
1413
- const log = fd === 1 ? stdout : stderr;
1414
- log(str);
1415
- return 0;
1416
- };
1417
- const original_fd_filestat_get = wasiImport.fd_filestat_get;
1418
- wasiImport.fd_filestat_get = (fd, filestat) => {
1419
- if (fd !== 1 && fd !== 2) {
1420
- return original_fd_filestat_get(fd, filestat);
1421
- }
1422
- const view = getMemoryView();
1423
- const result = original_fd_filestat_get(fd, filestat);
1424
- if (result !== 0) {
1425
- return result;
1426
- }
1427
- const filetypePtr = filestat + 0;
1428
- view.setUint8(filetypePtr, 2); // FILETYPE_CHARACTER_DEVICE
1429
- return 0;
1430
- };
1431
- const original_fd_fdstat_get = wasiImport.fd_fdstat_get;
1432
- wasiImport.fd_fdstat_get = (fd, fdstat) => {
1433
- if (fd !== 1 && fd !== 2) {
1434
- return original_fd_fdstat_get(fd, fdstat);
1435
- }
1436
- const view = getMemoryView();
1437
- const fs_filetypePtr = fdstat + 0;
1438
- view.setUint8(fs_filetypePtr, 2); // FILETYPE_CHARACTER_DEVICE
1439
- const fs_rights_basePtr = fdstat + 8;
1440
- // See https://github.com/WebAssembly/WASI/blob/v0.2.0/legacy/preview1/docs.md#record-members
1441
- const RIGHTS_FD_WRITE = 1 << 6;
1442
- view.setBigUint64(fs_rights_basePtr, BigInt(RIGHTS_FD_WRITE), true);
1443
- return 0;
1444
- };
1445
- },
1446
- setMemory(m) {
1447
- memory = m;
1448
- },
1449
- };
1450
- }
1451
-
1452
- let DATA_VIEW = new DataView(new ArrayBuffer());
1453
- function data_view(mem) {
1454
- if (DATA_VIEW.buffer !== mem.buffer)
1455
- DATA_VIEW = new DataView(mem.buffer);
1456
- return DATA_VIEW;
1457
- }
1458
- function to_uint32(val) {
1459
- return val >>> 0;
1460
- }
1461
- const UTF8_DECODER = new TextDecoder('utf-8');
1462
- const UTF8_ENCODER = new TextEncoder('utf-8');
1463
- function utf8_encode(s, realloc, memory) {
1464
- if (typeof s !== 'string')
1465
- throw new TypeError('expected a string');
1466
- if (s.length === 0) {
1467
- UTF8_ENCODED_LEN = 0;
1468
- return 1;
1469
- }
1470
- let alloc_len = 0;
1471
- let ptr = 0;
1472
- let writtenTotal = 0;
1473
- while (s.length > 0) {
1474
- ptr = realloc(ptr, alloc_len, 1, alloc_len + s.length);
1475
- alloc_len += s.length;
1476
- const { read, written } = UTF8_ENCODER.encodeInto(s, new Uint8Array(memory.buffer, ptr + writtenTotal, alloc_len - writtenTotal));
1477
- writtenTotal += written;
1478
- s = s.slice(read);
1479
- }
1480
- if (alloc_len > writtenTotal)
1481
- ptr = realloc(ptr, alloc_len, 1, writtenTotal);
1482
- UTF8_ENCODED_LEN = writtenTotal;
1483
- return ptr;
1484
- }
1485
- let UTF8_ENCODED_LEN = 0;
1486
- class Slab {
1487
- constructor() {
1488
- this.list = [];
1489
- this.head = 0;
1490
- }
1491
- insert(val) {
1492
- if (this.head >= this.list.length) {
1493
- this.list.push({
1494
- next: this.list.length + 1,
1495
- val: undefined,
1496
- });
1497
- }
1498
- const ret = this.head;
1499
- const slot = this.list[ret];
1500
- this.head = slot.next;
1501
- slot.next = -1;
1502
- slot.val = val;
1503
- return ret;
1504
- }
1505
- get(idx) {
1506
- if (idx >= this.list.length)
1507
- throw new RangeError('handle index not valid');
1508
- const slot = this.list[idx];
1509
- if (slot.next === -1)
1510
- return slot.val;
1511
- throw new RangeError('handle index not valid');
1512
- }
1513
- remove(idx) {
1514
- const ret = this.get(idx); // validate the slot
1515
- const slot = this.list[idx];
1516
- slot.val = undefined;
1517
- slot.next = this.head;
1518
- this.head = idx;
1519
- return ret;
1520
- }
1521
- }
1522
- function throw_invalid_bool() {
1523
- throw new RangeError("invalid variant discriminant for bool");
1524
- }
1525
-
1526
- class RbAbiGuest {
1527
- constructor() {
1528
- this._resource0_slab = new Slab();
1529
- }
1530
- addToImports(imports) {
1531
- if (!("canonical_abi" in imports))
1532
- imports["canonical_abi"] = {};
1533
- imports.canonical_abi['resource_drop_rb-abi-value'] = i => {
1534
- this._resource0_slab.remove(i).drop();
1535
- };
1536
- imports.canonical_abi['resource_clone_rb-abi-value'] = i => {
1537
- const obj = this._resource0_slab.get(i);
1538
- return this._resource0_slab.insert(obj.clone());
1539
- };
1540
- imports.canonical_abi['resource_get_rb-abi-value'] = i => {
1541
- return this._resource0_slab.get(i)._wasm_val;
1542
- };
1543
- imports.canonical_abi['resource_new_rb-abi-value'] = i => {
1544
- this._registry0;
1545
- return this._resource0_slab.insert(new RbAbiValue(i, this));
1546
- };
1547
- }
1548
- async instantiate(module, imports) {
1549
- imports = imports || {};
1550
- this.addToImports(imports);
1551
- if (module instanceof WebAssembly.Instance) {
1552
- this.instance = module;
1553
- }
1554
- else if (module instanceof WebAssembly.Module) {
1555
- this.instance = await WebAssembly.instantiate(module, imports);
1556
- }
1557
- else if (module instanceof ArrayBuffer || module instanceof Uint8Array) {
1558
- const { instance } = await WebAssembly.instantiate(module, imports);
1559
- this.instance = instance;
1560
- }
1561
- else {
1562
- const { instance } = await WebAssembly.instantiateStreaming(module, imports);
1563
- this.instance = instance;
1564
- }
1565
- this._exports = this.instance.exports;
1566
- this._registry0 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-abi-value']);
1567
- }
1568
- rubyShowVersion() {
1569
- this._exports['ruby-show-version: func() -> ()']();
1570
- }
1571
- rubyInit(arg0) {
1572
- const memory = this._exports.memory;
1573
- const realloc = this._exports["cabi_realloc"];
1574
- const vec1 = arg0;
1575
- const len1 = vec1.length;
1576
- const result1 = realloc(0, 0, 4, len1 * 8);
1577
- for (let i = 0; i < vec1.length; i++) {
1578
- const e = vec1[i];
1579
- const base = result1 + i * 8;
1580
- const ptr0 = utf8_encode(e, realloc, memory);
1581
- const len0 = UTF8_ENCODED_LEN;
1582
- data_view(memory).setInt32(base + 4, len0, true);
1583
- data_view(memory).setInt32(base + 0, ptr0, true);
1584
- }
1585
- this._exports['ruby-init: func(args: list<string>) -> ()'](result1, len1);
1586
- }
1587
- rubyInitLoadpath() {
1588
- this._exports['ruby-init-loadpath: func() -> ()']();
1589
- }
1590
- rbEvalStringProtect(arg0) {
1591
- const memory = this._exports.memory;
1592
- const realloc = this._exports["cabi_realloc"];
1593
- const ptr0 = utf8_encode(arg0, realloc, memory);
1594
- const len0 = UTF8_ENCODED_LEN;
1595
- const ret = this._exports['rb-eval-string-protect: func(str: string) -> tuple<handle<rb-abi-value>, s32>'](ptr0, len0);
1596
- return [this._resource0_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
1597
- }
1598
- rbFuncallvProtect(arg0, arg1, arg2) {
1599
- const memory = this._exports.memory;
1600
- const realloc = this._exports["cabi_realloc"];
1601
- const obj0 = arg0;
1602
- if (!(obj0 instanceof RbAbiValue))
1603
- throw new TypeError('expected instance of RbAbiValue');
1604
- const vec2 = arg2;
1605
- const len2 = vec2.length;
1606
- const result2 = realloc(0, 0, 4, len2 * 4);
1607
- for (let i = 0; i < vec2.length; i++) {
1608
- const e = vec2[i];
1609
- const base = result2 + i * 4;
1610
- const obj1 = e;
1611
- if (!(obj1 instanceof RbAbiValue))
1612
- throw new TypeError('expected instance of RbAbiValue');
1613
- data_view(memory).setInt32(base + 0, this._resource0_slab.insert(obj1.clone()), true);
1614
- }
1615
- const ret = this._exports['rb-funcallv-protect: func(recv: handle<rb-abi-value>, mid: u32, args: list<handle<rb-abi-value>>) -> tuple<handle<rb-abi-value>, s32>'](this._resource0_slab.insert(obj0.clone()), to_uint32(arg1), result2, len2);
1616
- return [this._resource0_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
1617
- }
1618
- rbIntern(arg0) {
1619
- const memory = this._exports.memory;
1620
- const realloc = this._exports["cabi_realloc"];
1621
- const ptr0 = utf8_encode(arg0, realloc, memory);
1622
- const len0 = UTF8_ENCODED_LEN;
1623
- const ret = this._exports['rb-intern: func(name: string) -> u32'](ptr0, len0);
1624
- return ret >>> 0;
1625
- }
1626
- rbErrinfo() {
1627
- const ret = this._exports['rb-errinfo: func() -> handle<rb-abi-value>']();
1628
- return this._resource0_slab.remove(ret);
1629
- }
1630
- rbClearErrinfo() {
1631
- this._exports['rb-clear-errinfo: func() -> ()']();
1632
- }
1633
- rstringPtr(arg0) {
1634
- const memory = this._exports.memory;
1635
- const obj0 = arg0;
1636
- if (!(obj0 instanceof RbAbiValue))
1637
- throw new TypeError('expected instance of RbAbiValue');
1638
- const ret = this._exports['rstring-ptr: func(value: handle<rb-abi-value>) -> string'](this._resource0_slab.insert(obj0.clone()));
1639
- const ptr1 = data_view(memory).getInt32(ret + 0, true);
1640
- const len1 = data_view(memory).getInt32(ret + 4, true);
1641
- const result1 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr1, len1));
1642
- this._exports["cabi_post_rstring-ptr"](ret);
1643
- return result1;
1644
- }
1645
- rbVmBugreport() {
1646
- this._exports['rb-vm-bugreport: func() -> ()']();
1647
- }
1648
- rbGcEnable() {
1649
- const ret = this._exports['rb-gc-enable: func() -> bool']();
1650
- const bool0 = ret;
1651
- return bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool());
1652
- }
1653
- rbGcDisable() {
1654
- const ret = this._exports['rb-gc-disable: func() -> bool']();
1655
- const bool0 = ret;
1656
- return bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool());
1657
- }
1658
- rbSetShouldProhibitRewind(arg0) {
1659
- const ret = this._exports['rb-set-should-prohibit-rewind: func(new-value: bool) -> bool'](arg0 ? 1 : 0);
1660
- const bool0 = ret;
1661
- return bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool());
1662
- }
1663
- }
1664
- class RbAbiValue {
1665
- constructor(wasm_val, obj) {
1666
- this._wasm_val = wasm_val;
1667
- this._obj = obj;
1668
- this._refcnt = 1;
1669
- obj._registry0.register(this, wasm_val, this);
1670
- }
1671
- clone() {
1672
- this._refcnt += 1;
1673
- return this;
1674
- }
1675
- drop() {
1676
- this._refcnt -= 1;
1677
- if (this._refcnt !== 0)
1678
- return;
1679
- this._obj._registry0.unregister(this);
1680
- const dtor = this._obj._exports['canonical_abi_drop_rb-abi-value'];
1681
- const wasm_val = this._wasm_val;
1682
- delete this._obj;
1683
- delete this._refcnt;
1684
- delete this._wasm_val;
1685
- dtor(wasm_val);
1686
- }
1687
- }
1688
-
1689
- function addRbJsAbiHostToImports(imports, obj, get_export) {
1690
- if (!("rb-js-abi-host" in imports))
1691
- imports["rb-js-abi-host"] = {};
1692
- imports["rb-js-abi-host"]["eval-js: func(code: string) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }"] = function (arg0, arg1, arg2) {
1693
- const memory = get_export("memory");
1694
- const ptr0 = arg0;
1695
- const len0 = arg1;
1696
- const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1697
- const ret0 = obj.evalJs(result0);
1698
- const variant1 = ret0;
1699
- switch (variant1.tag) {
1700
- case "success": {
1701
- const e = variant1.val;
1702
- data_view(memory).setInt8(arg2 + 0, 0, true);
1703
- data_view(memory).setInt32(arg2 + 4, resources0.insert(e), true);
1704
- break;
1705
- }
1706
- case "failure": {
1707
- const e = variant1.val;
1708
- data_view(memory).setInt8(arg2 + 0, 1, true);
1709
- data_view(memory).setInt32(arg2 + 4, resources0.insert(e), true);
1710
- break;
1711
- }
1712
- default:
1713
- throw new RangeError("invalid variant specified for JsAbiResult");
1714
- }
1715
- };
1716
- imports["rb-js-abi-host"]["is-js: func(value: handle<js-abi-value>) -> bool"] = function (arg0) {
1717
- const ret0 = obj.isJs(resources0.get(arg0));
1718
- return ret0 ? 1 : 0;
1719
- };
1720
- imports["rb-js-abi-host"]["instance-of: func(value: handle<js-abi-value>, klass: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
1721
- const ret0 = obj.instanceOf(resources0.get(arg0), resources0.get(arg1));
1722
- return ret0 ? 1 : 0;
1723
- };
1724
- imports["rb-js-abi-host"]["global-this: func() -> handle<js-abi-value>"] = function () {
1725
- const ret0 = obj.globalThis();
1726
- return resources0.insert(ret0);
1727
- };
1728
- imports["rb-js-abi-host"]["int-to-js-number: func(value: s32) -> handle<js-abi-value>"] = function (arg0) {
1729
- const ret0 = obj.intToJsNumber(arg0);
1730
- return resources0.insert(ret0);
1731
- };
1732
- imports["rb-js-abi-host"]["float-to-js-number: func(value: float64) -> handle<js-abi-value>"] = function (arg0) {
1733
- const ret0 = obj.floatToJsNumber(arg0);
1734
- return resources0.insert(ret0);
1735
- };
1736
- imports["rb-js-abi-host"]["string-to-js-string: func(value: string) -> handle<js-abi-value>"] = function (arg0, arg1) {
1737
- const memory = get_export("memory");
1738
- const ptr0 = arg0;
1739
- const len0 = arg1;
1740
- const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1741
- const ret0 = obj.stringToJsString(result0);
1742
- return resources0.insert(ret0);
1743
- };
1744
- imports["rb-js-abi-host"]["bool-to-js-bool: func(value: bool) -> handle<js-abi-value>"] = function (arg0) {
1745
- const bool0 = arg0;
1746
- const ret0 = obj.boolToJsBool(bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool()));
1747
- return resources0.insert(ret0);
1748
- };
1749
- imports["rb-js-abi-host"]["proc-to-js-function: func(value: u32) -> handle<js-abi-value>"] = function (arg0) {
1750
- const ret0 = obj.procToJsFunction(arg0 >>> 0);
1751
- return resources0.insert(ret0);
1752
- };
1753
- imports["rb-js-abi-host"]["rb-object-to-js-rb-value: func(raw-rb-abi-value: u32) -> handle<js-abi-value>"] = function (arg0) {
1754
- const ret0 = obj.rbObjectToJsRbValue(arg0 >>> 0);
1755
- return resources0.insert(ret0);
1756
- };
1757
- imports["rb-js-abi-host"]["js-value-to-string: func(value: handle<js-abi-value>) -> string"] = function (arg0, arg1) {
1758
- const memory = get_export("memory");
1759
- const realloc = get_export("cabi_realloc");
1760
- const ret0 = obj.jsValueToString(resources0.get(arg0));
1761
- const ptr0 = utf8_encode(ret0, realloc, memory);
1762
- const len0 = UTF8_ENCODED_LEN;
1763
- data_view(memory).setInt32(arg1 + 4, len0, true);
1764
- data_view(memory).setInt32(arg1 + 0, ptr0, true);
1765
- };
1766
- imports["rb-js-abi-host"]["js-value-to-integer: func(value: handle<js-abi-value>) -> variant { as-float(float64), bignum(string) }"] = function (arg0, arg1) {
1767
- const memory = get_export("memory");
1768
- const realloc = get_export("cabi_realloc");
1769
- const ret0 = obj.jsValueToInteger(resources0.get(arg0));
1770
- const variant1 = ret0;
1771
- switch (variant1.tag) {
1772
- case "as-float": {
1773
- const e = variant1.val;
1774
- data_view(memory).setInt8(arg1 + 0, 0, true);
1775
- data_view(memory).setFloat64(arg1 + 8, +e, true);
1776
- break;
1777
- }
1778
- case "bignum": {
1779
- const e = variant1.val;
1780
- data_view(memory).setInt8(arg1 + 0, 1, true);
1781
- const ptr0 = utf8_encode(e, realloc, memory);
1782
- const len0 = UTF8_ENCODED_LEN;
1783
- data_view(memory).setInt32(arg1 + 12, len0, true);
1784
- data_view(memory).setInt32(arg1 + 8, ptr0, true);
1785
- break;
1786
- }
1787
- default:
1788
- throw new RangeError("invalid variant specified for RawInteger");
1789
- }
1790
- };
1791
- imports["rb-js-abi-host"]["export-js-value-to-host: func(value: handle<js-abi-value>) -> ()"] = function (arg0) {
1792
- obj.exportJsValueToHost(resources0.get(arg0));
1793
- };
1794
- imports["rb-js-abi-host"]["import-js-value-from-host: func() -> handle<js-abi-value>"] = function () {
1795
- const ret0 = obj.importJsValueFromHost();
1796
- return resources0.insert(ret0);
1797
- };
1798
- imports["rb-js-abi-host"]["js-value-typeof: func(value: handle<js-abi-value>) -> string"] = function (arg0, arg1) {
1799
- const memory = get_export("memory");
1800
- const realloc = get_export("cabi_realloc");
1801
- const ret0 = obj.jsValueTypeof(resources0.get(arg0));
1802
- const ptr0 = utf8_encode(ret0, realloc, memory);
1803
- const len0 = UTF8_ENCODED_LEN;
1804
- data_view(memory).setInt32(arg1 + 4, len0, true);
1805
- data_view(memory).setInt32(arg1 + 0, ptr0, true);
1806
- };
1807
- imports["rb-js-abi-host"]["js-value-equal: func(lhs: handle<js-abi-value>, rhs: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
1808
- const ret0 = obj.jsValueEqual(resources0.get(arg0), resources0.get(arg1));
1809
- return ret0 ? 1 : 0;
1810
- };
1811
- imports["rb-js-abi-host"]["js-value-strictly-equal: func(lhs: handle<js-abi-value>, rhs: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
1812
- const ret0 = obj.jsValueStrictlyEqual(resources0.get(arg0), resources0.get(arg1));
1813
- return ret0 ? 1 : 0;
1814
- };
1815
- imports["rb-js-abi-host"]["reflect-apply: func(target: handle<js-abi-value>, this-argument: handle<js-abi-value>, arguments: list<handle<js-abi-value>>) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }"] = function (arg0, arg1, arg2, arg3, arg4) {
1816
- const memory = get_export("memory");
1817
- const len0 = arg3;
1818
- const base0 = arg2;
1819
- const result0 = [];
1820
- for (let i = 0; i < len0; i++) {
1821
- const base = base0 + i * 4;
1822
- result0.push(resources0.get(data_view(memory).getInt32(base + 0, true)));
1823
- }
1824
- const ret0 = obj.reflectApply(resources0.get(arg0), resources0.get(arg1), result0);
1825
- const variant1 = ret0;
1826
- switch (variant1.tag) {
1827
- case "success": {
1828
- const e = variant1.val;
1829
- data_view(memory).setInt8(arg4 + 0, 0, true);
1830
- data_view(memory).setInt32(arg4 + 4, resources0.insert(e), true);
1831
- break;
1832
- }
1833
- case "failure": {
1834
- const e = variant1.val;
1835
- data_view(memory).setInt8(arg4 + 0, 1, true);
1836
- data_view(memory).setInt32(arg4 + 4, resources0.insert(e), true);
1837
- break;
1838
- }
1839
- default:
1840
- throw new RangeError("invalid variant specified for JsAbiResult");
1841
- }
1842
- };
1843
- imports["rb-js-abi-host"]["reflect-construct: func(target: handle<js-abi-value>, arguments: list<handle<js-abi-value>>) -> handle<js-abi-value>"] = function (arg0, arg1, arg2) {
1844
- const memory = get_export("memory");
1845
- const len0 = arg2;
1846
- const base0 = arg1;
1847
- const result0 = [];
1848
- for (let i = 0; i < len0; i++) {
1849
- const base = base0 + i * 4;
1850
- result0.push(resources0.get(data_view(memory).getInt32(base + 0, true)));
1851
- }
1852
- const ret0 = obj.reflectConstruct(resources0.get(arg0), result0);
1853
- return resources0.insert(ret0);
1854
- };
1855
- imports["rb-js-abi-host"]["reflect-delete-property: func(target: handle<js-abi-value>, property-key: string) -> bool"] = function (arg0, arg1, arg2) {
1856
- const memory = get_export("memory");
1857
- const ptr0 = arg1;
1858
- const len0 = arg2;
1859
- const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1860
- const ret0 = obj.reflectDeleteProperty(resources0.get(arg0), result0);
1861
- return ret0 ? 1 : 0;
1862
- };
1863
- imports["rb-js-abi-host"]["reflect-get: func(target: handle<js-abi-value>, property-key: string) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }"] = function (arg0, arg1, arg2, arg3) {
1864
- const memory = get_export("memory");
1865
- const ptr0 = arg1;
1866
- const len0 = arg2;
1867
- const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1868
- const ret0 = obj.reflectGet(resources0.get(arg0), result0);
1869
- const variant1 = ret0;
1870
- switch (variant1.tag) {
1871
- case "success": {
1872
- const e = variant1.val;
1873
- data_view(memory).setInt8(arg3 + 0, 0, true);
1874
- data_view(memory).setInt32(arg3 + 4, resources0.insert(e), true);
1875
- break;
1876
- }
1877
- case "failure": {
1878
- const e = variant1.val;
1879
- data_view(memory).setInt8(arg3 + 0, 1, true);
1880
- data_view(memory).setInt32(arg3 + 4, resources0.insert(e), true);
1881
- break;
1882
- }
1883
- default:
1884
- throw new RangeError("invalid variant specified for JsAbiResult");
1885
- }
1886
- };
1887
- imports["rb-js-abi-host"]["reflect-get-own-property-descriptor: func(target: handle<js-abi-value>, property-key: string) -> handle<js-abi-value>"] = function (arg0, arg1, arg2) {
1888
- const memory = get_export("memory");
1889
- const ptr0 = arg1;
1890
- const len0 = arg2;
1891
- const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1892
- const ret0 = obj.reflectGetOwnPropertyDescriptor(resources0.get(arg0), result0);
1893
- return resources0.insert(ret0);
1894
- };
1895
- imports["rb-js-abi-host"]["reflect-get-prototype-of: func(target: handle<js-abi-value>) -> handle<js-abi-value>"] = function (arg0) {
1896
- const ret0 = obj.reflectGetPrototypeOf(resources0.get(arg0));
1897
- return resources0.insert(ret0);
1898
- };
1899
- imports["rb-js-abi-host"]["reflect-has: func(target: handle<js-abi-value>, property-key: string) -> bool"] = function (arg0, arg1, arg2) {
1900
- const memory = get_export("memory");
1901
- const ptr0 = arg1;
1902
- const len0 = arg2;
1903
- const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1904
- const ret0 = obj.reflectHas(resources0.get(arg0), result0);
1905
- return ret0 ? 1 : 0;
1906
- };
1907
- imports["rb-js-abi-host"]["reflect-is-extensible: func(target: handle<js-abi-value>) -> bool"] = function (arg0) {
1908
- const ret0 = obj.reflectIsExtensible(resources0.get(arg0));
1909
- return ret0 ? 1 : 0;
1910
- };
1911
- imports["rb-js-abi-host"]["reflect-own-keys: func(target: handle<js-abi-value>) -> list<handle<js-abi-value>>"] = function (arg0, arg1) {
1912
- const memory = get_export("memory");
1913
- const realloc = get_export("cabi_realloc");
1914
- const ret0 = obj.reflectOwnKeys(resources0.get(arg0));
1915
- const vec0 = ret0;
1916
- const len0 = vec0.length;
1917
- const result0 = realloc(0, 0, 4, len0 * 4);
1918
- for (let i = 0; i < vec0.length; i++) {
1919
- const e = vec0[i];
1920
- const base = result0 + i * 4;
1921
- data_view(memory).setInt32(base + 0, resources0.insert(e), true);
1922
- }
1923
- data_view(memory).setInt32(arg1 + 4, len0, true);
1924
- data_view(memory).setInt32(arg1 + 0, result0, true);
1925
- };
1926
- imports["rb-js-abi-host"]["reflect-prevent-extensions: func(target: handle<js-abi-value>) -> bool"] = function (arg0) {
1927
- const ret0 = obj.reflectPreventExtensions(resources0.get(arg0));
1928
- return ret0 ? 1 : 0;
1929
- };
1930
- imports["rb-js-abi-host"]["reflect-set: func(target: handle<js-abi-value>, property-key: string, value: handle<js-abi-value>) -> variant { success(handle<js-abi-value>), failure(handle<js-abi-value>) }"] = function (arg0, arg1, arg2, arg3, arg4) {
1931
- const memory = get_export("memory");
1932
- const ptr0 = arg1;
1933
- const len0 = arg2;
1934
- const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1935
- const ret0 = obj.reflectSet(resources0.get(arg0), result0, resources0.get(arg3));
1936
- const variant1 = ret0;
1937
- switch (variant1.tag) {
1938
- case "success": {
1939
- const e = variant1.val;
1940
- data_view(memory).setInt8(arg4 + 0, 0, true);
1941
- data_view(memory).setInt32(arg4 + 4, resources0.insert(e), true);
1942
- break;
1943
- }
1944
- case "failure": {
1945
- const e = variant1.val;
1946
- data_view(memory).setInt8(arg4 + 0, 1, true);
1947
- data_view(memory).setInt32(arg4 + 4, resources0.insert(e), true);
1948
- break;
1949
- }
1950
- default:
1951
- throw new RangeError("invalid variant specified for JsAbiResult");
1952
- }
1953
- };
1954
- imports["rb-js-abi-host"]["reflect-set-prototype-of: func(target: handle<js-abi-value>, prototype: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
1955
- const ret0 = obj.reflectSetPrototypeOf(resources0.get(arg0), resources0.get(arg1));
1956
- return ret0 ? 1 : 0;
1957
- };
1958
- if (!("canonical_abi" in imports))
1959
- imports["canonical_abi"] = {};
1960
- const resources0 = new Slab();
1961
- imports.canonical_abi["resource_drop_js-abi-value"] = (i) => {
1962
- const val = resources0.remove(i);
1963
- if (obj.dropJsAbiValue)
1964
- obj.dropJsAbiValue(val);
1965
- };
1966
- }
1967
-
1968
- class LegacyBinding extends RbAbiGuest {
1969
- async setInstance(instance) {
1970
- await this.instantiate(instance);
1971
- }
1972
- }
1973
- class ComponentBinding {
1974
- constructor() { }
1975
- setUnderlying(underlying) {
1976
- this.underlying = underlying;
1977
- }
1978
- rubyShowVersion() {
1979
- this.underlying.rubyShowVersion();
1980
- }
1981
- rubyInit(args) {
1982
- this.underlying.rubyInit(args);
1983
- }
1984
- rubyInitLoadpath() {
1985
- this.underlying.rubyInitLoadpath();
1986
- }
1987
- rbEvalStringProtect(str) {
1988
- return this.underlying.rbEvalStringProtect(str);
1989
- }
1990
- rbFuncallvProtect(recv, mid, args) {
1991
- return this.underlying.rbFuncallvProtect(recv, mid, args);
1992
- }
1993
- rbIntern(name) {
1994
- return this.underlying.rbIntern(name);
1995
- }
1996
- rbErrinfo() {
1997
- return this.underlying.rbErrinfo();
1998
- }
1999
- rbClearErrinfo() {
2000
- return this.underlying.rbClearErrinfo();
2001
- }
2002
- rstringPtr(value) {
2003
- return this.underlying.rstringPtr(value);
2004
- }
2005
- rbVmBugreport() {
2006
- this.underlying.rbVmBugreport();
2007
- }
2008
- rbGcEnable() {
2009
- return this.underlying.rbGcEnable();
2010
- }
2011
- rbGcDisable() {
2012
- return this.underlying.rbGcDisable();
2013
- }
2014
- rbSetShouldProhibitRewind(newValue) {
2015
- return this.underlying.rbSetShouldProhibitRewind(newValue);
2016
- }
2017
- async setInstance(instance) {
2018
- // No-op
2019
- }
2020
- addToImports(imports) {
2021
- // No-op
2022
- }
2023
- }
2024
-
2025
- /**
2026
- * A Ruby VM instance
2027
- * @see {@link RubyVM.instantiateComponent} and {@link RubyVM.instantiateModule} to create a new instance
2028
- * @category Essentials
2029
- */
2030
- class RubyVM {
2031
- /**
2032
- * Instantiate a Ruby VM with the given WebAssembly Core module with WASI Preview 1 implementation.
2033
- *
2034
- * @param options The options to instantiate the Ruby VM
2035
- * @returns A promise that resolves to the Ruby VM instance and the WebAssembly instance
2036
- * @category Essentials
2037
- *
2038
- * @example
2039
- *
2040
- * import { WASI } from "@bjorn3/browser_wasi_shim";
2041
- * const wasip1 = new WASI([], [], []);
2042
- * const module = await WebAssembly.compile("./path/to/ruby.wasm");
2043
- * const { vm } = await RubyVM.instantiateModule({ module, wasip1 });
2044
- *
2045
- */
2046
- static async instantiateModule(options) {
2047
- var _a, _b;
2048
- const { module, wasip1 } = options;
2049
- const vm = new RubyVM();
2050
- const imports = {
2051
- wasi_snapshot_preview1: wasip1.wasiImport,
2052
- };
2053
- vm.addToImports(imports);
2054
- (_a = options.addToImports) === null || _a === void 0 ? void 0 : _a.call(options, imports);
2055
- const instance = await WebAssembly.instantiate(module, imports);
2056
- await vm.setInstance(instance);
2057
- (_b = options.setMemory) === null || _b === void 0 ? void 0 : _b.call(options, instance.exports.memory);
2058
- wasip1.initialize(instance);
2059
- vm.initialize(options.args);
2060
- return { vm, instance };
2061
- }
2062
- /**
2063
- * Instantiate a Ruby VM with the given WebAssembly component with WASI Preview 2 implementation.
2064
- *
2065
- * @param options The options to instantiate the Ruby VM
2066
- * @returns A promise that resolves to the Ruby VM instance
2067
- * @category Essentials
2068
- *
2069
- * @example
2070
- *
2071
- * // First, you need to transpile the Ruby component to a JavaScript module using jco.
2072
- * // $ jco transpile --no-wasi-shim --instantiation --valid-lifting-optimization ./ruby.component.wasm -o ./component
2073
- * // Then, you can instantiate the Ruby VM with the component:
2074
- *
2075
- * import * as wasip2 from "@bytecodealliance/preview2-shim"
2076
- * import fs from "fs/promises";
2077
- * import path from "path";
2078
- *
2079
- * const { instantiate } = await import("./component/ruby.component.js");
2080
- * const getCoreModule = async (relativePath) => {
2081
- * const buffer = await fs.readFile(path.join("./component", relativePath));
2082
- * return WebAssembly.compile(buffer);
2083
- * }
2084
- *
2085
- * const { vm } = await RubyVM.instantiateComponent({
2086
- * instantiate, getCoreModule, wasip2,
2087
- * });
2088
- *
2089
- */
2090
- static async instantiateComponent(options) {
2091
- let initComponent;
2092
- if ("getCoreModule" in options) {
2093
- // A convenience overload to instantiate with "instantiate" function generated by jco
2094
- initComponent = async (jsRuntime) => {
2095
- const { instantiate, getCoreModule, wasip2 } = options;
2096
- const { cli, clocks, filesystem, io, random, sockets, http } = wasip2;
2097
- const importObject = {
2098
- "ruby:js/js-runtime": jsRuntime,
2099
- "wasi:cli/environment": cli.environment,
2100
- "wasi:cli/exit": cli.exit,
2101
- "wasi:cli/stderr": cli.stderr,
2102
- "wasi:cli/stdin": cli.stdin,
2103
- "wasi:cli/stdout": cli.stdout,
2104
- "wasi:cli/terminal-input": cli.terminalInput,
2105
- "wasi:cli/terminal-output": cli.terminalOutput,
2106
- "wasi:cli/terminal-stderr": cli.terminalStderr,
2107
- "wasi:cli/terminal-stdin": cli.terminalStdin,
2108
- "wasi:cli/terminal-stdout": cli.terminalStdout,
2109
- "wasi:clocks/monotonic-clock": clocks.monotonicClock,
2110
- "wasi:clocks/wall-clock": clocks.wallClock,
2111
- "wasi:filesystem/preopens": filesystem.preopens,
2112
- "wasi:filesystem/types": filesystem.types,
2113
- "wasi:io/error": io.error,
2114
- "wasi:io/poll": io.poll,
2115
- "wasi:io/streams": io.streams,
2116
- "wasi:random/random": random.random,
2117
- "wasi:sockets/tcp": sockets.tcp,
2118
- "wasi:http/types": http.types,
2119
- "wasi:http/incoming-handler": http.incomingHandler,
2120
- "wasi:http/outgoing-handler": http.outgoingHandler,
2121
- };
2122
- const component = await instantiate(getCoreModule, importObject, options.instantiateCore);
2123
- return component.rubyRuntime;
2124
- };
2125
- }
2126
- else {
2127
- initComponent = options.instantiate;
2128
- }
2129
- const vm = await this._instantiate({}, initComponent);
2130
- return { vm };
2131
- }
2132
- constructor(binding) {
2133
- this.instance = null;
2134
- this.interfaceState = {
2135
- hasJSFrameAfterRbFrame: false,
2136
- };
2137
- // Wrap exported functions from Ruby VM to prohibit nested VM operation
2138
- // if the call stack has sandwitched JS frames like JS -> Ruby -> JS -> Ruby.
2139
- const proxyExports = (exports) => {
2140
- const excludedMethods = [
2141
- "setInstance",
2142
- "addToImports",
2143
- "instantiate",
2144
- "rbSetShouldProhibitRewind",
2145
- "rbGcDisable",
2146
- "rbGcEnable",
2147
- ];
2148
- const excluded = ["constructor"].concat(excludedMethods);
2149
- // wrap all methods in RbAbi.RbAbiGuest class
2150
- for (const key of Object.getOwnPropertyNames(RbAbiGuest.prototype)) {
2151
- if (excluded.includes(key)) {
2152
- continue;
2153
- }
2154
- const value = exports[key];
2155
- if (typeof value === "function") {
2156
- exports[key] = (...args) => {
2157
- const isNestedVMCall = this.interfaceState.hasJSFrameAfterRbFrame;
2158
- if (isNestedVMCall) {
2159
- const oldShouldProhibitRewind = this.guest.rbSetShouldProhibitRewind(true);
2160
- const oldIsDisabledGc = this.guest.rbGcDisable();
2161
- const result = Reflect.apply(value, exports, args);
2162
- this.guest.rbSetShouldProhibitRewind(oldShouldProhibitRewind);
2163
- if (!oldIsDisabledGc) {
2164
- this.guest.rbGcEnable();
2165
- }
2166
- return result;
2167
- }
2168
- else {
2169
- return Reflect.apply(value, exports, args);
2170
- }
2171
- };
2172
- }
2173
- }
2174
- return exports;
2175
- };
2176
- this.guest = proxyExports(binding !== null && binding !== void 0 ? binding : new LegacyBinding());
2177
- this.transport = new JsValueTransport();
2178
- this.exceptionFormatter = new RbExceptionFormatter();
2179
- }
2180
- static async _instantiate(options, initComponent) {
2181
- const binding = new ComponentBinding();
2182
- const vm = new RubyVM(binding);
2183
- class JsAbiValue {
2184
- constructor(underlying) {
2185
- this.underlying = underlying;
2186
- }
2187
- }
2188
- const imports = vm.getImports((from) => new JsAbiValue(from), (to) => to.underlying);
2189
- const component = await initComponent(Object.assign(Object.assign({}, imports), { throwProhibitRewindException: (message) => {
2190
- vm.throwProhibitRewindException(message);
2191
- }, procToJsFunction: () => {
2192
- const rbValue = new RbValue(component.exportRbValueToJs(), vm, vm.privateObject());
2193
- return new JsAbiValue((...args) => {
2194
- return rbValue.call("call", ...args.map((arg) => vm.wrap(arg))).toJS();
2195
- });
2196
- }, rbObjectToJsRbValue: () => {
2197
- const rbValue = new RbValue(component.exportRbValueToJs(), vm, vm.privateObject());
2198
- return new JsAbiValue(rbValue);
2199
- }, JsAbiValue: JsAbiValue }));
2200
- binding.setUnderlying(component);
2201
- vm.initialize(options.args);
2202
- return vm;
2203
- }
2204
- /**
2205
- * Initialize the Ruby VM with the given command line arguments
2206
- * @param args The command line arguments to pass to Ruby. Must be
2207
- * an array of strings starting with the Ruby program name.
2208
- * @category Low-level initialization
2209
- */
2210
- initialize(args = ["ruby.wasm", "-EUTF-8", "-e_=0"]) {
2211
- const c_args = args.map((arg) => arg + "\0");
2212
- this.guest.rubyInit(c_args);
2213
- try {
2214
- this.eval(`
2215
- # Require Bundler standalone setup
2216
- if File.exist?("/bundle/bundler/setup.rb")
2217
- require "/bundle/bundler/setup.rb"
2218
- elsif File.exist?("/bundle/setup.rb")
2219
- # For non-CM builds, which doesn't use Bundler's standalone mode
2220
- require "/bundle/setup.rb"
2221
- end
2222
- `);
2223
- }
2224
- catch (e) {
2225
- console.warn("Failed to load /bundle/setup", e);
2226
- }
2227
- }
2228
- /**
2229
- * Set a given instance to interact JavaScript and Ruby's
2230
- * WebAssembly instance. This method must be called before calling
2231
- * Ruby API.
2232
- *
2233
- * @param instance The WebAssembly instance to interact with. Must
2234
- * be instantiated from a Ruby built with JS extension, and built
2235
- * with Reactor ABI instead of command line.
2236
- * @category Low-level initialization
2237
- */
2238
- async setInstance(instance) {
2239
- this.instance = instance;
2240
- await this.guest.setInstance(instance);
2241
- }
2242
- /**
2243
- * Add intrinsic import entries, which is necessary to interact JavaScript
2244
- * and Ruby's WebAssembly instance.
2245
- * @param imports The import object to add to the WebAssembly instance
2246
- * @category Low-level initialization
2247
- */
2248
- addToImports(imports) {
2249
- this.guest.addToImports(imports);
2250
- imports["rb-js-abi-host"] = {
2251
- rb_wasm_throw_prohibit_rewind_exception: (messagePtr, messageLen) => {
2252
- const memory = this.instance.exports.memory;
2253
- const str = new TextDecoder().decode(new Uint8Array(memory.buffer, messagePtr, messageLen));
2254
- this.throwProhibitRewindException(str);
2255
- },
2256
- };
2257
- addRbJsAbiHostToImports(imports, this.getImports((value) => value, (value) => value), (name) => {
2258
- return this.instance.exports[name];
2259
- });
2260
- }
2261
- throwProhibitRewindException(str) {
2262
- let message = "Ruby APIs that may rewind the VM stack are prohibited under nested VM operation " +
2263
- `(${str})\n` +
2264
- "Nested VM operation means that the call stack has sandwitched JS frames like JS -> Ruby -> JS -> Ruby " +
2265
- "caused by something like `window.rubyVM.eval(\"JS.global[:rubyVM].eval('Fiber.yield')\")`\n" +
2266
- "\n" +
2267
- "Please check your call stack and make sure that you are **not** doing any of the following inside the nested Ruby frame:\n" +
2268
- " 1. Switching fibers (e.g. Fiber#resume, Fiber.yield, and Fiber#transfer)\n" +
2269
- " Note that `evalAsync` JS API switches fibers internally\n" +
2270
- " 2. Raising uncaught exceptions\n" +
2271
- " Please catch all exceptions inside the nested operation\n" +
2272
- " 3. Calling Continuation APIs\n";
2273
- const error = new RbValue(this.guest.rbErrinfo(), this, this.privateObject());
2274
- if (error.call("nil?").toString() === "false") {
2275
- message += "\n" + this.exceptionFormatter.format(error, this, this.privateObject());
2276
- }
2277
- throw new RbFatalError(message);
2278
- }
2279
- getImports(toJSAbiValue, fromJSAbiValue) {
2280
- // NOTE: The GC may collect objects that are still referenced by Wasm
2281
- // locals because Asyncify cannot scan the Wasm stack above the JS frame.
2282
- // So we need to keep track whether the JS frame is sandwitched by Ruby
2283
- // frames or not, and prohibit nested VM operation if it is.
2284
- const proxyImports = (imports) => {
2285
- for (const [key, value] of Object.entries(imports)) {
2286
- if (typeof value === "function") {
2287
- imports[key] = (...args) => {
2288
- const oldValue = this.interfaceState.hasJSFrameAfterRbFrame;
2289
- this.interfaceState.hasJSFrameAfterRbFrame = true;
2290
- const result = Reflect.apply(value, imports, args);
2291
- this.interfaceState.hasJSFrameAfterRbFrame = oldValue;
2292
- return result;
2293
- };
2294
- }
2295
- }
2296
- return imports;
2297
- };
2298
- function wrapTry(f) {
2299
- return (...args) => {
2300
- try {
2301
- return { tag: "success", val: f(...args) };
2302
- }
2303
- catch (e) {
2304
- if (e instanceof RbFatalError) {
2305
- // RbFatalError should not be caught by Ruby because it Ruby VM
2306
- // can be already in an inconsistent state.
2307
- throw e;
2308
- }
2309
- return { tag: "failure", val: toJSAbiValue(e) };
2310
- }
2311
- };
2312
- }
2313
- return proxyImports({
2314
- evalJs: wrapTry((code) => {
2315
- return toJSAbiValue(Function(code)());
2316
- }),
2317
- isJs: (value) => {
2318
- // Just for compatibility with the old JS API
2319
- return true;
2320
- },
2321
- globalThis: () => {
2322
- if (typeof globalThis !== "undefined") {
2323
- return toJSAbiValue(globalThis);
2324
- }
2325
- else if (typeof global !== "undefined") {
2326
- return toJSAbiValue(global);
2327
- }
2328
- else if (typeof window !== "undefined") {
2329
- return toJSAbiValue(window);
2330
- }
2331
- throw new Error("unable to locate global object");
2332
- },
2333
- intToJsNumber: (value) => {
2334
- return toJSAbiValue(value);
2335
- },
2336
- floatToJsNumber: (value) => {
2337
- return toJSAbiValue(value);
2338
- },
2339
- stringToJsString: (value) => {
2340
- return toJSAbiValue(value);
2341
- },
2342
- boolToJsBool: (value) => {
2343
- return toJSAbiValue(value);
2344
- },
2345
- procToJsFunction: (rawRbAbiValue) => {
2346
- const rbValue = this.rbValueOfPointer(rawRbAbiValue);
2347
- return toJSAbiValue((...args) => {
2348
- return rbValue.call("call", ...args.map((arg) => this.wrap(arg))).toJS();
2349
- });
2350
- },
2351
- rbObjectToJsRbValue: (rawRbAbiValue) => {
2352
- return toJSAbiValue(this.rbValueOfPointer(rawRbAbiValue));
2353
- },
2354
- jsValueToString: (value) => {
2355
- value = fromJSAbiValue(value);
2356
- // According to the [spec](https://tc39.es/ecma262/multipage/text-processing.html#sec-string-constructor-string-value)
2357
- // `String(value)` always returns a string.
2358
- return String(value);
2359
- },
2360
- jsValueToInteger(value) {
2361
- value = fromJSAbiValue(value);
2362
- if (typeof value === "number") {
2363
- return { tag: "as-float", val: value };
2364
- }
2365
- else if (typeof value === "bigint") {
2366
- return { tag: "bignum", val: BigInt(value).toString(10) + "\0" };
2367
- }
2368
- else if (typeof value === "string") {
2369
- return { tag: "bignum", val: value + "\0" };
2370
- }
2371
- else if (typeof value === "undefined") {
2372
- return { tag: "as-float", val: 0 };
2373
- }
2374
- else {
2375
- return { tag: "as-float", val: Number(value) };
2376
- }
2377
- },
2378
- exportJsValueToHost: (value) => {
2379
- // See `JsValueExporter` for the reason why we need to do this
2380
- this.transport.takeJsValue(fromJSAbiValue(value));
2381
- },
2382
- importJsValueFromHost: () => {
2383
- return toJSAbiValue(this.transport.consumeJsValue());
2384
- },
2385
- instanceOf: (value, klass) => {
2386
- klass = fromJSAbiValue(klass);
2387
- if (typeof klass === "function") {
2388
- return fromJSAbiValue(value) instanceof klass;
2389
- }
2390
- else {
2391
- return false;
2392
- }
2393
- },
2394
- jsValueTypeof(value) {
2395
- return typeof fromJSAbiValue(value);
2396
- },
2397
- jsValueEqual(lhs, rhs) {
2398
- return fromJSAbiValue(lhs) == fromJSAbiValue(rhs);
2399
- },
2400
- jsValueStrictlyEqual(lhs, rhs) {
2401
- return fromJSAbiValue(lhs) === fromJSAbiValue(rhs);
2402
- },
2403
- reflectApply: wrapTry((target, thisArgument, args) => {
2404
- const jsArgs = args.map((arg) => fromJSAbiValue(arg));
2405
- return toJSAbiValue(Reflect.apply(fromJSAbiValue(target), fromJSAbiValue(thisArgument), jsArgs));
2406
- }),
2407
- reflectConstruct: function (target, args) {
2408
- throw new Error("Function not implemented.");
2409
- },
2410
- reflectDeleteProperty: function (target, propertyKey) {
2411
- throw new Error("Function not implemented.");
2412
- },
2413
- reflectGet: wrapTry((target, propertyKey) => {
2414
- return toJSAbiValue(fromJSAbiValue(target)[propertyKey]);
2415
- }),
2416
- reflectGetOwnPropertyDescriptor: function (target, propertyKey) {
2417
- throw new Error("Function not implemented.");
2418
- },
2419
- reflectGetPrototypeOf: function (target) {
2420
- throw new Error("Function not implemented.");
2421
- },
2422
- reflectHas: function (target, propertyKey) {
2423
- throw new Error("Function not implemented.");
2424
- },
2425
- reflectIsExtensible: function (target) {
2426
- throw new Error("Function not implemented.");
2427
- },
2428
- reflectOwnKeys: function (target) {
2429
- throw new Error("Function not implemented.");
2430
- },
2431
- reflectPreventExtensions: function (target) {
2432
- throw new Error("Function not implemented.");
2433
- },
2434
- reflectSet: wrapTry((target, propertyKey, value) => {
2435
- return toJSAbiValue(Reflect.set(fromJSAbiValue(target), propertyKey, fromJSAbiValue(value)));
2436
- }),
2437
- reflectSetPrototypeOf: function (target, prototype) {
2438
- throw new Error("Function not implemented.");
2439
- },
2440
- });
2441
- }
2442
- /**
2443
- * Print the Ruby version to stdout
2444
- */
2445
- printVersion() {
2446
- this.guest.rubyShowVersion();
2447
- }
2448
- /**
2449
- * Runs a string of Ruby code from JavaScript
2450
- * @param code The Ruby code to run
2451
- * @returns the result of the last expression
2452
- * @category Essentials
2453
- *
2454
- * @example
2455
- * vm.eval("puts 'hello world'");
2456
- * const result = vm.eval("1 + 2");
2457
- * console.log(result.toString()); // 3
2458
- *
2459
- */
2460
- eval(code) {
2461
- return evalRbCode(this, this.privateObject(), code);
2462
- }
2463
- /**
2464
- * Runs a string of Ruby code with top-level `JS::Object#await`
2465
- * Returns a promise that resolves when execution completes.
2466
- * @param code The Ruby code to run
2467
- * @returns a promise that resolves to the result of the last expression
2468
- * @category Essentials
2469
- *
2470
- * @example
2471
- * const text = await vm.evalAsync(`
2472
- * require 'js'
2473
- * response = JS.global.fetch('https://example.com').await
2474
- * response.text.await
2475
- * `);
2476
- * console.log(text.toString()); // <html>...</html>
2477
- */
2478
- evalAsync(code) {
2479
- const JS = this.eval("require 'js'; JS");
2480
- return newRbPromise(this, this.privateObject(), (future) => {
2481
- JS.call("__eval_async_rb", this.wrap(code), future);
2482
- });
2483
- }
2484
- /**
2485
- * Wrap a JavaScript value into a Ruby JS::Object
2486
- * @param value The value to convert to RbValue
2487
- * @returns the RbValue object representing the given JS value
2488
- *
2489
- * @example
2490
- * const hash = vm.eval(`Hash.new`)
2491
- * hash.call("store", vm.eval(`"key1"`), vm.wrap(new Object()));
2492
- */
2493
- wrap(value) {
2494
- return this.transport.importJsValue(value, this);
2495
- }
2496
- /** @private */
2497
- privateObject() {
2498
- return {
2499
- transport: this.transport,
2500
- exceptionFormatter: this.exceptionFormatter,
2501
- };
2502
- }
2503
- /** @private */
2504
- rbValueOfPointer(pointer) {
2505
- const abiValue = new RbAbiValue(pointer, this.guest);
2506
- return new RbValue(abiValue, this, this.privateObject());
2507
- }
2508
- }
2509
- /**
2510
- * Export a JS value held by the Ruby VM to the JS environment.
2511
- * This is implemented in a dirty way since wit cannot reference resources
2512
- * defined in other interfaces.
2513
- * In our case, we can't express `function(v: rb-abi-value) -> js-abi-value`
2514
- * because `rb-js-abi-host.wit`, that defines `js-abi-value`, is implemented
2515
- * by embedder side (JS) but `rb-abi-guest.wit`, that defines `rb-abi-value`
2516
- * is implemented by guest side (Wasm).
2517
- *
2518
- * This class is a helper to export by:
2519
- * 1. Call `function __export_to_js(v: rb-abi-value)` defined in guest from embedder side.
2520
- * 2. Call `function takeJsValue(v: js-abi-value)` defined in embedder from guest side with
2521
- * underlying JS value of given `rb-abi-value`.
2522
- * 3. Then `takeJsValue` implementation escapes the given JS value to the `_takenJsValues`
2523
- * stored in embedder side.
2524
- * 4. Finally, embedder side can take `_takenJsValues`.
2525
- *
2526
- * Note that `exportJsValue` is not reentrant.
2527
- *
2528
- * @private
2529
- */
2530
- class JsValueTransport {
2531
- constructor() {
2532
- this._takenJsValue = null;
2533
- }
2534
- takeJsValue(value) {
2535
- this._takenJsValue = value;
2536
- }
2537
- consumeJsValue() {
2538
- return this._takenJsValue;
2539
- }
2540
- exportJsValue(value) {
2541
- value.call("__export_to_js");
2542
- return this._takenJsValue;
2543
- }
2544
- importJsValue(value, vm) {
2545
- this._takenJsValue = value;
2546
- return vm.eval('require "js"; JS::Object').call("__import_from_js");
2547
- }
2548
- }
2549
- /**
2550
- * A RbValue is an object that represents a value in Ruby
2551
- * @category Essentials
2552
- */
2553
- class RbValue {
2554
- /**
2555
- * @hideconstructor
2556
- */
2557
- constructor(inner, vm, privateObject) {
2558
- this.inner = inner;
2559
- this.vm = vm;
2560
- this.privateObject = privateObject;
2561
- }
2562
- /**
2563
- * Call a given method with given arguments
2564
- *
2565
- * @param callee name of the Ruby method to call
2566
- * @param args arguments to pass to the method. Must be an array of RbValue
2567
- * @returns The result of the method call as a new RbValue.
2568
- *
2569
- * @example
2570
- * const ary = vm.eval("[1, 2, 3]");
2571
- * ary.call("push", 4);
2572
- * console.log(ary.call("sample").toString());
2573
- */
2574
- call(callee, ...args) {
2575
- const innerArgs = args.map((arg) => arg.inner);
2576
- return new RbValue(callRbMethod(this.vm, this.privateObject, this.inner, callee, innerArgs), this.vm, this.privateObject);
2577
- }
2578
- /**
2579
- * Call a given method that may call `JS::Object#await` with given arguments
2580
- *
2581
- * @param callee name of the Ruby method to call
2582
- * @param args arguments to pass to the method. Must be an array of RbValue
2583
- * @returns A Promise that resolves to the result of the method call as a new RbValue.
2584
- *
2585
- * @example
2586
- * const client = vm.eval(`
2587
- * require 'js'
2588
- * class HttpClient
2589
- * def get(url)
2590
- * JS.global.fetch(url).await
2591
- * end
2592
- * end
2593
- * HttpClient.new
2594
- * `);
2595
- * const response = await client.callAsync("get", vm.eval(`"https://example.com"`));
2596
- */
2597
- callAsync(callee, ...args) {
2598
- const JS = this.vm.eval("require 'js'; JS");
2599
- return newRbPromise(this.vm, this.privateObject, (future) => {
2600
- JS.call("__call_async_method", this, this.vm.wrap(callee), future, ...args);
2601
- });
2602
- }
2603
- /**
2604
- * @see {@link https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive}
2605
- * @param hint Preferred type of the result primitive value. `"number"`, `"string"`, or `"default"`.
2606
- */
2607
- [Symbol.toPrimitive](hint) {
2608
- if (hint === "string" || hint === "default") {
2609
- return this.toString();
2610
- }
2611
- else if (hint === "number") {
2612
- return null;
2613
- }
2614
- return null;
2615
- }
2616
- /**
2617
- * Returns a string representation of the value by calling `to_s`
2618
- */
2619
- toString() {
2620
- const rbString = callRbMethod(this.vm, this.privateObject, this.inner, "to_s", []);
2621
- return this.vm.guest.rstringPtr(rbString);
2622
- }
2623
- /**
2624
- * Returns a JavaScript object representation of the value
2625
- * by calling `to_js`.
2626
- *
2627
- * Returns null if the value is not convertible to a JavaScript object.
2628
- */
2629
- toJS() {
2630
- const JS = this.vm.eval("JS");
2631
- const jsValue = JS.call("try_convert", this);
2632
- if (jsValue.call("nil?").toString() === "true") {
2633
- return null;
2634
- }
2635
- return this.privateObject.transport.exportJsValue(jsValue);
2636
- }
2637
- }
2638
- var ruby_tag_type;
2639
- (function (ruby_tag_type) {
2640
- ruby_tag_type[ruby_tag_type["None"] = 0] = "None";
2641
- ruby_tag_type[ruby_tag_type["Return"] = 1] = "Return";
2642
- ruby_tag_type[ruby_tag_type["Break"] = 2] = "Break";
2643
- ruby_tag_type[ruby_tag_type["Next"] = 3] = "Next";
2644
- ruby_tag_type[ruby_tag_type["Retry"] = 4] = "Retry";
2645
- ruby_tag_type[ruby_tag_type["Redo"] = 5] = "Redo";
2646
- ruby_tag_type[ruby_tag_type["Raise"] = 6] = "Raise";
2647
- ruby_tag_type[ruby_tag_type["Throw"] = 7] = "Throw";
2648
- ruby_tag_type[ruby_tag_type["Fatal"] = 8] = "Fatal";
2649
- ruby_tag_type[ruby_tag_type["Mask"] = 15] = "Mask";
2650
- })(ruby_tag_type || (ruby_tag_type = {}));
2651
- class RbExceptionFormatter {
2652
- constructor() {
2653
- this.literalsCache = null;
2654
- this.isFormmatting = false;
2655
- }
2656
- format(error, vm, privateObject) {
2657
- // All Ruby exceptions raised during formatting exception message should
2658
- // be caught and return a fallback message.
2659
- // Therefore, we don't need to worry about infinite recursion here ideally
2660
- // but checking re-entrancy just in case.
2661
- class RbExceptionFormatterError extends Error {
2662
- }
2663
- if (this.isFormmatting) {
2664
- throw new RbExceptionFormatterError("Unexpected exception occurred during formatting exception message");
2665
- }
2666
- this.isFormmatting = true;
2667
- try {
2668
- return this._format(error, vm, privateObject);
2669
- }
2670
- finally {
2671
- this.isFormmatting = false;
2672
- }
2673
- }
2674
- _format(error, vm, privateObject) {
2675
- const [zeroLiteral, oneLiteral, newLineLiteral] = (() => {
2676
- if (this.literalsCache == null) {
2677
- const zeroOneNewLine = [
2678
- evalRbCode(vm, privateObject, "0"),
2679
- evalRbCode(vm, privateObject, "1"),
2680
- evalRbCode(vm, privateObject, `"\n"`),
2681
- ];
2682
- this.literalsCache = zeroOneNewLine;
2683
- return zeroOneNewLine;
2684
- }
2685
- else {
2686
- return this.literalsCache;
2687
- }
2688
- })();
2689
- let className;
2690
- let backtrace;
2691
- let message;
2692
- try {
2693
- className = error.call("class").toString();
2694
- }
2695
- catch (e) {
2696
- className = "unknown";
2697
- }
2698
- try {
2699
- message = error.call("message").toString();
2700
- }
2701
- catch (e) {
2702
- message = "unknown";
2703
- }
2704
- try {
2705
- backtrace = error.call("backtrace");
2706
- }
2707
- catch (e) {
2708
- return this.formatString(className, message);
2709
- }
2710
- if (backtrace.call("nil?").toString() === "true") {
2711
- return this.formatString(className, message);
2712
- }
2713
- try {
2714
- const firstLine = backtrace.call("at", zeroLiteral);
2715
- const restLines = backtrace
2716
- .call("drop", oneLiteral)
2717
- .call("join", newLineLiteral);
2718
- return this.formatString(className, message, [
2719
- firstLine.toString(),
2720
- restLines.toString(),
2721
- ]);
2722
- }
2723
- catch (e) {
2724
- return this.formatString(className, message);
2725
- }
2726
- }
2727
- formatString(klass, message, backtrace) {
2728
- if (backtrace) {
2729
- return `${backtrace[0]}: ${message} (${klass})\n${backtrace[1]}`;
2730
- }
2731
- else {
2732
- return `${klass}: ${message}`;
2733
- }
2734
- }
2735
- }
2736
- const checkStatusTag = (rawTag, vm, privateObject) => {
2737
- switch (rawTag & ruby_tag_type.Mask) {
2738
- case ruby_tag_type.None:
2739
- break;
2740
- case ruby_tag_type.Return:
2741
- throw new RbError("unexpected return");
2742
- case ruby_tag_type.Next:
2743
- throw new RbError("unexpected next");
2744
- case ruby_tag_type.Break:
2745
- throw new RbError("unexpected break");
2746
- case ruby_tag_type.Redo:
2747
- throw new RbError("unexpected redo");
2748
- case ruby_tag_type.Retry:
2749
- throw new RbError("retry outside of rescue clause");
2750
- case ruby_tag_type.Throw:
2751
- throw new RbError("unexpected throw");
2752
- case ruby_tag_type.Raise:
2753
- case ruby_tag_type.Fatal:
2754
- const error = new RbValue(vm.guest.rbErrinfo(), vm, privateObject);
2755
- if (error.call("nil?").toString() === "true") {
2756
- throw new RbError("no exception object");
2757
- }
2758
- // clear errinfo if got exception due to no rb_jump_tag
2759
- vm.guest.rbClearErrinfo();
2760
- throw new RbError(privateObject.exceptionFormatter.format(error, vm, privateObject));
2761
- default:
2762
- throw new RbError(`unknown error tag: ${rawTag}`);
2763
- }
2764
- };
2765
- function wrapRbOperation(vm, body) {
2766
- try {
2767
- return body();
2768
- }
2769
- catch (e) {
2770
- if (e instanceof RbError) {
2771
- throw e;
2772
- }
2773
- // All JS exceptions triggered by Ruby code are translated to Ruby exceptions,
2774
- // so non-RbError exceptions are unexpected.
2775
- try {
2776
- vm.guest.rbVmBugreport();
2777
- }
2778
- catch (e) {
2779
- console.error("Tried to report internal Ruby VM state but failed: ", e);
2780
- }
2781
- if (e instanceof WebAssembly.RuntimeError && e.message === "unreachable") {
2782
- const error = new RbError(`Something went wrong in Ruby VM: ${e}`);
2783
- error.stack = e.stack;
2784
- throw error;
2785
- }
2786
- else {
2787
- throw e;
2788
- }
2789
- }
2790
- }
2791
- const callRbMethod = (vm, privateObject, recv, callee, args) => {
2792
- const mid = vm.guest.rbIntern(callee + "\0");
2793
- return wrapRbOperation(vm, () => {
2794
- const [value, status] = vm.guest.rbFuncallvProtect(recv, mid, args);
2795
- checkStatusTag(status, vm, privateObject);
2796
- return value;
2797
- });
2798
- };
2799
- const evalRbCode = (vm, privateObject, code) => {
2800
- return wrapRbOperation(vm, () => {
2801
- const [value, status] = vm.guest.rbEvalStringProtect(code + "\0");
2802
- checkStatusTag(status, vm, privateObject);
2803
- return new RbValue(value, vm, privateObject);
2804
- });
2805
- };
2806
- function newRbPromise(vm, privateObject, body) {
2807
- return new Promise((resolve, reject) => {
2808
- const future = vm.wrap({
2809
- resolve,
2810
- reject: (error) => {
2811
- const rbError = new RbError(privateObject.exceptionFormatter.format(error, vm, privateObject));
2812
- reject(rbError);
2813
- },
2814
- });
2815
- body(future);
2816
- });
2817
- }
2818
- /**
2819
- * Error class thrown by Ruby execution
2820
- */
2821
- class RbError extends Error {
2822
- /**
2823
- * @hideconstructor
2824
- */
2825
- constructor(message) {
2826
- super(message);
2827
- }
2828
- }
2829
- /**
2830
- * Error class thrown by Ruby execution when it is not possible to recover.
2831
- * This is usually caused when Ruby VM is in an inconsistent state.
2832
- */
2833
- class RbFatalError extends RbError {
2834
- /**
2835
- * @hideconstructor
2836
- */
2837
- constructor(message) {
2838
- super("Ruby Fatal Error: " + message);
2839
- }
2840
- }
2841
-
2842
- const DefaultRubyVM = async (rubyModule, options = {}) => {
2843
- var _a, _b;
2844
- const args = [];
2845
- const env = Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}).map(([k, v]) => `${k}=${v}`);
2846
- const fds = [
2847
- new OpenFile(new File([])),
2848
- new OpenFile(new File([])),
2849
- new OpenFile(new File([])),
2850
- new PreopenDirectory("/", new Map()),
2851
- ];
2852
- const wasi = new WASI(args, env, fds, { debug: false });
2853
- const printer = ((_b = options.consolePrint) !== null && _b !== void 0 ? _b : true) ? consolePrinter() : undefined;
2854
- const { vm, instance } = await RubyVM.instantiateModule({
2855
- module: rubyModule, wasip1: wasi,
2856
- addToImports: (imports) => {
2857
- printer === null || printer === void 0 ? void 0 : printer.addToImports(imports);
2858
- },
2859
- setMemory: (memory) => {
2860
- printer === null || printer === void 0 ? void 0 : printer.setMemory(memory);
2861
- }
2862
- });
2863
- return {
2864
- vm,
2865
- wasi,
2866
- instance,
2867
- };
2868
- };
2869
-
2870
- /**
2871
- * The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Core Module.
2872
- */
2873
- const main$1 = async (pkg, options) => {
2874
- const response = fetch(`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`);
2875
- const module = await compileWebAssemblyModule(response);
2876
- const { vm } = await DefaultRubyVM(module, options);
2877
- await mainWithRubyVM(vm);
2878
- };
2879
- const mainWithRubyVM = async (vm) => {
2880
- vm.printVersion();
2881
- globalThis.rubyVM = vm;
2882
- // Wait for the text/ruby script tag to be read.
2883
- // It may take some time to read ruby+stdlib.wasm
2884
- // and DOMContentLoaded has already been fired.
2885
- if (document.readyState === "loading") {
2886
- document.addEventListener("DOMContentLoaded", () => runRubyScriptsInHtml(vm));
2887
- }
2888
- else {
2889
- runRubyScriptsInHtml(vm);
2890
- }
2891
- };
2892
- const runRubyScriptsInHtml = async (vm) => {
2893
- var _a, e_1, _b, _c;
2894
- const tags = document.querySelectorAll('script[type="text/ruby"]');
2895
- // Get Ruby scripts in parallel.
2896
- const promisingRubyScripts = Array.from(tags).map((tag) => loadScriptAsync(tag));
2897
- try {
2898
- // Run Ruby scripts sequentially.
2899
- for (var _d = true, promisingRubyScripts_1 = __asyncValues(promisingRubyScripts), promisingRubyScripts_1_1; promisingRubyScripts_1_1 = await promisingRubyScripts_1.next(), _a = promisingRubyScripts_1_1.done, !_a; _d = true) {
2900
- _c = promisingRubyScripts_1_1.value;
2901
- _d = false;
2902
- const script = _c;
2903
- if (script) {
2904
- const { scriptContent, evalStyle } = script;
2905
- switch (evalStyle) {
2906
- case "async":
2907
- vm.evalAsync(scriptContent);
2908
- break;
2909
- case "sync":
2910
- vm.eval(scriptContent);
2911
- break;
2912
- }
2913
- }
2914
- }
2915
- }
2916
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
2917
- finally {
2918
- try {
2919
- if (!_d && !_a && (_b = promisingRubyScripts_1.return)) await _b.call(promisingRubyScripts_1);
2920
- }
2921
- finally { if (e_1) throw e_1.error; }
2922
- }
2923
- };
2924
- const deriveEvalStyle = (tag) => {
2925
- const rawEvalStyle = tag.getAttribute("data-eval") || "sync";
2926
- if (rawEvalStyle !== "async" && rawEvalStyle !== "sync") {
2927
- console.warn(`data-eval attribute of script tag must be "async" or "sync". ${rawEvalStyle} is ignored and "sync" is used instead.`);
2928
- return "sync";
2929
- }
2930
- return rawEvalStyle;
2931
- };
2932
- const loadScriptAsync = async (tag) => {
2933
- const evalStyle = deriveEvalStyle(tag);
2934
- // Inline comments can be written with the src attribute of the script tag.
2935
- // The presence of the src attribute is checked before the presence of the inline.
2936
- // see: https://html.spec.whatwg.org/multipage/scripting.html#inline-documentation-for-external-scripts
2937
- if (tag.hasAttribute("src")) {
2938
- const url = tag.getAttribute("src");
2939
- const response = await fetch(url);
2940
- if (response.ok) {
2941
- return { scriptContent: await response.text(), evalStyle };
2942
- }
2943
- return Promise.resolve(null);
2944
- }
2945
- return Promise.resolve({ scriptContent: tag.innerHTML, evalStyle });
2946
- };
2947
- // WebAssembly.compileStreaming is a relatively new API.
2948
- // For example, it is not available in iOS Safari 14,
2949
- // so check whether WebAssembly.compileStreaming is available and
2950
- // fall back to the existing implementation using WebAssembly.compile if not.
2951
- const compileWebAssemblyModule = async function (response) {
2952
- if (!WebAssembly.compileStreaming) {
2953
- const buffer = await (await response).arrayBuffer();
2954
- return WebAssembly.compile(buffer);
2955
- }
2956
- else {
2957
- return WebAssembly.compileStreaming(response);
2958
- }
2959
- };
2960
-
2961
- var name = "@ruby/3.4-wasm-wasi";
2962
- var version = "2.7.1";
2963
- var description = "Ruby 3.4 built on WASI";
2964
- var main = "./dist/cjs/index.js";
2965
- var module = "./dist/esm/index.js";
2966
- var exports$1 = {
2967
- ".": {
2968
- browser: "./dist/esm/index.js",
2969
- umd: "./dist/umd/index.js",
2970
- "import": "./dist/esm/index.js",
2971
- require: "./dist/cjs/index.js"
2972
- },
2973
- "./dist/*": {
2974
- browser: "./dist/esm/*.js",
2975
- umd: "./dist/umd/*.js",
2976
- "import": "./dist/esm/*.js",
2977
- require: "./dist/cjs/*.js"
2978
- },
2979
- "./*.wasm": {
2980
- browser: "./*.wasm",
2981
- umd: "./*.wasm",
2982
- "import": "./*.wasm",
2983
- require: "./*.wasm"
2984
- }
2985
- };
2986
- var files = [
2987
- "dist",
2988
- "README.md"
2989
- ];
2990
- var scripts = {
2991
- test: "RUBY_NPM_PACKAGE_ROOT=../ruby-3.4-wasm-wasi npm -C ../ruby-wasm-wasi run test:run",
2992
- "build:deps": "cd ../ruby-wasm-wasi && npm run build",
2993
- "build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
2994
- "build:static:compat": "../ruby-wasm-wasi/tools/pack-compat-shim.mjs --dist=./dist --pkg=ruby-3.4-wasm-wasi",
2995
- "build:static": "npm run build:static:files && npm run build:static:compat",
2996
- "build:rollup": "rollup -c rollup.config.mjs",
2997
- build: "npm run build:deps && npm run build:static && npm run build:rollup && ../ruby-wasm-wasi/tools/post-build.sh ./dist"
2998
- };
2999
- var repository = "https://github.com/ruby/ruby.wasm";
3000
- var homepage = "https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-3.4-wasm-wasi";
3001
- var publishConfig = {
3002
- access: "public"
3003
- };
3004
- var keywords = [
3005
- "wasm",
3006
- "webassembly",
3007
- "wasi",
3008
- "ruby"
3009
- ];
3010
- var license = "MIT";
3011
- var dependencies = {
3012
- "@ruby/wasm-wasi": "^2.0.0"
3013
- };
3014
- var _package = {
3015
- name: name,
3016
- version: version,
3017
- description: description,
3018
- main: main,
3019
- module: module,
3020
- exports: exports$1,
3021
- files: files,
3022
- scripts: scripts,
3023
- repository: repository,
3024
- homepage: homepage,
3025
- publishConfig: publishConfig,
3026
- keywords: keywords,
3027
- license: license,
3028
- dependencies: dependencies
3029
- };
3030
-
3031
- var pkg = /*#__PURE__*/Object.freeze({
3032
- __proto__: null,
3033
- default: _package,
3034
- dependencies: dependencies,
3035
- description: description,
3036
- exports: exports$1,
3037
- files: files,
3038
- homepage: homepage,
3039
- keywords: keywords,
3040
- license: license,
3041
- main: main,
3042
- module: module,
3043
- name: name,
3044
- publishConfig: publishConfig,
3045
- repository: repository,
3046
- scripts: scripts,
3047
- version: version
3048
- });
3049
-
3050
- main$1(pkg);
3051
-
3052
- })();