Skip to content

Commit

Permalink
Rename APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Oct 2, 2023
1 parent 984a619 commit f0c6314
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
12 changes: 6 additions & 6 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ describe('ReactFlight', () => {
name: 'Seb',
age: 'rather not say',
};
ReactServer.unstable_taintShallowObject(
ReactServer.experimental_taintObjectReference(
"Don't pass the raw user object to the client",
user,
);
Expand All @@ -1497,7 +1497,7 @@ describe('ReactFlight', () => {
const User = clientReference(UserClient);

function change() {}
ReactServer.unstable_taintShallowObject(
ReactServer.experimental_taintObjectReference(
'A change handler cannot be passed to a client component',
change,
);
Expand Down Expand Up @@ -1525,7 +1525,7 @@ describe('ReactFlight', () => {
SECRET: '3e971ecc1485fe78625598bf9b6f85db',
},
};
ReactServer.unstable_taintValue(
ReactServer.experimental_taintUniqueValue(
'Cannot pass a secret token to the client',
process,
process.env.SECRET,
Expand Down Expand Up @@ -1555,7 +1555,7 @@ describe('ReactFlight', () => {
name: 'Seb',
token: BigInt('0x3e971ecc1485fe78625598bf9b6f85dc'),
};
ReactServer.unstable_taintValue(
ReactServer.experimental_taintUniqueValue(
'Cannot pass a secret token to the client',
currentUser,
currentUser.token,
Expand Down Expand Up @@ -1586,7 +1586,7 @@ describe('ReactFlight', () => {
name: 'Seb',
token: new Uint32Array([0x3e971ecc, 0x1485fe78, 0x625598bf, 0x9b6f85dd]),
};
ReactServer.unstable_taintValue(
ReactServer.experimental_taintUniqueValue(
'Cannot pass a secret token to the client',
currentUser,
currentUser.token,
Expand Down Expand Up @@ -1619,7 +1619,7 @@ describe('ReactFlight', () => {
name: 'Seb',
token: '3e971ecc1485fe78625598bf9b6f85db',
};
ReactServer.unstable_taintValue(
ReactServer.experimental_taintUniqueValue(
'Cannot pass a secret token to the client',
user,
user.token,
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/ReactSharedSubset.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export {default as __SECRET_SERVER_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} fr

// These are server-only
export {
taintValue as unstable_taintValue,
taintShallowObject as unstable_taintShallowObject,
taintUniqueValue as experimental_taintUniqueValue,
taintObjectReference as experimental_taintObjectReference,
} from './ReactTaint';

export {
Expand Down
13 changes: 8 additions & 5 deletions packages/react/src/ReactTaint.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const finalizationRegistry =
? new FinalizationRegistry(cleanup)
: null;

export function taintValue(
export function taintUniqueValue(
message: ?string,
lifetime: Reference,
value: string | bigint | $ArrayBufferView,
Expand Down Expand Up @@ -89,7 +89,7 @@ export function taintValue(
const kind = value === null ? 'null' : typeof value;
if (kind === 'object' || kind === 'function') {
throw new Error(
'taintValue cannot taint objects or functions. Try taintShallowObject instead.',
'taintUniqueValue cannot taint objects or functions. Try taintObjectReference instead.',
);
}
throw new Error(
Expand All @@ -113,23 +113,26 @@ export function taintValue(
}
}

export function taintShallowObject(message: ?string, object: Reference): void {
export function taintObjectReference(
message: ?string,
object: Reference,
): void {
if (!enableTaint) {
throw new Error('Not implemented.');
}
// eslint-disable-next-line react-internal/safe-string-coercion
message = '' + (message || defaultMessage);
if (typeof object === 'string' || typeof object === 'bigint') {
throw new Error(
'Only objects or functions can be passed to taintShallowObject. Try taintValue instead.',
'Only objects or functions can be passed to taintObjectReference. Try taintUniqueValue instead.',
);
}
if (
object === null ||
(typeof object !== 'object' && typeof object !== 'function')
) {
throw new Error(
'Only objects or functions can be passed to taintShallowObject.',
'Only objects or functions can be passed to taintObjectReference.',
);
}
TaintRegistryObjects.set(object, message);
Expand Down
6 changes: 3 additions & 3 deletions scripts/error-codes/codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@
"491": "It should not be possible to postpone both at the root of an element as well as a slot below. This is a bug in React.",
"492": "The \"react\" package in this environment is not configured correctly. The \"react-server\" condition must be enabled in any environment that runs React Server Components.",
"493": "To taint a value, a life time must be defined by passing an object that holds the value.",
"494": "taintValue cannot taint objects or functions. Try taintShallowObject instead.",
"494": "taintUniqueValue cannot taint objects or functions. Try taintObjectReference instead.",
"495": "Cannot taint a %s because the value is too general and cannot be a secret by",
"496": "Only objects or functions can be passed to taintShallowObject. Try taintValue instead.",
"497": "Only objects or functions can be passed to taintShallowObject."
"496": "Only objects or functions can be passed to taintObjectReference. Try taintUniqueValue instead.",
"497": "Only objects or functions can be passed to taintObjectReference."
}

0 comments on commit f0c6314

Please sign in to comment.