|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Keep the Test262 host out of default library, CLI, and WASM builds. |
| 3 | + |
| 4 | +set -euo pipefail |
| 5 | +export LC_ALL=C |
| 6 | + |
| 7 | +script_dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd) |
| 8 | +root=$(CDPATH='' cd -- "$script_dir/.." && pwd) |
| 9 | +cd "$root" |
| 10 | + |
| 11 | +die() { |
| 12 | + echo "error: $*" >&2 |
| 13 | + exit 1 |
| 14 | +} |
| 15 | + |
| 16 | +command -v cargo >/dev/null 2>&1 || die "cargo is required" |
| 17 | +command -v python3 >/dev/null 2>&1 || die "python3 is required" |
| 18 | + |
| 19 | +metadata=$(mktemp "${TMPDIR:-/tmp}/quickjs-oxide-metadata.XXXXXX") |
| 20 | +trap 'rm -f -- "$metadata"' EXIT |
| 21 | +cargo metadata --locked --format-version 1 --no-deps > "$metadata" |
| 22 | + |
| 23 | +python3 - "$metadata" <<'PY' |
| 24 | +import json |
| 25 | +from pathlib import Path |
| 26 | +import sys |
| 27 | +
|
| 28 | +
|
| 29 | +def fail(message: str) -> None: |
| 30 | + raise SystemExit(f"error: {message}") |
| 31 | +
|
| 32 | +
|
| 33 | +metadata = json.loads(Path(sys.argv[1]).read_text()) |
| 34 | +packages = {package["name"]: package for package in metadata["packages"]} |
| 35 | +
|
| 36 | +engine = packages.get("quickjs-oxide") |
| 37 | +if engine is None: |
| 38 | + fail("cargo metadata omitted the quickjs-oxide package") |
| 39 | +if engine["features"].get("default") != []: |
| 40 | + fail("quickjs-oxide default feature set must stay empty") |
| 41 | +if engine["features"].get("test262-host") != []: |
| 42 | + fail("quickjs-oxide must expose an empty, opt-in test262-host feature") |
| 43 | +
|
| 44 | +runner = [target for target in engine["targets"] if target["name"] == "run-test262"] |
| 45 | +if len(runner) != 1: |
| 46 | + fail("cargo metadata must contain exactly one run-test262 target") |
| 47 | +if runner[0].get("required-features") != ["test262-host"]: |
| 48 | + fail("run-test262 must require exactly the test262-host feature") |
| 49 | +
|
| 50 | +host_tests = { |
| 51 | + "oracle_create_realm", |
| 52 | + "oracle_host_gc", |
| 53 | + "oracle_is_html_dda", |
| 54 | +} |
| 55 | +for target_name in host_tests: |
| 56 | + targets = [target for target in engine["targets"] if target["name"] == target_name] |
| 57 | + if len(targets) != 1: |
| 58 | + fail(f"cargo metadata must contain exactly one {target_name} target") |
| 59 | + if targets[0].get("required-features") != ["test262-host"]: |
| 60 | + fail(f"{target_name} must require exactly the test262-host feature") |
| 61 | +
|
| 62 | +web = packages.get("quickjs-oxide-web") |
| 63 | +if web is None: |
| 64 | + fail("cargo metadata omitted the quickjs-oxide-web package") |
| 65 | +engine_dependencies = [ |
| 66 | + dependency |
| 67 | + for dependency in web["dependencies"] |
| 68 | + if dependency["name"] == "quickjs-oxide" |
| 69 | +] |
| 70 | +if len(engine_dependencies) != 1: |
| 71 | + fail("WASM wrapper must have exactly one quickjs-oxide dependency") |
| 72 | +dependency = engine_dependencies[0] |
| 73 | +if dependency["uses_default_features"] or dependency["features"]: |
| 74 | + fail("WASM wrapper must disable default features and enable no dev-support feature") |
| 75 | +
|
| 76 | +feature = '#[cfg(feature = "test262-host")]' |
| 77 | +
|
| 78 | +
|
| 79 | +def require_gated(path: str, declarations: tuple[str, ...]) -> None: |
| 80 | + lines = Path(path).read_text().splitlines() |
| 81 | + for declaration in declarations: |
| 82 | + matches = [index for index, line in enumerate(lines) if line == declaration] |
| 83 | + if len(matches) != 1: |
| 84 | + fail(f"{path} must contain exactly one declaration: {declaration.strip()}") |
| 85 | + index = matches[0] |
| 86 | + attributes = [] |
| 87 | + cursor = index - 1 |
| 88 | + while cursor >= 0 and lines[cursor].strip().startswith("#["): |
| 89 | + attributes.append(lines[cursor].strip()) |
| 90 | + cursor -= 1 |
| 91 | + if feature not in attributes: |
| 92 | + fail(f"{path} must gate {declaration.strip()} with test262-host") |
| 93 | +
|
| 94 | +
|
| 95 | +require_gated( |
| 96 | + "src/runtime.rs", |
| 97 | + ( |
| 98 | + "mod test262_agent;", |
| 99 | + "mod test262_host;", |
| 100 | + "pub use self::test262_agent::{Test262AgentError, Test262AgentSession};", |
| 101 | + "use crate::heap::Test262AgentKind;", |
| 102 | + " fn call_test262_gc(&self, invocation: NativeInvocation) -> Result<Completion, RuntimeError> {", |
| 103 | + " fn set_object_is_html_dda(&self, object: &ObjectRef) -> Result<(), RuntimeError> {", |
| 104 | + " pub fn new_code_point_range_function(&mut self) -> Result<CallableRef, RuntimeError> {", |
| 105 | + " pub fn new_test262_gc_function(&mut self) -> Result<CallableRef, RuntimeError> {", |
| 106 | + ), |
| 107 | +) |
| 108 | +require_gated( |
| 109 | + "src/lib.rs", |
| 110 | + ("pub use runtime::{Test262AgentError, Test262AgentSession};",), |
| 111 | +) |
| 112 | +require_gated( |
| 113 | + "src/heap.rs", |
| 114 | + ( |
| 115 | + "pub enum Test262AgentKind {", |
| 116 | + " StringCodePointRange,", |
| 117 | + " Test262DetachArrayBuffer,", |
| 118 | + " Test262EvalScript,", |
| 119 | + " Test262CreateRealm,", |
| 120 | + " Test262IsHtmlDda,", |
| 121 | + " Test262Gc,", |
| 122 | + " Test262Agent(Test262AgentKind),", |
| 123 | + " pub(crate) fn set_object_is_html_dda(&mut self, id: ObjectId) -> Result<(), HeapError> {", |
| 124 | + ), |
| 125 | +) |
| 126 | +require_gated( |
| 127 | + "src/runtime/native_dispatch.rs", |
| 128 | + ( |
| 129 | + " NativeFunctionId::StringCodePointRange => {", |
| 130 | + " NativeFunctionId::Test262DetachArrayBuffer => {", |
| 131 | + " NativeFunctionId::Test262EvalScript => {", |
| 132 | + " NativeFunctionId::Test262CreateRealm => self.call_test262_create_realm(invocation),", |
| 133 | + " NativeFunctionId::Test262IsHtmlDda => self.call_test262_is_html_dda(invocation),", |
| 134 | + " NativeFunctionId::Test262Gc => self.call_test262_gc(invocation),", |
| 135 | + " NativeFunctionId::Test262Agent(kind) => {", |
| 136 | + ), |
| 137 | +) |
| 138 | +require_gated( |
| 139 | + "src/runtime/intrinsics/array_buffer.rs", |
| 140 | + ( |
| 141 | + " pub(in crate::runtime) fn call_test262_detach_array_buffer(", |
| 142 | + " pub fn new_detach_array_buffer_function(&mut self) -> Result<CallableRef, RuntimeError> {", |
| 143 | + ), |
| 144 | +) |
| 145 | +require_gated( |
| 146 | + "src/runtime/intrinsics/string.rs", |
| 147 | + (" pub(in crate::runtime) fn call_string_code_point_range(",), |
| 148 | +) |
| 149 | +require_gated( |
| 150 | + "src/value.rs", |
| 151 | + ( |
| 152 | + " pub(crate) fn try_with_exact_capacity(capacity: usize) -> Result<Self, JsStringError> {", |
| 153 | + ), |
| 154 | +) |
| 155 | +
|
| 156 | +gate = Path("scripts/test-test262.sh").read_text() |
| 157 | +if "--features test262-host --bin run-test262" not in gate: |
| 158 | + fail("central Test262 gate must build run-test262 with test262-host") |
| 159 | +
|
| 160 | +gc_gate = Path("scripts/test-host-gc-reentrant-oracle.sh").read_text() |
| 161 | +if "--features test262-host" not in gc_gate: |
| 162 | + fail("host GC differential must enable test262-host") |
| 163 | +
|
| 164 | +parity_gate = Path("scripts/test-parity-slice.sh").read_text() |
| 165 | +if parity_gate.count("--features test262-host") < 2: |
| 166 | + fail("parity slice must test and lint the Test262 host feature") |
| 167 | +
|
| 168 | +workflow = Path(".github/workflows/ci.yml").read_text() |
| 169 | +if "./scripts/check-test262-host-boundary.sh" not in workflow: |
| 170 | + fail("public fast CI must enforce the Test262 host boundary") |
| 171 | +
|
| 172 | +print("Test262 host feature boundary passed.") |
| 173 | +PY |
0 commit comments