Skip to content

Commit 607f305

Browse files
committed
fix(harmony): 修复重写console时机错误
1 parent e0b9a02 commit 607f305

File tree

1 file changed

+22
-13
lines changed
  • packages/uni-console/src/runtime/console

1 file changed

+22
-13
lines changed

packages/uni-console/src/runtime/console/index.ts

+22-13
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ function sendConsoleMessages(messages: Message[]) {
3030
)
3131
}
3232

33-
if (__HARMONY_JSVM__) {
34-
if (
35-
typeof UTSProxyObject === 'object' &&
36-
UTSProxyObject !== null &&
37-
typeof UTSProxyObject.invokeSync === 'function'
38-
) {
39-
UTSProxyObject.invokeSync('__UniConsole', 'setSendConsoleMessages', [
40-
sendConsoleMessages,
41-
])
42-
}
43-
}
44-
4533
export function setSendConsole(value: SendFn, extra: Record<string, any> = {}) {
4634
sendConsole = value
4735
Object.assign(messageExtra, extra)
@@ -55,6 +43,17 @@ export function setSendConsole(value: SendFn, extra: Record<string, any> = {}) {
5543
const atFileRegex = /^\s*at\s+[\w/./-]+:\d+$/
5644

5745
export function rewriteConsole() {
46+
if (__HARMONY_JSVM__) {
47+
if (
48+
typeof UTSProxyObject === 'object' &&
49+
UTSProxyObject !== null &&
50+
typeof UTSProxyObject.invokeSync === 'function'
51+
) {
52+
UTSProxyObject.invokeSync('__UniConsole', 'setSendConsoleMessages', [
53+
sendConsoleMessages,
54+
])
55+
}
56+
}
5857
function wrapConsole(type: MessageType) {
5958
return function (...args: any[]) {
6059
const originalArgs = [...args]
@@ -113,7 +112,17 @@ export function rewriteConsole() {
113112
}
114113
}
115114
}
116-
return function restoreConsole() {}
115+
return function restoreConsole() {
116+
if (__HARMONY_JSVM__) {
117+
if (
118+
typeof UTSProxyObject === 'object' &&
119+
UTSProxyObject !== null &&
120+
typeof UTSProxyObject.invokeSync === 'function'
121+
) {
122+
UTSProxyObject.invokeSync('__UniConsole', 'restoreConsole', [])
123+
}
124+
}
125+
}
117126
}
118127

119128
function isConsoleWritable() {

0 commit comments

Comments
 (0)