fix: handle exports.__proto__ assignment in CJS modules#32262
Closed
fix: handle exports.__proto__ assignment in CJS modules#32262
exports.__proto__ assignment in CJS modules#32262Conversation
When Object.prototype.__proto__ is deleted (Deno's default), CJS modules using `exports.__proto__ = someObj` to set up prototype chains get a data property instead of setting the prototype. This fix adds a post-execution check in Module._load to convert __proto__ data properties into actual prototype assignments using Object.setPrototypeOf. Also filters __proto__ from ESM wrapper named exports since it's not a meaningful export name. Co-authored-by: bartlomieju <13602871+bartlomieju@users.noreply.github.com>
Co-authored-by: bartlomieju <13602871+bartlomieju@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix missing properties for npm:@toi/toi@1.3.0
fix: handle Feb 22, 2026
exports.__proto__ assignment in CJS modules
Contributor
|
Unfortunately, this PR is wrong approach. // https://cdn.jsdelivr.net/npm/@toi/toi@1.3.0/build/index.js
...
var date;
(function (date) {
...
})(date = exports.date || (exports.date = {}));Below PR will resolve the issue: % target/debug/deno repl
import * as toi from 'npm:@toi/toi@1.3.0'Deno 2.6.9
exit using ctrl+d, ctrl+c, or close()
> import * as toi from 'npm:@toi/toi@1.3.0'
undefined
> const obj = () => toi.required().and(toi.obj.isplain());
const req = () => toi.required();
const num = () => toi.num.is();
const str = () => toi.str.is();
const isValid = obj().and(
toi.obj.keys({
number: req().and(num()),
negNumber: req().and(num()),
maxNumber: req().and(num()),
string: req().and(str()),
longString: req().and(str()),
boolean: req().and(toi.bool.is()),
deeplyNested: obj().and(
toi.obj.keys({
foo: req().and(str()),
num: req().and(num()),
bool: req().and(toi.bool.is()),
}),
),
}),
);
undefined |
Member
|
Closing in favor of #32163 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Deno deletes
Object.prototype.__proto__by default, which breaks CJS modules that useexports.__proto__ = require('./base')to set up prototype inheritance. The__proto__setter is gone, so the assignment creates a data property instead of setting the prototype, leaving inherited properties inaccessible.Changes
ext/node/polyfills/01_require.js: AfterModule._loadexecutes a CJS module, detect own__proto__data properties onmodule.exportsand convert them to actual prototype assignments viaObject.setPrototypeOf()libs/node_resolver/analyze.rs: Filter__proto__from ESM wrapper named exports (alongsidedefaultandmodule.exports) — it's not a meaningful export name and interferes with prototype chain semanticsexports.__proto__pattern end-to-end, unit test for the wrapper filteringWarning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
cdn.jsdelivr.net/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)jsr.io/home/REDACTED/work/deno/deno/target/debug/deno deno run --allow-all --config=tests/config/deno.json ./tools/lint.js --js --check-cfg cfg(docsrs,test) --check-cfg cfg(feature, values("ahash", "alloc", "allocator-api2", "compiler_builtins", "core",�� -C metadata=1b7e5ed4d7eba4eb -O0 f/aws-lc-sys-0.2/home/REDACTED/work/deno/deno/target/debug/deps/test_server-7d0484505fb77ce1.0p36kbash ib f/aws-lc-sys-0.2/home/REDACTED/work/deno/deno/target/debug/deps/test_server-7d0484505fb77ce1.0ulsx--noprofile orted/include pointer py-library afc496e831/out/d--edition=2024(dns block)unpkg.com/home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
npm:@toi/toi@1.3.0import missing properties #27898🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.