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:
Родитель
80bcdc9942
Коммит
949296571b
|
@ -554,6 +554,7 @@ if (global.nativeLoggingHook) {
|
||||||
}
|
}
|
||||||
|
|
||||||
global.console = {
|
global.console = {
|
||||||
|
...(originalConsole ?? {}),
|
||||||
error: getNativeLogFunction(LOG_LEVELS.error),
|
error: getNativeLogFunction(LOG_LEVELS.error),
|
||||||
info: getNativeLogFunction(LOG_LEVELS.info),
|
info: getNativeLogFunction(LOG_LEVELS.info),
|
||||||
log: getNativeLogFunction(LOG_LEVELS.info),
|
log: getNativeLogFunction(LOG_LEVELS.info),
|
||||||
|
@ -578,7 +579,10 @@ if (global.nativeLoggingHook) {
|
||||||
if (__DEV__ && originalConsole) {
|
if (__DEV__ && originalConsole) {
|
||||||
Object.keys(console).forEach(methodName => {
|
Object.keys(console).forEach(methodName => {
|
||||||
const reactNativeMethod = console[methodName];
|
const reactNativeMethod = console[methodName];
|
||||||
if (originalConsole[methodName]) {
|
if (
|
||||||
|
originalConsole[methodName] &&
|
||||||
|
reactNativeMethod !== originalConsole[methodName]
|
||||||
|
) {
|
||||||
console[methodName] = function () {
|
console[methodName] = function () {
|
||||||
originalConsole[methodName](...arguments);
|
originalConsole[methodName](...arguments);
|
||||||
reactNativeMethod.apply(console, arguments);
|
reactNativeMethod.apply(console, arguments);
|
||||||
|
|
|
@ -553,6 +553,7 @@ if (global.nativeLoggingHook) {
|
||||||
}
|
}
|
||||||
|
|
||||||
global.console = {
|
global.console = {
|
||||||
|
...(originalConsole ?? {}),
|
||||||
error: getNativeLogFunction(LOG_LEVELS.error),
|
error: getNativeLogFunction(LOG_LEVELS.error),
|
||||||
info: getNativeLogFunction(LOG_LEVELS.info),
|
info: getNativeLogFunction(LOG_LEVELS.info),
|
||||||
log: getNativeLogFunction(LOG_LEVELS.info),
|
log: getNativeLogFunction(LOG_LEVELS.info),
|
||||||
|
@ -577,7 +578,10 @@ if (global.nativeLoggingHook) {
|
||||||
if (__DEV__ && originalConsole) {
|
if (__DEV__ && originalConsole) {
|
||||||
Object.keys(console).forEach(methodName => {
|
Object.keys(console).forEach(methodName => {
|
||||||
const reactNativeMethod = console[methodName];
|
const reactNativeMethod = console[methodName];
|
||||||
if (originalConsole[methodName]) {
|
if (
|
||||||
|
originalConsole[methodName] &&
|
||||||
|
reactNativeMethod !== originalConsole[methodName]
|
||||||
|
) {
|
||||||
console[methodName] = function () {
|
console[methodName] = function () {
|
||||||
originalConsole[methodName](...arguments);
|
originalConsole[methodName](...arguments);
|
||||||
reactNativeMethod.apply(console, arguments);
|
reactNativeMethod.apply(console, arguments);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче