krillplayer-plugin 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +24 -0
- package/README.md +85 -2
- package/bin/krillplayer-plugin.js +13 -0
- package/dist/cli.js +5309 -0
- package/dist/engine/engine.c +140 -0
- package/kernel/Sources/CQuickJS/include/kernel_qjs.h +47 -0
- package/kernel/Sources/CQuickJS/kernel_qjs.c +407 -0
- package/kernel/Sources/CQuickJS/quickjs_vendor.c +8 -0
- package/kernel/Sources/CQuickJS/vendor/LICENSE +24 -0
- package/kernel/Sources/CQuickJS/vendor/builtin-array-fromasync.h +121 -0
- package/kernel/Sources/CQuickJS/vendor/builtin-iterator-zip-keyed.h +313 -0
- package/kernel/Sources/CQuickJS/vendor/builtin-iterator-zip.h +321 -0
- package/kernel/Sources/CQuickJS/vendor/cutils.h +2374 -0
- package/kernel/Sources/CQuickJS/vendor/dtoa.c +1619 -0
- package/kernel/Sources/CQuickJS/vendor/dtoa.h +87 -0
- package/kernel/Sources/CQuickJS/vendor/libregexp-opcode.h +73 -0
- package/kernel/Sources/CQuickJS/vendor/libregexp.c +3530 -0
- package/kernel/Sources/CQuickJS/vendor/libregexp.h +106 -0
- package/kernel/Sources/CQuickJS/vendor/libunicode-table.h +5160 -0
- package/kernel/Sources/CQuickJS/vendor/libunicode.c +2074 -0
- package/kernel/Sources/CQuickJS/vendor/libunicode.h +172 -0
- package/kernel/Sources/CQuickJS/vendor/list.h +107 -0
- package/kernel/Sources/CQuickJS/vendor/quickjs-atom.h +279 -0
- package/kernel/Sources/CQuickJS/vendor/quickjs-c-atomics.h +54 -0
- package/kernel/Sources/CQuickJS/vendor/quickjs-opcode.h +377 -0
- package/kernel/Sources/CQuickJS/vendor/quickjs.c +65536 -0
- package/kernel/Sources/CQuickJS/vendor/quickjs.h +1529 -0
- package/kernel/Sources/Kernel/PluginPrelude.js +312 -0
- package/package.json +35 -4
- package/skill/krillplayer-plugin/SKILL.md +100 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/list-next-page-passes-the-cursor-back.json +28 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/list-popular-movies.json +48 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/list-service-unavailable-fails.json +22 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/list-top-rated-series.json +68 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/list-trending-movies-by-default.json +71 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/list-unknown-values-fall-back.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/parameters.json +42 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/search-blank.json +11 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/search-movies-first.json +50 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/search-series-after-the-movies.json +50 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/cases/search-series-next-page.json +25 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/manifest.ts +12 -0
- package/skill/krillplayer-plugin/assets/samples/catalog/plugin.ts +57 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/comments-first-segment.json +77 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/comments-last-segment-stops-at-the-end.json +77 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/comments-past-the-end-empty.json +14 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/comments-segment-covering-the-position.json +77 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/comments-unknown-match-not-found.json +13 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/match-by-filename-with-spaces.json +34 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/match-by-filename-without-a-work.json +28 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/match-episode-by-absolute-number.json +25 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/match-episode-by-season-and-number.json +32 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/match-episode-not-in-the-catalog-empty.json +20 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/match-movie-by-tmdb-gives-both-cuts.json +34 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/match-nothing-to-go-on-empty.json +13 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/cases/match-unknown-work-empty.json +18 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/manifest.ts +12 -0
- package/skill/krillplayer-plugin/assets/samples/danmaku-tool/plugin.ts +72 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/folder-gone-ended.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/folder-second-page-by-cursor.json +39 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/folder-skips-files-that-are-not-media.json +36 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/folder-with-subfolder-first-page.json +52 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-empty-folder.json +11 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-gone-not-found.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-lists-subfolders-and-media.json +28 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-second-page.json +22 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-folder-skips-subtitles.json +21 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-root-first-page.json +25 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/library-root-second-page.json +22 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/list-cursor-not-a-number-starts-over.json +30 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/list-root-first-page.json +29 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/list-root-second-page.json +25 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/nested-folder-carries-ancestors.json +25 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/play-file-at-the-root.json +22 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/play-file-encodes-each-path-segment.json +22 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/cases/play-file-gone-not-found.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/manifest.ts +12 -0
- package/skill/krillplayer-plugin/assets/samples/file-share/plugin.ts +192 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/list-first-page.json +247 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/list-missing-docs.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/list-not-json.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/list-refused.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/list-second-page.json +248 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/list-server-error.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/list-skips-incomplete-items.json +225 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/play-about-bananas.json +45 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/play-http-404.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/play-no-video-files.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/play-unknown-id.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/search-bad-request.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/search-bananas.json +247 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/search-blank-query.json +11 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/cases/search-rate-limited.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/manifest.ts +14 -0
- package/skill/krillplayer-plugin/assets/samples/internet-archive/plugin.ts +85 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/channel-creator-next-page.json +99 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/channel-creator-off-air-has-no-live.json +28 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/channel-creator-on-air.json +92 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/channel-creator-replays-tab.json +69 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/channel-unknown-ended.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/collection-playlist-around-a-video.json +56 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/collection-playlist.json +78 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/list-live.json +33 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/list-videos-first-page.json +59 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/list-videos-next-page.json +64 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/parameters.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-live.json +22 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-off-air-not-started.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-replay.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-upcoming-not-started.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/play-video.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/resolve-channel-link.json +28 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/resolve-live-link.json +29 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/resolve-other-site-unclaimed.json +8 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/resolve-playlist-link.json +27 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/resolve-removed-video-unclaimed.json +8 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/resolve-video-link.json +34 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/search-creator-live-playlist-and-videos.json +115 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/search-off-air-room.json +47 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/cases/status-live-id-comes-from-the-plugin.json +28 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/manifest.ts +12 -0
- package/skill/krillplayer-plugin/assets/samples/live-video-platform/plugin.ts +123 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/collection-box-set.json +80 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/collection-empty-subfolder.json +25 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/collection-folder-has-a-subfolder-and-files.json +53 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/collection-season-around-a-removed-episode-ended.json +15 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/collection-season-around-an-episode.json +67 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/collection-season-episodes.json +89 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/collection-series-lists-seasons.json +79 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/collection-series-next-page.json +54 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/collection-unknown-ended.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-everything-first-page.json +74 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-everything-last-page.json +86 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-nothing-new.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-changes-since-a-token-with-a-removal.json +88 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-ids-first-page.json +15 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/library-ids-last-page.json +14 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/list-files.json +22 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/list-movies-first-page.json +69 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/list-movies-next-page.json +30 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/list-shows.json +27 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/parameters.json +27 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/play-episode.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/play-file-without-duration.json +22 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/play-movie-version.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/play-movie.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/play-unknown-ended.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/search-across-kinds.json +81 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/cases/search-blank.json +11 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/manifest.ts +12 -0
- package/skill/krillplayer-plugin/assets/samples/media-server/plugin.ts +167 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/album-compilation-has-no-album-artist.json +63 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/album-songs-in-disc-order.json +117 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/artist-lists-albums-and-top-songs.json +103 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/artist-unknown-not-found.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/list-artists.json +32 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/list-newest-albums-first-page.json +51 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/list-past-the-end.json +13 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/list-playlists.json +22 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/list-stations-are-channels.json +28 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/list-unknown-section-not-found.json +13 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/play-song.json +24 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/play-station.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/play-unknown-not-found.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/playlist-first-page.json +67 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/playlist-next-page.json +48 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/cases/sections-lists-every-kind.json +28 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/manifest.ts +12 -0
- package/skill/krillplayer-plugin/assets/samples/music-library/plugin.ts +120 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/folder-gone-not-found.json +60 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/folder-nested-carries-ancestors.json +74 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/folder-second-page-by-cursor.json +88 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/folder-skips-subtitles-and-system-files.json +101 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/folder-without-access-asks-to-log-in.json +60 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-empty-folder.json +60 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-folder-gives-size-and-modified-time.json +78 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-folder-gone-not-found.json +60 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-folder-second-page.json +71 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-read-a-range.json +62 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-read-an-info-file.json +62 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-read-file-gone-not-found.json +62 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-root.json +84 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/library-source-offline-retryable.json +61 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/list-root-first-page.json +71 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/list-root-next-page-by-the-kernel-cursor.json +83 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/list-root-page-of-only-other-files-still-has-next.json +63 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/list-root.json +96 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/list-source-offline-retryable.json +61 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/list-wrong-account-asks-to-log-in.json +61 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/play-a-folder-not-found.json +61 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/play-audio-takes-no-subtitles.json +71 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/play-file-at-the-root.json +71 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/play-file-gone-not-found.json +60 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/play-finds-subtitles-across-pages.json +88 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/play-lists-subtitles-next-to-the-video.json +87 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/play-similar-name-takes-only-its-own-subtitles.json +80 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/cases/play-without-access-asks-to-log-in.json +60 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/manifest.ts +13 -0
- package/skill/krillplayer-plugin/assets/samples/network-share/plugin.ts +122 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/channel-around-a-removed-episode-ended.json +15 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/channel-around-an-episode.json +62 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/channel-episodic-newest-first.json +57 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/channel-episodic-next-page.json +42 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/channel-serial-oldest-first.json +57 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/channel-unknown-ended.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/list-first-page.json +32 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/list-past-the-end.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/play-episode.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/play-removed-ended.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/search-next-page.json +47 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/cases/search-shows-and-episodes.json +41 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/manifest.ts +12 -0
- package/skill/krillplayer-plugin/assets/samples/podcast/plugin.ts +77 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/find-episode-by-absolute-number.json +24 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/find-episode-by-season-and-number.json +26 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/find-episode-it-does-not-have.json +17 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/find-movie-by-imdb-only.json +39 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/find-movie-by-tmdb.json +40 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/find-movie-ids-win-over-the-title.json +16 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/find-movie-title-in-another-year-has-none.json +14 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/find-movie-without-ids-by-title-and-year.json +25 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/play-episode-version.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/play-movie-version.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/cases/play-unknown-ended.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/manifest.ts +12 -0
- package/skill/krillplayer-plugin/assets/samples/resource-finder/plugin.ts +70 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/fetch-after-login-gives-the-text.json +16 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/fetch-gives-the-text.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/fetch-login-required-without-credentials.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/fetch-unknown-track-not-found.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/login-methods-fields.json +24 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-by-filename-without-a-work.json +34 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-by-hash-gives-only-that-file.json +29 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-episode-by-season-and-number.json +32 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-episode-not-in-the-catalog-empty.json +22 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-hash-wins-over-a-misleading-filename.json +27 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-language-by-primary-subtag.json +24 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-movie-by-tmdb-in-language-order.json +51 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-nothing-to-go-on-empty.json +13 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-unknown-hash-falls-back-to-the-work.json +53 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-unknown-work-empty.json +20 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/cases/search-unwanted-language-empty.json +21 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/manifest.ts +12 -0
- package/skill/krillplayer-plugin/assets/samples/subtitle-tool/plugin.ts +104 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/channel-radio-is-audio.json +33 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/channel-station.json +33 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/channel-unknown-ended.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/list-all-stations.json +81 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/list-group.json +37 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/parameters.json +31 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/play-catch-up-is-on-demand.json +23 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/play-future-programme-has-no-catch-up.json +12 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/play-live-two-lines.json +31 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/play-radio.json +31 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/schedule-future-window-has-no-items.json +24 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/schedule-past-programmes-carry-catch-up.json +58 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/schedule-several-stations-in-one-call.json +127 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/schedule-window-without-programmes.json +15 -0
- package/skill/krillplayer-plugin/assets/samples/tv/cases/search-station.json +35 -0
- package/skill/krillplayer-plugin/assets/samples/tv/manifest.ts +12 -0
- package/skill/krillplayer-plugin/assets/samples/tv/plugin.ts +81 -0
- package/skill/krillplayer-plugin/references/cases.md +86 -0
- package/skill/krillplayer-plugin/references/choosing-a-kind.md +69 -0
- package/skill/krillplayer-plugin/references/contract.d.ts +1479 -0
- package/skill/krillplayer-plugin/references/errors-and-fixes.md +117 -0
- package/templates/apple-hls/cases/list-filtered.json +24 -0
- package/templates/apple-hls/cases/list-first-page.json +35 -0
- package/templates/apple-hls/cases/list-last-page.json +25 -0
- package/templates/apple-hls/cases/parameters.json +31 -0
- package/templates/apple-hls/cases/play-bipbop.json +23 -0
- package/templates/apple-hls/cases/play-unknown.json +12 -0
- package/templates/apple-hls/cases/search-blank-query.json +11 -0
- package/templates/apple-hls/cases/search-no-match.json +11 -0
- package/templates/apple-hls/cases/search-title-ignores-case.json +22 -0
- package/templates/apple-hls/manifest.ts +12 -0
- package/templates/apple-hls/plugin.ts +77 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/* 试跑器的执行层(ADR 0012、0016):一个子进程一个插件上下文,链接 App 内核的同一份 C 封装(kernel_qjs.c)
|
|
2
|
+
* 与入库的 QuickJS-ng,按 -O2 编译(engine.ts 负责编译)。它只把内核的 C 接口原样搬到管道上,自己不做判断:
|
|
3
|
+
* 期限、内存上限与原生栈预算都由 kq_* 执行,取值由 Node 一侧按 App 内核的 PluginLimits 给。
|
|
4
|
+
*
|
|
5
|
+
* 用法: engine <内存上限字节> <原生栈预算字节>
|
|
6
|
+
* 帧(双向同一格式,整数按本机字节序,Node 一侧按小端读):
|
|
7
|
+
* tag:u8 number:f64 a_len:u32 b_len:u32 a[a_len] b[b_len]
|
|
8
|
+
* Node → 引擎:I 安装前导脚本(a),M 加载模块(a 源码,b 名字),D 分发(a JSON,b 字节块),J 跑完待执行的任务,Q 退出;
|
|
9
|
+
* number 是距期限的秒数,0 表示不设期限(与 kq_set_deadline 同义,换成本进程的单调时钟)。
|
|
10
|
+
* 引擎 → Node:R 一次操作的结果(number 是 KQ_* 状态,a 是错误文本);H 插件调宿主(a JSON,b 字节块),
|
|
11
|
+
* 引擎阻塞到 Node 回 h(a JSON,b 字节块)或 e(a 错误文本)。
|
|
12
|
+
* 跑插件的是一条 512 KiB 栈的线程,与 App 里 Swift 并发线程池的线程栈相同(ADR 0012)。 */
|
|
13
|
+
#include "kernel_qjs.h"
|
|
14
|
+
|
|
15
|
+
#include <pthread.h>
|
|
16
|
+
#include <stdio.h>
|
|
17
|
+
#include <stdlib.h>
|
|
18
|
+
#include <string.h>
|
|
19
|
+
#include <unistd.h>
|
|
20
|
+
|
|
21
|
+
typedef struct {
|
|
22
|
+
uint8_t tag;
|
|
23
|
+
double number;
|
|
24
|
+
uint8_t *a;
|
|
25
|
+
uint32_t a_len;
|
|
26
|
+
uint8_t *b;
|
|
27
|
+
uint32_t b_len;
|
|
28
|
+
} Frame;
|
|
29
|
+
|
|
30
|
+
static size_t memory_limit;
|
|
31
|
+
static size_t stack_budget;
|
|
32
|
+
|
|
33
|
+
static int read_full(void *buffer, size_t size) {
|
|
34
|
+
uint8_t *p = buffer;
|
|
35
|
+
while (size > 0) {
|
|
36
|
+
ssize_t n = read(STDIN_FILENO, p, size);
|
|
37
|
+
if (n <= 0) return -1;
|
|
38
|
+
p += n;
|
|
39
|
+
size -= (size_t)n;
|
|
40
|
+
}
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static int write_full(const void *buffer, size_t size) {
|
|
45
|
+
const uint8_t *p = buffer;
|
|
46
|
+
while (size > 0) {
|
|
47
|
+
ssize_t n = write(STDOUT_FILENO, p, size);
|
|
48
|
+
if (n <= 0) return -1;
|
|
49
|
+
p += n;
|
|
50
|
+
size -= (size_t)n;
|
|
51
|
+
}
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* a 与 b 各多分配一个 0 字节:JS_Eval 要求源码以 0 结尾。 */
|
|
56
|
+
static int read_frame(Frame *frame) {
|
|
57
|
+
uint8_t header[17];
|
|
58
|
+
if (read_full(header, sizeof header)) return -1;
|
|
59
|
+
frame->tag = header[0];
|
|
60
|
+
memcpy(&frame->number, header + 1, 8);
|
|
61
|
+
memcpy(&frame->a_len, header + 9, 4);
|
|
62
|
+
memcpy(&frame->b_len, header + 13, 4);
|
|
63
|
+
frame->a = malloc((size_t)frame->a_len + 1);
|
|
64
|
+
frame->b = malloc((size_t)frame->b_len + 1);
|
|
65
|
+
if (!frame->a || !frame->b || read_full(frame->a, frame->a_len) || read_full(frame->b, frame->b_len)) return -1;
|
|
66
|
+
frame->a[frame->a_len] = 0;
|
|
67
|
+
frame->b[frame->b_len] = 0;
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static void write_frame(uint8_t tag, double number, const void *a, size_t a_len, const void *b, size_t b_len) {
|
|
72
|
+
uint8_t header[17];
|
|
73
|
+
uint32_t a32 = (uint32_t)a_len, b32 = (uint32_t)b_len;
|
|
74
|
+
header[0] = tag;
|
|
75
|
+
memcpy(header + 1, &number, 8);
|
|
76
|
+
memcpy(header + 9, &a32, 4);
|
|
77
|
+
memcpy(header + 13, &b32, 4);
|
|
78
|
+
if (write_full(header, sizeof header) || write_full(a, a_len) || write_full(b, b_len)) exit(3);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* Node 关了管道就没有宿主了:直接退出,不让插件在没有宿主的情况下接着跑。 */
|
|
82
|
+
static void host(void *opaque, const char *json, size_t json_len, const uint8_t *blob, size_t blob_len, KQReply *reply) {
|
|
83
|
+
(void)opaque;
|
|
84
|
+
write_frame('H', 0, json, json_len, blob, blob_len);
|
|
85
|
+
Frame frame;
|
|
86
|
+
if (read_frame(&frame)) exit(3);
|
|
87
|
+
if (frame.tag == 'h') {
|
|
88
|
+
reply->json = (char *)frame.a;
|
|
89
|
+
reply->json_len = frame.a_len;
|
|
90
|
+
reply->blob = frame.b;
|
|
91
|
+
reply->blob_len = frame.b_len;
|
|
92
|
+
} else {
|
|
93
|
+
reply->error = (char *)frame.a;
|
|
94
|
+
free(frame.b);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static void *serve(void *unused) {
|
|
99
|
+
(void)unused;
|
|
100
|
+
KQContext *q = kq_new(memory_limit, stack_budget, host, NULL);
|
|
101
|
+
for (;;) {
|
|
102
|
+
Frame frame;
|
|
103
|
+
if (read_frame(&frame)) exit(3);
|
|
104
|
+
if (frame.tag == 'Q') exit(0);
|
|
105
|
+
char *error = NULL;
|
|
106
|
+
int status = KQ_OUT_OF_MEMORY;
|
|
107
|
+
if (q) {
|
|
108
|
+
kq_set_deadline(q, frame.number > 0 ? kq_monotonic_seconds() + frame.number : 0);
|
|
109
|
+
switch (frame.tag) {
|
|
110
|
+
case 'I': status = kq_install(q, (const char *)frame.a, frame.a_len, &error); break;
|
|
111
|
+
case 'M': status = kq_load_module(q, (const char *)frame.a, frame.a_len, (const char *)frame.b, &error); break;
|
|
112
|
+
case 'D': status = kq_dispatch(q, (const char *)frame.a, frame.a_len, frame.b, frame.b_len, &error); break;
|
|
113
|
+
case 'J': status = kq_drain(q, &error); break;
|
|
114
|
+
default: fprintf(stderr, "engine: unknown frame %c\n", frame.tag); exit(2);
|
|
115
|
+
}
|
|
116
|
+
kq_set_deadline(q, 0);
|
|
117
|
+
}
|
|
118
|
+
write_frame('R', status, error ? error : "", error ? strlen(error) : 0, "", 0);
|
|
119
|
+
kq_free_error(error);
|
|
120
|
+
free(frame.a);
|
|
121
|
+
free(frame.b);
|
|
122
|
+
}
|
|
123
|
+
return NULL;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
int main(int argc, char **argv) {
|
|
127
|
+
if (argc != 3) {
|
|
128
|
+
fprintf(stderr, "usage: engine <memory-limit-bytes> <stack-budget-bytes>\n");
|
|
129
|
+
return 2;
|
|
130
|
+
}
|
|
131
|
+
memory_limit = strtoull(argv[1], NULL, 10);
|
|
132
|
+
stack_budget = strtoull(argv[2], NULL, 10);
|
|
133
|
+
pthread_attr_t attributes;
|
|
134
|
+
pthread_attr_init(&attributes);
|
|
135
|
+
pthread_attr_setstacksize(&attributes, 512 * 1024);
|
|
136
|
+
pthread_t thread;
|
|
137
|
+
if (pthread_create(&thread, &attributes, serve, NULL)) return 1;
|
|
138
|
+
pthread_join(thread, NULL);
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#ifndef KERNEL_QJS_H
|
|
2
|
+
#define KERNEL_QJS_H
|
|
3
|
+
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
|
|
7
|
+
/* 内核对 QuickJS-ng 的封装。Swift 只看到不透明的上下文与「JSON 文本 + 字节块」两种值。 */
|
|
8
|
+
|
|
9
|
+
typedef struct KQContext KQContext;
|
|
10
|
+
|
|
11
|
+
enum {
|
|
12
|
+
KQ_OK = 0,
|
|
13
|
+
KQ_EXCEPTION = 1,
|
|
14
|
+
KQ_INTERRUPTED = 2,
|
|
15
|
+
KQ_OUT_OF_MEMORY = 3,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/* 宿主回调的应答。各字段由宿主用 malloc 分配,引擎用完释放;error 非空时在 JS 里抛 TypeError。 */
|
|
19
|
+
typedef struct {
|
|
20
|
+
char *json;
|
|
21
|
+
size_t json_len;
|
|
22
|
+
uint8_t *blob;
|
|
23
|
+
size_t blob_len;
|
|
24
|
+
char *error;
|
|
25
|
+
} KQReply;
|
|
26
|
+
|
|
27
|
+
/* JS 调宿主:参数只在回调期间有效。 */
|
|
28
|
+
typedef void (*KQHost)(void *opaque, const char *json, size_t json_len, const uint8_t *blob, size_t blob_len,
|
|
29
|
+
KQReply *reply);
|
|
30
|
+
|
|
31
|
+
KQContext *kq_new(size_t memory_limit, size_t max_stack, KQHost host, void *opaque);
|
|
32
|
+
void kq_free(KQContext *q);
|
|
33
|
+
|
|
34
|
+
/* prelude 是一个函数表达式,以 (native, utf8Encode, utf8Decode) 调用,返回分发函数 (json, blob, namespace)。 */
|
|
35
|
+
int kq_install(KQContext *q, const char *prelude, size_t len, char **error);
|
|
36
|
+
int kq_load_module(KQContext *q, const char *source, size_t len, const char *name, char **error);
|
|
37
|
+
int kq_dispatch(KQContext *q, const char *json, size_t json_len, const uint8_t *blob, size_t blob_len, char **error);
|
|
38
|
+
int kq_drain(KQContext *q, char **error);
|
|
39
|
+
|
|
40
|
+
/* 单调时钟秒数;0 表示不设期限。中断处理函数到期后中断执行,插件捕获不到。 */
|
|
41
|
+
void kq_set_deadline(KQContext *q, double deadline);
|
|
42
|
+
double kq_monotonic_seconds(void);
|
|
43
|
+
/* 只给测试用:把这个进程里的单调时钟往前拨 seconds 秒(#562)。期限与网络等待都按它算,拨过期限的调用在下一次中断检查时到期。 */
|
|
44
|
+
void kq_skip_clock(double seconds);
|
|
45
|
+
void kq_free_error(char *error);
|
|
46
|
+
|
|
47
|
+
#endif
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
#include "kernel_qjs.h"
|
|
2
|
+
#include "vendor/quickjs.h"
|
|
3
|
+
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
/* 试跑器在作者机器上用同一份源码现编(plugins/trial-runner/engine.ts),Linux 上没有 malloc_size。 */
|
|
6
|
+
#if defined(__APPLE__)
|
|
7
|
+
#include <malloc/malloc.h>
|
|
8
|
+
#else
|
|
9
|
+
#include <malloc.h>
|
|
10
|
+
#define malloc_size malloc_usable_size
|
|
11
|
+
#endif
|
|
12
|
+
#include <string.h>
|
|
13
|
+
#include <time.h>
|
|
14
|
+
#include <stdatomic.h>
|
|
15
|
+
|
|
16
|
+
/* 引擎的全部分配都经这里计数。超过上限的那一次分配失败,并留下标记:插件即使捕获了 out of memory,内核也照样停用它。 */
|
|
17
|
+
typedef struct {
|
|
18
|
+
size_t used;
|
|
19
|
+
size_t limit;
|
|
20
|
+
bool exceeded;
|
|
21
|
+
} KQHeap;
|
|
22
|
+
|
|
23
|
+
struct KQContext {
|
|
24
|
+
KQHeap heap;
|
|
25
|
+
JSRuntime *rt;
|
|
26
|
+
JSContext *ctx;
|
|
27
|
+
KQHost host;
|
|
28
|
+
void *opaque;
|
|
29
|
+
double deadline;
|
|
30
|
+
bool interrupted;
|
|
31
|
+
JSValue dispatch;
|
|
32
|
+
JSValue namespace;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
static bool heap_allows(KQHeap *heap, size_t size) {
|
|
36
|
+
if (heap->limit != 0 && heap->used + size > heap->limit) {
|
|
37
|
+
heap->exceeded = true;
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static void *heap_admit(KQHeap *heap, void *ptr) {
|
|
44
|
+
if (ptr) heap->used += malloc_size(ptr);
|
|
45
|
+
return ptr;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static void *heap_calloc(void *opaque, size_t count, size_t size) {
|
|
49
|
+
if (size != 0 && count > SIZE_MAX / size) return NULL;
|
|
50
|
+
if (!heap_allows(opaque, count * size)) return NULL;
|
|
51
|
+
return heap_admit(opaque, calloc(count, size));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static void *heap_malloc(void *opaque, size_t size) {
|
|
55
|
+
if (!heap_allows(opaque, size)) return NULL;
|
|
56
|
+
return heap_admit(opaque, malloc(size));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static void heap_free(void *opaque, void *ptr) {
|
|
60
|
+
if (!ptr) return;
|
|
61
|
+
KQHeap *heap = opaque;
|
|
62
|
+
heap->used -= malloc_size(ptr);
|
|
63
|
+
free(ptr);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static void *heap_realloc(void *opaque, void *ptr, size_t size) {
|
|
67
|
+
if (!ptr) return heap_malloc(opaque, size);
|
|
68
|
+
KQHeap *heap = opaque;
|
|
69
|
+
size_t old = malloc_size(ptr);
|
|
70
|
+
if (size > old && !heap_allows(heap, size - old)) return NULL;
|
|
71
|
+
void *grown = realloc(ptr, size);
|
|
72
|
+
if (!grown) return NULL;
|
|
73
|
+
heap->used = heap->used - old + malloc_size(grown);
|
|
74
|
+
return grown;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static size_t heap_usable_size(const void *ptr) { return malloc_size(ptr); }
|
|
78
|
+
|
|
79
|
+
static const JSMallocFunctions heap_functions = {
|
|
80
|
+
heap_calloc, heap_malloc, heap_free, heap_realloc, heap_usable_size,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/* 测试拨过的秒数(kq_skip_clock),只增不减,加在单调时钟上。 */
|
|
84
|
+
static _Atomic(double) skipped_seconds = 0;
|
|
85
|
+
|
|
86
|
+
double kq_monotonic_seconds(void) {
|
|
87
|
+
struct timespec ts;
|
|
88
|
+
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
89
|
+
return (double)ts.tv_sec + (double)ts.tv_nsec / 1e9 + atomic_load(&skipped_seconds);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
void kq_skip_clock(double seconds) {
|
|
93
|
+
double old = atomic_load(&skipped_seconds);
|
|
94
|
+
while (seconds > 0 && !atomic_compare_exchange_weak(&skipped_seconds, &old, old + seconds)) {
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static int interrupt_handler(JSContext *ctx, void *opaque) {
|
|
99
|
+
(void)ctx;
|
|
100
|
+
KQContext *q = opaque;
|
|
101
|
+
if (q->deadline > 0 && kq_monotonic_seconds() > q->deadline) {
|
|
102
|
+
q->interrupted = true;
|
|
103
|
+
return 1;
|
|
104
|
+
}
|
|
105
|
+
return 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* JS 字符串转 UTF-8。QuickJS 把落单的代理项编成 WTF-8,这里换成 U+FFFD(同为 3 字节),与 TextEncoder 和 JSON 一致。 */
|
|
109
|
+
static char *utf8_copy(JSContext *ctx, JSValueConst value, size_t *len) {
|
|
110
|
+
const char *raw = JS_ToCStringLen(ctx, len, value);
|
|
111
|
+
if (!raw) return NULL;
|
|
112
|
+
char *out = malloc(*len + 1);
|
|
113
|
+
if (!out) {
|
|
114
|
+
JS_FreeCString(ctx, raw);
|
|
115
|
+
JS_ThrowOutOfMemory(ctx);
|
|
116
|
+
return NULL;
|
|
117
|
+
}
|
|
118
|
+
memcpy(out, raw, *len + 1);
|
|
119
|
+
JS_FreeCString(ctx, raw);
|
|
120
|
+
for (size_t i = 0; i + 2 < *len; i++) {
|
|
121
|
+
unsigned char *p = (unsigned char *)out + i;
|
|
122
|
+
if (p[0] == 0xED && p[1] >= 0xA0 && p[1] <= 0xBF) {
|
|
123
|
+
p[0] = 0xEF;
|
|
124
|
+
p[1] = 0xBF;
|
|
125
|
+
p[2] = 0xBD;
|
|
126
|
+
i += 2;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static const uint8_t *bytes_of(JSContext *ctx, JSValueConst value, size_t *len) {
|
|
133
|
+
*len = 0;
|
|
134
|
+
uint8_t *bytes = JS_GetUint8Array(ctx, len, value);
|
|
135
|
+
if (!bytes && JS_HasException(ctx)) return NULL;
|
|
136
|
+
return bytes ? bytes : (const uint8_t *)"";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* WHATWG Encoding 标准的 UTF-8 解码:非法序列按最长合法前缀替换成 U+FFFD;fatal 时抛 TypeError。 */
|
|
140
|
+
static JSValue utf8_decode(JSContext *ctx, const uint8_t *in, size_t len, bool fatal, bool ignore_bom) {
|
|
141
|
+
uint8_t *out = malloc(len * 3 + 1);
|
|
142
|
+
if (!out) return JS_ThrowOutOfMemory(ctx);
|
|
143
|
+
size_t n = 0, start = 0;
|
|
144
|
+
unsigned needed = 0, seen = 0;
|
|
145
|
+
uint8_t lower = 0x80, upper = 0xBF;
|
|
146
|
+
for (size_t i = 0; i <= len; i++) {
|
|
147
|
+
bool error = false;
|
|
148
|
+
if (i == len) {
|
|
149
|
+
error = needed != 0;
|
|
150
|
+
} else if (needed == 0) {
|
|
151
|
+
uint8_t b = in[i];
|
|
152
|
+
start = i;
|
|
153
|
+
if (b <= 0x7F) {
|
|
154
|
+
out[n++] = b;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (b >= 0xC2 && b <= 0xDF) {
|
|
158
|
+
needed = 1;
|
|
159
|
+
} else if (b >= 0xE0 && b <= 0xEF) {
|
|
160
|
+
if (b == 0xE0) lower = 0xA0;
|
|
161
|
+
if (b == 0xED) upper = 0x9F;
|
|
162
|
+
needed = 2;
|
|
163
|
+
} else if (b >= 0xF0 && b <= 0xF4) {
|
|
164
|
+
if (b == 0xF0) lower = 0x90;
|
|
165
|
+
if (b == 0xF4) upper = 0x8F;
|
|
166
|
+
needed = 3;
|
|
167
|
+
} else {
|
|
168
|
+
error = true;
|
|
169
|
+
}
|
|
170
|
+
} else if (in[i] < lower || in[i] > upper) {
|
|
171
|
+
error = true;
|
|
172
|
+
i--;
|
|
173
|
+
} else {
|
|
174
|
+
lower = 0x80;
|
|
175
|
+
upper = 0xBF;
|
|
176
|
+
if (++seen == needed) {
|
|
177
|
+
memcpy(out + n, in + start, needed + 1);
|
|
178
|
+
n += needed + 1;
|
|
179
|
+
needed = seen = 0;
|
|
180
|
+
}
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (!error) continue;
|
|
184
|
+
if (fatal) {
|
|
185
|
+
free(out);
|
|
186
|
+
return JS_ThrowTypeError(ctx, "The encoded data was not valid utf-8");
|
|
187
|
+
}
|
|
188
|
+
needed = seen = 0;
|
|
189
|
+
lower = 0x80;
|
|
190
|
+
upper = 0xBF;
|
|
191
|
+
out[n++] = 0xEF;
|
|
192
|
+
out[n++] = 0xBF;
|
|
193
|
+
out[n++] = 0xBD;
|
|
194
|
+
}
|
|
195
|
+
size_t skip = !ignore_bom && n >= 3 && out[0] == 0xEF && out[1] == 0xBB && out[2] == 0xBF ? 3 : 0;
|
|
196
|
+
JSValue result = JS_NewStringLen(ctx, (const char *)out + skip, n - skip);
|
|
197
|
+
free(out);
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
static JSValue js_native(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
|
|
202
|
+
(void)this_val;
|
|
203
|
+
(void)argc;
|
|
204
|
+
KQContext *q = JS_GetContextOpaque(ctx);
|
|
205
|
+
size_t json_len = 0, blob_len = 0;
|
|
206
|
+
char *json = utf8_copy(ctx, argv[0], &json_len);
|
|
207
|
+
if (!json) return JS_EXCEPTION;
|
|
208
|
+
const uint8_t *blob = bytes_of(ctx, argv[1], &blob_len);
|
|
209
|
+
if (!blob) {
|
|
210
|
+
free(json);
|
|
211
|
+
return JS_EXCEPTION;
|
|
212
|
+
}
|
|
213
|
+
KQReply reply = {0};
|
|
214
|
+
q->host(q->opaque, json, json_len, blob, blob_len, &reply);
|
|
215
|
+
free(json);
|
|
216
|
+
JSValue result;
|
|
217
|
+
if (reply.error) {
|
|
218
|
+
result = JS_ThrowTypeError(ctx, "%s", reply.error);
|
|
219
|
+
} else {
|
|
220
|
+
result = JS_NewArray(ctx);
|
|
221
|
+
JS_SetPropertyUint32(ctx, result, 0,
|
|
222
|
+
reply.json ? JS_NewStringLen(ctx, reply.json, reply.json_len) : JS_NewString(ctx, "null"));
|
|
223
|
+
JS_SetPropertyUint32(ctx, result, 1, JS_NewUint8ArrayCopy(ctx, reply.blob, reply.blob_len));
|
|
224
|
+
}
|
|
225
|
+
free(reply.json);
|
|
226
|
+
free(reply.blob);
|
|
227
|
+
free(reply.error);
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static JSValue js_utf8_encode(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
|
|
232
|
+
(void)this_val;
|
|
233
|
+
(void)argc;
|
|
234
|
+
size_t len = 0;
|
|
235
|
+
char *text = utf8_copy(ctx, argv[0], &len);
|
|
236
|
+
if (!text) return JS_EXCEPTION;
|
|
237
|
+
JSValue result = JS_NewUint8ArrayCopy(ctx, (const uint8_t *)text, len);
|
|
238
|
+
free(text);
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
static JSValue js_utf8_decode(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) {
|
|
243
|
+
(void)this_val;
|
|
244
|
+
(void)argc;
|
|
245
|
+
size_t len = 0;
|
|
246
|
+
const uint8_t *bytes = bytes_of(ctx, argv[0], &len);
|
|
247
|
+
if (!bytes) return JS_EXCEPTION;
|
|
248
|
+
return utf8_decode(ctx, bytes, len, JS_ToBool(ctx, argv[1]), JS_ToBool(ctx, argv[2]));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
static void enter(KQContext *q) {
|
|
252
|
+
q->interrupted = false;
|
|
253
|
+
JS_UpdateStackTop(q->rt);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
static int status_of(KQContext *q) {
|
|
257
|
+
if (q->heap.exceeded) return KQ_OUT_OF_MEMORY;
|
|
258
|
+
if (q->interrupted) return KQ_INTERRUPTED;
|
|
259
|
+
return KQ_EXCEPTION;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
static char *describe(KQContext *q, JSValueConst exception) {
|
|
263
|
+
JSContext *ctx = q->ctx;
|
|
264
|
+
const char *message = JS_ToCString(ctx, exception);
|
|
265
|
+
JSValue stack = JS_IsError(exception) ? JS_GetPropertyStr(ctx, exception, "stack") : JS_UNDEFINED;
|
|
266
|
+
const char *trace = JS_IsString(stack) ? JS_ToCString(ctx, stack) : NULL;
|
|
267
|
+
const char *text = message ? message : "exception";
|
|
268
|
+
size_t size = strlen(text) + (trace ? strlen(trace) + 1 : 0) + 1;
|
|
269
|
+
char *out = malloc(size);
|
|
270
|
+
if (out) {
|
|
271
|
+
strcpy(out, text);
|
|
272
|
+
if (trace && *trace) {
|
|
273
|
+
strcat(out, "\n");
|
|
274
|
+
strcat(out, trace);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (trace) JS_FreeCString(ctx, trace);
|
|
278
|
+
if (message) JS_FreeCString(ctx, message);
|
|
279
|
+
JS_FreeValue(ctx, stack);
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
static int fail(KQContext *q, char **error) {
|
|
284
|
+
JSValue exception = JS_GetException(q->ctx);
|
|
285
|
+
int status = status_of(q);
|
|
286
|
+
*error = describe(q, exception);
|
|
287
|
+
JS_FreeValue(q->ctx, exception);
|
|
288
|
+
return status;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
static int settle(KQContext *q, char **error) {
|
|
292
|
+
if (q->heap.exceeded || q->interrupted) {
|
|
293
|
+
*error = NULL;
|
|
294
|
+
return status_of(q);
|
|
295
|
+
}
|
|
296
|
+
return KQ_OK;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
KQContext *kq_new(size_t memory_limit, size_t max_stack, KQHost host, void *opaque) {
|
|
300
|
+
KQContext *q = calloc(1, sizeof(KQContext));
|
|
301
|
+
if (!q) return NULL;
|
|
302
|
+
q->heap.limit = memory_limit;
|
|
303
|
+
q->host = host;
|
|
304
|
+
q->opaque = opaque;
|
|
305
|
+
q->dispatch = JS_UNDEFINED;
|
|
306
|
+
q->namespace = JS_UNDEFINED;
|
|
307
|
+
q->rt = JS_NewRuntime2(&heap_functions, &q->heap);
|
|
308
|
+
if (!q->rt) {
|
|
309
|
+
free(q);
|
|
310
|
+
return NULL;
|
|
311
|
+
}
|
|
312
|
+
JS_SetMaxStackSize(q->rt, max_stack);
|
|
313
|
+
JS_SetInterruptHandler(q->rt, interrupt_handler, q);
|
|
314
|
+
q->ctx = JS_NewContextRaw(q->rt);
|
|
315
|
+
if (!q->ctx || JS_AddIntrinsicBaseObjects(q->ctx) || JS_AddIntrinsicDate(q->ctx) || JS_AddIntrinsicEval(q->ctx) ||
|
|
316
|
+
JS_AddIntrinsicRegExp(q->ctx) || JS_AddIntrinsicJSON(q->ctx) || JS_AddIntrinsicProxy(q->ctx) ||
|
|
317
|
+
JS_AddIntrinsicMapSet(q->ctx) || JS_AddIntrinsicTypedArrays(q->ctx) || JS_AddIntrinsicPromise(q->ctx) ||
|
|
318
|
+
JS_AddIntrinsicWeakRef(q->ctx)) {
|
|
319
|
+
kq_free(q);
|
|
320
|
+
return NULL;
|
|
321
|
+
}
|
|
322
|
+
JS_SetContextOpaque(q->ctx, q);
|
|
323
|
+
return q;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
void kq_free(KQContext *q) {
|
|
327
|
+
if (!q) return;
|
|
328
|
+
if (q->ctx) {
|
|
329
|
+
JS_FreeValue(q->ctx, q->dispatch);
|
|
330
|
+
JS_FreeValue(q->ctx, q->namespace);
|
|
331
|
+
JS_FreeContext(q->ctx);
|
|
332
|
+
}
|
|
333
|
+
JS_FreeRuntime(q->rt);
|
|
334
|
+
free(q);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
int kq_install(KQContext *q, const char *prelude, size_t len, char **error) {
|
|
338
|
+
enter(q);
|
|
339
|
+
JSContext *ctx = q->ctx;
|
|
340
|
+
JSValue setup = JS_Eval(ctx, prelude, len, "<kernel>", JS_EVAL_TYPE_GLOBAL);
|
|
341
|
+
if (JS_IsException(setup)) return fail(q, error);
|
|
342
|
+
JSValue natives[3] = {
|
|
343
|
+
JS_NewCFunction(ctx, js_native, "native", 2),
|
|
344
|
+
JS_NewCFunction(ctx, js_utf8_encode, "utf8Encode", 1),
|
|
345
|
+
JS_NewCFunction(ctx, js_utf8_decode, "utf8Decode", 3),
|
|
346
|
+
};
|
|
347
|
+
JSValue dispatch = JS_Call(ctx, setup, JS_UNDEFINED, 3, natives);
|
|
348
|
+
for (int i = 0; i < 3; i++) JS_FreeValue(ctx, natives[i]);
|
|
349
|
+
JS_FreeValue(ctx, setup);
|
|
350
|
+
if (JS_IsException(dispatch)) return fail(q, error);
|
|
351
|
+
q->dispatch = dispatch;
|
|
352
|
+
return settle(q, error);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
int kq_load_module(KQContext *q, const char *source, size_t len, const char *name, char **error) {
|
|
356
|
+
enter(q);
|
|
357
|
+
JSContext *ctx = q->ctx;
|
|
358
|
+
JSValue module = JS_Eval(ctx, source, len, name, JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
|
|
359
|
+
if (JS_IsException(module)) return fail(q, error);
|
|
360
|
+
JSModuleDef *definition = JS_VALUE_GET_PTR(module);
|
|
361
|
+
JSValue evaluation = JS_EvalFunction(ctx, module);
|
|
362
|
+
if (JS_IsException(evaluation)) return fail(q, error);
|
|
363
|
+
int status = kq_drain(q, error);
|
|
364
|
+
if (status != KQ_OK) {
|
|
365
|
+
JS_FreeValue(ctx, evaluation);
|
|
366
|
+
return status;
|
|
367
|
+
}
|
|
368
|
+
if (JS_PromiseState(ctx, evaluation) == JS_PROMISE_REJECTED) {
|
|
369
|
+
JS_Throw(ctx, JS_PromiseResult(ctx, evaluation));
|
|
370
|
+
JS_FreeValue(ctx, evaluation);
|
|
371
|
+
return fail(q, error);
|
|
372
|
+
}
|
|
373
|
+
JS_FreeValue(ctx, evaluation);
|
|
374
|
+
JSValue namespace = JS_GetModuleNamespace(ctx, definition);
|
|
375
|
+
if (JS_IsException(namespace)) return fail(q, error);
|
|
376
|
+
q->namespace = namespace;
|
|
377
|
+
return settle(q, error);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
int kq_dispatch(KQContext *q, const char *json, size_t json_len, const uint8_t *blob, size_t blob_len, char **error) {
|
|
381
|
+
enter(q);
|
|
382
|
+
JSContext *ctx = q->ctx;
|
|
383
|
+
JSValue args[3] = {
|
|
384
|
+
JS_NewStringLen(ctx, json, json_len),
|
|
385
|
+
JS_NewUint8ArrayCopy(ctx, blob, blob_len),
|
|
386
|
+
JS_DupValue(ctx, q->namespace),
|
|
387
|
+
};
|
|
388
|
+
JSValue result = JS_Call(ctx, q->dispatch, JS_UNDEFINED, 3, args);
|
|
389
|
+
for (int i = 0; i < 3; i++) JS_FreeValue(ctx, args[i]);
|
|
390
|
+
if (JS_IsException(result)) return fail(q, error);
|
|
391
|
+
JS_FreeValue(ctx, result);
|
|
392
|
+
return settle(q, error);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
int kq_drain(KQContext *q, char **error) {
|
|
396
|
+
enter(q);
|
|
397
|
+
for (;;) {
|
|
398
|
+
JSContext *job_ctx = NULL;
|
|
399
|
+
int ran = JS_ExecutePendingJob(q->rt, &job_ctx);
|
|
400
|
+
if (ran == 0) return settle(q, error);
|
|
401
|
+
if (ran < 0) return fail(q, error);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
void kq_set_deadline(KQContext *q, double deadline) { q->deadline = deadline; }
|
|
406
|
+
|
|
407
|
+
void kq_free_error(char *error) { free(error); }
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* 入库的 QuickJS-ng 源码在这一个编译单元里编译(上游的 amalgam 也是这样合并的)。
|
|
2
|
+
* 上游大量 64 位到 32 位的隐式截断会触发 SwiftPM 默认开的 -Wshorten-64-to-32,不改上游源码,只在这里关掉。 */
|
|
3
|
+
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
|
|
4
|
+
|
|
5
|
+
#include "vendor/dtoa.c"
|
|
6
|
+
#include "vendor/libregexp.c"
|
|
7
|
+
#include "vendor/libunicode.c"
|
|
8
|
+
#include "vendor/quickjs.c"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2026 Fabrice Bellard
|
|
4
|
+
Copyright (c) 2017-2024 Charlie Gordon
|
|
5
|
+
Copyright (c) 2023-2026 Ben Noordhuis
|
|
6
|
+
Copyright (c) 2023-2026 Saúl Ibarra Corretgé
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
21
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|