mirror of
https://github.com/denoland/deno.git
synced 2025-10-03 07:34:36 +00:00
refactor
This commit is contained in:
parent
8338652401
commit
0c906254e3
1 changed files with 14 additions and 25 deletions
|
@ -271,7 +271,7 @@ impl Event {
|
||||||
event_object: v8::Local<'a, v8::Object>,
|
event_object: v8::Local<'a, v8::Object>,
|
||||||
target: &EventTarget,
|
target: &EventTarget,
|
||||||
target_object: v8::Global<v8::Object>,
|
target_object: v8::Global<v8::Object>,
|
||||||
path: &Vec<Path>,
|
path: &[Path],
|
||||||
path_index: usize,
|
path_index: usize,
|
||||||
phase: InvokePhase,
|
phase: InvokePhase,
|
||||||
) {
|
) {
|
||||||
|
@ -762,9 +762,7 @@ impl CustomEvent {
|
||||||
)?;
|
)?;
|
||||||
let event = Event::new(typ, event_init.into_option());
|
let event = Event::new(typ, event_init.into_option());
|
||||||
|
|
||||||
let detail = if init.is_object()
|
let detail = if let Ok(init) = init.try_cast::<v8::Object>() {
|
||||||
&& let Some(init) = init.to_object(scope)
|
|
||||||
{
|
|
||||||
get_value(scope, init, "detail")
|
get_value(scope, init, "detail")
|
||||||
.map(|detail| v8::Global::new(scope, detail))
|
.map(|detail| v8::Global::new(scope, detail))
|
||||||
} else {
|
} else {
|
||||||
|
@ -906,9 +904,7 @@ impl ErrorEvent {
|
||||||
Event::new(typ, None)
|
Event::new(typ, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
let error = if init.is_object()
|
let error = if let Ok(init) = init.try_cast::<v8::Object>() {
|
||||||
&& let Some(init) = init.to_object(scope)
|
|
||||||
{
|
|
||||||
get_value(scope, init, "error").map(|error| v8::Global::new(scope, error))
|
get_value(scope, init, "error").map(|error| v8::Global::new(scope, error))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -931,12 +927,12 @@ impl ErrorEvent {
|
||||||
|
|
||||||
#[getter]
|
#[getter]
|
||||||
fn lineno(&self) -> u32 {
|
fn lineno(&self) -> u32 {
|
||||||
self.lineno.clone()
|
self.lineno
|
||||||
}
|
}
|
||||||
|
|
||||||
#[getter]
|
#[getter]
|
||||||
fn colno(&self) -> u32 {
|
fn colno(&self) -> u32 {
|
||||||
self.colno.clone()
|
self.colno
|
||||||
}
|
}
|
||||||
|
|
||||||
#[getter]
|
#[getter]
|
||||||
|
@ -965,6 +961,7 @@ impl GarbageCollected for PromiseRejectionEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PromiseRejectionEvent {
|
impl PromiseRejectionEvent {
|
||||||
|
#[inline]
|
||||||
fn new(
|
fn new(
|
||||||
promise: v8::Global<v8::Object>,
|
promise: v8::Global<v8::Object>,
|
||||||
reason: Option<v8::Global<v8::Value>>,
|
reason: Option<v8::Global<v8::Value>>,
|
||||||
|
@ -996,8 +993,7 @@ impl PromiseRejectionEvent {
|
||||||
let promise = {
|
let promise = {
|
||||||
let promise = get_value(scope, init, "promise");
|
let promise = get_value(scope, init, "promise");
|
||||||
if let Some(promise) = promise
|
if let Some(promise) = promise
|
||||||
&& promise.is_object()
|
&& let Ok(promise) = promise.try_cast::<v8::Object>()
|
||||||
&& let Some(promise) = promise.to_object(scope)
|
|
||||||
{
|
{
|
||||||
v8::Global::new(scope, promise)
|
v8::Global::new(scope, promise)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1065,6 +1061,7 @@ impl GarbageCollected for CloseEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CloseEvent {
|
impl CloseEvent {
|
||||||
|
#[inline]
|
||||||
fn new(init: Option<CloseEventInit>) -> CloseEvent {
|
fn new(init: Option<CloseEventInit>) -> CloseEvent {
|
||||||
let (was_clean, code, reason) = if let Some(init) = init {
|
let (was_clean, code, reason) = if let Some(init) = init {
|
||||||
(init.was_clean, init.code, init.reason)
|
(init.was_clean, init.code, init.reason)
|
||||||
|
@ -1222,16 +1219,13 @@ impl MessageEvent {
|
||||||
Event::new(typ, None)
|
Event::new(typ, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
let (data, source, ports) = if init.is_object()
|
let (data, source, ports) = if let Ok(init) = init.try_cast::<v8::Object>()
|
||||||
&& let Some(init) = init.to_object(scope)
|
|
||||||
{
|
{
|
||||||
let data = get_value(scope, init, "data")
|
let data = get_value(scope, init, "data")
|
||||||
.map(|value| v8::Global::new(scope, value));
|
.map(|value| v8::Global::new(scope, value));
|
||||||
// TODO(petamoriken): Validate Window or MessagePort
|
// TODO(petamoriken): Validate Window or MessagePort
|
||||||
let source = if let Some(source) = get_value(scope, init, "source") {
|
let source = if let Some(source) = get_value(scope, init, "source") {
|
||||||
if source.is_object()
|
if let Ok(source) = source.try_cast::<v8::Object>() {
|
||||||
&& let Some(source) = source.to_object(scope)
|
|
||||||
{
|
|
||||||
Some(v8::Global::new(scope, source))
|
Some(v8::Global::new(scope, source))
|
||||||
} else {
|
} else {
|
||||||
return Err(EventError::WebIDL(WebIdlError::new(
|
return Err(EventError::WebIDL(WebIdlError::new(
|
||||||
|
@ -1464,14 +1458,9 @@ impl ProgressEvent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub(crate) struct ReportExceptionStackedCalls(u32);
|
pub(crate) struct ReportExceptionStackedCalls(u32);
|
||||||
|
|
||||||
impl Default for ReportExceptionStackedCalls {
|
|
||||||
fn default() -> Self {
|
|
||||||
ReportExceptionStackedCalls(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/#report-the-exception
|
// https://html.spec.whatwg.org/#report-the-exception
|
||||||
fn report_exception<'a>(
|
fn report_exception<'a>(
|
||||||
scope: &mut v8::HandleScope<'a>,
|
scope: &mut v8::HandleScope<'a>,
|
||||||
|
@ -1525,8 +1514,8 @@ fn report_exception<'a>(
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
let error_event = ErrorEvent {
|
let error_event = ErrorEvent {
|
||||||
message: message.unwrap_or(String::new()),
|
message: message.unwrap_or_default(),
|
||||||
filename: file_name.unwrap_or(String::new()),
|
filename: file_name.unwrap_or_default(),
|
||||||
lineno: line_number.unwrap_or(0) as u32,
|
lineno: line_number.unwrap_or(0) as u32,
|
||||||
colno: column_number.unwrap_or(0) as u32,
|
colno: column_number.unwrap_or(0) as u32,
|
||||||
error: Some(v8::Global::new(scope, exception)),
|
error: Some(v8::Global::new(scope, exception)),
|
||||||
|
@ -1539,7 +1528,7 @@ fn report_exception<'a>(
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let global = scope.get_current_context().global(scope);
|
let global = scope.get_current_context().global(scope);
|
||||||
let target =
|
let target =
|
||||||
cppgc::try_unwrap_cppgc_object::<EventTarget>(scope, global.into())
|
cppgc::try_unwrap_cppgc_proto_object::<EventTarget>(scope, global.into())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let global = v8::Global::new(scope, global);
|
let global = v8::Global::new(scope, global);
|
||||||
event.dispatch(scope, state, event_object, &target, global, None)
|
event.dispatch(scope, state, event_object, &target, global, None)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue