diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f72d76da0..ca61e63a49 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -213,6 +213,41 @@ jobs: - name: Run yarn test262 run: exit 0 # TODO remove test262 from required tests for CI + test-hermes: + name: test-hermes + + # begin macro + + runs-on: ${{ matrix.platform }} + strategy: + fail-fast: false + matrix: + platform: [ubuntu-latest] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + # without this, setup-node errors on mismatched yarn versions + - run: corepack enable + + - name: Use Node.js 22.x + uses: actions/setup-node@v4 + with: + node-version: 22.x + cache: yarn + + - name: Install dependencies + run: yarn install --immutable + + # end macro + + - name: Run yarn build + run: yarn build + + - name: Run SES/Hermes smoke test + run: cd packages/ses && yarn test:hermes + viable-release: name: viable-release diff --git a/packages/ses/package.json b/packages/ses/package.json index e3eb14efa8..a7bb6b601b 100644 --- a/packages/ses/package.json +++ b/packages/ses/package.json @@ -78,6 +78,7 @@ "prepare": "npm run clean && npm run build", "qt": "ava", "test": "tsd && ava", + "test:hermes": "./scripts/hermes-test.sh", "test:xs": "xst dist/ses.umd.js test/_lockdown-safe.js", "postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'" }, @@ -97,6 +98,7 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-import": "^2.29.1", + "hermes-engine-cli": "^0.12.0", "prettier": "^3.3.3", "terser": "^5.16.6", "tsd": "^0.31.2", diff --git a/packages/ses/scripts/hermes-test.sh b/packages/ses/scripts/hermes-test.sh new file mode 100755 index 0000000000..2fdfa1688b --- /dev/null +++ b/packages/ses/scripts/hermes-test.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# Creates a JS smoke test to be compiled into Hermes bytecode (hbc). +# +# Usage: scripts/hermes-test.sh + +set -ueo pipefail + +DIR=$(dirname -- "${BASH_SOURCE[0]}") +cd "$DIR/.." + +OS="$(uname -s)" + +case "$OS" in + Linux*) + OS_DIR="linux64-bin" + ;; + Darwin*) + OS_DIR="osx-bin" + ;; + CYGWIN*|MINGW*|MSYS*) + OS_DIR="win64-bin" + ;; + *) + echo "Unsupported OS: $OS" + exit 1 + ;; +esac + +HERMESC="../../node_modules/hermes-engine-cli/$OS_DIR/hermesc" +HERMES="../../node_modules/hermes-engine-cli/$OS_DIR/hermes" + +echo "Concatenating: dist/ses-hermes.cjs + test/_hermes-smoke.js" +cat dist/ses-hermes.cjs test/_hermes-smoke.js > test/_hermes-smoke-dist.js +echo "Generated: test/_hermes-smoke-dist.js" + +# Errors on async arrow functions and async generators +# Both are unsupported on Hermes +echo "Executing: test/_hermes-smoke-dist.js on Hermes compiler" +$HERMESC test/_hermes-smoke-dist.js -emit-binary -out test/_hermes-smoke-dist.hbc +echo "Generated: test/_hermes-smoke-dist.hbc" +echo "Hermes compiler done" + +# TODO: Disabled until https://github.com/endojs/endo/issues/1891 complete +# echo "Executing generated bytecode file on Hermes VM" +# $HERMES -b test/_hermes-smoke-dist.hbc +# echo "Hermes VM done" +echo "Skipping: Hermes VM" + +echo "Hermes tests complete" + +echo "Removing: test/_hermes-smoke-dist.js" +rm test/_hermes-smoke-dist.js +echo "Removing: test/_hermes-smoke-dist.hbc" +rm test/_hermes-smoke-dist.hbc diff --git a/packages/ses/test/_hermes-smoke.js b/packages/ses/test/_hermes-smoke.js new file mode 100644 index 0000000000..0663956080 --- /dev/null +++ b/packages/ses/test/_hermes-smoke.js @@ -0,0 +1,49 @@ +// Hermes doesn't support native I/O, +// so we concat the SES shim above, +// when running this test on Hermes. + +/** + * Test calling SES lockdown. + */ +const testLockdown = () => { + lockdown(); +}; + +/** + * TODO: Test creating a new Compartment. + */ +// eslint-disable-next-line no-unused-vars +const testCompartment = () => { + // eslint-disable-next-line no-unused-vars + const c = new Compartment(); +}; + +/** + * TODO: Test Compartment import hook and resolve hook. + */ +// eslint-disable-next-line no-unused-vars +async function testCompartmentHooks() { + const resolveHook = a => a; + + async function importHook() { + return { + imports: [], + exports: ['meaning'], + execute(exports) { + exports.meaning = 42; + }, + }; + } + + const compartment = new Compartment({}, {}, { resolveHook, importHook }); + + const module = compartment.module('.'); + + const { + namespace: { _meaning }, + } = await compartment.import('.'); + + assert(module); +} + +testLockdown(); diff --git a/yarn.lock b/yarn.lock index dbf81d4412..68f3ea22af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1079,6 +1079,15 @@ __metadata: languageName: node linkType: hard +"@jest/schemas@npm:^29.4.3": + version: 29.4.3 + resolution: "@jest/schemas@npm:29.4.3" + dependencies: + "@sinclair/typebox": "npm:^0.25.16" + checksum: 10c0/8a35967cec454d1de2d5a58ab99b49a0ff798d1dce2d817bdd9960bb2f070493f767fbbf419e6a263860d3b1ef1e50ab609a76ae21b5f8c09bb0859e8f51a098 + languageName: node + linkType: hard + "@jest/schemas@npm:^29.6.3": version: 29.6.3 resolution: "@jest/schemas@npm:29.6.3" @@ -2006,6 +2015,13 @@ __metadata: languageName: node linkType: hard +"@sinclair/typebox@npm:^0.25.16": + version: 0.25.24 + resolution: "@sinclair/typebox@npm:0.25.24" + checksum: 10c0/2faf9878f3a65a1f2855add80b0fe8c6fe83f084ea1ab432fa7506e7c85c55ae121c4af516d089b5737f5fad23b3628fcc83a6a5df29030c3f611185ce0388ac + languageName: node + linkType: hard + "@sinclair/typebox@npm:^0.27.8": version: 0.27.8 resolution: "@sinclair/typebox@npm:0.27.8" @@ -2461,7 +2477,16 @@ __metadata: languageName: node linkType: hard -"acorn@npm:^8.11.3, acorn@npm:^8.12.0, acorn@npm:^8.2.4, acorn@npm:^8.5.0, acorn@npm:^8.6.0, acorn@npm:^8.9.0": +"acorn@npm:^8.11.3, acorn@npm:^8.2.4, acorn@npm:^8.5.0, acorn@npm:^8.6.0, acorn@npm:^8.9.0": + version: 8.11.3 + resolution: "acorn@npm:8.11.3" + bin: + acorn: bin/acorn + checksum: 10c0/3ff155f8812e4a746fee8ecff1f227d527c4c45655bb1fad6347c3cb58e46190598217551b1500f18542d2bbe5c87120cb6927f5a074a59166fbdd9468f0a299 + languageName: node + linkType: hard + +"acorn@npm:^8.12.0": version: 8.13.0 resolution: "acorn@npm:8.13.0" bin: @@ -3800,7 +3825,7 @@ __metadata: languageName: node linkType: hard -"debug@npm:4, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.4, debug@npm:^4.3.5, debug@npm:^4.3.6": +"debug@npm:4, debug@npm:^4.3.1, debug@npm:^4.3.2, debug@npm:^4.3.4, debug@npm:^4.3.6": version: 4.3.7 resolution: "debug@npm:4.3.7" dependencies: @@ -3821,6 +3846,18 @@ __metadata: languageName: node linkType: hard +"debug@npm:^4.3.5": + version: 4.3.5 + resolution: "debug@npm:4.3.5" + dependencies: + ms: "npm:2.1.2" + peerDependenciesMeta: + supports-color: + optional: true + checksum: 10c0/082c375a2bdc4f4469c99f325ff458adad62a3fc2c482d59923c260cb08152f34e2659f72b3767db8bb2f21ca81a60a42d1019605a412132d7b9f59363a005cc + languageName: node + linkType: hard + "debug@npm:~3.1.0": version: 3.1.0 resolution: "debug@npm:3.1.0" @@ -3990,6 +4027,13 @@ __metadata: languageName: node linkType: hard +"diff-sequences@npm:^29.4.3": + version: 29.4.3 + resolution: "diff-sequences@npm:29.4.3" + checksum: 10c0/183800b9fd8523a05a3a50ade0fafe81d4b8a8ac113b077d2bc298052ccdc081e3b896f19bf65768b536daebd8169a493c4764cb70a2195e14c442c12538d121 + languageName: node + linkType: hard + "diff-sequences@npm:^29.6.3": version: 29.6.3 resolution: "diff-sequences@npm:29.6.3" @@ -5532,6 +5576,13 @@ __metadata: languageName: node linkType: hard +"hermes-engine-cli@npm:^0.12.0": + version: 0.12.0 + resolution: "hermes-engine-cli@npm:0.12.0" + checksum: 10c0/53a00336632cc7a743e9a88a5199865cf922d118f42f15bed4d2ed2fee635acd0d4d8563803b47e7c1bc2d17650281eb9188be8cfdaa25887243cfee840523be + languageName: node + linkType: hard + "hosted-git-info@npm:^2.1.4": version: 2.8.9 resolution: "hosted-git-info@npm:2.8.9" @@ -6320,7 +6371,7 @@ __metadata: languageName: node linkType: hard -"jest-diff@npm:>=29.4.3 < 30, jest-diff@npm:^29.0.3, jest-diff@npm:^29.4.1": +"jest-diff@npm:>=29.4.3 < 30, jest-diff@npm:^29.4.1": version: 29.7.0 resolution: "jest-diff@npm:29.7.0" dependencies: @@ -6332,6 +6383,25 @@ __metadata: languageName: node linkType: hard +"jest-diff@npm:^29.0.3": + version: 29.5.0 + resolution: "jest-diff@npm:29.5.0" + dependencies: + chalk: "npm:^4.0.0" + diff-sequences: "npm:^29.4.3" + jest-get-type: "npm:^29.4.3" + pretty-format: "npm:^29.5.0" + checksum: 10c0/00fda597fa6ee22774453c3cd35c2210bd7f749cf48ad7a41c13b898b2943c9c047842720eb928cdb949b9de87204d8d8987bf12aefdb2f0504f5f4112cab5b0 + languageName: node + linkType: hard + +"jest-get-type@npm:^29.4.3": + version: 29.4.3 + resolution: "jest-get-type@npm:29.4.3" + checksum: 10c0/874b0ced6b1cc677ff7fcf0dc86d02674617a7d0b73d47097604fb3ca460178d16104efdd3837e8b8bf0520ad5d210838c07483b058802b457b8413e60628fd0 + languageName: node + linkType: hard + "jest-get-type@npm:^29.6.3": version: 29.6.3 resolution: "jest-get-type@npm:29.6.3" @@ -7056,7 +7126,7 @@ __metadata: languageName: node linkType: hard -"minimatch@npm:6 || 7 || 8 || 9, minimatch@npm:^9.0.0, minimatch@npm:^9.0.1, minimatch@npm:^9.0.4, minimatch@npm:^9.0.5": +"minimatch@npm:6 || 7 || 8 || 9, minimatch@npm:^9.0.0, minimatch@npm:^9.0.4, minimatch@npm:^9.0.5": version: 9.0.5 resolution: "minimatch@npm:9.0.5" dependencies: @@ -7101,6 +7171,15 @@ __metadata: languageName: node linkType: hard +"minimatch@npm:^9.0.1": + version: 9.0.4 + resolution: "minimatch@npm:9.0.4" + dependencies: + brace-expansion: "npm:^2.0.1" + checksum: 10c0/2c16f21f50e64922864e560ff97c587d15fd491f65d92a677a344e970fe62aafdbeafe648965fa96d33c061b4d0eabfe0213466203dd793367e7f28658cf6414 + languageName: node + linkType: hard + "minimist-options@npm:4.1.0": version: 4.1.0 resolution: "minimist-options@npm:4.1.0" @@ -7179,6 +7258,15 @@ __metadata: languageName: node linkType: hard +"minipass@npm:^4.0.0": + version: 4.0.0 + resolution: "minipass@npm:4.0.0" + dependencies: + yallist: "npm:^4.0.0" + checksum: 10c0/ea9a3eee82a33899693db3c25333ce15d1a900bb7ef47aa97d44db91d293bcbd9a3c5127da617b92844411fcaf6270c37f79755bbcbe11e5d329f60bad6d7229 + languageName: node + linkType: hard + "minipass@npm:^4.2.4": version: 4.2.8 resolution: "minipass@npm:4.2.8" @@ -7275,6 +7363,13 @@ __metadata: languageName: node linkType: hard +"ms@npm:2.1.2": + version: 2.1.2 + resolution: "ms@npm:2.1.2" + checksum: 10c0/a437714e2f90dbf881b5191d35a6db792efbca5badf112f87b9e1c712aace4b4b9b742dd6537f3edf90fd6f684de897cec230abde57e87883766712ddda297cc + languageName: node + linkType: hard + "ms@npm:^2.1.1, ms@npm:^2.1.3": version: 2.1.3 resolution: "ms@npm:2.1.3" @@ -8317,6 +8412,17 @@ __metadata: languageName: node linkType: hard +"pretty-format@npm:^29.5.0": + version: 29.5.0 + resolution: "pretty-format@npm:29.5.0" + dependencies: + "@jest/schemas": "npm:^29.4.3" + ansi-styles: "npm:^5.0.0" + react-is: "npm:^18.0.0" + checksum: 10c0/bcc0190d050196b64e501e5c2b44beb802d79a2b70b6fe6b24ae2d5e0f31237dfcb1f0ab2ada4678829b6ee38507ba292396301aff0a8122e575ffd45d5d037c + languageName: node + linkType: hard + "pretty-format@npm:^29.7.0": version: 29.7.0 resolution: "pretty-format@npm:29.7.0" @@ -8894,7 +9000,18 @@ __metadata: languageName: node linkType: hard -"semver@npm:^7.0.0, semver@npm:^7.1.1, semver@npm:^7.3.2, semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.5.4, semver@npm:^7.6.3": +"semver@npm:^7.0.0, semver@npm:^7.1.1, semver@npm:^7.3.2, semver@npm:^7.3.4, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.5.4": + version: 7.5.4 + resolution: "semver@npm:7.5.4" + dependencies: + lru-cache: "npm:^6.0.0" + bin: + semver: bin/semver.js + checksum: 10c0/5160b06975a38b11c1ab55950cb5b8a23db78df88275d3d8a42ccf1f29e55112ac995b3a26a522c36e3b5f76b0445f1eef70d696b8c7862a2b4303d7b0e7609e + languageName: node + linkType: hard + +"semver@npm:^7.3.8, semver@npm:^7.5.3, semver@npm:^7.6.3": version: 7.6.3 resolution: "semver@npm:7.6.3" bin: @@ -8952,6 +9069,7 @@ __metadata: eslint-config-prettier: "npm:^9.1.0" eslint-plugin-eslint-comments: "npm:^3.2.0" eslint-plugin-import: "npm:^2.29.1" + hermes-engine-cli: "npm:^0.12.0" prettier: "npm:^3.3.3" terser: "npm:^5.16.6" tsd: "npm:^0.31.2" @@ -9596,7 +9714,7 @@ __metadata: languageName: node linkType: hard -"tar@npm:6.2.1, tar@npm:^6.1.11, tar@npm:^6.1.2, tar@npm:^6.2.1": +"tar@npm:6.2.1, tar@npm:^6.2.1": version: 6.2.1 resolution: "tar@npm:6.2.1" dependencies: @@ -9610,6 +9728,20 @@ __metadata: languageName: node linkType: hard +"tar@npm:^6.1.11, tar@npm:^6.1.2": + version: 6.1.13 + resolution: "tar@npm:6.1.13" + dependencies: + chownr: "npm:^2.0.0" + fs-minipass: "npm:^2.0.0" + minipass: "npm:^4.0.0" + minizlib: "npm:^2.1.1" + mkdirp: "npm:^1.0.3" + yallist: "npm:^4.0.0" + checksum: 10c0/eee5f264f3f3c27cd8d4934f80c568470f92811c416144ab671bb36b45a8ed55fbfbbd31f0146f3eddaca91fd564c9a7ec4d2086940968b836f4a2c54146c060 + languageName: node + linkType: hard + "temp-dir@npm:1.0.0": version: 1.0.0 resolution: "temp-dir@npm:1.0.0"