From 047d643b9fbbb2979871a6f5084ecb3d485a857c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 4 Oct 2026 09:55:19 -0700 Subject: [PATCH 1/3] fix(jsc): preserve namespace marker ownership for require interop Adapt the own-property handling from oven-sh/WebKit#279 by @robobun (c28e418308d752c2ee497ca83e220594979d4f29). Create a separate live namespace facade for require(esm), leaving imports untouched and all JavaScript writes subject to namespace invariants. Facade lifetime and reuse belong to the embedder require cache. --- .../module-namespace-esmodule-marker.js | 52 ++++++++++++++++++ .../resources/namespace-esmodule-default.js | 4 ++ .../resources/namespace-esmodule-explicit.js | 2 + .../namespace-esmodule-no-default.js | 1 + .../runtime/JSModuleNamespaceObject.cpp | 54 ++++++++++++++++--- .../runtime/JSModuleNamespaceObject.h | 6 +-- Source/JavaScriptCore/tools/JSDollarVM.cpp | 13 +++++ jsc.md | 1 + 8 files changed, 123 insertions(+), 10 deletions(-) create mode 100644 JSTests/stress/module-namespace-esmodule-marker.js create mode 100644 JSTests/stress/resources/namespace-esmodule-default.js create mode 100644 JSTests/stress/resources/namespace-esmodule-explicit.js create mode 100644 JSTests/stress/resources/namespace-esmodule-no-default.js diff --git a/JSTests/stress/module-namespace-esmodule-marker.js b/JSTests/stress/module-namespace-esmodule-marker.js new file mode 100644 index 0000000000000..be1fd162a04e4 --- /dev/null +++ b/JSTests/stress/module-namespace-esmodule-marker.js @@ -0,0 +1,52 @@ +//@ requireOptions("--useDollarVM=1") + +function check(value, message) { + if (!value) + throw new Error(message); +} + +function checkMarker(namespace, value) { + check(Object.getPrototypeOf(namespace) === null, "null prototype"); + check(!Object.isExtensible(namespace), "non-extensible namespace"); + check("__esModule" in namespace, "marker in namespace"); + check(Object.prototype.hasOwnProperty.call(namespace, "__esModule"), "own marker"); + const descriptor = Object.getOwnPropertyDescriptor(namespace, "__esModule"); + check(descriptor.value === value && descriptor.writable && descriptor.enumerable && !descriptor.configurable, "marker descriptor"); + check(!Reflect.set(namespace, "__esModule", value), "set fails even for the same value"); + check(!Reflect.deleteProperty(namespace, "__esModule"), "delete fails"); + check(Reflect.defineProperty(namespace, "__esModule", { value }), "same-value define succeeds"); + for (const descriptor of [{ value: {} }, { writable: false }, { enumerable: false }, { configurable: true }, { get() {} }]) + check(!Reflect.defineProperty(namespace, "__esModule", descriptor), "invalid definition fails"); +} + +async function test() { + const namespace = await import("./resources/namespace-esmodule-default.js"); + check(!("__esModule" in namespace), "ordinary namespace has no marker"); + check(!Object.prototype.hasOwnProperty.call(namespace, "__esModule"), "no own marker"); + check(Object.getOwnPropertyDescriptor(namespace, "__esModule") === undefined, "no marker descriptor"); + check(!Reflect.set(namespace, "__esModule", true), "cannot create marker with set"); + check(!Reflect.defineProperty(namespace, "__esModule", { value: true }), "cannot create marker with defineProperty"); + // Only Bun embedders request the require(esm) facade. + if (typeof $vm.moduleNamespaceForRequire !== "function") + return; + const required = $vm.moduleNamespaceForRequire(namespace); + check(required !== namespace, "separate namespace"); + check($vm.moduleNamespaceForRequire(namespace) !== required, "fresh facade for a new require-cache entry"); + check($vm.moduleNamespaceForRequire(required) === required, "already marked facade"); + check(!("__esModule" in namespace), "import remains unmarked"); + checkMarker(required, true); + check(Reflect.ownKeys(required).map(String).join() === "Alpha,__esModule,_a,bump,default,value,zzz,Symbol(Symbol.toStringTag)", "sorted own keys"); + check(Object.getOwnPropertySymbols(required).length === 1, "marker is not a symbol"); + namespace.bump(); + check(required.value === 2 && namespace.value === 2, "live bindings"); + gc(); + check(required.value === 2, "facade survives collection"); + const explicit = await import("./resources/namespace-esmodule-explicit.js"); + check($vm.moduleNamespaceForRequire(explicit) === explicit, "explicit undefined marker retained"); + checkMarker(explicit, undefined); + const noDefault = await import("./resources/namespace-esmodule-no-default.js"); + check($vm.moduleNamespaceForRequire(noDefault) === noDefault, "no facade without default"); + check(!("__esModule" in noDefault), "no marker without default"); +} + +test().catch($vm.abort); diff --git a/JSTests/stress/resources/namespace-esmodule-default.js b/JSTests/stress/resources/namespace-esmodule-default.js new file mode 100644 index 0000000000000..9e013ebe12cf9 --- /dev/null +++ b/JSTests/stress/resources/namespace-esmodule-default.js @@ -0,0 +1,4 @@ +export default { d: 1 }; +export const Alpha = 1, _a = 2, zzz = 3; +export let value = 1; +export function bump() { value++; } diff --git a/JSTests/stress/resources/namespace-esmodule-explicit.js b/JSTests/stress/resources/namespace-esmodule-explicit.js new file mode 100644 index 0000000000000..6194da44c47f7 --- /dev/null +++ b/JSTests/stress/resources/namespace-esmodule-explicit.js @@ -0,0 +1,2 @@ +export const __esModule = undefined; +export default 1; diff --git a/JSTests/stress/resources/namespace-esmodule-no-default.js b/JSTests/stress/resources/namespace-esmodule-no-default.js new file mode 100644 index 0000000000000..efeee5db16c08 --- /dev/null +++ b/JSTests/stress/resources/namespace-esmodule-no-default.js @@ -0,0 +1 @@ +export const value = 1; diff --git a/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp b/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp index b71463daf87da..3cdc6899138d9 100644 --- a/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp +++ b/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.cpp @@ -172,8 +172,9 @@ bool JSModuleNamespaceObject::getOwnPropertySlotCommon(JSGlobalObject* globalObj auto iterator = m_exports.find(propertyName.uid()); if (iterator == m_exports.end()) { #if USE(BUN_JSC_ADDITIONS) - if (propertyName == vm.propertyNames->__esModule) { - return Base::getOwnPropertySlot(this, globalObject, propertyName, slot); + if (m_hasESModuleMarker && propertyName == vm.propertyNames->__esModule) { + slot.setValue(this, static_cast(PropertyAttribute::DontDelete), jsBoolean(true)); + return true; } #endif return false; @@ -267,8 +268,6 @@ bool JSModuleNamespaceObject::put(JSCell* cell, JSGlobalObject* globalObject, Pr auto* thisObject = uncheckedDowncast(cell); if (thisObject->m_isOverridingValue) { return true; - } else if (propertyName == vm.propertyNames->__esModule && !thisObject->m_exports.contains(propertyName.uid())) [[unlikely]] { - RELEASE_AND_RETURN(scope, Base::put(thisObject, globalObject, propertyName, value, slot)); } #endif @@ -302,6 +301,10 @@ bool JSModuleNamespaceObject::deleteProperty(JSCell* cell, JSGlobalObject* globa RETURN_IF_EXCEPTION(scope, false); } +#if USE(BUN_JSC_ADDITIONS) + if (thisObject->m_hasESModuleMarker && propertyName == vm.propertyNames->__esModule) + return false; +#endif return !thisObject->m_exports.contains(propertyName.uid()); } @@ -328,7 +331,18 @@ void JSModuleNamespaceObject::getOwnPropertyNames(JSObject* cell, JSGlobalObject thisObject->ensureDeferredNamespaceEvaluation(globalObject); RETURN_IF_EXCEPTION(scope, void()); } +#if USE(BUN_JSC_ADDITIONS) + const Identifier& esModuleIdent = vm.propertyNames->__esModule; + bool needsESModuleMarker = thisObject->m_hasESModuleMarker + && propertyNames.includeStringProperties(); +#endif for (const auto& name : thisObject->m_exports.keys()) { +#if USE(BUN_JSC_ADDITIONS) + if (needsESModuleMarker && WTF::codePointCompareLessThan(StringView(esModuleIdent.impl()), StringView(name.get()))) { + propertyNames.add(esModuleIdent); + needsESModuleMarker = false; + } +#endif if (mode == DontEnumPropertiesMode::Exclude) { // Perform [[GetOwnProperty]] to throw ReferenceError if binding is uninitialized. PropertySlot slot(cell, PropertySlot::InternalMethodType::GetOwnProperty); @@ -339,6 +353,10 @@ void JSModuleNamespaceObject::getOwnPropertyNames(JSObject* cell, JSGlobalObject } propertyNames.add(name); } +#if USE(BUN_JSC_ADDITIONS) + if (needsESModuleMarker) + propertyNames.add(esModuleIdent); +#endif if (propertyNames.includeSymbolProperties()) { scope.release(); thisObject->getOwnNonIndexPropertyNames(globalObject, propertyNames, mode); @@ -366,8 +384,6 @@ bool JSModuleNamespaceObject::defineOwnProperty(JSObject* cell, JSGlobalObject* #if USE(BUN_JSC_ADDITIONS) if (thisObject->m_isOverridingValue) { return true; - } else if (propertyName == vm.propertyNames->__esModule && !thisObject->m_exports.contains(propertyName.uid())) { - RELEASE_AND_RETURN(scope, Base::defineOwnProperty(thisObject, globalObject, propertyName, descriptor, shouldThrow)); } #endif @@ -423,6 +439,32 @@ bool JSModuleNamespaceObject::defineOwnProperty(JSObject* cell, JSGlobalObject* #if USE(BUN_JSC_ADDITIONS) +JSModuleNamespaceObject* JSModuleNamespaceObject::createNamespaceForRequire(JSGlobalObject* globalObject) +{ + VM& vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + if (m_isDeferred) [[unlikely]] { + ensureDeferredNamespaceEvaluation(globalObject); + RETURN_IF_EXCEPTION(scope, nullptr); + } + if (m_hasESModuleMarker || m_exports.contains(vm.propertyNames->__esModule.impl()) || !m_exports.contains(vm.propertyNames->defaultKeyword.impl())) + return this; + + // Node's require(esm) facade adds a marker without changing the imported namespace. + // Copy resolutions, not values, so re-exports and uninitialized/live bindings stay live. + Vector> resolutions; + resolutions.reserveInitialCapacity(m_exports.size()); + for (const auto& entry : m_exports) { + resolutions.append({ Identifier::fromUid(vm, entry.key.get()), { + AbstractModuleRecord::Resolution::Type::Resolved, entry.value.moduleRecord.get(), entry.value.localName, + } }); + } + auto* result = create(globalObject, globalObject->moduleNamespaceObjectStructure(), m_moduleRecord.get(), WTF::move(resolutions)); + RETURN_IF_EXCEPTION(scope, nullptr); + result->m_hasESModuleMarker = true; + return result; +} + void JSModuleNamespaceObject::overrideExports(JSGlobalObject* globalObject, const WTF::Function& iter) { VM& vm = globalObject->vm(); diff --git a/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.h b/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.h index 9e3e15b746a75..996afd3fa8c1b 100644 --- a/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.h +++ b/Source/JavaScriptCore/runtime/JSModuleNamespaceObject.h @@ -65,6 +65,7 @@ class JSModuleNamespaceObject final : public JSNonFinalObject { DECLARE_EXPORT_INFO; #if USE(BUN_JSC_ADDITIONS) + JS_EXPORT_PRIVATE JSModuleNamespaceObject* createNamespaceForRequire(JSGlobalObject*); bool overrideExportValue(JSGlobalObject*, PropertyName, JSValue); void overrideExports(JSGlobalObject* globalObject, const WTF::Function& iter); #endif @@ -74,10 +75,6 @@ class JSModuleNamespaceObject final : public JSNonFinalObject { AbstractModuleRecord* moduleRecord() LIFETIME_BOUND { return m_moduleRecord.get(); } -#if USE(BUN_JSC_ADDITIONS) - WTF::TriState m_hasESModuleMarker = WTF::TriState::Indeterminate; -#endif - private: JS_EXPORT_PRIVATE JSModuleNamespaceObject(VM&, Structure*, AbstractModuleRecord*, Vector>&&, bool isDeferred); JS_EXPORT_PRIVATE void finishCreation(JSGlobalObject*, bool shouldPreventExtensions); @@ -97,6 +94,7 @@ class JSModuleNamespaceObject final : public JSNonFinalObject { const bool m_isDeferred; #if USE(BUN_JSC_ADDITIONS) bool m_isOverridingValue = false; + bool m_hasESModuleMarker = false; #endif friend size_t cellSize(JSCell*); diff --git a/Source/JavaScriptCore/tools/JSDollarVM.cpp b/Source/JavaScriptCore/tools/JSDollarVM.cpp index 91a0e60f0b64b..55387bbafae7d 100644 --- a/Source/JavaScriptCore/tools/JSDollarVM.cpp +++ b/Source/JavaScriptCore/tools/JSDollarVM.cpp @@ -4287,6 +4287,18 @@ JSC_DEFINE_HOST_FUNCTION(functionGlobalObjectForObject, (JSGlobalObject*, CallFr } #if USE(BUN_JSC_ADDITIONS) +JSC_DEFINE_HOST_FUNCTION(functionModuleNamespaceForRequire, (JSGlobalObject* globalObject, CallFrame* callFrame)) +{ + DollarVMAssertScope assertScope; + auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); + auto* namespaceObject = dynamicDowncast(callFrame->argument(0)); + if (!namespaceObject) + return throwVMTypeError(globalObject, scope, "expected a module namespace"_s); + auto* result = namespaceObject->createNamespaceForRequire(globalObject); + RETURN_IF_EXCEPTION(scope, { }); + return JSValue::encode(result); +} + // The embedder's AsyncLocalStorage frame slot (JSGlobalObject::m_asyncContextData // field 0), which promise reactions and async continuations capture and restore. JSC_DEFINE_HOST_FUNCTION(functionAsyncContext, (JSGlobalObject* globalObject, CallFrame*)) @@ -6023,6 +6035,7 @@ void JSDollarVM::finishCreation(VM& vm) addFunction(vm, alwaysAllow, "decommittedMarkedBlockPagePoison"_s, functionDecommittedMarkedBlockPagePoison, 0); #if USE(BUN_JSC_ADDITIONS) addFunction(vm, alwaysAllow, "evacuateAuxiliaryBlocks"_s, functionEvacuateAuxiliaryBlocks, 2); + addFunction(vm, allowIfNotFuzz, "moduleNamespaceForRequire"_s, functionModuleNamespaceForRequire, 1); #endif addFunction(vm, allowIfNotFuzz, "globalObjectCount"_s, functionGlobalObjectCount, 0); diff --git a/jsc.md b/jsc.md index aef529dec8584..37885e91ad552 100644 --- a/jsc.md +++ b/jsc.md @@ -3,6 +3,7 @@ ## Unreleased - Fix `Intl.Segmenter` containing lookups around surrogate pairs so segment boundaries and word status agree with iteration. +- Expose the require(esm) `__esModule` marker as an own enumerable namespace property while preserving unmarked imports and live bindings. Adapts [oven-sh/WebKit#279](https://github.com/oven-sh/WebKit/pull/279). Thanks @robobun! This changelog covers updates to JavaScriptCore in Bun's WebKit fork, from `9a2cc42ae1bf` to `7bc2f97e2835`. From e16b2c769df30053ce668e444aae8cfaec8b6f1d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 4 Oct 2026 10:25:57 -0700 Subject: [PATCH 2/3] ci: qualify namespace changes with the paired Bun adapter Run a read-only native Linux check for engine pull requests. Verify JSC stress results explicitly and exercise namespace regressions with the matching Bun adapter before publication qualification. Publishing remains in the separate manually approved artifact workflow. --- .../qualification/patches/008-namespace.patch | 537 ++++++++++++++++++ .github/openclaw/qualify.sh | 4 +- .github/openclaw/verify-jsc-results.py | 17 + .github/workflows/openclaw-checks.yml | 84 +++ OPENCLAW.md | 6 + 5 files changed, 647 insertions(+), 1 deletion(-) create mode 100644 .github/openclaw/qualification/patches/008-namespace.patch create mode 100644 .github/openclaw/verify-jsc-results.py create mode 100644 .github/workflows/openclaw-checks.yml diff --git a/.github/openclaw/qualification/patches/008-namespace.patch b/.github/openclaw/qualification/patches/008-namespace.patch new file mode 100644 index 0000000000000..c461a55ea10e9 --- /dev/null +++ b/.github/openclaw/qualification/patches/008-namespace.patch @@ -0,0 +1,537 @@ +diff --git a/src/js/builtins/CommonJS.ts b/src/js/builtins/CommonJS.ts +index d4ea37ea..92299d62 100644 +--- a/src/js/builtins/CommonJS.ts ++++ b/src/js/builtins/CommonJS.ts +@@ -124,26 +124,11 @@ export function overridableRequire(this: JSCommonJSModule, originalId: string, o + + const namespace = out; + // In a require cycle the namespace is live while the module body is still +- // running, so an export named `__esModule` / `module.exports` may be in TDZ. +- let esModule, moduleExports; ++ // running, so an export named `module.exports` may be in TDZ. ++ let moduleExports; + try { +- esModule = namespace.__esModule; + moduleExports = namespace["module.exports"]; + } catch {} +- // In Bun, when __esModule is not defined, it's a CustomAccessor on the prototype. +- // Various libraries expect __esModule to be set when using ESM from require(). +- // We don't want to always inject the __esModule export into every module, +- // And creating an Object wrapper causes the actual exports to not be own properties. +- // So instead of either of those, we make it so that the __esModule property can be set at runtime. +- // It only supports "true" and undefined. Anything non-truthy is treated as undefined. +- // https://github.com/oven-sh/bun/issues/14411 +- if (esModule === undefined) { +- try { +- namespace.__esModule = true; +- } catch { +- // https://github.com/oven-sh/bun/issues/17816 +- } +- } + + return (mod.exports = moduleExports ?? namespace); + } +@@ -217,25 +202,10 @@ export function requireESMFromHijackedExtension(this: JSCommonJSModule, id: stri + const namespace = $requireESM(id, this); + + // See `overridableRequire`: TDZ-safe reads for the require-cycle case. +- let esModule, moduleExports; ++ let moduleExports; + try { +- esModule = namespace.__esModule; + moduleExports = namespace["module.exports"]; + } catch {} +- // In Bun, when __esModule is not defined, it's a CustomAccessor on the prototype. +- // Various libraries expect __esModule to be set when using ESM from require(). +- // We don't want to always inject the __esModule export into every module, +- // And creating an Object wrapper causes the actual exports to not be own properties. +- // So instead of either of those, we make it so that the __esModule property can be set at runtime. +- // It only supports "true" and undefined. Anything non-truthy is treated as undefined. +- // https://github.com/oven-sh/bun/issues/14411 +- if (esModule === undefined) { +- try { +- namespace.__esModule = true; +- } catch { +- // https://github.com/oven-sh/bun/issues/17816 +- } +- } + + this.exports = moduleExports ?? namespace; + } +diff --git a/src/jsc/bindings/JSCommonJSModule.cpp b/src/jsc/bindings/JSCommonJSModule.cpp +index a043ef3c..4a11ee7c 100644 +--- a/src/jsc/bindings/JSCommonJSModule.cpp ++++ b/src/jsc/bindings/JSCommonJSModule.cpp +@@ -1188,7 +1188,8 @@ void populateESMExports( + + if (auto* exports = result.getObject()) { + bool hasESModuleMarker = false; +- if (!ignoreESModuleAnnotation) { ++ // A native namespace forwarded by CJS keeps its default binding inside that namespace. ++ if (!ignoreESModuleAnnotation && !jsDynamicCast(exports)) { + PropertySlot slot(exports, PropertySlot::InternalMethodType::VMInquiry, &vm); + auto has = exports->getPropertySlot(globalObject, esModuleMarker, slot); + RETURN_IF_EXCEPTION(scope, ); +@@ -1213,7 +1214,7 @@ void populateESMExports( + if (canPerformFastEnumeration(structure)) { + exports->structure()->forEachProperty(vm, [&](const PropertyTableEntry& entry) -> bool { + auto key = entry.key(); +- if (key->isSymbol() || key == esModuleMarker) ++ if (key->isSymbol()) + return true; + + needsToAssignDefault = needsToAssignDefault && key != vm.propertyNames->defaultKeyword; +@@ -1230,7 +1231,7 @@ void populateESMExports( + RETURN_IF_EXCEPTION(scope, ); + + for (auto property : properties) { +- if (property.isEmpty() || property.isNull() || property == esModuleMarker || property.isPrivateName() || property.isSymbol()) [[unlikely]] ++ if (property.isEmpty() || property.isNull() || property.isPrivateName() || property.isSymbol()) [[unlikely]] + continue; + + // ignore constructor +@@ -1336,7 +1337,25 @@ void JSCommonJSModule::toSyntheticSource(JSC::JSGlobalObject* globalObject, + auto result = this->exportsObject(); + RETURN_IF_EXCEPTION(scope, ); + +- RELEASE_AND_RETURN(scope, populateESMExports(globalObject, result, exportNames, exportValues, this->ignoreESModuleAnnotation)); ++ populateESMExports(globalObject, result, exportNames, exportValues, this->ignoreESModuleAnnotation); ++ RETURN_IF_EXCEPTION(scope, ); ++ ++ auto& vm = globalObject->vm(); ++ const auto moduleExports = Identifier::fromString(vm, "module.exports"_s); ++ exportValues.append(result); ++ if (exportValues.hasOverflowed()) { ++ throwOutOfMemoryError(globalObject, scope); ++ return; ++ } ++ // Node's CJS namespace always exposes the original exports through this name. ++ for (size_t i = 0; i < exportNames.size(); ++i) { ++ if (exportNames[i] == moduleExports) { ++ exportValues[i] = exportValues.last(); ++ exportValues.removeLast(); ++ return; ++ } ++ } ++ exportNames.append(moduleExports); + } + + void JSCommonJSModule::setExportsObject(JSC::JSValue exportsObject) +diff --git a/src/jsc/bindings/NodeVMModule.cpp b/src/jsc/bindings/NodeVMModule.cpp +index ef0440c5..2570d1cd 100644 +--- a/src/jsc/bindings/NodeVMModule.cpp ++++ b/src/jsc/bindings/NodeVMModule.cpp +@@ -348,13 +348,8 @@ JSModuleNamespaceObject* NodeVMModule::namespaceObject(JSC::JSGlobalObject* glob + object = amr->getModuleNamespace(globalObject); + RETURN_IF_EXCEPTION(scope, {}); + if (object) { +- // The shared module namespace structure carries an __esModule accessor for +- // CJS interop, but a Module Namespace Exotic Object is specified to have a +- // null [[Prototype]], which is what vm modules must expose. +- object->setPrototypeDirect(vm, jsNull()); + namespaceObject(vm, object); + } +- RETURN_IF_EXCEPTION(scope, {}); + + return object; + } +diff --git a/src/jsc/bindings/ZigGlobalObject.cpp b/src/jsc/bindings/ZigGlobalObject.cpp +index 2c61e485..5e47c42b 100644 +--- a/src/jsc/bindings/ZigGlobalObject.cpp ++++ b/src/jsc/bindings/ZigGlobalObject.cpp +@@ -811,9 +811,11 @@ JSC_DEFINE_HOST_FUNCTION(functionEsmNamespaceForCjs, (JSC::JSGlobalObject * glob + RETURN_IF_EXCEPTION(scope, {}); + if (!record) + return JSValue::encode(jsUndefined()); +- auto* ns = record->getModuleNamespace(globalObject, false); ++ auto* ns = record->getModuleNamespace(globalObject); + RETURN_IF_EXCEPTION(scope, {}); +- return JSValue::encode(ns); ++ auto* required = ns->createNamespaceForRequire(globalObject); ++ RETURN_IF_EXCEPTION(scope, {}); ++ return JSValue::encode(required); + } + + JSC_DEFINE_HOST_FUNCTION(functionEsmRegistryHasEvaluated, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) +@@ -883,9 +885,11 @@ JSC_DEFINE_HOST_FUNCTION(functionEsmLoadSync, (JSC::JSGlobalObject * lexicalGlob + if (auto* entry = loader->registryEntry(key)) { + entryExistedBefore = true; + if (isModuleEvaluated(entry->record()) || isModuleEvaluatingSync(entry->record())) { +- auto* ns = entry->record()->getModuleNamespace(globalObject, false); ++ auto* ns = entry->record()->getModuleNamespace(globalObject); ++ RETURN_IF_EXCEPTION(scope, {}); ++ auto* required = ns->createNamespaceForRequire(globalObject); + RETURN_IF_EXCEPTION(scope, {}); +- return JSValue::encode(ns); ++ return JSValue::encode(required); + } + // Any other Evaluating record (one with top-level await) must not + // reach loadModuleSync: Link() and Evaluate() reject that status. +@@ -958,9 +962,11 @@ JSC_DEFINE_HOST_FUNCTION(functionEsmLoadSync, (JSC::JSGlobalObject * lexicalGlob + } + } + +- auto* ns = record->getModuleNamespace(globalObject, false); ++ auto* ns = record->getModuleNamespace(globalObject); ++ RETURN_IF_EXCEPTION(scope, {}); ++ auto* required = ns->createNamespaceForRequire(globalObject); + RETURN_IF_EXCEPTION(scope, {}); +- return JSValue::encode(ns); ++ return JSValue::encode(required); + } + + #define WEBCORE_GENERATED_CONSTRUCTOR_GETTER(ConstructorName) \ +@@ -1990,31 +1996,6 @@ extern "C" napi_env ZigGlobalObject__makeNapiEnvForFFI(Zig::GlobalObject* global + } + + extern "C" JSC::EncodedJSValue CryptoObject__create(JSGlobalObject*); +-JSC_DEFINE_CUSTOM_GETTER(moduleNamespacePrototypeGetESModuleMarker, (JSGlobalObject * globalObject, JSC::EncodedJSValue encodedThisValue, PropertyName)) +-{ +- JSValue thisValue = JSValue::decode(encodedThisValue); +- JSModuleNamespaceObject* moduleNamespaceObject = dynamicDowncast(thisValue); +- if (!moduleNamespaceObject || moduleNamespaceObject->m_hasESModuleMarker != WTF::TriState::True) { +- return JSC::JSValue::encode(jsUndefined()); +- } +- +- return JSC::JSValue::encode(jsBoolean(true)); +-} +- +-JSC_DEFINE_CUSTOM_SETTER(moduleNamespacePrototypeSetESModuleMarker, (JSGlobalObject * globalObject, JSC::EncodedJSValue encodedThisValue, JSC::EncodedJSValue encodedValue, PropertyName)) +-{ +- auto& vm = JSC::getVM(globalObject); +- JSValue thisValue = JSValue::decode(encodedThisValue); +- JSModuleNamespaceObject* moduleNamespaceObject = dynamicDowncast(thisValue); +- if (!moduleNamespaceObject) { +- return false; +- } +- auto scope = DECLARE_THROW_SCOPE(vm); +- JSValue value = JSValue::decode(encodedValue); +- WTF::TriState triState = value.toBoolean(globalObject) ? WTF::TriState::True : WTF::TriState::False; +- moduleNamespaceObject->m_hasESModuleMarker = triState; +- return true; +-} + + namespace { + +@@ -2347,11 +2328,6 @@ void GlobalObject::finishCreation(VM& vm) + createMemoryFootprintStructure( + init.vm, static_cast(init.owner))); + } }, +- { OBJECT_OFFSETOF(GlobalObject, m_moduleNamespaceObjectStructure), [](const LazyProperty::Initializer& init) { +- JSObject* moduleNamespacePrototype = JSC::constructEmptyObject(init.vm, init.owner->nullPrototypeObjectStructure()); +- moduleNamespacePrototype->putDirectCustomAccessor(init.vm, init.vm.propertyNames->__esModule, CustomGetterSetter::create(init.vm, moduleNamespacePrototypeGetESModuleMarker, moduleNamespacePrototypeSetESModuleMarker), PropertyAttribute::DontEnum | PropertyAttribute::DontDelete | PropertyAttribute::CustomAccessor | 0); +- init.set(JSModuleNamespaceObject::createStructure(init.vm, init.owner, moduleNamespacePrototype)); +- } }, + { OBJECT_OFFSETOF(GlobalObject, m_JSBufferSubclassStructure), [](const LazyProperty::Initializer& init) { + auto scope = DECLARE_TOP_EXCEPTION_SCOPE(init.vm); + auto* globalObject = static_cast(init.owner); +@@ -2684,8 +2660,6 @@ void GlobalObject::finishCreation(VM& vm) + dynamicDowncast(init.owner))); + }); + +- // Change prototype from null to object for synthetic modules. +- + m_vmModuleContextMap.initLater( + [](const Initializer& init) { + init.set(JSWeakMap::create(init.vm, init.owner->weakMapStructure())); +diff --git a/test/js/bun/import-attributes/import-attributes.test.ts b/test/js/bun/import-attributes/import-attributes.test.ts +index 2c188866..00eef072 100644 +--- a/test/js/bun/import-attributes/import-attributes.test.ts ++++ b/test/js/bun/import-attributes/import-attributes.test.ts +@@ -344,11 +344,11 @@ describe("other loaders do not crash", () => { + }); + + describe("?raw", () => { +- for (const [name, fn] of [ +- ["bun run", testBunRun], ++ for (const [name, fn, expected] of [ ++ ["bun run", testBunRun, {}], + // ["bun build", testBunBuild], // TODO: bun.build doesn't support query params at all yet +- ["bun run await import", testBunRunAwaitImport], +- ["require", testBunRunRequire], ++ ["bun run await import", testBunRunAwaitImport, {}], ++ ["require", testBunRunRequire, { __esModule: true }], + // ["bun build require", testBunBuildRequire], // TODO: bun.build doesn't support query params at all yet + ] as const) { + test(name, async () => { +@@ -357,7 +357,7 @@ describe("?raw", () => { + await using question_raw = tempDir("import-attributes", { + [filename]: code, + }); +- expect(await fn(question_raw, null, filename + "?raw")).toEqual({ default: code }); ++ expect(await fn(question_raw, null, filename + "?raw")).toEqual({ ...expected, default: code }); + }); + } + }); +diff --git a/test/js/bun/namespace-prototype-pollution.test.ts b/test/js/bun/namespace-prototype-pollution.test.ts +index 36c25f43..bb49b55c 100644 +--- a/test/js/bun/namespace-prototype-pollution.test.ts ++++ b/test/js/bun/namespace-prototype-pollution.test.ts +@@ -19,8 +19,9 @@ test("namespace imports should not inherit from Object.prototype", async () => { + console.log("PASS: prototype pollution prevented"); + } + +- // Verify __esModule still works +- console.log("__esModule settable:", (mod.__esModule = true, mod.__esModule === true)); ++ console.log("Null prototype:", Object.getPrototypeOf(mod) === null); ++ console.log("__esModule absent:", !("__esModule" in mod)); ++ console.log("__esModule immutable:", !Reflect.set(mod, "__esModule", true)); + + // Original exports should work + console.log("Original export:", mod.value); +@@ -38,6 +39,8 @@ test("namespace imports should not inherit from Object.prototype", async () => { + + expect(exitCode).toBe(0); + expect(stdout).toContain("PASS: prototype pollution prevented"); +- expect(stdout).toContain("__esModule settable: true"); ++ expect(stdout).toContain("Null prototype: true"); ++ expect(stdout).toContain("__esModule absent: true"); ++ expect(stdout).toContain("__esModule immutable: true"); + expect(stdout).toContain("Original export: original"); + }); +diff --git a/test/js/bun/resolve/esModule-annotation.test.js b/test/js/bun/resolve/esModule-annotation.test.js +index 01c5fb3b..c4bfe3c9 100644 +--- a/test/js/bun/resolve/esModule-annotation.test.js ++++ b/test/js/bun/resolve/esModule-annotation.test.js +@@ -21,20 +21,20 @@ describe('without type: "module"', () => { + __esModule: true, + }); + +- // The module namespace object will not have the __esModule property. +- expect(WithoutTypeModuleExportEsModuleAnnotationNoDefault.__esModule).toBeUndefined(); ++ expect(Object.hasOwn(WithoutTypeModuleExportEsModuleAnnotationNoDefault, "__esModule")).toBe(true); ++ expect(WithoutTypeModuleExportEsModuleAnnotationNoDefault.__esModule).toBeTrue(); + }); + + test("exports.default = true; exports.__esModule = true;", () => { + expect(WithoutTypeModuleExportEsModuleAnnotation.default).toBeTrue(); +- expect(WithoutTypeModuleExportEsModuleAnnotation.__esModule).toBeUndefined(); ++ expect(WithoutTypeModuleExportEsModuleAnnotation.__esModule).toBeTrue(); + }); + + test("exports.default = true;", () => { + expect(WithoutTypeModuleExportEsModuleNoAnnotation.default).toEqual({ + default: true, + }); +- expect(WithoutTypeModuleExportEsModuleAnnotation.__esModule).toBeUndefined(); ++ expect(WithoutTypeModuleExportEsModuleNoAnnotation.__esModule).toBeUndefined(); + }); + }); + +@@ -65,7 +65,7 @@ describe('with type: "module"', () => { + expect(WithTypeModuleExportEsModuleNoAnnotation.default).toEqual({ + default: true, + }); +- expect(WithTypeModuleExportEsModuleAnnotation.__esModule).toBeTrue(); ++ expect(WithTypeModuleExportEsModuleNoAnnotation.__esModule).toBeUndefined(); + }); + }); + +diff --git a/test/js/bun/resolve/esModule.test.ts b/test/js/bun/resolve/esModule.test.ts +index 1d66d9ed..0f3bc3cb 100644 +--- a/test/js/bun/resolve/esModule.test.ts ++++ b/test/js/bun/resolve/esModule.test.ts +@@ -1,31 +1,149 @@ + import { expect, test } from "bun:test"; +- +-// Top-level `await import(self)` is a spec-level deadlock under the new +-// pure-C++ module loader (Node prints an "unsettled top-level await" warning +-// and exits). A static self-import yields the same namespace object without +-// blocking evaluation on itself. ++import { bunEnv, bunExe, tempDir } from "harness"; + import * as Self from "./esModule.test.ts"; + +-test("__esModule defaults to undefined", () => { ++test("an imported namespace has no inherited or writable __esModule marker", () => { ++ expect(Object.getPrototypeOf(Self)).toBeNull(); ++ expect("__esModule" in Self).toBe(false); ++ expect(Object.hasOwn(Self, "__esModule")).toBe(false); ++ expect(Object.getOwnPropertyDescriptor(Self, "__esModule")).toBeUndefined(); ++ expect(Reflect.ownKeys(Self)).toEqual([Symbol.toStringTag]); ++ expect(Reflect.set(Self, "__esModule", true)).toBe(false); ++ expect(Reflect.defineProperty(Self, "__esModule", { value: true })).toBe(false); ++ expect(require("./esModule.test.ts")).toBe(Self); + expect(Self.__esModule).toBeUndefined(); + }); + +-test("__esModule is settable", () => { +- Self.__esModule = true; +- expect(Self.__esModule).toBe(true); +- Self.__esModule = false; +- expect(Self.__esModule).toBe(undefined); +- Self.__esModule = true; +- expect(Self.__esModule).toBe(true); +- Self.__esModule = undefined; +-}); +- +-test("require of self sets __esModule", () => { +- expect(Self.__esModule).toBeUndefined(); +- { +- const Self = require("./esModule.test.ts"); +- expect(Self.__esModule).toBe(true); ++for (const order of ["import-first", "require-first", "cache-first"]) { ++ test.concurrent(`require(esm) marker reflection and live bindings (${order})`, async () => { ++ using dir = tempDir("namespace-marker", { ++ "default.mjs": "export default {}; export let value = 1; export function bump() { value++; }", ++ "none.mjs": "export const value = 1;", ++ "false.mjs": "export const __esModule = false; export default 1;", ++ "undefined.mjs": "export const __esModule = undefined; export default 1;", ++ "true.mjs": "export const __esModule = true; export default 1;", ++ "sorted.mjs": "export default 1; export const Alpha = 1, _a = 2, zzz = 3;", ++ "leaf.mjs": "export const value = 'synthetic-ok';", ++ "alias.mjs": "import * as z from './leaf.mjs'; export * from './leaf.mjs'; export { z, z as default };", ++ "entry.mjs": ` ++import assert from 'node:assert/strict'; ++import { createRequire } from 'node:module'; ++const require = createRequire(import.meta.url); ++function marker(ns, present, value) { ++ assert.equal(Object.getPrototypeOf(ns), null); ++ assert.equal(Object.isExtensible(ns), false); ++ assert.equal('__esModule' in ns, present); ++ assert.equal(Object.hasOwn(ns, '__esModule'), present); ++ assert.equal(Object.prototype.hasOwnProperty.call(ns, '__esModule'), present); ++ assert.deepEqual(Object.getOwnPropertyDescriptor(ns, '__esModule'), present ? { ++ value, writable: true, enumerable: true, configurable: false, ++ } : undefined); ++ assert.equal(Reflect.set(ns, '__esModule', true), false); ++ assert.equal(Reflect.set(ns, '__esModule', value), false); ++ assert.equal(Reflect.defineProperty(ns, '__esModule', { value }), present); ++ for (const descriptor of [{ value: {} }, { writable: false }, { enumerable: false }, { configurable: true }, { get() {} }]) ++ assert.equal(Reflect.defineProperty(ns, '__esModule', descriptor), false); ++ assert.equal(Reflect.deleteProperty(ns, '__esModule'), !present); ++} ++for (const [name, hasDefault, explicit, value] of [ ++ ['default', true, false, undefined], ['none', false, false, undefined], ++ ['false', true, true, false], ['undefined', true, true, undefined], ['true', true, true, true], ++]) { ++ let imported, required; ++ if (${JSON.stringify(order)} !== 'require-first') { ++ imported = await import('./' + name + '.mjs'); ++ marker(imported, explicit, value); ++ if (${JSON.stringify(order)} === 'cache-first') void require.cache[require.resolve('./' + name + '.mjs')]; ++ required = require('./' + name + '.mjs'); ++ } else { ++ required = require('./' + name + '.mjs'); ++ imported = await import('./' + name + '.mjs'); ++ } ++ marker(imported, explicit, value); ++ marker(required, explicit || hasDefault, explicit ? value : hasDefault ? true : undefined); ++ assert.equal(imported === required, explicit || !hasDefault); ++ assert.equal(require('./' + name + '.mjs'), required); ++ delete require.cache[require.resolve('./' + name + '.mjs')]; ++ const reloaded = require('./' + name + '.mjs'); ++ // Bun also evicts the ESM registry on cache deletion; only check the added facade's identity. ++ if (hasDefault && !explicit) assert.notEqual(reloaded, required); ++ marker(reloaded, explicit || hasDefault, explicit ? value : hasDefault ? true : undefined); ++ if (name === 'default') { ++ imported.bump(); ++ assert.equal(required.value, 2); ++ assert.equal(({ ...required }).__esModule, true); ++ assert.equal(Object.assign({}, required).__esModule, true); ++ assert.equal(JSON.parse(JSON.stringify(required)).__esModule, true); ++ globalThis.Bun?.gc(true); ++ assert.equal(required.value, imported.value); + } +- expect(Self.__esModule).toBe(true); +- expect(Object.getOwnPropertyNames(Self)).toBeEmpty(); ++} ++const sorted = require('./sorted.mjs'); ++assert.deepEqual(Reflect.ownKeys(sorted), ['Alpha', '__esModule', '_a', 'default', 'zzz', Symbol.toStringTag]); ++assert.deepEqual(Object.keys(sorted), ['Alpha', '__esModule', '_a', 'default', 'zzz']); ++const alias = await import('./alias.mjs'); ++const interop = alias.default && typeof alias.default === 'object' && '__esModule' in alias.default ? alias.default : alias; ++assert.equal(interop.z.value, 'synthetic-ok'); ++assert.equal(require('./alias.mjs').__esModule, true); ++assert.equal('__esModule' in alias, false); ++console.log('ok'); ++`, ++ }); ++ await using proc = Bun.spawn({ ++ cmd: [bunExe(), "entry.mjs"], ++ cwd: String(dir), ++ env: bunEnv, ++ stdout: "pipe", ++ stderr: "pipe", ++ }); ++ const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); ++ expect({ stdout, stderr, exitCode }).toEqual({ stdout: "ok\n", stderr: "", exitCode: 0 }); ++ }); ++} ++ ++test.concurrent("CommonJS-as-ESM namespaces preserve explicit markers and own-key reflection", async () => { ++ using dir = tempDir("cjs-namespace-marker", { ++ "plain.cjs": "exports.value = 1;", ++ "true.cjs": "Object.defineProperty(exports, '__esModule', { value: true }); exports.value = 1;", ++ "false.cjs": "exports.__esModule = false; exports.value = 1;", ++ "undefined.cjs": "exports.__esModule = undefined; exports.value = 1;", ++ "collision.cjs": "exports['module.exports'] = 3; exports.value = 1;", ++ "forwarded.mjs": "export default 'kept'; export const value = 1;", ++ "forwarder.cjs": "module.exports = require('./forwarded.mjs');", ++ "entry.mjs": ` ++import assert from 'node:assert/strict'; ++import { createRequire } from 'node:module'; ++const require = createRequire(import.meta.url); ++for (const [name, present, value] of [ ++ ['plain', false], ['true', true, true], ['false', true, false], ['undefined', true, undefined], ['collision', false], ++]) { ++ const ns = await import('./' + name + '.cjs'); ++ assert.equal(Object.getPrototypeOf(ns), null); ++ assert.equal(Object.isExtensible(ns), false); ++ assert.equal('__esModule' in ns, present); ++ assert.equal(Object.hasOwn(ns, '__esModule'), present); ++ assert.equal(Object.prototype.hasOwnProperty.call(ns, '__esModule'), present); ++ assert.deepEqual(Object.getOwnPropertyDescriptor(ns, '__esModule'), present ? { ++ value, writable: true, enumerable: true, configurable: false, ++ } : undefined); ++ assert.deepEqual(Reflect.ownKeys(ns), [...(present ? ['__esModule'] : []), 'default', 'module.exports', 'value', Symbol.toStringTag]); ++ assert.equal(ns['module.exports'], require('./' + name + '.cjs')); ++ assert.equal(Reflect.set(ns, '__esModule', true), false); ++} ++const forwarded = await import('./forwarder.cjs'); ++assert.equal(forwarded.default, require('./forwarder.cjs')); ++assert.equal(forwarded.default.default, 'kept'); ++assert.equal(forwarded['module.exports'], forwarded.default); ++console.log('ok'); ++`, ++ }); ++ await using proc = Bun.spawn({ ++ cmd: [bunExe(), "entry.mjs"], ++ cwd: String(dir), ++ env: bunEnv, ++ stdout: "pipe", ++ stderr: "pipe", ++ }); ++ const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); ++ expect({ stdout, stderr, exitCode }).toEqual({ stdout: "ok\n", stderr: "", exitCode: 0 }); + }); +diff --git a/test/js/bun/resolve/require-esm-evaluating-cycle.test.ts b/test/js/bun/resolve/require-esm-evaluating-cycle.test.ts +index 4002df11..ec50c1d7 100644 +--- a/test/js/bun/resolve/require-esm-evaluating-cycle.test.ts ++++ b/test/js/bun/resolve/require-esm-evaluating-cycle.test.ts +@@ -44,9 +44,10 @@ test("require(esm) inside a require cycle returns the live namespace, not an emp + expect(exitCode).toBe(0); + }); + +-// The CommonJS side reads `__esModule` / `"module.exports"` off that live +-// namespace; when the module happens to export a binding by that name that is +-// still in TDZ, require() itself must not throw (reading it afterwards does). ++// The CommonJS side reads `"module.exports"` off that live namespace. Marker ++// selection checks export names without reading the bindings. When either ++// binding is still in TDZ, require() itself must not throw ++// (reading it afterwards does). + test("require(esm) inside a require cycle tolerates a TDZ `__esModule` export", async () => { + using dir = tempDir("require-esm-evaluating-cycle-tdz", { + "a.mjs": ` +diff --git a/test/js/node/module/require-extensions.test.ts b/test/js/node/module/require-extensions.test.ts +index 86dfa1d9..70f3514d 100644 +--- a/test/js/node/module/require-extensions.test.ts ++++ b/test/js/node/module/require-extensions.test.ts +@@ -156,7 +156,7 @@ test("wrapping an existing extension but it's secretly sync esm", () => { + original(module, filename); + })); + const mod = require("./extensions-fixture/secretly_esm"); +- expect(mod).toEqual({ default: 1 }); ++ expect({ ...mod }).toEqual({ __esModule: true, default: 1 }); + expect(mocked).toBeCalled(); + } finally { + require.extensions[".cjs"] = original; diff --git a/.github/openclaw/qualify.sh b/.github/openclaw/qualify.sh index d4a60484c9d07..3851758bba671 100644 --- a/.github/openclaw/qualify.sh +++ b/.github/openclaw/qualify.sh @@ -26,6 +26,7 @@ for arm in baseline candidate; do for patch in "$inputs/patches/001-proxy.patch" "$inputs"/patches/00[3-7]-*.patch; do git apply --exclude=CHANGELOG.md --exclude='docs/*' --exclude='test/js/node/worker_threads/*' "$patch" done + git apply --exclude=CHANGELOG.md --exclude='docs/*' "$inputs/patches/008-namespace.patch" cp "$inputs/worker-resource-limits.test.ts" test/js/node/worker_threads/openclaw-resource-limits.test.ts git diff --check git diff --binary HEAD > "$QUALIFICATION_DIR/bun-adapters.patch" @@ -58,6 +59,7 @@ done python3 "$inputs/compare-fork-ci.py" "$QUALIFICATION_DIR/baseline" "$QUALIFICATION_DIR/candidate" --output "$QUALIFICATION_DIR/faithfulness.json" candidate="$QUALIFICATION_DIR/bun/build/qualify-candidate/bun" unset BUN_WEBKIT_ARTIFACT_MANIFEST BUN_BUILD_CACHE_DIR BUN_BUILD_PREFETCH_DIR +"$candidate" test test/js/bun/resolve/esModule.test.ts test/js/bun/namespace-prototype-pollution.test.ts test/js/bun/resolve/require-esm-evaluating-cycle.test.ts test/js/bun/import-attributes/import-attributes.test.ts test/js/node/module/require-extensions.test.ts > "$QUALIFICATION_DIR/namespace.log" 2>&1 "$candidate" "$inputs/segmenter.js" > "$QUALIFICATION_DIR/segmenter.log" 2>&1 "$candidate" test test/js/node/vm/vm.test.ts -t 'a Proxy in the prototype chain' > "$QUALIFICATION_DIR/proxy.log" 2>&1 "$candidate" test test/js/node/worker_threads/openclaw-resource-limits.test.ts -t 'resourceLimits' > "$QUALIFICATION_DIR/resource-limits.log" 2>&1 @@ -73,7 +75,7 @@ assert faith['selected_files']==44 and faith['result_files']==46 for name in ['als-plugin','als-native']: rows=json.loads((root/(name+'.json')).read_text())['results'] assert len(rows)==14 and all(r['exitCode']==0 for r in rows) -for name,minimum in [('proxy',4),('resource-limits',14)]: +for name,minimum in [('proxy',4),('resource-limits',14),('namespace',41)]: text=(root/(name+'.log')).read_text() passes=re.search(r'(\d+) pass',text) assert passes and int(passes[1])>=minimum, name+' missing passing cases' diff --git a/.github/openclaw/verify-jsc-results.py b/.github/openclaw/verify-jsc-results.py new file mode 100644 index 0000000000000..e6bfcea1bb07b --- /dev/null +++ b/.github/openclaw/verify-jsc-results.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +"""The stress runner's results file, not its exit status, is authoritative.""" +import json +import sys +from pathlib import Path + +root = Path(sys.argv[1]) +lines = (root / "results").read_text().splitlines() +if not lines: + raise SystemExit("JSC produced no test results") +namespace = [line for line in lines if "module-namespace-esmodule-marker.js" in line] +if not namespace: + raise SystemExit("The namespace marker regression did not execute") +failures = [line for line in lines if not line.endswith(": PASS")] +if failures: + raise SystemExit("JSC failures:\n" + "\n".join(failures)) +print(json.dumps({"tests": len(lines), "marker_variants": len(namespace), "passed": True})) diff --git a/.github/workflows/openclaw-checks.yml b/.github/workflows/openclaw-checks.yml new file mode 100644 index 0000000000000..c5dfb7b4334f9 --- /dev/null +++ b/.github/workflows/openclaw-checks.yml @@ -0,0 +1,84 @@ +name: OpenClaw engine checks +on: + pull_request: + branches: [openclaw/main] + workflow_dispatch: +permissions: + contents: read +concurrency: + group: openclaw-engine-checks-${{ github.ref }} + cancel-in-progress: true +jobs: + linux-native: + if: github.repository == 'openclaw/WebKit' + runs-on: blacksmith-32vcpu-ubuntu-2404 + timeout-minutes: 150 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + fetch-depth: 16 + persist-credentials: false + sparse-checkout-cone-mode: false + sparse-checkout: | + /* + !/LayoutTests/ + !/JSTests/* + !/PerformanceTests/ + !/Websites/ + !/ManualTests/ + !/WebDriverTests/ + /JSTests/stress/ + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 + with: + node-version: '26.3.0' + - name: Verify pipeline integrity and runner support + run: | + python3 .github/openclaw/test_release.py + bash .github/openclaw/preflight.sh + - name: Build native Linux engine with the unchanged lane + env: + BUILDX_METADATA_PROVENANCE: max + run: python3 .github/openclaw/artifacts.py build --lane bun-webkit-linux-amd64 --output "$RUNNER_TEMP/linux-artifact" + - name: Install pinned Bun and JSC test tools + run: | + curl -fsSL --retry 5 https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc > /dev/null + echo 'deb https://apt.llvm.org/noble/ llvm-toolchain-noble-23 main' | sudo tee /etc/apt/sources.list.d/llvm.list + sudo apt-get update -qq + sudo apt-get install -y --no-install-recommends cmake ninja-build nasm ccache golang-go clang-23 lld-23 llvm-23 unzip ruby ruby-highline libjson-pp-perl + rustup toolchain install nightly-2026-09-15 --profile minimal --component rust-src + echo 'RUSTUP_TOOLCHAIN=nightly-2026-09-15' >> "$GITHUB_ENV" + echo '/usr/lib/llvm-23/bin' >> "$GITHUB_PATH" + curl -fSL --retry 5 https://github.com/oven-sh/bun/releases/download/bun-v1.4.2/bun-linux-x64.zip -o "$RUNNER_TEMP/bun.zip" + unzip -q "$RUNNER_TEMP/bun.zip" -d "$RUNNER_TEMP/bootstrap" + echo "$RUNNER_TEMP/bootstrap/bun-linux-x64" >> "$GITHUB_PATH" + - name: Exercise module namespace engine regressions + run: | + mkdir "$RUNNER_TEMP/jsc-artifact" + tar -xzf "$RUNNER_TEMP/linux-artifact/bun-webkit-linux-amd64.tar.gz" -C "$RUNNER_TEMP/jsc-artifact" + # $vm is a JavaScript identifier. + # shellcheck disable=SC2016 + "$RUNNER_TEMP/jsc-artifact/bun-webkit/bin/jsc" --useDollarVM=1 -e 'if (typeof $vm.moduleNamespaceForRequire !== "function") throw new Error("namespace test hook is missing");' + Tools/Scripts/run-jsc-stress-tests JSTests/stress --jsc "$RUNNER_TEMP/jsc-artifact/bun-webkit/bin/jsc" --child-processes 16 --filter 'module-namespace|module-loader-security-thenable-namespace' --output-dir "$RUNNER_TEMP/jsc-results" --no-retry + python3 .github/openclaw/verify-jsc-results.py "$RUNNER_TEMP/jsc-results" + - name: Qualify the paired Bun adapter and fork selection + env: + ARTIFACT_DIR: ${{ runner.temp }}/linux-artifact + QUALIFICATION_DIR: ${{ runner.temp }}/qualification + run: bash .github/openclaw/qualify.sh + - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a + if: always() + with: + name: linux-native-proof + path: | + ${{ runner.temp }}/qualification/*.json + ${{ runner.temp }}/qualification/*.log + ${{ runner.temp }}/qualification/*.sha256 + ${{ runner.temp }}/qualification/*.patch + ${{ runner.temp }}/qualification/baseline/*.json + ${{ runner.temp }}/qualification/baseline/*.log + ${{ runner.temp }}/qualification/candidate/*.json + ${{ runner.temp }}/qualification/candidate/*.log + ${{ runner.temp }}/jsc-results/results + ${{ runner.temp }}/jsc-results/*.log + if-no-files-found: error + retention-days: 7 diff --git a/OPENCLAW.md b/OPENCLAW.md index 6148a10075f35..7bc1f59e5e64c 100644 --- a/OPENCLAW.md +++ b/OPENCLAW.md @@ -90,3 +90,9 @@ use an old Bun executable with headers/libraries from another engine ABI. - Preserve module-loader async context through resolution and evaluation. - Add opt-in per-VM worker managed-heap and stack budgets. - Add checksum-pinned, immutable OpenClaw artifact publication with a Linux regression gate. + +## Namespace interop qualification + +Pull requests run the read-only Linux engine check. It builds the unchanged native lane, verifies the JSC namespace stress results, and builds Bun with the matching qualification adapters before running the fork selection and namespace regressions. It has no publication job. + +The namespace adapter in `.github/openclaw/qualification/patches/008-namespace.patch` accompanies the engine facade API. Keep it in sync with the matching Bun integration until that integration becomes the qualification baseline. The native engine change and Bun consumer must be rebuilt together; a new engine release alone does not remove Bun's old namespace prototype. From 9a378d31653dfdeece9dffcb8293ca97b0eb9971 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 4 Oct 2026 10:31:08 -0700 Subject: [PATCH 3/3] build: sync the qualification namespace cast correction --- .github/openclaw/qualification/patches/008-namespace.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/openclaw/qualification/patches/008-namespace.patch b/.github/openclaw/qualification/patches/008-namespace.patch index c461a55ea10e9..cb68b30745492 100644 --- a/.github/openclaw/qualification/patches/008-namespace.patch +++ b/.github/openclaw/qualification/patches/008-namespace.patch @@ -59,7 +59,7 @@ index d4ea37ea..92299d62 100644 this.exports = moduleExports ?? namespace; } diff --git a/src/jsc/bindings/JSCommonJSModule.cpp b/src/jsc/bindings/JSCommonJSModule.cpp -index a043ef3c..4a11ee7c 100644 +index a043ef3c..a3d89187 100644 --- a/src/jsc/bindings/JSCommonJSModule.cpp +++ b/src/jsc/bindings/JSCommonJSModule.cpp @@ -1188,7 +1188,8 @@ void populateESMExports( @@ -68,7 +68,7 @@ index a043ef3c..4a11ee7c 100644 bool hasESModuleMarker = false; - if (!ignoreESModuleAnnotation) { + // A native namespace forwarded by CJS keeps its default binding inside that namespace. -+ if (!ignoreESModuleAnnotation && !jsDynamicCast(exports)) { ++ if (!ignoreESModuleAnnotation && !dynamicDowncast(exports)) { PropertySlot slot(exports, PropertySlot::InternalMethodType::VMInquiry, &vm); auto has = exports->getPropertySlot(globalObject, esModuleMarker, slot); RETURN_IF_EXCEPTION(scope, );