Console polyfill: preserve unknown methods from originalConsole if found (#43459)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43459

Changelog: [General][Changed] - Console polyfill now copies all properties from the existing `console` object

Fusebox now exposes a full WHATWG `console` object integrated directly with CDP debugging (D54826073). Some WHATWG `console` methods are missing from React Native's polyfill/shim, so let's pass those through unmodified so they can still be called.

(Long term, we shouldn't need most of `console.js`, but let's get there gradually as there are many RN users still depending on `nativeLoggingHook` etc.)

NOTE: We also update the "bundled" copy of `console.js` that lives in the jsinspector-modern C++ test suite.

Reviewed By: huntie

Differential Revision: D54827902

fbshipit-source-id: c6c9128903496810192614f4f8d80b68b02e25c4
This commit is contained in:
Moti Zilberman 2024-03-15 04:23:57 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 80bcdc9942
Коммит 949296571b
2 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -554,6 +554,7 @@ if (global.nativeLoggingHook) {
}
global.console = {
...(originalConsole ?? {}),
error: getNativeLogFunction(LOG_LEVELS.error),
info: getNativeLogFunction(LOG_LEVELS.info),
log: getNativeLogFunction(LOG_LEVELS.info),
@ -578,7 +579,10 @@ if (global.nativeLoggingHook) {
if (__DEV__ && originalConsole) {
Object.keys(console).forEach(methodName => {
const reactNativeMethod = console[methodName];
if (originalConsole[methodName]) {
if (
originalConsole[methodName] &&
reactNativeMethod !== originalConsole[methodName]
) {
console[methodName] = function () {
originalConsole[methodName](...arguments);
reactNativeMethod.apply(console, arguments);

Просмотреть файл

@ -553,6 +553,7 @@ if (global.nativeLoggingHook) {
}
global.console = {
...(originalConsole ?? {}),
error: getNativeLogFunction(LOG_LEVELS.error),
info: getNativeLogFunction(LOG_LEVELS.info),
log: getNativeLogFunction(LOG_LEVELS.info),
@ -577,7 +578,10 @@ if (global.nativeLoggingHook) {
if (__DEV__ && originalConsole) {
Object.keys(console).forEach(methodName => {
const reactNativeMethod = console[methodName];
if (originalConsole[methodName]) {
if (
originalConsole[methodName] &&
reactNativeMethod !== originalConsole[methodName]
) {
console[methodName] = function () {
originalConsole[methodName](...arguments);
reactNativeMethod.apply(console, arguments);