-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: protect against prototype mutation
Ensures that mutating the `Object` prototype does not influence the parsing of `package.json` files. PR-URL: #44007 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
- Loading branch information
Showing
8 changed files
with
96 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import explicit from 'explicit-main'; | ||
import implicit from 'implicit-main'; | ||
import implicitModule from 'implicit-main-type-module'; | ||
import noMain from 'no-main-field'; | ||
|
||
function getImplicitCommonjs () { | ||
return import('implicit-main-type-commonjs'); | ||
} | ||
|
||
export {explicit, implicit, implicitModule, getImplicitCommonjs}; | ||
export {explicit, implicit, implicitModule, getImplicitCommonjs, noMain}; | ||
export default 'success'; |
2 changes: 2 additions & 0 deletions
2
test/fixtures/es-module-specifiers/node_modules/no-main-field/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
test/fixtures/es-module-specifiers/node_modules/no-main-field/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const assert = require('assert'); | ||
|
||
Object.defineProperty(Object.prototype, 'name', { | ||
__proto__: null, | ||
get: common.mustNotCall('get %Object.prototype%.name'), | ||
set: common.mustNotCall('set %Object.prototype%.name'), | ||
enumerable: false, | ||
}); | ||
Object.defineProperty(Object.prototype, 'main', { | ||
__proto__: null, | ||
get: common.mustNotCall('get %Object.prototype%.main'), | ||
set: common.mustNotCall('set %Object.prototype%.main'), | ||
enumerable: false, | ||
}); | ||
Object.defineProperty(Object.prototype, 'type', { | ||
__proto__: null, | ||
get: common.mustNotCall('get %Object.prototype%.type'), | ||
set: common.mustNotCall('set %Object.prototype%.type'), | ||
enumerable: false, | ||
}); | ||
Object.defineProperty(Object.prototype, 'exports', { | ||
__proto__: null, | ||
get: common.mustNotCall('get %Object.prototype%.exports'), | ||
set: common.mustNotCall('set %Object.prototype%.exports'), | ||
enumerable: false, | ||
}); | ||
Object.defineProperty(Object.prototype, 'imports', { | ||
__proto__: null, | ||
get: common.mustNotCall('get %Object.prototype%.imports'), | ||
set: common.mustNotCall('set %Object.prototype%.imports'), | ||
enumerable: false, | ||
}); | ||
|
||
assert.strictEqual( | ||
require(fixtures.path('es-module-specifiers', 'node_modules', 'no-main-field')), | ||
'no main field' | ||
); | ||
|
||
import(fixtures.fileURL('es-module-specifiers', 'index.mjs')) | ||
.then(common.mustCall((module) => assert.strictEqual(module.noMain, 'no main field'))); |