Unverified Commit 58209bde authored by Josh Story's avatar Josh Story Committed by GitHub

Exclude Object and Promise prototype properties from shadowing for params and searchParams (#70568)

params and searchParams are now promises however to facilitate migration
params and searchParams can still be referenced directly on these props.
There are a number of special properties however that conflict with this
and this change special cases more property names to not be
synchronously accessed.

We exclude common Object prototype properties, Promise prototype
properties, and properties that are commonly existence tested like
toJSON and displayName.
parent af8af5ea
...@@ -192,10 +192,32 @@ function makeAbortingExoticParams( ...@@ -192,10 +192,32 @@ function makeAbortingExoticParams(
Object.keys(underlyingParams).forEach((prop) => { Object.keys(underlyingParams).forEach((prop) => {
switch (prop) { switch (prop) {
// Object prototype
case 'hasOwnProperty':
case 'isPrototypeOf':
case 'propertyIsEnumerable':
case 'toString':
case 'valueOf':
case 'toLocaleString':
// Promise prototype
// fallthrough
case 'then': case 'then':
case 'status': { case 'catch':
// We can't assign params over these properties because the VM and React use case 'finally':
// them to reason about the Promise.
// React Promise extension
// fallthrough
case 'value':
case 'status':
// Common tested properties
// fallthrough
case 'toJSON':
case '$$typeof':
case '__esModule': {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
break break
} }
default: { default: {
...@@ -246,11 +268,32 @@ function makeErroringExoticParams( ...@@ -246,11 +268,32 @@ function makeErroringExoticParams(
Object.keys(underlyingParams).forEach((prop) => { Object.keys(underlyingParams).forEach((prop) => {
switch (prop) { switch (prop) {
// Object prototype
case 'hasOwnProperty':
case 'isPrototypeOf':
case 'propertyIsEnumerable':
case 'toString':
case 'valueOf':
case 'toLocaleString':
// Promise prototype
// fallthrough
case 'then': case 'then':
case 'catch':
case 'finally':
// React Promise extension
// fallthrough
case 'value':
case 'status': case 'status':
case 'value': {
// We can't assign params over these properties because the VM and React use // Common tested properties
// them to reason about the Promise. // fallthrough
case 'toJSON':
case '$$typeof':
case '__esModule': {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
break break
} }
default: { default: {
...@@ -335,11 +378,32 @@ function makeUntrackedExoticParams(underlyingParams: Params): Promise<Params> { ...@@ -335,11 +378,32 @@ function makeUntrackedExoticParams(underlyingParams: Params): Promise<Params> {
Object.keys(underlyingParams).forEach((prop) => { Object.keys(underlyingParams).forEach((prop) => {
switch (prop) { switch (prop) {
// Object prototype
case 'hasOwnProperty':
case 'isPrototypeOf':
case 'propertyIsEnumerable':
case 'toString':
case 'valueOf':
case 'toLocaleString':
// Promise prototype
// fallthrough
case 'then': case 'then':
case 'catch':
case 'finally':
// React Promise extension
// fallthrough
case 'value': case 'value':
case 'status': { case 'status':
// These properties cannot be shadowed with a search param because they
// are necessary for ReactPromise's to work correctly with `use` // Common tested properties
// fallthrough
case 'toJSON':
case '$$typeof':
case '__esModule': {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
break break
} }
default: { default: {
...@@ -370,11 +434,32 @@ function makeDynamicallyTrackedExoticParamsWithDevWarnings( ...@@ -370,11 +434,32 @@ function makeDynamicallyTrackedExoticParamsWithDevWarnings(
Object.keys(underlyingParams).forEach((prop) => { Object.keys(underlyingParams).forEach((prop) => {
switch (prop) { switch (prop) {
// Object prototype
case 'hasOwnProperty':
case 'isPrototypeOf':
case 'propertyIsEnumerable':
case 'toString':
case 'valueOf':
case 'toLocaleString':
// Promise prototype
// fallthrough
case 'then': case 'then':
case 'catch':
case 'finally':
// React Promise extension
// fallthrough
case 'value': case 'value':
case 'status': { case 'status':
// These properties cannot be shadowed with a search param because they
// are necessary for ReactPromise's to work correctly with `use` // Common tested properties
// fallthrough
case 'toJSON':
case '$$typeof':
case '__esModule': {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
unproxiedProperties.push(prop) unproxiedProperties.push(prop)
break break
} }
......
...@@ -193,6 +193,33 @@ function makeAbortingExoticSearchParams( ...@@ -193,6 +193,33 @@ function makeAbortingExoticSearchParams(
annotateDynamicAccess(expression, prerenderStore) annotateDynamicAccess(expression, prerenderStore)
return ReflectAdapter.get(target, prop, receiver) return ReflectAdapter.get(target, prop, receiver)
} }
// Object prototype
case 'hasOwnProperty':
case 'isPrototypeOf':
case 'propertyIsEnumerable':
case 'toString':
case 'valueOf':
case 'toLocaleString':
// Promise prototype
// fallthrough
case 'catch':
case 'finally':
// React Promise extension
// fallthrough
case 'value':
// Common tested properties
// fallthrough
case 'toJSON':
case '$$typeof':
case '__esModule': {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
return ReflectAdapter.get(target, prop, receiver)
}
default: { default: {
if (typeof prop === 'string') { if (typeof prop === 'string') {
const expression = describeStringPropertyAccess( const expression = describeStringPropertyAccess(
...@@ -267,6 +294,32 @@ function makeErroringExoticSearchParams( ...@@ -267,6 +294,32 @@ function makeErroringExoticSearchParams(
} }
switch (prop) { switch (prop) {
// Object prototype
case 'hasOwnProperty':
case 'isPrototypeOf':
case 'propertyIsEnumerable':
case 'toString':
case 'valueOf':
case 'toLocaleString':
// Promise prototype
// fallthrough
case 'catch':
case 'finally':
// React Promise extension
// fallthrough
case 'value':
// Common tested properties
// fallthrough
case 'toJSON':
case '$$typeof':
case '__esModule': {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
return ReflectAdapter.get(target, prop, receiver)
}
case 'then': { case 'then': {
const expression = const expression =
'`await searchParams`, `searchParams.then`, or similar' '`await searchParams`, `searchParams.then`, or similar'
...@@ -402,11 +455,32 @@ function makeUntrackedExoticSearchParams( ...@@ -402,11 +455,32 @@ function makeUntrackedExoticSearchParams(
Object.keys(underlyingSearchParams).forEach((prop) => { Object.keys(underlyingSearchParams).forEach((prop) => {
switch (prop) { switch (prop) {
// Object prototype
case 'hasOwnProperty':
case 'isPrototypeOf':
case 'propertyIsEnumerable':
case 'toString':
case 'valueOf':
case 'toLocaleString':
// Promise prototype
// fallthrough
case 'then': case 'then':
case 'catch':
case 'finally':
// React Promise extension
// fallthrough
case 'value': case 'value':
case 'status': { case 'status':
// These properties cannot be shadowed with a search param because they
// are necessary for ReactPromise's to work correctly with `use` // Common tested properties
// fallthrough
case 'toJSON':
case '$$typeof':
case '__esModule': {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
break break
} }
default: { default: {
...@@ -503,11 +577,32 @@ function makeDynamicallyTrackedExoticSearchParamsWithDevWarnings( ...@@ -503,11 +577,32 @@ function makeDynamicallyTrackedExoticSearchParamsWithDevWarnings(
Object.keys(underlyingSearchParams).forEach((prop) => { Object.keys(underlyingSearchParams).forEach((prop) => {
switch (prop) { switch (prop) {
// Object prototype
case 'hasOwnProperty':
case 'isPrototypeOf':
case 'propertyIsEnumerable':
case 'toString':
case 'valueOf':
case 'toLocaleString':
// Promise prototype
// fallthrough
case 'then': case 'then':
case 'catch':
case 'finally':
// React Promise extension
// fallthrough
case 'value': case 'value':
case 'status': { case 'status':
// These properties cannot be shadowed with a search param because they
// are necessary for ReactPromise's to work correctly with `use` // Common tested properties
// fallthrough
case 'toJSON':
case '$$typeof':
case '__esModule': {
// These properties cannot be shadowed because they need to be the
// true underlying value for Promises to work correctly at runtime
unproxiedProperties.push(prop) unproxiedProperties.push(prop)
break break
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment