jsg 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3019 @@
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
+ Copyright (c) 2022 Yuta Saito. All rights reserved.
1268
+ Licensed under the MIT License
1269
+ ```
1270
+
1271
+ ---
1272
+
1273
+ ## MIT License
1274
+
1275
+ ```
1276
+ Permission is hereby granted, free of charge, to any person obtaining a copy
1277
+ of this software and associated documentation files (the "Software"), to deal
1278
+ in the Software without restriction, including without limitation the rights
1279
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1280
+ copies of the Software, and to permit persons to whom the Software is
1281
+ furnished to do so, subject to the following conditions:
1282
+
1283
+ The above copyright notice and this permission notice shall be included in all
1284
+ copies or substantial portions of the Software.
1285
+
1286
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1287
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1288
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1289
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1290
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1291
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1292
+ SOFTWARE.
1293
+ ```
1294
+ */
1295
+ (function () {
1296
+ 'use strict';
1297
+
1298
+ /******************************************************************************
1299
+ Copyright (c) Microsoft Corporation.
1300
+
1301
+ Permission to use, copy, modify, and/or distribute this software for any
1302
+ purpose with or without fee is hereby granted.
1303
+
1304
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1305
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1306
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1307
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1308
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1309
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1310
+ PERFORMANCE OF THIS SOFTWARE.
1311
+ ***************************************************************************** */
1312
+ /* global Reflect, Promise, SuppressedError, Symbol */
1313
+
1314
+
1315
+ function __values(o) {
1316
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1317
+ if (m) return m.call(o);
1318
+ if (o && typeof o.length === "number") return {
1319
+ next: function () {
1320
+ if (o && i >= o.length) o = void 0;
1321
+ return { value: o && o[i++], done: !o };
1322
+ }
1323
+ };
1324
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1325
+ }
1326
+
1327
+ function __asyncValues(o) {
1328
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
1329
+ var m = o[Symbol.asyncIterator], i;
1330
+ 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);
1331
+ 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); }); }; }
1332
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
1333
+ }
1334
+
1335
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1336
+ var e = new Error(message);
1337
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1338
+ };
1339
+
1340
+ 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);}}
1341
+
1342
+ 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);
1343
+
1344
+ 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"}};}};
1345
+
1346
+ 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{}
1347
+
1348
+ 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;}}}
1349
+
1350
+ /**
1351
+ * Create a console printer that can be used as an overlay of WASI imports.
1352
+ * See the example below for how to use it.
1353
+ *
1354
+ * ```javascript
1355
+ * const imports = {
1356
+ * "wasi_snapshot_preview1": wasi.wasiImport,
1357
+ * }
1358
+ * const printer = consolePrinter();
1359
+ * printer.addToImports(imports);
1360
+ *
1361
+ * const instance = await WebAssembly.instantiate(module, imports);
1362
+ * printer.setMemory(instance.exports.memory);
1363
+ * ```
1364
+ *
1365
+ * Note that the `stdout` and `stderr` functions are called with text, not
1366
+ * bytes. This means that bytes written to stdout/stderr will be decoded as
1367
+ * UTF-8 and then passed to the `stdout`/`stderr` functions every time a write
1368
+ * occurs without buffering.
1369
+ *
1370
+ * @param stdout A function that will be called when stdout is written to.
1371
+ * Defaults to `console.log`.
1372
+ * @param stderr A function that will be called when stderr is written to.
1373
+ * Defaults to `console.warn`.
1374
+ * @returns An object that can be used as an overlay of WASI imports.
1375
+ */
1376
+ function consolePrinter({ stdout, stderr, } = {
1377
+ stdout: console.log,
1378
+ stderr: console.warn,
1379
+ }) {
1380
+ let memory = undefined;
1381
+ let _view = undefined;
1382
+ function getMemoryView() {
1383
+ if (typeof memory === "undefined") {
1384
+ throw new Error("Memory is not set");
1385
+ }
1386
+ if (_view === undefined || _view.buffer.byteLength === 0) {
1387
+ _view = new DataView(memory.buffer);
1388
+ }
1389
+ return _view;
1390
+ }
1391
+ const decoder = new TextDecoder();
1392
+ return {
1393
+ addToImports(imports) {
1394
+ const wasiImport = imports.wasi_snapshot_preview1;
1395
+ const original_fd_write = wasiImport.fd_write;
1396
+ wasiImport.fd_write = (fd, iovs, iovsLen, nwritten) => {
1397
+ if (fd !== 1 && fd !== 2) {
1398
+ return original_fd_write(fd, iovs, iovsLen, nwritten);
1399
+ }
1400
+ const view = getMemoryView();
1401
+ const buffers = Array.from({ length: iovsLen }, (_, i) => {
1402
+ const ptr = iovs + i * 8;
1403
+ const buf = view.getUint32(ptr, true);
1404
+ const bufLen = view.getUint32(ptr + 4, true);
1405
+ return new Uint8Array(memory.buffer, buf, bufLen);
1406
+ });
1407
+ let written = 0;
1408
+ let str = "";
1409
+ for (const buffer of buffers) {
1410
+ str += decoder.decode(buffer);
1411
+ written += buffer.byteLength;
1412
+ }
1413
+ view.setUint32(nwritten, written, true);
1414
+ const log = fd === 1 ? stdout : stderr;
1415
+ log(str);
1416
+ return 0;
1417
+ };
1418
+ const original_fd_filestat_get = wasiImport.fd_filestat_get;
1419
+ wasiImport.fd_filestat_get = (fd, filestat) => {
1420
+ if (fd !== 1 && fd !== 2) {
1421
+ return original_fd_filestat_get(fd, filestat);
1422
+ }
1423
+ const view = getMemoryView();
1424
+ const result = original_fd_filestat_get(fd, filestat);
1425
+ if (result !== 0) {
1426
+ return result;
1427
+ }
1428
+ const filetypePtr = filestat + 0;
1429
+ view.setUint8(filetypePtr, 2); // FILETYPE_CHARACTER_DEVICE
1430
+ return 0;
1431
+ };
1432
+ const original_fd_fdstat_get = wasiImport.fd_fdstat_get;
1433
+ wasiImport.fd_fdstat_get = (fd, fdstat) => {
1434
+ if (fd !== 1 && fd !== 2) {
1435
+ return original_fd_fdstat_get(fd, fdstat);
1436
+ }
1437
+ const view = getMemoryView();
1438
+ const fs_filetypePtr = fdstat + 0;
1439
+ view.setUint8(fs_filetypePtr, 2); // FILETYPE_CHARACTER_DEVICE
1440
+ const fs_rights_basePtr = fdstat + 8;
1441
+ view.setBigUint64(fs_rights_basePtr, BigInt(1)); // RIGHTS_FD_WRITE
1442
+ return 0;
1443
+ };
1444
+ },
1445
+ setMemory(m) {
1446
+ memory = m;
1447
+ },
1448
+ };
1449
+ }
1450
+
1451
+ let DATA_VIEW = new DataView(new ArrayBuffer());
1452
+ function data_view(mem) {
1453
+ if (DATA_VIEW.buffer !== mem.buffer)
1454
+ DATA_VIEW = new DataView(mem.buffer);
1455
+ return DATA_VIEW;
1456
+ }
1457
+ function to_uint32(val) {
1458
+ return val >>> 0;
1459
+ }
1460
+ const UTF8_DECODER = new TextDecoder('utf-8');
1461
+ const UTF8_ENCODER = new TextEncoder('utf-8');
1462
+ function utf8_encode(s, realloc, memory) {
1463
+ if (typeof s !== 'string')
1464
+ throw new TypeError('expected a string');
1465
+ if (s.length === 0) {
1466
+ UTF8_ENCODED_LEN = 0;
1467
+ return 1;
1468
+ }
1469
+ let alloc_len = 0;
1470
+ let ptr = 0;
1471
+ let writtenTotal = 0;
1472
+ while (s.length > 0) {
1473
+ ptr = realloc(ptr, alloc_len, 1, alloc_len + s.length);
1474
+ alloc_len += s.length;
1475
+ const { read, written } = UTF8_ENCODER.encodeInto(s, new Uint8Array(memory.buffer, ptr + writtenTotal, alloc_len - writtenTotal));
1476
+ writtenTotal += written;
1477
+ s = s.slice(read);
1478
+ }
1479
+ if (alloc_len > writtenTotal)
1480
+ ptr = realloc(ptr, alloc_len, 1, writtenTotal);
1481
+ UTF8_ENCODED_LEN = writtenTotal;
1482
+ return ptr;
1483
+ }
1484
+ let UTF8_ENCODED_LEN = 0;
1485
+ class Slab {
1486
+ constructor() {
1487
+ this.list = [];
1488
+ this.head = 0;
1489
+ }
1490
+ insert(val) {
1491
+ if (this.head >= this.list.length) {
1492
+ this.list.push({
1493
+ next: this.list.length + 1,
1494
+ val: undefined,
1495
+ });
1496
+ }
1497
+ const ret = this.head;
1498
+ const slot = this.list[ret];
1499
+ this.head = slot.next;
1500
+ slot.next = -1;
1501
+ slot.val = val;
1502
+ return ret;
1503
+ }
1504
+ get(idx) {
1505
+ if (idx >= this.list.length)
1506
+ throw new RangeError('handle index not valid');
1507
+ const slot = this.list[idx];
1508
+ if (slot.next === -1)
1509
+ return slot.val;
1510
+ throw new RangeError('handle index not valid');
1511
+ }
1512
+ remove(idx) {
1513
+ const ret = this.get(idx); // validate the slot
1514
+ const slot = this.list[idx];
1515
+ slot.val = undefined;
1516
+ slot.next = this.head;
1517
+ this.head = idx;
1518
+ return ret;
1519
+ }
1520
+ }
1521
+ function throw_invalid_bool() {
1522
+ throw new RangeError("invalid variant discriminant for bool");
1523
+ }
1524
+
1525
+ class RbAbiGuest {
1526
+ constructor() {
1527
+ this._resource0_slab = new Slab();
1528
+ this._resource1_slab = new Slab();
1529
+ }
1530
+ addToImports(imports) {
1531
+ if (!("canonical_abi" in imports))
1532
+ imports["canonical_abi"] = {};
1533
+ imports.canonical_abi['resource_drop_rb-iseq'] = i => {
1534
+ this._resource0_slab.remove(i).drop();
1535
+ };
1536
+ imports.canonical_abi['resource_clone_rb-iseq'] = 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-iseq'] = i => {
1541
+ return this._resource0_slab.get(i)._wasm_val;
1542
+ };
1543
+ imports.canonical_abi['resource_new_rb-iseq'] = i => {
1544
+ this._registry0;
1545
+ return this._resource0_slab.insert(new RbIseq(i, this));
1546
+ };
1547
+ imports.canonical_abi['resource_drop_rb-abi-value'] = i => {
1548
+ this._resource1_slab.remove(i).drop();
1549
+ };
1550
+ imports.canonical_abi['resource_clone_rb-abi-value'] = i => {
1551
+ const obj = this._resource1_slab.get(i);
1552
+ return this._resource1_slab.insert(obj.clone());
1553
+ };
1554
+ imports.canonical_abi['resource_get_rb-abi-value'] = i => {
1555
+ return this._resource1_slab.get(i)._wasm_val;
1556
+ };
1557
+ imports.canonical_abi['resource_new_rb-abi-value'] = i => {
1558
+ this._registry1;
1559
+ return this._resource1_slab.insert(new RbAbiValue(i, this));
1560
+ };
1561
+ }
1562
+ async instantiate(module, imports) {
1563
+ imports = imports || {};
1564
+ this.addToImports(imports);
1565
+ if (module instanceof WebAssembly.Instance) {
1566
+ this.instance = module;
1567
+ }
1568
+ else if (module instanceof WebAssembly.Module) {
1569
+ this.instance = await WebAssembly.instantiate(module, imports);
1570
+ }
1571
+ else if (module instanceof ArrayBuffer || module instanceof Uint8Array) {
1572
+ const { instance } = await WebAssembly.instantiate(module, imports);
1573
+ this.instance = instance;
1574
+ }
1575
+ else {
1576
+ const { instance } = await WebAssembly.instantiateStreaming(module, imports);
1577
+ this.instance = instance;
1578
+ }
1579
+ this._exports = this.instance.exports;
1580
+ this._registry0 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-iseq']);
1581
+ this._registry1 = new FinalizationRegistry(this._exports['canonical_abi_drop_rb-abi-value']);
1582
+ }
1583
+ rubyShowVersion() {
1584
+ this._exports['ruby-show-version: func() -> ()']();
1585
+ }
1586
+ rubyInit() {
1587
+ this._exports['ruby-init: func() -> ()']();
1588
+ }
1589
+ rubySysinit(arg0) {
1590
+ const memory = this._exports.memory;
1591
+ const realloc = this._exports["cabi_realloc"];
1592
+ const vec1 = arg0;
1593
+ const len1 = vec1.length;
1594
+ const result1 = realloc(0, 0, 4, len1 * 8);
1595
+ for (let i = 0; i < vec1.length; i++) {
1596
+ const e = vec1[i];
1597
+ const base = result1 + i * 8;
1598
+ const ptr0 = utf8_encode(e, realloc, memory);
1599
+ const len0 = UTF8_ENCODED_LEN;
1600
+ data_view(memory).setInt32(base + 4, len0, true);
1601
+ data_view(memory).setInt32(base + 0, ptr0, true);
1602
+ }
1603
+ this._exports['ruby-sysinit: func(args: list<string>) -> ()'](result1, len1);
1604
+ }
1605
+ rubyOptions(arg0) {
1606
+ const memory = this._exports.memory;
1607
+ const realloc = this._exports["cabi_realloc"];
1608
+ const vec1 = arg0;
1609
+ const len1 = vec1.length;
1610
+ const result1 = realloc(0, 0, 4, len1 * 8);
1611
+ for (let i = 0; i < vec1.length; i++) {
1612
+ const e = vec1[i];
1613
+ const base = result1 + i * 8;
1614
+ const ptr0 = utf8_encode(e, realloc, memory);
1615
+ const len0 = UTF8_ENCODED_LEN;
1616
+ data_view(memory).setInt32(base + 4, len0, true);
1617
+ data_view(memory).setInt32(base + 0, ptr0, true);
1618
+ }
1619
+ const ret = this._exports['ruby-options: func(args: list<string>) -> handle<rb-iseq>'](result1, len1);
1620
+ return this._resource0_slab.remove(ret);
1621
+ }
1622
+ rubyScript(arg0) {
1623
+ const memory = this._exports.memory;
1624
+ const realloc = this._exports["cabi_realloc"];
1625
+ const ptr0 = utf8_encode(arg0, realloc, memory);
1626
+ const len0 = UTF8_ENCODED_LEN;
1627
+ this._exports['ruby-script: func(name: string) -> ()'](ptr0, len0);
1628
+ }
1629
+ rubyInitLoadpath() {
1630
+ this._exports['ruby-init-loadpath: func() -> ()']();
1631
+ }
1632
+ rbEvalStringProtect(arg0) {
1633
+ const memory = this._exports.memory;
1634
+ const realloc = this._exports["cabi_realloc"];
1635
+ const ptr0 = utf8_encode(arg0, realloc, memory);
1636
+ const len0 = UTF8_ENCODED_LEN;
1637
+ const ret = this._exports['rb-eval-string-protect: func(str: string) -> tuple<handle<rb-abi-value>, s32>'](ptr0, len0);
1638
+ return [this._resource1_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
1639
+ }
1640
+ rbFuncallvProtect(arg0, arg1, arg2) {
1641
+ const memory = this._exports.memory;
1642
+ const realloc = this._exports["cabi_realloc"];
1643
+ const obj0 = arg0;
1644
+ if (!(obj0 instanceof RbAbiValue))
1645
+ throw new TypeError('expected instance of RbAbiValue');
1646
+ const vec2 = arg2;
1647
+ const len2 = vec2.length;
1648
+ const result2 = realloc(0, 0, 4, len2 * 4);
1649
+ for (let i = 0; i < vec2.length; i++) {
1650
+ const e = vec2[i];
1651
+ const base = result2 + i * 4;
1652
+ const obj1 = e;
1653
+ if (!(obj1 instanceof RbAbiValue))
1654
+ throw new TypeError('expected instance of RbAbiValue');
1655
+ data_view(memory).setInt32(base + 0, this._resource1_slab.insert(obj1.clone()), true);
1656
+ }
1657
+ 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._resource1_slab.insert(obj0.clone()), to_uint32(arg1), result2, len2);
1658
+ return [this._resource1_slab.remove(data_view(memory).getInt32(ret + 0, true)), data_view(memory).getInt32(ret + 4, true)];
1659
+ }
1660
+ rbIntern(arg0) {
1661
+ const memory = this._exports.memory;
1662
+ const realloc = this._exports["cabi_realloc"];
1663
+ const ptr0 = utf8_encode(arg0, realloc, memory);
1664
+ const len0 = UTF8_ENCODED_LEN;
1665
+ const ret = this._exports['rb-intern: func(name: string) -> u32'](ptr0, len0);
1666
+ return ret >>> 0;
1667
+ }
1668
+ rbErrinfo() {
1669
+ const ret = this._exports['rb-errinfo: func() -> handle<rb-abi-value>']();
1670
+ return this._resource1_slab.remove(ret);
1671
+ }
1672
+ rbClearErrinfo() {
1673
+ this._exports['rb-clear-errinfo: func() -> ()']();
1674
+ }
1675
+ rstringPtr(arg0) {
1676
+ const memory = this._exports.memory;
1677
+ const obj0 = arg0;
1678
+ if (!(obj0 instanceof RbAbiValue))
1679
+ throw new TypeError('expected instance of RbAbiValue');
1680
+ const ret = this._exports['rstring-ptr: func(value: handle<rb-abi-value>) -> string'](this._resource1_slab.insert(obj0.clone()));
1681
+ const ptr1 = data_view(memory).getInt32(ret + 0, true);
1682
+ const len1 = data_view(memory).getInt32(ret + 4, true);
1683
+ const result1 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr1, len1));
1684
+ this._exports["cabi_post_rstring-ptr"](ret);
1685
+ return result1;
1686
+ }
1687
+ rbVmBugreport() {
1688
+ this._exports['rb-vm-bugreport: func() -> ()']();
1689
+ }
1690
+ rbGcEnable() {
1691
+ const ret = this._exports['rb-gc-enable: func() -> bool']();
1692
+ const bool0 = ret;
1693
+ return bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool());
1694
+ }
1695
+ rbGcDisable() {
1696
+ const ret = this._exports['rb-gc-disable: func() -> bool']();
1697
+ const bool0 = ret;
1698
+ return bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool());
1699
+ }
1700
+ rbSetShouldProhibitRewind(arg0) {
1701
+ const ret = this._exports['rb-set-should-prohibit-rewind: func(new-value: bool) -> bool'](arg0 ? 1 : 0);
1702
+ const bool0 = ret;
1703
+ return bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool());
1704
+ }
1705
+ }
1706
+ class RbIseq {
1707
+ constructor(wasm_val, obj) {
1708
+ this._wasm_val = wasm_val;
1709
+ this._obj = obj;
1710
+ this._refcnt = 1;
1711
+ obj._registry0.register(this, wasm_val, this);
1712
+ }
1713
+ clone() {
1714
+ this._refcnt += 1;
1715
+ return this;
1716
+ }
1717
+ drop() {
1718
+ this._refcnt -= 1;
1719
+ if (this._refcnt !== 0)
1720
+ return;
1721
+ this._obj._registry0.unregister(this);
1722
+ const dtor = this._obj._exports['canonical_abi_drop_rb-iseq'];
1723
+ const wasm_val = this._wasm_val;
1724
+ delete this._obj;
1725
+ delete this._refcnt;
1726
+ delete this._wasm_val;
1727
+ dtor(wasm_val);
1728
+ }
1729
+ }
1730
+ class RbAbiValue {
1731
+ constructor(wasm_val, obj) {
1732
+ this._wasm_val = wasm_val;
1733
+ this._obj = obj;
1734
+ this._refcnt = 1;
1735
+ obj._registry1.register(this, wasm_val, this);
1736
+ }
1737
+ clone() {
1738
+ this._refcnt += 1;
1739
+ return this;
1740
+ }
1741
+ drop() {
1742
+ this._refcnt -= 1;
1743
+ if (this._refcnt !== 0)
1744
+ return;
1745
+ this._obj._registry1.unregister(this);
1746
+ const dtor = this._obj._exports['canonical_abi_drop_rb-abi-value'];
1747
+ const wasm_val = this._wasm_val;
1748
+ delete this._obj;
1749
+ delete this._refcnt;
1750
+ delete this._wasm_val;
1751
+ dtor(wasm_val);
1752
+ }
1753
+ }
1754
+
1755
+ function addRbJsAbiHostToImports(imports, obj, get_export) {
1756
+ if (!("rb-js-abi-host" in imports))
1757
+ imports["rb-js-abi-host"] = {};
1758
+ 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) {
1759
+ const memory = get_export("memory");
1760
+ const ptr0 = arg0;
1761
+ const len0 = arg1;
1762
+ const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1763
+ const ret0 = obj.evalJs(result0);
1764
+ const variant1 = ret0;
1765
+ switch (variant1.tag) {
1766
+ case "success": {
1767
+ const e = variant1.val;
1768
+ data_view(memory).setInt8(arg2 + 0, 0, true);
1769
+ data_view(memory).setInt32(arg2 + 4, resources0.insert(e), true);
1770
+ break;
1771
+ }
1772
+ case "failure": {
1773
+ const e = variant1.val;
1774
+ data_view(memory).setInt8(arg2 + 0, 1, true);
1775
+ data_view(memory).setInt32(arg2 + 4, resources0.insert(e), true);
1776
+ break;
1777
+ }
1778
+ default:
1779
+ throw new RangeError("invalid variant specified for JsAbiResult");
1780
+ }
1781
+ };
1782
+ imports["rb-js-abi-host"]["is-js: func(value: handle<js-abi-value>) -> bool"] = function (arg0) {
1783
+ const ret0 = obj.isJs(resources0.get(arg0));
1784
+ return ret0 ? 1 : 0;
1785
+ };
1786
+ imports["rb-js-abi-host"]["instance-of: func(value: handle<js-abi-value>, klass: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
1787
+ const ret0 = obj.instanceOf(resources0.get(arg0), resources0.get(arg1));
1788
+ return ret0 ? 1 : 0;
1789
+ };
1790
+ imports["rb-js-abi-host"]["global-this: func() -> handle<js-abi-value>"] = function () {
1791
+ const ret0 = obj.globalThis();
1792
+ return resources0.insert(ret0);
1793
+ };
1794
+ imports["rb-js-abi-host"]["int-to-js-number: func(value: s32) -> handle<js-abi-value>"] = function (arg0) {
1795
+ const ret0 = obj.intToJsNumber(arg0);
1796
+ return resources0.insert(ret0);
1797
+ };
1798
+ imports["rb-js-abi-host"]["float-to-js-number: func(value: float64) -> handle<js-abi-value>"] = function (arg0) {
1799
+ const ret0 = obj.floatToJsNumber(arg0);
1800
+ return resources0.insert(ret0);
1801
+ };
1802
+ imports["rb-js-abi-host"]["string-to-js-string: func(value: string) -> handle<js-abi-value>"] = function (arg0, arg1) {
1803
+ const memory = get_export("memory");
1804
+ const ptr0 = arg0;
1805
+ const len0 = arg1;
1806
+ const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1807
+ const ret0 = obj.stringToJsString(result0);
1808
+ return resources0.insert(ret0);
1809
+ };
1810
+ imports["rb-js-abi-host"]["bool-to-js-bool: func(value: bool) -> handle<js-abi-value>"] = function (arg0) {
1811
+ const bool0 = arg0;
1812
+ const ret0 = obj.boolToJsBool(bool0 == 0 ? false : (bool0 == 1 ? true : throw_invalid_bool()));
1813
+ return resources0.insert(ret0);
1814
+ };
1815
+ imports["rb-js-abi-host"]["proc-to-js-function: func(value: u32) -> handle<js-abi-value>"] = function (arg0) {
1816
+ const ret0 = obj.procToJsFunction(arg0 >>> 0);
1817
+ return resources0.insert(ret0);
1818
+ };
1819
+ imports["rb-js-abi-host"]["rb-object-to-js-rb-value: func(raw-rb-abi-value: u32) -> handle<js-abi-value>"] = function (arg0) {
1820
+ const ret0 = obj.rbObjectToJsRbValue(arg0 >>> 0);
1821
+ return resources0.insert(ret0);
1822
+ };
1823
+ imports["rb-js-abi-host"]["js-value-to-string: func(value: handle<js-abi-value>) -> string"] = function (arg0, arg1) {
1824
+ const memory = get_export("memory");
1825
+ const realloc = get_export("cabi_realloc");
1826
+ const ret0 = obj.jsValueToString(resources0.get(arg0));
1827
+ const ptr0 = utf8_encode(ret0, realloc, memory);
1828
+ const len0 = UTF8_ENCODED_LEN;
1829
+ data_view(memory).setInt32(arg1 + 4, len0, true);
1830
+ data_view(memory).setInt32(arg1 + 0, ptr0, true);
1831
+ };
1832
+ imports["rb-js-abi-host"]["js-value-to-integer: func(value: handle<js-abi-value>) -> variant { as-float(float64), bignum(string) }"] = function (arg0, arg1) {
1833
+ const memory = get_export("memory");
1834
+ const realloc = get_export("cabi_realloc");
1835
+ const ret0 = obj.jsValueToInteger(resources0.get(arg0));
1836
+ const variant1 = ret0;
1837
+ switch (variant1.tag) {
1838
+ case "as-float": {
1839
+ const e = variant1.val;
1840
+ data_view(memory).setInt8(arg1 + 0, 0, true);
1841
+ data_view(memory).setFloat64(arg1 + 8, +e, true);
1842
+ break;
1843
+ }
1844
+ case "bignum": {
1845
+ const e = variant1.val;
1846
+ data_view(memory).setInt8(arg1 + 0, 1, true);
1847
+ const ptr0 = utf8_encode(e, realloc, memory);
1848
+ const len0 = UTF8_ENCODED_LEN;
1849
+ data_view(memory).setInt32(arg1 + 12, len0, true);
1850
+ data_view(memory).setInt32(arg1 + 8, ptr0, true);
1851
+ break;
1852
+ }
1853
+ default:
1854
+ throw new RangeError("invalid variant specified for RawInteger");
1855
+ }
1856
+ };
1857
+ imports["rb-js-abi-host"]["export-js-value-to-host: func(value: handle<js-abi-value>) -> ()"] = function (arg0) {
1858
+ obj.exportJsValueToHost(resources0.get(arg0));
1859
+ };
1860
+ imports["rb-js-abi-host"]["import-js-value-from-host: func() -> handle<js-abi-value>"] = function () {
1861
+ const ret0 = obj.importJsValueFromHost();
1862
+ return resources0.insert(ret0);
1863
+ };
1864
+ imports["rb-js-abi-host"]["js-value-typeof: func(value: handle<js-abi-value>) -> string"] = function (arg0, arg1) {
1865
+ const memory = get_export("memory");
1866
+ const realloc = get_export("cabi_realloc");
1867
+ const ret0 = obj.jsValueTypeof(resources0.get(arg0));
1868
+ const ptr0 = utf8_encode(ret0, realloc, memory);
1869
+ const len0 = UTF8_ENCODED_LEN;
1870
+ data_view(memory).setInt32(arg1 + 4, len0, true);
1871
+ data_view(memory).setInt32(arg1 + 0, ptr0, true);
1872
+ };
1873
+ imports["rb-js-abi-host"]["js-value-equal: func(lhs: handle<js-abi-value>, rhs: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
1874
+ const ret0 = obj.jsValueEqual(resources0.get(arg0), resources0.get(arg1));
1875
+ return ret0 ? 1 : 0;
1876
+ };
1877
+ imports["rb-js-abi-host"]["js-value-strictly-equal: func(lhs: handle<js-abi-value>, rhs: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
1878
+ const ret0 = obj.jsValueStrictlyEqual(resources0.get(arg0), resources0.get(arg1));
1879
+ return ret0 ? 1 : 0;
1880
+ };
1881
+ 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) {
1882
+ const memory = get_export("memory");
1883
+ const len0 = arg3;
1884
+ const base0 = arg2;
1885
+ const result0 = [];
1886
+ for (let i = 0; i < len0; i++) {
1887
+ const base = base0 + i * 4;
1888
+ result0.push(resources0.get(data_view(memory).getInt32(base + 0, true)));
1889
+ }
1890
+ const ret0 = obj.reflectApply(resources0.get(arg0), resources0.get(arg1), result0);
1891
+ const variant1 = ret0;
1892
+ switch (variant1.tag) {
1893
+ case "success": {
1894
+ const e = variant1.val;
1895
+ data_view(memory).setInt8(arg4 + 0, 0, true);
1896
+ data_view(memory).setInt32(arg4 + 4, resources0.insert(e), true);
1897
+ break;
1898
+ }
1899
+ case "failure": {
1900
+ const e = variant1.val;
1901
+ data_view(memory).setInt8(arg4 + 0, 1, true);
1902
+ data_view(memory).setInt32(arg4 + 4, resources0.insert(e), true);
1903
+ break;
1904
+ }
1905
+ default:
1906
+ throw new RangeError("invalid variant specified for JsAbiResult");
1907
+ }
1908
+ };
1909
+ 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) {
1910
+ const memory = get_export("memory");
1911
+ const len0 = arg2;
1912
+ const base0 = arg1;
1913
+ const result0 = [];
1914
+ for (let i = 0; i < len0; i++) {
1915
+ const base = base0 + i * 4;
1916
+ result0.push(resources0.get(data_view(memory).getInt32(base + 0, true)));
1917
+ }
1918
+ const ret0 = obj.reflectConstruct(resources0.get(arg0), result0);
1919
+ return resources0.insert(ret0);
1920
+ };
1921
+ imports["rb-js-abi-host"]["reflect-delete-property: func(target: handle<js-abi-value>, property-key: string) -> bool"] = function (arg0, arg1, arg2) {
1922
+ const memory = get_export("memory");
1923
+ const ptr0 = arg1;
1924
+ const len0 = arg2;
1925
+ const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1926
+ const ret0 = obj.reflectDeleteProperty(resources0.get(arg0), result0);
1927
+ return ret0 ? 1 : 0;
1928
+ };
1929
+ 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) {
1930
+ const memory = get_export("memory");
1931
+ const ptr0 = arg1;
1932
+ const len0 = arg2;
1933
+ const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1934
+ const ret0 = obj.reflectGet(resources0.get(arg0), result0);
1935
+ const variant1 = ret0;
1936
+ switch (variant1.tag) {
1937
+ case "success": {
1938
+ const e = variant1.val;
1939
+ data_view(memory).setInt8(arg3 + 0, 0, true);
1940
+ data_view(memory).setInt32(arg3 + 4, resources0.insert(e), true);
1941
+ break;
1942
+ }
1943
+ case "failure": {
1944
+ const e = variant1.val;
1945
+ data_view(memory).setInt8(arg3 + 0, 1, true);
1946
+ data_view(memory).setInt32(arg3 + 4, resources0.insert(e), true);
1947
+ break;
1948
+ }
1949
+ default:
1950
+ throw new RangeError("invalid variant specified for JsAbiResult");
1951
+ }
1952
+ };
1953
+ 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) {
1954
+ const memory = get_export("memory");
1955
+ const ptr0 = arg1;
1956
+ const len0 = arg2;
1957
+ const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1958
+ const ret0 = obj.reflectGetOwnPropertyDescriptor(resources0.get(arg0), result0);
1959
+ return resources0.insert(ret0);
1960
+ };
1961
+ imports["rb-js-abi-host"]["reflect-get-prototype-of: func(target: handle<js-abi-value>) -> handle<js-abi-value>"] = function (arg0) {
1962
+ const ret0 = obj.reflectGetPrototypeOf(resources0.get(arg0));
1963
+ return resources0.insert(ret0);
1964
+ };
1965
+ imports["rb-js-abi-host"]["reflect-has: func(target: handle<js-abi-value>, property-key: string) -> bool"] = function (arg0, arg1, arg2) {
1966
+ const memory = get_export("memory");
1967
+ const ptr0 = arg1;
1968
+ const len0 = arg2;
1969
+ const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
1970
+ const ret0 = obj.reflectHas(resources0.get(arg0), result0);
1971
+ return ret0 ? 1 : 0;
1972
+ };
1973
+ imports["rb-js-abi-host"]["reflect-is-extensible: func(target: handle<js-abi-value>) -> bool"] = function (arg0) {
1974
+ const ret0 = obj.reflectIsExtensible(resources0.get(arg0));
1975
+ return ret0 ? 1 : 0;
1976
+ };
1977
+ imports["rb-js-abi-host"]["reflect-own-keys: func(target: handle<js-abi-value>) -> list<handle<js-abi-value>>"] = function (arg0, arg1) {
1978
+ const memory = get_export("memory");
1979
+ const realloc = get_export("cabi_realloc");
1980
+ const ret0 = obj.reflectOwnKeys(resources0.get(arg0));
1981
+ const vec0 = ret0;
1982
+ const len0 = vec0.length;
1983
+ const result0 = realloc(0, 0, 4, len0 * 4);
1984
+ for (let i = 0; i < vec0.length; i++) {
1985
+ const e = vec0[i];
1986
+ const base = result0 + i * 4;
1987
+ data_view(memory).setInt32(base + 0, resources0.insert(e), true);
1988
+ }
1989
+ data_view(memory).setInt32(arg1 + 4, len0, true);
1990
+ data_view(memory).setInt32(arg1 + 0, result0, true);
1991
+ };
1992
+ imports["rb-js-abi-host"]["reflect-prevent-extensions: func(target: handle<js-abi-value>) -> bool"] = function (arg0) {
1993
+ const ret0 = obj.reflectPreventExtensions(resources0.get(arg0));
1994
+ return ret0 ? 1 : 0;
1995
+ };
1996
+ 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) {
1997
+ const memory = get_export("memory");
1998
+ const ptr0 = arg1;
1999
+ const len0 = arg2;
2000
+ const result0 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr0, len0));
2001
+ const ret0 = obj.reflectSet(resources0.get(arg0), result0, resources0.get(arg3));
2002
+ const variant1 = ret0;
2003
+ switch (variant1.tag) {
2004
+ case "success": {
2005
+ const e = variant1.val;
2006
+ data_view(memory).setInt8(arg4 + 0, 0, true);
2007
+ data_view(memory).setInt32(arg4 + 4, resources0.insert(e), true);
2008
+ break;
2009
+ }
2010
+ case "failure": {
2011
+ const e = variant1.val;
2012
+ data_view(memory).setInt8(arg4 + 0, 1, true);
2013
+ data_view(memory).setInt32(arg4 + 4, resources0.insert(e), true);
2014
+ break;
2015
+ }
2016
+ default:
2017
+ throw new RangeError("invalid variant specified for JsAbiResult");
2018
+ }
2019
+ };
2020
+ imports["rb-js-abi-host"]["reflect-set-prototype-of: func(target: handle<js-abi-value>, prototype: handle<js-abi-value>) -> bool"] = function (arg0, arg1) {
2021
+ const ret0 = obj.reflectSetPrototypeOf(resources0.get(arg0), resources0.get(arg1));
2022
+ return ret0 ? 1 : 0;
2023
+ };
2024
+ if (!("canonical_abi" in imports))
2025
+ imports["canonical_abi"] = {};
2026
+ const resources0 = new Slab();
2027
+ imports.canonical_abi["resource_drop_js-abi-value"] = (i) => {
2028
+ const val = resources0.remove(i);
2029
+ if (obj.dropJsAbiValue)
2030
+ obj.dropJsAbiValue(val);
2031
+ };
2032
+ }
2033
+
2034
+ class LegacyBinding extends RbAbiGuest {
2035
+ async setInstance(instance) {
2036
+ await this.instantiate(instance);
2037
+ }
2038
+ }
2039
+ class ComponentBinding {
2040
+ constructor() { }
2041
+ setUnderlying(underlying) {
2042
+ this.underlying = underlying;
2043
+ }
2044
+ rubyShowVersion() {
2045
+ this.underlying.rubyShowVersion();
2046
+ }
2047
+ rubyInit() {
2048
+ this.underlying.rubyInit();
2049
+ }
2050
+ rubySysinit(args) {
2051
+ this.underlying.rubySysinit(args);
2052
+ }
2053
+ rubyOptions(args) {
2054
+ this.underlying.rubyOptions(args);
2055
+ }
2056
+ rubyScript(name) {
2057
+ this.underlying.rubyScript(name);
2058
+ }
2059
+ rubyInitLoadpath() {
2060
+ this.underlying.rubyInitLoadpath();
2061
+ }
2062
+ rbEvalStringProtect(str) {
2063
+ return this.underlying.rbEvalStringProtect(str);
2064
+ }
2065
+ rbFuncallvProtect(recv, mid, args) {
2066
+ return this.underlying.rbFuncallvProtect(recv, mid, args);
2067
+ }
2068
+ rbIntern(name) {
2069
+ return this.underlying.rbIntern(name);
2070
+ }
2071
+ rbErrinfo() {
2072
+ return this.underlying.rbErrinfo();
2073
+ }
2074
+ rbClearErrinfo() {
2075
+ return this.underlying.rbClearErrinfo();
2076
+ }
2077
+ rstringPtr(value) {
2078
+ return this.underlying.rstringPtr(value);
2079
+ }
2080
+ rbVmBugreport() {
2081
+ this.underlying.rbVmBugreport();
2082
+ }
2083
+ rbGcEnable() {
2084
+ return this.underlying.rbGcEnable();
2085
+ }
2086
+ rbGcDisable() {
2087
+ return this.underlying.rbGcDisable();
2088
+ }
2089
+ rbSetShouldProhibitRewind(newValue) {
2090
+ return this.underlying.rbSetShouldProhibitRewind(newValue);
2091
+ }
2092
+ async setInstance(instance) {
2093
+ // No-op
2094
+ }
2095
+ addToImports(imports) {
2096
+ // No-op
2097
+ }
2098
+ }
2099
+
2100
+ /**
2101
+ * A Ruby VM instance
2102
+ *
2103
+ * @example
2104
+ *
2105
+ * const wasi = new WASI();
2106
+ * const vm = new RubyVM();
2107
+ * const imports = {
2108
+ * wasi_snapshot_preview1: wasi.wasiImport,
2109
+ * };
2110
+ *
2111
+ * vm.addToImports(imports);
2112
+ *
2113
+ * const instance = await WebAssembly.instantiate(rubyModule, imports);
2114
+ * await vm.setInstance(instance);
2115
+ * wasi.initialize(instance);
2116
+ * vm.initialize();
2117
+ *
2118
+ */
2119
+ class RubyVM {
2120
+ constructor(binding) {
2121
+ this.instance = null;
2122
+ this.interfaceState = {
2123
+ hasJSFrameAfterRbFrame: false,
2124
+ };
2125
+ // Wrap exported functions from Ruby VM to prohibit nested VM operation
2126
+ // if the call stack has sandwitched JS frames like JS -> Ruby -> JS -> Ruby.
2127
+ const proxyExports = (exports) => {
2128
+ const excludedMethods = [
2129
+ "setInstance",
2130
+ "addToImports",
2131
+ "instantiate",
2132
+ "rbSetShouldProhibitRewind",
2133
+ "rbGcDisable",
2134
+ "rbGcEnable",
2135
+ ];
2136
+ const excluded = ["constructor"].concat(excludedMethods);
2137
+ // wrap all methods in RbAbi.RbAbiGuest class
2138
+ for (const key of Object.getOwnPropertyNames(RbAbiGuest.prototype)) {
2139
+ if (excluded.includes(key)) {
2140
+ continue;
2141
+ }
2142
+ const value = exports[key];
2143
+ if (typeof value === "function") {
2144
+ exports[key] = (...args) => {
2145
+ const isNestedVMCall = this.interfaceState.hasJSFrameAfterRbFrame;
2146
+ if (isNestedVMCall) {
2147
+ const oldShouldProhibitRewind = this.guest.rbSetShouldProhibitRewind(true);
2148
+ const oldIsDisabledGc = this.guest.rbGcDisable();
2149
+ const result = Reflect.apply(value, exports, args);
2150
+ this.guest.rbSetShouldProhibitRewind(oldShouldProhibitRewind);
2151
+ if (!oldIsDisabledGc) {
2152
+ this.guest.rbGcEnable();
2153
+ }
2154
+ return result;
2155
+ }
2156
+ else {
2157
+ return Reflect.apply(value, exports, args);
2158
+ }
2159
+ };
2160
+ }
2161
+ }
2162
+ return exports;
2163
+ };
2164
+ this.guest = proxyExports(binding !== null && binding !== void 0 ? binding : new LegacyBinding());
2165
+ this.transport = new JsValueTransport();
2166
+ this.exceptionFormatter = new RbExceptionFormatter();
2167
+ }
2168
+ static async _instantiate(initComponent, options) {
2169
+ const binding = new ComponentBinding();
2170
+ const vm = new RubyVM(binding);
2171
+ class JsAbiValue {
2172
+ constructor(underlying) {
2173
+ this.underlying = underlying;
2174
+ }
2175
+ }
2176
+ const imports = vm.getImports((from) => new JsAbiValue(from), (to) => to.underlying);
2177
+ const component = await initComponent(Object.assign(Object.assign({}, imports), { throwProhibitRewindException: (message) => {
2178
+ vm.throwProhibitRewindException(message);
2179
+ }, procToJsFunction: () => {
2180
+ const rbValue = new RbValue(component.exportRbValueToJs(), vm, vm.privateObject());
2181
+ return new JsAbiValue((...args) => {
2182
+ return rbValue.call("call", ...args.map((arg) => vm.wrap(arg))).toJS();
2183
+ });
2184
+ }, rbObjectToJsRbValue: () => {
2185
+ const rbValue = new RbValue(component.exportRbValueToJs(), vm, vm.privateObject());
2186
+ return new JsAbiValue(rbValue);
2187
+ }, JsAbiValue: JsAbiValue }));
2188
+ binding.setUnderlying(component);
2189
+ vm.initialize(options.args);
2190
+ return vm;
2191
+ }
2192
+ /**
2193
+ * Initialize the Ruby VM with the given command line arguments
2194
+ * @param args The command line arguments to pass to Ruby. Must be
2195
+ * an array of strings starting with the Ruby program name.
2196
+ */
2197
+ initialize(args = ["ruby.wasm", "-EUTF-8", "-e_=0"]) {
2198
+ const c_args = args.map((arg) => arg + "\0");
2199
+ this.guest.rubyInit();
2200
+ this.guest.rubySysinit(c_args);
2201
+ this.guest.rubyOptions(c_args);
2202
+ this.eval(`require "/bundle/setup"`);
2203
+ }
2204
+ /**
2205
+ * Set a given instance to interact JavaScript and Ruby's
2206
+ * WebAssembly instance. This method must be called before calling
2207
+ * Ruby API.
2208
+ *
2209
+ * @param instance The WebAssembly instance to interact with. Must
2210
+ * be instantiated from a Ruby built with JS extension, and built
2211
+ * with Reactor ABI instead of command line.
2212
+ */
2213
+ async setInstance(instance) {
2214
+ this.instance = instance;
2215
+ await this.guest.setInstance(instance);
2216
+ }
2217
+ /**
2218
+ * Add intrinsic import entries, which is necessary to interact JavaScript
2219
+ * and Ruby's WebAssembly instance.
2220
+ * @param imports The import object to add to the WebAssembly instance
2221
+ */
2222
+ addToImports(imports) {
2223
+ this.guest.addToImports(imports);
2224
+ imports["rb-js-abi-host"] = {
2225
+ rb_wasm_throw_prohibit_rewind_exception: (messagePtr, messageLen) => {
2226
+ const memory = this.instance.exports.memory;
2227
+ const str = new TextDecoder().decode(new Uint8Array(memory.buffer, messagePtr, messageLen));
2228
+ this.throwProhibitRewindException(str);
2229
+ },
2230
+ };
2231
+ addRbJsAbiHostToImports(imports, this.getImports((value) => value, (value) => value), (name) => {
2232
+ return this.instance.exports[name];
2233
+ });
2234
+ }
2235
+ throwProhibitRewindException(str) {
2236
+ let message = "Ruby APIs that may rewind the VM stack are prohibited under nested VM operation " +
2237
+ `(${str})\n` +
2238
+ "Nested VM operation means that the call stack has sandwitched JS frames like JS -> Ruby -> JS -> Ruby " +
2239
+ "caused by something like `window.rubyVM.eval(\"JS.global[:rubyVM].eval('Fiber.yield')\")`\n" +
2240
+ "\n" +
2241
+ "Please check your call stack and make sure that you are **not** doing any of the following inside the nested Ruby frame:\n" +
2242
+ " 1. Switching fibers (e.g. Fiber#resume, Fiber.yield, and Fiber#transfer)\n" +
2243
+ " Note that `evalAsync` JS API switches fibers internally\n" +
2244
+ " 2. Raising uncaught exceptions\n" +
2245
+ " Please catch all exceptions inside the nested operation\n" +
2246
+ " 3. Calling Continuation APIs\n";
2247
+ const error = new RbValue(this.guest.rbErrinfo(), this, this.privateObject());
2248
+ if (error.call("nil?").toString() === "false") {
2249
+ message += "\n" + this.exceptionFormatter.format(error, this, this.privateObject());
2250
+ }
2251
+ throw new RbFatalError(message);
2252
+ }
2253
+ getImports(toJSAbiValue, fromJSAbiValue) {
2254
+ // NOTE: The GC may collect objects that are still referenced by Wasm
2255
+ // locals because Asyncify cannot scan the Wasm stack above the JS frame.
2256
+ // So we need to keep track whether the JS frame is sandwitched by Ruby
2257
+ // frames or not, and prohibit nested VM operation if it is.
2258
+ const proxyImports = (imports) => {
2259
+ for (const [key, value] of Object.entries(imports)) {
2260
+ if (typeof value === "function") {
2261
+ imports[key] = (...args) => {
2262
+ const oldValue = this.interfaceState.hasJSFrameAfterRbFrame;
2263
+ this.interfaceState.hasJSFrameAfterRbFrame = true;
2264
+ const result = Reflect.apply(value, imports, args);
2265
+ this.interfaceState.hasJSFrameAfterRbFrame = oldValue;
2266
+ return result;
2267
+ };
2268
+ }
2269
+ }
2270
+ return imports;
2271
+ };
2272
+ function wrapTry(f) {
2273
+ return (...args) => {
2274
+ try {
2275
+ return { tag: "success", val: f(...args) };
2276
+ }
2277
+ catch (e) {
2278
+ if (e instanceof RbFatalError) {
2279
+ // RbFatalError should not be caught by Ruby because it Ruby VM
2280
+ // can be already in an inconsistent state.
2281
+ throw e;
2282
+ }
2283
+ return { tag: "failure", val: toJSAbiValue(e) };
2284
+ }
2285
+ };
2286
+ }
2287
+ return proxyImports({
2288
+ evalJs: wrapTry((code) => {
2289
+ return toJSAbiValue(Function(code)());
2290
+ }),
2291
+ isJs: (value) => {
2292
+ // Just for compatibility with the old JS API
2293
+ return true;
2294
+ },
2295
+ globalThis: () => {
2296
+ if (typeof globalThis !== "undefined") {
2297
+ return toJSAbiValue(globalThis);
2298
+ }
2299
+ else if (typeof global !== "undefined") {
2300
+ return toJSAbiValue(global);
2301
+ }
2302
+ else if (typeof window !== "undefined") {
2303
+ return toJSAbiValue(window);
2304
+ }
2305
+ throw new Error("unable to locate global object");
2306
+ },
2307
+ intToJsNumber: (value) => {
2308
+ return toJSAbiValue(value);
2309
+ },
2310
+ floatToJsNumber: (value) => {
2311
+ return toJSAbiValue(value);
2312
+ },
2313
+ stringToJsString: (value) => {
2314
+ return toJSAbiValue(value);
2315
+ },
2316
+ boolToJsBool: (value) => {
2317
+ return toJSAbiValue(value);
2318
+ },
2319
+ procToJsFunction: (rawRbAbiValue) => {
2320
+ const rbValue = this.rbValueOfPointer(rawRbAbiValue);
2321
+ return toJSAbiValue((...args) => {
2322
+ return rbValue.call("call", ...args.map((arg) => this.wrap(arg))).toJS();
2323
+ });
2324
+ },
2325
+ rbObjectToJsRbValue: (rawRbAbiValue) => {
2326
+ return toJSAbiValue(this.rbValueOfPointer(rawRbAbiValue));
2327
+ },
2328
+ jsValueToString: (value) => {
2329
+ value = fromJSAbiValue(value);
2330
+ // According to the [spec](https://tc39.es/ecma262/multipage/text-processing.html#sec-string-constructor-string-value)
2331
+ // `String(value)` always returns a string.
2332
+ return String(value);
2333
+ },
2334
+ jsValueToInteger(value) {
2335
+ value = fromJSAbiValue(value);
2336
+ if (typeof value === "number") {
2337
+ return { tag: "as-float", val: value };
2338
+ }
2339
+ else if (typeof value === "bigint") {
2340
+ return { tag: "bignum", val: BigInt(value).toString(10) + "\0" };
2341
+ }
2342
+ else if (typeof value === "string") {
2343
+ return { tag: "bignum", val: value + "\0" };
2344
+ }
2345
+ else if (typeof value === "undefined") {
2346
+ return { tag: "as-float", val: 0 };
2347
+ }
2348
+ else {
2349
+ return { tag: "as-float", val: Number(value) };
2350
+ }
2351
+ },
2352
+ exportJsValueToHost: (value) => {
2353
+ // See `JsValueExporter` for the reason why we need to do this
2354
+ this.transport.takeJsValue(fromJSAbiValue(value));
2355
+ },
2356
+ importJsValueFromHost: () => {
2357
+ return toJSAbiValue(this.transport.consumeJsValue());
2358
+ },
2359
+ instanceOf: (value, klass) => {
2360
+ klass = fromJSAbiValue(klass);
2361
+ if (typeof klass === "function") {
2362
+ return fromJSAbiValue(value) instanceof klass;
2363
+ }
2364
+ else {
2365
+ return false;
2366
+ }
2367
+ },
2368
+ jsValueTypeof(value) {
2369
+ return typeof fromJSAbiValue(value);
2370
+ },
2371
+ jsValueEqual(lhs, rhs) {
2372
+ return fromJSAbiValue(lhs) == fromJSAbiValue(rhs);
2373
+ },
2374
+ jsValueStrictlyEqual(lhs, rhs) {
2375
+ return fromJSAbiValue(lhs) === fromJSAbiValue(rhs);
2376
+ },
2377
+ reflectApply: wrapTry((target, thisArgument, args) => {
2378
+ const jsArgs = args.map((arg) => fromJSAbiValue(arg));
2379
+ return toJSAbiValue(Reflect.apply(fromJSAbiValue(target), fromJSAbiValue(thisArgument), jsArgs));
2380
+ }),
2381
+ reflectConstruct: function (target, args) {
2382
+ throw new Error("Function not implemented.");
2383
+ },
2384
+ reflectDeleteProperty: function (target, propertyKey) {
2385
+ throw new Error("Function not implemented.");
2386
+ },
2387
+ reflectGet: wrapTry((target, propertyKey) => {
2388
+ return toJSAbiValue(fromJSAbiValue(target)[propertyKey]);
2389
+ }),
2390
+ reflectGetOwnPropertyDescriptor: function (target, propertyKey) {
2391
+ throw new Error("Function not implemented.");
2392
+ },
2393
+ reflectGetPrototypeOf: function (target) {
2394
+ throw new Error("Function not implemented.");
2395
+ },
2396
+ reflectHas: function (target, propertyKey) {
2397
+ throw new Error("Function not implemented.");
2398
+ },
2399
+ reflectIsExtensible: function (target) {
2400
+ throw new Error("Function not implemented.");
2401
+ },
2402
+ reflectOwnKeys: function (target) {
2403
+ throw new Error("Function not implemented.");
2404
+ },
2405
+ reflectPreventExtensions: function (target) {
2406
+ throw new Error("Function not implemented.");
2407
+ },
2408
+ reflectSet: wrapTry((target, propertyKey, value) => {
2409
+ return toJSAbiValue(Reflect.set(fromJSAbiValue(target), propertyKey, fromJSAbiValue(value)));
2410
+ }),
2411
+ reflectSetPrototypeOf: function (target, prototype) {
2412
+ throw new Error("Function not implemented.");
2413
+ },
2414
+ });
2415
+ }
2416
+ /**
2417
+ * Print the Ruby version to stdout
2418
+ */
2419
+ printVersion() {
2420
+ this.guest.rubyShowVersion();
2421
+ }
2422
+ /**
2423
+ * Runs a string of Ruby code from JavaScript
2424
+ * @param code The Ruby code to run
2425
+ * @returns the result of the last expression
2426
+ *
2427
+ * @example
2428
+ * vm.eval("puts 'hello world'");
2429
+ * const result = vm.eval("1 + 2");
2430
+ * console.log(result.toString()); // 3
2431
+ *
2432
+ */
2433
+ eval(code) {
2434
+ return evalRbCode(this, this.privateObject(), code);
2435
+ }
2436
+ /**
2437
+ * Runs a string of Ruby code with top-level `JS::Object#await`
2438
+ * Returns a promise that resolves when execution completes.
2439
+ * @param code The Ruby code to run
2440
+ * @returns a promise that resolves to the result of the last expression
2441
+ *
2442
+ * @example
2443
+ * const text = await vm.evalAsync(`
2444
+ * require 'js'
2445
+ * response = JS.global.fetch('https://example.com').await
2446
+ * response.text.await
2447
+ * `);
2448
+ * console.log(text.toString()); // <html>...</html>
2449
+ */
2450
+ evalAsync(code) {
2451
+ const JS = this.eval("require 'js'; JS");
2452
+ return newRbPromise(this, this.privateObject(), (future) => {
2453
+ JS.call("__eval_async_rb", this.wrap(code), future);
2454
+ });
2455
+ }
2456
+ /**
2457
+ * Wrap a JavaScript value into a Ruby JS::Object
2458
+ * @param value The value to convert to RbValue
2459
+ * @returns the RbValue object representing the given JS value
2460
+ *
2461
+ * @example
2462
+ * const hash = vm.eval(`Hash.new`)
2463
+ * hash.call("store", vm.eval(`"key1"`), vm.wrap(new Object()));
2464
+ */
2465
+ wrap(value) {
2466
+ return this.transport.importJsValue(value, this);
2467
+ }
2468
+ /** @private */
2469
+ privateObject() {
2470
+ return {
2471
+ transport: this.transport,
2472
+ exceptionFormatter: this.exceptionFormatter,
2473
+ };
2474
+ }
2475
+ /** @private */
2476
+ rbValueOfPointer(pointer) {
2477
+ const abiValue = new RbAbiValue(pointer, this.guest);
2478
+ return new RbValue(abiValue, this, this.privateObject());
2479
+ }
2480
+ }
2481
+ /**
2482
+ * Export a JS value held by the Ruby VM to the JS environment.
2483
+ * This is implemented in a dirty way since wit cannot reference resources
2484
+ * defined in other interfaces.
2485
+ * In our case, we can't express `function(v: rb-abi-value) -> js-abi-value`
2486
+ * because `rb-js-abi-host.wit`, that defines `js-abi-value`, is implemented
2487
+ * by embedder side (JS) but `rb-abi-guest.wit`, that defines `rb-abi-value`
2488
+ * is implemented by guest side (Wasm).
2489
+ *
2490
+ * This class is a helper to export by:
2491
+ * 1. Call `function __export_to_js(v: rb-abi-value)` defined in guest from embedder side.
2492
+ * 2. Call `function takeJsValue(v: js-abi-value)` defined in embedder from guest side with
2493
+ * underlying JS value of given `rb-abi-value`.
2494
+ * 3. Then `takeJsValue` implementation escapes the given JS value to the `_takenJsValues`
2495
+ * stored in embedder side.
2496
+ * 4. Finally, embedder side can take `_takenJsValues`.
2497
+ *
2498
+ * Note that `exportJsValue` is not reentrant.
2499
+ *
2500
+ * @private
2501
+ */
2502
+ class JsValueTransport {
2503
+ constructor() {
2504
+ this._takenJsValue = null;
2505
+ }
2506
+ takeJsValue(value) {
2507
+ this._takenJsValue = value;
2508
+ }
2509
+ consumeJsValue() {
2510
+ return this._takenJsValue;
2511
+ }
2512
+ exportJsValue(value) {
2513
+ value.call("__export_to_js");
2514
+ return this._takenJsValue;
2515
+ }
2516
+ importJsValue(value, vm) {
2517
+ this._takenJsValue = value;
2518
+ return vm.eval('require "js"; JS::Object').call("__import_from_js");
2519
+ }
2520
+ }
2521
+ /**
2522
+ * A RbValue is an object that represents a value in Ruby
2523
+ */
2524
+ class RbValue {
2525
+ /**
2526
+ * @hideconstructor
2527
+ */
2528
+ constructor(inner, vm, privateObject) {
2529
+ this.inner = inner;
2530
+ this.vm = vm;
2531
+ this.privateObject = privateObject;
2532
+ }
2533
+ /**
2534
+ * Call a given method with given arguments
2535
+ *
2536
+ * @param callee name of the Ruby method to call
2537
+ * @param args arguments to pass to the method. Must be an array of RbValue
2538
+ * @returns The result of the method call as a new RbValue.
2539
+ *
2540
+ * @example
2541
+ * const ary = vm.eval("[1, 2, 3]");
2542
+ * ary.call("push", 4);
2543
+ * console.log(ary.call("sample").toString());
2544
+ */
2545
+ call(callee, ...args) {
2546
+ const innerArgs = args.map((arg) => arg.inner);
2547
+ return new RbValue(callRbMethod(this.vm, this.privateObject, this.inner, callee, innerArgs), this.vm, this.privateObject);
2548
+ }
2549
+ /**
2550
+ * Call a given method that may call `JS::Object#await` with given arguments
2551
+ *
2552
+ * @param callee name of the Ruby method to call
2553
+ * @param args arguments to pass to the method. Must be an array of RbValue
2554
+ * @returns A Promise that resolves to the result of the method call as a new RbValue.
2555
+ *
2556
+ * @example
2557
+ * const client = vm.eval(`
2558
+ * require 'js'
2559
+ * class HttpClient
2560
+ * def get(url)
2561
+ * JS.global.fetch(url).await
2562
+ * end
2563
+ * end
2564
+ * HttpClient.new
2565
+ * `);
2566
+ * const response = await client.callAsync("get", vm.eval(`"https://example.com"`));
2567
+ */
2568
+ callAsync(callee, ...args) {
2569
+ const JS = this.vm.eval("require 'js'; JS");
2570
+ return newRbPromise(this.vm, this.privateObject, (future) => {
2571
+ JS.call("__call_async_method", this, this.vm.wrap(callee), future, ...args);
2572
+ });
2573
+ }
2574
+ /**
2575
+ * @see {@link https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive}
2576
+ * @param hint Preferred type of the result primitive value. `"number"`, `"string"`, or `"default"`.
2577
+ */
2578
+ [Symbol.toPrimitive](hint) {
2579
+ if (hint === "string" || hint === "default") {
2580
+ return this.toString();
2581
+ }
2582
+ else if (hint === "number") {
2583
+ return null;
2584
+ }
2585
+ return null;
2586
+ }
2587
+ /**
2588
+ * Returns a string representation of the value by calling `to_s`
2589
+ */
2590
+ toString() {
2591
+ const rbString = callRbMethod(this.vm, this.privateObject, this.inner, "to_s", []);
2592
+ return this.vm.guest.rstringPtr(rbString);
2593
+ }
2594
+ /**
2595
+ * Returns a JavaScript object representation of the value
2596
+ * by calling `to_js`.
2597
+ *
2598
+ * Returns null if the value is not convertible to a JavaScript object.
2599
+ */
2600
+ toJS() {
2601
+ const JS = this.vm.eval("JS");
2602
+ const jsValue = JS.call("try_convert", this);
2603
+ if (jsValue.call("nil?").toString() === "true") {
2604
+ return null;
2605
+ }
2606
+ return this.privateObject.transport.exportJsValue(jsValue);
2607
+ }
2608
+ }
2609
+ var ruby_tag_type;
2610
+ (function (ruby_tag_type) {
2611
+ ruby_tag_type[ruby_tag_type["None"] = 0] = "None";
2612
+ ruby_tag_type[ruby_tag_type["Return"] = 1] = "Return";
2613
+ ruby_tag_type[ruby_tag_type["Break"] = 2] = "Break";
2614
+ ruby_tag_type[ruby_tag_type["Next"] = 3] = "Next";
2615
+ ruby_tag_type[ruby_tag_type["Retry"] = 4] = "Retry";
2616
+ ruby_tag_type[ruby_tag_type["Redo"] = 5] = "Redo";
2617
+ ruby_tag_type[ruby_tag_type["Raise"] = 6] = "Raise";
2618
+ ruby_tag_type[ruby_tag_type["Throw"] = 7] = "Throw";
2619
+ ruby_tag_type[ruby_tag_type["Fatal"] = 8] = "Fatal";
2620
+ ruby_tag_type[ruby_tag_type["Mask"] = 15] = "Mask";
2621
+ })(ruby_tag_type || (ruby_tag_type = {}));
2622
+ class RbExceptionFormatter {
2623
+ constructor() {
2624
+ this.literalsCache = null;
2625
+ this.isFormmatting = false;
2626
+ }
2627
+ format(error, vm, privateObject) {
2628
+ // All Ruby exceptions raised during formatting exception message should
2629
+ // be caught and return a fallback message.
2630
+ // Therefore, we don't need to worry about infinite recursion here ideally
2631
+ // but checking re-entrancy just in case.
2632
+ class RbExceptionFormatterError extends Error {
2633
+ }
2634
+ if (this.isFormmatting) {
2635
+ throw new RbExceptionFormatterError("Unexpected exception occurred during formatting exception message");
2636
+ }
2637
+ this.isFormmatting = true;
2638
+ try {
2639
+ return this._format(error, vm, privateObject);
2640
+ }
2641
+ finally {
2642
+ this.isFormmatting = false;
2643
+ }
2644
+ }
2645
+ _format(error, vm, privateObject) {
2646
+ const [zeroLiteral, oneLiteral, newLineLiteral] = (() => {
2647
+ if (this.literalsCache == null) {
2648
+ const zeroOneNewLine = [
2649
+ evalRbCode(vm, privateObject, "0"),
2650
+ evalRbCode(vm, privateObject, "1"),
2651
+ evalRbCode(vm, privateObject, `"\n"`),
2652
+ ];
2653
+ this.literalsCache = zeroOneNewLine;
2654
+ return zeroOneNewLine;
2655
+ }
2656
+ else {
2657
+ return this.literalsCache;
2658
+ }
2659
+ })();
2660
+ let className;
2661
+ let backtrace;
2662
+ let message;
2663
+ try {
2664
+ className = error.call("class").toString();
2665
+ }
2666
+ catch (e) {
2667
+ className = "unknown";
2668
+ }
2669
+ try {
2670
+ message = error.call("message").toString();
2671
+ }
2672
+ catch (e) {
2673
+ message = "unknown";
2674
+ }
2675
+ try {
2676
+ backtrace = error.call("backtrace");
2677
+ }
2678
+ catch (e) {
2679
+ return this.formatString(className, message);
2680
+ }
2681
+ if (backtrace.call("nil?").toString() === "true") {
2682
+ return this.formatString(className, message);
2683
+ }
2684
+ try {
2685
+ const firstLine = backtrace.call("at", zeroLiteral);
2686
+ const restLines = backtrace
2687
+ .call("drop", oneLiteral)
2688
+ .call("join", newLineLiteral);
2689
+ return this.formatString(className, message, [
2690
+ firstLine.toString(),
2691
+ restLines.toString(),
2692
+ ]);
2693
+ }
2694
+ catch (e) {
2695
+ return this.formatString(className, message);
2696
+ }
2697
+ }
2698
+ formatString(klass, message, backtrace) {
2699
+ if (backtrace) {
2700
+ return `${backtrace[0]}: ${message} (${klass})\n${backtrace[1]}`;
2701
+ }
2702
+ else {
2703
+ return `${klass}: ${message}`;
2704
+ }
2705
+ }
2706
+ }
2707
+ const checkStatusTag = (rawTag, vm, privateObject) => {
2708
+ switch (rawTag & ruby_tag_type.Mask) {
2709
+ case ruby_tag_type.None:
2710
+ break;
2711
+ case ruby_tag_type.Return:
2712
+ throw new RbError("unexpected return");
2713
+ case ruby_tag_type.Next:
2714
+ throw new RbError("unexpected next");
2715
+ case ruby_tag_type.Break:
2716
+ throw new RbError("unexpected break");
2717
+ case ruby_tag_type.Redo:
2718
+ throw new RbError("unexpected redo");
2719
+ case ruby_tag_type.Retry:
2720
+ throw new RbError("retry outside of rescue clause");
2721
+ case ruby_tag_type.Throw:
2722
+ throw new RbError("unexpected throw");
2723
+ case ruby_tag_type.Raise:
2724
+ case ruby_tag_type.Fatal:
2725
+ const error = new RbValue(vm.guest.rbErrinfo(), vm, privateObject);
2726
+ if (error.call("nil?").toString() === "true") {
2727
+ throw new RbError("no exception object");
2728
+ }
2729
+ // clear errinfo if got exception due to no rb_jump_tag
2730
+ vm.guest.rbClearErrinfo();
2731
+ throw new RbError(privateObject.exceptionFormatter.format(error, vm, privateObject));
2732
+ default:
2733
+ throw new RbError(`unknown error tag: ${rawTag}`);
2734
+ }
2735
+ };
2736
+ function wrapRbOperation(vm, body) {
2737
+ try {
2738
+ return body();
2739
+ }
2740
+ catch (e) {
2741
+ if (e instanceof RbError) {
2742
+ throw e;
2743
+ }
2744
+ // All JS exceptions triggered by Ruby code are translated to Ruby exceptions,
2745
+ // so non-RbError exceptions are unexpected.
2746
+ try {
2747
+ vm.guest.rbVmBugreport();
2748
+ }
2749
+ catch (e) {
2750
+ console.error("Tried to report internal Ruby VM state but failed: ", e);
2751
+ }
2752
+ if (e instanceof WebAssembly.RuntimeError && e.message === "unreachable") {
2753
+ const error = new RbError(`Something went wrong in Ruby VM: ${e}`);
2754
+ error.stack = e.stack;
2755
+ throw error;
2756
+ }
2757
+ else {
2758
+ throw e;
2759
+ }
2760
+ }
2761
+ }
2762
+ const callRbMethod = (vm, privateObject, recv, callee, args) => {
2763
+ const mid = vm.guest.rbIntern(callee + "\0");
2764
+ return wrapRbOperation(vm, () => {
2765
+ const [value, status] = vm.guest.rbFuncallvProtect(recv, mid, args);
2766
+ checkStatusTag(status, vm, privateObject);
2767
+ return value;
2768
+ });
2769
+ };
2770
+ const evalRbCode = (vm, privateObject, code) => {
2771
+ return wrapRbOperation(vm, () => {
2772
+ const [value, status] = vm.guest.rbEvalStringProtect(code + "\0");
2773
+ checkStatusTag(status, vm, privateObject);
2774
+ return new RbValue(value, vm, privateObject);
2775
+ });
2776
+ };
2777
+ function newRbPromise(vm, privateObject, body) {
2778
+ return new Promise((resolve, reject) => {
2779
+ const future = vm.wrap({
2780
+ resolve,
2781
+ reject: (error) => {
2782
+ const rbError = new RbError(privateObject.exceptionFormatter.format(error, vm, privateObject));
2783
+ reject(rbError);
2784
+ },
2785
+ });
2786
+ body(future);
2787
+ });
2788
+ }
2789
+ /**
2790
+ * Error class thrown by Ruby execution
2791
+ */
2792
+ class RbError extends Error {
2793
+ /**
2794
+ * @hideconstructor
2795
+ */
2796
+ constructor(message) {
2797
+ super(message);
2798
+ }
2799
+ }
2800
+ /**
2801
+ * Error class thrown by Ruby execution when it is not possible to recover.
2802
+ * This is usually caused when Ruby VM is in an inconsistent state.
2803
+ */
2804
+ class RbFatalError extends RbError {
2805
+ /**
2806
+ * @hideconstructor
2807
+ */
2808
+ constructor(message) {
2809
+ super("Ruby Fatal Error: " + message);
2810
+ }
2811
+ }
2812
+
2813
+ const DefaultRubyVM = async (rubyModule, options = {}) => {
2814
+ var _a, _b;
2815
+ const args = [];
2816
+ const env = Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}).map(([k, v]) => `${k}=${v}`);
2817
+ const fds = [
2818
+ new OpenFile(new File([])),
2819
+ new OpenFile(new File([])),
2820
+ new OpenFile(new File([])),
2821
+ new PreopenDirectory("/", new Map()),
2822
+ ];
2823
+ const wasi = new WASI(args, env, fds, { debug: false });
2824
+ const vm = new RubyVM();
2825
+ const imports = {
2826
+ wasi_snapshot_preview1: wasi.wasiImport,
2827
+ };
2828
+ vm.addToImports(imports);
2829
+ const printer = ((_b = options.consolePrint) !== null && _b !== void 0 ? _b : true) ? consolePrinter() : undefined;
2830
+ printer === null || printer === void 0 ? void 0 : printer.addToImports(imports);
2831
+ const instance = await WebAssembly.instantiate(rubyModule, imports);
2832
+ await vm.setInstance(instance);
2833
+ printer === null || printer === void 0 ? void 0 : printer.setMemory(instance.exports.memory);
2834
+ wasi.initialize(instance);
2835
+ vm.initialize();
2836
+ return {
2837
+ vm,
2838
+ wasi,
2839
+ instance,
2840
+ };
2841
+ };
2842
+
2843
+ const main$1 = async (pkg, options) => {
2844
+ const response = fetch(`assets/ruby-app.wasm`);
2845
+ const module = await compileWebAssemblyModule(response);
2846
+ const { vm } = await DefaultRubyVM(module, options);
2847
+ vm.printVersion();
2848
+ globalThis.rubyVM = vm;
2849
+ // Wait for the text/ruby script tag to be read.
2850
+ // It may take some time to read ruby+stdlib.wasm
2851
+ // and DOMContentLoaded has already been fired.
2852
+ if (document.readyState === "loading") {
2853
+ document.addEventListener("DOMContentLoaded", () => runRubyScriptsInHtml(vm));
2854
+ }
2855
+ else {
2856
+ runRubyScriptsInHtml(vm);
2857
+ }
2858
+ };
2859
+ const runRubyScriptsInHtml = async (vm) => {
2860
+ var _a, e_1, _b, _c;
2861
+ const tags = document.querySelectorAll('script[type="text/ruby"]');
2862
+ // Get Ruby scripts in parallel.
2863
+ const promisingRubyScripts = Array.from(tags).map((tag) => loadScriptAsync(tag));
2864
+ try {
2865
+ // Run Ruby scripts sequentially.
2866
+ 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) {
2867
+ _c = promisingRubyScripts_1_1.value;
2868
+ _d = false;
2869
+ const script = _c;
2870
+ if (script) {
2871
+ const { scriptContent, evalStyle } = script;
2872
+ switch (evalStyle) {
2873
+ case "async":
2874
+ vm.evalAsync(scriptContent);
2875
+ break;
2876
+ case "sync":
2877
+ vm.eval(scriptContent);
2878
+ break;
2879
+ }
2880
+ }
2881
+ }
2882
+ }
2883
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2884
+ finally {
2885
+ try {
2886
+ if (!_d && !_a && (_b = promisingRubyScripts_1.return)) await _b.call(promisingRubyScripts_1);
2887
+ }
2888
+ finally { if (e_1) throw e_1.error; }
2889
+ }
2890
+ };
2891
+ const deriveEvalStyle = (tag) => {
2892
+ const rawEvalStyle = tag.getAttribute("data-eval") || "sync";
2893
+ if (rawEvalStyle !== "async" && rawEvalStyle !== "sync") {
2894
+ console.warn(`data-eval attribute of script tag must be "async" or "sync". ${rawEvalStyle} is ignored and "sync" is used instead.`);
2895
+ return "sync";
2896
+ }
2897
+ return rawEvalStyle;
2898
+ };
2899
+ const loadScriptAsync = async (tag) => {
2900
+ const evalStyle = deriveEvalStyle(tag);
2901
+ // Inline comments can be written with the src attribute of the script tag.
2902
+ // The presence of the src attribute is checked before the presence of the inline.
2903
+ // see: https://html.spec.whatwg.org/multipage/scripting.html#inline-documentation-for-external-scripts
2904
+ if (tag.hasAttribute("src")) {
2905
+ const url = tag.getAttribute("src");
2906
+ const response = await fetch(url);
2907
+ if (response.ok) {
2908
+ return { scriptContent: await response.text(), evalStyle };
2909
+ }
2910
+ return Promise.resolve(null);
2911
+ }
2912
+ return Promise.resolve({ scriptContent: tag.innerHTML, evalStyle });
2913
+ };
2914
+ // WebAssembly.compileStreaming is a relatively new API.
2915
+ // For example, it is not available in iOS Safari 14,
2916
+ // so check whether WebAssembly.compileStreaming is available and
2917
+ // fall back to the existing implementation using WebAssembly.compile if not.
2918
+ const compileWebAssemblyModule = async function (response) {
2919
+ if (!WebAssembly.compileStreaming) {
2920
+ const buffer = await (await response).arrayBuffer();
2921
+ return WebAssembly.compile(buffer);
2922
+ }
2923
+ else {
2924
+ return WebAssembly.compileStreaming(response);
2925
+ }
2926
+ };
2927
+
2928
+ var name = "@ruby/3.3-wasm-wasi";
2929
+ var version = "2.6.0";
2930
+ var description = "Ruby 3.3 built on WASI";
2931
+ var main = "./dist/cjs/index.js";
2932
+ var module = "./dist/esm/index.js";
2933
+ var exports$1 = {
2934
+ ".": {
2935
+ browser: "./dist/esm/index.js",
2936
+ umd: "./dist/umd/index.js",
2937
+ "import": "./dist/esm/index.js",
2938
+ require: "./dist/cjs/index.js"
2939
+ },
2940
+ "./dist/*": {
2941
+ browser: "./dist/esm/*.js",
2942
+ umd: "./dist/umd/*.js",
2943
+ "import": "./dist/esm/*.js",
2944
+ require: "./dist/cjs/*.js"
2945
+ },
2946
+ "./*.wasm": {
2947
+ browser: "./*.wasm",
2948
+ umd: "./*.wasm",
2949
+ "import": "./*.wasm",
2950
+ require: "./*.wasm"
2951
+ }
2952
+ };
2953
+ var files = [
2954
+ "dist",
2955
+ "README.md"
2956
+ ];
2957
+ var scripts = {
2958
+ test: "RUBY_NPM_PACKAGE_ROOT=../ruby-3.3-wasm-wasi npm -C ../ruby-wasm-wasi run test:run",
2959
+ "build:deps": "cd ../ruby-wasm-wasi && npm run build",
2960
+ "build:static:files": "../ruby-wasm-wasi/tools/pack-static-files.sh ./dist",
2961
+ "build:static:compat": "../ruby-wasm-wasi/tools/pack-compat-shim.mjs --dist=./dist --pkg=ruby-3.3-wasm-wasi",
2962
+ "build:static": "npm run build:static:files && npm run build:static:compat",
2963
+ "build:rollup": "rollup -c rollup.config.mjs",
2964
+ build: "npm run build:deps && npm run build:static && npm run build:rollup && ../ruby-wasm-wasi/tools/post-build.sh ./dist"
2965
+ };
2966
+ var repository = "https://github.com/ruby/ruby.wasm";
2967
+ var homepage = "https://github.com/ruby/ruby.wasm/tree/main/packages/npm-packages/ruby-3.3-wasm-wasi";
2968
+ var publishConfig = {
2969
+ access: "public"
2970
+ };
2971
+ var keywords = [
2972
+ "wasm",
2973
+ "webassembly",
2974
+ "wasi",
2975
+ "ruby"
2976
+ ];
2977
+ var license = "MIT";
2978
+ var dependencies = {
2979
+ "@ruby/wasm-wasi": "^2.0.0"
2980
+ };
2981
+ var _package = {
2982
+ name: name,
2983
+ version: version,
2984
+ description: description,
2985
+ main: main,
2986
+ module: module,
2987
+ exports: exports$1,
2988
+ files: files,
2989
+ scripts: scripts,
2990
+ repository: repository,
2991
+ homepage: homepage,
2992
+ publishConfig: publishConfig,
2993
+ keywords: keywords,
2994
+ license: license,
2995
+ dependencies: dependencies
2996
+ };
2997
+
2998
+ var pkg = /*#__PURE__*/Object.freeze({
2999
+ __proto__: null,
3000
+ default: _package,
3001
+ dependencies: dependencies,
3002
+ description: description,
3003
+ exports: exports$1,
3004
+ files: files,
3005
+ homepage: homepage,
3006
+ keywords: keywords,
3007
+ license: license,
3008
+ main: main,
3009
+ module: module,
3010
+ name: name,
3011
+ publishConfig: publishConfig,
3012
+ repository: repository,
3013
+ scripts: scripts,
3014
+ version: version
3015
+ });
3016
+
3017
+ main$1(pkg);
3018
+
3019
+ })();