chromium dom v8 event

 

v8 启动:

void LocalWindowProxy::Initialize() 

void LocalFrameClientImpl::DidCreateScriptContext

RenderFrameImpl::DidCreateScriptContext

NodeBindings::LoadEnvironment

EventTarget::SetAttributeEventListener

 EventTarget::AddEventListenerInternal

LocalDOMWindow::AddedEventListener

聚集在 V8_event_target.cc里面

 V8EventTarget::AddEventListenerMethodCallback
static void AddEventListenerMethod(const v8::FunctionCallbackInfo& info) {
  ExceptionState exception_state(info.GetIsolate(), ExceptionState::kExecutionContext, "EventTarget", "addEventListener");

  EventTarget* impl = V8EventTarget::ToImpl(info.Holder());

  if (UNLIKELY(info.Length() < 2)) {
    exception_state.ThrowTypeError(ExceptionMessages::NotEnoughArguments(2, info.Length()));
    return;
  }

  V8StringResource<> type;
  V8EventListener* listener;
  AddEventListenerOptionsOrBoolean options;
  int num_args_passed = info.Length();
  while (num_args_passed > 0) {
    if (!info[num_args_passed - 1]->IsUndefined())
      break;
    --num_args_passed;
  }
  type = info[0];
  if (!type.Prepare())
    return;

  if (info[1]->IsObject()) {
    listener = V8EventListener::Create(info[1].As());
  } else if (info[1]->IsNullOrUndefined()) {
    listener = nullptr;
  } else {
    exception_state.ThrowTypeError("The callback provided as parameter 2 is not an object.");
    return;
  }

  if (UNLIKELY(num_args_passed <= 2)) {
    V8EventTarget::AddEventListenerMethodPrologueCustom(info, impl);
    impl->addEventListener(type, listener);
    return;
  }
  V8AddEventListenerOptionsOrBoolean::ToImpl(info.GetIsolate(), info[2], options, UnionTypeConversionMode::kNotNullable, exception_state);
  if (exception_state.HadException())
    return;

  V8EventTarget::AddEventListenerMethodPrologueCustom(info, impl);
  impl->addEventListener(type, listener, options);
}

EventTarget::AddEventListenerInternal

 


 

获取事件属性:

    Vector argv;
    argv.push_back(ToNode() ? ToNode()->nodeName() : InterfaceName());
    argv.push_back(event_type);
    activity_logger->LogEvent("blinkAddEventListener", argv.size(),
                              argv.data());

nodejs electron启动设置错误回调:

void V8Window::OnerrorAttributeSetterCallback(
    const v8::FunctionCallbackInfo& info) {
  RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(info.GetIsolate(), "Blink_DOMWindow_onerror_Setter");

  v8::Local v8_value = info[0];

  dom_window_v8_internal::OnerrorAttributeSetter(v8_value, info);
}
class GlobalEventHandlers {
  STATIC_ONLY(GlobalEventHandlers);

 public:
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(abort, kAbort)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(activateinvisible, kActivateinvisible)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(auxclick, kAuxclick)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(blur, kBlur)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(beforeactivate, kBeforeactivate)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(cancel, kCancel)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(canplay, kCanplay)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(canplaythrough, kCanplaythrough)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(change, kChange)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(click, kClick)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(close, kClose)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(contextmenu, kContextmenu)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(cuechange, kCuechange)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(dblclick, kDblclick)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(drag, kDrag)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(dragend, kDragend)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(dragenter, kDragenter)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(dragleave, kDragleave)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(dragover, kDragover)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(dragstart, kDragstart)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(drop, kDrop)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(durationchange, kDurationchange)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(emptied, kEmptied)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(ended, kEnded)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(error, kError)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(focus, kFocus)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(formdata, kFormdata)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(gotpointercapture, kGotpointercapture)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(input, kInput)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(invalid, kInvalid)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(keydown, kKeydown)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(keypress, kKeypress)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(keyup, kKeyup)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(load, kLoad)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(loadeddata, kLoadeddata)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(loadedmetadata, kLoadedmetadata)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(loadstart, kLoadstart)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(lostpointercapture,
                                         kLostpointercapture)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(mousedown, kMousedown)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(mouseenter, kMouseenter)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(mouseleave, kMouseleave)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(mousemove, kMousemove)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(mouseout, kMouseout)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(mouseover, kMouseover)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(mouseup, kMouseup)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(mousewheel, kMousewheel)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(overscroll, kOverscroll)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(pause, kPause)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(play, kPlay)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(playing, kPlaying)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(pointercancel, kPointercancel)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(pointerdown, kPointerdown)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(pointerenter, kPointerenter)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(pointerleave, kPointerleave)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(pointermove, kPointermove)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(pointerout, kPointerout)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(pointerover, kPointerover)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(pointerrawupdate, kPointerrawupdate)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(pointerup, kPointerup)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(progress, kProgress)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(ratechange, kRatechange)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(reset, kReset)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(resize, kResize)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(scroll, kScroll)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(scrollend, kScrollend)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(seeked, kSeeked)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(seeking, kSeeking)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(select, kSelect)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(selectionchange, kSelectionchange)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(selectstart, kSelectstart)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(stalled, kStalled)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(submit, kSubmit)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(suspend, kSuspend)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(timeupdate, kTimeupdate)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(toggle, kToggle)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(touchcancel, kTouchcancel)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(touchend, kTouchend)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(touchmove, kTouchmove)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(touchstart, kTouchstart)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(volumechange, kVolumechange)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(waiting, kWaiting)
  DEFINE_STATIC_ATTRIBUTE_EVENT_LISTENER(wheel, kWheel)
};

}  // namespace
bool EventTarget::SetAttributeEventListener(const AtomicString& event_type,
                                            EventListener* listener) {
  RegisteredEventListener* registered_listener =
      GetAttributeRegisteredEventListener(event_type);
  if (!listener) {
    if (registered_listener)
      removeEventListener(event_type, registered_listener->Callback(), false);
    return false;
  }
  if (registered_listener) {
    if (IsA(listener) &&
        IsInstrumentedForAsyncStack(event_type)) {
      probe::AsyncTaskScheduled(GetExecutionContext(), event_type,
                                listener->async_task_id());
    }
    registered_listener->SetCallback(listener);
    return true;
  }
  return addEventListener(event_type, listener, false);
}

 

你可能感兴趣的:(chromium dom v8 event)