Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
25559ed0
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
25559ed0
编写于
1月 16, 2019
作者:
C
Chinmay Garde
提交者:
GitHub
1月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Wrap the user entrypoint function in a zone with native exception callback. (#7512)
上级
1b0d09b2
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
113 addition
and
48 deletion
+113
-48
common/settings.h
common/settings.h
+8
-0
lib/ui/hooks.dart
lib/ui/hooks.dart
+14
-0
lib/ui/ui_dart_state.cc
lib/ui/ui_dart_state.cc
+25
-9
lib/ui/ui_dart_state.h
lib/ui/ui_dart_state.h
+5
-0
lib/ui/window/window.cc
lib/ui/window/window.cc
+22
-0
runtime/dart_isolate.cc
runtime/dart_isolate.cc
+38
-39
runtime/dart_isolate.h
runtime/dart_isolate.h
+1
-0
未找到文件。
common/settings.h
浏览文件 @
25559ed0
...
...
@@ -20,6 +20,9 @@ namespace blink {
using
TaskObserverAdd
=
std
::
function
<
void
(
intptr_t
/* key */
,
fml
::
closure
/* callback */
)
>
;
using
TaskObserverRemove
=
std
::
function
<
void
(
intptr_t
/* key */
)
>
;
using
UnhandledExceptionCallback
=
std
::
function
<
bool
(
const
std
::
string
&
/* error */
,
const
std
::
string
&
/* stack trace */
)
>
;
struct
Settings
{
Settings
();
...
...
@@ -80,6 +83,11 @@ struct Settings {
// as fast as possible in returning from this callback. Long running
// operations in this callback do have the capability of introducing jank.
std
::
function
<
void
(
int64_t
)
>
idle_notification_callback
;
// A callback given to the embedder to react to unhandled exceptions in the
// running Flutter application. This callback is made on an internal engine
// managed thread and embedders must thread as necessary. Performing blocking
// calls in this callback will cause applications to jank.
UnhandledExceptionCallback
unhandled_exception_callback
;
bool
enable_software_rendering
=
false
;
bool
skia_deterministic_rendering_on_cpu
=
false
;
bool
verbose_logging
=
false
;
...
...
lib/ui/hooks.dart
浏览文件 @
25559ed0
...
...
@@ -162,6 +162,20 @@ void _drawFrame() {
_invoke
(
window
.
onDrawFrame
,
window
.
_onDrawFrameZone
);
}
@pragma
(
'vm:entry-point'
)
// ignore: unused_element
void
_runMainZoned
(
Function
startMainIsolateFunction
,
Function
userMainFunction
)
{
startMainIsolateFunction
((){
runZoned
<
Future
<
void
>>(()
{
userMainFunction
();
},
onError:
(
Object
error
,
StackTrace
stackTrace
)
{
_reportUnhandledException
(
error
.
toString
(),
stackTrace
.
toString
());
});
},
null
);
}
void
_reportUnhandledException
(
String
error
,
String
stackTrace
)
native
'Window_reportUnhandledException'
;
/// Invokes [callback] inside the given [zone].
void
_invoke
(
void
callback
(),
Zone
zone
)
{
if
(
callback
==
null
)
...
...
lib/ui/ui_dart_state.cc
浏览文件 @
25559ed0
...
...
@@ -13,15 +13,17 @@ using tonic::ToDart;
namespace
blink
{
UIDartState
::
UIDartState
(
TaskRunners
task_runners
,
TaskObserverAdd
add_callback
,
TaskObserverRemove
remove_callback
,
fml
::
WeakPtr
<
SnapshotDelegate
>
snapshot_delegate
,
fml
::
WeakPtr
<
IOManager
>
io_manager
,
std
::
string
advisory_script_uri
,
std
::
string
advisory_script_entrypoint
,
std
::
string
logger_prefix
,
IsolateNameServer
*
isolate_name_server
)
UIDartState
::
UIDartState
(
TaskRunners
task_runners
,
TaskObserverAdd
add_callback
,
TaskObserverRemove
remove_callback
,
fml
::
WeakPtr
<
SnapshotDelegate
>
snapshot_delegate
,
fml
::
WeakPtr
<
IOManager
>
io_manager
,
std
::
string
advisory_script_uri
,
std
::
string
advisory_script_entrypoint
,
std
::
string
logger_prefix
,
UnhandledExceptionCallback
unhandled_exception_callback
,
IsolateNameServer
*
isolate_name_server
)
:
task_runners_
(
std
::
move
(
task_runners
)),
add_callback_
(
std
::
move
(
add_callback
)),
remove_callback_
(
std
::
move
(
remove_callback
)),
...
...
@@ -30,6 +32,7 @@ UIDartState::UIDartState(TaskRunners task_runners,
advisory_script_uri_
(
std
::
move
(
advisory_script_uri
)),
advisory_script_entrypoint_
(
std
::
move
(
advisory_script_entrypoint
)),
logger_prefix_
(
std
::
move
(
logger_prefix
)),
unhandled_exception_callback_
(
unhandled_exception_callback
),
isolate_name_server_
(
isolate_name_server
)
{
AddOrRemoveTaskObserver
(
true
/* add */
);
}
...
...
@@ -133,4 +136,17 @@ tonic::DartErrorHandleType UIDartState::GetLastError() {
return
error
;
}
void
UIDartState
::
ReportUnhandledException
(
const
std
::
string
&
error
,
const
std
::
string
&
stack_trace
)
{
if
(
unhandled_exception_callback_
&&
unhandled_exception_callback_
(
error
,
stack_trace
))
{
return
;
}
// Either the exception handler was not set or it could not handle the error,
// just log the exception.
FML_LOG
(
ERROR
)
<<
"Unhandled Exception: "
<<
error
<<
std
::
endl
<<
stack_trace
;
}
}
// namespace blink
lib/ui/ui_dart_state.h
浏览文件 @
25559ed0
...
...
@@ -57,6 +57,9 @@ class UIDartState : public tonic::DartState {
tonic
::
DartErrorHandleType
GetLastError
();
void
ReportUnhandledException
(
const
std
::
string
&
error
,
const
std
::
string
&
stack_trace
);
template
<
class
T
>
static
flow
::
SkiaGPUObject
<
T
>
CreateGPUObject
(
sk_sp
<
T
>
object
)
{
if
(
!
object
)
{
...
...
@@ -77,6 +80,7 @@ class UIDartState : public tonic::DartState {
std
::
string
advisory_script_uri
,
std
::
string
advisory_script_entrypoint
,
std
::
string
logger_prefix
,
UnhandledExceptionCallback
unhandled_exception_callback
,
IsolateNameServer
*
isolate_name_server
);
~
UIDartState
()
override
;
...
...
@@ -102,6 +106,7 @@ class UIDartState : public tonic::DartState {
std
::
string
debug_name_
;
std
::
unique_ptr
<
Window
>
window_
;
tonic
::
DartMicrotaskQueue
microtask_queue_
;
UnhandledExceptionCallback
unhandled_exception_callback_
;
IsolateNameServer
*
isolate_name_server_
;
void
AddOrRemoveTaskObserver
(
bool
add
);
...
...
lib/ui/window/window.cc
浏览文件 @
25559ed0
...
...
@@ -65,6 +65,27 @@ void SetIsolateDebugName(Dart_NativeArguments args) {
UIDartState
::
Current
()
->
SetDebugName
(
name
);
}
void
ReportUnhandledException
(
Dart_NativeArguments
args
)
{
Dart_Handle
exception
=
nullptr
;
auto
error_name
=
tonic
::
DartConverter
<
std
::
string
>::
FromArguments
(
args
,
0
,
exception
);
if
(
exception
)
{
Dart_ThrowException
(
exception
);
return
;
}
auto
stack_trace
=
tonic
::
DartConverter
<
std
::
string
>::
FromArguments
(
args
,
1
,
exception
);
if
(
exception
)
{
Dart_ThrowException
(
exception
);
return
;
}
UIDartState
::
Current
()
->
ReportUnhandledException
(
std
::
move
(
error_name
),
std
::
move
(
stack_trace
));
}
Dart_Handle
SendPlatformMessage
(
Dart_Handle
window
,
const
std
::
string
&
name
,
Dart_Handle
callback
,
...
...
@@ -318,6 +339,7 @@ void Window::RegisterNatives(tonic::DartLibraryNatives* natives) {
{
"Window_render"
,
Render
,
2
,
true
},
{
"Window_updateSemantics"
,
UpdateSemantics
,
2
,
true
},
{
"Window_setIsolateDebugName"
,
SetIsolateDebugName
,
2
,
true
},
{
"Window_reportUnhandledException"
,
ReportUnhandledException
,
2
,
true
},
});
}
...
...
runtime/dart_isolate.cc
浏览文件 @
25559ed0
...
...
@@ -22,6 +22,7 @@
#include "third_party/tonic/dart_message_handler.h"
#include "third_party/tonic/dart_state.h"
#include "third_party/tonic/file_loader/file_loader.h"
#include "third_party/tonic/logging/dart_invoke.h"
#include "third_party/tonic/scopes/dart_api_scope.h"
#include "third_party/tonic/scopes/dart_isolate_scope.h"
...
...
@@ -109,6 +110,7 @@ DartIsolate::DartIsolate(DartVM* vm,
advisory_script_uri
,
advisory_script_entrypoint
,
vm
->
GetSettings
().
log_tag
,
vm
->
GetSettings
().
unhandled_exception_callback
,
vm
->
GetIsolateNameServer
()),
vm_
(
vm
),
isolate_snapshot_
(
std
::
move
(
isolate_snapshot
)),
...
...
@@ -391,33 +393,49 @@ bool DartIsolate::MarkIsolateRunnable() {
}
FML_WARN_UNUSED_RESULT
bool
DartIsolate
::
Run
(
const
std
::
string
&
entrypoint_name
)
{
TRACE_EVENT0
(
"flutter"
,
"DartIsolate::Run"
);
if
(
phase_
!=
Phase
::
Ready
)
{
static
bool
InvokeMainEntrypoint
(
Dart_Handle
user_entrypoint_function
)
{
if
(
tonic
::
LogIfError
(
user_entrypoint_function
))
{
FML_LOG
(
ERROR
)
<<
"Could not resolve main entrypoint function."
;
return
false
;
}
tonic
::
DartState
::
Scope
scope
(
this
);
auto
run_main_zoned_function
=
Dart_GetField
(
Dart_LookupLibrary
(
tonic
::
ToDart
(
"dart:ui"
)),
tonic
::
ToDart
(
"_runMainZoned"
));
Dart_Handle
entrypoint
=
Dart_GetField
(
Dart_RootLibrary
(),
tonic
::
ToDart
(
entrypoint_name
.
c_str
()));
if
(
tonic
::
LogIfError
(
entrypoint
))
{
auto
start_main_isolate_function
=
Dart_GetField
(
Dart_LookupLibrary
(
tonic
::
ToDart
(
"dart:isolate"
)),
tonic
::
ToDart
(
"_startMainIsolate"
));
if
(
tonic
::
LogIfError
(
run_main_zoned_function
)
||
tonic
::
LogIfError
(
start_main_isolate_function
))
{
FML_LOG
(
ERROR
)
<<
"Could not resolve main entrypoint trampolines."
;
return
false
;
}
Dart_Handle
isolate_lib
=
Dart_LookupLibrary
(
tonic
::
ToDart
(
"dart:isolate"
));
if
(
tonic
::
LogIfError
(
isolate_lib
))
{
if
(
tonic
::
LogIfError
(
tonic
::
DartInvoke
(
run_main_zoned_function
,
{
start_main_isolate_function
,
user_entrypoint_function
})))
{
FML_LOG
(
ERROR
)
<<
"Could not invoke the main entrypoint."
;
return
false
;
}
Dart_Handle
isolate_args
[]
=
{
entrypoint
,
Dart_Null
(),
};
return
true
;
}
if
(
tonic
::
LogIfError
(
Dart_Invoke
(
isolate_lib
,
tonic
::
ToDart
(
"_startMainIsolate"
),
sizeof
(
isolate_args
)
/
sizeof
(
isolate_args
[
0
]),
isolate_args
)))
{
FML_WARN_UNUSED_RESULT
bool
DartIsolate
::
Run
(
const
std
::
string
&
entrypoint_name
)
{
TRACE_EVENT0
(
"flutter"
,
"DartIsolate::Run"
);
if
(
phase_
!=
Phase
::
Ready
)
{
return
false
;
}
tonic
::
DartState
::
Scope
scope
(
this
);
auto
user_entrypoint_function
=
Dart_GetField
(
Dart_RootLibrary
(),
tonic
::
ToDart
(
entrypoint_name
.
c_str
()));
if
(
!
InvokeMainEntrypoint
(
user_entrypoint_function
))
{
return
false
;
}
...
...
@@ -436,30 +454,11 @@ bool DartIsolate::RunFromLibrary(const std::string& library_name,
tonic
::
DartState
::
Scope
scope
(
this
);
Dart_Handle
library
=
Dart_LookupLibrary
(
tonic
::
ToDart
(
library_name
.
c_str
()));
if
(
tonic
::
LogIfError
(
library
))
{
return
false
;
}
Dart_Handle
entrypoint
=
Dart_GetField
(
library
,
tonic
::
ToDart
(
entrypoint_name
.
c_str
()));
if
(
tonic
::
LogIfError
(
entrypoint
))
{
return
false
;
}
Dart_Handle
isolate_lib
=
Dart_LookupLibrary
(
tonic
::
ToDart
(
"dart:isolate"
));
if
(
tonic
::
LogIfError
(
isolate_lib
))
{
return
false
;
}
Dart_Handle
isolate_args
[]
=
{
entrypoint
,
Dart_Null
(),
};
auto
user_entrypoint_function
=
Dart_GetField
(
Dart_LookupLibrary
(
tonic
::
ToDart
(
library_name
.
c_str
())),
tonic
::
ToDart
(
entrypoint_name
.
c_str
()));
if
(
tonic
::
LogIfError
(
Dart_Invoke
(
isolate_lib
,
tonic
::
ToDart
(
"_startMainIsolate"
),
sizeof
(
isolate_args
)
/
sizeof
(
isolate_args
[
0
]),
isolate_args
)))
{
if
(
!
InvokeMainEntrypoint
(
user_entrypoint_function
))
{
return
false
;
}
...
...
runtime/dart_isolate.h
浏览文件 @
25559ed0
...
...
@@ -88,6 +88,7 @@ class DartIsolate : public UIDartState {
DartVM
*
GetDartVM
()
const
;
fml
::
RefPtr
<
DartSnapshot
>
GetIsolateSnapshot
()
const
;
fml
::
RefPtr
<
DartSnapshot
>
GetSharedSnapshot
()
const
;
std
::
weak_ptr
<
DartIsolate
>
GetWeakIsolatePtr
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录