summaryrefslogtreecommitdiff
path: root/lib/internal/policy
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2019-11-22 18:04:46 +0100
committerMichaël Zasso <targos@protonmail.com>2019-11-25 10:28:15 +0100
commit0646eda4fc0affb98e13c30acb522e63b7fd6dde (patch)
tree078209f50b044e24ea2c72cbbe7dca6e34bb7e25 /lib/internal/policy
parent35c6e0cc2b56a5380e6808ef5603ecc2b167e032 (diff)
downloadandroid-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.tar.gz
android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.tar.bz2
android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.zip
lib: flatten access to primordials
Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/internal/policy')
-rw-r--r--lib/internal/policy/manifest.js33
-rw-r--r--lib/internal/policy/sri.js22
2 files changed, 29 insertions, 26 deletions
diff --git a/lib/internal/policy/manifest.js b/lib/internal/policy/manifest.js
index e8400b672e..d078ed092e 100644
--- a/lib/internal/policy/manifest.js
+++ b/lib/internal/policy/manifest.js
@@ -2,11 +2,13 @@
const {
Map,
- MapPrototype,
- Object,
- RegExpPrototype,
+ MapPrototypeSet,
+ ObjectEntries,
+ ObjectFreeze,
+ ObjectSetPrototypeOf,
+ RegExpPrototypeTest,
SafeMap,
- uncurryThis
+ uncurryThis,
} = primordials;
const {
canBeRequiredByUsers
@@ -28,7 +30,6 @@ const HashUpdate = uncurryThis(crypto.Hash.prototype.update);
const HashDigest = uncurryThis(crypto.Hash.prototype.digest);
const BufferEquals = uncurryThis(Buffer.prototype.equals);
const BufferToString = uncurryThis(Buffer.prototype.toString);
-const { entries } = Object;
const kRelativeURLStringPattern = /^\.{0,2}\//;
const { getOptionValue } = require('internal/options');
const shouldAbortOnUncaughtException =
@@ -73,7 +74,7 @@ class Manifest {
}
this.#reaction = reaction;
- const manifestEntries = entries(obj.resources);
+ const manifestEntries = ObjectEntries(obj.resources);
const parsedURLs = new SafeMap();
for (let i = 0; i < manifestEntries.length; i++) {
@@ -84,7 +85,7 @@ class Manifest {
resourceURL = parsedURLs.get(resourceHREF);
resourceHREF = resourceURL.href;
} else if (
- RegExpPrototype.test(kRelativeURLStringPattern, resourceHREF)
+ RegExpPrototypeTest(kRelativeURLStringPattern, resourceHREF)
) {
resourceURL = new URL(resourceHREF, manifestURL);
resourceHREF = resourceURL.href;
@@ -96,7 +97,7 @@ class Manifest {
if (integrity != null) {
debug(`Manifest contains integrity for url ${originalHREF}`);
if (typeof integrity === 'string') {
- const sri = Object.freeze(SRI.parse(integrity));
+ const sri = ObjectFreeze(SRI.parse(integrity));
if (integrities.has(resourceHREF)) {
const old = integrities.get(resourceHREF);
let mismatch = false;
@@ -156,7 +157,7 @@ class Manifest {
parsedURLs.set(to, resolvedURL);
parsedURLs.set(href, resolvedURL);
return resolvedURL;
- } else if (RegExpPrototype.test(kRelativeURLStringPattern, to)) {
+ } else if (RegExpPrototypeTest(kRelativeURLStringPattern, to)) {
const resolvedURL = new URL(to, manifestURL);
const href = resourceURL.href;
parsedURLs.set(to, resolvedURL);
@@ -180,7 +181,7 @@ class Manifest {
'dependencies');
}
}
- Object.freeze(this);
+ ObjectFreeze(this);
}
getRedirector(requester) {
@@ -217,7 +218,7 @@ class Manifest {
timingSafeEqual(digest, expected)) {
return true;
}
- MapPrototype.set(
+ MapPrototypeSet(
realIntegrities,
algorithm,
BufferToString(digest, 'base64')
@@ -230,8 +231,8 @@ class Manifest {
}
// Lock everything down to avoid problems even if reference is leaked somehow
-Object.setPrototypeOf(Manifest, null);
-Object.setPrototypeOf(Manifest.prototype, null);
-Object.freeze(Manifest);
-Object.freeze(Manifest.prototype);
-module.exports = Object.freeze({ Manifest });
+ObjectSetPrototypeOf(Manifest, null);
+ObjectSetPrototypeOf(Manifest.prototype, null);
+ObjectFreeze(Manifest);
+ObjectFreeze(Manifest.prototype);
+module.exports = ObjectFreeze({ Manifest });
diff --git a/lib/internal/policy/sri.js b/lib/internal/policy/sri.js
index 877c96a6f7..38d7fc9e07 100644
--- a/lib/internal/policy/sri.js
+++ b/lib/internal/policy/sri.js
@@ -2,9 +2,12 @@
// Value of https://w3c.github.io/webappsec-subresource-integrity/#the-integrity-attribute
const {
- Object,
- RegExpPrototype,
- StringPrototype
+ ObjectDefineProperty,
+ ObjectFreeze,
+ ObjectSeal,
+ RegExpPrototypeExec,
+ RegExpPrototypeTest,
+ StringPrototypeSlice,
} = primordials;
// Returns [{algorithm, value (in base64 string), options,}]
@@ -20,10 +23,9 @@ const kHASH_EXPRESSION = `(${kHASH_ALGO})-(${kHASH_VALUE})`;
const kOPTION_EXPRESSION = `(${kVCHAR}*)`;
const kHASH_WITH_OPTIONS = `${kHASH_EXPRESSION}(?:[?](${kOPTION_EXPRESSION}))?`;
const kSRIPattern = RegExp(`(${kWSP}*)(?:${kHASH_WITH_OPTIONS})`, 'g');
-const { freeze } = Object;
-Object.seal(kSRIPattern);
+ObjectSeal(kSRIPattern);
const kAllWSP = RegExp(`^${kWSP}*$`);
-Object.seal(kAllWSP);
+ObjectSeal(kAllWSP);
const BufferFrom = require('buffer').Buffer.from;
@@ -32,7 +34,7 @@ const parse = (str) => {
let prevIndex = 0;
let match;
const entries = [];
- while (match = RegExpPrototype.exec(kSRIPattern, str)) {
+ while (match = RegExpPrototypeExec(kSRIPattern, str)) {
if (match.index !== prevIndex) {
throw new ERR_SRI_PARSE(str, str.charAt(prevIndex), prevIndex);
}
@@ -41,10 +43,10 @@ const parse = (str) => {
}
// Avoid setters being fired
- Object.defineProperty(entries, entries.length, {
+ ObjectDefineProperty(entries, entries.length, {
enumerable: true,
configurable: true,
- value: freeze({
+ value: ObjectFreeze({
__proto__: null,
algorithm: match[2],
value: BufferFrom(match[3], 'base64'),
@@ -55,7 +57,7 @@ const parse = (str) => {
}
if (prevIndex !== str.length) {
- if (!RegExpPrototype.test(kAllWSP, StringPrototype.slice(str, prevIndex))) {
+ if (!RegExpPrototypeTest(kAllWSP, StringPrototypeSlice(str, prevIndex))) {
throw new ERR_SRI_PARSE(str, str.charAt(prevIndex), prevIndex);
}
}